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