Changeset 4479 in osm for applications/editors/josm


Ignore:
Timestamp:
2007-09-06T22:42:51+02:00 (18 years ago)
Author:
frederik
Message:
  • fixed hint line drawing
  • fixed selection list update
  • reinstated continuous drawing by hitting the spacebar at intermediate nodes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/core_0.5/src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java

    r4466 r4479  
    5252         */
    5353        public AddSegmentAction(MapFrame mapFrame) {
    54                 super(tr("Connect two node"),
     54                super(tr("Connect two nodes"),
    5555                                "addsegment",
    5656                                tr("Connect two nodes using ways."),
     
    7373        }
    7474
    75        
     75        /**
     76         * Called when user hits space bar while dragging.
     77         */
    7678        @Override public void actionPerformed(ActionEvent e) {
    7779                super.actionPerformed(e);
     
    102104
    103105                Node hovered = Main.map.mapView.getNearestNode(e.getPoint());
    104                 if (hovered == null || hovered == first) return;
    105 
     106                if (hovered == second) return;
     107
     108                drawHint(false);
    106109                second = hovered;
    107110                drawHint(true);
     
    115118                        drawHint(false);
    116119                        makeSegment();
     120                        first = null;
    117121                }
    118122        }
     
    143147                Node n1 = first;
    144148                Node n2 = second;
    145                         first = null;
    146                         second = null;
     149               
     150                // this is to allow continued segment drawing by hitting the space bar
     151                // at every intermediate node
     152                first = second;
     153                second = null;
    147154
    148155                if (n1 == null || n2 == null || n1 == n2) return;
    149                
     156
    150157                Way w = getWayForNode(n1);
    151158                Way wnew;
     159                Collection<OsmPrimitive> sel = Main.ds.getSelected();
     160               
    152161                if (w == null) {
     162                        // create a new way and add it to the current selection.
    153163                        wnew = new Way();
    154164                        wnew.nodes.add(n1);
    155165                        wnew.nodes.add(n2);
    156166                        Main.main.undoRedo.add(new AddCommand(wnew));
     167                        sel.add(wnew);
     168                        Main.ds.setSelected(sel);
    157169                } else {
     170                        // extend an existing way; only add to current selection if
     171                        // it is not already in there.
    158172                        wnew = new Way(w);
    159173                        if (wnew.nodes.get(wnew.nodes.size() - 1) == n1) {
     
    163177                        }
    164178                        Main.main.undoRedo.add(new ChangeCommand(w, wnew));
     179                        // do not use wnew below; ChangeCommand only uses wnew as a
     180                        // message about changes to be done to w but will not replace w!
     181                        if (!sel.contains(w)) {
     182                                sel.add(w);
     183                        }
     184                        // do not move this into the if block above since it also
     185                        // fires the selection change event which is desired.
     186                        Main.ds.setSelected(sel);
    165187                }
    166 
    167                         Collection<OsmPrimitive> sel = Main.ds.getSelected();
    168                 sel.add(wnew);
    169                         Main.ds.setSelected(sel);
    170188
    171189                Main.map.mapView.repaint();
Note: See TracChangeset for help on using the changeset viewer.