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.
18 package org.altusmetrum.micropeak;
22 import java.awt.Component;
25 import org.altusmetrum.AltosLib.*;
27 public class MicroPreferences extends AltosPreferences {
29 static final int tab_elt_pad = 5;
31 static Font label_font;
32 static Font value_font;
33 static Font status_font;
34 static Font table_label_font;
35 static Font table_value_font;
37 final static int font_size_small = 1;
38 final static int font_size_medium = 2;
39 final static int font_size_large = 3;
41 static void set_fonts(int size) {
53 case font_size_medium:
64 label_font = new Font("Dialog", Font.PLAIN, brief_size);
65 value_font = new Font("Monospaced", Font.PLAIN, brief_size);
66 status_font = new Font("SansSerif", Font.BOLD, status_size);
67 table_label_font = new Font("SansSerif", Font.PLAIN, table_size);
68 table_value_font = new Font("Monospaced", Font.PLAIN, table_size);
71 /* font size preferences name */
72 final static String fontSizePreference = "FONT-SIZE";
74 /* Look&Feel preference name */
75 final static String lookAndFeelPreference = "LOOK-AND-FEEL";
77 /* UI Component to pop dialogs up */
78 static Component component;
80 static LinkedList<MicroFontListener> font_listeners;
82 static int font_size = font_size_medium;
84 static LinkedList<MicroUIListener> ui_listeners;
86 static String look_and_feel = null;
89 static boolean serial_debug;
91 public static void init() {
92 AltosPreferences.init(new MicroPreferencesBackend());
94 font_listeners = new LinkedList<MicroFontListener>();
96 font_size = backend.getInt(fontSizePreference, font_size_medium);
98 look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
100 ui_listeners = new LinkedList<MicroUIListener>();
101 serial_debug = backend.getBoolean(serialDebugPreference, false);
106 static void set_component(Component in_component) {
107 component = in_component;
110 private static boolean check_dir(File dir) {
113 JOptionPane.showMessageDialog(component,
115 "Cannot create directory",
116 JOptionPane.ERROR_MESSAGE);
119 } else if (!dir.isDirectory()) {
120 JOptionPane.showMessageDialog(component,
122 "Is not a directory",
123 JOptionPane.ERROR_MESSAGE);
129 /* Configure the log directory. This is where all telemetry and eeprom files
130 * will be written to, and where replay will look for telemetry files
132 public static void ConfigureLog() {
133 JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile());
135 logdir_chooser.setDialogTitle("Configure Data Logging Directory");
136 logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
138 if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
139 File dir = logdir_chooser.getSelectedFile();
144 public static int font_size() {
145 synchronized (backend) {
150 static void set_fonts() {
153 public static void set_font_size(int new_font_size) {
154 synchronized (backend) {
155 font_size = new_font_size;
156 backend.putInt(fontSizePreference, font_size);
158 set_fonts(font_size);
159 for (MicroFontListener l : font_listeners)
160 l.font_size_changed(font_size);
164 public static void register_font_listener(MicroFontListener l) {
165 synchronized (backend) {
166 font_listeners.add(l);
170 public static void unregister_font_listener(MicroFontListener l) {
171 synchronized (backend) {
172 font_listeners.remove(l);
176 public static void set_look_and_feel(String new_look_and_feel) {
178 UIManager.setLookAndFeel(new_look_and_feel);
179 } catch (Exception e) {
181 synchronized(backend) {
182 look_and_feel = new_look_and_feel;
183 backend.putString(lookAndFeelPreference, look_and_feel);
185 for (MicroUIListener l : ui_listeners)
186 l.ui_changed(look_and_feel);
190 public static String look_and_feel() {
191 synchronized (backend) {
192 return look_and_feel;
196 public static void register_ui_listener(MicroUIListener l) {
197 synchronized(backend) {
202 public static void unregister_ui_listener(MicroUIListener l) {
203 synchronized (backend) {
204 ui_listeners.remove(l);
207 public static void set_serial_debug(boolean new_serial_debug) {
208 synchronized (backend) {
209 serial_debug = new_serial_debug;
210 backend.putBoolean(serialDebugPreference, serial_debug);
215 public static boolean serial_debug() {
216 synchronized (backend) {