docs: Document altosui "Graph Data" button
[fw/altos] / ao-tools / 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         /* DocumentListener interface methods */
51         public void changedUpdate(DocumentEvent e) {
52                 AltosPreferences.set_callsign(callsign_value.getText());
53         }
54
55         public void insertUpdate(DocumentEvent e) {
56                 changedUpdate(e);
57         }
58
59         public void removeUpdate(DocumentEvent e) {
60                 changedUpdate(e);
61         }
62
63         public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
64                 super(in_owner, "Configure AltosUI", false);
65
66                 GridBagConstraints      c;
67
68                 Insets insets = new Insets(4, 4, 4, 4);
69
70                 owner = in_owner;
71                 voice = in_voice;
72                 pane = getContentPane();
73                 pane.setLayout(new GridBagLayout());
74
75                 c = new GridBagConstraints();
76                 c.insets = insets;
77                 c.fill = GridBagConstraints.NONE;
78                 c.anchor = GridBagConstraints.WEST;
79
80                 /* Nice label at the top */
81                 c.gridx = 0;
82                 c.gridy = 0;
83                 c.gridwidth = 3;
84                 c.fill = GridBagConstraints.NONE;
85                 c.anchor = GridBagConstraints.CENTER;
86                 pane.add(new JLabel ("Configure AltOS UI"), c);
87
88                 /* Voice settings */
89                 c.gridx = 0;
90                 c.gridy = 1;
91                 c.gridwidth = 1;
92                 c.fill = GridBagConstraints.NONE;
93                 c.anchor = GridBagConstraints.WEST;
94                 pane.add(new JLabel("Voice"), c);
95
96                 enable_voice = new JRadioButton("Enable", AltosPreferences.voice());
97                 enable_voice.addActionListener(new ActionListener() {
98                                 public void actionPerformed(ActionEvent e) {
99                                         JRadioButton item = (JRadioButton) e.getSource();
100                                         boolean enabled = item.isSelected();
101                                         AltosPreferences.set_voice(enabled);
102                                         if (enabled)
103                                                 voice.speak_always("Enable voice.");
104                                         else
105                                                 voice.speak_always("Disable voice.");
106                                 }
107                         });
108                 c.gridx = 1;
109                 c.gridy = 1;
110                 c.gridwidth = 1;
111                 c.weightx = 1;
112                 c.fill = GridBagConstraints.NONE;
113                 c.anchor = GridBagConstraints.WEST;
114                 pane.add(enable_voice, c);
115
116                 c.gridx = 2;
117                 c.gridy = 1;
118                 c.gridwidth = 1;
119                 c.weightx = 1;
120                 c.fill = GridBagConstraints.NONE;
121                 c.anchor = GridBagConstraints.EAST;
122                 test_voice = new JButton("Test Voice");
123                 test_voice.addActionListener(new ActionListener() {
124                                 public void actionPerformed(ActionEvent e) {
125                                         voice.speak("That's one small step for man; one giant leap for mankind.");
126                                 }
127                         });
128                 pane.add(test_voice, c);
129
130                 /* Log directory settings */
131                 c.gridx = 0;
132                 c.gridy = 2;
133                 c.gridwidth = 1;
134                 c.fill = GridBagConstraints.NONE;
135                 c.anchor = GridBagConstraints.WEST;
136                 pane.add(new JLabel("Log Directory"), c);
137
138                 configure_log = new JButton(AltosPreferences.logdir().getPath());
139                 configure_log.addActionListener(new ActionListener() {
140                                 public void actionPerformed(ActionEvent e) {
141                                         AltosPreferences.ConfigureLog();
142                                         configure_log.setText(AltosPreferences.logdir().getPath());
143                                 }
144                         });
145                 c.gridx = 1;
146                 c.gridy = 2;
147                 c.gridwidth = 2;
148                 c.fill = GridBagConstraints.BOTH;
149                 c.anchor = GridBagConstraints.WEST;
150                 pane.add(configure_log, c);
151
152                 /* Callsign setting */
153                 c.gridx = 0;
154                 c.gridy = 3;
155                 c.gridwidth = 1;
156                 c.fill = GridBagConstraints.NONE;
157                 c.anchor = GridBagConstraints.WEST;
158                 pane.add(new JLabel("Callsign"), c);
159
160                 callsign_value = new JTextField(AltosPreferences.callsign());
161                 callsign_value.getDocument().addDocumentListener(this);
162                 c.gridx = 1;
163                 c.gridy = 3;
164                 c.gridwidth = 2;
165                 c.fill = GridBagConstraints.BOTH;
166                 c.anchor = GridBagConstraints.WEST;
167                 pane.add(callsign_value, c);
168
169                 /* And a close button at the bottom */
170                 close = new JButton("Close");
171                 close.addActionListener(new ActionListener() {
172                                 public void actionPerformed(ActionEvent e) {
173                                         setVisible(false);
174                                 }
175                         });
176                 c.gridx = 0;
177                 c.gridy = 4;
178                 c.gridwidth = 3;
179                 c.fill = GridBagConstraints.NONE;
180                 c.anchor = GridBagConstraints.CENTER;
181                 pane.add(close, c);
182
183                 pack();
184                 setLocationRelativeTo(owner);
185                 setVisible(true);
186         }
187 }