2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
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.
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.
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.
21 import java.awt.event.*;
24 import javax.swing.filechooser.FileNameExtensionFilter;
25 import javax.swing.table.*;
26 import javax.swing.event.*;
30 import java.util.prefs.*;
31 import java.util.concurrent.LinkedBlockingQueue;
32 import javax.swing.plaf.basic.*;
34 class DelegatingRenderer implements ListCellRenderer {
37 public static void install(JComboBox comboBox) {
38 DelegatingRenderer renderer = new DelegatingRenderer(comboBox);
39 renderer.initialise();
40 comboBox.setRenderer(renderer);
44 private final JComboBox comboBox;
47 private ListCellRenderer delegate;
50 private DelegatingRenderer(JComboBox comboBox) {
51 this.comboBox = comboBox;
55 private void initialise() {
56 delegate = new JComboBox().getRenderer();
57 comboBox.addPropertyChangeListener("UI", new PropertyChangeListener() {
59 public void propertyChange(PropertyChangeEvent evt) {
60 delegate = new JComboBox().getRenderer();
66 public Component getListCellRendererComponent(JList list,
67 Object value, int index, boolean isSelected, boolean cellHasFocus) {
69 return delegate.getListCellRendererComponent(list,
70 ((UIManager.LookAndFeelInfo) value).getName(),
71 index, isSelected, cellHasFocus);
75 public class AltosConfigureUI
77 implements DocumentListener
83 JRadioButton enable_voice;
87 JButton configure_log;
88 JTextField log_directory;
90 JLabel callsign_label;
91 JTextField callsign_value;
93 JLabel font_size_label;
94 JComboBox font_size_value;
96 JLabel look_and_feel_label;
97 JComboBox look_and_feel_value;
99 JRadioButton serial_debug;
101 JButton manage_bluetooth;
102 JButton manage_frequencies;
104 final static String[] font_size_names = { "Small", "Medium", "Large" };
106 /* DocumentListener interface methods */
107 public void changedUpdate(DocumentEvent e) {
108 AltosPreferences.set_callsign(callsign_value.getText());
111 public void insertUpdate(DocumentEvent e) {
115 public void removeUpdate(DocumentEvent e) {
119 public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
120 super(in_owner, "Configure AltosUI", false);
122 GridBagConstraints c;
124 Insets insets = new Insets(4, 4, 4, 4);
130 pane = getContentPane();
131 pane.setLayout(new GridBagLayout());
133 c = new GridBagConstraints();
135 c.fill = GridBagConstraints.NONE;
136 c.anchor = GridBagConstraints.WEST;
138 /* Nice label at the top */
142 c.fill = GridBagConstraints.NONE;
143 c.anchor = GridBagConstraints.CENTER;
144 pane.add(new JLabel ("Configure AltOS UI"), c);
149 c.fill = GridBagConstraints.NONE;
150 c.anchor = GridBagConstraints.CENTER;
151 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
157 c.fill = GridBagConstraints.NONE;
158 c.anchor = GridBagConstraints.WEST;
159 pane.add(new JLabel("Voice"), c);
161 enable_voice = new JRadioButton("Enable", AltosPreferences.voice());
162 enable_voice.addActionListener(new ActionListener() {
163 public void actionPerformed(ActionEvent e) {
164 JRadioButton item = (JRadioButton) e.getSource();
165 boolean enabled = item.isSelected();
166 AltosPreferences.set_voice(enabled);
168 voice.speak_always("Enable voice.");
170 voice.speak_always("Disable voice.");
177 c.fill = GridBagConstraints.NONE;
178 c.anchor = GridBagConstraints.WEST;
179 pane.add(enable_voice, c);
180 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
186 c.fill = GridBagConstraints.NONE;
187 c.anchor = GridBagConstraints.EAST;
188 test_voice = new JButton("Test Voice");
189 test_voice.addActionListener(new ActionListener() {
190 public void actionPerformed(ActionEvent e) {
191 voice.speak("That's one small step for man; one giant leap for mankind.");
194 pane.add(test_voice, c);
195 test_voice.setToolTipText("Play a stock audio clip to check volume");
197 /* Log directory settings */
201 c.fill = GridBagConstraints.NONE;
202 c.anchor = GridBagConstraints.WEST;
203 pane.add(new JLabel("Log Directory"), c);
205 configure_log = new JButton(AltosPreferences.logdir().getPath());
206 configure_log.addActionListener(new ActionListener() {
207 public void actionPerformed(ActionEvent e) {
208 AltosPreferences.ConfigureLog();
209 configure_log.setText(AltosPreferences.logdir().getPath());
215 c.fill = GridBagConstraints.BOTH;
216 c.anchor = GridBagConstraints.WEST;
217 pane.add(configure_log, c);
218 configure_log.setToolTipText("Which directory flight logs are stored in");
220 /* Callsign setting */
224 c.fill = GridBagConstraints.NONE;
225 c.anchor = GridBagConstraints.WEST;
226 pane.add(new JLabel("Callsign"), c);
228 callsign_value = new JTextField(AltosPreferences.callsign());
229 callsign_value.getDocument().addDocumentListener(this);
233 c.fill = GridBagConstraints.BOTH;
234 c.anchor = GridBagConstraints.WEST;
235 pane.add(callsign_value, c);
236 callsign_value.setToolTipText("Callsign sent in packet mode");
238 /* Font size setting */
242 c.fill = GridBagConstraints.NONE;
243 c.anchor = GridBagConstraints.WEST;
244 pane.add(new JLabel("Font size"), c);
246 font_size_value = new JComboBox(font_size_names);
247 int font_size = AltosPreferences.font_size();
248 font_size_value.setSelectedIndex(font_size - Altos.font_size_small);
249 font_size_value.addActionListener(new ActionListener() {
250 public void actionPerformed(ActionEvent e) {
251 int size = font_size_value.getSelectedIndex() + Altos.font_size_small;
253 AltosPreferences.set_font_size(size);
259 c.fill = GridBagConstraints.BOTH;
260 c.anchor = GridBagConstraints.WEST;
261 pane.add(font_size_value, c);
262 font_size_value.setToolTipText("Font size used in telemetry window");
264 /* Look & Feel setting */
268 c.fill = GridBagConstraints.NONE;
269 c.anchor = GridBagConstraints.WEST;
270 pane.add(new JLabel("Look & feel"), c);
272 class LookAndFeelRenderer extends BasicComboBoxRenderer implements ListCellRenderer {
274 public LookAndFeelRenderer() {
278 public Component getListCellRendererComponent(
283 boolean cellHasFocus)
285 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
286 setText(((UIManager.LookAndFeelInfo) value).getName());
291 final UIManager.LookAndFeelInfo[] look_and_feels = UIManager.getInstalledLookAndFeels();
293 System.out.printf("look_and_feels %d\n", look_and_feels.length);
294 look_and_feel_value = new JComboBox(look_and_feels);
296 DelegatingRenderer.install(look_and_feel_value);
298 String look_and_feel = AltosPreferences.look_and_feel();
299 for (int i = 0; i < look_and_feels.length; i++)
300 if (look_and_feel.equals(look_and_feels[i].getClassName()))
301 look_and_feel_value.setSelectedIndex(i);
303 look_and_feel_value.addActionListener(new ActionListener() {
304 public void actionPerformed(ActionEvent e) {
305 int id = look_and_feel_value.getSelectedIndex();
307 AltosPreferences.set_look_and_feel(look_and_feels[id].getClassName());
313 c.fill = GridBagConstraints.BOTH;
314 c.anchor = GridBagConstraints.WEST;
315 pane.add(look_and_feel_value, c);
316 look_and_feel_value.setToolTipText("Look&feel used for new windows");
318 /* Serial debug setting */
322 c.fill = GridBagConstraints.NONE;
323 c.anchor = GridBagConstraints.WEST;
324 pane.add(new JLabel("Serial Debug"), c);
326 serial_debug = new JRadioButton("Enable", AltosPreferences.serial_debug());
327 serial_debug.addActionListener(new ActionListener() {
328 public void actionPerformed(ActionEvent e) {
329 JRadioButton item = (JRadioButton) e.getSource();
330 boolean enabled = item.isSelected();
331 AltosPreferences.set_serial_debug(enabled);
334 serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
339 c.fill = GridBagConstraints.NONE;
340 c.anchor = GridBagConstraints.WEST;
341 pane.add(serial_debug, c);
343 manage_bluetooth = new JButton("Manage Bluetooth");
344 manage_bluetooth.addActionListener(new ActionListener() {
345 public void actionPerformed(ActionEvent e) {
346 AltosBTManage.show(owner, Altos.bt_known);
352 c.fill = GridBagConstraints.NONE;
353 c.anchor = GridBagConstraints.WEST;
354 pane.add(manage_bluetooth, c);
356 manage_frequencies = new JButton("Manage Frequencies");
357 manage_frequencies.addActionListener(new ActionListener() {
358 public void actionPerformed(ActionEvent e) {
359 AltosConfigFreqUI.show(owner);
362 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
367 c.fill = GridBagConstraints.NONE;
368 c.anchor = GridBagConstraints.WEST;
369 pane.add(manage_frequencies, c);
371 /* And a close button at the bottom */
372 close = new JButton("Close");
373 close.addActionListener(new ActionListener() {
374 public void actionPerformed(ActionEvent e) {
381 c.fill = GridBagConstraints.NONE;
382 c.anchor = GridBagConstraints.CENTER;
386 setLocationRelativeTo(owner);