summaryrefslogtreecommitdiff
path: root/altosuilib/AltosSiteMapTile.java
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-05-27 20:34:29 -0700
committerKeith Packard <keithp@keithp.com>2014-05-27 20:34:29 -0700
commite6cfa25702b3dc1d492c5f1a4d0b4ba4831d30bd (patch)
treeb1a2d1a0be6bc26a4a268dec5f34d1ffe03059c7 /altosuilib/AltosSiteMapTile.java
parent8e44580cbe978f1570d4d2ac13d3dd7cd470ecf7 (diff)
altosuilib: Decompress map images asynchronously and in parallel
This speeds up loading map images from disk quite a bit, and keeps the UI responsive while that happens as well. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosuilib/AltosSiteMapTile.java')
-rw-r--r--altosuilib/AltosSiteMapTile.java70
1 files changed, 50 insertions, 20 deletions
diff --git a/altosuilib/AltosSiteMapTile.java b/altosuilib/AltosSiteMapTile.java
index 09f184a3..136fbd7a 100644
--- a/altosuilib/AltosSiteMapTile.java
+++ b/altosuilib/AltosSiteMapTile.java
@@ -51,11 +51,15 @@ public class AltosSiteMapTile extends JComponent {
LinkedList<AltosPoint> points;
public synchronized void queue_repaint() {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- repaint();
- }
- });
+ if (SwingUtilities.isEventDispatchThread())
+ repaint();
+ else {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ repaint();
+ }
+ });
+ }
}
public void load_map(File pngFile) {
@@ -68,13 +72,14 @@ public class AltosSiteMapTile extends JComponent {
public void set_font(Font font) {
this.font = font;
this.status = AltosSiteMapCache.success;
- queue_repaint();
}
public void set_status(int status) {
- file = null;
- this.status = status;
- queue_repaint();
+ if (status != this.status || file != null) {
+ file = null;
+ this.status = status;
+ queue_repaint();
+ }
}
public void clearMap() {
@@ -83,7 +88,6 @@ public class AltosSiteMapTile extends JComponent {
points = null;
file = null;
status = AltosSiteMapCache.success;
- queue_repaint();
line = null;
}
@@ -151,17 +155,14 @@ public class AltosSiteMapTile extends JComponent {
return String.format(format, distance);
}
- public void paint(Graphics g) {
- Graphics2D g2d = (Graphics2D) g;
- AltosPoint prev = null;
- Image img = null;
+ boolean painting;
- if (file != null)
- img = AltosSiteMapCache.get_image(this, file, px_size, px_size);
-
- if (img != null) {
- g2d.drawImage(img, 0, 0, null);
+ public void paint_graphics(Graphics2D g2d, Image image) {
+ if (image != null) {
+ AltosSiteMap.debug_component(this, "paint_graphics");
+ g2d.drawImage(image, 0, 0, null);
} else {
+ AltosSiteMap.debug_component(this, "erase_graphics");
g2d.setColor(Color.GRAY);
g2d.fillRect(0, 0, getWidth(), getHeight());
String message = null;
@@ -199,6 +200,7 @@ public class AltosSiteMapTile extends JComponent {
g2d.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
if (points != null) {
+ AltosPoint prev = null;
for (AltosPoint point : points) {
if (prev != null) {
if (0 <= point.state && point.state < stateColors.length)
@@ -237,9 +239,37 @@ public class AltosSiteMapTile extends JComponent {
}
g2d.drawString(message, x, y);
}
+ painting = false;
+ }
+
+ public void paint(Graphics g) {
+ Graphics2D g2d = (Graphics2D) g;
+ Image image = null;
+ boolean queued = false;
+
+ if (painting) {
+ AltosSiteMap.debug_component(this, "already painting");
+ return;
+ }
+ AltosSiteMap.debug_component(this, "paint");
+
+ if (file != null) {
+ AltosSiteMapImage aimage;
+
+ aimage = AltosSiteMapCache.get_image(this, file, px_size, px_size);
+ if (aimage != null) {
+ if (aimage.validate())
+ image = aimage.image;
+ else
+ queued = true;
+ }
+ }
+ if (!queued)
+ paint_graphics(g2d, image);
+ painting = queued;
}
- public synchronized void show(int state, Point2D.Double last_pt, Point2D.Double pt)
+ public void show(int state, Point2D.Double last_pt, Point2D.Double pt)
{
if (points == null)
points = new LinkedList<AltosPoint>();