altosui: eliminate menu bar, moving elements to buttons.
[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 java.io.*;
26 import java.util.*;
27 import java.text.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
30
31 public class AltosConfigureUI extends JDialog {
32         JFrame          owner;
33         AltosVoice      voice;
34         Container       pane;
35
36         JRadioButton    enable_voice;
37         JButton         test_voice;
38         JButton         close;
39
40         JButton         configure_log;
41         JTextField      log_directory;
42
43         public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
44                 super(in_owner, "Configure AltosUI", false);
45
46                 GridBagConstraints      c;
47
48                 Insets insets = new Insets(4, 4, 4, 4);
49
50                 owner = in_owner;
51                 voice = in_voice;
52                 pane = getContentPane();
53                 pane.setLayout(new GridBagLayout());
54
55                 c = new GridBagConstraints();
56                 c.insets = insets;
57                 c.fill = GridBagConstraints.NONE;
58                 c.anchor = GridBagConstraints.CENTER;
59
60                 /* Enable Voice */
61                 c.gridx = 0;
62                 c.gridy = 0;
63                 enable_voice = new JRadioButton("Enable Voice", AltosPreferences.voice());
64                 enable_voice.addActionListener(new ActionListener() {
65                                 public void actionPerformed(ActionEvent e) {
66                                         JRadioButton item = (JRadioButton) e.getSource();
67                                         boolean enabled = item.isSelected();
68                                         AltosPreferences.set_voice(enabled);
69                                         if (enabled)
70                                                 voice.speak_always("Enable voice.");
71                                         else
72                                                 voice.speak_always("Disable voice.");
73                                 }
74                         });
75                 pane.add(enable_voice, c);
76                 c.gridx = 1;
77                 c.gridy = 0;
78                 test_voice = new JButton("Test Voice");
79                 test_voice.addActionListener(new ActionListener() {
80                                 public void actionPerformed(ActionEvent e) {
81                                         voice.speak("That's one small step for man; one giant leap for mankind.");
82                                 }
83                         });
84                 pane.add(test_voice, c);
85
86                 close = new JButton("Close");
87                 close.addActionListener(new ActionListener() {
88                                 public void actionPerformed(ActionEvent e) {
89                                         setVisible(false);
90                                 }
91                         });
92                 c.gridx = 0;
93                 c.gridy = 3;
94                 c.gridwidth = 2;
95                 pane.add(close, c);
96
97                 configure_log = new JButton("Configure Log");
98                 configure_log.addActionListener(new ActionListener() {
99                                 public void actionPerformed(ActionEvent e) {
100                                         AltosPreferences.ConfigureLog();
101                                         log_directory.setText(AltosPreferences.logdir().getPath());
102                                 }
103                         });
104                 c.gridwidth = 1;
105
106                 c.gridx = 0;
107                 c.gridy = 2;
108                 pane.add(configure_log, c);
109
110                 log_directory = new JTextField(AltosPreferences.logdir().getPath());
111                 c.gridx = 1;
112                 c.gridy = 2;
113                 c.fill = GridBagConstraints.BOTH;
114                 pane.add(log_directory, c);
115
116                 pack();
117                 setLocationRelativeTo(owner);
118                 setVisible(true);
119         }
120 }