| 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.Graphics;
|
|---|
| 8 | import java.awt.Insets;
|
|---|
| 9 | import java.awt.Point;
|
|---|
| 10 | import java.awt.Rectangle;
|
|---|
| 11 | import java.awt.event.ActionEvent;
|
|---|
| 12 | import java.awt.event.ActionListener;
|
|---|
| 13 | import java.awt.event.MouseAdapter;
|
|---|
| 14 | import java.awt.event.MouseListener;
|
|---|
| 15 | import java.awt.event.MouseMotionAdapter;
|
|---|
| 16 | import java.awt.event.MouseEvent;
|
|---|
| 17 | import java.awt.event.MouseMotionListener;
|
|---|
| 18 | import java.io.IOException;
|
|---|
| 19 | import java.net.URL;
|
|---|
| 20 | import java.util.Collection;
|
|---|
| 21 | import java.util.Iterator;
|
|---|
| 22 |
|
|---|
| 23 | import javax.swing.BorderFactory;
|
|---|
| 24 | import javax.swing.Icon;
|
|---|
| 25 | import javax.swing.JOptionPane;
|
|---|
| 26 | import javax.swing.Timer;
|
|---|
| 27 | import javax.swing.border.BevelBorder;
|
|---|
| 28 | import javax.swing.border.Border;
|
|---|
| 29 |
|
|---|
| 30 | import org.openstreetmap.josm.Main;
|
|---|
| 31 | import org.openstreetmap.josm.actions.mapmode.SelectAction.Mode;
|
|---|
| 32 | import org.openstreetmap.josm.data.coor.LatLon;
|
|---|
| 33 | import org.openstreetmap.josm.tools.AudioPlayer;
|
|---|
| 34 | import org.openstreetmap.josm.data.gpx.GpxTrack;
|
|---|
| 35 | import org.openstreetmap.josm.data.gpx.WayPoint;
|
|---|
| 36 | import org.openstreetmap.josm.data.coor.EastNorth;
|
|---|
| 37 | import org.openstreetmap.josm.gui.MapFrame;
|
|---|
| 38 | import org.openstreetmap.josm.gui.layer.markerlayer.PlayHeadMarker;
|
|---|
| 39 | import org.openstreetmap.josm.gui.MapView;
|
|---|
| 40 | import org.openstreetmap.josm.gui.layer.GpxLayer;
|
|---|
| 41 |
|
|---|
| 42 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 43 |
|
|---|
| 44 | /**
|
|---|
| 45 | * Singleton marker class to track position of audio.
|
|---|
| 46 | *
|
|---|
| 47 | * @author david.earl
|
|---|
| 48 | *
|
|---|
| 49 | */
|
|---|
| 50 | public class PlayHeadDragMode extends MapMode {
|
|---|
| 51 |
|
|---|
| 52 | private boolean dragging = false;
|
|---|
| 53 | private Point mousePos = null;
|
|---|
| 54 | private Point mouseStart = null;
|
|---|
| 55 | private PlayHeadMarker playHeadMarker = null;
|
|---|
| 56 |
|
|---|
| 57 | public PlayHeadDragMode(PlayHeadMarker m) {
|
|---|
| 58 | super("play head drag", "playheaddrag", "play head trag", 0, Main.map, Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
|
|---|
| 59 | playHeadMarker = m;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | @Override public void enterMode() {
|
|---|
| 63 | super.enterMode();
|
|---|
| 64 | Main.map.mapView.addMouseListener(this);
|
|---|
| 65 | Main.map.mapView.addMouseMotionListener(this);
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | @Override public void exitMode() {
|
|---|
| 69 | super.exitMode();
|
|---|
| 70 | Main.map.mapView.removeMouseListener(this);
|
|---|
| 71 | Main.map.mapView.removeMouseMotionListener(this);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | @Override public void mousePressed(MouseEvent ev) {
|
|---|
| 75 | mouseStart = mousePos = ev.getPoint();
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | @Override public void mouseDragged(MouseEvent ev) {
|
|---|
| 79 | if (mouseStart == null || mousePos == null) return;
|
|---|
| 80 | if ((ev.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) return;
|
|---|
| 81 | Point p = ev.getPoint();
|
|---|
| 82 | if (p == null) return;
|
|---|
| 83 | if (! dragging) {
|
|---|
| 84 | if (p.distance(mouseStart) < 3) return;
|
|---|
| 85 | playHeadMarker.startDrag();
|
|---|
| 86 | dragging = true;
|
|---|
| 87 | }
|
|---|
| 88 | if (p.distance(mousePos) == 0) return;
|
|---|
| 89 | playHeadMarker.drag(Main.map.mapView.getEastNorth(ev.getX(), ev.getY()));
|
|---|
| 90 | mousePos = p;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | @Override public void mouseReleased(MouseEvent ev) {
|
|---|
| 94 | Point p = ev.getPoint();
|
|---|
| 95 | mouseStart = null;
|
|---|
| 96 | if (ev.getButton() != MouseEvent.BUTTON1 || p == null || ! dragging)
|
|---|
| 97 | return;
|
|---|
| 98 | boolean shift = (ev.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
|
|---|
| 99 | EastNorth en = Main.map.mapView.getEastNorth(ev.getX(), ev.getY());
|
|---|
| 100 | if (! shift) {
|
|---|
| 101 | playHeadMarker.reposition(en);
|
|---|
| 102 | } else {
|
|---|
| 103 | playHeadMarker.synchronize(en);
|
|---|
| 104 | }
|
|---|
| 105 | mousePos = null;
|
|---|
| 106 | dragging = false;
|
|---|
| 107 |
|
|---|
| 108 | /*
|
|---|
| 109 | boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
|
|---|
| 110 | boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
|
|---|
| 111 | */
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | @Override public String getModeHelpText() {
|
|---|
| 115 | return tr("Drag play head and release near track to play audio from there; SHIFT+release to synchronize audio at that point.");
|
|---|
| 116 | }
|
|---|
| 117 | }
|
|---|