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