Bump java lib versions in preparation for 1.9.2
[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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package altosui;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.beans.*;
24 import javax.swing.*;
25 import javax.swing.event.*;
26 import org.altusmetrum.altosuilib_14.*;
27
28 public class AltosConfigureUI
29         extends AltosUIConfigure
30         implements DocumentListener
31 {
32         AltosVoice      voice;
33
34         public JTextField       callsign_value;
35         public JComboBox<String>        position_value;
36
37         /* DocumentListener interface methods */
38         public void insertUpdate(DocumentEvent e) {
39                 changedUpdate(e);
40         }
41
42         public void removeUpdate(DocumentEvent e) {
43                 changedUpdate(e);
44         }
45
46         public void changedUpdate(DocumentEvent e) {
47                 if (callsign_value != null)
48                         AltosUIPreferences.set_callsign(callsign_value.getText());
49         }
50
51         public void add_voice() {
52
53                 /* Voice settings */
54                 pane.add(new JLabel("Voice"), constraints(0, 1));
55
56                 JRadioButton enable_voice = new JRadioButton("Enable", AltosUIPreferences.voice());
57                 enable_voice.addActionListener(new ActionListener() {
58                                 public void actionPerformed(ActionEvent e) {
59                                         JRadioButton item = (JRadioButton) e.getSource();
60                                         boolean enabled = item.isSelected();
61                                         AltosUIPreferences.set_voice(enabled);
62                                         if (enabled)
63                                                 voice.speak_always("Enable voice.");
64                                         else
65                                                 voice.speak_always("Disable voice.");
66                                 }
67                         });
68                 pane.add(enable_voice, constraints(1, 1));
69                 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
70
71                 JButton test_voice = new JButton("Test Voice");
72                 test_voice.addActionListener(new ActionListener() {
73                                 public void actionPerformed(ActionEvent e) {
74                                         voice.speak("That's one small step for man; one giant leap for mankind.");
75                                 }
76                         });
77                 pane.add(test_voice, constraints(2, 1));
78                 test_voice.setToolTipText("Play a stock audio clip to check volume");
79                 row++;
80         }
81
82         public void add_callsign() {
83                 /* Callsign setting */
84                 pane.add(new JLabel("Callsign"), constraints(0, 1));
85
86                 callsign_value = new JTextField(AltosUIPreferences.callsign());
87                 callsign_value.getDocument().addDocumentListener(this);
88                 callsign_value.setToolTipText("Callsign sent in packet mode");
89                 pane.add(callsign_value, constraints(1, 2, GridBagConstraints.BOTH));
90                 row++;
91         }
92
93         boolean has_bluetooth;
94
95         public void add_bluetooth() {
96                 JButton manage_bluetooth = new JButton("Manage Bluetooth");
97                 manage_bluetooth.addActionListener(new ActionListener() {
98                                 public void actionPerformed(ActionEvent e) {
99                                         AltosBTManage.show(owner, AltosBTKnown.bt_known());
100                                 }
101                         });
102                 pane.add(manage_bluetooth, constraints(0, 2));
103                 /* in the same row as add_frequencies, so don't bump row */
104                 has_bluetooth = true;
105         }
106
107         public void add_frequencies() {
108                 JButton manage_frequencies = new JButton("Manage Frequencies");
109                 manage_frequencies.addActionListener(new ActionListener() {
110                                 public void actionPerformed(ActionEvent e) {
111                                         AltosConfigFreqUI.show(owner);
112                                 }
113                         });
114                 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
115                 if (has_bluetooth)
116                         pane.add(manage_frequencies, constraints(2, 1));
117                 else
118                         pane.add(manage_frequencies, constraints(0, 3));
119                 row++;
120         }
121
122         final static String[] position_names = {
123                 "Top left",
124                 "Top",
125                 "Top right",
126                 "Left",
127                 "Center",
128                 "Right",
129                 "Bottom left",
130                 "Bottom",
131                 "Bottom right",
132         };
133
134         public void add_position() {
135                 pane.add(new JLabel ("Menu position"), constraints(0, 1));
136
137                 position_value = new JComboBox<String>(position_names);
138                 position_value.setMaximumRowCount(position_names.length);
139                 int position = AltosUIPreferences.position();
140                 position_value.setSelectedIndex(position);
141                 position_value.addActionListener(new ActionListener() {
142                                 public void actionPerformed(ActionEvent e) {
143                                         int     position = position_value.getSelectedIndex();
144                                         AltosUIPreferences.set_position(position);
145                                 }
146                         });
147                 pane.add(position_value, constraints(1, 2, GridBagConstraints.BOTH));
148                 position_value.setToolTipText("Position of main AltosUI window");
149                 row++;
150         }
151
152         public AltosConfigureUI(JFrame owner, AltosVoice voice) {
153                 super(owner);
154
155                 this.voice = voice;
156         }
157 }