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;
|
| 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 | * @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. |
| 75 | 92 | */ |
| 76 | 93 | public void exitMode() { |
| 77 | 94 | putValue("active", Boolean.FALSE); |
| … |
… |
public abstract class MapMode extends JosmAction implements MouseListener, Mouse
|
| 79 | 96 | Main.map.mapView.resetCursor(this); |
| 80 | 97 | } |
| 81 | 98 | |
| | 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 | |
| 82 | 113 | protected void updateStatusLine() { |
| 83 | 114 | Main.map.statusLine.setHelpText(getModeHelpText()); |
| 84 | 115 | 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); |