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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altosuilib_11;
23 import java.awt.Component;
25 import org.altusmetrum.altoslib_11.*;
27 public class AltosUIPreferences extends AltosPreferences {
29 /* font size preferences name */
30 final static String fontSizePreference = "FONT-SIZE";
32 /* Look&Feel preference name */
33 final static String lookAndFeelPreference = "LOOK-AND-FEEL";
35 /* Window position preference name */
36 final static String positionPreference = "POSITION";
38 /* Maps cache size preference name */
39 final static String mapCachePreference = "MAP-CACHE";
41 /* UI Component to pop dialogs up */
42 static Component component;
44 static LinkedList<AltosFontListener> font_listeners;
46 static int font_size = AltosUILib.font_size_medium;
48 static LinkedList<AltosUIListener> ui_listeners;
50 static String look_and_feel = null;
53 public static boolean serial_debug;
55 static LinkedList<AltosPositionListener> position_listeners;
57 public static int position = AltosUILib.position_top_left;
59 public static void init() {
60 AltosPreferences.init(new AltosUIPreferencesBackend());
62 font_listeners = new LinkedList<AltosFontListener>();
64 font_size = backend.getInt(fontSizePreference, AltosUILib.font_size_medium);
65 AltosUILib.set_fonts(font_size);
66 look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
68 ui_listeners = new LinkedList<AltosUIListener>();
69 serial_debug = backend.getBoolean(serialDebugPreference, false);
71 AltosLink.set_debug(serial_debug);
73 position = backend.getInt(positionPreference, AltosUILib.position_top_left);
74 position_listeners = new LinkedList<AltosPositionListener>();
79 public static void set_component(Component in_component) {
80 component = in_component;
83 private static boolean check_dir(File dir) {
86 JOptionPane.showMessageDialog(component,
88 "Cannot create directory",
89 JOptionPane.ERROR_MESSAGE);
92 } else if (!dir.isDirectory()) {
93 JOptionPane.showMessageDialog(component,
96 JOptionPane.ERROR_MESSAGE);
102 /* Configure the log directory. This is where all telemetry and eeprom files
103 * will be written to, and where replay will look for telemetry files
105 public static void ConfigureLog() {
106 JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile());
108 logdir_chooser.setDialogTitle("Configure Data Logging Directory");
109 logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
111 if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
112 File dir = logdir_chooser.getSelectedFile();
117 public static int font_size() {
118 synchronized (backend) {
123 static void set_fonts() {
126 public static void set_font_size(int new_font_size) {
127 synchronized (backend) {
128 font_size = new_font_size;
129 backend.putInt(fontSizePreference, font_size);
131 AltosUILib.set_fonts(font_size);
132 for (AltosFontListener l : font_listeners)
133 l.font_size_changed(font_size);
137 public static void register_font_listener(AltosFontListener l) {
138 synchronized (backend) {
139 font_listeners.add(l);
143 public static void unregister_font_listener(AltosFontListener l) {
144 synchronized (backend) {
145 font_listeners.remove(l);
149 public static void set_look_and_feel(String new_look_and_feel) {
151 UIManager.setLookAndFeel(new_look_and_feel);
152 } catch (Exception e) {
154 synchronized(backend) {
155 look_and_feel = new_look_and_feel;
156 backend.putString(lookAndFeelPreference, look_and_feel);
158 for (AltosUIListener l : ui_listeners)
159 l.ui_changed(look_and_feel);
163 public static String look_and_feel() {
164 synchronized (backend) {
165 return look_and_feel;
169 public static void register_ui_listener(AltosUIListener l) {
170 synchronized(backend) {
175 public static void unregister_ui_listener(AltosUIListener l) {
176 synchronized (backend) {
177 ui_listeners.remove(l);
180 public static void set_serial_debug(boolean new_serial_debug) {
181 AltosLink.set_debug(new_serial_debug);
182 synchronized (backend) {
183 serial_debug = new_serial_debug;
184 backend.putBoolean(serialDebugPreference, serial_debug);
189 public static boolean serial_debug() {
190 synchronized (backend) {
195 public static void register_position_listener(AltosPositionListener l) {
196 synchronized(backend) {
197 position_listeners.add(l);
201 public static void unregister_position_listener(AltosPositionListener l) {
202 synchronized (backend) {
203 position_listeners.remove(l);
207 public static void set_position(int new_position) {
208 synchronized (backend) {
209 position = new_position;
210 backend.putInt(positionPreference, position);
212 for (AltosPositionListener l : position_listeners)
213 l.position_changed(position);
217 public static int position() {
218 synchronized (backend) {