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

Last change on this file since 4327 was 4327, checked in by xeen, 13 years ago

updates visual appearance of highlights and adds them to select and delete action

in more detail:

  • add target highlighting to select action
  • add target cursor to select action
  • add target highlighting to delete action
  • unify ctrl/alt/shift modifier detection in MapMode actions
  • highlights are now a halo around the way/node instead of a color change
  • default highlight color is now the same as the select color (red)
  • ability to highlight WaySegments and VirtualNodes
  • various style/whitespace nits
  • fixes #2411

This patch touches a lot of areas, so please report any regressions in the map mode
tools. Also please add a comment to #2411 if you find to highlighting in select
mode distracting, so it can be fine tuned (or turned off by default).

  • Property svn:eol-style set to native
File size: 3.4 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.InputEvent;
7import java.awt.event.MouseEvent;
8import java.awt.event.MouseListener;
9import java.awt.event.MouseMotionListener;
10
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.actions.JosmAction;
13import org.openstreetmap.josm.gui.MapFrame;
14import org.openstreetmap.josm.gui.layer.Layer;
15import org.openstreetmap.josm.tools.ImageProvider;
16import 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 */
26abstract 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.map != null)
74 Main.map.selectMapMode(this);
75 }
76
77 // By default, all tools will work with all layers. Can be overwritten to require
78 // a special type of layer
79 public boolean layerIsSupported(Layer l) {
80 return true;
81 }
82
83 protected void updateKeyModifiers(InputEvent e) {
84 updateKeyModifiers(e.getModifiers());
85 }
86
87 protected void updateKeyModifiers(MouseEvent e) {
88 updateKeyModifiers(e.getModifiers());
89 }
90
91 protected void updateKeyModifiers(int modifiers) {
92 ctrl = (modifiers & ActionEvent.CTRL_MASK) != 0;
93 alt = (modifiers & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0;
94 shift = (modifiers & ActionEvent.SHIFT_MASK) != 0;
95 }
96
97 public void mouseReleased(MouseEvent e) {}
98 public void mouseExited(MouseEvent e) {}
99 public void mousePressed(MouseEvent e) {}
100 public void mouseClicked(MouseEvent e) {}
101 public void mouseEntered(MouseEvent e) {}
102 public void mouseMoved(MouseEvent e) {}
103 public void mouseDragged(MouseEvent e) {}
104}
Note: See TracBrowser for help on using the repository browser.