Bump java library versions
[fw/altos] / altosuilib / AltosUIPreferences.java
index 485cb582f1cd13f93af714433f459afdbe6b08b7..9760494c74f7bea6193611f8a70d7c650493d526 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altosuilib;
+package org.altusmetrum.altosuilib_6;
 
 import java.io.*;
 import java.util.*;
 import java.awt.Component;
 import javax.swing.*;
-import org.altusmetrum.AltosLib.*;
+import org.altusmetrum.altoslib_6.*;
 
 public class AltosUIPreferences extends AltosPreferences {
 
@@ -31,6 +31,12 @@ public class AltosUIPreferences extends AltosPreferences {
        /* Look&Feel preference name */
        final static String lookAndFeelPreference = "LOOK-AND-FEEL";
 
+       /* Window position preference name */
+       final static String positionPreference = "POSITION";
+
+       /* Maps cache size preference name */
+       final static String mapCachePreference = "MAP-CACHE";
+
        /* UI Component to pop dialogs up */
        static Component component;
 
@@ -45,6 +51,14 @@ public class AltosUIPreferences extends AltosPreferences {
        /* Serial debug */
        public static boolean serial_debug;
 
+       static LinkedList<AltosPositionListener> position_listeners;
+
+       public static int position = AltosUILib.position_top_left;
+
+       static LinkedList<AltosUIMapCacheListener> map_cache_listeners;
+
+       public static int map_cache = 9;
+
        public static void init() {
                AltosPreferences.init(new AltosUIPreferencesBackend());
 
@@ -56,7 +70,14 @@ public class AltosUIPreferences extends AltosPreferences {
 
                ui_listeners = new LinkedList<AltosUIListener>();
                serial_debug = backend.getBoolean(serialDebugPreference, false);
+
                AltosLink.set_debug(serial_debug);
+
+               position = backend.getInt(positionPreference, AltosUILib.position_top_left);
+               position_listeners = new LinkedList<AltosPositionListener>();
+
+               map_cache = backend.getInt(mapCachePreference, 9);
+               map_cache_listeners = new LinkedList<AltosUIMapCacheListener>();
        }
 
        static { init(); }
@@ -177,4 +198,59 @@ public class AltosUIPreferences extends AltosPreferences {
                }
        }
 
+       public static void register_position_listener(AltosPositionListener l) {
+               synchronized(backend) {
+                       position_listeners.add(l);
+               }
+       }
+
+       public static void unregister_position_listener(AltosPositionListener l) {
+               synchronized (backend) {
+                       position_listeners.remove(l);
+               }
+       }
+
+       public static void set_position(int new_position) {
+               synchronized (backend) {
+                       position = new_position;
+                       backend.putInt(positionPreference, position);
+                       flush_preferences();
+                       for (AltosPositionListener l : position_listeners)
+                               l.position_changed(position);
+               }
+       }
+
+       public static int position() {
+               synchronized (backend) {
+                       return position;
+               }
+       }
+
+       public static void register_map_cache_listener(AltosUIMapCacheListener l) {
+               synchronized(backend) {
+                       map_cache_listeners.add(l);
+               }
+       }
+
+       public static void unregister_map_cache_listener(AltosUIMapCacheListener l) {
+               synchronized (backend) {
+                       map_cache_listeners.remove(l);
+               }
+       }
+
+       public static void set_map_cache(int new_map_cache) {
+               synchronized(backend) {
+                       map_cache = new_map_cache;
+                       backend.putInt(mapCachePreference, map_cache);
+                       flush_preferences();
+                       for (AltosUIMapCacheListener l: map_cache_listeners)
+                               l.map_cache_changed(map_cache);
+               }
+       }
+
+       public static int map_cache() {
+               synchronized(backend) {
+                       return map_cache;
+               }
+       }
 }