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);
133 c.fill = GridBagConstraints.NONE;
134 c.anchor = GridBagConstraints.EAST;
135 test_voice = new JButton("Test Voice");
136 test_voice.addActionListener(new ActionListener() {
137 public void actionPerformed(ActionEvent e) {
138 voice.speak("That's one small step for man; one giant leap for mankind.");
141 pane.add(test_voice, c);
143 /* Log directory settings */
147 c.fill = GridBagConstraints.NONE;
148 c.anchor = GridBagConstraints.WEST;
149 pane.add(new JLabel("Log Directory"), c);
151 configure_log = new JButton(AltosPreferences.logdir().getPath());
152 configure_log.addActionListener(new ActionListener() {
153 public void actionPerformed(ActionEvent e) {
154 AltosPreferences.ConfigureLog();
155 configure_log.setText(AltosPreferences.logdir().getPath());
161 c.fill = GridBagConstraints.BOTH;
162 c.anchor = GridBagConstraints.WEST;
163 pane.add(configure_log, c);
165 /* Callsign setting */
169 c.fill = GridBagConstraints.NONE;
170 c.anchor = GridBagConstraints.WEST;
171 pane.add(new JLabel("Callsign"), c);
173 callsign_value = new JTextField(AltosPreferences.callsign());
174 callsign_value.getDocument().addDocumentListener(this);
178 c.fill = GridBagConstraints.BOTH;
179 c.anchor = GridBagConstraints.WEST;
180 pane.add(callsign_value, c);
182 /* Serial debug setting */
186 c.fill = GridBagConstraints.NONE;
187 c.anchor = GridBagConstraints.WEST;
188 pane.add(new JLabel("Serial Debug"), c);
190 serial_debug = new JRadioButton("Enable", AltosPreferences.serial_debug());
191 serial_debug.addActionListener(new ActionListener() {
192 public void actionPerformed(ActionEvent e) {
193 JRadioButton item = (JRadioButton) e.getSource();
194 boolean enabled = item.isSelected();
195 AltosPreferences.set_serial_debug(enabled);
202 c.fill = GridBagConstraints.NONE;
203 c.anchor = GridBagConstraints.WEST;
204 pane.add(serial_debug, c);
207 // manage_bluetooth = new JButton("Manage Bluetooth");
208 // manage_bluetooth.addActionListener(new ActionListener() {
209 // public void actionPerformed(ActionEvent e) {
210 // AltosBTManage.show(owner, Altos.bt_known);
216 // c.fill = GridBagConstraints.NONE;
217 // c.anchor = GridBagConstraints.WEST;
218 // pane.add(manage_bluetooth, c);
220 manage_frequencies = new JButton("Manage Frequencies");
221 manage_frequencies.addActionListener(new ActionListener() {
222 public void actionPerformed(ActionEvent e) {
223 AltosConfigFreqUI.show(owner);
231 c.fill = GridBagConstraints.NONE;
232 c.anchor = GridBagConstraints.WEST;
233 pane.add(manage_frequencies, c);
235 /* And a close button at the bottom */
236 close = new JButton("Close");
237 close.addActionListener(new ActionListener() {
238 public void actionPerformed(ActionEvent e) {
245 c.fill = GridBagConstraints.NONE;
246 c.anchor = GridBagConstraints.CENTER;
250 setLocationRelativeTo(owner);