altos: Support staging by going back to boost as needed
[fw/altos] / altosui / AltosConfigureUI.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package altosui;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
25 import javax.swing.event.*;
26 import java.io.*;
27 import java.util.*;
28 import java.text.*;
29 import java.util.prefs.*;
30 import java.util.concurrent.LinkedBlockingQueue;
31
32 public class AltosConfigureUI
33         extends JDialog
34         implements DocumentListener
35 {
36         JFrame          owner;
37         AltosVoice      voice;
38         Container       pane;
39
40         JRadioButton    enable_voice;
41         JButton         test_voice;
42         JButton         close;
43
44         JButton         configure_log;
45         JTextField      log_directory;
46
47         JLabel          callsign_label;
48         JTextField      callsign_value;
49
50         JLabel          font_size_label;
51         JComboBox       font_size_value;
52
53         JRadioButton    serial_debug;
54
55         JButton         manage_bluetooth;
56         JButton         manage_frequencies;
57
58         final static String[] font_size_names = { "Small", "Medium", "Large" };
59
60         /* DocumentListener interface methods */
61         public void changedUpdate(DocumentEvent e) {
62                 AltosPreferences.set_callsign(callsign_value.getText());
63         }
64
65         public void insertUpdate(DocumentEvent e) {
66                 changedUpdate(e);
67         }
68
69         public void removeUpdate(DocumentEvent e) {
70                 changedUpdate(e);
71         }
72
73         public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
74                 super(in_owner, "Configure AltosUI", false);
75
76                 GridBagConstraints      c;
77
78                 Insets insets = new Insets(4, 4, 4, 4);
79
80                 int row = 0;
81
82                 owner = in_owner;
83                 voice = in_voice;
84                 pane = getContentPane();
85                 pane.setLayout(new GridBagLayout());
86
87                 c = new GridBagConstraints();
88                 c.insets = insets;
89                 c.fill = GridBagConstraints.NONE;
90                 c.anchor = GridBagConstraints.WEST;
91
92                 /* Nice label at the top */
93                 c.gridx = 0;
94                 c.gridy = row++;
95                 c.gridwidth = 3;
96                 c.fill = GridBagConstraints.NONE;
97                 c.anchor = GridBagConstraints.CENTER;
98                 pane.add(new JLabel ("Configure AltOS UI"), c);
99
100                 c.gridx = 0;
101                 c.gridy = row++;
102                 c.gridwidth = 3;
103                 c.fill = GridBagConstraints.NONE;
104                 c.anchor = GridBagConstraints.CENTER;
105                 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
106
107                 /* Voice settings */
108                 c.gridx = 0;
109                 c.gridy = row;
110                 c.gridwidth = 1;
111                 c.fill = GridBagConstraints.NONE;
112                 c.anchor = GridBagConstraints.WEST;
113                 pane.add(new JLabel("Voice"), c);
114
115                 enable_voice = new JRadioButton("Enable", AltosPreferences.voice());
116                 enable_voice.addActionListener(new ActionListener() {
117                                 public void actionPerformed(ActionEvent e) {
118                                         JRadioButton item = (JRadioButton) e.getSource();
119                                         boolean enabled = item.isSelected();
120                                         AltosPreferences.set_voice(enabled);
121                                         if (enabled)
122                                                 voice.speak_always("Enable voice.");
123                                         else
124                                                 voice.speak_always("Disable voice.");
125                                 }
126                         });
127                 c.gridx = 1;
128                 c.gridy = row;
129                 c.gridwidth = 1;
130                 c.weightx = 1;
131                 c.fill = GridBagConstraints.NONE;
132                 c.anchor = GridBagConstraints.WEST;
133                 pane.add(enable_voice, c);
134                 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
135
136                 c.gridx = 2;
137                 c.gridy = row++;
138                 c.gridwidth = 1;
139                 c.weightx = 1;
140                 c.fill = GridBagConstraints.NONE;
141                 c.anchor = GridBagConstraints.EAST;
142                 test_voice = new JButton("Test Voice");
143                 test_voice.addActionListener(new ActionListener() {
144                                 public void actionPerformed(ActionEvent e) {
145                                         voice.speak("That's one small step for man; one giant leap for mankind.");
146                                 }
147                         });
148                 pane.add(test_voice, c);
149                 test_voice.setToolTipText("Play a stock audio clip to check volume");
150
151                 /* Log directory settings */
152                 c.gridx = 0;
153                 c.gridy = row;
154                 c.gridwidth = 1;
155                 c.fill = GridBagConstraints.NONE;
156                 c.anchor = GridBagConstraints.WEST;
157                 pane.add(new JLabel("Log Directory"), c);
158
159                 configure_log = new JButton(AltosPreferences.logdir().getPath());
160                 configure_log.addActionListener(new ActionListener() {
161                                 public void actionPerformed(ActionEvent e) {
162                                         AltosPreferences.ConfigureLog();
163                                         configure_log.setText(AltosPreferences.logdir().getPath());
164                                 }
165                         });
166                 c.gridx = 1;
167                 c.gridy = row++;
168                 c.gridwidth = 2;
169                 c.fill = GridBagConstraints.BOTH;
170                 c.anchor = GridBagConstraints.WEST;
171                 pane.add(configure_log, c);
172                 configure_log.setToolTipText("Which directory flight logs are stored in");
173
174                 /* Callsign setting */
175                 c.gridx = 0;
176                 c.gridy = row;
177                 c.gridwidth = 1;
178                 c.fill = GridBagConstraints.NONE;
179                 c.anchor = GridBagConstraints.WEST;
180                 pane.add(new JLabel("Callsign"), c);
181
182                 callsign_value = new JTextField(AltosPreferences.callsign());
183                 callsign_value.getDocument().addDocumentListener(this);
184                 c.gridx = 1;
185                 c.gridy = row++;
186                 c.gridwidth = 2;
187                 c.fill = GridBagConstraints.BOTH;
188                 c.anchor = GridBagConstraints.WEST;
189                 pane.add(callsign_value, c);
190                 callsign_value.setToolTipText("Callsign sent in packet mode");
191
192                 /* Font size setting */
193                 c.gridx = 0;
194                 c.gridy = row;
195                 c.gridwidth = 1;
196                 c.fill = GridBagConstraints.NONE;
197                 c.anchor = GridBagConstraints.WEST;
198                 pane.add(new JLabel("Font size"), c);
199
200                 font_size_value = new JComboBox(font_size_names);
201                 int font_size = AltosPreferences.font_size();
202                 font_size_value.setSelectedIndex(font_size - Altos.font_size_small);
203                 font_size_value.addActionListener(new ActionListener() {
204                                 public void actionPerformed(ActionEvent e) {
205                                         int     size = font_size_value.getSelectedIndex() + Altos.font_size_small;
206
207                                         AltosPreferences.set_font_size(size);
208                                 }
209                         });
210                 c.gridx = 1;
211                 c.gridy = row++;
212                 c.gridwidth = 2;
213                 c.fill = GridBagConstraints.BOTH;
214                 c.anchor = GridBagConstraints.WEST;
215                 pane.add(font_size_value, c);
216                 font_size_value.setToolTipText("Font size used in telemetry window");
217
218                 /* Serial debug setting */
219                 c.gridx = 0;
220                 c.gridy = row;
221                 c.gridwidth = 1;
222                 c.fill = GridBagConstraints.NONE;
223                 c.anchor = GridBagConstraints.WEST;
224                 pane.add(new JLabel("Serial Debug"), c);
225
226                 serial_debug = new JRadioButton("Enable", AltosPreferences.serial_debug());
227                 serial_debug.addActionListener(new ActionListener() {
228                                 public void actionPerformed(ActionEvent e) {
229                                         JRadioButton item = (JRadioButton) e.getSource();
230                                         boolean enabled = item.isSelected();
231                                         AltosPreferences.set_serial_debug(enabled);
232                                 }
233                         });
234                 serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
235
236                 c.gridx = 1;
237                 c.gridy = row++;
238                 c.gridwidth = 3;
239                 c.fill = GridBagConstraints.NONE;
240                 c.anchor = GridBagConstraints.WEST;
241                 pane.add(serial_debug, c);
242
243                 manage_bluetooth = new JButton("Manage Bluetooth");
244                 manage_bluetooth.addActionListener(new ActionListener() {
245                                 public void actionPerformed(ActionEvent e) {
246                                         AltosBTManage.show(owner, Altos.bt_known);
247                                 }
248                         });
249                 c.gridx = 0;
250                 c.gridy = row;
251                 c.gridwidth = 2;
252                 c.fill = GridBagConstraints.NONE;
253                 c.anchor = GridBagConstraints.WEST;
254                 pane.add(manage_bluetooth, c);
255
256                 manage_frequencies = new JButton("Manage Frequencies");
257                 manage_frequencies.addActionListener(new ActionListener() {
258                                 public void actionPerformed(ActionEvent e) {
259                                         AltosConfigFreqUI.show(owner);
260                                 }
261                         });
262                 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
263                 c.gridx = 2;
264                 c.gridx = 2;
265                 c.gridy = row++;
266                 c.gridwidth = 2;
267                 c.fill = GridBagConstraints.NONE;
268                 c.anchor = GridBagConstraints.WEST;
269                 pane.add(manage_frequencies, c);
270
271                 /* And a close button at the bottom */
272                 close = new JButton("Close");
273                 close.addActionListener(new ActionListener() {
274                                 public void actionPerformed(ActionEvent e) {
275                                         setVisible(false);
276                                 }
277                         });
278                 c.gridx = 0;
279                 c.gridy = row++;
280                 c.gridwidth = 3;
281                 c.fill = GridBagConstraints.NONE;
282                 c.anchor = GridBagConstraints.CENTER;
283                 pane.add(close, c);
284
285                 pack();
286                 setLocationRelativeTo(owner);
287                 setVisible(true);
288         }
289 }