Ticket #23422: 23422.patch

File 23422.patch, 5.4 KB (added by GerdP, 23 months ago)
  • src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java

     
    125125
    126126    private boolean snap;
    127127
    128     private final MapView mv;
    129 
    130128    // Mouse tracking state
    131129    private Point mousePressedPos;
    132130    private boolean mouseIsDown;
     
    145143     * Constructs a new {@code ParallelWayAction}.
    146144     * @param mapFrame Map frame
    147145     */
    148     public ParallelWayAction(MapFrame mapFrame) {
     146    public ParallelWayAction() {
    149147        super(tr("Parallel"), "parallel", tr("Make parallel copies of ways"),
    150148            Shortcut.registerShortcut("mapmode:parallel", tr("Mode: {0}",
    151149                tr("Parallel")), KeyEvent.VK_P, Shortcut.SHIFT),
    152150            ImageProvider.getCursor("normal", "parallel"));
    153151        setHelpId(ht("/Action/Parallel"));
    154         mv = mapFrame.mapView;
    155152    }
    156153
    157154    @Override
     
    163160
    164161        // #19887: overwrite default: we want to show the distance to the original way
    165162        MainApplication.getMap().statusLine.setAutoLength(false);
    166 
     163        MapView mv = MainApplication.getMap().mapView;
    167164        mv.addMouseListener(this);
    168165        mv.addMouseMotionListener(this);
    169166        mv.addTemporaryLayer(temporaryLayer);
     
    179176    @Override
    180177    public void exitMode() {
    181178        super.exitMode();
     179        MapView mv = MainApplication.getMap().mapView;
    182180        mv.removeMouseListener(this);
    183181        mv.removeMouseMotionListener(this);
    184182        mv.removeTemporaryLayer(temporaryLayer);
     
    213211
    214212    @Override
    215213    public void modifiersExChanged(int modifiers) {
    216         if (MainApplication.getMap() == null || mv == null || !mv.isActiveLayerDrawable())
     214        if (!MainApplication.isDisplayingMapView() || !MainApplication.getMap().mapView.isActiveLayerDrawable())
    217215            return;
    218216
    219217        // Should only get InputEvents due to the mask in enterMode
     
    247245        default: throw new AssertionError();
    248246        }
    249247        if (newCursor != null) {
    250             mv.setNewCursor(newCursor, this);
     248            MainApplication.getMap().mapView.setNewCursor(newCursor, this);
    251249        }
    252250    }
    253251
     
    258256    }
    259257
    260258    private boolean sanityCheck() {
     259        MapView mv = MainApplication.getMap().mapView;
    261260        // @formatter:off
    262261        boolean areWeSane =
    263262            mv.isActiveLayerVisible() &&
     
    303302
    304303        if (!mouseHasBeenDragged) {
    305304            // use point from press or click event? (or are these always the same)
    306             Way nearestWay = mv.getNearestWay(e.getPoint(), OsmPrimitive::isSelectable);
     305            Way nearestWay = MainApplication.getMap().mapView.getNearestWay(e.getPoint(), OsmPrimitive::isSelectable);
    307306            if (nearestWay == null) {
    308307                if (matchesCurrentModifiers(SET_SELECTED_MODIFIER_COMBO)) {
    309308                    clearSourceWays();
     
    381380
    382381        // Calculate distance to the reference line
    383382        Point p = e.getPoint();
     383        MapView mv = MainApplication.getMap().mapView;
    384384        EastNorth enp = mv.getEastNorth((int) p.getX(), (int) p.getY());
    385385        EastNorth nearestPointOnRefLine = Geometry.closestPointToLine(referenceSegment.getFirstNode().getEastNorth(),
    386386                referenceSegment.getSecondNode().getEastNorth(), enp);
     
    498498
    499499    // TODO: rename
    500500    private boolean initParallelWays(Point p, boolean copyTags) {
    501         referenceSegment = mv.getNearestWaySegment(p, OsmPrimitive::isUsable, true);
     501        referenceSegment = MainApplication.getMap().mapView.getNearestWaySegment(p, OsmPrimitive::isUsable, true);
    502502        if (referenceSegment == null)
    503503            return false;
    504504
  • src/org/openstreetmap/josm/gui/MapFrame.java

     
    251251        addMapMode(new IconToggleButton(mapModeDraw, false));
    252252        addMapMode(new IconToggleButton(mapModeZoom, true));
    253253        addMapMode(new IconToggleButton(mapModeDelete, true));
    254         addMapMode(new IconToggleButton(new ParallelWayAction(this), true));
     254        addMapMode(new IconToggleButton(new ParallelWayAction(), true));
    255255        addMapMode(new IconToggleButton(new ExtrudeAction(), true));
    256256        addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(), false));
    257257        addMapMode(new IconToggleButton(new SplitMode(), false));
  • test/unit/org/openstreetmap/josm/actions/mapmode/ParallelWayActionTest.java

     
    3030        try {
    3131            MainApplication.getLayerManager().addLayer(layer);
    3232            MapFrame map = MainApplication.getMap();
    33             ParallelWayAction mapMode = new ParallelWayAction(map);
     33            ParallelWayAction mapMode = new ParallelWayAction();
    3434            MapMode oldMapMode = map.mapMode;
    3535            assertTrue(map.selectMapMode(mapMode));
    3636            assertEquals(mapMode, map.mapMode);