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.altosuilib_10;
22 import java.awt.Component;
24 import org.altusmetrum.altoslib_10.*;
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 /* Window position preference name */
35 final static String positionPreference = "POSITION";
37 /* Maps cache size preference name */
38 final static String mapCachePreference = "MAP-CACHE";
40 /* UI Component to pop dialogs up */
41 static Component component;
43 static LinkedList<AltosFontListener> font_listeners;
45 static int font_size = AltosUILib.font_size_medium;
47 static LinkedList<AltosUIListener> ui_listeners;
49 static String look_and_feel = null;
52 public static boolean serial_debug;
54 static LinkedList<AltosPositionListener> position_listeners;
56 public static int position = AltosUILib.position_top_left;
58 public static void init() {
59 AltosPreferences.init(new AltosUIPreferencesBackend());
61 font_listeners = new LinkedList<AltosFontListener>();
63 font_size = backend.getInt(fontSizePreference, AltosUILib.font_size_medium);
64 AltosUILib.set_fonts(font_size);
65 look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
67 ui_listeners = new LinkedList<AltosUIListener>();
68 serial_debug = backend.getBoolean(serialDebugPreference, false);
70 AltosLink.set_debug(serial_debug);
72 position = backend.getInt(positionPreference, AltosUILib.position_top_left);
73 position_listeners = new LinkedList<AltosPositionListener>();
78 public static void set_component(Component in_component) {
79 component = in_component;
82 private static boolean check_dir(File dir) {
85 JOptionPane.showMessageDialog(component,
87 "Cannot create directory",
88 JOptionPane.ERROR_MESSAGE);
91 } else if (!dir.isDirectory()) {
92 JOptionPane.showMessageDialog(component,
95 JOptionPane.ERROR_MESSAGE);
101 /* Configure the log directory. This is where all telemetry and eeprom files
102 * will be written to, and where replay will look for telemetry files
104 public static void ConfigureLog() {
105 JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile());
107 logdir_chooser.setDialogTitle("Configure Data Logging Directory");
108 logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
110 if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
111 File dir = logdir_chooser.getSelectedFile();
116 public static int font_size() {
117 synchronized (backend) {
122 static void set_fonts() {
125 public static void set_font_size(int new_font_size) {
126 synchronized (backend) {
127 font_size = new_font_size;
128 backend.putInt(fontSizePreference, font_size);
130 AltosUILib.set_fonts(font_size);
131 for (AltosFontListener l : font_listeners)
132 l.font_size_changed(font_size);
136 public static void register_font_listener(AltosFontListener l) {
137 synchronized (backend) {
138 font_listeners.add(l);
142 public static void unregister_font_listener(AltosFontListener l) {
143 synchronized (backend) {
144 font_listeners.remove(l);
148 public static void set_look_and_feel(String new_look_and_feel) {
150 UIManager.setLookAndFeel(new_look_and_feel);
151 } catch (Exception e) {
153 synchronized(backend) {
154 look_and_feel = new_look_and_feel;
155 backend.putString(lookAndFeelPreference, look_and_feel);
157 for (AltosUIListener l : ui_listeners)
158 l.ui_changed(look_and_feel);
162 public static String look_and_feel() {
163 synchronized (backend) {
164 return look_and_feel;
168 public static void register_ui_listener(AltosUIListener l) {
169 synchronized(backend) {
174 public static void unregister_ui_listener(AltosUIListener l) {
175 synchronized (backend) {
176 ui_listeners.remove(l);
179 public static void set_serial_debug(boolean new_serial_debug) {
180 AltosLink.set_debug(new_serial_debug);
181 synchronized (backend) {
182 serial_debug = new_serial_debug;
183 backend.putBoolean(serialDebugPreference, serial_debug);
188 public static boolean serial_debug() {
189 synchronized (backend) {
194 public static void register_position_listener(AltosPositionListener l) {
195 synchronized(backend) {
196 position_listeners.add(l);
200 public static void unregister_position_listener(AltosPositionListener l) {
201 synchronized (backend) {
202 position_listeners.remove(l);
206 public static void set_position(int new_position) {
207 synchronized (backend) {
208 position = new_position;
209 backend.putInt(positionPreference, position);
211 for (AltosPositionListener l : position_listeners)
212 l.position_changed(position);
216 public static int position() {
217 synchronized (backend) {