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 AltosPreferences.init(new AltosUIPreferencesBackend());
51 font_listeners = new LinkedList<AltosFontListener>();
53 font_size = backend.getInt(fontSizePreference, Altos.font_size_medium);
54 Altos.set_fonts(font_size);
55 look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
57 ui_listeners = new LinkedList<AltosUIListener>();
58 serial_debug = backend.getBoolean(serialDebugPreference, false);
59 AltosLink.set_debug(serial_debug);
64 static void set_component(Component in_component) {
65 component = in_component;
68 private static boolean check_dir(File dir) {
71 JOptionPane.showMessageDialog(component,
73 "Cannot create directory",
74 JOptionPane.ERROR_MESSAGE);
77 } else if (!dir.isDirectory()) {
78 JOptionPane.showMessageDialog(component,
81 JOptionPane.ERROR_MESSAGE);
87 /* Configure the log directory. This is where all telemetry and eeprom files
88 * will be written to, and where replay will look for telemetry files
90 public static void ConfigureLog() {
91 JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile());
93 logdir_chooser.setDialogTitle("Configure Data Logging Directory");
94 logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
96 if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
97 File dir = logdir_chooser.getSelectedFile();
102 public static int font_size() {
103 synchronized (backend) {
108 static void set_fonts() {
111 public static void set_font_size(int new_font_size) {
112 synchronized (backend) {
113 font_size = new_font_size;
114 backend.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 (backend) {
124 font_listeners.add(l);
128 public static void unregister_font_listener(AltosFontListener l) {
129 synchronized (backend) {
130 font_listeners.remove(l);
134 public static void set_look_and_feel(String new_look_and_feel) {
136 UIManager.setLookAndFeel(new_look_and_feel);
137 } catch (Exception e) {
139 synchronized(backend) {
140 look_and_feel = new_look_and_feel;
141 backend.putString(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 synchronized (backend) {
150 return look_and_feel;
154 public static void register_ui_listener(AltosUIListener l) {
155 synchronized(backend) {
160 public static void unregister_ui_listener(AltosUIListener l) {
161 synchronized (backend) {
162 ui_listeners.remove(l);
165 public static void set_serial_debug(boolean new_serial_debug) {
166 AltosLink.set_debug(serial_debug);
167 synchronized (backend) {
168 serial_debug = new_serial_debug;
169 backend.putBoolean(serialDebugPreference, serial_debug);
174 public static boolean serial_debug() {
175 synchronized (backend) {