telegps: Add graph display
[fw/altos] / altosuilib / AltosSiteMapTile.java
index 09f184a37869cf121f19e3f556b535f10ca7e4ea..f8b924a82cd7444ed74abf08a380271eb62a0a5b 100644 (file)
@@ -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,21 @@ 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;
+       int     painting_serial;
+       int     painted_serial;
+
+       public void paint_graphics(Graphics2D g2d, Image image, int serial) {
+
+               if (serial < painted_serial)
+                       return;
 
-               if (file != null)
-                       img = AltosSiteMapCache.get_image(this, file, px_size, px_size);
+               painted_serial = serial;
 
-               if (img != null) {
-                       g2d.drawImage(img, 0, 0, null);
+               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 +207,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)
@@ -239,7 +248,31 @@ public class AltosSiteMapTile extends JComponent {
                }
        }
 
-       public synchronized void show(int state, Point2D.Double last_pt, Point2D.Double pt)
+       public void paint(Graphics g) {
+               Graphics2D              g2d = (Graphics2D) g;
+               Image                   image = null;
+               boolean                 queued = false;
+
+               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(painting_serial))
+                                       image = aimage.image;
+                               else
+                                       queued = true;
+                       }
+               }
+               if (!queued)
+                       paint_graphics(g2d, image, painting_serial);
+       }
+
+       public void show(int state, Point2D.Double last_pt, Point2D.Double pt)
        {
                if (points == null)
                        points = new LinkedList<AltosPoint>();