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