Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[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 java.beans.*;
23 import javax.swing.*;
24 import javax.swing.event.*;
25 import org.altusmetrum.altosuilib.*;
26
27 public class AltosConfigureUI
28         extends AltosUIConfigure
29         implements DocumentListener
30 {
31         AltosVoice      voice;
32
33         public JTextField       callsign_value;
34
35         /* DocumentListener interface methods */
36         public void insertUpdate(DocumentEvent e) {
37                 changedUpdate(e);
38         }
39
40         public void removeUpdate(DocumentEvent e) {
41                 changedUpdate(e);
42         }
43
44         public void changedUpdate(DocumentEvent e) {
45                 if (callsign_value != null) 
46                         AltosUIPreferences.set_callsign(callsign_value.getText());
47         }
48
49         public void add_voice() {
50
51                 /* Voice settings */
52                 pane.add(new JLabel("Voice"), constraints(0, 1));
53
54                 JRadioButton enable_voice = new JRadioButton("Enable", AltosUIPreferences.voice());
55                 enable_voice.addActionListener(new ActionListener() {
56                                 public void actionPerformed(ActionEvent e) {
57                                         JRadioButton item = (JRadioButton) e.getSource();
58                                         boolean enabled = item.isSelected();
59                                         AltosUIPreferences.set_voice(enabled);
60                                         if (enabled)
61                                                 voice.speak_always("Enable voice.");
62                                         else
63                                                 voice.speak_always("Disable voice.");
64                                 }
65                         });
66                 pane.add(enable_voice, constraints(1, 1));
67                 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
68
69                 JButton test_voice = new JButton("Test Voice");
70                 test_voice.addActionListener(new ActionListener() {
71                                 public void actionPerformed(ActionEvent e) {
72                                         voice.speak("That's one small step for man; one giant leap for mankind.");
73                                 }
74                         });
75                 pane.add(test_voice, constraints(2, 1));
76                 test_voice.setToolTipText("Play a stock audio clip to check volume");
77                 row++;
78         }
79
80         public void add_callsign() {
81                 /* Callsign setting */
82                 pane.add(new JLabel("Callsign"), constraints(0, 1));
83
84                 JTextField callsign_value = new JTextField(AltosUIPreferences.callsign());
85                 callsign_value.getDocument().addDocumentListener(this);
86                 callsign_value.setToolTipText("Callsign sent in packet mode");
87                 pane.add(callsign_value, constraints(1, 2, GridBagConstraints.BOTH));
88                 row++;
89         }
90
91         public void add_bluetooth() {
92                 JButton manage_bluetooth = new JButton("Manage Bluetooth");
93                 manage_bluetooth.addActionListener(new ActionListener() {
94                                 public void actionPerformed(ActionEvent e) {
95                                         AltosBTManage.show(owner, AltosBTKnown.bt_known());
96                                 }
97                         });
98                 pane.add(manage_bluetooth, constraints(0, 2));
99                 /* in the same row as add_frequencies, so don't bump row */
100         }
101
102         public void add_frequencies() {
103                 JButton manage_frequencies = new JButton("Manage Frequencies");
104                 manage_frequencies.addActionListener(new ActionListener() {
105                                 public void actionPerformed(ActionEvent e) {
106                                         AltosConfigFreqUI.show(owner);
107                                 }
108                         });
109                 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
110                 pane.add(manage_frequencies, constraints(2, 1));
111                 row++;
112         }
113
114         public AltosConfigureUI(JFrame owner, AltosVoice voice) {
115                 super(owner);
116
117                 this.voice = voice;
118         }
119 }