]> git.gag.com Git - fw/altos/blob - altosui/AltosConfigureUI.java
altosdroid: Import initial versions of XML and Java for Tab content
[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_1.*;
26
27 public class AltosConfigureUI
28         extends AltosUIConfigure
29         implements DocumentListener
30 {
31         AltosVoice      voice;
32
33         public JTextField       callsign_value;
34         public JComboBox        position_value;
35
36         /* DocumentListener interface methods */
37         public void insertUpdate(DocumentEvent e) {
38                 changedUpdate(e);
39         }
40
41         public void removeUpdate(DocumentEvent e) {
42                 changedUpdate(e);
43         }
44
45         public void changedUpdate(DocumentEvent e) {
46                 if (callsign_value != null)
47                         AltosUIPreferences.set_callsign(callsign_value.getText());
48         }
49
50         public void add_voice() {
51
52                 /* Voice settings */
53                 pane.add(new JLabel("Voice"), constraints(0, 1));
54
55                 JRadioButton enable_voice = new JRadioButton("Enable", AltosUIPreferences.voice());
56                 enable_voice.addActionListener(new ActionListener() {
57                                 public void actionPerformed(ActionEvent e) {
58                                         JRadioButton item = (JRadioButton) e.getSource();
59                                         boolean enabled = item.isSelected();
60                                         AltosUIPreferences.set_voice(enabled);
61                                         if (enabled)
62                                                 voice.speak_always("Enable voice.");
63                                         else
64                                                 voice.speak_always("Disable voice.");
65                                 }
66                         });
67                 pane.add(enable_voice, constraints(1, 1));
68                 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
69
70                 JButton test_voice = new JButton("Test Voice");
71                 test_voice.addActionListener(new ActionListener() {
72                                 public void actionPerformed(ActionEvent e) {
73                                         voice.speak("That's one small step for man; one giant leap for mankind.");
74                                 }
75                         });
76                 pane.add(test_voice, constraints(2, 1));
77                 test_voice.setToolTipText("Play a stock audio clip to check volume");
78                 row++;
79         }
80
81         public void add_callsign() {
82                 /* Callsign setting */
83                 pane.add(new JLabel("Callsign"), constraints(0, 1));
84
85                 callsign_value = new JTextField(AltosUIPreferences.callsign());
86                 callsign_value.getDocument().addDocumentListener(this);
87                 callsign_value.setToolTipText("Callsign sent in packet mode");
88                 pane.add(callsign_value, constraints(1, 2, GridBagConstraints.BOTH));
89                 row++;
90         }
91
92         public void add_bluetooth() {
93                 JButton manage_bluetooth = new JButton("Manage Bluetooth");
94                 manage_bluetooth.addActionListener(new ActionListener() {
95                                 public void actionPerformed(ActionEvent e) {
96                                         AltosBTManage.show(owner, AltosBTKnown.bt_known());
97                                 }
98                         });
99                 pane.add(manage_bluetooth, constraints(0, 2));
100                 /* in the same row as add_frequencies, so don't bump row */
101         }
102
103         public void add_frequencies() {
104                 JButton manage_frequencies = new JButton("Manage Frequencies");
105                 manage_frequencies.addActionListener(new ActionListener() {
106                                 public void actionPerformed(ActionEvent e) {
107                                         AltosConfigFreqUI.show(owner);
108                                 }
109                         });
110                 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
111                 pane.add(manage_frequencies, constraints(2, 1));
112                 row++;
113         }
114
115         final static String[] position_names = {
116                 "Top left",
117                 "Top",
118                 "Top right",
119                 "Left",
120                 "Center",
121                 "Right",
122                 "Bottom left",
123                 "Bottom",
124                 "Bottom right",
125         };
126                 
127         public void add_position() {
128                 pane.add(new JLabel ("Menu position"), constraints(0, 1));
129                 
130                 position_value = new JComboBox (position_names);
131                 position_value.setMaximumRowCount(position_names.length);
132                 int position = AltosUIPreferences.position();
133                 position_value.setSelectedIndex(position);
134                 position_value.addActionListener(new ActionListener() {
135                                 public void actionPerformed(ActionEvent e) {
136                                         int     position = position_value.getSelectedIndex();
137                                         AltosUIPreferences.set_position(position);
138                                 }
139                         });
140                 pane.add(position_value, constraints(1, 2, GridBagConstraints.BOTH));
141                 position_value.setToolTipText("Position of main AltosUI window");
142                 row++;
143         }
144
145         public AltosConfigureUI(JFrame owner, AltosVoice voice) {
146                 super(owner);
147
148                 this.voice = voice;
149         }
150 }