2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
25 import javax.swing.event.*;
29 import java.util.prefs.*;
30 import java.util.concurrent.LinkedBlockingQueue;
32 public class AltosConfigureUI
34 implements DocumentListener
40 JRadioButton enable_voice;
44 JButton configure_log;
45 JTextField log_directory;
47 JLabel callsign_label;
48 JTextField callsign_value;
50 JLabel font_size_label;
51 JComboBox font_size_value;
53 JRadioButton serial_debug;
56 // JButton manage_bluetooth;
57 JButton manage_frequencies;
59 final static String[] font_size_names = { "Small", "Medium", "Large" };
61 /* DocumentListener interface methods */
62 public void changedUpdate(DocumentEvent e) {
63 AltosPreferences.set_callsign(callsign_value.getText());
66 public void insertUpdate(DocumentEvent e) {
70 public void removeUpdate(DocumentEvent e) {
74 public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
75 super(in_owner, "Configure AltosUI", false);
79 Insets insets = new Insets(4, 4, 4, 4);
85 pane = getContentPane();
86 pane.setLayout(new GridBagLayout());
88 c = new GridBagConstraints();
90 c.fill = GridBagConstraints.NONE;
91 c.anchor = GridBagConstraints.WEST;
93 /* Nice label at the top */
97 c.fill = GridBagConstraints.NONE;
98 c.anchor = GridBagConstraints.CENTER;
99 pane.add(new JLabel ("Configure AltOS UI"), c);
104 c.fill = GridBagConstraints.NONE;
105 c.anchor = GridBagConstraints.CENTER;
106 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
112 c.fill = GridBagConstraints.NONE;
113 c.anchor = GridBagConstraints.WEST;
114 pane.add(new JLabel("Voice"), c);
116 enable_voice = new JRadioButton("Enable", AltosPreferences.voice());
117 enable_voice.addActionListener(new ActionListener() {
118 public void actionPerformed(ActionEvent e) {
119 JRadioButton item = (JRadioButton) e.getSource();
120 boolean enabled = item.isSelected();
121 AltosPreferences.set_voice(enabled);
123 voice.speak_always("Enable voice.");
125 voice.speak_always("Disable voice.");
132 c.fill = GridBagConstraints.NONE;
133 c.anchor = GridBagConstraints.WEST;
134 pane.add(enable_voice, c);
135 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
141 c.fill = GridBagConstraints.NONE;
142 c.anchor = GridBagConstraints.EAST;
143 test_voice = new JButton("Test Voice");
144 test_voice.addActionListener(new ActionListener() {
145 public void actionPerformed(ActionEvent e) {
146 voice.speak("That's one small step for man; one giant leap for mankind.");
149 pane.add(test_voice, c);
150 test_voice.setToolTipText("Play a stock audio clip to check volume");
152 /* Log directory settings */
156 c.fill = GridBagConstraints.NONE;
157 c.anchor = GridBagConstraints.WEST;
158 pane.add(new JLabel("Log Directory"), c);
160 configure_log = new JButton(AltosPreferences.logdir().getPath());
161 configure_log.addActionListener(new ActionListener() {
162 public void actionPerformed(ActionEvent e) {
163 AltosPreferences.ConfigureLog();
164 configure_log.setText(AltosPreferences.logdir().getPath());
170 c.fill = GridBagConstraints.BOTH;
171 c.anchor = GridBagConstraints.WEST;
172 pane.add(configure_log, c);
173 configure_log.setToolTipText("Which directory flight logs are stored in");
175 /* Callsign setting */
179 c.fill = GridBagConstraints.NONE;
180 c.anchor = GridBagConstraints.WEST;
181 pane.add(new JLabel("Callsign"), c);
183 callsign_value = new JTextField(AltosPreferences.callsign());
184 callsign_value.getDocument().addDocumentListener(this);
188 c.fill = GridBagConstraints.BOTH;
189 c.anchor = GridBagConstraints.WEST;
190 pane.add(callsign_value, c);
191 callsign_value.setToolTipText("Callsign sent in packet mode");
193 /* Font size setting */
197 c.fill = GridBagConstraints.NONE;
198 c.anchor = GridBagConstraints.WEST;
199 pane.add(new JLabel("Font size"), c);
201 font_size_value = new JComboBox(font_size_names);
202 int font_size = AltosPreferences.font_size();
203 font_size_value.setSelectedIndex(font_size - Altos.font_size_small);
204 font_size_value.addActionListener(new ActionListener() {
205 public void actionPerformed(ActionEvent e) {
206 int size = font_size_value.getSelectedIndex() + Altos.font_size_small;
208 AltosPreferences.set_font_size(size);
214 c.fill = GridBagConstraints.BOTH;
215 c.anchor = GridBagConstraints.WEST;
216 pane.add(font_size_value, c);
217 font_size_value.setToolTipText("Font size used in telemetry window");
219 /* Serial debug setting */
223 c.fill = GridBagConstraints.NONE;
224 c.anchor = GridBagConstraints.WEST;
225 pane.add(new JLabel("Serial Debug"), c);
227 serial_debug = new JRadioButton("Enable", AltosPreferences.serial_debug());
228 serial_debug.addActionListener(new ActionListener() {
229 public void actionPerformed(ActionEvent e) {
230 JRadioButton item = (JRadioButton) e.getSource();
231 boolean enabled = item.isSelected();
232 AltosPreferences.set_serial_debug(enabled);
235 serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
240 c.fill = GridBagConstraints.NONE;
241 c.anchor = GridBagConstraints.WEST;
242 pane.add(serial_debug, c);
245 // manage_bluetooth = new JButton("Manage Bluetooth");
246 // manage_bluetooth.addActionListener(new ActionListener() {
247 // public void actionPerformed(ActionEvent e) {
248 // AltosBTManage.show(owner, Altos.bt_known);
254 // c.fill = GridBagConstraints.NONE;
255 // c.anchor = GridBagConstraints.WEST;
256 // pane.add(manage_bluetooth, c);
258 manage_frequencies = new JButton("Manage Frequencies");
259 manage_frequencies.addActionListener(new ActionListener() {
260 public void actionPerformed(ActionEvent e) {
261 AltosConfigFreqUI.show(owner);
264 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
270 c.fill = GridBagConstraints.NONE;
271 c.anchor = GridBagConstraints.WEST;
272 pane.add(manage_frequencies, c);
274 /* And a close button at the bottom */
275 close = new JButton("Close");
276 close.addActionListener(new ActionListener() {
277 public void actionPerformed(ActionEvent e) {
284 c.fill = GridBagConstraints.NONE;
285 c.anchor = GridBagConstraints.CENTER;
289 setLocationRelativeTo(owner);