001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.preferences.audio;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.GridBagLayout;
007
008import javax.swing.Box;
009import javax.swing.JCheckBox;
010import javax.swing.JLabel;
011import javax.swing.JPanel;
012
013import org.openstreetmap.josm.Main;
014import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
015import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
016import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
017import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
018import org.openstreetmap.josm.gui.widgets.JosmTextField;
019import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
020import org.openstreetmap.josm.tools.GBC;
021
022/**
023 * Audio preferences.
024 */
025public final class AudioPreference extends DefaultTabPreferenceSetting {
026
027    /**
028     * Factory used to create a new {@code AudioPreference}.
029     */
030    public static class Factory implements PreferenceSettingFactory {
031        @Override
032        public PreferenceSetting createPreferenceSetting() {
033            return new AudioPreference();
034        }
035    }
036
037    private AudioPreference() {
038        super(/* ICON(preferences/) */ "audio", tr("Audio Settings"), tr("Settings for the audio player and audio markers."));
039    }
040
041    private final JCheckBox audioMenuVisible = new JCheckBox(tr("Display the Audio menu."));
042    private final JCheckBox markerButtonLabels = new JCheckBox(tr("Label audio (and image and web) markers."));
043    private final JCheckBox markerAudioTraceVisible = new JCheckBox(tr("Display live audio trace."));
044
045    // various methods of making markers on import audio
046    private final JCheckBox audioMarkersFromExplicitWaypoints = new JCheckBox(tr("Explicit waypoints with valid timestamps."));
047    private final JCheckBox audioMarkersFromUntimedWaypoints = new JCheckBox(tr("Explicit waypoints with time estimated from track position."));
048    private final JCheckBox audioMarkersFromNamedTrackpoints = new JCheckBox(tr("Named trackpoints."));
049    private final JCheckBox audioMarkersFromWavTimestamps = new JCheckBox(tr("Modified times (time stamps) of audio files."));
050    private final JCheckBox audioMarkersFromStart = new JCheckBox(tr("Start of track (will always do this if no other markers available)."));
051
052    private final JosmTextField audioLeadIn = new JosmTextField(8);
053    private final JosmTextField audioForwardBackAmount = new JosmTextField(8);
054    private final JosmTextField audioFastForwardMultiplier = new JosmTextField(8);
055    private final JosmTextField audioCalibration = new JosmTextField(8);
056
057    @Override
058    public void addGui(PreferenceTabbedPane gui) {
059        JPanel audio = new VerticallyScrollablePanel(new GridBagLayout());
060
061        // audioMenuVisible
062        audioMenuVisible.setSelected(!Main.pref.getBoolean("audio.menuinvisible"));
063        audioMenuVisible.setToolTipText(tr("Show or hide the audio menu entry on the main menu bar."));
064        audio.add(audioMenuVisible, GBC.eol().insets(0, 0, 0, 0));
065
066        // audioTraceVisible
067        markerAudioTraceVisible.setSelected(Main.pref.getBoolean("marker.traceaudio", true));
068        markerAudioTraceVisible.setToolTipText(
069                tr("Display a moving icon representing the point on the synchronized track where the audio currently playing was recorded."));
070        audio.add(markerAudioTraceVisible, GBC.eol().insets(0, 0, 0, 0));
071
072        // buttonLabels
073        markerButtonLabels.setSelected(Main.pref.getBoolean("marker.buttonlabels", true));
074        markerButtonLabels.setToolTipText(tr("Put text labels against audio (and image and web) markers as well as their button icons."));
075        audio.add(markerButtonLabels, GBC.eol().insets(0, 0, 0, 0));
076
077        audio.add(new JLabel(tr("When importing audio, make markers from...")), GBC.eol());
078
079        // audioMarkersFromExplicitWaypoints
080        audioMarkersFromExplicitWaypoints.setSelected(Main.pref.getBoolean("marker.audiofromexplicitwaypoints", true));
081        audioMarkersFromExplicitWaypoints.setToolTipText(tr("When importing audio, apply it to any waypoints in the GPX layer."));
082        audio.add(audioMarkersFromExplicitWaypoints, GBC.eol().insets(10, 0, 0, 0));
083
084        // audioMarkersFromUntimedWaypoints
085        audioMarkersFromUntimedWaypoints.setSelected(Main.pref.getBoolean("marker.audiofromuntimedwaypoints", true));
086        audioMarkersFromUntimedWaypoints.setToolTipText(tr("When importing audio, apply it to any waypoints in the GPX layer."));
087        audio.add(audioMarkersFromUntimedWaypoints, GBC.eol().insets(10, 0, 0, 0));
088
089        // audioMarkersFromNamedTrackpoints
090        audioMarkersFromNamedTrackpoints.setSelected(Main.pref.getBoolean("marker.audiofromnamedtrackpoints", false));
091        audioMarkersFromNamedTrackpoints.setToolTipText(
092                tr("Automatically create audio markers from trackpoints (rather than explicit waypoints) with names or descriptions."));
093        audio.add(audioMarkersFromNamedTrackpoints, GBC.eol().insets(10, 0, 0, 0));
094
095        // audioMarkersFromWavTimestamps
096        audioMarkersFromWavTimestamps.setSelected(Main.pref.getBoolean("marker.audiofromwavtimestamps", false));
097        audioMarkersFromWavTimestamps.setToolTipText(
098                tr("Create audio markers at the position on the track corresponding to the modified time of each audio WAV file imported."));
099        audio.add(audioMarkersFromWavTimestamps, GBC.eol().insets(10, 0, 0, 0));
100
101        // audioMarkersFromStart
102        audioMarkersFromStart.setSelected(Main.pref.getBoolean("marker.audiofromstart"));
103        audioMarkersFromStart.setToolTipText(
104                tr("Automatically create audio markers from trackpoints (rather than explicit waypoints) with names or descriptions."));
105        audio.add(audioMarkersFromStart, GBC.eol().insets(10, 0, 0, 0));
106
107        audioForwardBackAmount.setText(Main.pref.get("audio.forwardbackamount", "10.0"));
108        audioForwardBackAmount.setToolTipText(tr("The number of seconds to jump forward or back when the relevant button is pressed"));
109        audio.add(new JLabel(tr("Forward/back time (seconds)")), GBC.std());
110        audio.add(audioForwardBackAmount, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
111
112        audioFastForwardMultiplier.setText(Main.pref.get("audio.fastfwdmultiplier", "1.3"));
113        audioFastForwardMultiplier.setToolTipText(tr("The amount by which the speed is multiplied for fast forwarding"));
114        audio.add(new JLabel(tr("Fast forward multiplier")), GBC.std());
115        audio.add(audioFastForwardMultiplier, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
116
117        audioLeadIn.setText(Main.pref.get("audio.leadin", "1.0"));
118        audioLeadIn.setToolTipText(
119                tr("Playback starts this number of seconds before (or after, if negative) the audio track position requested"));
120        audio.add(new JLabel(tr("Lead-in time (seconds)")), GBC.std());
121        audio.add(audioLeadIn, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
122
123        audioCalibration.setText(Main.pref.get("audio.calibration", "1.0"));
124        audioCalibration.setToolTipText(tr("The ratio of voice recorder elapsed time to true elapsed time"));
125        audio.add(new JLabel(tr("Voice recorder calibration")), GBC.std());
126        audio.add(audioCalibration, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
127
128        audio.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
129
130        createPreferenceTabWithScrollPane(gui, audio);
131    }
132
133    @Override
134    public boolean ok() {
135        Main.pref.put("audio.menuinvisible", !audioMenuVisible.isSelected());
136        Main.pref.put("marker.traceaudio", markerAudioTraceVisible.isSelected());
137        Main.pref.put("marker.buttonlabels", markerButtonLabels.isSelected());
138        Main.pref.put("marker.audiofromexplicitwaypoints", audioMarkersFromExplicitWaypoints.isSelected());
139        Main.pref.put("marker.audiofromuntimedwaypoints", audioMarkersFromUntimedWaypoints.isSelected());
140        Main.pref.put("marker.audiofromnamedtrackpoints", audioMarkersFromNamedTrackpoints.isSelected());
141        Main.pref.put("marker.audiofromwavtimestamps", audioMarkersFromWavTimestamps.isSelected());
142        Main.pref.put("marker.audiofromstart", audioMarkersFromStart.isSelected());
143        Main.pref.put("audio.forwardbackamount", audioForwardBackAmount.getText());
144        Main.pref.put("audio.fastfwdmultiplier", audioFastForwardMultiplier.getText());
145        Main.pref.put("audio.leadin", audioLeadIn.getText());
146        Main.pref.put("audio.calibration", audioCalibration.getText());
147        return false;
148    }
149}