Changeset 34182 in osm for applications/editors
- Timestamp:
- 2018-05-10T08:58:51+02:00 (6 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
r34138 r34182 41 41 42 42 /** 43 * The DoubleSplitAction is a mapmode that allows users to add 44 * a bus_bay,abridge or a tunnel .43 * The DoubleSplitAction is a mapmode that allows users to add a bus_bay,a 44 * bridge or a tunnel . 45 45 * 46 46 * @author Biswesh … … 48 48 public class DoubleSplitAction extends MapMode { 49 49 50 private static final String MAP_MODE_NAME = "Double Split"; 51 52 private transient Set<OsmPrimitive> newHighlights = new HashSet<>(); 53 private transient Set<OsmPrimitive> oldHighlights = new HashSet<>(); 54 private int nodeCount = 0; 55 private List<Node> atNodes = new ArrayList<>(); 56 private Way previousAffectedWay; 57 58 private final Cursor cursorJoinNode; 59 private final Cursor cursorJoinWay; 60 61 /** 62 * Creates a new DoubleSplitAction 63 */ 64 public DoubleSplitAction() { 65 super(tr(MAP_MODE_NAME), "bus", tr(MAP_MODE_NAME), 66 null, getCursor()); 67 68 cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode"); 69 cursorJoinWay = ImageProvider.getCursor("crosshair", "joinway"); 70 } 71 72 private static Cursor getCursor() { 73 Cursor cursor = ImageProvider.getCursor("crosshair", "bus"); 74 if (cursor == null) 75 cursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); 76 return cursor; 77 } 78 79 @Override 80 public void enterMode() { 81 super.enterMode(); 82 MainApplication.getMap().mapView.addMouseListener(this); 83 MainApplication.getMap().mapView.addMouseMotionListener(this); 84 } 85 86 @Override 87 public void exitMode() { 88 // if we have one node selected and we exit the mode then undo the node 89 if (nodeCount == 1) { 90 for(int i=0;i<2;i++) { 91 MainApplication.undoRedo.undo(); 92 } 93 nodeCount = 0; 94 atNodes.clear(); 95 previousAffectedWay = null; 96 updateHighlights(); 97 } 98 super.exitMode(); 99 MainApplication.getMap().mapView.removeMouseListener(this); 100 MainApplication.getMap().mapView.removeMouseMotionListener(this); 101 } 102 103 @Override 104 public void mouseMoved(MouseEvent e) { 105 106 //while the mouse is moving, surroundings are checked 107 //if anything is found, it will be highlighted. 108 //priority is given to nodes 109 Cursor newCurs = getCursor(); 110 111 Node n = MainApplication.getMap().mapView.getNearestNode(e.getPoint(), OsmPrimitive::isUsable); 112 if (n != null) { 113 newHighlights.add(n); 114 newCurs = cursorJoinNode; 115 } else { 116 List<WaySegment> wss = 117 MainApplication.getMap().mapView.getNearestWaySegments(e.getPoint(), OsmPrimitive::isSelectable); 118 119 if (!wss.isEmpty()) { 120 for (WaySegment ws : wss) { 121 newHighlights.add(ws.way); 122 } 123 newCurs = cursorJoinWay; 124 } 125 } 126 127 MainApplication.getMap().mapView.setCursor(newCurs); 128 updateHighlights(); 129 } 130 131 @Override 132 public void mouseClicked(MouseEvent e) { 133 134 Boolean newNode = false; 135 Node newStopPos; 136 137 //check if the user as selected an existing node, or a new one 138 Node n = MainApplication.getMap().mapView.getNearestNode(e.getPoint(), OsmPrimitive::isUsable); 139 if (n == null) { 140 newNode = true; 141 newStopPos = new Node(MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY())); 142 } else { 143 newStopPos = new Node(n); 144 } 145 146 147 if (newNode) { 148 MainApplication.undoRedo.add(new AddCommand(getLayerManager().getEditDataSet(), newStopPos)); 149 } else { 150 MainApplication.undoRedo.add(new ChangeCommand(n, newStopPos)); 151 newStopPos = n; 152 } 153 154 MainApplication.getLayerManager().getEditLayer().data.setSelected(newStopPos); 155 156 //join the node to the way only if the node is new 157 if (newNode) { 158 JoinNodeWayAction joinNodeWayAction = JoinNodeWayAction.createMoveNodeOntoWayAction(); 159 joinNodeWayAction.actionPerformed(null); 160 } 161 162 if (newStopPos.getParentWays().isEmpty()) 163 return; 164 165 Way affected = newStopPos.getParentWays().get(0); 166 167 if (affected == null) 168 return; 169 170 atNodes.add(newStopPos); 171 172 // to check the number of nodes that have been selected 173 // do not split if this is the first selected node 174 if (nodeCount == 0) { 175 previousAffectedWay = affected; 176 nodeCount++; 177 return; 178 } 179 180 181 // if both the nodes are starting and ending points of the same way 182 // we don't split the way, just add new key-value to the way 183 if (atNodes.get(0).isConnectionNode() && atNodes.get(1).isConnectionNode()) { 184 for (Way way : atNodes.get(0).getParentWays()) { 185 if ( atNodes.get(1).getParentWays().contains(way)) { 186 List<TagMap> affectedKeysList = new ArrayList<>(); 187 affectedKeysList.add(way.getKeys()); 188 newHighlights.add(way); 189 dialogBox(Arrays.asList(way), affectedKeysList); 190 return; 191 } 192 } 193 nodeCount = 0; 194 atNodes.clear(); 195 previousAffectedWay = null; 196 updateHighlights(); 197 return; 198 } 199 200 // if first node is a connection node 201 if (atNodes.get(0).isConnectionNode()) { 202 if (atNodes.get(0).getParentWays().contains(affected)) 203 previousAffectedWay = affected; 204 else { 205 nodeCount = 0; 206 atNodes.clear(); 207 previousAffectedWay = null; 208 updateHighlights(); 209 return; 210 } 211 } 212 213 // if second node is a connection node 214 if (atNodes.get(1).isConnectionNode()) { 215 if (atNodes.get(1).getParentWays().contains(previousAffectedWay)) 216 affected = previousAffectedWay; 217 else { 218 nodeCount = 0; 219 atNodes.clear(); 220 previousAffectedWay = null; 221 updateHighlights(); 222 return; 223 } 224 } 225 226 // if both the nodes are not on same way and don't have any common node then make second node as first node 227 Node commonNode = null; 228 boolean twoWaysWithCommonNode = false; 229 if (previousAffectedWay != affected) { 230 // check if they have any common node 231 boolean canSplit = false; 232 List<Node> presentNodeList = affected.getNodes(); 233 for (Node previousNode : previousAffectedWay.getNodes()) { 234 if (presentNodeList.contains(previousNode)) { 235 canSplit = true; 236 twoWaysWithCommonNode = true; 237 commonNode = previousNode; 238 } 239 } 240 // if no common node 241 if (!canSplit) { 242 // select the first node 243 Node nodeToBeDeleted = atNodes.get(0); 244 245 if (nodeToBeDeleted != null) { 246 // remove first node from list 247 atNodes.remove(0); 248 249 // remove last 2 commands from command list 250 Command lastCommand = MainApplication.undoRedo.commands.removeLast(); 251 Command secondLastCommand = MainApplication.undoRedo.commands.removeLast(); 252 253 // now we can undo the previous node as the command for present node has been removed from list 254 for(int i=0;i<2;i++) { 255 MainApplication.undoRedo.undo(); 256 } 257 258 // now again add back the last 2 commands, so overall we undo third last and fourth last command 259 MainApplication.undoRedo.commands.add(secondLastCommand); 260 MainApplication.undoRedo.commands.add(lastCommand); 261 262 MainApplication.undoRedo.redo(); 263 } 264 previousAffectedWay = affected; 265 return; 266 } 267 } 268 269 // ****need to add undoredo for previousAffectedWay, atNode, nodeCount 270 271 List<TagMap> affectedKeysList = new ArrayList<>(); 272 273 if ( twoWaysWithCommonNode ) { 274 List<Node> nodelist1 = Arrays.asList(atNodes.get(0),commonNode); 275 List<Node> nodelist2 = Arrays.asList(atNodes.get(1),commonNode); 276 277 affectedKeysList.add(previousAffectedWay.getKeys()); 278 affectedKeysList.add(affected.getKeys()); 279 280 // split both the ways separately 281 282 SplitWayCommand result1 = SplitWayCommand.split( 283 previousAffectedWay, nodelist1 , Collections.emptyList()); 284 285 SplitWayCommand result2 = SplitWayCommand.split( 286 affected, nodelist2 , Collections.emptyList()); 287 288 MainApplication.undoRedo.add(result1); 289 MainApplication.undoRedo.add(result2); 290 291 Way way1 = null, way2 = null; 292 293 // Find middle way which is a part of both the ways, so find the 2 ways which together would form middle way 294 boolean isOriginalWay = true; // we check both the original way and new ways 295 for (Way way : result1.getNewWays()) { 296 if (way.containsNode(commonNode) && way.containsNode(atNodes.get(0))) { 297 way1 = way; 298 isOriginalWay = false; 299 break; 300 } 301 } 302 if (isOriginalWay) { 303 Way way = result1.getOriginalWay(); 304 if (way.containsNode(commonNode) && way.containsNode(atNodes.get(0))) { 305 way1 = way; 306 } 307 } 308 309 // now do for 2nd way 310 isOriginalWay = true; 311 312 for (Way way : result2.getNewWays()) { 313 if (way.containsNode(commonNode) && way.containsNode(atNodes.get(1))) { 314 way2 = way; 315 isOriginalWay = false; 316 break; 317 } 318 } 319 320 if (isOriginalWay) { 321 Way way = result2.getOriginalWay(); 322 if (way.containsNode(commonNode) && way.containsNode(atNodes.get(1))) { 323 way2 = way; 324 } 325 } 326 327 if (way1!=null && way2!=null) { 328 List<Way> selectedWays = Arrays.asList(way1, way2); 329 newHighlights.add(way1); 330 newHighlights.add(way2); 331 dialogBox(selectedWays, affectedKeysList); 332 } 333 334 } else { 335 336 Way selectedWay = null; 337 338 SplitWayCommand result = SplitWayCommand.split( 339 affected, atNodes , Collections.emptyList()); 340 if (result == null) 341 return; 342 343 MainApplication.undoRedo.add(result); 344 345 // Find the middle way after split 346 List<Way> affectedWayList = result.getNewWays(); 347 for (Way way : affectedWayList) { 348 if (atNodes.contains(way.firstNode()) && atNodes.contains(way.lastNode())) { 349 selectedWay = way; 350 break; 351 } 352 } 353 354 if (selectedWay != null) { 355 affectedKeysList.add(affected.getKeys()); 356 newHighlights.add(selectedWay); 357 dialogBox(Arrays.asList(selectedWay), affectedKeysList); 358 } 359 } 360 361 // reset values of all the variables after two nodes are selected and split 362 nodeCount = 0; 363 atNodes.clear(); 364 previousAffectedWay = null; 365 updateHighlights(); 366 367 } 368 369 private void dialogBox(List<Way> selectedWay, List<TagMap> affectedKeysList) { 370 371 final ExtendedDialog dialog = new SelectFromOptionDialog(selectedWay, affectedKeysList); 372 dialog.toggleEnable("way.split.segment-selection-dialog"); 373 if (!dialog.toggleCheckState()) { 374 dialog.setModal(false); 375 dialog.showDialog(); 376 return; // splitting is performed in SegmentToKeepSelectionDialog.buttonAction() 377 } 378 379 } 380 381 //turn off what has been highlighted on last mouse move and highlight what has to be highlighted now 50 private static final String MAP_MODE_NAME = "Double Split"; 51 52 private transient Set<OsmPrimitive> newHighlights = new HashSet<>(); 53 private transient Set<OsmPrimitive> oldHighlights = new HashSet<>(); 54 private int nodeCount = 0; 55 private List<Node> atNodes = new ArrayList<>(); 56 private Way previousAffectedWay; 57 58 private final Cursor cursorJoinNode; 59 private final Cursor cursorJoinWay; 60 61 /** 62 * Creates a new DoubleSplitAction 63 */ 64 public DoubleSplitAction() { 65 super(tr(MAP_MODE_NAME), "logo_double_split", tr(MAP_MODE_NAME), null, getCursor()); 66 67 cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode"); 68 cursorJoinWay = ImageProvider.getCursor("crosshair", "joinway"); 69 } 70 71 private static Cursor getCursor() { 72 Cursor cursor = ImageProvider.getCursor("crosshair", "bus"); 73 if (cursor == null) 74 cursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); 75 return cursor; 76 } 77 78 @Override 79 public void enterMode() { 80 super.enterMode(); 81 MainApplication.getMap().mapView.addMouseListener(this); 82 MainApplication.getMap().mapView.addMouseMotionListener(this); 83 } 84 85 @Override 86 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 } 97 super.exitMode(); 98 MainApplication.getMap().mapView.removeMouseListener(this); 99 MainApplication.getMap().mapView.removeMouseMotionListener(this); 100 } 101 102 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()) { 111 for (Way way : atNodes.get(0).getParentWays()) { 112 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; 118 } 119 } 120 121 reset(); 122 return true; 123 } 124 return false; 125 } 126 127 private boolean firstNodeIsConnectionNode(Node node, Way affected) { 128 if (node.isConnectionNode()) { 129 if (node.getParentWays().contains(affected)) 130 previousAffectedWay = affected; 131 else { 132 reset(); 133 return true; 134 } 135 } 136 return false; 137 } 138 139 private boolean secondNodeIsConnectionNode(Node node) { 140 if (atNodes.get(1).isConnectionNode()) { 141 if (atNodes.get(1).getParentWays().contains(previousAffectedWay)) 142 return false; 143 else { 144 reset(); 145 return true; 146 } 147 } 148 return false; 149 } 150 151 private Node checkCommonNode(Way affected) { 152 153 // check if they have any common node 154 List<Node> presentNodeList = affected.getNodes(); 155 for (Node previousNode : previousAffectedWay.getNodes()) { 156 if (presentNodeList.contains(previousNode)) { 157 return previousNode; 158 } 159 } 160 161 return null; 162 } 163 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) { 196 List<TagMap> affectedKeysList = new ArrayList<>(); 197 198 List<Node> nodelist1 = Arrays.asList(atNodes.get(0), commonNode); 199 List<Node> nodelist2 = Arrays.asList(atNodes.get(1), commonNode); 200 201 affectedKeysList.add(previousAffectedWay.getKeys()); 202 affectedKeysList.add(affected.getKeys()); 203 204 // split both the ways separately 205 206 SplitWayCommand result1 = SplitWayCommand.split(previousAffectedWay, nodelist1, Collections.emptyList()); 207 208 SplitWayCommand result2 = SplitWayCommand.split(affected, nodelist2, Collections.emptyList()); 209 210 MainApplication.undoRedo.add(result1); 211 MainApplication.undoRedo.add(result2); 212 213 Way way1 = null, way2 = null; 214 215 // Find middle way which is a part of both the ways, so find the 2 ways which 216 // together would form middle way 217 boolean isOriginalWay = true; // we check both the original way and new ways 218 for (Way way : result1.getNewWays()) { 219 if (way.containsNode(commonNode) && way.containsNode(atNodes.get(0))) { 220 way1 = way; 221 isOriginalWay = false; 222 break; 223 } 224 } 225 if (isOriginalWay) { 226 Way way = result1.getOriginalWay(); 227 if (way.containsNode(commonNode) && way.containsNode(atNodes.get(0))) { 228 way1 = way; 229 } 230 } 231 232 // now do for 2nd way 233 isOriginalWay = true; 234 235 for (Way way : result2.getNewWays()) { 236 if (way.containsNode(commonNode) && way.containsNode(atNodes.get(1))) { 237 way2 = way; 238 isOriginalWay = false; 239 break; 240 } 241 } 242 243 if (isOriginalWay) { 244 Way way = result2.getOriginalWay(); 245 if (way.containsNode(commonNode) && way.containsNode(atNodes.get(1))) { 246 way2 = way; 247 } 248 } 249 250 if (way1 != null && way2 != null) { 251 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) { 259 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 } 276 277 if (selectedWay != null) { 278 affectedKeysList.add(affected.getKeys()); 279 newHighlights.add(selectedWay); 280 dialogBox(Arrays.asList(selectedWay), affectedKeysList); 281 } 282 } 283 284 @Override 285 public void mouseMoved(MouseEvent e) { 286 287 // while the mouse is moving, surroundings are checked 288 // if anything is found, it will be highlighted. 289 // priority is given to nodes 290 Cursor newCurs = getCursor(); 291 292 Node n = MainApplication.getMap().mapView.getNearestNode(e.getPoint(), OsmPrimitive::isUsable); 293 if (n != null) { 294 newHighlights.add(n); 295 newCurs = cursorJoinNode; 296 } else { 297 List<WaySegment> wss = MainApplication.getMap().mapView.getNearestWaySegments(e.getPoint(), 298 OsmPrimitive::isSelectable); 299 300 if (!wss.isEmpty()) { 301 for (WaySegment ws : wss) { 302 newHighlights.add(ws.way); 303 } 304 newCurs = cursorJoinWay; 305 } 306 } 307 308 MainApplication.getMap().mapView.setCursor(newCurs); 309 updateHighlights(); 310 } 311 312 @Override 313 public void mouseClicked(MouseEvent e) { 314 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 421 } 422 423 // turn off what has been highlighted on last mouse move and highlight what has 424 // to be highlighted now 425 382 426 private void updateHighlights() { 383 if (oldHighlights.isEmpty() && newHighlights.isEmpty()) { 384 return; 385 } 386 387 for (OsmPrimitive osm : oldHighlights) { 388 osm.setHighlighted(false); 389 } 390 391 for (OsmPrimitive osm : newHighlights) { 392 osm.setHighlighted(true); 393 } 394 395 MainApplication.getLayerManager().getEditLayer().invalidate(); 396 397 oldHighlights.clear(); 398 oldHighlights.addAll(newHighlights); 399 newHighlights.clear(); 400 } 401 402 403 //A dialogBox to query whether to select bus_bay, tunnel or bridge. 404 405 static class SelectFromOptionDialog extends ExtendedDialog { 406 static final AtomicInteger DISPLAY_COUNT = new AtomicInteger(); 407 final transient List<Way> selectedWay; 408 private JComboBox<String> keys; 409 private JComboBox<String> values; 427 if (oldHighlights.isEmpty() && newHighlights.isEmpty()) { 428 return; 429 } 430 431 for (OsmPrimitive osm : oldHighlights) { 432 osm.setHighlighted(false); 433 } 434 435 for (OsmPrimitive osm : newHighlights) { 436 osm.setHighlighted(true); 437 } 438 439 MainApplication.getLayerManager().getEditLayer().invalidate(); 440 441 oldHighlights.clear(); 442 oldHighlights.addAll(newHighlights); 443 newHighlights.clear(); 444 } 445 446 // A dialogBox to query whether to select bus_bay, tunnel or bridge. 447 448 static class SelectFromOptionDialog extends ExtendedDialog { 449 static final AtomicInteger DISPLAY_COUNT = new AtomicInteger(); 450 final transient List<Way> selectedWay; 451 private JComboBox<String> keys; 452 private JComboBox<String> values; 410 453 private List<TagMap> affectedKeysList; 411 454 412 SelectFromOptionDialog(List<Way> selectedWay, List<TagMap> affectedKeysList) { 413 super(Main.parent, tr("What do you want the segment to be?"), 414 new String[]{tr("Ok"), tr("Cancel")}, true); 415 this.selectedWay = selectedWay; 416 this.affectedKeysList = affectedKeysList; 417 418 setButtonIcons("ok", "cancel"); 419 setCancelButton(2); 420 configureContextsensitiveHelp("/Dialog/AddValue", true /* show help button */); 421 422 final JPanel pane = new JPanel(new GridBagLayout()); 423 pane.add(new JLabel("Select the appropriate option"), GBC.eol().fill(GBC.HORIZONTAL)); 424 425 426 keys = new JComboBox<>(); 427 values = new JComboBox<>(); 428 keys.setEditable(true); 429 keys.setModel(new DefaultComboBoxModel<>(new String[]{"bus_bay", "bridge", "tunnel"})); 430 values.setModel(new DefaultComboBoxModel<>(new String[]{"both", "right", "left"})); 431 432 //below code changes the list in values on the basis of key 433 keys.addActionListener (new ActionListener () { 434 @Override 455 SelectFromOptionDialog(List<Way> selectedWay, List<TagMap> affectedKeysList) { 456 super(Main.parent, tr("What do you want the segment to be?"), new String[] { tr("Ok"), tr("Cancel") }, 457 true); 458 this.selectedWay = selectedWay; 459 this.affectedKeysList = affectedKeysList; 460 461 setButtonIcons("ok", "cancel"); 462 setCancelButton(2); 463 configureContextsensitiveHelp("/Dialog/AddValue", true /* show help button */); 464 465 final JPanel pane = new JPanel(new GridBagLayout()); 466 pane.add(new JLabel("Select the appropriate option"), GBC.eol().fill(GBC.HORIZONTAL)); 467 468 keys = new JComboBox<>(); 469 values = new JComboBox<>(); 470 keys.setEditable(true); 471 keys.setModel(new DefaultComboBoxModel<>(new String[] { "bus_bay", "bridge", "tunnel" })); 472 values.setModel(new DefaultComboBoxModel<>(new String[] { "both", "right", "left" })); 473 474 // below code changes the list in values on the basis of key 475 keys.addActionListener(new ActionListener() { 476 @Override 435 477 public void actionPerformed(ActionEvent e) { 436 if ("bus_bay".equals(keys.getSelectedItem())){437 values.setModel(new DefaultComboBoxModel<>(new String[]{"both", "right", "left"}));438 } else if ("bridge".equals(keys.getSelectedItem())){439 values.setModel(new DefaultComboBoxModel<>(new String[]{"yes"}));440 } else if ("tunnel".equals(keys.getSelectedItem())){441 values.setModel(new DefaultComboBoxModel<>(new String[]{"yes", "culvert"}));442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 } else if(keys.getSelectedItem() == "tunnel") {466 467 468 469 470 471 472 if (this.affectedKeysList.size() == 2) {473 474 475 476 477 478 479 } else if(keys.getSelectedItem() == "tunnel") {480 481 482 483 484 485 486 487 488 478 if ("bus_bay".equals(keys.getSelectedItem())) { 479 values.setModel(new DefaultComboBoxModel<>(new String[] { "both", "right", "left" })); 480 } else if ("bridge".equals(keys.getSelectedItem())) { 481 values.setModel(new DefaultComboBoxModel<>(new String[] { "yes" })); 482 } else if ("tunnel".equals(keys.getSelectedItem())) { 483 values.setModel(new DefaultComboBoxModel<>(new String[] { "yes", "culvert" })); 484 } 485 } 486 }); 487 488 pane.add(keys, GBC.eop().fill(GBC.HORIZONTAL)); 489 pane.add(values, GBC.eop().fill(GBC.HORIZONTAL)); 490 491 setContent(pane, false); 492 setDefaultCloseOperation(HIDE_ON_CLOSE); 493 } 494 495 @Override 496 protected void buttonAction(int buttonIndex, ActionEvent evt) { 497 super.buttonAction(buttonIndex, evt); 498 toggleSaveState(); // necessary since #showDialog() does not handle it due to the non-modal dialog 499 500 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); 512 } 513 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 } 489 531 }
Note:
See TracChangeset
for help on using the changeset viewer.