import javax.swing.filechooser.FileSystemView;
class AltosPreferences {
- static Preferences preferences;
+ public static Preferences preferences;
/* logdir preference name */
final static String logdirPreference = "LOGDIR";
/* scanning telemetry preferences name */
final static String scanningTelemetryPreference = "SCANNING-TELEMETRY";
- /* font size preferences name */
- final static String fontSizePreference = "FONT-SIZE";
+ /* Launcher serial preference name */
+ final static String launcherSerialPreference = "LAUNCHER-SERIAL";
+ /* Launcher channel preference name */
+ final static String launcherChannelPreference = "LAUNCHER-CHANNEL";
+
/* Default logdir is ~/TeleMetrum */
final static String logdirName = "TeleMetrum";
- /* UI Component to pop dialogs up */
- static Component component;
-
/* Log directory */
static File logdir;
/* Scanning telemetry */
static int scanning_telemetry;
- static LinkedList<AltosFontListener> font_listeners;
-
- static int font_size = Altos.font_size_medium;
-
/* List of frequencies */
final static String common_frequencies_node_name = "COMMON-FREQUENCIES";
static AltosFrequency[] common_frequencies;
node.put(String.format(description_format, i), frequencies[i].description);
}
}
+ static int launcher_serial;
+
+ static int launcher_channel;
public static void init() {
preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
scanning_telemetry = preferences.getInt(scanningTelemetryPreference,(1 << Altos.ao_telemetry_standard));
- font_listeners = new LinkedList<AltosFontListener>();
+ launcher_serial = preferences.getInt(launcherSerialPreference, 0);
- font_size = preferences.getInt(fontSizePreference, Altos.font_size_medium);
- Altos.set_fonts(font_size);
+ launcher_channel = preferences.getInt(launcherChannelPreference, 0);
String firmwaredir_string = preferences.get(firmwaredirPreference, null);
if (firmwaredir_string != null)
AltosSerial.set_debug(serial_debug);
common_frequencies = load_common_frequencies();
+
}
static { init(); }
- static void set_component(Component in_component) {
- component = in_component;
- }
-
static void flush_preferences() {
try {
preferences.flush();
} catch (BackingStoreException ee) {
+/*
if (component != null)
JOptionPane.showMessageDialog(component,
preferences.absolutePath(),
"Cannot save prefernces",
JOptionPane.ERROR_MESSAGE);
else
+*/
System.err.printf("Cannot save preferences\n");
}
}
}
}
- private static boolean check_dir(File dir) {
- if (!dir.exists()) {
- if (!dir.mkdirs()) {
- JOptionPane.showMessageDialog(component,
- dir.getName(),
- "Cannot create directory",
- JOptionPane.ERROR_MESSAGE);
- return false;
- }
- } else if (!dir.isDirectory()) {
- JOptionPane.showMessageDialog(component,
- dir.getName(),
- "Is not a directory",
- JOptionPane.ERROR_MESSAGE);
- return false;
- }
- return true;
- }
-
- /* Configure the log directory. This is where all telemetry and eeprom files
- * will be written to, and where replay will look for telemetry files
- */
- public static void ConfigureLog() {
- JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile());
-
- logdir_chooser.setDialogTitle("Configure Data Logging Directory");
- logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
-
- if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
- File dir = logdir_chooser.getSelectedFile();
- if (check_dir(dir))
- set_logdir(dir);
- }
- }
-
public static File logdir() {
return logdir;
}
return firmwaredir;
}
- public static int font_size() {
- return font_size;
- }
-
- static void set_fonts() {
- }
-
- public static void set_font_size(int new_font_size) {
- font_size = new_font_size;
+ public static void set_serial_debug(boolean new_serial_debug) {
+ serial_debug = new_serial_debug;
+ AltosSerial.set_debug(serial_debug);
synchronized (preferences) {
- preferences.putInt(fontSizePreference, font_size);
+ preferences.putBoolean(serialDebugPreference, serial_debug);
flush_preferences();
- Altos.set_fonts(font_size);
- for (AltosFontListener l : font_listeners)
- l.font_size_changed(font_size);
}
}
- public static void register_font_listener(AltosFontListener l) {
- synchronized (preferences) {
- font_listeners.add(l);
- }
+ public static boolean serial_debug() {
+ return serial_debug;
}
- public static void unregister_font_listener(AltosFontListener l) {
+ public static void set_launcher_serial(int new_launcher_serial) {
+ launcher_serial = new_launcher_serial;
+ System.out.printf("set launcher serial to %d\n", new_launcher_serial);
synchronized (preferences) {
- font_listeners.remove(l);
+ preferences.putInt(launcherSerialPreference, launcher_serial);
+ flush_preferences();
}
}
- public static void set_serial_debug(boolean new_serial_debug) {
- serial_debug = new_serial_debug;
- AltosSerial.set_debug(serial_debug);
+ public static int launcher_serial() {
+ return launcher_serial;
+ }
+
+ public static void set_launcher_channel(int new_launcher_channel) {
+ launcher_channel = new_launcher_channel;
+ System.out.printf("set launcher channel to %d\n", new_launcher_channel);
synchronized (preferences) {
- preferences.putBoolean(serialDebugPreference, serial_debug);
+ preferences.putInt(launcherChannelPreference, launcher_channel);
flush_preferences();
}
}
- public static boolean serial_debug() {
- return serial_debug;
+ public static int launcher_channel() {
+ return launcher_channel;
}
-
+
public static Preferences bt_devices() {
return preferences.node("bt_devices");
}