summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-06-13 21:26:33 -0700
committerKeith Packard <keithp@keithp.com>2014-06-13 21:26:33 -0700
commit9a6a3c34293eac6442f766e13ce148f595e891eb (patch)
tree7a9b05e48f8aabc43260b377c6b7b3559cd75fbd
parent92895c87bc3d97bf4990f1feda0bd8b07da4c405 (diff)
altosuilib: Make map-cache per-window instead of global
This consumes more memory, but avoids cache conflicts between windows Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--altosuilib/AltosUIMapCache.java22
-rw-r--r--altosuilib/AltosUIMapPreload.java3
-rw-r--r--altosuilib/AltosUIMapTile.java4
-rw-r--r--altosuilib/AltosUIMapTileListener.java2
-rw-r--r--altosuilib/AltosUIMapView.java6
5 files changed, 25 insertions, 12 deletions
diff --git a/altosuilib/AltosUIMapCache.java b/altosuilib/AltosUIMapCache.java
index e849da79..55311d8c 100644
--- a/altosuilib/AltosUIMapCache.java
+++ b/altosuilib/AltosUIMapCache.java
@@ -31,18 +31,19 @@ public class AltosUIMapCache {
static final int bad_request = 3;
static final int forbidden = 4;
- static private Object fetch_lock = new Object();
+ static final int min_cache_size = 9;
+ static final int max_cache_size = 24;
- static final int min_cache_size = 9;
- static final int max_cache_size = 24;
+ private Object fetch_lock = new Object();
+ private Object cache_lock = new Object();
- static int cache_size = min_cache_size;
+ int cache_size = min_cache_size;
- static AltosUIMapImage[] images = new AltosUIMapImage[cache_size];
+ AltosUIMapImage[] images = new AltosUIMapImage[cache_size];
- static Object cache_lock = new Object();
+ long used;
- public static void set_cache_size(int new_size) {
+ public void set_cache_size(int new_size) {
if (new_size < min_cache_size)
new_size = min_cache_size;
if (new_size > max_cache_size)
@@ -64,9 +65,7 @@ public class AltosUIMapCache {
}
}
- static long used;
-
- public static Image get(AltosUIMapTile tile, AltosUIMapStore store, int width, int height) {
+ public Image get(AltosUIMapTile tile, AltosUIMapStore store, int width, int height) {
int oldest = -1;
long age = used;
@@ -109,4 +108,7 @@ public class AltosUIMapCache {
}
}
}
+
+ public AltosUIMapCache() {
+ }
}
diff --git a/altosuilib/AltosUIMapPreload.java b/altosuilib/AltosUIMapPreload.java
index d702dddf..3bdba39e 100644
--- a/altosuilib/AltosUIMapPreload.java
+++ b/altosuilib/AltosUIMapPreload.java
@@ -209,6 +209,7 @@ class AltosUISites extends Thread {
public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, ItemListener, AltosUIMapTileListener {
AltosUIFrame owner;
AltosUIMap map;
+ AltosUIMapCache cache = new AltosUIMapCache();
AltosUIMapPos lat;
AltosUIMapPos lon;
@@ -353,6 +354,8 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I
}
}
+ public AltosUIMapCache cache() { return cache; }
+
public void set_sites() {
int i = 1;
for (AltosUISite site : sites.sites) {
diff --git a/altosuilib/AltosUIMapTile.java b/altosuilib/AltosUIMapTile.java
index 6fbcdb4b..7c823183 100644
--- a/altosuilib/AltosUIMapTile.java
+++ b/altosuilib/AltosUIMapTile.java
@@ -34,6 +34,7 @@ public class AltosUIMapTile {
int zoom;
int maptype;
AltosUIMapStore store;
+ AltosUIMapCache cache;
int status;
private File map_file() {
@@ -153,7 +154,7 @@ public class AltosUIMapTile {
++painting_serial;
if (image == null && t.has_location())
- image = AltosUIMapCache.get(this, store, px_size, px_size);
+ image = cache.get(this, store, px_size, px_size);
paint_graphics(g2d, t, painting_serial);
}
@@ -173,6 +174,7 @@ public class AltosUIMapTile {
public AltosUIMapTile(AltosUIMapTileListener listener, AltosUILatLon upper_left, AltosUILatLon center, int zoom, int maptype, int px_size, Font font) {
this.listener = listener;
this.upper_left = upper_left;
+ cache = listener.cache();
while (center.lon < -180.0)
center.lon += 360.0;
diff --git a/altosuilib/AltosUIMapTileListener.java b/altosuilib/AltosUIMapTileListener.java
index 4cc3ff2f..4ca13539 100644
--- a/altosuilib/AltosUIMapTileListener.java
+++ b/altosuilib/AltosUIMapTileListener.java
@@ -19,4 +19,6 @@ package org.altusmetrum.altosuilib_2;
public interface AltosUIMapTileListener {
abstract public void notify_tile(AltosUIMapTile tile, int status);
+
+ abstract public AltosUIMapCache cache();
}
diff --git a/altosuilib/AltosUIMapView.java b/altosuilib/AltosUIMapView.java
index efae3767..4df178e2 100644
--- a/altosuilib/AltosUIMapView.java
+++ b/altosuilib/AltosUIMapView.java
@@ -34,6 +34,8 @@ public class AltosUIMapView extends Component implements MouseMotionListener, Mo
AltosUIMapLine line = new AltosUIMapLine();
+ AltosUIMapCache cache = new AltosUIMapCache();
+
LinkedList<AltosUIMapMark> marks = new LinkedList<AltosUIMapMark>();
LinkedList<AltosUIMapZoomListener> zoom_listeners = new LinkedList<AltosUIMapZoomListener>();
@@ -368,7 +370,7 @@ public class AltosUIMapView extends Component implements MouseMotionListener, Mo
for (Point point : to_remove)
tiles.remove(point);
- AltosUIMapCache.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(((lower_right.y - upper_left.y) / px_size + 1) * ((lower_right.x - upper_left.x) / px_size + 1));
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);
@@ -394,6 +396,8 @@ public class AltosUIMapView extends Component implements MouseMotionListener, Mo
}
}
+ public AltosUIMapCache cache() { return cache; }
+
/* AltosUIMapStoreListener methods */
public void notify_store(AltosUIMapStore store, int status) {
if (load_listener != null) {