Changeset 12630 in josm for trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
- Timestamp:
- 2017-08-24T00:15:51+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r12517 r12630 54 54 import org.openstreetmap.josm.data.preferences.DoubleProperty; 55 55 import org.openstreetmap.josm.data.preferences.StrokeProperty; 56 import org.openstreetmap.josm.gui.MainApplication; 56 57 import org.openstreetmap.josm.gui.MainMenu; 58 import org.openstreetmap.josm.gui.MapFrame; 57 59 import org.openstreetmap.josm.gui.MapView; 58 60 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; … … 270 272 snapCheckboxMenuItem.getAction().setEnabled(true); 271 273 272 Main.map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener); 274 MapFrame map = MainApplication.getMap(); 275 map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener); 273 276 Main.registerActionShortcut(backspaceAction, backspaceShortcut); 274 277 275 Main.map.mapView.addMouseListener(this);276 Main.map.mapView.addMouseMotionListener(this);277 Main.map.mapView.addTemporaryLayer(this);278 map.mapView.addMouseListener(this); 279 map.mapView.addMouseMotionListener(this); 280 map.mapView.addTemporaryLayer(this); 278 281 SelectionEventManager.getInstance().addSelectionListenerForEdt(this); 279 282 280 Main.map.keyDetector.addKeyListener(this);281 Main.map.keyDetector.addModifierExListener(this);283 map.keyDetector.addKeyListener(this); 284 map.keyDetector.addModifierExListener(this); 282 285 ignoreNextKeyRelease = true; 283 286 } … … 286 289 public void exitMode() { 287 290 super.exitMode(); 288 Main.map.mapView.removeMouseListener(this); 289 Main.map.mapView.removeMouseMotionListener(this); 290 Main.map.mapView.removeTemporaryLayer(this); 291 MapFrame map = MainApplication.getMap(); 292 map.mapView.removeMouseListener(this); 293 map.mapView.removeMouseMotionListener(this); 294 map.mapView.removeTemporaryLayer(this); 291 295 SelectionEventManager.getInstance().removeSelectionListener(this); 292 296 Main.unregisterActionShortcut(backspaceAction, backspaceShortcut); … … 294 298 snapCheckboxMenuItem.getAction().setEnabled(false); 295 299 296 Main.map.statusLine.getAnglePanel().removeMouseListener(snapHelper.anglePopupListener);297 Main.map.statusLine.activateAnglePanel(false);300 map.statusLine.getAnglePanel().removeMouseListener(snapHelper.anglePopupListener); 301 map.statusLine.activateAnglePanel(false); 298 302 299 303 removeHighlighting(); 300 Main.map.keyDetector.removeKeyListener(this);301 Main.map.keyDetector.removeModifierExListener(this);304 map.keyDetector.removeKeyListener(this); 305 map.keyDetector.removeModifierExListener(this); 302 306 } 303 307 … … 307 311 @Override 308 312 public void modifiersExChanged(int modifiers) { 309 if (!Main .isDisplayingMapView() || !Main.map.mapView.isActiveLayerDrawable())313 if (!MainApplication.isDisplayingMapView() || !MainApplication.getMap().mapView.isActiveLayerDrawable()) 310 314 return; 311 315 updateKeyModifiersEx(modifiers); … … 341 345 @Override 342 346 public void selectionChanged(SelectionChangeEvent event) { 343 if (!Main .map.mapView.isActiveLayerDrawable())347 if (!MainApplication.getMap().mapView.isActiveLayerDrawable()) 344 348 return; 345 349 computeHelperLine(); … … 360 364 lastUsedNode = null; 361 365 wayIsFinished = true; 362 Main .map.selectSelectTool(true);366 MainApplication.getMap().selectSelectTool(true); 363 367 snapHelper.noSnapNow(); 364 368 … … 392 396 if (e.getButton() != MouseEvent.BUTTON1) 393 397 return; 394 if (!Main.map.mapView.isActiveLayerDrawable()) 398 MapView mapView = MainApplication.getMap().mapView; 399 if (!mapView.isActiveLayerDrawable()) 395 400 return; 396 401 // request focus in order to enable the expected keyboard shortcuts 397 402 // 398 Main.map.mapView.requestFocus();403 mapView.requestFocus(); 399 404 400 405 if (e.getClickCount() > 1 && mousePos != null && mousePos.equals(oldMousePos)) { … … 417 422 418 423 boolean newNode = false; 419 Node n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive::isSelectable);424 Node n = mapView.getNearestNode(mousePos, OsmPrimitive::isSelectable); 420 425 if (ctrl) { 421 426 Iterator<Way> it = ds.getSelectedWays().iterator(); … … 453 458 newEN = snapHelper.getSnapPoint(foundPoint); 454 459 // do not add new node if there is some node within snapping distance 455 double tolerance = Main.map.mapView.getDist100Pixel() * toleranceMultiplier;460 double tolerance = mapView.getDist100Pixel() * toleranceMultiplier; 456 461 if (foundPoint.distance(newEN) > tolerance) { 457 462 n = new Node(newEN); // point != projected, so we create new node … … 459 464 } 460 465 } else { // n==null, no node found in clicked area 461 EastNorth mouseEN = Main.map.mapView.getEastNorth(e.getX(), e.getY());466 EastNorth mouseEN = mapView.getEastNorth(e.getX(), e.getY()); 462 467 newEN = snapHelper.isSnapOn() ? snapHelper.getSnapPoint(mouseEN) : mouseEN; 463 468 n = new Node(newEN); //create node at clicked point … … 486 491 if (!ctrl) { 487 492 // Insert the node into all the nearby way segments 488 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(489 Main.map.mapView.getPoint(n), OsmPrimitive::isSelectable);493 List<WaySegment> wss = mapView.getNearestWaySegments( 494 mapView.getPoint(n), OsmPrimitive::isSelectable); 490 495 if (snapHelper.isActive()) { 491 496 tryToMoveNodeOnIntersection(wss, n); … … 622 627 // from aerial imagery or GPS tracks. 623 628 if (VIEWPORT_FOLLOWING.get()) { 624 Main.map.mapView.smoothScrollTo(n.getEastNorth());629 mapView.smoothScrollTo(n.getEastNorth()); 625 630 } 626 631 computeHelperLine(); … … 767 772 @Override 768 773 public void mouseMoved(MouseEvent e) { 769 if (!Main .map.mapView.isActiveLayerDrawable())774 if (!MainApplication.getMap().mapView.isActiveLayerDrawable()) 770 775 return; 771 776 … … 787 792 private void tryToSetBaseSegmentForAngleSnap() { 788 793 if (mousePos != null) { 789 WaySegment seg = Main .map.mapView.getNearestWaySegment(mousePos, OsmPrimitive::isSelectable);794 WaySegment seg = MainApplication.getMap().mapView.getNearestWaySegment(mousePos, OsmPrimitive::isSelectable); 790 795 if (seg != null) { 791 796 snapHelper.setBaseSegment(seg); … … 809 814 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 810 815 811 MapView mv = Main .map.mapView;816 MapView mv = MainApplication.getMap().mapView; 812 817 Node currentMouseNode = null; 813 818 mouseOnExistingNode = null; … … 864 869 865 870 static void showStatusInfo(double angle, double hdg, double distance, boolean activeFlag) { 866 Main.map.statusLine.setAngle(angle); 867 Main.map.statusLine.activateAnglePanel(activeFlag); 868 Main.map.statusLine.setHeading(hdg); 869 Main.map.statusLine.setDist(distance); 871 MapFrame map = MainApplication.getMap(); 872 map.statusLine.setAngle(angle); 873 map.statusLine.activateAnglePanel(activeFlag); 874 map.statusLine.setHeading(hdg); 875 map.statusLine.setDist(distance); 870 876 } 871 877 … … 1060 1066 // fall through to default action. 1061 1067 // (for semi-parallel lines, intersection might be miles away!) 1062 if (Main.map.mapView.getPoint2D(n).distance(Main.map.mapView.getPoint2D(intersection)) < SNAP_TO_INTERSECTION_THRESHOLD.get()) { 1068 MapFrame map = MainApplication.getMap(); 1069 if (map.mapView.getPoint2D(n).distance(map.mapView.getPoint2D(intersection)) < SNAP_TO_INTERSECTION_THRESHOLD.get()) { 1063 1070 n.setEastNorth(intersection); 1064 1071 return; … … 1113 1120 private void addHighlighting() { 1114 1121 newHighlights = new HashSet<>(); 1122 MapView mapView = MainApplication.getMap().mapView; 1115 1123 1116 1124 // if ctrl key is held ("no join"), don't highlight anything 1117 1125 if (ctrl) { 1118 Main.map.mapView.setNewCursor(cursor, this);1126 mapView.setNewCursor(cursor, this); 1119 1127 redrawIfRequired(); 1120 1128 return; … … 1123 1131 // This happens when nothing is selected, but we still want to highlight the "target node" 1124 1132 if (mouseOnExistingNode == null && mousePos != null && getLayerManager().getEditDataSet().selectionEmpty()) { 1125 mouseOnExistingNode = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive::isSelectable);1133 mouseOnExistingNode = mapView.getNearestNode(mousePos, OsmPrimitive::isSelectable); 1126 1134 } 1127 1135 1128 1136 if (mouseOnExistingNode != null) { 1129 Main.map.mapView.setNewCursor(cursorJoinNode, this);1137 mapView.setNewCursor(cursorJoinNode, this); 1130 1138 newHighlights.add(mouseOnExistingNode); 1131 1139 redrawIfRequired(); … … 1135 1143 // Insert the node into all the nearby way segments 1136 1144 if (mouseOnExistingWays.isEmpty()) { 1137 Main.map.mapView.setNewCursor(cursor, this);1145 mapView.setNewCursor(cursor, this); 1138 1146 redrawIfRequired(); 1139 1147 return; 1140 1148 } 1141 1149 1142 Main.map.mapView.setNewCursor(cursorJoinWay, this);1150 mapView.setNewCursor(cursorJoinWay, this); 1143 1151 newHighlights.addAll(mouseOnExistingWays); 1144 1152 redrawIfRequired(); … … 1157 1165 public void paint(Graphics2D g, MapView mv, Bounds box) { 1158 1166 // sanity checks 1159 if (Main.map.mapView == null || mousePos == null 1167 MapView mapView = MainApplication.getMap().mapView; 1168 if (mapView == null || mousePos == null 1160 1169 // don't draw line if we don't know where from or where to 1161 1170 || currentMouseEastNorth == null || getCurrentBaseNode() == null 1162 1171 // don't draw line if mouse is outside window 1163 || ! Main.map.mapView.getState().getForView(mousePos.getX(), mousePos.getY()).isInView())1172 || !mapView.getState().getForView(mousePos.getX(), mousePos.getY()).isInView()) 1164 1173 return; 1165 1174 … … 1368 1377 @Override 1369 1378 protected void updateEnabledState() { 1370 setEnabled(Main.map != null && Main.map.mapMode instanceof DrawAction); 1379 MapFrame map = MainApplication.getMap(); 1380 setEnabled(map != null && map.mapMode instanceof DrawAction); 1371 1381 } 1372 1382 }
Note:
See TracChangeset
for help on using the changeset viewer.