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
71 public Container pane;
75 final static String[] font_size_names = { "Small", "Medium", "Large" };
77 public GridBagConstraints constraints (int x, int width, int fill) {
78 GridBagConstraints c = new GridBagConstraints();
79 Insets insets = new Insets(4, 4, 4, 4);
84 c.anchor = GridBagConstraints.CENTER;
86 c.anchor = GridBagConstraints.EAST;
88 c.anchor = GridBagConstraints.WEST;
95 public GridBagConstraints constraints(int x, int width) {
96 return constraints(x, width, GridBagConstraints.NONE);
99 public void add_voice() {
102 public void add_log_dir() {
103 /* Log directory settings */
104 pane.add(new JLabel("Log Directory"), constraints(0, 1));
106 final JButton configure_log = new JButton(AltosUIPreferences.logdir().getPath());
107 configure_log.addActionListener(new ActionListener() {
108 public void actionPerformed(ActionEvent e) {
109 AltosUIPreferences.ConfigureLog();
110 configure_log.setText(AltosUIPreferences.logdir().getPath());
113 pane.add(configure_log, constraints(1, 2));
114 configure_log.setToolTipText("Which directory flight logs are stored in");
118 public void add_callsign() {
121 public void add_units() {
122 /* Imperial units setting */
123 pane.add(new JLabel("Imperial Units"), constraints(0, 1));
125 JRadioButton imperial_units = new JRadioButton("Enable", AltosUIPreferences.imperial_units());
126 imperial_units.addActionListener(new ActionListener() {
127 public void actionPerformed(ActionEvent e) {
128 JRadioButton item = (JRadioButton) e.getSource();
129 boolean enabled = item.isSelected();
130 AltosUIPreferences.set_imperial_units(enabled);
133 imperial_units.setToolTipText("Use Imperial units instead of metric");
134 pane.add(imperial_units, constraints(1, 2));
138 public void add_font_size() {
139 /* Font size setting */
140 pane.add(new JLabel("Font size"), constraints(0, 1));
142 final JComboBox font_size_value = new JComboBox(font_size_names);
143 int font_size = AltosUIPreferences.font_size();
144 font_size_value.setSelectedIndex(font_size - AltosUILib.font_size_small);
145 font_size_value.addActionListener(new ActionListener() {
146 public void actionPerformed(ActionEvent e) {
147 int size = font_size_value.getSelectedIndex() + AltosUILib.font_size_small;
149 AltosUIPreferences.set_font_size(size);
152 pane.add(font_size_value, constraints(1, 2, GridBagConstraints.BOTH));
153 font_size_value.setToolTipText("Font size used in telemetry window");
157 public void add_look_and_feel() {
158 /* Look & Feel setting */
159 pane.add(new JLabel("Look & feel"), constraints(0, 1));
162 class LookAndFeelRenderer extends BasicComboBoxRenderer implements ListCellRenderer {
164 public LookAndFeelRenderer() {
168 public Component getListCellRendererComponent(
173 boolean cellHasFocus)
175 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
176 setText(((UIManager.LookAndFeelInfo) value).getName());
182 final UIManager.LookAndFeelInfo[] look_and_feels = UIManager.getInstalledLookAndFeels();
184 final JComboBox look_and_feel_value = new JComboBox(look_and_feels);
186 DelegatingRenderer.install(look_and_feel_value);
188 String look_and_feel = AltosUIPreferences.look_and_feel();
189 for (int i = 0; i < look_and_feels.length; i++)
190 if (look_and_feel.equals(look_and_feels[i].getClassName()))
191 look_and_feel_value.setSelectedIndex(i);
193 look_and_feel_value.addActionListener(new ActionListener() {
194 public void actionPerformed(ActionEvent e) {
195 int id = look_and_feel_value.getSelectedIndex();
197 AltosUIPreferences.set_look_and_feel(look_and_feels[id].getClassName());
200 pane.add(look_and_feel_value, constraints(1, 2, GridBagConstraints.BOTH));
201 look_and_feel_value.setToolTipText("Look&feel used for new windows");
205 public void add_serial_debug() {
206 GridBagConstraints c = new GridBagConstraints();
208 /* Serial debug setting */
209 pane.add(new JLabel("Serial Debug"), constraints(0, 1));
211 JRadioButton serial_debug = new JRadioButton("Enable", AltosUIPreferences.serial_debug());
212 serial_debug.addActionListener(new ActionListener() {
213 public void actionPerformed(ActionEvent e) {
214 JRadioButton item = (JRadioButton) e.getSource();
215 boolean enabled = item.isSelected();
216 AltosUIPreferences.set_serial_debug(enabled);
219 serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
223 c.fill = GridBagConstraints.NONE;
224 c.anchor = GridBagConstraints.WEST;
225 pane.add(serial_debug, c);
228 public void add_bluetooth() {
231 public void add_frequencies() {
234 public AltosUIConfigure(JFrame in_owner) {
235 super(in_owner, "Configure AltosUI", false);
238 pane = getContentPane();
239 pane.setLayout(new GridBagLayout());
243 /* Nice label at the top */
244 pane.add(new JLabel ("Configure AltOS UI"),
248 pane.add(new JLabel (String.format("AltOS version %s", AltosUIVersion.version)),
261 /* And a close button at the bottom */
262 JButton close = new JButton("Close");
263 close.addActionListener(new ActionListener() {
264 public void actionPerformed(ActionEvent e) {
268 pane.add(close, constraints(0, 3));
271 setLocationRelativeTo(owner);