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.
23 import java.util.prefs.*;
24 import java.util.concurrent.LinkedBlockingQueue;
25 import java.awt.Component;
27 import javax.swing.filechooser.FileSystemView;
28 import org.altusmetrum.AltosLib.*;
30 public class AltosUIPreferences extends AltosPreferences {
32 /* font size preferences name */
33 final static String fontSizePreference = "FONT-SIZE";
35 /* Look&Feel preference name */
36 final static String lookAndFeelPreference = "LOOK-AND-FEEL";
38 /* UI Component to pop dialogs up */
39 static Component component;
41 static LinkedList<AltosFontListener> font_listeners;
43 static int font_size = Altos.font_size_medium;
45 static LinkedList<AltosUIListener> ui_listeners;
47 static String look_and_feel = null;
50 static boolean serial_debug;
52 public static void init() {
53 font_listeners = new LinkedList<AltosFontListener>();
55 font_size = preferences.getInt(fontSizePreference, Altos.font_size_medium);
56 Altos.set_fonts(font_size);
57 look_and_feel = preferences.get(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
59 ui_listeners = new LinkedList<AltosUIListener>();
60 serial_debug = preferences.getBoolean(serialDebugPreference, false);
61 AltosLink.set_debug(serial_debug);
66 static void set_component(Component in_component) {
67 component = in_component;
70 private static boolean check_dir(File dir) {
73 JOptionPane.showMessageDialog(component,
75 "Cannot create directory",
76 JOptionPane.ERROR_MESSAGE);
79 } else if (!dir.isDirectory()) {
80 JOptionPane.showMessageDialog(component,
83 JOptionPane.ERROR_MESSAGE);
89 /* Configure the log directory. This is where all telemetry and eeprom files
90 * will be written to, and where replay will look for telemetry files
92 public static void ConfigureLog() {
93 JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile());
95 logdir_chooser.setDialogTitle("Configure Data Logging Directory");
96 logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
98 if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
99 File dir = logdir_chooser.getSelectedFile();
104 public static int font_size() {
108 static void set_fonts() {
111 public static void set_font_size(int new_font_size) {
112 font_size = new_font_size;
113 synchronized (preferences) {
114 preferences.putInt(fontSizePreference, font_size);
116 Altos.set_fonts(font_size);
117 for (AltosFontListener l : font_listeners)
118 l.font_size_changed(font_size);
122 public static void register_font_listener(AltosFontListener l) {
123 synchronized (preferences) {
124 font_listeners.add(l);
128 public static void unregister_font_listener(AltosFontListener l) {
129 synchronized (preferences) {
130 font_listeners.remove(l);
134 public static void set_look_and_feel(String new_look_and_feel) {
135 look_and_feel = new_look_and_feel;
137 UIManager.setLookAndFeel(look_and_feel);
138 } catch (Exception e) {
140 synchronized(preferences) {
141 preferences.put(lookAndFeelPreference, look_and_feel);
143 for (AltosUIListener l : ui_listeners)
144 l.ui_changed(look_and_feel);
148 public static String look_and_feel() {
149 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 serial_debug = new_serial_debug;
165 AltosLink.set_debug(serial_debug);
166 synchronized (preferences) {
167 preferences.putBoolean(serialDebugPreference, serial_debug);
172 public static boolean serial_debug() {