Changeset 34217 in osm for applications/editors/josm/plugins
- Timestamp:
- 2018-05-24T14:13:24+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/DoubleSplitAction.java
r34182 r34217 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Color; 6 7 import java.awt.Cursor; 8 import java.awt.Graphics2D; 7 9 import java.awt.GridBagLayout; 10 import java.awt.Point; 8 11 import java.awt.event.ActionEvent; 9 12 import java.awt.event.ActionListener; 13 import java.awt.event.KeyEvent; 14 import java.awt.event.KeyListener; 10 15 import java.awt.event.MouseEvent; 11 16 import java.util.ArrayList; … … 15 20 import java.util.List; 16 21 import java.util.Set; 17 import java.util.concurrent.atomic.AtomicInteger;18 22 19 23 import javax.swing.DefaultComboBoxModel; … … 28 32 import org.openstreetmap.josm.command.ChangeCommand; 29 33 import org.openstreetmap.josm.command.Command; 34 import org.openstreetmap.josm.command.SequenceCommand; 30 35 //import org.openstreetmap.josm.command.Command; 31 36 import org.openstreetmap.josm.command.SplitWayCommand; 37 import org.openstreetmap.josm.data.Bounds; 38 import org.openstreetmap.josm.data.coor.ILatLon; 39 import org.openstreetmap.josm.data.coor.LatLon; 32 40 import org.openstreetmap.josm.data.osm.Node; 33 41 import org.openstreetmap.josm.data.osm.OsmPrimitive; 42 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 43 import org.openstreetmap.josm.data.osm.Relation; 44 import org.openstreetmap.josm.data.osm.RelationMember; 34 45 import org.openstreetmap.josm.data.osm.TagMap; 35 46 import org.openstreetmap.josm.data.osm.Way; … … 37 48 import org.openstreetmap.josm.gui.ExtendedDialog; 38 49 import org.openstreetmap.josm.gui.MainApplication; 50 import org.openstreetmap.josm.gui.MapView; 51 import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable; 52 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 53 import org.openstreetmap.josm.tools.CheckParameterUtil; 39 54 import org.openstreetmap.josm.tools.GBC; 40 55 import org.openstreetmap.josm.tools.ImageProvider; … … 46 61 * @author Biswesh 47 62 */ 48 public class DoubleSplitAction extends MapMode {63 public class DoubleSplitAction extends MapMode implements KeyListener { 49 64 50 65 private static final String MAP_MODE_NAME = "Double Split"; … … 52 67 private transient Set<OsmPrimitive> newHighlights = new HashSet<>(); 53 68 private transient Set<OsmPrimitive> oldHighlights = new HashSet<>(); 54 private int nodeCount = 0;55 69 private List<Node> atNodes = new ArrayList<>(); 56 private Way previousAffectedWay; 70 private final DoubleSplitLayer temporaryLayer = new DoubleSplitLayer(); 71 ILatLon Pos1 = null; 72 ILatLon Pos2 = null; 73 Way SegWay1 = null; 74 Way SegWay2 = null; 75 Way affected; 76 Way previousAffectedWay; 57 77 58 78 private final Cursor cursorJoinNode; … … 64 84 public DoubleSplitAction() { 65 85 super(tr(MAP_MODE_NAME), "logo_double_split", tr(MAP_MODE_NAME), null, getCursor()); 66 67 86 cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode"); 68 87 cursorJoinWay = ImageProvider.getCursor("crosshair", "joinway"); 88 69 89 } 70 90 71 91 private static Cursor getCursor() { 72 Cursor cursor = ImageProvider.getCursor("crosshair", "bus"); 73 if (cursor == null) 74 cursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); 92 Cursor cursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); 75 93 return cursor; 76 94 } … … 81 99 MainApplication.getMap().mapView.addMouseListener(this); 82 100 MainApplication.getMap().mapView.addMouseMotionListener(this); 101 MainApplication.getMap().mapView.addKeyListener(this); 102 MainApplication.getMap().mapView.addTemporaryLayer(temporaryLayer); 83 103 } 84 104 85 105 @Override 86 106 public void exitMode() { 87 // if we have one node selected and we exit the mode then undo the node 88 if (nodeCount == 1) { 89 for (int i = 0; i < 2; i++) { 90 MainApplication.undoRedo.undo(); 91 } 92 nodeCount = 0; 93 atNodes.clear(); 94 previousAffectedWay = null; 95 updateHighlights(); 96 } 107 reset(); 97 108 super.exitMode(); 98 109 MainApplication.getMap().mapView.removeMouseListener(this); 99 110 MainApplication.getMap().mapView.removeMouseMotionListener(this); 111 MainApplication.getMap().mapView.removeKeyListener(this); 112 MainApplication.getMap().mapView.removeTemporaryLayer(temporaryLayer); 113 resetLayer(); 100 114 } 101 115 102 116 private void reset() { 103 nodeCount = 0; 104 atNodes.clear(); 105 previousAffectedWay = null; 106 updateHighlights(); 107 } 108 109 private boolean startEndPoints(){ 110 if (atNodes.get(0).isConnectionNode() && atNodes.get(1).isConnectionNode()) { 117 try { 118 atNodes.clear(); 119 updateHighlights(); 120 } catch (Exception e) { 121 e.printStackTrace(); 122 } 123 System.out.println("reset"); 124 } 125 126 private void resetLayer() { 127 Pos1 = null; 128 Pos2 = null; 129 SegWay1 = null; 130 SegWay2 = null; 131 } 132 133 private boolean startEndPoints(List<Command> commandList) { 134 135 try { 111 136 for (Way way : atNodes.get(0).getParentWays()) { 112 137 if (atNodes.get(1).getParentWays().contains(way)) { 113 List<TagMap> affectedKeysList = new ArrayList<>(); 114 affectedKeysList.add(way.getKeys()); 115 newHighlights.add(way); 116 dialogBox(Arrays.asList(way), affectedKeysList); 117 return true; 138 if (way.isFirstLastNode(atNodes.get(0)) && way.isFirstLastNode(atNodes.get(1))) { 139 List<TagMap> affectedKeysList = new ArrayList<>(); 140 affectedKeysList.add(way.getKeys()); 141 newHighlights.add(way); 142 dialogBox(3, null, way, way, commandList); 143 return true; 144 } 118 145 } 119 146 } 120 121 reset();122 return true;123 } 147 } catch (Exception e) { 148 e.printStackTrace(); 149 } 150 124 151 return false; 125 152 } 126 153 127 private boolean firstNodeIsConnectionNode(Node node, Way affected ) {154 private boolean firstNodeIsConnectionNode(Node node, Way affected, Way previousAffectedWay) { 128 155 if (node.isConnectionNode()) { 129 156 if (node.getParentWays().contains(affected)) 130 157 previousAffectedWay = affected; 131 158 else { 132 reset();133 159 return true; 134 160 } … … 137 163 } 138 164 139 private boolean secondNodeIsConnectionNode(Node node ) {165 private boolean secondNodeIsConnectionNode(Node node, Way previousAffectedWay) { 140 166 if (atNodes.get(1).isConnectionNode()) { 141 167 if (atNodes.get(1).getParentWays().contains(previousAffectedWay)) 142 168 return false; 143 169 else { 144 reset();145 170 return true; 146 171 } … … 149 174 } 150 175 151 private Node checkCommonNode(Way affected ) {152 153 176 private Node checkCommonNode(Way affected, Way previousAffectedWay) { 177 178 // check if they have any common node 154 179 List<Node> presentNodeList = affected.getNodes(); 155 180 for (Node previousNode : previousAffectedWay.getNodes()) { … … 158 183 } 159 184 } 160 161 185 return null; 162 186 } 163 187 164 private void removeFirstNode(Way affected) { 165 166 // select the first node 167 Node nodeToBeDeleted = atNodes.get(0); 168 169 if (nodeToBeDeleted != null) { 170 // remove first node from list 171 atNodes.remove(0); 172 173 // remove last 2 commands from command list 174 Command lastCommand = MainApplication.undoRedo.commands.removeLast(); 175 Command secondLastCommand = MainApplication.undoRedo.commands.removeLast(); 176 177 // now we can undo the previous node as the command for present node has been 178 // removed from list 179 for (int i = 0; i < 2; i++) { 180 MainApplication.undoRedo.undo(); 181 } 182 183 // now again add back the last 2 commands, so overall we undo third last and 184 // fourth last command 185 MainApplication.undoRedo.commands.add(secondLastCommand); 186 MainApplication.undoRedo.commands.add(lastCommand); 187 188 MainApplication.undoRedo.redo(); 189 } 190 191 previousAffectedWay = affected; 192 193 } 194 195 private void addKeysOnBothWays(Node commonNode, Way affected) { 188 private void removeFirstNode() { 189 190 atNodes.get(0).setDeleted(true); 191 atNodes.get(1).setDeleted(true); 192 Pos1 = Pos2; 193 Pos2 = null; 194 SegWay1 = SegWay2; 195 SegWay2 = null; 196 reset(); 197 } 198 199 private void action() { 200 201 List<Command> commandList = new ArrayList<>(); 202 203 // check if the user has selected an existing node, or a new one 204 Node node1 = createNode(Pos1, commandList); 205 if (node1 == null) { 206 resetLayer(); 207 reset(); 208 return; 209 } 210 Node node2 = createNode(Pos2, commandList); 211 if (node2 == null) { 212 node1.setDeleted(true); 213 Pos2 = null; 214 SegWay2 = null; 215 reset(); 216 return; 217 } 218 219 if (node1.equals(node2)) { 220 resetLayer(); 221 return; 222 } 223 224 atNodes.add(node1); 225 atNodes.add(node2); 226 227 previousAffectedWay = SegWay1; 228 affected = SegWay2; 229 230 if (affected == null || previousAffectedWay == null) { 231 node1.setDeleted(true); 232 node2.setDeleted(true); 233 resetLayer(); 234 return; 235 } 236 237 // if both the nodes are starting and ending points of the same way 238 // we don't split the way, just add new key-value to the way 239 boolean areStartEndPoints = startEndPoints(commandList); 240 if (areStartEndPoints) { 241 resetLayer(); 242 return; 243 } 244 245 // if first node is a connection node 246 boolean isConnectionNode = firstNodeIsConnectionNode(atNodes.get(0), affected, previousAffectedWay); 247 if (isConnectionNode) { 248 resetLayer(); 249 return; 250 } 251 252 // if second node is a connection node 253 isConnectionNode = secondNodeIsConnectionNode(atNodes.get(1), previousAffectedWay); 254 if (isConnectionNode) { 255 resetLayer(); 256 return; 257 } else { 258 if (atNodes.get(1).isConnectionNode()) { 259 affected = previousAffectedWay; 260 } 261 } 262 263 // if both the nodes are not on same way and don't have any common node then 264 // make second node as first node 265 Node commonNode = null; 266 boolean twoWaysWithCommonNode = false; 267 if (previousAffectedWay != affected) { 268 commonNode = checkCommonNode(affected, previousAffectedWay); 269 if (commonNode == null) { 270 removeFirstNode(); 271 return; 272 } else { 273 twoWaysWithCommonNode = true; 274 } 275 } 276 277 if (twoWaysWithCommonNode) { 278 dialogBox(1, commonNode, affected, previousAffectedWay, commandList); 279 } else { 280 dialogBox(2, commonNode, affected, previousAffectedWay, commandList); 281 } 282 } 283 284 private void dialogBox(int type, Node commonNode, Way affected, Way previousAffectedWay, 285 List<Command> commandList) { 286 287 final ExtendedDialog dialog = new SelectFromOptionDialog(type, commonNode, affected, previousAffectedWay, 288 commandList, atNodes); 289 dialog.toggleEnable("way.split.segment-selection-dialog"); 290 if (!dialog.toggleCheckState()) { 291 dialog.setModal(false); 292 dialog.showDialog(); 293 return; // splitting is performed in SegmentToKeepSelectionDialog.buttonAction() 294 } 295 296 } 297 298 private Node createNode(ILatLon Pos, List<Command> commandList) { 299 Boolean newNode = false; 300 Node newStopPos; 301 302 Point p = new Point(); 303 p.setLocation(Pos.lat(), Pos.lon()); 304 305 Node n = MainApplication.getMap().mapView.getNearestNode(p, OsmPrimitive::isUsable); 306 if (n == null) { 307 newNode = true; 308 newStopPos = new Node(MainApplication.getMap().mapView.getLatLon(Pos.lat(), Pos.lon())); 309 } else { 310 newStopPos = new Node(n); 311 } 312 313 if (newNode) { 314 commandList.add(new AddCommand(getLayerManager().getEditDataSet(), newStopPos)); 315 } else { 316 commandList.add(new ChangeCommand(n, newStopPos)); 317 MainApplication.getLayerManager().getEditLayer().data.setSelected(newStopPos); 318 newStopPos = n; 319 } 320 321 return newStopPos; 322 } 323 324 private void addKeys(Way affected, List<Command> commandList, JComboBox<String> keys, JComboBox<String> values) { 196 325 List<TagMap> affectedKeysList = new ArrayList<>(); 326 Way selectedWay = null; 327 328 MainApplication.undoRedo.add(new SequenceCommand("Add Nodes", commandList)); 329 commandList.clear(); 330 331 addParentWay(atNodes.get(0)); 332 addParentWay(atNodes.get(1)); 333 334 SplitWayCommand result = SplitWayCommand.split(affected, atNodes, Collections.emptyList()); 335 if (result == null) 336 return; 337 338 commandList.add(result); 339 MainApplication.undoRedo.add(new SequenceCommand("Split Way", commandList)); 340 341 // Find the middle way after split 342 List<Way> affectedWayList = result.getNewWays(); 343 affectedWayList.add(result.getOriginalWay()); 344 345 for (Way way : affectedWayList) { 346 if (atNodes.contains(way.firstNode()) && atNodes.contains(way.lastNode())) { 347 selectedWay = way; 348 break; 349 } 350 } 351 352 if (selectedWay != null) { 353 affectedKeysList.add(affected.getKeys()); 354 addTags(affectedKeysList, Arrays.asList(selectedWay), keys, values); 355 } 356 } 357 358 private void addKeysOnBothWays(Node commonNode, Way affected, Way previousAffectedWay, List<Command> commandList, 359 JComboBox<String> keys, JComboBox<String> values) { 360 List<TagMap> affectedKeysList = new ArrayList<>(); 361 362 MainApplication.undoRedo.add(new SequenceCommand("Add Nodes", commandList)); 363 commandList.clear(); 364 365 // join newly created nodes to parent ways 366 addParentWay(atNodes.get(0)); 367 addParentWay(atNodes.get(1)); 197 368 198 369 List<Node> nodelist1 = Arrays.asList(atNodes.get(0), commonNode); 199 370 List<Node> nodelist2 = Arrays.asList(atNodes.get(1), commonNode); 200 371 372 // required to be added to newly split way 201 373 affectedKeysList.add(previousAffectedWay.getKeys()); 202 374 affectedKeysList.add(affected.getKeys()); 203 375 204 376 // split both the ways separately 205 206 377 SplitWayCommand result1 = SplitWayCommand.split(previousAffectedWay, nodelist1, Collections.emptyList()); 207 208 378 SplitWayCommand result2 = SplitWayCommand.split(affected, nodelist2, Collections.emptyList()); 209 379 210 MainApplication.undoRedo.add(result1); 211 MainApplication.undoRedo.add(result2); 380 if (result1 != null) 381 commandList.add(result1); 382 if (result2 != null) 383 commandList.add(result2); 384 MainApplication.undoRedo.add(new SequenceCommand("Split Way", commandList)); 385 386 // add newly split way to relations 387 List<Relation> referrers1 = OsmPrimitive.getFilteredList(previousAffectedWay.getReferrers(), Relation.class); 388 referrers1.removeIf(r -> !RouteUtils.isPTRoute(r)); 389 390 int Index1 = getIndex(previousAffectedWay, referrers1, previousAffectedWay); 391 392 List<Relation> referrers2 = OsmPrimitive.getFilteredList(affected.getReferrers(), Relation.class); 393 referrers2.removeIf(r -> !RouteUtils.isPTRoute(r)); 394 395 int Index2 = getIndex(affected, referrers2, previousAffectedWay); 212 396 213 397 Way way1 = null, way2 = null; … … 217 401 boolean isOriginalWay = true; // we check both the original way and new ways 218 402 for (Way way : result1.getNewWays()) { 403 checkMembership(way, referrers1, Index1); 219 404 if (way.containsNode(commonNode) && way.containsNode(atNodes.get(0))) { 220 405 way1 = way; … … 223 408 } 224 409 } 410 411 checkMembership(result1.getOriginalWay(), referrers1, Index1); 412 225 413 if (isOriginalWay) { 226 414 Way way = result1.getOriginalWay(); … … 234 422 235 423 for (Way way : result2.getNewWays()) { 424 checkMembership(way, referrers2, Index2); 236 425 if (way.containsNode(commonNode) && way.containsNode(atNodes.get(1))) { 237 426 way2 = way; … … 241 430 } 242 431 432 checkMembership(result2.getOriginalWay(), referrers2, Index2); 433 243 434 if (isOriginalWay) { 244 435 Way way = result2.getOriginalWay(); … … 250 441 if (way1 != null && way2 != null) { 251 442 List<Way> selectedWays = Arrays.asList(way1, way2); 252 newHighlights.add(way1); 253 newHighlights.add(way2); 254 dialogBox(selectedWays, affectedKeysList); 255 } 256 } 257 258 private void addKeys(Way affected) { 443 addTags(affectedKeysList, selectedWays, keys, values); 444 } 445 } 446 447 private void addKeysWhenStartEndPoint(Way affected, List<Command> commandList, JComboBox<String> keys, 448 JComboBox<String> values) { 259 449 List<TagMap> affectedKeysList = new ArrayList<>(); 260 Way selectedWay = null; 261 262 SplitWayCommand result = SplitWayCommand.split(affected, atNodes, Collections.emptyList()); 263 if (result == null) 264 return; 265 266 MainApplication.undoRedo.add(result); 267 268 // Find the middle way after split 269 List<Way> affectedWayList = result.getNewWays(); 270 for (Way way : affectedWayList) { 271 if (atNodes.contains(way.firstNode()) && atNodes.contains(way.lastNode())) { 272 selectedWay = way; 273 break; 274 } 275 } 450 Way selectedWay = affected; 451 452 MainApplication.undoRedo.add(new SequenceCommand("Add Nodes", commandList)); 453 commandList.clear(); 454 455 addParentWay(atNodes.get(0)); 456 addParentWay(atNodes.get(1)); 276 457 277 458 if (selectedWay != null) { 278 459 affectedKeysList.add(affected.getKeys()); 279 newHighlights.add(selectedWay); 280 dialogBox(Arrays.asList(selectedWay), affectedKeysList); 281 } 460 addTags(affectedKeysList, Arrays.asList(selectedWay), keys, values); 461 } 462 } 463 464 private void addParentWay(Node node) { 465 if (node.getParentWays().size() == 0) { 466 MainApplication.getLayerManager().getEditLayer().data.setSelected(node); 467 // join the node to the way only if the node is new 468 JoinNodeWayAction joinNodeWayAction = JoinNodeWayAction.createMoveNodeOntoWayAction(); 469 joinNodeWayAction.actionPerformed(null); 470 } 471 } 472 473 private void checkMembership(Way way, List<Relation> referrers, int Index) { 474 for (Relation r : referrers) { 475 boolean isMember = false; 476 for (RelationMember rm : r.getMembers()) { 477 if (rm.getType() == OsmPrimitiveType.WAY) { 478 if (rm.getWay().equals(way)) { 479 isMember = true; 480 } 481 } 482 } 483 if (!isMember) { 484 r.addMember(new RelationMember("", way)); 485 } 486 } 487 } 488 489 private int getIndex(Way way, List<Relation> referrers, Way previousAffectedWay) { 490 int Index = -1; 491 for (Relation r : referrers) { 492 for (int i = 0; i < r.getMembers().size(); i++) { 493 if (r.getMembers().get(i).isWay() && r.getMembers().get(i).getWay().equals(previousAffectedWay)) { 494 Index = i; 495 } 496 } 497 } 498 return Index; 499 } 500 501 private void addTags(List<TagMap> affectedKeysList, List<Way> selectedWay, JComboBox<String> keys, 502 JComboBox<String> values) { 503 TagMap newKeys1 = affectedKeysList.get(0); 504 newKeys1.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 505 506 if (keys.getSelectedItem() == "bridge") { 507 newKeys1.put("layer", "1"); 508 selectedWay.get(0).setKeys(newKeys1); 509 } else if (keys.getSelectedItem() == "tunnel") { 510 newKeys1.put("layer", "-1"); 511 selectedWay.get(0).setKeys(newKeys1); 512 } else { 513 selectedWay.get(0).setKeys(newKeys1); 514 } 515 516 if (affectedKeysList.size() == 2) { 517 TagMap newKeys2 = affectedKeysList.get(1); 518 newKeys2.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 519 520 if (keys.getSelectedItem() == "bridge") { 521 newKeys2.put("layer", "1"); 522 selectedWay.get(1).setKeys(newKeys2); 523 } else if (keys.getSelectedItem() == "tunnel") { 524 newKeys2.put("layer", "-1"); 525 selectedWay.get(1).setKeys(newKeys2); 526 } else { 527 selectedWay.get(1).setKeys(newKeys2); 528 } 529 } 530 resetLayer(); 282 531 } 283 532 … … 313 562 public void mouseClicked(MouseEvent e) { 314 563 315 Boolean newNode = false; 316 Node newStopPos; 317 318 // check if the user has selected an existing node, or a new one 319 Node n = MainApplication.getMap().mapView.getNearestNode(e.getPoint(), OsmPrimitive::isUsable); 320 if (n == null) { 321 newNode = true; 322 newStopPos = new Node(MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY())); 323 } else { 324 newStopPos = new Node(n); 325 } 326 327 if (newNode) { 328 MainApplication.undoRedo.add(new AddCommand(getLayerManager().getEditDataSet(), newStopPos)); 329 } else { 330 MainApplication.undoRedo.add(new ChangeCommand(n, newStopPos)); 331 newStopPos = n; 332 } 333 334 MainApplication.getLayerManager().getEditLayer().data.setSelected(newStopPos); 335 336 // join the node to the way only if the node is new 337 if (newNode) { 338 JoinNodeWayAction joinNodeWayAction = JoinNodeWayAction.createMoveNodeOntoWayAction(); 339 joinNodeWayAction.actionPerformed(null); 340 } 341 342 if (newStopPos.getParentWays().isEmpty()) 343 return; 344 345 Way affected = newStopPos.getParentWays().get(0); 346 347 if (affected == null) 348 return; 349 350 atNodes.add(newStopPos); 351 352 // to check the number of nodes that have been selected 353 // do not split if this is the first selected node 354 if (nodeCount == 0) { 355 previousAffectedWay = affected; 356 nodeCount++; 357 return; 358 } 359 360 // if both the nodes are starting and ending points of the same way 361 // we don't split the way, just add new key-value to the way 362 boolean areStartEndPoints = startEndPoints(); 363 if (areStartEndPoints) 364 return; 365 366 // if first node is a connection node 367 boolean isConnectionNode = firstNodeIsConnectionNode(atNodes.get(0), affected); 368 if (isConnectionNode) 369 return; 370 371 // if second node is a connection node 372 isConnectionNode = secondNodeIsConnectionNode(atNodes.get(1)); 373 if (isConnectionNode) 374 return; 375 else { 376 if (atNodes.get(1).isConnectionNode()) { 377 affected = previousAffectedWay; 378 } 379 } 380 381 382 // if both the nodes are not on same way and don't have any common node then 383 // make second node as first node 384 Node commonNode = null; 385 boolean twoWaysWithCommonNode = false; 386 if (previousAffectedWay != affected) { 387 commonNode = checkCommonNode(affected); 388 if (commonNode == null) { 389 removeFirstNode(affected); 390 return; 391 } else { 392 twoWaysWithCommonNode = true; 393 } 394 } 395 396 397 // ****need to add undoredo for previousAffectedWay, atNode, nodeCount 398 399 if (twoWaysWithCommonNode) { 400 addKeysOnBothWays(commonNode, affected); 401 402 } else { 403 addKeys(affected); 404 } 405 406 // reset values of all the variables after two nodes are selected and split 407 reset(); 408 409 } 410 411 private void dialogBox(List<Way> selectedWay, List<TagMap> affectedKeysList) { 412 413 final ExtendedDialog dialog = new SelectFromOptionDialog(selectedWay, affectedKeysList); 414 dialog.toggleEnable("way.split.segment-selection-dialog"); 415 if (!dialog.toggleCheckState()) { 416 dialog.setModal(false); 417 dialog.showDialog(); 418 return; // splitting is performed in SegmentToKeepSelectionDialog.buttonAction() 419 } 420 564 if (Pos1 == null) { 565 SegWay1 = MainApplication.getMap().mapView.getNearestWay(e.getPoint(), OsmPrimitive::isSelectable); 566 if (SegWay1 != null) { 567 Pos1 = new LatLon(e.getX(), e.getY()); 568 } 569 } else if (Pos2 == null) { 570 if (Pos1.lat() != e.getX() || Pos1.lon() != e.getY()) { 571 SegWay2 = MainApplication.getMap().mapView.getNearestWay(e.getPoint(), OsmPrimitive::isSelectable); 572 if (SegWay2 != null) 573 Pos2 = new LatLon(e.getX(), e.getY()); 574 } 575 } 576 577 if (Pos2 != null) { 578 reset(); 579 action(); 580 } 421 581 } 422 582 423 583 // turn off what has been highlighted on last mouse move and highlight what has 424 584 // to be highlighted now 425 426 private void updateHighlights() { 585 private void updateHighlights() { 427 586 if (oldHighlights.isEmpty() && newHighlights.isEmpty()) { 428 587 return; … … 444 603 } 445 604 605 @Override 606 public void keyTyped(KeyEvent e) { 607 System.out.println("keyTyped"); 608 } 609 610 @Override 611 public void keyPressed(KeyEvent e) { 612 System.out.println("keyPressed"); 613 boolean z = e.getKeyCode() == KeyEvent.VK_Z; 614 updateKeyModifiers(e); 615 System.out.println(ctrl); 616 if (z) { 617 if (Pos1 != null && Pos2 == null) { 618 Pos1 = null; 619 SegWay1 = null; 620 temporaryLayer.invalidate(); 621 } 622 } 623 } 624 625 @Override 626 public void keyReleased(KeyEvent e) { 627 System.out.println("keyReleased"); 628 } 629 446 630 // A dialogBox to query whether to select bus_bay, tunnel or bridge. 447 631 448 static class SelectFromOptionDialog extends ExtendedDialog { 449 static final AtomicInteger DISPLAY_COUNT = new AtomicInteger(); 450 final transient List<Way> selectedWay; 632 private class SelectFromOptionDialog extends ExtendedDialog { 633 Way affected, previousAffectedWay; 451 634 private JComboBox<String> keys; 452 635 private JComboBox<String> values; 453 private List<TagMap> affectedKeysList; 454 455 SelectFromOptionDialog(List<Way> selectedWay, List<TagMap> affectedKeysList) { 636 private int type; 637 private List<Command> commandList; 638 private Node commonNode; 639 640 SelectFromOptionDialog(int type, Node commonNode, Way affected, Way previousAffectedWay, 641 List<Command> commandList, List<Node> atNode) { 456 642 super(Main.parent, tr("What do you want the segment to be?"), new String[] { tr("Ok"), tr("Cancel") }, 457 643 true); 458 this.selectedWay = selectedWay; 459 this.affectedKeysList = affectedKeysList; 644 this.affected = affected; 645 this.previousAffectedWay = previousAffectedWay; 646 this.commandList = commandList; 647 this.type = type; 648 this.commonNode = commonNode; 460 649 461 650 setButtonIcons("ok", "cancel"); … … 499 688 500 689 if (getValue() == 1) { 501 TagMap newKeys1 = this.affectedKeysList.get(0); 502 newKeys1.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 503 504 if (keys.getSelectedItem() == "bridge") { 505 newKeys1.put("layer", "1"); 506 this.selectedWay.get(0).setKeys(newKeys1); 507 } else if (keys.getSelectedItem() == "tunnel") { 508 newKeys1.put("layer", "-1"); 509 this.selectedWay.get(0).setKeys(newKeys1); 510 } else { 511 this.selectedWay.get(0).setKeys(newKeys1); 690 if (this.type == 1) { 691 addKeysOnBothWays(this.commonNode, this.affected, this.previousAffectedWay, this.commandList, keys, 692 values); 693 } else if (this.type == 2) { 694 addKeys(this.affected, this.commandList, keys, values); 695 } else if (this.type == 3) { 696 addKeysWhenStartEndPoint(this.affected, this.commandList, keys, values); 512 697 } 513 698 514 if (this.affectedKeysList.size() == 2) { 515 TagMap newKeys2 = this.affectedKeysList.get(1); 516 newKeys2.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 517 518 if (keys.getSelectedItem() == "bridge") { 519 newKeys2.put("layer", "1"); 520 this.selectedWay.get(1).setKeys(newKeys2); 521 } else if (keys.getSelectedItem() == "tunnel") { 522 newKeys2.put("layer", "-1"); 523 this.selectedWay.get(1).setKeys(newKeys2); 524 } else { 525 this.selectedWay.get(1).setKeys(newKeys2); 526 } 527 } 528 } 529 } 530 } 699 } else if (getValue() == 2) { 700 resetLayer(); 701 } 702 } 703 704 } 705 706 private class DoubleSplitLayer extends AbstractMapViewPaintable { 707 @Override 708 public void paint(Graphics2D g, MapView mv, Bounds bbox) { 709 if (Pos1 != null) { 710 CheckParameterUtil.ensureParameterNotNull(mv, "mv"); 711 g.setColor(Color.RED); 712 g.fillRect((int) Pos1.lat(), (int) Pos1.lon(), 6, 6); 713 } 714 if (Pos2 != null) { 715 CheckParameterUtil.ensureParameterNotNull(mv, "mv"); 716 g.setColor(Color.RED); 717 g.fillRect((int) Pos2.lat(), (int) Pos2.lon(), 5, 5); 718 } 719 } 720 } 721 531 722 }
Note:
See TracChangeset
for help on using the changeset viewer.