altos: Add delays to bt startup sequence
[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
54         /* DocumentListener interface methods */
55         public void changedUpdate(DocumentEvent e) {
56                 AltosPreferences.set_callsign(callsign_value.getText());
57         }
58
59         public void insertUpdate(DocumentEvent e) {
60                 changedUpdate(e);
61         }
62
63         public void removeUpdate(DocumentEvent e) {
64                 changedUpdate(e);
65         }
66
67         public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
68                 super(in_owner, "Configure AltosUI", false);
69
70                 GridBagConstraints      c;
71
72                 Insets insets = new Insets(4, 4, 4, 4);
73
74                 owner = in_owner;
75                 voice = in_voice;
76                 pane = getContentPane();
77                 pane.setLayout(new GridBagLayout());
78
79                 c = new GridBagConstraints();
80                 c.insets = insets;
81                 c.fill = GridBagConstraints.NONE;
82                 c.anchor = GridBagConstraints.WEST;
83
84                 /* Nice label at the top */
85                 c.gridx = 0;
86                 c.gridy = 0;
87                 c.gridwidth = 3;
88                 c.fill = GridBagConstraints.NONE;
89                 c.anchor = GridBagConstraints.CENTER;
90                 pane.add(new JLabel ("Configure AltOS UI"), c);
91
92                 c.gridx = 0;
93                 c.gridy = 1;
94                 c.gridwidth = 3;
95                 c.fill = GridBagConstraints.NONE;
96                 c.anchor = GridBagConstraints.CENTER;
97                 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
98
99                 /* Voice settings */
100                 c.gridx = 0;
101                 c.gridy = 2;
102                 c.gridwidth = 1;
103                 c.fill = GridBagConstraints.NONE;
104                 c.anchor = GridBagConstraints.WEST;
105                 pane.add(new JLabel("Voice"), c);
106
107                 enable_voice = new JRadioButton("Enable", AltosPreferences.voice());
108                 enable_voice.addActionListener(new ActionListener() {
109                                 public void actionPerformed(ActionEvent e) {
110                                         JRadioButton item = (JRadioButton) e.getSource();
111                                         boolean enabled = item.isSelected();
112                                         AltosPreferences.set_voice(enabled);
113                                         if (enabled)
114                                                 voice.speak_always("Enable voice.");
115                                         else
116                                                 voice.speak_always("Disable voice.");
117                                 }
118                         });
119                 c.gridx = 1;
120                 c.gridy = 2;
121                 c.gridwidth = 1;
122                 c.weightx = 1;
123                 c.fill = GridBagConstraints.NONE;
124                 c.anchor = GridBagConstraints.WEST;
125                 pane.add(enable_voice, c);
126
127                 c.gridx = 2;
128                 c.gridy = 2;
129                 c.gridwidth = 1;
130                 c.weightx = 1;
131                 c.fill = GridBagConstraints.NONE;
132                 c.anchor = GridBagConstraints.EAST;
133                 test_voice = new JButton("Test Voice");
134                 test_voice.addActionListener(new ActionListener() {
135                                 public void actionPerformed(ActionEvent e) {
136                                         voice.speak("That's one small step for man; one giant leap for mankind.");
137                                 }
138                         });
139                 pane.add(test_voice, c);
140
141                 /* Log directory settings */
142                 c.gridx = 0;
143                 c.gridy = 3;
144                 c.gridwidth = 1;
145                 c.fill = GridBagConstraints.NONE;
146                 c.anchor = GridBagConstraints.WEST;
147                 pane.add(new JLabel("Log Directory"), c);
148
149                 configure_log = new JButton(AltosPreferences.logdir().getPath());
150                 configure_log.addActionListener(new ActionListener() {
151                                 public void actionPerformed(ActionEvent e) {
152                                         AltosPreferences.ConfigureLog();
153                                         configure_log.setText(AltosPreferences.logdir().getPath());
154                                 }
155                         });
156                 c.gridx = 1;
157                 c.gridy = 3;
158                 c.gridwidth = 2;
159                 c.fill = GridBagConstraints.BOTH;
160                 c.anchor = GridBagConstraints.WEST;
161                 pane.add(configure_log, c);
162
163                 /* Callsign setting */
164                 c.gridx = 0;
165                 c.gridy = 4;
166                 c.gridwidth = 1;
167                 c.fill = GridBagConstraints.NONE;
168                 c.anchor = GridBagConstraints.WEST;
169                 pane.add(new JLabel("Callsign"), c);
170
171                 callsign_value = new JTextField(AltosPreferences.callsign());
172                 callsign_value.getDocument().addDocumentListener(this);
173                 c.gridx = 1;
174                 c.gridy = 4;
175                 c.gridwidth = 2;
176                 c.fill = GridBagConstraints.BOTH;
177                 c.anchor = GridBagConstraints.WEST;
178                 pane.add(callsign_value, c);
179
180                 /* Serial debug setting */
181                 c.gridx = 0;
182                 c.gridy = 5;
183                 c.gridwidth = 1;
184                 c.fill = GridBagConstraints.NONE;
185                 c.anchor = GridBagConstraints.WEST;
186                 pane.add(new JLabel("Serial Debug"), c);
187
188                 serial_debug = new JRadioButton("Enable", AltosPreferences.serial_debug());
189                 serial_debug.addActionListener(new ActionListener() {
190                                 public void actionPerformed(ActionEvent e) {
191                                         JRadioButton item = (JRadioButton) e.getSource();
192                                         boolean enabled = item.isSelected();
193                                         AltosPreferences.set_serial_debug(enabled);
194                                 }
195                         });
196
197                 c.gridx = 1;
198                 c.gridy = 5;
199                 c.gridwidth = 3;
200                 c.fill = GridBagConstraints.NONE;
201                 c.anchor = GridBagConstraints.WEST;
202                 pane.add(serial_debug, c);
203
204                 manage_bluetooth = new JButton("Manage Bluetooth");
205                 manage_bluetooth.addActionListener(new ActionListener() {
206                                 public void actionPerformed(ActionEvent e) {
207                                         AltosBTManage.show(owner, Altos.bt_known);
208                                 }
209                         });
210                 c.gridx = 1;
211                 c.gridy = 6;
212                 c.gridwidth = 3;
213                 c.fill = GridBagConstraints.NONE;
214                 c.anchor = GridBagConstraints.WEST;
215                 pane.add(manage_bluetooth, c);
216
217                 /* And a close button at the bottom */
218                 close = new JButton("Close");
219                 close.addActionListener(new ActionListener() {
220                                 public void actionPerformed(ActionEvent e) {
221                                         setVisible(false);
222                                 }
223                         });
224                 c.gridx = 0;
225                 c.gridy = 7;
226                 c.gridwidth = 3;
227                 c.fill = GridBagConstraints.NONE;
228                 c.anchor = GridBagConstraints.CENTER;
229                 pane.add(close, c);
230
231                 pack();
232                 setLocationRelativeTo(owner);
233                 setVisible(true);
234         }
235 }