Ignore:
Timestamp:
2017-08-24T00:15:51+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15182 - deprecate Main.map and Main.isDisplayingMapView(). Replacements: gui.MainApplication.getMap() / gui.MainApplication.isDisplayingMapView()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r12517 r12630  
    5454import org.openstreetmap.josm.data.preferences.DoubleProperty;
    5555import org.openstreetmap.josm.data.preferences.StrokeProperty;
     56import org.openstreetmap.josm.gui.MainApplication;
    5657import org.openstreetmap.josm.gui.MainMenu;
     58import org.openstreetmap.josm.gui.MapFrame;
    5759import org.openstreetmap.josm.gui.MapView;
    5860import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
     
    270272        snapCheckboxMenuItem.getAction().setEnabled(true);
    271273
    272         Main.map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener);
     274        MapFrame map = MainApplication.getMap();
     275        map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener);
    273276        Main.registerActionShortcut(backspaceAction, backspaceShortcut);
    274277
    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);
    278281        SelectionEventManager.getInstance().addSelectionListenerForEdt(this);
    279282
    280         Main.map.keyDetector.addKeyListener(this);
    281         Main.map.keyDetector.addModifierExListener(this);
     283        map.keyDetector.addKeyListener(this);
     284        map.keyDetector.addModifierExListener(this);
    282285        ignoreNextKeyRelease = true;
    283286    }
     
    286289    public void exitMode() {
    287290        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);
    291295        SelectionEventManager.getInstance().removeSelectionListener(this);
    292296        Main.unregisterActionShortcut(backspaceAction, backspaceShortcut);
     
    294298        snapCheckboxMenuItem.getAction().setEnabled(false);
    295299
    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);
    298302
    299303        removeHighlighting();
    300         Main.map.keyDetector.removeKeyListener(this);
    301         Main.map.keyDetector.removeModifierExListener(this);
     304        map.keyDetector.removeKeyListener(this);
     305        map.keyDetector.removeModifierExListener(this);
    302306    }
    303307
     
    307311    @Override
    308312    public void modifiersExChanged(int modifiers) {
    309         if (!Main.isDisplayingMapView() || !Main.map.mapView.isActiveLayerDrawable())
     313        if (!MainApplication.isDisplayingMapView() || !MainApplication.getMap().mapView.isActiveLayerDrawable())
    310314            return;
    311315        updateKeyModifiersEx(modifiers);
     
    341345    @Override
    342346    public void selectionChanged(SelectionChangeEvent event) {
    343         if (!Main.map.mapView.isActiveLayerDrawable())
     347        if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
    344348            return;
    345349        computeHelperLine();
     
    360364        lastUsedNode = null;
    361365        wayIsFinished = true;
    362         Main.map.selectSelectTool(true);
     366        MainApplication.getMap().selectSelectTool(true);
    363367        snapHelper.noSnapNow();
    364368
     
    392396        if (e.getButton() != MouseEvent.BUTTON1)
    393397            return;
    394         if (!Main.map.mapView.isActiveLayerDrawable())
     398        MapView mapView = MainApplication.getMap().mapView;
     399        if (!mapView.isActiveLayerDrawable())
    395400            return;
    396401        // request focus in order to enable the expected keyboard shortcuts
    397402        //
    398         Main.map.mapView.requestFocus();
     403        mapView.requestFocus();
    399404
    400405        if (e.getClickCount() > 1 && mousePos != null && mousePos.equals(oldMousePos)) {
     
    417422
    418423        boolean newNode = false;
    419         Node n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive::isSelectable);
     424        Node n = mapView.getNearestNode(mousePos, OsmPrimitive::isSelectable);
    420425        if (ctrl) {
    421426            Iterator<Way> it = ds.getSelectedWays().iterator();
     
    453458                newEN = snapHelper.getSnapPoint(foundPoint);
    454459                // 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;
    456461                if (foundPoint.distance(newEN) > tolerance) {
    457462                    n = new Node(newEN); // point != projected, so we create new node
     
    459464                }
    460465            } 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());
    462467                newEN = snapHelper.isSnapOn() ? snapHelper.getSnapPoint(mouseEN) : mouseEN;
    463468                n = new Node(newEN); //create node at clicked point
     
    486491            if (!ctrl) {
    487492                // 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);
    490495                if (snapHelper.isActive()) {
    491496                    tryToMoveNodeOnIntersection(wss, n);
     
    622627        // from aerial imagery or GPS tracks.
    623628        if (VIEWPORT_FOLLOWING.get()) {
    624             Main.map.mapView.smoothScrollTo(n.getEastNorth());
     629            mapView.smoothScrollTo(n.getEastNorth());
    625630        }
    626631        computeHelperLine();
     
    767772    @Override
    768773    public void mouseMoved(MouseEvent e) {
    769         if (!Main.map.mapView.isActiveLayerDrawable())
     774        if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
    770775            return;
    771776
     
    787792    private void tryToSetBaseSegmentForAngleSnap() {
    788793        if (mousePos != null) {
    789             WaySegment seg = Main.map.mapView.getNearestWaySegment(mousePos, OsmPrimitive::isSelectable);
     794            WaySegment seg = MainApplication.getMap().mapView.getNearestWaySegment(mousePos, OsmPrimitive::isSelectable);
    790795            if (seg != null) {
    791796                snapHelper.setBaseSegment(seg);
     
    809814        Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected();
    810815
    811         MapView mv = Main.map.mapView;
     816        MapView mv = MainApplication.getMap().mapView;
    812817        Node currentMouseNode = null;
    813818        mouseOnExistingNode = null;
     
    864869
    865870    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);
    870876    }
    871877
     
    10601066        // fall through to default action.
    10611067        // (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()) {
    10631070            n.setEastNorth(intersection);
    10641071            return;
     
    11131120    private void addHighlighting() {
    11141121        newHighlights = new HashSet<>();
     1122        MapView mapView = MainApplication.getMap().mapView;
    11151123
    11161124        // if ctrl key is held ("no join"), don't highlight anything
    11171125        if (ctrl) {
    1118             Main.map.mapView.setNewCursor(cursor, this);
     1126            mapView.setNewCursor(cursor, this);
    11191127            redrawIfRequired();
    11201128            return;
     
    11231131        // This happens when nothing is selected, but we still want to highlight the "target node"
    11241132        if (mouseOnExistingNode == null && mousePos != null && getLayerManager().getEditDataSet().selectionEmpty()) {
    1125             mouseOnExistingNode = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive::isSelectable);
     1133            mouseOnExistingNode = mapView.getNearestNode(mousePos, OsmPrimitive::isSelectable);
    11261134        }
    11271135
    11281136        if (mouseOnExistingNode != null) {
    1129             Main.map.mapView.setNewCursor(cursorJoinNode, this);
     1137            mapView.setNewCursor(cursorJoinNode, this);
    11301138            newHighlights.add(mouseOnExistingNode);
    11311139            redrawIfRequired();
     
    11351143        // Insert the node into all the nearby way segments
    11361144        if (mouseOnExistingWays.isEmpty()) {
    1137             Main.map.mapView.setNewCursor(cursor, this);
     1145            mapView.setNewCursor(cursor, this);
    11381146            redrawIfRequired();
    11391147            return;
    11401148        }
    11411149
    1142         Main.map.mapView.setNewCursor(cursorJoinWay, this);
     1150        mapView.setNewCursor(cursorJoinWay, this);
    11431151        newHighlights.addAll(mouseOnExistingWays);
    11441152        redrawIfRequired();
     
    11571165    public void paint(Graphics2D g, MapView mv, Bounds box) {
    11581166        // sanity checks
    1159         if (Main.map.mapView == null || mousePos == null
     1167        MapView mapView = MainApplication.getMap().mapView;
     1168        if (mapView == null || mousePos == null
    11601169                // don't draw line if we don't know where from or where to
    11611170                || currentMouseEastNorth == null || getCurrentBaseNode() == null
    11621171                // 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())
    11641173            return;
    11651174
     
    13681377        @Override
    13691378        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);
    13711381        }
    13721382    }
Note: See TracChangeset for help on using the changeset viewer.