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;
55 JButton manage_bluetooth;
56 JButton manage_frequencies;
58 final static String[] font_size_names = { "Small", "Medium", "Large" };
60 /* DocumentListener interface methods */
61 public void changedUpdate(DocumentEvent e) {
62 AltosPreferences.set_callsign(callsign_value.getText());
65 public void insertUpdate(DocumentEvent e) {
69 public void removeUpdate(DocumentEvent e) {
73 public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
74 super(in_owner, "Configure AltosUI", false);
78 Insets insets = new Insets(4, 4, 4, 4);
84 pane = getContentPane();
85 pane.setLayout(new GridBagLayout());
87 c = new GridBagConstraints();
89 c.fill = GridBagConstraints.NONE;
90 c.anchor = GridBagConstraints.WEST;
92 /* Nice label at the top */
96 c.fill = GridBagConstraints.NONE;
97 c.anchor = GridBagConstraints.CENTER;
98 pane.add(new JLabel ("Configure AltOS UI"), c);
103 c.fill = GridBagConstraints.NONE;
104 c.anchor = GridBagConstraints.CENTER;
105 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
111 c.fill = GridBagConstraints.NONE;
112 c.anchor = GridBagConstraints.WEST;
113 pane.add(new JLabel("Voice"), c);
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);
122 voice.speak_always("Enable voice.");
124 voice.speak_always("Disable voice.");
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");
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.");
148 pane.add(test_voice, c);
149 test_voice.setToolTipText("Play a stock audio clip to check volume");
151 /* Log directory settings */
155 c.fill = GridBagConstraints.NONE;
156 c.anchor = GridBagConstraints.WEST;
157 pane.add(new JLabel("Log Directory"), c);
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());
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");
174 /* Callsign setting */
178 c.fill = GridBagConstraints.NONE;
179 c.anchor = GridBagConstraints.WEST;
180 pane.add(new JLabel("Callsign"), c);
182 callsign_value = new JTextField(AltosPreferences.callsign());
183 callsign_value.getDocument().addDocumentListener(this);
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");
192 /* Font size setting */
196 c.fill = GridBagConstraints.NONE;
197 c.anchor = GridBagConstraints.WEST;
198 pane.add(new JLabel("Font size"), c);
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;
207 AltosPreferences.set_font_size(size);
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");
218 /* Serial debug setting */
222 c.fill = GridBagConstraints.NONE;
223 c.anchor = GridBagConstraints.WEST;
224 pane.add(new JLabel("Serial Debug"), c);
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);
234 serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
239 c.fill = GridBagConstraints.NONE;
240 c.anchor = GridBagConstraints.WEST;
241 pane.add(serial_debug, c);
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);
252 c.fill = GridBagConstraints.NONE;
253 c.anchor = GridBagConstraints.WEST;
254 pane.add(manage_bluetooth, c);
256 manage_frequencies = new JButton("Manage Frequencies");
257 manage_frequencies.addActionListener(new ActionListener() {
258 public void actionPerformed(ActionEvent e) {
259 AltosConfigFreqUI.show(owner);
262 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
267 c.fill = GridBagConstraints.NONE;
268 c.anchor = GridBagConstraints.WEST;
269 pane.add(manage_frequencies, c);
271 /* And a close button at the bottom */
272 close = new JButton("Close");
273 close.addActionListener(new ActionListener() {
274 public void actionPerformed(ActionEvent e) {
281 c.fill = GridBagConstraints.NONE;
282 c.anchor = GridBagConstraints.CENTER;
286 setLocationRelativeTo(owner);