altosuilib: Update map preloading UI to include zoom and maptypes
[fw/altos] / altosuilib / AltosSiteMapTile.java
index 136fbd7a23095b00c7b7c2283fd6516e36e0077f..f8b924a82cd7444ed74abf08a380271eb62a0a5b 100644 (file)
@@ -155,9 +155,16 @@ public class AltosSiteMapTile extends JComponent {
                return String.format(format, distance);
        }
 
-       boolean painting;
+       int     painting_serial;
+       int     painted_serial;
+
+       public void paint_graphics(Graphics2D g2d, Image image, int serial) {
+
+               if (serial < painted_serial)
+                       return;
+
+               painted_serial = serial;
 
-       public void paint_graphics(Graphics2D g2d, Image image) {
                if (image != null) {
                        AltosSiteMap.debug_component(this, "paint_graphics");
                        g2d.drawImage(image, 0, 0, null);
@@ -239,7 +246,6 @@ public class AltosSiteMapTile extends JComponent {
                        }
                        g2d.drawString(message, x, y);
                }
-               painting = false;
        }
 
        public void paint(Graphics g) {
@@ -247,26 +253,23 @@ public class AltosSiteMapTile extends JComponent {
                Image                   image = null;
                boolean                 queued = false;
 
-               if (painting) {
-                       AltosSiteMap.debug_component(this, "already painting");
-                       return;
-               }
                AltosSiteMap.debug_component(this, "paint");
 
+               ++painting_serial;
+
                if (file != null) {
                        AltosSiteMapImage       aimage;
 
                        aimage = AltosSiteMapCache.get_image(this, file, px_size, px_size);
                        if (aimage != null) {
-                               if (aimage.validate())
+                               if (aimage.validate(painting_serial))
                                        image = aimage.image;
                                else
                                        queued = true;
                        }
                }
                if (!queued)
-                       paint_graphics(g2d, image);
-               painting = queued;
+                       paint_graphics(g2d, image, painting_serial);
        }
 
        public void show(int state, Point2D.Double last_pt, Point2D.Double pt)