AltosSiteMapTile: adjust centering calculation
[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.CENTER;
79
80                 /* Enable Voice */
81                 c.gridx = 0;
82                 c.gridy = 0;
83                 enable_voice = new JRadioButton("Enable Voice", AltosPreferences.voice());
84                 enable_voice.addActionListener(new ActionListener() {
85                                 public void actionPerformed(ActionEvent e) {
86                                         JRadioButton item = (JRadioButton) e.getSource();
87                                         boolean enabled = item.isSelected();
88                                         AltosPreferences.set_voice(enabled);
89                                         if (enabled)
90                                                 voice.speak_always("Enable voice.");
91                                         else
92                                                 voice.speak_always("Disable voice.");
93                                 }
94                         });
95                 pane.add(enable_voice, c);
96                 c.gridx = 1;
97                 c.gridy = 0;
98                 test_voice = new JButton("Test Voice");
99                 test_voice.addActionListener(new ActionListener() {
100                                 public void actionPerformed(ActionEvent e) {
101                                         voice.speak("That's one small step for man; one giant leap for mankind.");
102                                 }
103                         });
104                 pane.add(test_voice, c);
105
106                 configure_log = new JButton("Configure Log");
107                 configure_log.addActionListener(new ActionListener() {
108                                 public void actionPerformed(ActionEvent e) {
109                                         AltosPreferences.ConfigureLog();
110                                         log_directory.setText(AltosPreferences.logdir().getPath());
111                                 }
112                         });
113                 c.gridwidth = 1;
114
115                 c.gridx = 0;
116                 c.gridy = 2;
117                 pane.add(configure_log, c);
118
119                 log_directory = new JTextField(AltosPreferences.logdir().getPath());
120                 c.gridx = 1;
121                 c.gridy = 2;
122                 c.fill = GridBagConstraints.BOTH;
123                 pane.add(log_directory, c);
124
125                 callsign_label = new JLabel("Callsign");
126                 c.gridx = 0;
127                 c.gridy = 3;
128                 pane.add(callsign_label, c);
129
130                 callsign_value = new JTextField(AltosPreferences.callsign());
131                 callsign_value.getDocument().addDocumentListener(this);
132                 c.gridx = 1;
133                 c.gridy = 3;
134                 pane.add(callsign_value, c);
135
136                 close = new JButton("Close");
137                 close.addActionListener(new ActionListener() {
138                                 public void actionPerformed(ActionEvent e) {
139                                         setVisible(false);
140                                 }
141                         });
142                 c.gridx = 0;
143                 c.gridy = 4;
144                 c.gridwidth = 2;
145                 c.fill = GridBagConstraints.NONE;
146                 pane.add(close, c);
147
148                 pack();
149                 setLocationRelativeTo(owner);
150                 setVisible(true);
151         }
152 }