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 JRadioButton serial_debug;
53 // JButton manage_bluetooth;
54 JButton manage_frequencies;
56 /* DocumentListener interface methods */
57 public void changedUpdate(DocumentEvent e) {
58 AltosPreferences.set_callsign(callsign_value.getText());
61 public void insertUpdate(DocumentEvent e) {
65 public void removeUpdate(DocumentEvent e) {
69 public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
70 super(in_owner, "Configure AltosUI", false);
74 Insets insets = new Insets(4, 4, 4, 4);
78 pane = getContentPane();
79 pane.setLayout(new GridBagLayout());
81 c = new GridBagConstraints();
83 c.fill = GridBagConstraints.NONE;
84 c.anchor = GridBagConstraints.WEST;
86 /* Nice label at the top */
90 c.fill = GridBagConstraints.NONE;
91 c.anchor = GridBagConstraints.CENTER;
92 pane.add(new JLabel ("Configure AltOS UI"), c);
97 c.fill = GridBagConstraints.NONE;
98 c.anchor = GridBagConstraints.CENTER;
99 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
105 c.fill = GridBagConstraints.NONE;
106 c.anchor = GridBagConstraints.WEST;
107 pane.add(new JLabel("Voice"), c);
109 enable_voice = new JRadioButton("Enable", AltosPreferences.voice());
110 enable_voice.addActionListener(new ActionListener() {
111 public void actionPerformed(ActionEvent e) {
112 JRadioButton item = (JRadioButton) e.getSource();
113 boolean enabled = item.isSelected();
114 AltosPreferences.set_voice(enabled);
116 voice.speak_always("Enable voice.");
118 voice.speak_always("Disable voice.");
125 c.fill = GridBagConstraints.NONE;
126 c.anchor = GridBagConstraints.WEST;
127 pane.add(enable_voice, c);
128 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
134 c.fill = GridBagConstraints.NONE;
135 c.anchor = GridBagConstraints.EAST;
136 test_voice = new JButton("Test Voice");
137 test_voice.addActionListener(new ActionListener() {
138 public void actionPerformed(ActionEvent e) {
139 voice.speak("That's one small step for man; one giant leap for mankind.");
142 pane.add(test_voice, c);
143 test_voice.setToolTipText("Play a stock audio clip to check volume");
145 /* Log directory settings */
149 c.fill = GridBagConstraints.NONE;
150 c.anchor = GridBagConstraints.WEST;
151 pane.add(new JLabel("Log Directory"), c);
153 configure_log = new JButton(AltosPreferences.logdir().getPath());
154 configure_log.addActionListener(new ActionListener() {
155 public void actionPerformed(ActionEvent e) {
156 AltosPreferences.ConfigureLog();
157 configure_log.setText(AltosPreferences.logdir().getPath());
163 c.fill = GridBagConstraints.BOTH;
164 c.anchor = GridBagConstraints.WEST;
165 pane.add(configure_log, c);
166 configure_log.setToolTipText("Which directory flight logs are stored in");
168 /* Callsign setting */
172 c.fill = GridBagConstraints.NONE;
173 c.anchor = GridBagConstraints.WEST;
174 pane.add(new JLabel("Callsign"), c);
176 callsign_value = new JTextField(AltosPreferences.callsign());
177 callsign_value.getDocument().addDocumentListener(this);
181 c.fill = GridBagConstraints.BOTH;
182 c.anchor = GridBagConstraints.WEST;
183 pane.add(callsign_value, c);
184 callsign_value.setToolTipText("Callsign sent in packet mode");
186 /* Serial debug setting */
190 c.fill = GridBagConstraints.NONE;
191 c.anchor = GridBagConstraints.WEST;
192 pane.add(new JLabel("Serial Debug"), c);
194 serial_debug = new JRadioButton("Enable", AltosPreferences.serial_debug());
195 serial_debug.addActionListener(new ActionListener() {
196 public void actionPerformed(ActionEvent e) {
197 JRadioButton item = (JRadioButton) e.getSource();
198 boolean enabled = item.isSelected();
199 AltosPreferences.set_serial_debug(enabled);
202 serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
207 c.fill = GridBagConstraints.NONE;
208 c.anchor = GridBagConstraints.WEST;
209 pane.add(serial_debug, c);
212 // manage_bluetooth = new JButton("Manage Bluetooth");
213 // manage_bluetooth.addActionListener(new ActionListener() {
214 // public void actionPerformed(ActionEvent e) {
215 // AltosBTManage.show(owner, Altos.bt_known);
221 // c.fill = GridBagConstraints.NONE;
222 // c.anchor = GridBagConstraints.WEST;
223 // pane.add(manage_bluetooth, c);
225 manage_frequencies = new JButton("Manage Frequencies");
226 manage_frequencies.addActionListener(new ActionListener() {
227 public void actionPerformed(ActionEvent e) {
228 AltosConfigFreqUI.show(owner);
231 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
237 c.fill = GridBagConstraints.NONE;
238 c.anchor = GridBagConstraints.WEST;
239 pane.add(manage_frequencies, c);
241 /* And a close button at the bottom */
242 close = new JButton("Close");
243 close.addActionListener(new ActionListener() {
244 public void actionPerformed(ActionEvent e) {
251 c.fill = GridBagConstraints.NONE;
252 c.anchor = GridBagConstraints.CENTER;
256 setLocationRelativeTo(owner);