}
}
-public class AltosSiteMap extends JComponent implements AltosFlightDisplay, MouseMotionListener, MouseListener {
+public class AltosSiteMap extends JComponent implements AltosFlightDisplay, MouseMotionListener, MouseListener, HierarchyBoundsListener {
// preferred vertical step in a tile in naut. miles
// will actually choose a step size between x and 2x, where this
// is 1.5x
tile.set_status(AltosSiteMapCache.loading);
int status = AltosSiteMapCache.fetch_map(pngfile, pngurl);
if (status == AltosSiteMapCache.success) {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- tile.load_map(pngfile);
- }
- });
+ if (SwingUtilities.isEventDispatchThread())
+ tile.load_map(pngfile);
+ else {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ tile.load_map(pngfile);
+ }
+ });
+ }
} else {
tile.set_status(status);
System.out.printf("# Failed to fetch file %s (status %d)\n", pngfile, status);
Thread thread = new Thread() {
public void run() {
init_map(offset, load_mode_cached|load_mode_uncached);
- finishTileLater(tile, offset);
+ SwingUtilities.invokeLater( new Runnable() {
+ public void run() {
+ addTileAt(tile, offset);
+ }
+ } );
}
};
thread.start();
}
public void setBaseLocation(double lat, double lng) {
- for (AltosSiteMapTile tile : mapTiles.values())
- tile.clearMap();
this.lat = lat;
this.lon = lng;
base_location_set = true;
private void initMaps(double lat, double lng) {
setBaseLocation(lat, lng);
+ for (AltosSiteMapTile tile : mapTiles.values())
+ tile.clearMap();
Thread thread = new Thread() {
public void run() {
for (Point k : mapTiles.keySet())
JLabel zoom_label;
public void set_zoom_label() {
- zoom_label.setText(String.format("- %d -", zoom - default_zoom));
+ zoom_label.setText(String.format("Zoom %d", zoom - default_zoom));
}
public void set_zoom(int zoom) {
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);
- }
- } );
- }
private void ensureTilesAround(Point base_offset) {
for (int x = -radius; x <= radius; x++) {
}
}
+ static void debug_component(Component who, String where) {
+// Rectangle r = who.getBounds();
+// int x = r.x / px_size;
+// int y = r.y / px_size;
+//
+// System.out.printf ("%3d, %3d: %s\n", x, y, where);
+ }
+
LatLng latlng(MouseEvent e) {
if (!base_location_set)
return null;
public void mouseReleased(MouseEvent e) {
}
+ public void set_cache_size() {
+ Rectangle r = comp.getVisibleRect();
+
+ int width_tiles = (r.width + 2*px_size) / px_size;
+ int height_tiles = (r.height + 2*px_size) / px_size;
+ int tiles = width_tiles * height_tiles;
+ AltosSiteMapCache.set_cache_size(tiles);
+ }
+
+ /* HierarchyBoundsListener methods */
+ public void ancestorMoved(HierarchyEvent e) {
+ set_cache_size();
+ }
+
+ public void ancestorResized(HierarchyEvent e) {
+ set_cache_size();
+ }
+
JScrollPane pane = new JScrollPane();
public AltosSiteMap(int in_radius) {
comp.addMouseMotionListener(this);
comp.addMouseListener(this);
+ comp.addHierarchyBoundsListener(this);
GrabNDrag scroller = new GrabNDrag(comp);