Changeset 35740 in osm for applications/editors


Ignore:
Timestamp:
2021-05-02T11:21:05+02:00 (3 years ago)
Author:
GerdP
Message:

fix #20564 and #20585: Buildings tool shows wrong cursor icon
patch 20564_and_20585.patch (modified) by Solarspot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/DrawBuildingAction.java

    r35669 r35740  
    4040import org.openstreetmap.josm.gui.util.KeyPressReleaseListener;
    4141import org.openstreetmap.josm.gui.util.ModifierExListener;
     42import org.openstreetmap.josm.spi.preferences.Config;
     43import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    4244import org.openstreetmap.josm.tools.Geometry;
    4345import org.openstreetmap.josm.tools.ImageProvider;
     
    5153    }
    5254
    53     private final Cursor cursorCrosshair;
    5455    private final Cursor cursorJoinNode;
    5556    private final Cursor cursorJoinWay;
     
    6566
    6667    final transient Building building = new Building();
     68
     69    private final PreferenceChangedListener shapeChangeListener = event -> updCursor();
    6770
    6871    public DrawBuildingAction() {
     
    7174                        tr("Mode: {0}", tr("Draw buildings")),
    7275                        KeyEvent.VK_B, Shortcut.DIRECT),
    73                 getCursor());
    74 
    75         cursorCrosshair = getCursor();
     76                // Set super.cursor to crosshair without overlay because super.cursor is final,
     77                // but we use two different cursors with overlays for rectangular and circular buildings
     78                // the actual cursor is drawn in enterMode()
     79                ImageProvider.getCursor("crosshair", null));
     80
     81        currCursor = getCursor();
    7682        cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode");
    7783        cursorJoinWay = ImageProvider.getCursor("crosshair", "joinway");
    78         currCursor = cursorCrosshair;
    7984    }
    8085
     
    134139    public void enterMode() {
    135140        super.enterMode();
     141
    136142        MapFrame map = MainApplication.getMap();
    137143        if (getLayerManager().getEditDataSet() == null) {
     
    140146        }
    141147        selectedColor = new NamedColorProperty(marktr("selected"), selectedColor).get();
    142         currCursor = cursorCrosshair;
    143148        map.mapView.addMouseListener(this);
    144149        map.mapView.addMouseMotionListener(this);
     
    147152        map.keyDetector.addModifierExListener(this);
    148153        SelectionEventManager.getInstance().addSelectionListener(this);
     154        Config.getPref().addKeyPreferenceChangeListener("buildings_tool.shape", shapeChangeListener);
     155
    149156        updateSnap(getLayerManager().getEditDataSet().getSelected());
     157        // super.enterMode() draws the basic cursor. Overwrite it with the cursor for the current building mode.
     158        updCursor();
    150159    }
    151160
     
    160169        map.keyDetector.removeModifierExListener(this);
    161170        SelectionEventManager.getInstance().removeSelectionListener(this);
     171        Config.getPref().removeKeyPreferenceChangeListener("buildings_tool.shape", shapeChangeListener);
     172
    162173        if (mode != Mode.None)
    163174            map.mapView.repaint();
     
    386397
    387398    private void updCursor() {
    388         if (mousePos == null)
    389             return;
    390399        if (!MainApplication.isDisplayingMapView())
    391400            return;
    392         Node n = null;
    393         if (!ctrl) {
    394             n = MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isSelectable);
     401
     402        if (!ctrl && (mousePos != null)) {
     403            Node n = MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isSelectable);
    395404            if (n != null) {
    396405                setCursor(cursorJoinNode);
Note: See TracChangeset for help on using the changeset viewer.