1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.gui.layer.markerlayer;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Graphics;
|
---|
7 | import java.awt.Point;
|
---|
8 | import java.awt.Rectangle;
|
---|
9 | import java.awt.event.ActionEvent;
|
---|
10 | import java.awt.event.ActionListener;
|
---|
11 | import java.io.IOException;
|
---|
12 | import java.net.URL;
|
---|
13 |
|
---|
14 | import javax.swing.Icon;
|
---|
15 | import javax.swing.JOptionPane;
|
---|
16 | import javax.swing.Timer;
|
---|
17 |
|
---|
18 | import org.openstreetmap.josm.Main;
|
---|
19 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
20 | import org.openstreetmap.josm.tools.AudioPlayer;
|
---|
21 | import org.openstreetmap.josm.data.gpx.WayPoint;
|
---|
22 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
23 | import org.openstreetmap.josm.gui.MapView;
|
---|
24 |
|
---|
25 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Marker class with audio playback capability.
|
---|
29 | *
|
---|
30 | * @author Frederik Ramm <frederik@remote.org>
|
---|
31 | *
|
---|
32 | */
|
---|
33 | public class AudioMarker extends ButtonMarker {
|
---|
34 |
|
---|
35 | private URL audioUrl;
|
---|
36 | private static AudioMarker recentlyPlayedMarker = null;
|
---|
37 | public double syncOffset;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Verifies the parameter whether a new AudioMarker can be created and return
|
---|
41 | * one or return <code>null</code>.
|
---|
42 | */
|
---|
43 | public static AudioMarker create(LatLon ll, String text, String url, MarkerLayer parentLayer, double time, double offset) {
|
---|
44 | try {
|
---|
45 | return new AudioMarker(ll, text, new URL(url), parentLayer, time, offset);
|
---|
46 | } catch (Exception ex) {
|
---|
47 | return null;
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | private AudioMarker(LatLon ll, String text, URL audioUrl, MarkerLayer parentLayer, double time, double offset) {
|
---|
52 | super(ll, text, "speech.png", parentLayer, time, offset);
|
---|
53 | this.audioUrl = audioUrl;
|
---|
54 | this.syncOffset = 0.0;
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override public void actionPerformed(ActionEvent ev) {
|
---|
58 | play();
|
---|
59 | }
|
---|
60 |
|
---|
61 | public static AudioMarker recentlyPlayedMarker() {
|
---|
62 | return recentlyPlayedMarker;
|
---|
63 | }
|
---|
64 |
|
---|
65 | public URL url() {
|
---|
66 | return audioUrl;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Starts playing the audio associated with the marker: used in response to pressing
|
---|
71 | * the marker as well as indirectly
|
---|
72 | *
|
---|
73 | */
|
---|
74 | public void play() {
|
---|
75 | try {
|
---|
76 | // first enable tracing the audio along the track
|
---|
77 | if (Main.pref.getBoolean("marker.traceaudio", true) && parentLayer != null) {
|
---|
78 | parentLayer.traceAudio();
|
---|
79 | }
|
---|
80 |
|
---|
81 | AudioPlayer.play(audioUrl, offset + syncOffset);
|
---|
82 | recentlyPlayedMarker = this;
|
---|
83 | } catch (Exception e) {
|
---|
84 | AudioPlayer.audioMalfunction(e);
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | public void adjustOffset(double adjustment) {
|
---|
89 | syncOffset = adjustment; // added to offset may turn out negative, but that's ok
|
---|
90 | }
|
---|
91 |
|
---|
92 | public double syncOffset() {
|
---|
93 | return syncOffset;
|
---|
94 | }
|
---|
95 |
|
---|
96 | public static String inventName (double offset) {
|
---|
97 | int wholeSeconds = (int)(offset + 0.5);
|
---|
98 | if (wholeSeconds < 60)
|
---|
99 | return Integer.toString(wholeSeconds);
|
---|
100 | else if (wholeSeconds < 3600)
|
---|
101 | return String.format("%d:%02d", wholeSeconds / 60, wholeSeconds % 60);
|
---|
102 | else
|
---|
103 | return String.format("%d:%02d:%02d", wholeSeconds / 3600, (wholeSeconds % 3600)/60, wholeSeconds % 60);
|
---|
104 | }
|
---|
105 | }
|
---|