a8a70ffdfb62ed7a7dd938ae8308e9dc3a2e74a5
[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         JRadioButton    serial_debug;
51
52         JButton         manage_bluetooth;
53         JButton         manage_frequencies;
54
55         /* DocumentListener interface methods */
56         public void changedUpdate(DocumentEvent e) {
57                 AltosPreferences.set_callsign(callsign_value.getText());
58         }
59
60         public void insertUpdate(DocumentEvent e) {
61                 changedUpdate(e);
62         }
63
64         public void removeUpdate(DocumentEvent e) {
65                 changedUpdate(e);
66         }
67
68         public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
69                 super(in_owner, "Configure AltosUI", false);
70
71                 GridBagConstraints      c;
72
73                 Insets insets = new Insets(4, 4, 4, 4);
74
75                 owner = in_owner;
76                 voice = in_voice;
77                 pane = getContentPane();
78                 pane.setLayout(new GridBagLayout());
79
80                 c = new GridBagConstraints();
81                 c.insets = insets;
82                 c.fill = GridBagConstraints.NONE;
83                 c.anchor = GridBagConstraints.WEST;
84
85                 /* Nice label at the top */
86                 c.gridx = 0;
87                 c.gridy = 0;
88                 c.gridwidth = 3;
89                 c.fill = GridBagConstraints.NONE;
90                 c.anchor = GridBagConstraints.CENTER;
91                 pane.add(new JLabel ("Configure AltOS UI"), c);
92
93                 c.gridx = 0;
94                 c.gridy = 1;
95                 c.gridwidth = 3;
96                 c.fill = GridBagConstraints.NONE;
97                 c.anchor = GridBagConstraints.CENTER;
98                 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
99
100                 /* Voice settings */
101                 c.gridx = 0;
102                 c.gridy = 2;
103                 c.gridwidth = 1;
104                 c.fill = GridBagConstraints.NONE;
105                 c.anchor = GridBagConstraints.WEST;
106                 pane.add(new JLabel("Voice"), c);
107
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);
114                                         if (enabled)
115                                                 voice.speak_always("Enable voice.");
116                                         else
117                                                 voice.speak_always("Disable voice.");
118                                 }
119                         });
120                 c.gridx = 1;
121                 c.gridy = 2;
122                 c.gridwidth = 1;
123                 c.weightx = 1;
124                 c.fill = GridBagConstraints.NONE;
125                 c.anchor = GridBagConstraints.WEST;
126                 pane.add(enable_voice, c);
127
128                 c.gridx = 2;
129                 c.gridy = 2;
130                 c.gridwidth = 1;
131                 c.weightx = 1;
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.");
138                                 }
139                         });
140                 pane.add(test_voice, c);
141
142                 /* Log directory settings */
143                 c.gridx = 0;
144                 c.gridy = 3;
145                 c.gridwidth = 1;
146                 c.fill = GridBagConstraints.NONE;
147                 c.anchor = GridBagConstraints.WEST;
148                 pane.add(new JLabel("Log Directory"), c);
149
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());
155                                 }
156                         });
157                 c.gridx = 1;
158                 c.gridy = 3;
159                 c.gridwidth = 2;
160                 c.fill = GridBagConstraints.BOTH;
161                 c.anchor = GridBagConstraints.WEST;
162                 pane.add(configure_log, c);
163
164                 /* Callsign setting */
165                 c.gridx = 0;
166                 c.gridy = 4;
167                 c.gridwidth = 1;
168                 c.fill = GridBagConstraints.NONE;
169                 c.anchor = GridBagConstraints.WEST;
170                 pane.add(new JLabel("Callsign"), c);
171
172                 callsign_value = new JTextField(AltosPreferences.callsign());
173                 callsign_value.getDocument().addDocumentListener(this);
174                 c.gridx = 1;
175                 c.gridy = 4;
176                 c.gridwidth = 2;
177                 c.fill = GridBagConstraints.BOTH;
178                 c.anchor = GridBagConstraints.WEST;
179                 pane.add(callsign_value, c);
180
181                 /* Serial debug setting */
182                 c.gridx = 0;
183                 c.gridy = 5;
184                 c.gridwidth = 1;
185                 c.fill = GridBagConstraints.NONE;
186                 c.anchor = GridBagConstraints.WEST;
187                 pane.add(new JLabel("Serial Debug"), c);
188
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);
195                                 }
196                         });
197
198                 c.gridx = 1;
199                 c.gridy = 5;
200                 c.gridwidth = 3;
201                 c.fill = GridBagConstraints.NONE;
202                 c.anchor = GridBagConstraints.WEST;
203                 pane.add(serial_debug, c);
204
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);
209                                 }
210                         });
211                 c.gridx = 0;
212                 c.gridy = 6;
213                 c.gridwidth = 2;
214                 c.fill = GridBagConstraints.NONE;
215                 c.anchor = GridBagConstraints.WEST;
216                 pane.add(manage_bluetooth, c);
217
218                 manage_frequencies = new JButton("Manage Frequencies");
219                 manage_frequencies.addActionListener(new ActionListener() {
220                                 public void actionPerformed(ActionEvent e) {
221                                         AltosConfigFreqUI.show(owner);
222                                 }
223                         });
224                 c.gridx = 2;
225                 c.gridy = 6;
226                 c.gridwidth = 2;
227                 c.fill = GridBagConstraints.NONE;
228                 c.anchor = GridBagConstraints.WEST;
229                 pane.add(manage_frequencies, c);
230
231                 /* And a close button at the bottom */
232                 close = new JButton("Close");
233                 close.addActionListener(new ActionListener() {
234                                 public void actionPerformed(ActionEvent e) {
235                                         setVisible(false);
236                                 }
237                         });
238                 c.gridx = 0;
239                 c.gridy = 7;
240                 c.gridwidth = 3;
241                 c.fill = GridBagConstraints.NONE;
242                 c.anchor = GridBagConstraints.CENTER;
243                 pane.add(close, c);
244
245                 pack();
246                 setLocationRelativeTo(owner);
247                 setVisible(true);
248         }
249 }