| 1 | package org.openstreetmap.josm.actions;
|
|---|
| 2 |
|
|---|
| 3 | import java.awt.event.ActionEvent;
|
|---|
| 4 |
|
|---|
| 5 | import javax.swing.AbstractAction;
|
|---|
| 6 | import javax.swing.ImageIcon;
|
|---|
| 7 |
|
|---|
| 8 | import org.openstreetmap.josm.gui.MapFrame;
|
|---|
| 9 | import org.openstreetmap.josm.gui.MapView;
|
|---|
| 10 |
|
|---|
| 11 | /**
|
|---|
| 12 | * A class implementing MapMode is able to be selected as an mode for map editing.
|
|---|
| 13 | * As example scrolling the map is a MapMode, connecting Nodes to new LineSegments
|
|---|
| 14 | * is another.
|
|---|
| 15 | *
|
|---|
| 16 | * MapModes should register/deregister all necessary listener on the map's view
|
|---|
| 17 | * control.
|
|---|
| 18 | */
|
|---|
| 19 | abstract public class MapMode extends AbstractAction {
|
|---|
| 20 |
|
|---|
| 21 | /**
|
|---|
| 22 | * The parent mapframe this mode belongs to.
|
|---|
| 23 | */
|
|---|
| 24 | protected final MapFrame mapFrame;
|
|---|
| 25 |
|
|---|
| 26 | /**
|
|---|
| 27 | * Construct a mapMode with the given icon and the given MapFrame
|
|---|
| 28 | *
|
|---|
| 29 | * @param iconName The filename of the icon.
|
|---|
| 30 | * @param mapFrame The parent MapFrame, this MapMode belongs to.
|
|---|
| 31 | */
|
|---|
| 32 | public MapMode(String name, String iconName, int mnemonic, MapFrame mapFrame) {
|
|---|
| 33 | super(name, new ImageIcon(iconName));
|
|---|
| 34 | putValue(MNEMONIC_KEY, mnemonic);
|
|---|
| 35 | this.mapFrame = mapFrame;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | /**
|
|---|
| 39 | * Register all listener to the mapView
|
|---|
| 40 | * @param mapView The view, where the listener should be registered.
|
|---|
| 41 | */
|
|---|
| 42 | abstract public void registerListener(MapView mapView);
|
|---|
| 43 |
|
|---|
| 44 | /**
|
|---|
| 45 | * Unregister all listener previously registered.
|
|---|
| 46 | * @param mapView The view from which the listener should be deregistered.
|
|---|
| 47 | */
|
|---|
| 48 | abstract public void unregisterListener(MapView mapView);
|
|---|
| 49 |
|
|---|
| 50 | /**
|
|---|
| 51 | * Call selectMapMode(this) on the parent mapFrame.
|
|---|
| 52 | */
|
|---|
| 53 | public void actionPerformed(ActionEvent e) {
|
|---|
| 54 | mapFrame.selectMapMode(this);
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|