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