Saves the preferred style and uses that for all current and new windows.
Signed-off-by: Keith Packard <keithp@keithp.com>
import libaltosJNI.*;
-public class AltosBTManage extends JDialog implements ActionListener, Iterable<AltosBTDevice> {
+public class AltosBTManage extends AltosDialog implements ActionListener, Iterable<AltosBTDevice> {
LinkedBlockingQueue<AltosBTDevice> found_devices;
Frame frame;
LinkedList<ActionListener> listeners;
import java.util.concurrent.LinkedBlockingQueue;
public class AltosCSVUI
- extends JDialog
+ extends AltosDialog
implements ActionListener
{
JFileChooser csv_chooser;
import java.util.prefs.*;
import java.util.concurrent.*;
-class AltosEditFreqUI extends JDialog implements ActionListener {
+class AltosEditFreqUI extends AltosDialog implements ActionListener {
Frame frame;
JTextField frequency;
JTextField description;
}
}
-public class AltosConfigFreqUI extends JDialog implements ActionListener {
+public class AltosConfigFreqUI extends AltosDialog implements ActionListener {
Frame frame;
LinkedList<ActionListener> listeners;
import libaltosJNI.*;
public class AltosConfigUI
- extends JDialog
+ extends AltosDialog
implements ActionListener, ItemListener, DocumentListener
{
import java.awt.*;
import java.awt.event.*;
+import java.beans.*;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.*;
import java.text.*;
import java.util.prefs.*;
import java.util.concurrent.LinkedBlockingQueue;
+import javax.swing.plaf.basic.*;
+
+class DelegatingRenderer implements ListCellRenderer {
+
+ // ...
+ public static void install(JComboBox comboBox) {
+ DelegatingRenderer renderer = new DelegatingRenderer(comboBox);
+ renderer.initialise();
+ comboBox.setRenderer(renderer);
+ }
+
+ // ...
+ private final JComboBox comboBox;
+
+ // ...
+ private ListCellRenderer delegate;
+
+ // ...
+ private DelegatingRenderer(JComboBox comboBox) {
+ this.comboBox = comboBox;
+ }
+
+ // ...
+ private void initialise() {
+ delegate = new JComboBox().getRenderer();
+ comboBox.addPropertyChangeListener("UI", new PropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ delegate = new JComboBox().getRenderer();
+ }
+ });
+ }
+
+ // ...
+ public Component getListCellRendererComponent(JList list,
+ Object value, int index, boolean isSelected, boolean cellHasFocus) {
+
+ return delegate.getListCellRendererComponent(list,
+ ((UIManager.LookAndFeelInfo) value).getName(),
+ index, isSelected, cellHasFocus);
+ }
+}
public class AltosConfigureUI
- extends JDialog
+ extends AltosDialog
implements DocumentListener
{
JFrame owner;
JLabel font_size_label;
JComboBox font_size_value;
+ JLabel look_and_feel_label;
+ JComboBox look_and_feel_value;
+
JRadioButton serial_debug;
JButton manage_bluetooth;
pane.add(font_size_value, c);
font_size_value.setToolTipText("Font size used in telemetry window");
+ /* Look & Feel setting */
+ c.gridx = 0;
+ c.gridy = row;
+ c.gridwidth = 1;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.WEST;
+ pane.add(new JLabel("Look & feel"), c);
+
+ class LookAndFeelRenderer extends BasicComboBoxRenderer implements ListCellRenderer {
+
+ public LookAndFeelRenderer() {
+ super();
+ }
+
+ public Component getListCellRendererComponent(
+ JList list,
+ Object value,
+ int index,
+ boolean isSelected,
+ boolean cellHasFocus)
+ {
+ super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+ setText(((UIManager.LookAndFeelInfo) value).getName());
+ return this;
+ }
+ }
+
+ final UIManager.LookAndFeelInfo[] look_and_feels = UIManager.getInstalledLookAndFeels();
+
+ System.out.printf("look_and_feels %d\n", look_and_feels.length);
+ look_and_feel_value = new JComboBox(look_and_feels);
+
+ DelegatingRenderer.install(look_and_feel_value);
+
+ String look_and_feel = AltosPreferences.look_and_feel();
+ for (int i = 0; i < look_and_feels.length; i++)
+ if (look_and_feel.equals(look_and_feels[i].getClassName()))
+ look_and_feel_value.setSelectedIndex(i);
+
+ look_and_feel_value.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ int id = look_and_feel_value.getSelectedIndex();
+
+ AltosPreferences.set_look_and_feel(look_and_feels[id].getClassName());
+ }
+ });
+ c.gridx = 1;
+ c.gridy = row++;
+ c.gridwidth = 2;
+ c.fill = GridBagConstraints.BOTH;
+ c.anchor = GridBagConstraints.WEST;
+ pane.add(look_and_feel_value, c);
+ look_and_feel_value.setToolTipText("Look&feel used for new windows");
+
/* Serial debug setting */
c.gridx = 0;
c.gridy = row;
import java.awt.event.*;
import libaltosJNI.*;
-public class AltosDeviceDialog extends JDialog implements ActionListener {
+public class AltosDeviceDialog extends AltosDialog implements ActionListener {
private AltosDevice value;
private JList list;
--- /dev/null
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package altosui;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import javax.swing.table.*;
+import java.io.*;
+import java.util.*;
+import java.text.*;
+import java.util.prefs.*;
+import java.util.concurrent.*;
+
+import libaltosJNI.*;
+
+class AltosDialogListener extends WindowAdapter {
+ public void windowClosing (WindowEvent e) {
+ AltosPreferences.unregister_ui_listener((AltosDialog) e.getWindow());
+ }
+}
+
+public class AltosDialog extends JDialog implements AltosUIListener {
+
+ public void ui_changed(String look_and_feel) {
+ SwingUtilities.updateComponentTreeUI(this);
+ this.pack();
+ }
+
+ public AltosDialog() {
+ AltosPreferences.register_ui_listener(this);
+ addWindowListener(new AltosDialogListener());
+ }
+
+ public AltosDialog(Frame frame, String label, boolean modal) {
+ super(frame, label, modal);
+ AltosPreferences.register_ui_listener(this);
+ addWindowListener(new AltosDialogListener());
+ }
+
+ public AltosDialog(Frame frame, boolean modal) {
+ super(frame, modal);
+ AltosPreferences.register_ui_listener(this);
+ addWindowListener(new AltosDialogListener());
+ }
+}
import java.util.prefs.*;
import java.util.concurrent.LinkedBlockingQueue;
-public class AltosEepromMonitor extends JDialog {
+public class AltosEepromMonitor extends AltosDialog {
Container pane;
Box box;
}
}
-public class AltosEepromSelect extends JDialog implements ActionListener {
+public class AltosEepromSelect extends AltosDialog implements ActionListener {
private JList list;
private JFrame frame;
JButton ok;
import java.util.concurrent.*;
public class AltosFlashUI
- extends JDialog
+ extends AltosDialog
implements ActionListener
{
Container pane;
import java.util.prefs.*;
import java.util.concurrent.*;
-public class AltosFlightUI extends JFrame implements AltosFlightDisplay, AltosFontListener {
+public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener {
AltosVoice voice;
AltosFlightReader reader;
AltosDisplayThread thread;
--- /dev/null
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package altosui;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import javax.swing.table.*;
+import java.io.*;
+import java.util.*;
+import java.text.*;
+import java.util.prefs.*;
+import java.util.concurrent.*;
+
+import libaltosJNI.*;
+
+class AltosFrameListener extends WindowAdapter {
+ public void windowClosing (WindowEvent e) {
+ AltosPreferences.unregister_ui_listener((AltosFrame) e.getWindow());
+ }
+}
+
+public class AltosFrame extends JFrame implements AltosUIListener {
+
+ public void ui_changed(String look_and_feel) {
+ SwingUtilities.updateComponentTreeUI(this);
+ this.pack();
+ }
+
+ public AltosFrame() {
+ AltosPreferences.register_ui_listener(this);
+ addWindowListener(new AltosFrameListener());
+ }
+
+ public AltosFrame(String name) {
+ super(name);
+ AltosPreferences.register_ui_listener(this);
+ addWindowListener(new AltosFrameListener());
+ }
+}
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
-public class AltosGraphUI extends JFrame
+public class AltosGraphUI extends AltosFrame
{
JTabbedPane pane;
}
}
-public class AltosIdleMonitorUI extends JFrame implements AltosFlightDisplay {
+public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener {
AltosDevice device;
JTabbedPane pane;
AltosPad pad;
flightInfo.set_font();
}
+ public void font_size_changed(int font_size) {
+ set_font();
+ }
+
public void show(AltosState state, int crc_errors) {
try {
pad.show(state, crc_errors);
bag.add(pane, c);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+
+ AltosPreferences.register_font_listener(this);
+
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
disconnect();
setVisible(false);
dispose();
+ AltosPreferences.unregister_font_listener(AltosIdleMonitorUI.this);
}
});
import java.util.concurrent.*;
public class AltosIgniteUI
- extends JDialog
+ extends AltosDialog
implements ActionListener
{
AltosDevice device;
}
public class AltosLaunchUI
- extends JDialog
+ extends AltosDialog
implements ActionListener
{
AltosDevice device;
/* Launcher serial preference name */
final static String launcherSerialPreference = "LAUNCHER-SERIAL";
- /* Launcher channel prefernce name */
+ /* Launcher channel preference name */
final static String launcherChannelPreference = "LAUNCHER-CHANNEL";
+ /* Look&Feel preference name */
+ final static String lookAndFeelPreference = "LOOK-AND-FEEL";
+
/* Default logdir is ~/TeleMetrum */
final static String logdirName = "TeleMetrum";
static int font_size = Altos.font_size_medium;
+ static LinkedList<AltosUIListener> ui_listeners;
+
+ static String look_and_feel = null;
+
/* List of frequencies */
final static String common_frequencies_node_name = "COMMON-FREQUENCIES";
static AltosFrequency[] common_frequencies;
AltosSerial.set_debug(serial_debug);
common_frequencies = load_common_frequencies();
+
+ look_and_feel = preferences.get(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
+
+ ui_listeners = new LinkedList<AltosUIListener>();
}
static { init(); }
}
}
+ public static void set_look_and_feel(String new_look_and_feel) {
+ look_and_feel = new_look_and_feel;
+ try {
+ UIManager.setLookAndFeel(look_and_feel);
+ } catch (Exception e) {
+ }
+ synchronized(preferences) {
+ preferences.put(lookAndFeelPreference, look_and_feel);
+ flush_preferences();
+ for (AltosUIListener l : ui_listeners)
+ l.ui_changed(look_and_feel);
+ }
+ }
+
+ public static String look_and_feel() {
+ return look_and_feel;
+ }
+
+ public static void register_ui_listener(AltosUIListener l) {
+ synchronized(preferences) {
+ ui_listeners.add(l);
+ }
+ }
+
+ public static void unregister_ui_listener(AltosUIListener l) {
+ synchronized (preferences) {
+ ui_listeners.remove(l);
+ }
+ }
public static void set_serial_debug(boolean new_serial_debug) {
serial_debug = new_serial_debug;
AltosSerial.set_debug(serial_debug);
import java.util.prefs.*;
public class AltosRomconfigUI
- extends JDialog
+ extends AltosDialog
implements ActionListener
{
Container pane;
}
public class AltosScanUI
- extends JDialog
+ extends AltosDialog
implements ActionListener
{
AltosUI owner;
}
}
-public class AltosSiteMapPreload extends JDialog implements ActionListener, ItemListener {
+public class AltosSiteMapPreload extends AltosDialog implements ActionListener, ItemListener {
AltosUI owner;
AltosSiteMap map;
import libaltosJNI.*;
-public class AltosUI extends JFrame {
+public class AltosUI extends AltosFrame {
public AltosVoice voice = new AltosVoice();
public static boolean load_library(Frame frame) {
public static void main(final String[] args) {
try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ UIManager.setLookAndFeel(AltosPreferences.look_and_feel());
} catch (Exception e) {
}
/* Handle batch-mode */
--- /dev/null
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package altosui;
+
+public interface AltosUIListener {
+ public void ui_changed(String look_and_feel);
+}
AltosTelemetry.java \
AltosTelemetryIterable.java \
AltosUI.java \
+ AltosUIListener.java \
+ AltosFrame.java \
+ AltosDialog.java \
AltosWriter.java \
AltosDataPointReader.java \
AltosDataPoint.java \