altosui: Make flight monitor font size configurable
[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 // BLUETOOTH
56 //      JButton         manage_bluetooth;
57         JButton         manage_frequencies;
58
59         final static String[] font_size_names = { "Small", "Medium", "Large" };
60
61         /* DocumentListener interface methods */
62         public void changedUpdate(DocumentEvent e) {
63                 AltosPreferences.set_callsign(callsign_value.getText());
64         }
65
66         public void insertUpdate(DocumentEvent e) {
67                 changedUpdate(e);
68         }
69
70         public void removeUpdate(DocumentEvent e) {
71                 changedUpdate(e);
72         }
73
74         public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
75                 super(in_owner, "Configure AltosUI", false);
76
77                 GridBagConstraints      c;
78
79                 Insets insets = new Insets(4, 4, 4, 4);
80
81                 int row = 0;
82
83                 owner = in_owner;
84                 voice = in_voice;
85                 pane = getContentPane();
86                 pane.setLayout(new GridBagLayout());
87
88                 c = new GridBagConstraints();
89                 c.insets = insets;
90                 c.fill = GridBagConstraints.NONE;
91                 c.anchor = GridBagConstraints.WEST;
92
93                 /* Nice label at the top */
94                 c.gridx = 0;
95                 c.gridy = row++;
96                 c.gridwidth = 3;
97                 c.fill = GridBagConstraints.NONE;
98                 c.anchor = GridBagConstraints.CENTER;
99                 pane.add(new JLabel ("Configure AltOS UI"), c);
100
101                 c.gridx = 0;
102                 c.gridy = row++;
103                 c.gridwidth = 3;
104                 c.fill = GridBagConstraints.NONE;
105                 c.anchor = GridBagConstraints.CENTER;
106                 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
107
108                 /* Voice settings */
109                 c.gridx = 0;
110                 c.gridy = row;
111                 c.gridwidth = 1;
112                 c.fill = GridBagConstraints.NONE;
113                 c.anchor = GridBagConstraints.WEST;
114                 pane.add(new JLabel("Voice"), c);
115
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);
122                                         if (enabled)
123                                                 voice.speak_always("Enable voice.");
124                                         else
125                                                 voice.speak_always("Disable voice.");
126                                 }
127                         });
128                 c.gridx = 1;
129                 c.gridy = row;
130                 c.gridwidth = 1;
131                 c.weightx = 1;
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");
136
137                 c.gridx = 2;
138                 c.gridy = row++;
139                 c.gridwidth = 1;
140                 c.weightx = 1;
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.");
147                                 }
148                         });
149                 pane.add(test_voice, c);
150                 test_voice.setToolTipText("Play a stock audio clip to check volume");
151
152                 /* Log directory settings */
153                 c.gridx = 0;
154                 c.gridy = row;
155                 c.gridwidth = 1;
156                 c.fill = GridBagConstraints.NONE;
157                 c.anchor = GridBagConstraints.WEST;
158                 pane.add(new JLabel("Log Directory"), c);
159
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());
165                                 }
166                         });
167                 c.gridx = 1;
168                 c.gridy = row++;
169                 c.gridwidth = 2;
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");
174
175                 /* Callsign setting */
176                 c.gridx = 0;
177                 c.gridy = row;
178                 c.gridwidth = 1;
179                 c.fill = GridBagConstraints.NONE;
180                 c.anchor = GridBagConstraints.WEST;
181                 pane.add(new JLabel("Callsign"), c);
182
183                 callsign_value = new JTextField(AltosPreferences.callsign());
184                 callsign_value.getDocument().addDocumentListener(this);
185                 c.gridx = 1;
186                 c.gridy = row++;
187                 c.gridwidth = 2;
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");
192
193                 /* Font size setting */
194                 c.gridx = 0;
195                 c.gridy = row;
196                 c.gridwidth = 1;
197                 c.fill = GridBagConstraints.NONE;
198                 c.anchor = GridBagConstraints.WEST;
199                 pane.add(new JLabel("Font size"), c);
200
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;
207
208                                         AltosPreferences.set_font_size(size);
209                                 }
210                         });
211                 c.gridx = 1;
212                 c.gridy = row++;
213                 c.gridwidth = 2;
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");
218
219                 /* Serial debug setting */
220                 c.gridx = 0;
221                 c.gridy = row;
222                 c.gridwidth = 1;
223                 c.fill = GridBagConstraints.NONE;
224                 c.anchor = GridBagConstraints.WEST;
225                 pane.add(new JLabel("Serial Debug"), c);
226
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);
233                                 }
234                         });
235                 serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
236
237                 c.gridx = 1;
238                 c.gridy = row++;
239                 c.gridwidth = 3;
240                 c.fill = GridBagConstraints.NONE;
241                 c.anchor = GridBagConstraints.WEST;
242                 pane.add(serial_debug, c);
243
244 // BLUETOOTH
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);
249 //                              }
250 //                      });
251 //              c.gridx = 0;
252 //              c.gridy = row++;
253 //              c.gridwidth = 2;
254 //              c.fill = GridBagConstraints.NONE;
255 //              c.anchor = GridBagConstraints.WEST;
256 //              pane.add(manage_bluetooth, c);
257
258                 manage_frequencies = new JButton("Manage Frequencies");
259                 manage_frequencies.addActionListener(new ActionListener() {
260                                 public void actionPerformed(ActionEvent e) {
261                                         AltosConfigFreqUI.show(owner);
262                                 }
263                         });
264                 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
265 // BLUETOOTH
266 //              c.gridx = 2;
267                 c.gridx = 1;
268                 c.gridy = row++;
269                 c.gridwidth = 2;
270                 c.fill = GridBagConstraints.NONE;
271                 c.anchor = GridBagConstraints.WEST;
272                 pane.add(manage_frequencies, c);
273
274                 /* And a close button at the bottom */
275                 close = new JButton("Close");
276                 close.addActionListener(new ActionListener() {
277                                 public void actionPerformed(ActionEvent e) {
278                                         setVisible(false);
279                                 }
280                         });
281                 c.gridx = 0;
282                 c.gridy = row++;
283                 c.gridwidth = 3;
284                 c.fill = GridBagConstraints.NONE;
285                 c.anchor = GridBagConstraints.CENTER;
286                 pane.add(close, c);
287
288                 pack();
289                 setLocationRelativeTo(owner);
290                 setVisible(true);
291         }
292 }