Changeset 409 in josm for trunk/src/org
- Timestamp:
- 2007-10-21T20:40:41+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r408 r409 24 24 25 25 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.actions.GroupAction;27 import org.openstreetmap.josm.actions.mapmode.SelectAction.Mode;28 26 import org.openstreetmap.josm.command.AddCommand; 29 27 import org.openstreetmap.josm.command.ChangeCommand; … … 43 41 */ 44 42 public class DrawAction extends MapMode { 43 44 private static Node lastUsedNode = null; 45 45 46 46 public DrawAction(MapFrame mapFrame) { … … 52 52 KeyStroke.getKeyStroke(KeyEvent.VK_N, 0), tr("Draw")); 53 53 54 // Add extra shortcut U 55 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 56 KeyStroke.getKeyStroke(KeyEvent.VK_U, 0), tr("Unselect All")); 57 54 58 //putValue("help", "Action/AddNode/Autnode"); 55 59 } … … 94 98 boolean newNode = false; 95 99 Node n = null; 96 if (!ctrl) n = Main.map.mapView.getNearestNode(e.getPoint()); 97 if (n == null) { 100 if (!ctrl) { 101 n = Main.map.mapView.getNearestNode(e.getPoint()); 102 } 103 104 if (n != null) { 105 // user clicked on node 106 if (selection.isEmpty()) { 107 // select the clicked node and do nothing else 108 // (this is just a convenience option so that people don't 109 // have to switch modes) 110 Main.ds.setSelected(n); 111 return; 112 } 113 114 } else { 115 // no node found in clicked area 98 116 n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY())); 99 117 if (n.coor.isOutSideWorld()) { … … 143 161 } 144 162 } 163 164 // This part decides whether or not a "segment" (i.e. a connection) is made to an 165 // existing node. 166 167 // For a connection to be made, the user must either have a node selected (connection 168 // is made to that node), or he must have a way selected *and* one of the endpoints 169 // of that way must be the last used node (connection is made to last used node), or 170 // he must have a way and a node selected (connection is made to the selected node). 171 145 172 boolean extendedWay = false; 146 // shift modifier never connects, just makes new node 147 if (!shift && selection.size() == 1 && selection.iterator().next() instanceof Node) { 148 Node n0 = (Node) selection.iterator().next(); 149 if (n0 == n) { 173 174 if (!shift && selection.size() > 0 && selection.size() < 3) { 175 176 Node selectedNode = null; 177 Way selectedWay = null; 178 179 for (OsmPrimitive p : selection) { 180 if (p instanceof Node) { 181 if (selectedNode != null) return; 182 selectedNode = (Node) p; 183 } else if (p instanceof Way) { 184 if (selectedWay != null) return; 185 selectedWay = (Way) p; 186 } 187 } 188 189 // the node from which we make a connection 190 Node n0 = null; 191 192 if (selectedNode == null) { 193 if (selectedWay == null) return; 194 if (lastUsedNode == selectedWay.nodes.get(0) || lastUsedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) { 195 n0 = lastUsedNode; 196 } 197 } else if (selectedWay == null) { 198 n0 = selectedNode; 199 } else { 200 if (selectedNode == selectedWay.nodes.get(0) || selectedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) { 201 n0 = selectedNode; 202 } 203 } 204 205 if (n0 == null || n0 == n) { 150 206 return; // Don't create zero length way segments. 151 207 } 152 208 153 // alt modifier makes connection to selected node but not existing way 154 Way way = alt ? null : getWayForNode(n0); 209 // Ok we know now that we'll insert a line segment, but will it connect to an 210 // existing way or make a new way of its own? The "alt" modifier means that the 211 // user wants a new way. 212 213 Way way = alt ? null : (selectedWay != null) ? selectedWay : getWayForNode(n0); 155 214 if (way == null) { 156 215 way = new Way(); … … 175 234 176 235 extendedWay = true; 236 Main.ds.setSelected(way); 177 237 } 178 238 … … 186 246 title = tr("Add node into way"); 187 247 } 248 Main.ds.setSelected(n); 188 249 } else if (!newNode) { 189 250 title = tr("Connect existing way to node"); … … 197 258 198 259 Main.main.undoRedo.add(c); 199 Main.ds.setSelected(n);260 lastUsedNode = n; 200 261 Main.map.mapView.repaint(); 201 262 }
Note:
See TracChangeset
for help on using the changeset viewer.