altoslib: Add units change notification list
authorKeith Packard <keithp@keithp.com>
Mon, 31 Dec 2012 19:38:53 +0000 (11:38 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 31 Dec 2012 19:38:53 +0000 (11:38 -0800)
This allows the UI to automatically respond to changes in the
preferred units.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosPreferences.java
altoslib/AltosUnitsListener.java [new file with mode: 0644]
altoslib/Makefile.am

index 47196d6e70b89342ef3f876207bef574bcb941f4..e50b9b5cf05a9a856b1b60fb3af6fe604ac3db39 100644 (file)
@@ -367,6 +367,8 @@ public class AltosPreferences {
                set_common_frequencies(new_frequencies);
        }
 
+       static LinkedList<AltosUnitsListener> units_listeners;
+
        public static boolean imperial_units() {
                synchronized(backend) {
                        return AltosConvert.imperial_units;
@@ -379,5 +381,24 @@ public class AltosPreferences {
                        backend.putBoolean(unitsPreference, imperial_units);
                        flush_preferences();
                }
+               if (units_listeners != null) {
+                       for (AltosUnitsListener l : units_listeners) {
+                               l.units_changed(imperial_units);
+                       }
+               }
+       }
+
+       public static void register_units_listener(AltosUnitsListener l) {
+               synchronized(backend) {
+                       if (units_listeners == null)
+                               units_listeners = new LinkedList<AltosUnitsListener>();
+                       units_listeners.add(l);
+               }
+       }
+
+       public static void unregister_units_listener(AltosUnitsListener l) {
+               synchronized(backend) {
+                       units_listeners.remove(l);
+               }
        }
 }
diff --git a/altoslib/AltosUnitsListener.java b/altoslib/AltosUnitsListener.java
new file mode 100644 (file)
index 0000000..50a00cd
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.AltosLib;
+
+public interface AltosUnitsListener {
+       public void units_changed(boolean imperial_units);
+}
index 0086bc6555fc617414ddc63b51756012e1efc555..1b03c92557d4bd4dc3d83e979272e3cead0693a8 100644 (file)
@@ -69,6 +69,7 @@ AltosLib_JAVA = \
        $(SRC)/AltosTelemetryRecordSensor.java \
        $(SRC)/AltosTelemetryRecordMegaSensor.java \
        $(SRC)/AltosTelemetryRecordMegaData.java \
+       $(SRC)/AltosUnitsListener.java \
        $(SRC)/AltosMs5607.java \
        $(SRC)/AltosIMU.java \
        $(SRC)/AltosMag.java \