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