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.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 AltosConfigureUI
69 implements DocumentListener
75 JRadioButton enable_voice;
79 JButton configure_log;
80 JTextField log_directory;
82 JLabel callsign_label;
83 JTextField callsign_value;
85 JRadioButton imperial_units;
87 JLabel font_size_label;
88 JComboBox font_size_value;
90 JLabel look_and_feel_label;
91 JComboBox look_and_feel_value;
93 JRadioButton serial_debug;
95 JButton manage_bluetooth;
96 JButton manage_frequencies;
98 final static String[] font_size_names = { "Small", "Medium", "Large" };
100 /* DocumentListener interface methods */
101 public void changedUpdate(DocumentEvent e) {
102 AltosUIPreferences.set_callsign(callsign_value.getText());
105 public void insertUpdate(DocumentEvent e) {
109 public void removeUpdate(DocumentEvent e) {
113 public AltosConfigureUI(JFrame in_owner, AltosVoice in_voice) {
114 super(in_owner, "Configure AltosUI", false);
116 GridBagConstraints c;
118 Insets insets = new Insets(4, 4, 4, 4);
124 pane = getContentPane();
125 pane.setLayout(new GridBagLayout());
127 c = new GridBagConstraints();
129 c.fill = GridBagConstraints.NONE;
130 c.anchor = GridBagConstraints.WEST;
132 /* Nice label at the top */
136 c.fill = GridBagConstraints.NONE;
137 c.anchor = GridBagConstraints.CENTER;
138 pane.add(new JLabel ("Configure AltOS UI"), c);
143 c.fill = GridBagConstraints.NONE;
144 c.anchor = GridBagConstraints.CENTER;
145 pane.add(new JLabel (String.format("AltOS version %s", AltosVersion.version)), c);
151 c.fill = GridBagConstraints.NONE;
152 c.anchor = GridBagConstraints.WEST;
153 pane.add(new JLabel("Voice"), c);
155 enable_voice = new JRadioButton("Enable", AltosUIPreferences.voice());
156 enable_voice.addActionListener(new ActionListener() {
157 public void actionPerformed(ActionEvent e) {
158 JRadioButton item = (JRadioButton) e.getSource();
159 boolean enabled = item.isSelected();
160 AltosUIPreferences.set_voice(enabled);
162 voice.speak_always("Enable voice.");
164 voice.speak_always("Disable voice.");
171 c.fill = GridBagConstraints.NONE;
172 c.anchor = GridBagConstraints.WEST;
173 pane.add(enable_voice, c);
174 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
180 c.fill = GridBagConstraints.NONE;
181 c.anchor = GridBagConstraints.EAST;
182 test_voice = new JButton("Test Voice");
183 test_voice.addActionListener(new ActionListener() {
184 public void actionPerformed(ActionEvent e) {
185 voice.speak("That's one small step for man; one giant leap for mankind.");
188 pane.add(test_voice, c);
189 test_voice.setToolTipText("Play a stock audio clip to check volume");
191 /* Log directory settings */
195 c.fill = GridBagConstraints.NONE;
196 c.anchor = GridBagConstraints.WEST;
197 pane.add(new JLabel("Log Directory"), c);
199 configure_log = new JButton(AltosUIPreferences.logdir().getPath());
200 configure_log.addActionListener(new ActionListener() {
201 public void actionPerformed(ActionEvent e) {
202 AltosUIPreferences.ConfigureLog();
203 configure_log.setText(AltosUIPreferences.logdir().getPath());
209 c.fill = GridBagConstraints.BOTH;
210 c.anchor = GridBagConstraints.WEST;
211 pane.add(configure_log, c);
212 configure_log.setToolTipText("Which directory flight logs are stored in");
214 /* Callsign setting */
218 c.fill = GridBagConstraints.NONE;
219 c.anchor = GridBagConstraints.WEST;
220 pane.add(new JLabel("Callsign"), c);
222 callsign_value = new JTextField(AltosUIPreferences.callsign());
223 callsign_value.getDocument().addDocumentListener(this);
227 c.fill = GridBagConstraints.BOTH;
228 c.anchor = GridBagConstraints.WEST;
229 pane.add(callsign_value, c);
230 callsign_value.setToolTipText("Callsign sent in packet mode");
232 /* Imperial units setting */
236 c.fill = GridBagConstraints.NONE;
237 c.anchor = GridBagConstraints.WEST;
238 pane.add(new JLabel("Imperial Units"), c);
240 imperial_units = new JRadioButton("Enable", AltosUIPreferences.imperial_units());
241 imperial_units.addActionListener(new ActionListener() {
242 public void actionPerformed(ActionEvent e) {
243 JRadioButton item = (JRadioButton) e.getSource();
244 boolean enabled = item.isSelected();
245 AltosUIPreferences.set_imperial_units(enabled);
248 imperial_units.setToolTipText("Use Imperial units instead of metric");
253 c.fill = GridBagConstraints.NONE;
254 c.anchor = GridBagConstraints.WEST;
255 pane.add(imperial_units, c);
257 /* Font size setting */
261 c.fill = GridBagConstraints.NONE;
262 c.anchor = GridBagConstraints.WEST;
263 pane.add(new JLabel("Font size"), c);
265 font_size_value = new JComboBox(font_size_names);
266 int font_size = AltosUIPreferences.font_size();
267 font_size_value.setSelectedIndex(font_size - Altos.font_size_small);
268 font_size_value.addActionListener(new ActionListener() {
269 public void actionPerformed(ActionEvent e) {
270 int size = font_size_value.getSelectedIndex() + Altos.font_size_small;
272 AltosUIPreferences.set_font_size(size);
278 c.fill = GridBagConstraints.BOTH;
279 c.anchor = GridBagConstraints.WEST;
280 pane.add(font_size_value, c);
281 font_size_value.setToolTipText("Font size used in telemetry window");
283 /* Look & Feel setting */
287 c.fill = GridBagConstraints.NONE;
288 c.anchor = GridBagConstraints.WEST;
289 pane.add(new JLabel("Look & feel"), c);
292 class LookAndFeelRenderer extends BasicComboBoxRenderer implements ListCellRenderer {
294 public LookAndFeelRenderer() {
298 public Component getListCellRendererComponent(
303 boolean cellHasFocus)
305 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
306 setText(((UIManager.LookAndFeelInfo) value).getName());
312 final UIManager.LookAndFeelInfo[] look_and_feels = UIManager.getInstalledLookAndFeels();
314 look_and_feel_value = new JComboBox(look_and_feels);
316 DelegatingRenderer.install(look_and_feel_value);
318 String look_and_feel = AltosUIPreferences.look_and_feel();
319 for (int i = 0; i < look_and_feels.length; i++)
320 if (look_and_feel.equals(look_and_feels[i].getClassName()))
321 look_and_feel_value.setSelectedIndex(i);
323 look_and_feel_value.addActionListener(new ActionListener() {
324 public void actionPerformed(ActionEvent e) {
325 int id = look_and_feel_value.getSelectedIndex();
327 AltosUIPreferences.set_look_and_feel(look_and_feels[id].getClassName());
333 c.fill = GridBagConstraints.BOTH;
334 c.anchor = GridBagConstraints.WEST;
335 pane.add(look_and_feel_value, c);
336 look_and_feel_value.setToolTipText("Look&feel used for new windows");
338 /* Serial debug setting */
342 c.fill = GridBagConstraints.NONE;
343 c.anchor = GridBagConstraints.WEST;
344 pane.add(new JLabel("Serial Debug"), c);
346 serial_debug = new JRadioButton("Enable", AltosUIPreferences.serial_debug());
347 serial_debug.addActionListener(new ActionListener() {
348 public void actionPerformed(ActionEvent e) {
349 JRadioButton item = (JRadioButton) e.getSource();
350 boolean enabled = item.isSelected();
351 AltosUIPreferences.set_serial_debug(enabled);
354 serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
359 c.fill = GridBagConstraints.NONE;
360 c.anchor = GridBagConstraints.WEST;
361 pane.add(serial_debug, c);
363 manage_bluetooth = new JButton("Manage Bluetooth");
364 manage_bluetooth.addActionListener(new ActionListener() {
365 public void actionPerformed(ActionEvent e) {
366 AltosBTManage.show(owner, AltosBTKnown.bt_known());
372 c.fill = GridBagConstraints.NONE;
373 c.anchor = GridBagConstraints.WEST;
374 pane.add(manage_bluetooth, c);
376 manage_frequencies = new JButton("Manage Frequencies");
377 manage_frequencies.addActionListener(new ActionListener() {
378 public void actionPerformed(ActionEvent e) {
379 AltosConfigFreqUI.show(owner);
382 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
387 c.fill = GridBagConstraints.NONE;
388 c.anchor = GridBagConstraints.WEST;
389 pane.add(manage_frequencies, c);
391 /* And a close button at the bottom */
392 close = new JButton("Close");
393 close.addActionListener(new ActionListener() {
394 public void actionPerformed(ActionEvent e) {
401 c.fill = GridBagConstraints.NONE;
402 c.anchor = GridBagConstraints.CENTER;
406 setLocationRelativeTo(owner);