Ticket #20564: 20564_and_20585-simple.patch

File 20564_and_20585-simple.patch, 4.2 KB (added by GerdP, 5 years ago)

Hmm, if I got that right the changes for enum ConfigKey are just refactoring and not needed to fix the problems? I think we should not do both steps in one change. Please review my version.

  • src/org/openstreetmap/josm/plugins/buildings_tools/DrawBuildingAction.java

     
    3939import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    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;
    4446import org.openstreetmap.josm.tools.Logging;
     
    5052        None, Drawing, DrawingWidth, DrawingAngFix
    5153    }
    5254
    53     private final Cursor cursorCrosshair;
    5455    private final Cursor cursorJoinNode;
    5556    private final Cursor cursorJoinWay;
    5657    private Cursor currCursor;
     
    6566
    6667    final transient Building building = new Building();
    6768
     69    private final PreferenceChangedListener shapeChangeListener = event -> updCursor();
     70
    6871    public DrawBuildingAction() {
    6972        super(tr("Draw buildings"), "building", tr("Draw buildings"),
    7073                Shortcut.registerShortcut("mapmode:buildings",
    7174                        tr("Mode: {0}", tr("Draw buildings")),
    7275                        KeyEvent.VK_B, Shortcut.DIRECT),
    73                 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));
    7480
    75         cursorCrosshair = getCursor();
     81        currCursor = getCursor();
    7682        cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode");
    7783        cursorJoinWay = ImageProvider.getCursor("crosshair", "joinway");
    78         currCursor = cursorCrosshair;
    7984    }
    8085
    8186    private static Cursor getCursor() {
     
    133138    @Override
    134139    public void enterMode() {
    135140        super.enterMode();
     141
    136142        MapFrame map = MainApplication.getMap();
    137143        if (getLayerManager().getEditDataSet() == null) {
    138144            map.selectSelectTool(false);
     
    139145            return;
    140146        }
    141147        selectedColor = new NamedColorProperty(marktr("selected"), selectedColor).get();
    142         currCursor = cursorCrosshair;
    143148        map.mapView.addMouseListener(this);
    144149        map.mapView.addMouseMotionListener(this);
    145150        map.mapView.addTemporaryLayer(this);
     
    146151        map.keyDetector.addKeyListener(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
    152161    @Override
     
    159168        map.keyDetector.removeKeyListener(this);
    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();
    164175        mode = Mode.None;
     
    385396    }
    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);
    397406                return;