Ticket #13465: patch-map-mode-consistency.2.patch

File patch-map-mode-consistency.2.patch, 5.0 KB (added by michael2402, 5 years ago)
  • src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    diff --git a/src/org/openstreetmap/josm/actions/mapmode/MapMode.java b/src/org/openstreetmap/josm/actions/mapmode/MapMode.java
    index f6d774f..545e2d9 100644
    a b import java.awt.event.MouseMotionListener; 
    1010
    1111import org.openstreetmap.josm.Main;
    1212import org.openstreetmap.josm.actions.JosmAction;
     13import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
     14import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    1315import org.openstreetmap.josm.gui.MapFrame;
    1416import org.openstreetmap.josm.gui.layer.Layer;
    1517import org.openstreetmap.josm.tools.ImageProvider;
    1618import org.openstreetmap.josm.tools.Shortcut;
    17 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    18 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    1919
    2020/**
    2121 * A class implementing MapMode is able to be selected as an mode for map editing.
    public abstract class MapMode extends JosmAction implements MouseListener, Mouse 
    5656        putValue(NAME, name);
    5757        putValue(SMALL_ICON, ImageProvider.get("mapmode", iconName));
    5858        putValue(SHORT_DESCRIPTION, tooltip);
     59        putValue("active", Boolean.FALSE);
    5960        this.cursor = cursor;
    6061    }
    6162
    6263    /**
    63      * Makes this map mode active.
     64     * Makes this map mode active. This may never fail. Super needs to be called if implementations override this method.
     65     * <p>
     66     * Use {@link #layerIsSupported(Layer)} to prevent the mode from being activated.
    6467     */
    6568    public void enterMode() {
    6669        putValue("active", Boolean.TRUE);
    public abstract class MapMode extends JosmAction implements MouseListener, Mouse 
    7174    }
    7275
    7376    /**
    74      * Makes this map mode inactive.
     77     * Calls {@link #enterMode()}. Checks the state.
     78     * @since xxx
     79     */
     80    public final void enterModeCallCheck() {
     81        if (getValue("active") != Boolean.FALSE) {
     82            throw new IllegalStateException("enterMode() called twice");
     83        }
     84        enterMode();
     85        if (getValue("active") != Boolean.TRUE) {
     86            throw new IllegalStateException("enterMode() did not call super.");
     87        }
     88    }
     89
     90    /**
     91     * Makes this map mode inactive. This may never fail. Super needs to be called if implementations override this method.
    7592     */
    7693    public void exitMode() {
    7794        putValue("active", Boolean.FALSE);
    public abstract class MapMode extends JosmAction implements MouseListener, Mouse 
    7996        Main.map.mapView.resetCursor(this);
    8097    }
    8198
     99    /**
     100     * Calls {@link #exitMode()}. Checks the state.
     101     * @since xxx
     102     */
     103    public final void exitModeCallCheck() {
     104        if (getValue("active") != Boolean.TRUE) {
     105            throw new IllegalStateException("exitMode() called twice");
     106        }
     107        exitMode();
     108        if (getValue("active") != Boolean.FALSE) {
     109            throw new IllegalStateException("exitMode() did not call super.");
     110        }
     111    }
     112
    82113    protected void updateStatusLine() {
    83114        Main.map.statusLine.setHelpText(getModeHelpText());
    84115        Main.map.statusLine.repaint();
  • src/org/openstreetmap/josm/gui/MapFrame.java

    diff --git a/src/org/openstreetmap/josm/gui/MapFrame.java b/src/org/openstreetmap/josm/gui/MapFrame.java
    index 9a12018..2dc64c6 100644
    a b public class MapFrame extends JPanel implements Destroyable, ActiveLayerChangeLi 
    447447        if (newMapMode == oldMapMode)
    448448            return true;
    449449        if (oldMapMode != null) {
    450             oldMapMode.exitMode();
     450            oldMapMode.exitModeCallCheck();
    451451        }
    452452        this.mapMode = newMapMode;
    453         newMapMode.enterMode();
     453        newMapMode.enterModeCallCheck();
    454454        lastMapMode.put(newLayer, newMapMode);
    455455        fireMapModeChanged(oldMapMode, newMapMode);
    456456        return true;
    public class MapFrame extends JPanel implements Destroyable, ActiveLayerChangeLi 
    774774                // but it don't work well with for example editgpx layer
    775775                selectMapMode(newMapMode, newLayer);
    776776            } else if (mapMode != null) {
    777                 mapMode.exitMode(); // if new mode is null - simply exit from previous mode
     777                mapMode.exitModeCallCheck(); // if new mode is null - simply exit from previous mode
    778778                mapMode = null;
    779779            }
    780780        }
    public class MapFrame extends JPanel implements Destroyable, ActiveLayerChangeLi 
    782782        if (e.getPreviousActiveLayer() != null) {
    783783            if (!modeChanged && mapMode != null) {
    784784                // Let mapmodes know about new active layer
    785                 mapMode.exitMode();
    786                 mapMode.enterMode();
     785                mapMode.exitModeCallCheck();
     786                mapMode.enterModeCallCheck();
    787787            }
    788788            // invalidate repaint cache
    789789            mapView.preferenceChanged(null);