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

Last change on this file since 3747 was 2017, checked in by Gubaer, 15 years ago

removed OptionPaneUtil
cleanup of deprecated Layer API
cleanup of deprecated APIs in OsmPrimitive and Way
cleanup of imports

  • Property svn:eol-style set to native
File size: 2.8 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.gui.layer.Layer;
14import org.openstreetmap.josm.tools.ImageProvider;
15import org.openstreetmap.josm.tools.Shortcut;
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 Ways
20 * is another.
21 *
22 * MapModes should register/deregister all necessary listeners on the map's view
23 * control.
24 */
25abstract public class MapMode extends JosmAction implements MouseListener, MouseMotionListener {
26 private final Cursor cursor;
27 private Cursor oldCursor;
28
29 /**
30 * Constructor for mapmodes without an menu
31 */
32 public MapMode(String name, String iconName, String tooltip, Shortcut shortcut, MapFrame mapFrame, Cursor cursor) {
33 super(name, "mapmode/"+iconName, tooltip, shortcut, false);
34 this.cursor = cursor;
35 putValue("active", false);
36 }
37
38 /**
39 * Constructor for mapmodes with an menu (no shortcut will be registered)
40 */
41 public MapMode(String name, String iconName, String tooltip, MapFrame mapFrame, Cursor cursor) {
42 putValue(NAME, name);
43 putValue(SMALL_ICON, ImageProvider.get("mapmode", iconName));
44 putValue(SHORT_DESCRIPTION, tooltip);
45 this.cursor = cursor;
46 }
47
48 public void enterMode() {
49 putValue("active", true);
50 oldCursor = Main.map.mapView.getCursor();
51 Main.map.mapView.setCursor(cursor);
52 updateStatusLine();
53 }
54 public void exitMode() {
55 putValue("active", false);
56 Main.map.mapView.setCursor(oldCursor);
57 }
58
59 protected void updateStatusLine() {
60 Main.map.statusLine.setHelpText(getModeHelpText());
61 Main.map.statusLine.repaint();
62 }
63
64 public String getModeHelpText() {
65 return "";
66 }
67 /**
68 * Call selectMapMode(this) on the parent mapFrame.
69 */
70 public void actionPerformed(ActionEvent e) {
71 if (Main.map != null)
72 Main.map.selectMapMode(this);
73 }
74
75 // By default, all tools will work with all layers. Can be overwritten to require
76 // a special type of layer
77 public boolean layerIsSupported(Layer l) {
78 return true;
79 }
80
81 public void mouseReleased(MouseEvent e) {}
82 public void mouseExited(MouseEvent e) {}
83 public void mousePressed(MouseEvent e) {}
84 public void mouseClicked(MouseEvent e) {}
85 public void mouseEntered(MouseEvent e) {}
86 public void mouseMoved(MouseEvent e) {}
87 public void mouseDragged(MouseEvent e) {}
88}
Note: See TracBrowser for help on using the repository browser.