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/AltosSiteMapCache.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'altosui/AltosSiteMapCache.java') 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