altosui: Add tool-tips to config dialogs
[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                 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
129
130                 c.gridx = 2;
131                 c.gridy = 2;
132                 c.gridwidth = 1;
133                 c.weightx = 1;
134                 c.fill = GridBagConstraints.NONE;
135                 c.anchor = GridBagConstraints.EAST;
136                 test_voice = new JButton("Test Voice");
137                 test_voice.addActionListener(new ActionListener() {
138                                 public void actionPerformed(ActionEvent e) {
139                                         voice.speak("That's one small step for man; one giant leap for mankind.");
140                                 }
141                         });
142                 pane.add(test_voice, c);
143                 test_voice.setToolTipText("Play a stock audio clip to check volume");
144
145                 /* Log directory settings */
146                 c.gridx = 0;
147                 c.gridy = 3;
148                 c.gridwidth = 1;
149                 c.fill = GridBagConstraints.NONE;
150                 c.anchor = GridBagConstraints.WEST;
151                 pane.add(new JLabel("Log Directory"), c);
152
153                 configure_log = new JButton(AltosPreferences.logdir().getPath());
154                 configure_log.addActionListener(new ActionListener() {
155                                 public void actionPerformed(ActionEvent e) {
156                                         AltosPreferences.ConfigureLog();
157                                         configure_log.setText(AltosPreferences.logdir().getPath());
158                                 }
159                         });
160                 c.gridx = 1;
161                 c.gridy = 3;
162                 c.gridwidth = 2;
163                 c.fill = GridBagConstraints.BOTH;
164                 c.anchor = GridBagConstraints.WEST;
165                 pane.add(configure_log, c);
166                 configure_log.setToolTipText("Which directory flight logs are stored in");
167
168                 /* Callsign setting */
169                 c.gridx = 0;
170                 c.gridy = 4;
171                 c.gridwidth = 1;
172                 c.fill = GridBagConstraints.NONE;
173                 c.anchor = GridBagConstraints.WEST;
174                 pane.add(new JLabel("Callsign"), c);
175
176                 callsign_value = new JTextField(AltosPreferences.callsign());
177                 callsign_value.getDocument().addDocumentListener(this);
178                 c.gridx = 1;
179                 c.gridy = 4;
180                 c.gridwidth = 2;
181                 c.fill = GridBagConstraints.BOTH;
182                 c.anchor = GridBagConstraints.WEST;
183                 pane.add(callsign_value, c);
184                 callsign_value.setToolTipText("Callsign sent in packet mode");
185
186                 /* Serial debug setting */
187                 c.gridx = 0;
188                 c.gridy = 5;
189                 c.gridwidth = 1;
190                 c.fill = GridBagConstraints.NONE;
191                 c.anchor = GridBagConstraints.WEST;
192                 pane.add(new JLabel("Serial Debug"), c);
193
194                 serial_debug = new JRadioButton("Enable", AltosPreferences.serial_debug());
195                 serial_debug.addActionListener(new ActionListener() {
196                                 public void actionPerformed(ActionEvent e) {
197                                         JRadioButton item = (JRadioButton) e.getSource();
198                                         boolean enabled = item.isSelected();
199                                         AltosPreferences.set_serial_debug(enabled);
200                                 }
201                         });
202                 serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
203
204                 c.gridx = 1;
205                 c.gridy = 5;
206                 c.gridwidth = 3;
207                 c.fill = GridBagConstraints.NONE;
208                 c.anchor = GridBagConstraints.WEST;
209                 pane.add(serial_debug, c);
210
211 // BLUETOOTH
212 //              manage_bluetooth = new JButton("Manage Bluetooth");
213 //              manage_bluetooth.addActionListener(new ActionListener() {
214 //                              public void actionPerformed(ActionEvent e) {
215 //                                      AltosBTManage.show(owner, Altos.bt_known);
216 //                              }
217 //                      });
218 //              c.gridx = 0;
219 //              c.gridy = 6;
220 //              c.gridwidth = 2;
221 //              c.fill = GridBagConstraints.NONE;
222 //              c.anchor = GridBagConstraints.WEST;
223 //              pane.add(manage_bluetooth, c);
224
225                 manage_frequencies = new JButton("Manage Frequencies");
226                 manage_frequencies.addActionListener(new ActionListener() {
227                                 public void actionPerformed(ActionEvent e) {
228                                         AltosConfigFreqUI.show(owner);
229                                 }
230                         });
231                 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
232 // BLUETOOTH
233 //              c.gridx = 2;
234                 c.gridx = 1;
235                 c.gridy = 6;
236                 c.gridwidth = 2;
237                 c.fill = GridBagConstraints.NONE;
238                 c.anchor = GridBagConstraints.WEST;
239                 pane.add(manage_frequencies, c);
240
241                 /* And a close button at the bottom */
242                 close = new JButton("Close");
243                 close.addActionListener(new ActionListener() {
244                                 public void actionPerformed(ActionEvent e) {
245                                         setVisible(false);
246                                 }
247                         });
248                 c.gridx = 0;
249                 c.gridy = 7;
250                 c.gridwidth = 3;
251                 c.fill = GridBagConstraints.NONE;
252                 c.anchor = GridBagConstraints.CENTER;
253                 pane.add(close, c);
254
255                 pack();
256                 setLocationRelativeTo(owner);
257                 setVisible(true);
258         }
259 }