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

Last change on this file since 4327 was 4327, checked in by xeen, 14 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: 2.6 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions.mapmode;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Cursor;
7import java.awt.Point;
8import java.awt.event.MouseEvent;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.coor.EastNorth;
12import org.openstreetmap.josm.gui.layer.markerlayer.PlayHeadMarker;
13
14/**
15 * Singleton marker class to track position of audio.
16 *
17 * @author david.earl
18 *
19 */
20public class PlayHeadDragMode extends MapMode {
21
22 private boolean dragging = false;
23 private Point mousePos = null;
24 private Point mouseStart = null;
25 private PlayHeadMarker playHeadMarker = null;
26
27 public PlayHeadDragMode(PlayHeadMarker m) {
28 super(tr("Drag play head"), "playheaddrag", tr("Drag play head"), null,
29 Main.map, Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
30 playHeadMarker = m;
31 }
32
33 @Override public void enterMode() {
34 super.enterMode();
35 Main.map.mapView.addMouseListener(this);
36 Main.map.mapView.addMouseMotionListener(this);
37 }
38
39 @Override public void exitMode() {
40 super.exitMode();
41 Main.map.mapView.removeMouseListener(this);
42 Main.map.mapView.removeMouseMotionListener(this);
43 }
44
45 @Override public void mousePressed(MouseEvent ev) {
46 mouseStart = mousePos = ev.getPoint();
47 }
48
49 @Override public void mouseDragged(MouseEvent ev) {
50 if (mouseStart == null || mousePos == null) return;
51 if ((ev.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) return;
52 Point p = ev.getPoint();
53 if (p == null) return;
54 if (! dragging) {
55 if (p.distance(mouseStart) < 3) return;
56 playHeadMarker.startDrag();
57 dragging = true;
58 }
59 if (p.distance(mousePos) == 0) return;
60 playHeadMarker.drag(Main.map.mapView.getEastNorth(ev.getX(), ev.getY()));
61 mousePos = p;
62 }
63
64 @Override public void mouseReleased(MouseEvent ev) {
65 Point p = ev.getPoint();
66 mouseStart = null;
67 if (ev.getButton() != MouseEvent.BUTTON1 || p == null || ! dragging)
68 return;
69
70 updateKeyModifiers(ev);
71
72 EastNorth en = Main.map.mapView.getEastNorth(ev.getX(), ev.getY());
73 if (! shift) {
74 playHeadMarker.reposition(en);
75 } else {
76 playHeadMarker.synchronize(en);
77 }
78 mousePos = null;
79 dragging = false;
80 }
81
82 @Override public String getModeHelpText() {
83 return tr("Drag play head and release near track to play audio from there; SHIFT+release to synchronize audio at that point.");
84 }
85}
Note: See TracBrowser for help on using the repository browser.