2 * Copyright © 2011 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.
22 import java.awt.Component;
24 import org.altusmetrum.AltosLib.*;
26 public class AltosUIPreferences extends AltosPreferences {
28 /* font size preferences name */
29 final static String fontSizePreference = "FONT-SIZE";
31 /* Look&Feel preference name */
32 final static String lookAndFeelPreference = "LOOK-AND-FEEL";
34 /* UI Component to pop dialogs up */
35 static Component component;
37 static LinkedList<AltosFontListener> font_listeners;
39 static int font_size = Altos.font_size_medium;
41 static LinkedList<AltosUIListener> ui_listeners;
43 static String look_and_feel = null;
46 static boolean serial_debug;
48 public static void init() {
49 font_listeners = new LinkedList<AltosFontListener>();
51 font_size = preferences.getInt(fontSizePreference, Altos.font_size_medium);
52 Altos.set_fonts(font_size);
53 look_and_feel = preferences.get(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
55 ui_listeners = new LinkedList<AltosUIListener>();
56 serial_debug = preferences.getBoolean(serialDebugPreference, false);
57 AltosLink.set_debug(serial_debug);
62 static void set_component(Component in_component) {
63 component = in_component;
66 private static boolean check_dir(File dir) {
69 JOptionPane.showMessageDialog(component,
71 "Cannot create directory",
72 JOptionPane.ERROR_MESSAGE);
75 } else if (!dir.isDirectory()) {
76 JOptionPane.showMessageDialog(component,
79 JOptionPane.ERROR_MESSAGE);
85 /* Configure the log directory. This is where all telemetry and eeprom files
86 * will be written to, and where replay will look for telemetry files
88 public static void ConfigureLog() {
89 JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile());
91 logdir_chooser.setDialogTitle("Configure Data Logging Directory");
92 logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
94 if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
95 File dir = logdir_chooser.getSelectedFile();
100 public static int font_size() {
101 synchronized (preferences) {
106 static void set_fonts() {
109 public static void set_font_size(int new_font_size) {
110 synchronized (preferences) {
111 font_size = new_font_size;
112 preferences.putInt(fontSizePreference, font_size);
114 Altos.set_fonts(font_size);
115 for (AltosFontListener l : font_listeners)
116 l.font_size_changed(font_size);
120 public static void register_font_listener(AltosFontListener l) {
121 synchronized (preferences) {
122 font_listeners.add(l);
126 public static void unregister_font_listener(AltosFontListener l) {
127 synchronized (preferences) {
128 font_listeners.remove(l);
132 public static void set_look_and_feel(String new_look_and_feel) {
134 UIManager.setLookAndFeel(new_look_and_feel);
135 } catch (Exception e) {
137 synchronized(preferences) {
138 look_and_feel = new_look_and_feel;
139 preferences.put(lookAndFeelPreference, look_and_feel);
141 for (AltosUIListener l : ui_listeners)
142 l.ui_changed(look_and_feel);
146 public static String look_and_feel() {
147 synchronized (preferences) {
148 return look_and_feel;
152 public static void register_ui_listener(AltosUIListener l) {
153 synchronized(preferences) {
158 public static void unregister_ui_listener(AltosUIListener l) {
159 synchronized (preferences) {
160 ui_listeners.remove(l);
163 public static void set_serial_debug(boolean new_serial_debug) {
164 AltosLink.set_debug(new_serial_debug);
165 synchronized (preferences) {
166 serial_debug = new_serial_debug;
167 preferences.putBoolean(serialDebugPreference, serial_debug);
172 public static boolean serial_debug() {
173 synchronized (preferences) {