From 398c02b945a58634c8932f07df2c2be8438da7d1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 9 Apr 2013 00:28:05 -0700 Subject: altoslib/altosui: Carry receiver status around in AltosListenerState This moves the crc_errors into the new structure and adds a receiver battery voltage value there as well. Now the receiver status can be monitored separately from the flight status. That also means that code receiving state updates should be prepared to accept missing listener or flight state values. Signed-off-by: Keith Packard --- altosui/AltosSiteMap.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'altosui/AltosSiteMap.java') diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java index f614eae6..5bf02e54 100644 --- a/altosui/AltosSiteMap.java +++ b/altosui/AltosSiteMap.java @@ -264,7 +264,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { initMaps(lat, lon); scrollRocketToVisible(pt(lat, lon)); } - public void show(final AltosState state, final int crc_errors) { + public void show(final AltosState state, final AltosListenerState listener_state) { // if insufficient gps data, nothing to update if (!state.gps.locked && state.gps.nsat < 4) return; @@ -294,7 +294,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { Point2D.Double ref, lref; ref = translatePoint(pt, tileCoordOffset(offset)); lref = translatePoint(last_pt, tileCoordOffset(offset)); - tile.show(state, crc_errors, lref, ref); + tile.show(state, listener_state, lref, ref); if (0 <= ref.x && ref.x < px_size) if (0 <= ref.y && ref.y < px_size) in_any = true; @@ -307,7 +307,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { lref = translatePoint(last_pt, tileCoordOffset(offset)); AltosSiteMapTile tile = createTile(offset); - tile.show(state, crc_errors, lref, ref); + tile.show(state, listener_state, lref, ref); initMap(offset); finishTileLater(tile, offset); } -- cgit v1.2.3 From a03aaaca60ccb4b44595e5e1c1047d07d8b6d60f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 16 Apr 2013 17:33:42 -0700 Subject: altosui: Handle broken network in map tile loading Handle missing pngfiles in AltosSetMapCache by checking ImageIO.read for null return. Do incremental map tile downloading asynchronously so that the UI doesn't lock up when the network is slow Signed-off-by: Keith Packard --- altosui/AltosSiteMap.java | 16 ++++++++++++---- altosui/AltosSiteMapCache.java | 10 +++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'altosui/AltosSiteMap.java') diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java index 5bf02e54..23085f3e 100644 --- a/altosui/AltosSiteMap.java +++ b/altosui/AltosSiteMap.java @@ -220,6 +220,16 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { return pngfile.toString(); } + public void initAndFinishMapAsync (final AltosSiteMapTile tile, final Point offset) { + Thread thread = new Thread() { + public void run() { + initMap(offset); + finishTileLater(tile, offset); + } + }; + thread.start(); + } + public void setBaseLocation(double lat, double lng) { for (Point k : mapTiles.keySet()) { AltosSiteMapTile tile = mapTiles.get(k); @@ -308,8 +318,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { AltosSiteMapTile tile = createTile(offset); tile.show(state, listener_state, lref, ref); - initMap(offset); - finishTileLater(tile, offset); + initAndFinishMapAsync(tile, offset); } scrollRocketToVisible(pt); @@ -370,8 +379,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { if (mapTiles.containsKey(offset)) continue; AltosSiteMapTile tile = createTile(offset); - initMap(offset); - finishTileLater(tile, offset); + initAndFinishMapAsync(tile, offset); } } } diff --git a/altosui/AltosSiteMapCache.java b/altosui/AltosSiteMapCache.java index 617ed4a9..40c8ff6b 100644 --- a/altosui/AltosSiteMapCache.java +++ b/altosui/AltosSiteMapCache.java @@ -19,6 +19,7 @@ package altosui; import javax.swing.*; import javax.imageio.ImageIO; +import java.awt.image.*; import java.io.*; import java.net.URL; import java.net.URLConnection; @@ -87,7 +88,14 @@ public class AltosSiteMapCache extends JLabel { } try { - return new ImageIcon(ImageIO.read(pngfile)); + BufferedImage img; + + img = ImageIO.read(pngfile); + if (img == null) { + System.out.printf("# Can't read pngfile %s\n", pngfile); + return null; + } + return new ImageIcon(img); } catch (IOException e) { System.out.printf("# IO error trying to load %s\n", pngfile); return null; -- cgit v1.2.3