1 | // License: GPL. See LICENSE file for details.
|
---|
2 | package org.openstreetmap.josm.actions.mapmode;
|
---|
3 |
|
---|
4 | import java.awt.Cursor;
|
---|
5 | import java.awt.event.ActionEvent;
|
---|
6 | import java.awt.event.InputEvent;
|
---|
7 | import java.awt.event.MouseEvent;
|
---|
8 | import java.awt.event.MouseListener;
|
---|
9 | import java.awt.event.MouseMotionListener;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
13 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
14 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * A class implementing MapMode is able to be selected as an mode for map editing.
|
---|
20 | * As example scrolling the map is a MapMode, connecting Nodes to new Ways
|
---|
21 | * is another.
|
---|
22 | *
|
---|
23 | * MapModes should register/deregister all necessary listeners on the map's view
|
---|
24 | * control.
|
---|
25 | */
|
---|
26 | abstract public class MapMode extends JosmAction implements MouseListener, MouseMotionListener {
|
---|
27 | protected final Cursor cursor;
|
---|
28 | protected boolean ctrl;
|
---|
29 | protected boolean alt;
|
---|
30 | protected boolean shift;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Constructor for mapmodes without an menu
|
---|
34 | */
|
---|
35 | public MapMode(String name, String iconName, String tooltip, Shortcut shortcut, MapFrame mapFrame, Cursor cursor) {
|
---|
36 | super(name, "mapmode/"+iconName, tooltip, shortcut, false);
|
---|
37 | this.cursor = cursor;
|
---|
38 | putValue("active", false);
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Constructor for mapmodes with an menu (no shortcut will be registered)
|
---|
43 | */
|
---|
44 | public MapMode(String name, String iconName, String tooltip, MapFrame mapFrame, Cursor cursor) {
|
---|
45 | putValue(NAME, name);
|
---|
46 | putValue(SMALL_ICON, ImageProvider.get("mapmode", iconName));
|
---|
47 | putValue(SHORT_DESCRIPTION, tooltip);
|
---|
48 | this.cursor = cursor;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public void enterMode() {
|
---|
52 | putValue("active", true);
|
---|
53 | Main.map.mapView.setNewCursor(cursor, this);
|
---|
54 | updateStatusLine();
|
---|
55 | }
|
---|
56 | public void exitMode() {
|
---|
57 | putValue("active", false);
|
---|
58 | Main.map.mapView.resetCursor(this);
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected void updateStatusLine() {
|
---|
62 | Main.map.statusLine.setHelpText(getModeHelpText());
|
---|
63 | Main.map.statusLine.repaint();
|
---|
64 | }
|
---|
65 |
|
---|
66 | public String getModeHelpText() {
|
---|
67 | return "";
|
---|
68 | }
|
---|
69 | /**
|
---|
70 | * Call selectMapMode(this) on the parent mapFrame.
|
---|
71 | */
|
---|
72 | public void actionPerformed(ActionEvent e) {
|
---|
73 | if (Main.isDisplayingMapView()) {
|
---|
74 | Main.map.selectMapMode(this);
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | // By default, all tools will work with all layers. Can be overwritten to require
|
---|
79 | // a special type of layer
|
---|
80 | public boolean layerIsSupported(Layer l) {
|
---|
81 | return true;
|
---|
82 | }
|
---|
83 |
|
---|
84 | protected void updateKeyModifiers(InputEvent e) {
|
---|
85 | updateKeyModifiers(e.getModifiers());
|
---|
86 | }
|
---|
87 |
|
---|
88 | protected void updateKeyModifiers(MouseEvent e) {
|
---|
89 | updateKeyModifiers(e.getModifiers());
|
---|
90 | }
|
---|
91 |
|
---|
92 | protected void updateKeyModifiers(int modifiers) {
|
---|
93 | ctrl = (modifiers & ActionEvent.CTRL_MASK) != 0;
|
---|
94 | alt = (modifiers & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0;
|
---|
95 | shift = (modifiers & ActionEvent.SHIFT_MASK) != 0;
|
---|
96 | }
|
---|
97 |
|
---|
98 | public void mouseReleased(MouseEvent e) {}
|
---|
99 | public void mouseExited(MouseEvent e) {}
|
---|
100 | public void mousePressed(MouseEvent e) {}
|
---|
101 | public void mouseClicked(MouseEvent e) {}
|
---|
102 | public void mouseEntered(MouseEvent e) {}
|
---|
103 | public void mouseMoved(MouseEvent e) {}
|
---|
104 | public void mouseDragged(MouseEvent e) {}
|
---|
105 | }
|
---|