diff options
| author | Anthony Towns <aj@erisian.com.au> | 2010-11-21 14:05:00 +1000 | 
|---|---|---|
| committer | Anthony Towns <aj@erisian.com.au> | 2010-11-21 14:05:00 +1000 | 
| commit | 71e487344395a8efc9cd279aad92f601ff4c6d3d (patch) | |
| tree | 335fdc9d4d1668dd3aca3f44b3949204d1fe3042 | |
| parent | c040bcd06679484175542208fb564d0271a7fc1b (diff) | |
AltosSiteMap: thread safe tile addition
| -rw-r--r-- | ao-tools/altosui/AltosSiteMap.java | 30 | 
1 files changed, 19 insertions, 11 deletions
| 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; | 
