1 | package org.openstreetmap.josm.actions.mapmode;
|
---|
2 |
|
---|
3 | import java.awt.event.ActionEvent;
|
---|
4 | import java.awt.event.MouseEvent;
|
---|
5 | import java.awt.event.MouseListener;
|
---|
6 | import java.awt.event.MouseMotionListener;
|
---|
7 |
|
---|
8 | import javax.swing.AbstractAction;
|
---|
9 | import javax.swing.JComponent;
|
---|
10 | import javax.swing.KeyStroke;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.gui.ImageProvider;
|
---|
13 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
14 | import org.openstreetmap.josm.gui.MapView;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * A class implementing MapMode is able to be selected as an mode for map editing.
|
---|
18 | * As example scrolling the map is a MapMode, connecting Nodes to new LineSegments
|
---|
19 | * is another.
|
---|
20 | *
|
---|
21 | * MapModes should register/deregister all necessary listener on the map's view
|
---|
22 | * control.
|
---|
23 | */
|
---|
24 | abstract public class MapMode extends AbstractAction implements MouseListener, MouseMotionListener {
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * The parent mapframe this mode belongs to.
|
---|
28 | */
|
---|
29 | protected final MapFrame mapFrame;
|
---|
30 | /**
|
---|
31 | * Shortcut to the MapView.
|
---|
32 | */
|
---|
33 | protected final MapView mv;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Construct a mapMode with the given icon and the given MapFrame
|
---|
37 | *
|
---|
38 | * @param iconName The filename of the icon.
|
---|
39 | * @param mapFrame The parent MapFrame, this MapMode belongs to.
|
---|
40 | */
|
---|
41 | public MapMode(String name, String iconName, String tooltip, int mnemonic, MapFrame mapFrame) {
|
---|
42 | super(name, ImageProvider.get("mapmode", iconName));
|
---|
43 | putValue(MNEMONIC_KEY, mnemonic);
|
---|
44 | putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(mnemonic,0));
|
---|
45 | putValue(LONG_DESCRIPTION, tooltip);
|
---|
46 | mapFrame.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(mnemonic,0), this);
|
---|
47 | mapFrame.getActionMap().put(this, this);
|
---|
48 | this.mapFrame = mapFrame;
|
---|
49 | mv = mapFrame.mapView;
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Register all listener to the mapView
|
---|
54 | * @param mapView The view, where the listener should be registered.
|
---|
55 | */
|
---|
56 | public void registerListener() {
|
---|
57 | firePropertyChange("active", false, true);
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Unregister all listener previously registered.
|
---|
62 | * @param mapView The view from which the listener should be deregistered.
|
---|
63 | */
|
---|
64 | public void unregisterListener() {
|
---|
65 | firePropertyChange("active", true, false);
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Call selectMapMode(this) on the parent mapFrame.
|
---|
70 | */
|
---|
71 | public void actionPerformed(ActionEvent e) {
|
---|
72 | mapFrame.selectMapMode(this);
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Does nothing. Only to subclass.
|
---|
77 | */
|
---|
78 | public void mouseClicked(MouseEvent e) {}
|
---|
79 | /**
|
---|
80 | * Does nothing. Only to subclass.
|
---|
81 | */
|
---|
82 | public void mousePressed(MouseEvent e) {}
|
---|
83 | /**
|
---|
84 | * Does nothing. Only to subclass.
|
---|
85 | */
|
---|
86 | public void mouseReleased(MouseEvent e) {}
|
---|
87 | /**
|
---|
88 | * Does nothing. Only to subclass.
|
---|
89 | */
|
---|
90 | public void mouseEntered(MouseEvent e) {}
|
---|
91 | /**
|
---|
92 | * Does nothing. Only to subclass.
|
---|
93 | */
|
---|
94 | public void mouseExited(MouseEvent e) {}
|
---|
95 | /**
|
---|
96 | * Does nothing. Only to subclass.
|
---|
97 | */
|
---|
98 | public void mouseMoved(MouseEvent e) {}
|
---|
99 | /**
|
---|
100 | * Does nothing. Only to subclass.
|
---|
101 | */
|
---|
102 | public void mouseDragged(MouseEvent e) {}
|
---|
103 | }
|
---|