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;
|
10 | 10 | |
11 | 11 | import org.openstreetmap.josm.Main; |
12 | 12 | import org.openstreetmap.josm.actions.JosmAction; |
| 13 | import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; |
| 14 | import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; |
13 | 15 | import org.openstreetmap.josm.gui.MapFrame; |
14 | 16 | import org.openstreetmap.josm.gui.layer.Layer; |
15 | 17 | import org.openstreetmap.josm.tools.ImageProvider; |
16 | 18 | import org.openstreetmap.josm.tools.Shortcut; |
17 | | import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; |
18 | | import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * A class implementing MapMode is able to be selected as an mode for map editing. |
… |
… |
public abstract class MapMode extends JosmAction implements MouseListener, Mouse
|
56 | 56 | putValue(NAME, name); |
57 | 57 | putValue(SMALL_ICON, ImageProvider.get("mapmode", iconName)); |
58 | 58 | putValue(SHORT_DESCRIPTION, tooltip); |
| 59 | putValue("active", Boolean.FALSE); |
59 | 60 | this.cursor = cursor; |
60 | 61 | } |
61 | 62 | |
62 | 63 | /** |
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. |
64 | 67 | */ |
65 | 68 | public void enterMode() { |
66 | 69 | putValue("active", Boolean.TRUE); |
… |
… |
public abstract class MapMode extends JosmAction implements MouseListener, Mouse
|
71 | 74 | } |
72 | 75 | |
73 | 76 | /** |
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. |
75 | 91 | */ |
76 | 92 | public void exitMode() { |
77 | 93 | putValue("active", Boolean.FALSE); |
… |
… |
public abstract class MapMode extends JosmAction implements MouseListener, Mouse
|
79 | 95 | Main.map.mapView.resetCursor(this); |
80 | 96 | } |
81 | 97 | |
| 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 | |
82 | 111 | protected void updateStatusLine() { |
83 | 112 | Main.map.statusLine.setHelpText(getModeHelpText()); |
84 | 113 | Main.map.statusLine.repaint(); |
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
|
447 | 447 | if (newMapMode == oldMapMode) |
448 | 448 | return true; |
449 | 449 | if (oldMapMode != null) { |
450 | | oldMapMode.exitMode(); |
| 450 | oldMapMode.exitModeCallCheck(); |
451 | 451 | } |
452 | 452 | this.mapMode = newMapMode; |
453 | | newMapMode.enterMode(); |
| 453 | newMapMode.enterModeCallCheck(); |
454 | 454 | lastMapMode.put(newLayer, newMapMode); |
455 | 455 | fireMapModeChanged(oldMapMode, newMapMode); |
456 | 456 | return true; |
… |
… |
public class MapFrame extends JPanel implements Destroyable, ActiveLayerChangeLi
|
774 | 774 | // but it don't work well with for example editgpx layer |
775 | 775 | selectMapMode(newMapMode, newLayer); |
776 | 776 | } 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 |
778 | 778 | mapMode = null; |
779 | 779 | } |
780 | 780 | } |
… |
… |
public class MapFrame extends JPanel implements Destroyable, ActiveLayerChangeLi
|
782 | 782 | if (e.getPreviousActiveLayer() != null) { |
783 | 783 | if (!modeChanged && mapMode != null) { |
784 | 784 | // Let mapmodes know about new active layer |
785 | | mapMode.exitMode(); |
786 | | mapMode.enterMode(); |
| 785 | mapMode.exitModeCallCheck(); |
| 786 | mapMode.enterModeCallCheck(); |
787 | 787 | } |
788 | 788 | // invalidate repaint cache |
789 | 789 | mapView.preferenceChanged(null); |