| 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(tr("Drag play head"), "playheaddrag", tr("Drag play head"), null,
|
|---|
| 30 | Main.map, Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
|
|---|
| 31 | playHeadMarker = m;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | @Override public void enterMode() {
|
|---|
| 35 | super.enterMode();
|
|---|
| 36 | Main.map.mapView.addMouseListener(this);
|
|---|
| 37 | Main.map.mapView.addMouseMotionListener(this);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | @Override public void exitMode() {
|
|---|
| 41 | super.exitMode();
|
|---|
| 42 | Main.map.mapView.removeMouseListener(this);
|
|---|
| 43 | Main.map.mapView.removeMouseMotionListener(this);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | @Override public void mousePressed(MouseEvent ev) {
|
|---|
| 47 | mouseStart = mousePos = ev.getPoint();
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | @Override public void mouseDragged(MouseEvent ev) {
|
|---|
| 51 | if (mouseStart == null || mousePos == null) return;
|
|---|
| 52 | if ((ev.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) return;
|
|---|
| 53 | Point p = ev.getPoint();
|
|---|
| 54 | if (p == null) return;
|
|---|
| 55 | if (! dragging) {
|
|---|
| 56 | if (p.distance(mouseStart) < 3) return;
|
|---|
| 57 | playHeadMarker.startDrag();
|
|---|
| 58 | dragging = true;
|
|---|
| 59 | }
|
|---|
| 60 | if (p.distance(mousePos) == 0) return;
|
|---|
| 61 | playHeadMarker.drag(Main.map.mapView.getEastNorth(ev.getX(), ev.getY()));
|
|---|
| 62 | mousePos = p;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | @Override public void mouseReleased(MouseEvent ev) {
|
|---|
| 66 | Point p = ev.getPoint();
|
|---|
| 67 | mouseStart = null;
|
|---|
| 68 | if (ev.getButton() != MouseEvent.BUTTON1 || p == null || ! dragging)
|
|---|
| 69 | return;
|
|---|
| 70 | boolean shift = (ev.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
|
|---|
| 71 | EastNorth en = Main.map.mapView.getEastNorth(ev.getX(), ev.getY());
|
|---|
| 72 | if (! shift) {
|
|---|
| 73 | playHeadMarker.reposition(en);
|
|---|
| 74 | } else {
|
|---|
| 75 | playHeadMarker.synchronize(en);
|
|---|
| 76 | }
|
|---|
| 77 | mousePos = null;
|
|---|
| 78 | dragging = false;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | @Override public String getModeHelpText() {
|
|---|
| 82 | return tr("Drag play head and release near track to play audio from there; SHIFT+release to synchronize audio at that point.");
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|