row++;
}
+ static final Integer map_caches[] = { 9, 25, 100 };
+
+ public void add_map_cache() {
+ pane.add(new JLabel("Map Cache Size"), constraints(0, 1));
+
+ final JComboBox<Integer> map_cache = new JComboBox<Integer>(map_caches);
+
+ map_cache.setEditable(true);
+ map_cache.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ try {
+ int size = (Integer) (map_cache.getSelectedItem());
+
+ AltosUIPreferences.set_map_cache(size);
+ } catch (ClassCastException ce) {
+ map_cache.setSelectedItem(new Integer(AltosUIPreferences.map_cache()));
+ }
+ }
+ });
+
+ map_cache.setSelectedItem (new Integer(AltosUIPreferences.map_cache()));
+ pane.add(map_cache, constraints(1, 2, GridBagConstraints.BOTH));
+ row++;
+ }
+
public void add_bluetooth() {
}
add_font_size();
add_look_and_feel();
add_position();
+ add_map_cache();
add_bluetooth();
add_frequencies();
import java.io.*;
import java.net.*;
-public class AltosUIMapCache {
+public class AltosUIMapCache implements AltosUIMapCacheListener {
static final int success = 0;
static final int loading = 1;
static final int failed = 2;
static final int bad_request = 3;
static final int forbidden = 4;
- static final int min_cache_size = 9;
- static final int max_cache_size = 24;
+ int min_cache_size; /* configured minimum cache size */
+ int cache_size; /* current cache size */
+ int requested_cache_size; /* cache size computed by application */
private Object fetch_lock = new Object();
private Object cache_lock = new Object();
- int cache_size = min_cache_size;
-
AltosUIMapImage[] images = new AltosUIMapImage[cache_size];
long used;
public void set_cache_size(int new_size) {
+
+ requested_cache_size = new_size;
+
if (new_size < min_cache_size)
new_size = min_cache_size;
- if (new_size > max_cache_size)
- new_size = max_cache_size;
+
if (new_size == cache_size)
return;
+ System.out.printf("cache size now %d\n", new_size);
+
synchronized(cache_lock) {
AltosUIMapImage[] new_images = new AltosUIMapImage[new_size];
try {
image = new AltosUIMapImage(tile, store);
image.used = used++;
- if (images[oldest] != null)
+ if (images[oldest] != null) {
+ System.out.printf("drop %s\n", images[oldest].store.file.toString());
images[oldest].flush();
+ }
+
+ System.out.printf("load %s\n", store.file.toString());
images[oldest] = image;
}
}
+ public void map_cache_changed(int map_cache) {
+ min_cache_size = map_cache;
+
+ set_cache_size(requested_cache_size);
+ }
+
+ public void dispose() {
+ AltosUIPreferences.unregister_map_cache_listener(this);
+
+ for (int i = 0; i < cache_size; i++) {
+ AltosUIMapImage image = images[i];
+
+ if (image != null)
+ image.flush();
+ }
+ }
+
public AltosUIMapCache() {
+ min_cache_size = AltosUIPreferences.map_cache();
+
+ set_cache_size(0);
+
+ AltosUIPreferences.register_map_cache_listener(this);
}
}
--- /dev/null
+/*
+ * Copyright © 2014 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.altosuilib_3;
+
+public interface AltosUIMapCacheListener {
+ public void map_cache_changed(int map_cache);
+}
for (Point point : to_remove)
tiles.remove(point);
- cache.set_cache_size(((lower_right.y - upper_left.y) / px_size + 1) * ((lower_right.x - upper_left.x) / px_size + 1));
+ cache.set_cache_size((getWidth() / px_size + 2) * (getHeight() / px_size + 2));
for (int y = upper_left.y; y <= lower_right.y; y += px_size) {
for (int x = upper_left.x; x <= lower_right.x; x += px_size) {
Point point = new Point(x, y);
/* 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;
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());
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(); }
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;
+ }
+ }
}
AltosUIMapPath.java \
AltosUIMapTile.java \
AltosUIMapCache.java \
+ AltosUIMapCacheListener.java \
AltosUIMapImage.java \
AltosUIMapTransform.java \
AltosUIMapRectangle.java \