source: josm/trunk/src/org/openstreetmap/josm/actions/mapmode/MapMode.java@ 1047

Last change on this file since 1047 was 1023, checked in by stoecker, 16 years ago

close bug #1622. Keyboard shortcuts and specific OS handling

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.actions.mapmode;
3
4import java.awt.Cursor;
5import java.awt.event.ActionEvent;
6import java.awt.event.MouseEvent;
7import java.awt.event.MouseListener;
8import java.awt.event.MouseMotionListener;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.actions.JosmAction;
12import org.openstreetmap.josm.gui.MapFrame;
13import org.openstreetmap.josm.tools.ImageProvider;
14import org.openstreetmap.josm.tools.ShortCut;
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 Ways
19 * is another.
20 *
21 * MapModes should register/deregister all necessary listeners on the map's view
22 * control.
23 */
24abstract public class MapMode extends JosmAction implements MouseListener, MouseMotionListener {
25 private final Cursor cursor;
26 private Cursor oldCursor;
27
28 /**
29 * Constructor for mapmodes without an menu
30 */
31 public MapMode(String name, String iconName, String tooltip, ShortCut shortCut, MapFrame mapFrame, Cursor cursor) {
32 super(name, "mapmode/"+iconName, tooltip, shortCut, false);
33 this.cursor = cursor;
34 putValue("active", false);
35 }
36
37 /**
38 * Constructor for mapmodes without an menu
39 */
40 @Deprecated
41 public MapMode(String name, String iconName, String tooltip, int keystroke, MapFrame mapFrame, Cursor cursor) {
42 super(name, "mapmode/"+iconName, tooltip, keystroke, 0, false);
43 this.cursor = cursor;
44 putValue("active", false);
45 }
46
47 /**
48 * Constructor for mapmodes with an menu (no shortcut will be registered)
49 */
50 public MapMode(String name, String iconName, String tooltip, MapFrame mapFrame, Cursor cursor) {
51 putValue(NAME, name);
52 putValue(SMALL_ICON, ImageProvider.get("mapmode", iconName));
53 putValue(SHORT_DESCRIPTION, tooltip);
54 this.cursor = cursor;
55 }
56
57 public void enterMode() {
58 putValue("active", true);
59 oldCursor = Main.map.mapView.getCursor();
60 Main.map.mapView.setCursor(cursor);
61 updateStatusLine();
62 }
63 public void exitMode() {
64 putValue("active", false);
65 Main.map.mapView.setCursor(oldCursor);
66 }
67
68 protected void updateStatusLine() {
69 Main.map.statusLine.setHelpText(getModeHelpText());
70 Main.map.statusLine.repaint();
71 }
72
73 public String getModeHelpText() {
74 return "";
75 }
76 /**
77 * Call selectMapMode(this) on the parent mapFrame.
78 */
79 public void actionPerformed(ActionEvent e) {
80 if (Main.map != null)
81 Main.map.selectMapMode(this);
82 }
83
84 public void mouseReleased(MouseEvent e) {}
85 public void mouseExited(MouseEvent e) {}
86 public void mousePressed(MouseEvent e) {}
87 public void mouseClicked(MouseEvent e) {}
88 public void mouseEntered(MouseEvent e) {}
89 public void mouseMoved(MouseEvent e) {}
90 public void mouseDragged(MouseEvent e) {}
91}
Note: See TracBrowser for help on using the repository browser.