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

File patch-map-mode-consistency.patch, 4.9 KB (added by michael2402, 8 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..b4418be 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     */
     79    public final void enterModeCallCheck() {
     80        if (getValue("active") != Boolean.FALSE) {
     81            throw new IllegalStateException("enterMode() called twice");
     82        }
     83        enterMode();
     84        if (getValue("active") != Boolean.TRUE) {
     85            throw new IllegalStateException("enterMode() did not call super.");
     86        }
     87    }
     88
     89    /**
     90     * Makes this map mode inactive. This may never fail. Super needs to be called if implementations override this method.
    7591     */
    7692    public void exitMode() {
    7793        putValue("active", Boolean.FALSE);
    public abstract class MapMode extends JosmAction implements MouseListener, Mouse  
    7995        Main.map.mapView.resetCursor(this);
    8096    }
    8197
     98    /**
     99     * Calls {@link #exitMode()}. Checks the state.
     100     */
     101    public final void exitModeCallCheck() {
     102        if (getValue("active") != Boolean.TRUE) {
     103            throw new IllegalStateException("exitMode() called twice");
     104        }
     105        exitMode();
     106        if (getValue("active") != Boolean.FALSE) {
     107            throw new IllegalStateException("exitMode() did not call super.");
     108        }
     109    }
     110
    82111    protected void updateStatusLine() {
    83112        Main.map.statusLine.setHelpText(getModeHelpText());
    84113        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);