From 4a9ded5b39ed08e13abc2cddba8b712f62b983f2 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 21 Nov 2010 17:39:50 +1000 Subject: [PATCH] AltosSiteMap: ensure buffer around active tile --- ao-tools/altosui/AltosSiteMap.java | 53 ++++++++++++++++++++------ ao-tools/altosui/AltosSiteMapTile.java | 17 ++++++--- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index b2d79043..802eb68c 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -260,29 +260,57 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { if (0 <= ref.y && ref.y < px_size) in_any = true; } - if (!in_any) { - final AltosSiteMapTile tile = new AltosSiteMapTile(px_size); - final Point offset = tileOffset(pt); - mapTiles.put(offset, tile); + Point offset = tileOffset(pt); + if (!in_any) { Point2D.Double ref, lref; ref = translatePoint(pt, tileCoordOffset(offset)); lref = translatePoint(last_pt, tileCoordOffset(offset)); - tile.show(state, crc_errors, lref, ref); + AltosSiteMapTile tile = createTile(offset); + tile.show(state, crc_errors, lref, ref); initMap(tile, offset); + finishTileLater(tile, offset); + } - SwingUtilities.invokeLater( new Runnable() { - public void run() { - addTileAt(tile, offset); - setViewportView(comp); - } - } ); + if (offset != tileOffset(last_pt)) { + ensureTilesAround(offset); } + last_pt = pt; last_state = state.state; } + private AltosSiteMapTile createTile(final Point offset) { + final AltosSiteMapTile tile = new AltosSiteMapTile(px_size); + mapTiles.put(offset, tile); + return tile; + } + private void finishTileLater(final AltosSiteMapTile tile, + final Point offset) + { + SwingUtilities.invokeLater( new Runnable() { + public void run() { + addTileAt(tile, offset); + tile.setScrollable(); + } + } ); + } + + private void ensureTilesAround(Point base_offset) { + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + Point offset = new Point(base_offset.x + x, base_offset.y + y); + if (mapTiles.containsKey(offset)) + continue; + AltosSiteMapTile tile = createTile(offset); + initMap(tile, offset); + finishTileLater(tile, offset); + } + } + } + + private void addTileAt(AltosSiteMapTile tile, Point offset) { if (Math.abs(offset.x) >= MAX_TILE_DELTA || Math.abs(offset.y) >= MAX_TILE_DELTA) @@ -328,10 +356,11 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { - AltosSiteMapTile t = new AltosSiteMapTile(px_size); Point offset = new Point(x, y); + AltosSiteMapTile t = new AltosSiteMapTile(px_size); mapTiles.put(offset, t); addTileAt(t, offset); + t.setScrollable(); } } setViewportView(comp); diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index ea8c8bd9..e0942986 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -52,10 +52,17 @@ public class AltosSiteMapTile extends JLayeredPane { Color.BLACK // landed }; - boolean drawn_landed_circle = false; - boolean drawn_boost_circle = false; - public void show(AltosState state, int crc_errors, - Point2D.Double last_pt, Point2D.Double pt) + private boolean drawn_landed_circle = false; + private boolean drawn_boost_circle = false; + private boolean scrollable = false; + public synchronized void setScrollable() { + scrollable = true; + } + public synchronized boolean isScrollable() { + return scrollable; + } + public synchronized void show(AltosState state, int crc_errors, + Point2D.Double last_pt, Point2D.Double pt) { if (0 <= state.state && state.state < stateColors.length) { g2d.setColor(stateColors[state.state]); @@ -63,7 +70,7 @@ public class AltosSiteMapTile extends JLayeredPane { g2d.draw(new Line2D.Double(last_pt, pt)); int px_size = getWidth(); - if (0 <= pt.x && pt.x < px_size) { + if (isScrollable() && 0 <= pt.x && pt.x < px_size) { if (0 <= pt.y && pt.y < px_size) { int dx = 500, dy = 250; if (state.state > 2) { -- 2.30.2