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

Last change on this file since 6380 was 6380, checked in by Don-vip, 11 years ago

update license/copyright information

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
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 /**
28 * Constructs a new {@code PlayHeadDragMode}.
29 * @param m Audio marker
30 */
31 public PlayHeadDragMode(PlayHeadMarker m) {
32 super(tr("Drag play head"), "playheaddrag", tr("Drag play head"), null,
33 Main.map, Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
34 playHeadMarker = m;
35 }
36
37 @Override public void enterMode() {
38 super.enterMode();
39 Main.map.mapView.addMouseListener(this);
40 Main.map.mapView.addMouseMotionListener(this);
41 }
42
43 @Override public void exitMode() {
44 super.exitMode();
45 Main.map.mapView.removeMouseListener(this);
46 Main.map.mapView.removeMouseMotionListener(this);
47 }
48
49 @Override public void mousePressed(MouseEvent ev) {
50 mouseStart = mousePos = ev.getPoint();
51 }
52
53 @Override public void mouseDragged(MouseEvent ev) {
54 if (mouseStart == null || mousePos == null) return;
55 if ((ev.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) return;
56 Point p = ev.getPoint();
57 if (! dragging) {
58 if (p.distance(mouseStart) < 3) return;
59 playHeadMarker.startDrag();
60 dragging = true;
61 }
62 if (p.distance(mousePos) == 0) return;
63 playHeadMarker.drag(Main.map.mapView.getEastNorth(ev.getX(), ev.getY()));
64 mousePos = p;
65 }
66
67 @Override public void mouseReleased(MouseEvent ev) {
68 Point p = ev.getPoint();
69 mouseStart = null;
70 if (ev.getButton() != MouseEvent.BUTTON1 || p == null || ! dragging)
71 return;
72
73 requestFocusInMapView();
74 updateKeyModifiers(ev);
75
76 EastNorth en = Main.map.mapView.getEastNorth(ev.getX(), ev.getY());
77 if (! shift) {
78 playHeadMarker.reposition(en);
79 } else {
80 playHeadMarker.synchronize(en);
81 }
82 mousePos = null;
83 dragging = false;
84 }
85
86 @Override public String getModeHelpText() {
87 return tr("Drag play head and release near track to play audio from there; SHIFT+release to synchronize audio at that point.");
88 }
89}
Note: See TracBrowser for help on using the repository browser.