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;
52 JButton manage_bluetooth;
53 JButton manage_frequencies;
55 /* DocumentListener interface methods */
56 public void changedUpdate(DocumentEvent e) {
57 AltosPreferences.set_callsign(callsign_value.getText());
60 public void insertUpdate(DocumentEvent e) {
64 public void removeUpdate(DocumentEvent e) {
68 public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
69 super(in_owner, "Configure AltosUI", false);
73 Insets insets = new Insets(4, 4, 4, 4);
77 pane = getContentPane();
78 pane.setLayout(new GridBagLayout());
80 c = new GridBagConstraints();
82 c.fill = GridBagConstraints.NONE;
83 c.anchor = GridBagConstraints.WEST;
85 /* Nice label at the top */
89 c.fill = GridBagConstraints.NONE;
90 c.anchor = GridBagConstraints.CENTER;
91 pane.add(new JLabel ("Configure AltOS UI"), c);
96 c.fill = GridBagConstraints.NONE;
97 c.anchor = GridBagConstraints.CENTER;
98 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
104 c.fill = GridBagConstraints.NONE;
105 c.anchor = GridBagConstraints.WEST;
106 pane.add(new JLabel("Voice"), c);
108 enable_voice = new JRadioButton("Enable", AltosPreferences.voice());
109 enable_voice.addActionListener(new ActionListener() {
110 public void actionPerformed(ActionEvent e) {
111 JRadioButton item = (JRadioButton) e.getSource();
112 boolean enabled = item.isSelected();
113 AltosPreferences.set_voice(enabled);
115 voice.speak_always("Enable voice.");
117 voice.speak_always("Disable voice.");
124 c.fill = GridBagConstraints.NONE;
125 c.anchor = GridBagConstraints.WEST;
126 pane.add(enable_voice, c);
132 c.fill = GridBagConstraints.NONE;
133 c.anchor = GridBagConstraints.EAST;
134 test_voice = new JButton("Test Voice");
135 test_voice.addActionListener(new ActionListener() {
136 public void actionPerformed(ActionEvent e) {
137 voice.speak("That's one small step for man; one giant leap for mankind.");
140 pane.add(test_voice, c);
142 /* Log directory settings */
146 c.fill = GridBagConstraints.NONE;
147 c.anchor = GridBagConstraints.WEST;
148 pane.add(new JLabel("Log Directory"), c);
150 configure_log = new JButton(AltosPreferences.logdir().getPath());
151 configure_log.addActionListener(new ActionListener() {
152 public void actionPerformed(ActionEvent e) {
153 AltosPreferences.ConfigureLog();
154 configure_log.setText(AltosPreferences.logdir().getPath());
160 c.fill = GridBagConstraints.BOTH;
161 c.anchor = GridBagConstraints.WEST;
162 pane.add(configure_log, c);
164 /* Callsign setting */
168 c.fill = GridBagConstraints.NONE;
169 c.anchor = GridBagConstraints.WEST;
170 pane.add(new JLabel("Callsign"), c);
172 callsign_value = new JTextField(AltosPreferences.callsign());
173 callsign_value.getDocument().addDocumentListener(this);
177 c.fill = GridBagConstraints.BOTH;
178 c.anchor = GridBagConstraints.WEST;
179 pane.add(callsign_value, c);
181 /* Serial debug setting */
185 c.fill = GridBagConstraints.NONE;
186 c.anchor = GridBagConstraints.WEST;
187 pane.add(new JLabel("Serial Debug"), c);
189 serial_debug = new JRadioButton("Enable", AltosPreferences.serial_debug());
190 serial_debug.addActionListener(new ActionListener() {
191 public void actionPerformed(ActionEvent e) {
192 JRadioButton item = (JRadioButton) e.getSource();
193 boolean enabled = item.isSelected();
194 AltosPreferences.set_serial_debug(enabled);
201 c.fill = GridBagConstraints.NONE;
202 c.anchor = GridBagConstraints.WEST;
203 pane.add(serial_debug, c);
205 manage_bluetooth = new JButton("Manage Bluetooth");
206 manage_bluetooth.addActionListener(new ActionListener() {
207 public void actionPerformed(ActionEvent e) {
208 AltosBTManage.show(owner, Altos.bt_known);
214 c.fill = GridBagConstraints.NONE;
215 c.anchor = GridBagConstraints.WEST;
216 pane.add(manage_bluetooth, c);
218 manage_frequencies = new JButton("Manage Frequencies");
219 manage_frequencies.addActionListener(new ActionListener() {
220 public void actionPerformed(ActionEvent e) {
221 AltosConfigFreqUI.show(owner);
227 c.fill = GridBagConstraints.NONE;
228 c.anchor = GridBagConstraints.WEST;
229 pane.add(manage_frequencies, c);
231 /* And a close button at the bottom */
232 close = new JButton("Close");
233 close.addActionListener(new ActionListener() {
234 public void actionPerformed(ActionEvent e) {
241 c.fill = GridBagConstraints.NONE;
242 c.anchor = GridBagConstraints.CENTER;
246 setLocationRelativeTo(owner);