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 JRadioButton imperial_units;
96 JLabel font_size_label;
97 JComboBox font_size_value;
99 JLabel look_and_feel_label;
100 JComboBox look_and_feel_value;
102 JRadioButton serial_debug;
104 JButton manage_bluetooth;
105 JButton manage_frequencies;
107 final static String[] font_size_names = { "Small", "Medium", "Large" };
109 /* DocumentListener interface methods */
110 public void changedUpdate(DocumentEvent e) {
111 AltosUIPreferences.set_callsign(callsign_value.getText());
114 public void insertUpdate(DocumentEvent e) {
118 public void removeUpdate(DocumentEvent e) {
122 public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
123 super(in_owner, "Configure AltosUI", false);
125 GridBagConstraints c;
127 Insets insets = new Insets(4, 4, 4, 4);
133 pane = getContentPane();
134 pane.setLayout(new GridBagLayout());
136 c = new GridBagConstraints();
138 c.fill = GridBagConstraints.NONE;
139 c.anchor = GridBagConstraints.WEST;
141 /* Nice label at the top */
145 c.fill = GridBagConstraints.NONE;
146 c.anchor = GridBagConstraints.CENTER;
147 pane.add(new JLabel ("Configure AltOS UI"), c);
152 c.fill = GridBagConstraints.NONE;
153 c.anchor = GridBagConstraints.CENTER;
154 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
160 c.fill = GridBagConstraints.NONE;
161 c.anchor = GridBagConstraints.WEST;
162 pane.add(new JLabel("Voice"), c);
164 enable_voice = new JRadioButton("Enable", AltosUIPreferences.voice());
165 enable_voice.addActionListener(new ActionListener() {
166 public void actionPerformed(ActionEvent e) {
167 JRadioButton item = (JRadioButton) e.getSource();
168 boolean enabled = item.isSelected();
169 AltosUIPreferences.set_voice(enabled);
171 voice.speak_always("Enable voice.");
173 voice.speak_always("Disable voice.");
180 c.fill = GridBagConstraints.NONE;
181 c.anchor = GridBagConstraints.WEST;
182 pane.add(enable_voice, c);
183 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
189 c.fill = GridBagConstraints.NONE;
190 c.anchor = GridBagConstraints.EAST;
191 test_voice = new JButton("Test Voice");
192 test_voice.addActionListener(new ActionListener() {
193 public void actionPerformed(ActionEvent e) {
194 voice.speak("That's one small step for man; one giant leap for mankind.");
197 pane.add(test_voice, c);
198 test_voice.setToolTipText("Play a stock audio clip to check volume");
200 /* Log directory settings */
204 c.fill = GridBagConstraints.NONE;
205 c.anchor = GridBagConstraints.WEST;
206 pane.add(new JLabel("Log Directory"), c);
208 configure_log = new JButton(AltosUIPreferences.logdir().getPath());
209 configure_log.addActionListener(new ActionListener() {
210 public void actionPerformed(ActionEvent e) {
211 AltosUIPreferences.ConfigureLog();
212 configure_log.setText(AltosUIPreferences.logdir().getPath());
218 c.fill = GridBagConstraints.BOTH;
219 c.anchor = GridBagConstraints.WEST;
220 pane.add(configure_log, c);
221 configure_log.setToolTipText("Which directory flight logs are stored in");
223 /* Callsign setting */
227 c.fill = GridBagConstraints.NONE;
228 c.anchor = GridBagConstraints.WEST;
229 pane.add(new JLabel("Callsign"), c);
231 callsign_value = new JTextField(AltosUIPreferences.callsign());
232 callsign_value.getDocument().addDocumentListener(this);
236 c.fill = GridBagConstraints.BOTH;
237 c.anchor = GridBagConstraints.WEST;
238 pane.add(callsign_value, c);
239 callsign_value.setToolTipText("Callsign sent in packet mode");
241 /* Imperial units setting */
245 c.fill = GridBagConstraints.NONE;
246 c.anchor = GridBagConstraints.WEST;
247 pane.add(new JLabel("Imperial Units"), c);
249 imperial_units = new JRadioButton("Enable", AltosUIPreferences.imperial_units());
250 imperial_units.addActionListener(new ActionListener() {
251 public void actionPerformed(ActionEvent e) {
252 JRadioButton item = (JRadioButton) e.getSource();
253 boolean enabled = item.isSelected();
254 AltosUIPreferences.set_imperial_units(enabled);
257 imperial_units.setToolTipText("Use Imperial units instead of metric");
262 c.fill = GridBagConstraints.NONE;
263 c.anchor = GridBagConstraints.WEST;
264 pane.add(imperial_units, c);
266 /* Font size setting */
270 c.fill = GridBagConstraints.NONE;
271 c.anchor = GridBagConstraints.WEST;
272 pane.add(new JLabel("Font size"), c);
274 font_size_value = new JComboBox(font_size_names);
275 int font_size = AltosUIPreferences.font_size();
276 font_size_value.setSelectedIndex(font_size - Altos.font_size_small);
277 font_size_value.addActionListener(new ActionListener() {
278 public void actionPerformed(ActionEvent e) {
279 int size = font_size_value.getSelectedIndex() + Altos.font_size_small;
281 AltosUIPreferences.set_font_size(size);
287 c.fill = GridBagConstraints.BOTH;
288 c.anchor = GridBagConstraints.WEST;
289 pane.add(font_size_value, c);
290 font_size_value.setToolTipText("Font size used in telemetry window");
292 /* Look & Feel setting */
296 c.fill = GridBagConstraints.NONE;
297 c.anchor = GridBagConstraints.WEST;
298 pane.add(new JLabel("Look & feel"), c);
300 class LookAndFeelRenderer extends BasicComboBoxRenderer implements ListCellRenderer {
302 public LookAndFeelRenderer() {
306 public Component getListCellRendererComponent(
311 boolean cellHasFocus)
313 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
314 setText(((UIManager.LookAndFeelInfo) value).getName());
319 final UIManager.LookAndFeelInfo[] look_and_feels = UIManager.getInstalledLookAndFeels();
321 look_and_feel_value = new JComboBox(look_and_feels);
323 DelegatingRenderer.install(look_and_feel_value);
325 String look_and_feel = AltosUIPreferences.look_and_feel();
326 for (int i = 0; i < look_and_feels.length; i++)
327 if (look_and_feel.equals(look_and_feels[i].getClassName()))
328 look_and_feel_value.setSelectedIndex(i);
330 look_and_feel_value.addActionListener(new ActionListener() {
331 public void actionPerformed(ActionEvent e) {
332 int id = look_and_feel_value.getSelectedIndex();
334 AltosUIPreferences.set_look_and_feel(look_and_feels[id].getClassName());
340 c.fill = GridBagConstraints.BOTH;
341 c.anchor = GridBagConstraints.WEST;
342 pane.add(look_and_feel_value, c);
343 look_and_feel_value.setToolTipText("Look&feel used for new windows");
345 /* Serial debug setting */
349 c.fill = GridBagConstraints.NONE;
350 c.anchor = GridBagConstraints.WEST;
351 pane.add(new JLabel("Serial Debug"), c);
353 serial_debug = new JRadioButton("Enable", AltosUIPreferences.serial_debug());
354 serial_debug.addActionListener(new ActionListener() {
355 public void actionPerformed(ActionEvent e) {
356 JRadioButton item = (JRadioButton) e.getSource();
357 boolean enabled = item.isSelected();
358 AltosUIPreferences.set_serial_debug(enabled);
361 serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
366 c.fill = GridBagConstraints.NONE;
367 c.anchor = GridBagConstraints.WEST;
368 pane.add(serial_debug, c);
370 manage_bluetooth = new JButton("Manage Bluetooth");
371 manage_bluetooth.addActionListener(new ActionListener() {
372 public void actionPerformed(ActionEvent e) {
373 AltosBTManage.show(owner, AltosBTKnown.bt_known());
379 c.fill = GridBagConstraints.NONE;
380 c.anchor = GridBagConstraints.WEST;
381 pane.add(manage_bluetooth, c);
383 manage_frequencies = new JButton("Manage Frequencies");
384 manage_frequencies.addActionListener(new ActionListener() {
385 public void actionPerformed(ActionEvent e) {
386 AltosConfigFreqUI.show(owner);
389 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
394 c.fill = GridBagConstraints.NONE;
395 c.anchor = GridBagConstraints.WEST;
396 pane.add(manage_frequencies, c);
398 /* And a close button at the bottom */
399 close = new JButton("Close");
400 close.addActionListener(new ActionListener() {
401 public void actionPerformed(ActionEvent e) {
408 c.fill = GridBagConstraints.NONE;
409 c.anchor = GridBagConstraints.CENTER;
413 setLocationRelativeTo(owner);