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