X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosui%2FAltosPreferences.java;h=c8dee743f2318950efc834da3a917d92aa5d0ddd;hb=3cc2eed6cdafe788a8617ab45c6664077e76411e;hp=d4df4e163efecaf18462fc0f49fce012564f138a;hpb=d908c2ebd0b11a54cfd922a192249d0f0df0ddb0;p=fw%2Faltos diff --git a/altosui/AltosPreferences.java b/altosui/AltosPreferences.java index d4df4e16..c8dee743 100644 --- a/altosui/AltosPreferences.java +++ b/altosui/AltosPreferences.java @@ -34,6 +34,9 @@ class AltosPreferences { /* channel preference name */ final static String channelPreferenceFormat = "CHANNEL-%d"; + /* telemetry format preference name */ + final static String telemetryPreferenceFormat = "TELEMETRY-%d"; + /* voice preference name */ final static String voicePreference = "VOICE"; @@ -61,6 +64,9 @@ class AltosPreferences { /* Channel (map serial to channel) */ static Hashtable channels; + /* Telemetry (map serial to telemetry format) */ + static Hashtable telemetries; + /* Voice preference */ static boolean voice; @@ -73,11 +79,9 @@ class AltosPreferences { /* Serial debug */ static boolean serial_debug; - public static void init(Component ui) { + public static void init() { preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); - component = ui; - /* Initialize logdir from preferences */ String logdir_string = preferences.get(logdirPreference, null); if (logdir_string != null) @@ -94,6 +98,8 @@ class AltosPreferences { channels = new Hashtable(); + telemetries = new Hashtable(); + voice = preferences.getBoolean(voicePreference, true); callsign = preferences.get(callsignPreference,"N0CALL"); @@ -108,14 +114,23 @@ class AltosPreferences { AltosSerial.set_debug(serial_debug); } + static { init(); } + + static void set_component(Component in_component) { + component = in_component; + } + static void flush_preferences() { try { preferences.flush(); } catch (BackingStoreException ee) { - JOptionPane.showMessageDialog(component, - preferences.absolutePath(), - "Cannot save prefernces", - JOptionPane.ERROR_MESSAGE); + if (component != null) + JOptionPane.showMessageDialog(component, + preferences.absolutePath(), + "Cannot save prefernces", + JOptionPane.ERROR_MESSAGE); + else + System.err.printf("Cannot save preferences\n"); } } @@ -189,6 +204,23 @@ class AltosPreferences { return channel; } + public static void set_telemetry(int serial, int new_telemetry) { + telemetries.put(serial, new_telemetry); + synchronized (preferences) { + preferences.putInt(String.format(telemetryPreferenceFormat, serial), new_telemetry); + flush_preferences(); + } + } + + public static int telemetry(int serial) { + if (telemetries.containsKey(serial)) + return telemetries.get(serial); + int telemetry = preferences.getInt(String.format(telemetryPreferenceFormat, serial), + Altos.ao_telemetry_standard); + telemetries.put(serial, telemetry); + return telemetry; + } + public static void set_voice(boolean new_voice) { voice = new_voice; synchronized (preferences) { @@ -237,4 +269,8 @@ class AltosPreferences { public static boolean serial_debug() { return serial_debug; } + + public static Preferences bt_devices() { + return preferences.node("bt_devices"); + } }