001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.preferences;
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.widgets.JosmTextField;
015import org.openstreetmap.josm.tools.GBC;
016
017/*
018 * marker.audiosampleminsecs
019 * marker.audiosampleminmetres
020 * marker.buttonlabels
021 * markers.namedtrackpoints
022 * audio.forwardbackamount
023 * audio.leadin
024 * audio.menuinvisible
025 * marker.audiotraceVisible
026 * audio.toolbar ??
027 */
028
029public final class AudioPreference extends DefaultTabPreferenceSetting {
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("audio", tr("Audio Settings"), tr("Settings for the audio player and audio markers."));
040    }
041
042    private JCheckBox audioMenuVisible = new JCheckBox(tr("Display the Audio menu."));
043    private JCheckBox markerButtonLabels = new JCheckBox(tr("Label audio (and image and web) markers."));
044    private JCheckBox markerAudioTraceVisible = new JCheckBox(tr("Display live audio trace."));
045
046    // various methods of making markers on import audio
047    private JCheckBox audioMarkersFromExplicitWaypoints = new JCheckBox(tr("Explicit waypoints with valid timestamps."));
048    private JCheckBox audioMarkersFromUntimedWaypoints = new JCheckBox(tr("Explicit waypoints with time estimated from track position."));
049    private JCheckBox audioMarkersFromNamedTrackpoints = new JCheckBox(tr("Named trackpoints."));
050    private JCheckBox audioMarkersFromWavTimestamps = new JCheckBox(tr("Modified times (time stamps) of audio files."));
051    private JCheckBox audioMarkersFromStart = new JCheckBox(tr("Start of track (will always do this if no other markers available)."));
052
053    private JosmTextField audioLeadIn = new JosmTextField(8);
054    private JosmTextField audioForwardBackAmount = new JosmTextField(8);
055    private JosmTextField audioFastForwardMultiplier = new JosmTextField(8);
056    private JosmTextField audioCalibration = new JosmTextField(8);
057
058    @Override
059    public void addGui(PreferenceTabbedPane gui) {
060        JPanel audio = new JPanel(new GridBagLayout());
061
062        // audioMenuVisible
063        audioMenuVisible.setSelected(! Main.pref.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(Main.pref.getBoolean("marker.traceaudio", true));
069        markerAudioTraceVisible.setToolTipText(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(tr("Automatically create audio markers from trackpoints (rather than explicit waypoints) with names or descriptions."));
092        audio.add(audioMarkersFromNamedTrackpoints, GBC.eol().insets(10,0,0,0));
093
094        // audioMarkersFromWavTimestamps
095        audioMarkersFromWavTimestamps.setSelected(Main.pref.getBoolean("marker.audiofromwavtimestamps", false));
096        audioMarkersFromWavTimestamps.setToolTipText(tr("Create audio markers at the position on the track corresponding to the modified time of each audio WAV file imported."));
097        audio.add(audioMarkersFromWavTimestamps, GBC.eol().insets(10,0,0,0));
098
099        // audioMarkersFromStart
100        audioMarkersFromStart.setSelected(Main.pref.getBoolean("marker.audiofromstart"));
101        audioMarkersFromStart.setToolTipText(tr("Automatically create audio markers from trackpoints (rather than explicit waypoints) with names or descriptions."));
102        audio.add(audioMarkersFromStart, GBC.eol().insets(10,0,0,0));
103
104        audioForwardBackAmount.setText(Main.pref.get("audio.forwardbackamount", "10.0"));
105        audioForwardBackAmount.setToolTipText(tr("The number of seconds to jump forward or back when the relevant button is pressed"));
106        audio.add(new JLabel(tr("Forward/back time (seconds)")), GBC.std());
107        audio.add(audioForwardBackAmount, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
108
109        audioFastForwardMultiplier.setText(Main.pref.get("audio.fastfwdmultiplier", "1.3"));
110        audioFastForwardMultiplier.setToolTipText(tr("The amount by which the speed is multiplied for fast forwarding"));
111        audio.add(new JLabel(tr("Fast forward multiplier")), GBC.std());
112        audio.add(audioFastForwardMultiplier, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
113
114        audioLeadIn.setText(Main.pref.get("audio.leadin", "1.0"));
115        audioLeadIn.setToolTipText(tr("Playback starts this number of seconds before (or after, if negative) the audio track position requested"));
116        audio.add(new JLabel(tr("Lead-in time (seconds)")), GBC.std());
117        audio.add(audioLeadIn, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
118
119        audioCalibration.setText(Main.pref.get("audio.calibration", "1.0"));
120        audioCalibration.setToolTipText(tr("The ratio of voice recorder elapsed time to true elapsed time"));
121        audio.add(new JLabel(tr("Voice recorder calibration")), GBC.std());
122        audio.add(audioCalibration, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
123
124        audio.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
125
126        createPreferenceTabWithScrollPane(gui, audio);
127    }
128
129    @Override
130    public boolean ok() {
131        Main.pref.put("audio.menuinvisible", ! audioMenuVisible.isSelected());
132        Main.pref.put("marker.traceaudio", markerAudioTraceVisible.isSelected());
133        Main.pref.put("marker.buttonlabels", markerButtonLabels.isSelected());
134        Main.pref.put("marker.audiofromexplicitwaypoints", audioMarkersFromExplicitWaypoints.isSelected());
135        Main.pref.put("marker.audiofromuntimedwaypoints", audioMarkersFromUntimedWaypoints.isSelected());
136        Main.pref.put("marker.audiofromnamedtrackpoints", audioMarkersFromNamedTrackpoints.isSelected());
137        Main.pref.put("marker.audiofromwavtimestamps", audioMarkersFromWavTimestamps.isSelected());
138        Main.pref.put("marker.audiofromstart", audioMarkersFromStart.isSelected());
139        Main.pref.put("audio.forwardbackamount", audioForwardBackAmount.getText());
140        Main.pref.put("audio.fastfwdmultiplier", audioFastForwardMultiplier.getText());
141        Main.pref.put("audio.leadin", audioLeadIn.getText());
142        Main.pref.put("audio.calibration", audioCalibration.getText());
143        return false;
144    }
145}