Ticket #20564: 20564_and_20585.patch

File 20564_and_20585.patch, 9.3 KB (added by Solarspot, 5 years ago)

Managed to find a simple solution for #20585 with a listener. Sinse the patch for this ticket isn't merged yet, here is a patch that fixes both similar issues #20564 and #20585

  • new file plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/ConfigKey.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/ConfigKey.java b/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/ConfigKey.java
    new file mode 100644
    - +  
     1package org.openstreetmap.josm.plugins.buildings_tools;
     2
     3enum ConfigKey {
     4    TAGS("buildings_tools.tags"),
     5    SHAPE("buildings_tools.shape"),
     6    BBMODE("buildings_tools.bbmode"),
     7    SOFTCURSOR("buildings_tools.softcursor"),
     8    NOCLICKDRAG("buildings_tools.noclickdrag"),
     9    ADDRNODE("buildings_tools.addrNode");
     10
     11    private final String key;
     12
     13    ConfigKey(String key) {
     14        this.key = key;
     15    }
     16
     17    public String getKey() {
     18        return key;
     19    }
     20}
     21 No newline at end of file
  • plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/DrawBuildingAction.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/DrawBuildingAction.java b/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/DrawBuildingAction.java
    a b  
    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(ConfigKey.SHAPE.getKey(), 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(ConfigKey.SHAPE.getKey(), 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;
  • plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/ToolSettings.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/ToolSettings.java b/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/ToolSettings.java
    a b  
    1919        // Hide default constructor for utils classes
    2020    }
    2121
    22     public static final BooleanProperty PROP_USE_ADDR_NODE = new BooleanProperty("buildings_tools.addrNode", false);
     22    static final BooleanProperty PROP_USE_ADDR_NODE = new BooleanProperty(ConfigKey.ADDRNODE.getKey(), false);
    2323
    2424    public enum Shape {
    2525            CIRCLE, RECTANGLE
     
    7171            values.add(entry.getKey());
    7272            values.add(entry.getValue());
    7373        }
    74         Config.getPref().putList("buildings_tools.tags", values);
     74        Config.getPref().putList(ConfigKey.TAGS.getKey(), values);
    7575    }
    7676
    7777    private static void loadTags() {
    7878        TAGS.clear();
    79         Collection<String> values = Config.getPref().getList("buildings_tools.tags",
     79        Collection<String> values = Config.getPref().getList(ConfigKey.TAGS.getKey(),
    8080                Arrays.asList("building", "yes"));
    8181        try {
    8282            for (Iterator<String> iterator = values.iterator(); iterator.hasNext();) {
     
    8888    }
    8989
    9090    public static void saveShape(Shape shape) {
    91         Config.getPref().put("buildings_tool.shape", shape.name());
     91        Config.getPref().put(ConfigKey.SHAPE.getKey(), shape.name());
    9292    }
    9393
    9494    private static Shape loadShape() {
    95         String shape = Config.getPref().get("buildings_tool.shape");
     95        String shape = Config.getPref().get(ConfigKey.SHAPE.getKey());
    9696        if (ToolSettings.Shape.CIRCLE.name().equals(shape)) {
    9797            ToolSettings.shape = Shape.CIRCLE;
    9898            return Shape.CIRCLE;
     
    103103    }
    104104
    105105    public static void setBBMode(boolean bbmode) {
    106         Config.getPref().putBoolean("buildings_tools.bbmode", bbmode);
     106        Config.getPref().putBoolean(ConfigKey.BBMODE.getKey(), bbmode);
    107107    }
    108108
    109109    public static boolean isBBMode() {
    110         return Config.getPref().getBoolean("buildings_tools.bbmode", false);
     110        return Config.getPref().getBoolean(ConfigKey.BBMODE.getKey(), false);
    111111    }
    112112
    113113    public static void setSoftCursor(boolean softCursor) {
    114         Config.getPref().putBoolean("buildings_tools.softcursor", softCursor);
     114        Config.getPref().putBoolean(ConfigKey.SOFTCURSOR.getKey(), softCursor);
    115115    }
    116116
    117117    public static boolean isSoftCursor() {
    118         return Config.getPref().getBoolean("buildings_tools.softcursor", false);
     118        return Config.getPref().getBoolean(ConfigKey.SOFTCURSOR.getKey(), false);
    119119    }
    120120
    121121    public static boolean isAutoSelect() {
     
    127127    }
    128128
    129129    public static boolean isNoClickAndDrag() {
    130         return Config.getPref().getBoolean("buildings_tools.noclickdrag", false);
     130        return Config.getPref().getBoolean(ConfigKey.NOCLICKDRAG.getKey(), false);
    131131    }
    132132
    133133    public static void setNoClickAndDrag(boolean noClickDrag) {
    134         Config.getPref().putBoolean("buildings_tools.noclickdrag", noClickDrag);
     134        Config.getPref().putBoolean(ConfigKey.NOCLICKDRAG.getKey(), noClickDrag);
    135135    }
    136136}