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.
18 package org.altusmetrum.altosuilib;
21 import java.awt.event.*;
24 import javax.swing.event.*;
26 class DelegatingRenderer implements ListCellRenderer {
29 public static void install(JComboBox comboBox) {
30 DelegatingRenderer renderer = new DelegatingRenderer(comboBox);
31 renderer.initialise();
32 comboBox.setRenderer(renderer);
36 private final JComboBox comboBox;
39 private ListCellRenderer delegate;
42 private DelegatingRenderer(JComboBox comboBox) {
43 this.comboBox = comboBox;
47 private void initialise() {
48 delegate = new JComboBox().getRenderer();
49 comboBox.addPropertyChangeListener("UI", new PropertyChangeListener() {
51 public void propertyChange(PropertyChangeEvent evt) {
52 delegate = new JComboBox().getRenderer();
58 public Component getListCellRendererComponent(JList list,
59 Object value, int index, boolean isSelected, boolean cellHasFocus) {
61 return delegate.getListCellRendererComponent(list,
62 ((UIManager.LookAndFeelInfo) value).getName(),
63 index, isSelected, cellHasFocus);
67 public class AltosUIConfigure
69 implements DocumentListener
74 JRadioButton enable_voice;
78 JButton configure_log;
79 JTextField log_directory;
81 JLabel callsign_label;
82 JTextField callsign_value;
84 JRadioButton imperial_units;
86 JLabel font_size_label;
87 JComboBox font_size_value;
89 JLabel look_and_feel_label;
90 JComboBox look_and_feel_value;
92 JRadioButton serial_debug;
94 JButton manage_bluetooth;
95 JButton manage_frequencies;
99 final static String[] font_size_names = { "Small", "Medium", "Large" };
101 /* DocumentListener interface methods */
102 public void changedUpdate(DocumentEvent e) {
103 if (callsign_value != null)
104 AltosUIPreferences.set_callsign(callsign_value.getText());
107 public void insertUpdate(DocumentEvent e) {
111 public void removeUpdate(DocumentEvent e) {
115 public GridBagConstraints constraints (int x, int width, int fill) {
116 GridBagConstraints c = new GridBagConstraints();
117 Insets insets = new Insets(4, 4, 4, 4);
122 c.anchor = GridBagConstraints.CENTER;
124 c.anchor = GridBagConstraints.WEST;
131 public GridBagConstraints constraints(int x, int width) {
132 return constraints(x, width, GridBagConstraints.NONE);
135 public void add_voice() {
136 // GridBagConstraints c = new GridBagConstraints();
138 // /* Voice settings */
142 // c.fill = GridBagConstraints.NONE;
143 // c.anchor = GridBagConstraints.WEST;
144 // pane.add(new JLabel("Voice"), c);
146 // enable_voice = new JRadioButton("Enable", AltosUIPreferences.voice());
147 // enable_voice.addActionListener(new ActionListener() {
148 // public void actionPerformed(ActionEvent e) {
149 // JRadioButton item = (JRadioButton) e.getSource();
150 // boolean enabled = item.isSelected();
151 // AltosUIPreferences.set_voice(enabled);
153 // voice.speak_always("Enable voice.");
155 // voice.speak_always("Disable voice.");
162 // c.fill = GridBagConstraints.NONE;
163 // c.anchor = GridBagConstraints.WEST;
164 // pane.add(enable_voice, c);
165 // enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
171 // c.fill = GridBagConstraints.NONE;
172 // c.anchor = GridBagConstraints.EAST;
173 // test_voice = new JButton("Test Voice");
174 // test_voice.addActionListener(new ActionListener() {
175 // public void actionPerformed(ActionEvent e) {
176 // voice.speak("That's one small step for man; one giant leap for mankind.");
179 // pane.add(test_voice, c);
180 // test_voice.setToolTipText("Play a stock audio clip to check volume");
184 public void add_log_dir() {
185 /* Log directory settings */
186 pane.add(new JLabel("Log Directory"), constraints(0, 1));
188 configure_log = new JButton(AltosUIPreferences.logdir().getPath());
189 configure_log.addActionListener(new ActionListener() {
190 public void actionPerformed(ActionEvent e) {
191 AltosUIPreferences.ConfigureLog();
192 configure_log.setText(AltosUIPreferences.logdir().getPath());
195 pane.add(configure_log, constraints(1, 2));
196 configure_log.setToolTipText("Which directory flight logs are stored in");
200 public void add_callsign() {
201 // /* Callsign setting */
202 // pane.add(new JLabel("Callsign"), constraints(0, 1));
204 // callsign_value = new JTextField(AltosUIPreferences.callsign());
205 // callsign_value.getDocument().addDocumentListener(this);
206 // callsign_value.setToolTipText("Callsign sent in packet mode");
207 // pane.add(callsign_value, constraints(1, 2, GridBagConstraints.BOTH));
211 public void add_units() {
212 /* Imperial units setting */
213 pane.add(new JLabel("Imperial Units"), constraints(0, 1));
215 imperial_units = new JRadioButton("Enable", AltosUIPreferences.imperial_units());
216 imperial_units.addActionListener(new ActionListener() {
217 public void actionPerformed(ActionEvent e) {
218 JRadioButton item = (JRadioButton) e.getSource();
219 boolean enabled = item.isSelected();
220 AltosUIPreferences.set_imperial_units(enabled);
223 imperial_units.setToolTipText("Use Imperial units instead of metric");
224 pane.add(imperial_units, constraints(1, 2));
228 public void add_font_size() {
229 /* Font size setting */
230 pane.add(new JLabel("Font size"), constraints(0, 1));
232 font_size_value = new JComboBox(font_size_names);
233 int font_size = AltosUIPreferences.font_size();
234 font_size_value.setSelectedIndex(font_size - AltosUILib.font_size_small);
235 font_size_value.addActionListener(new ActionListener() {
236 public void actionPerformed(ActionEvent e) {
237 int size = font_size_value.getSelectedIndex() + AltosUILib.font_size_small;
239 AltosUIPreferences.set_font_size(size);
242 pane.add(font_size_value, constraints(1, 2, GridBagConstraints.BOTH));
243 font_size_value.setToolTipText("Font size used in telemetry window");
247 public void add_look_and_feel() {
248 /* Look & Feel setting */
249 pane.add(new JLabel("Look & feel"), constraints(0, 1));
252 class LookAndFeelRenderer extends BasicComboBoxRenderer implements ListCellRenderer {
254 public LookAndFeelRenderer() {
258 public Component getListCellRendererComponent(
263 boolean cellHasFocus)
265 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
266 setText(((UIManager.LookAndFeelInfo) value).getName());
272 final UIManager.LookAndFeelInfo[] look_and_feels = UIManager.getInstalledLookAndFeels();
274 look_and_feel_value = new JComboBox(look_and_feels);
276 DelegatingRenderer.install(look_and_feel_value);
278 String look_and_feel = AltosUIPreferences.look_and_feel();
279 for (int i = 0; i < look_and_feels.length; i++)
280 if (look_and_feel.equals(look_and_feels[i].getClassName()))
281 look_and_feel_value.setSelectedIndex(i);
283 look_and_feel_value.addActionListener(new ActionListener() {
284 public void actionPerformed(ActionEvent e) {
285 int id = look_and_feel_value.getSelectedIndex();
287 AltosUIPreferences.set_look_and_feel(look_and_feels[id].getClassName());
290 pane.add(look_and_feel_value, constraints(1, 2, GridBagConstraints.BOTH));
291 look_and_feel_value.setToolTipText("Look&feel used for new windows");
295 public void add_serial_debug() {
296 GridBagConstraints c = new GridBagConstraints();
298 /* Serial debug setting */
299 pane.add(new JLabel("Serial Debug"), constraints(0, 1));
301 serial_debug = new JRadioButton("Enable", AltosUIPreferences.serial_debug());
302 serial_debug.addActionListener(new ActionListener() {
303 public void actionPerformed(ActionEvent e) {
304 JRadioButton item = (JRadioButton) e.getSource();
305 boolean enabled = item.isSelected();
306 AltosUIPreferences.set_serial_debug(enabled);
309 serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
312 public void add_bluetooth() {
313 // GridBagConstraints c = new GridBagConstraints();
317 // c.fill = GridBagConstraints.NONE;
318 // c.anchor = GridBagConstraints.WEST;
319 // pane.add(serial_debug, c);
321 // manage_bluetooth = new JButton("Manage Bluetooth");
322 // manage_bluetooth.addActionListener(new ActionListener() {
323 // public void actionPerformed(ActionEvent e) {
324 // AltosBTManage.show(owner, AltosBTKnown.bt_known());
330 // c.fill = GridBagConstraints.NONE;
331 // c.anchor = GridBagConstraints.WEST;
332 // pane.add(manage_bluetooth, c);
335 public void add_frequencies() {
336 // GridBagConstraints c = new GridBagConstraints();
337 // manage_frequencies = new JButton("Manage Frequencies");
338 // manage_frequencies.addActionListener(new ActionListener() {
339 // public void actionPerformed(ActionEvent e) {
340 // AltosConfigFreqUI.show(owner);
343 // manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
348 // c.fill = GridBagConstraints.NONE;
349 // c.anchor = GridBagConstraints.WEST;
350 // pane.add(manage_frequencies, c);
353 public AltosUIConfigure(JFrame in_owner) {
354 super(in_owner, "Configure AltosUI", false);
357 pane = getContentPane();
358 pane.setLayout(new GridBagLayout());
362 /* Nice label at the top */
363 pane.add(new JLabel ("Configure AltOS UI"),
367 pane.add(new JLabel (String.format("AltOS version %s", AltosUIVersion.version)),
380 /* And a close button at the bottom */
381 close = new JButton("Close");
382 close.addActionListener(new ActionListener() {
383 public void actionPerformed(ActionEvent e) {
387 pane.add(close, constraints(0, 3));
390 setLocationRelativeTo(owner);