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.*;
33 import org.altusmetrum.AltosLib.*;
35 class DelegatingRenderer implements ListCellRenderer {
38 public static void install(JComboBox comboBox) {
39 DelegatingRenderer renderer = new DelegatingRenderer(comboBox);
40 renderer.initialise();
41 comboBox.setRenderer(renderer);
45 private final JComboBox comboBox;
48 private ListCellRenderer delegate;
51 private DelegatingRenderer(JComboBox comboBox) {
52 this.comboBox = comboBox;
56 private void initialise() {
57 delegate = new JComboBox().getRenderer();
58 comboBox.addPropertyChangeListener("UI", new PropertyChangeListener() {
60 public void propertyChange(PropertyChangeEvent evt) {
61 delegate = new JComboBox().getRenderer();
67 public Component getListCellRendererComponent(JList list,
68 Object value, int index, boolean isSelected, boolean cellHasFocus) {
70 return delegate.getListCellRendererComponent(list,
71 ((UIManager.LookAndFeelInfo) value).getName(),
72 index, isSelected, cellHasFocus);
76 public class AltosConfigureUI
78 implements DocumentListener
84 JRadioButton enable_voice;
88 JButton configure_log;
89 JTextField log_directory;
91 JLabel callsign_label;
92 JTextField callsign_value;
94 JLabel font_size_label;
95 JComboBox font_size_value;
97 JLabel look_and_feel_label;
98 JComboBox look_and_feel_value;
100 JRadioButton serial_debug;
102 JButton manage_bluetooth;
103 JButton manage_frequencies;
105 final static String[] font_size_names = { "Small", "Medium", "Large" };
107 /* DocumentListener interface methods */
108 public void changedUpdate(DocumentEvent e) {
109 AltosUIPreferences.set_callsign(callsign_value.getText());
112 public void insertUpdate(DocumentEvent e) {
116 public void removeUpdate(DocumentEvent e) {
120 public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
121 super(in_owner, "Configure AltosUI", false);
123 GridBagConstraints c;
125 Insets insets = new Insets(4, 4, 4, 4);
131 pane = getContentPane();
132 pane.setLayout(new GridBagLayout());
134 c = new GridBagConstraints();
136 c.fill = GridBagConstraints.NONE;
137 c.anchor = GridBagConstraints.WEST;
139 /* Nice label at the top */
143 c.fill = GridBagConstraints.NONE;
144 c.anchor = GridBagConstraints.CENTER;
145 pane.add(new JLabel ("Configure AltOS UI"), c);
150 c.fill = GridBagConstraints.NONE;
151 c.anchor = GridBagConstraints.CENTER;
152 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
158 c.fill = GridBagConstraints.NONE;
159 c.anchor = GridBagConstraints.WEST;
160 pane.add(new JLabel("Voice"), c);
162 enable_voice = new JRadioButton("Enable", AltosUIPreferences.voice());
163 enable_voice.addActionListener(new ActionListener() {
164 public void actionPerformed(ActionEvent e) {
165 JRadioButton item = (JRadioButton) e.getSource();
166 boolean enabled = item.isSelected();
167 AltosUIPreferences.set_voice(enabled);
169 voice.speak_always("Enable voice.");
171 voice.speak_always("Disable voice.");
178 c.fill = GridBagConstraints.NONE;
179 c.anchor = GridBagConstraints.WEST;
180 pane.add(enable_voice, c);
181 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
187 c.fill = GridBagConstraints.NONE;
188 c.anchor = GridBagConstraints.EAST;
189 test_voice = new JButton("Test Voice");
190 test_voice.addActionListener(new ActionListener() {
191 public void actionPerformed(ActionEvent e) {
192 voice.speak("That's one small step for man; one giant leap for mankind.");
195 pane.add(test_voice, c);
196 test_voice.setToolTipText("Play a stock audio clip to check volume");
198 /* Log directory settings */
202 c.fill = GridBagConstraints.NONE;
203 c.anchor = GridBagConstraints.WEST;
204 pane.add(new JLabel("Log Directory"), c);
206 configure_log = new JButton(AltosUIPreferences.logdir().getPath());
207 configure_log.addActionListener(new ActionListener() {
208 public void actionPerformed(ActionEvent e) {
209 AltosUIPreferences.ConfigureLog();
210 configure_log.setText(AltosUIPreferences.logdir().getPath());
216 c.fill = GridBagConstraints.BOTH;
217 c.anchor = GridBagConstraints.WEST;
218 pane.add(configure_log, c);
219 configure_log.setToolTipText("Which directory flight logs are stored in");
221 /* Callsign setting */
225 c.fill = GridBagConstraints.NONE;
226 c.anchor = GridBagConstraints.WEST;
227 pane.add(new JLabel("Callsign"), c);
229 callsign_value = new JTextField(AltosUIPreferences.callsign());
230 callsign_value.getDocument().addDocumentListener(this);
234 c.fill = GridBagConstraints.BOTH;
235 c.anchor = GridBagConstraints.WEST;
236 pane.add(callsign_value, c);
237 callsign_value.setToolTipText("Callsign sent in packet mode");
239 /* Font size setting */
243 c.fill = GridBagConstraints.NONE;
244 c.anchor = GridBagConstraints.WEST;
245 pane.add(new JLabel("Font size"), c);
247 font_size_value = new JComboBox(font_size_names);
248 int font_size = AltosUIPreferences.font_size();
249 font_size_value.setSelectedIndex(font_size - Altos.font_size_small);
250 font_size_value.addActionListener(new ActionListener() {
251 public void actionPerformed(ActionEvent e) {
252 int size = font_size_value.getSelectedIndex() + Altos.font_size_small;
254 AltosUIPreferences.set_font_size(size);
260 c.fill = GridBagConstraints.BOTH;
261 c.anchor = GridBagConstraints.WEST;
262 pane.add(font_size_value, c);
263 font_size_value.setToolTipText("Font size used in telemetry window");
265 /* Look & Feel setting */
269 c.fill = GridBagConstraints.NONE;
270 c.anchor = GridBagConstraints.WEST;
271 pane.add(new JLabel("Look & feel"), c);
273 class LookAndFeelRenderer extends BasicComboBoxRenderer implements ListCellRenderer {
275 public LookAndFeelRenderer() {
279 public Component getListCellRendererComponent(
284 boolean cellHasFocus)
286 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
287 setText(((UIManager.LookAndFeelInfo) value).getName());
292 final UIManager.LookAndFeelInfo[] look_and_feels = UIManager.getInstalledLookAndFeels();
294 look_and_feel_value = new JComboBox(look_and_feels);
296 DelegatingRenderer.install(look_and_feel_value);
298 String look_and_feel = AltosUIPreferences.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 AltosUIPreferences.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", AltosUIPreferences.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 AltosUIPreferences.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, AltosBTKnown.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);