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

Last change on this file since 373 was 373, checked in by framm, 17 years ago
  • introduced various modifier keys to existing modes (for add node mode, shift to disable auto-connect and ctrl to disable auto-insert/reuse; for delete mode, shift to delete way segment and alt to delete way+nodes)
  • added small help bar at bottom of screen to display available modifiers
File size: 2.4 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
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;
14
15/**
16 * A class implementing MapMode is able to be selected as an mode for map editing.
17 * As example scrolling the map is a MapMode, connecting Nodes to new Ways
18 * is another.
19 *
20 * MapModes should register/deregister all necessary listener on the map's view
21 * control.
22 */
23abstract public class MapMode extends JosmAction implements MouseListener, MouseMotionListener {
24 private final Cursor cursor;
25 private Cursor oldCursor;
26
27 /**
28 * Constructor for mapmodes without an menu
29 */
30 public MapMode(String name, String iconName, String tooltip, int keystroke, MapFrame mapFrame, Cursor cursor) {
31 super(name, "mapmode/"+iconName, tooltip, keystroke, 0, false);
32 this.cursor = cursor;
33 putValue("active", false);
34 }
35
36 /**
37 * Constructor for mapmodes with an menu (no shortcut will be registered)
38 */
39 public MapMode(String name, String iconName, String tooltip, MapFrame mapFrame, Cursor cursor) {
40 putValue(NAME, name);
41 putValue(SMALL_ICON, ImageProvider.get("mapmode", iconName));
42 putValue(SHORT_DESCRIPTION, tooltip);
43 this.cursor = cursor;
44 }
45
46 public void enterMode() {
47 putValue("active", true);
48 oldCursor = Main.map.mapView.getCursor();
49 Main.map.mapView.setCursor(cursor);
50 updateStatusLine();
51 }
52 public void exitMode() {
53 putValue("active", false);
54 Main.map.mapView.setCursor(oldCursor);
55 }
56
57 protected void updateStatusLine() {
58 Main.map.statusLine.setHelpText(getModeHelpText());
59 }
60
61 public String getModeHelpText() {
62 return "";
63 }
64 /**
65 * Call selectMapMode(this) on the parent mapFrame.
66 */
67 public void actionPerformed(ActionEvent e) {
68 if (Main.map != null)
69 Main.map.selectMapMode(this);
70 }
71
72 public void mouseReleased(MouseEvent e) {}
73 public void mouseExited(MouseEvent e) {}
74 public void mousePressed(MouseEvent e) {}
75 public void mouseClicked(MouseEvent e) {}
76 public void mouseEntered(MouseEvent e) {}
77 public void mouseMoved(MouseEvent e) {}
78 public void mouseDragged(MouseEvent e) {}
79}
Note: See TracBrowser for help on using the repository browser.