From: Anthony Towns Date: Sun, 21 Nov 2010 04:05:00 +0000 (+1000) Subject: AltosSiteMap: thread safe tile addition X-Git-Tag: debian/0.7.1+117+ge7954c8~3 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=71e487344395a8efc9cd279aad92f601ff4c6d3d AltosSiteMap: thread safe tile addition --- diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index dd99ad48..df5207bf 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -229,7 +229,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { boolean initialised = false; Point2D.Double last_pt = null; int last_state = -1; - public void show(AltosState state, int crc_errors) { + public void show(final AltosState state, final int crc_errors) { // if insufficient gps data, nothing to update if (state.gps == null) return; @@ -245,7 +245,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { initialised = true; } - Point2D.Double pt = pt(state.gps.lat, state.gps.lon); + final Point2D.Double pt = pt(state.gps.lat, state.gps.lon); if (last_pt == pt && last_state == state.state) return; @@ -263,15 +263,23 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { in_any = true; } if (!in_any) { - AltosSiteMapTile tile = addTileAt(tileOffset(pt)); - setViewportView(comp); - - Point2D.Double ref, lref; - ref = translatePoint(pt, tileCoordOffset(tile)); - lref = translatePoint(last_pt, tileCoordOffset(tile)); - tile.show(state, crc_errors, lref, ref); - - initMap(tile); + try { + SwingUtilities.invokeAndWait( new Runnable() { + public void run() { + AltosSiteMapTile tile = addTileAt(tileOffset(pt)); + setViewportView(comp); + + Point2D.Double ref, lref; + ref = translatePoint(pt, tileCoordOffset(tile)); + lref = translatePoint(last_pt, tileCoordOffset(tile)); + tile.show(state, crc_errors, lref, ref); + + initMap(tile); + } + } ); + } catch (Exception e) { + // pray + } } last_pt = pt; last_state = state.state;