1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions.mapmode;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Cursor;
|
---|
7 | import java.awt.Point;
|
---|
8 | import java.awt.event.ActionEvent;
|
---|
9 | import java.awt.event.MouseEvent;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
13 | import org.openstreetmap.josm.gui.layer.markerlayer.PlayHeadMarker;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Singleton marker class to track position of audio.
|
---|
17 | *
|
---|
18 | * @author david.earl
|
---|
19 | *
|
---|
20 | */
|
---|
21 | public class PlayHeadDragMode extends MapMode {
|
---|
22 |
|
---|
23 | private boolean dragging = false;
|
---|
24 | private Point mousePos = null;
|
---|
25 | private Point mouseStart = null;
|
---|
26 | private PlayHeadMarker playHeadMarker = null;
|
---|
27 |
|
---|
28 | public PlayHeadDragMode(PlayHeadMarker m) {
|
---|
29 | super("play head drag", "playheaddrag", "play head trag", 0, 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 | boolean shift = (ev.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
|
---|
70 | EastNorth en = Main.map.mapView.getEastNorth(ev.getX(), ev.getY());
|
---|
71 | if (! shift) {
|
---|
72 | playHeadMarker.reposition(en);
|
---|
73 | } else {
|
---|
74 | playHeadMarker.synchronize(en);
|
---|
75 | }
|
---|
76 | mousePos = null;
|
---|
77 | dragging = false;
|
---|
78 |
|
---|
79 | /*
|
---|
80 | boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
|
---|
81 | boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
|
---|
82 | */
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override public String getModeHelpText() {
|
---|
86 | return tr("Drag play head and release near track to play audio from there; SHIFT+release to synchronize audio at that point.");
|
---|
87 | }
|
---|
88 | }
|
---|