+ LatLng line_start, line_end;
+
+ private void set_line() {
+ if (line_start != null && line_end != null) {
+ Point2D.Double start = pt(line_start.lat, line_start.lng);
+ Point2D.Double end = pt(line_end.lat, line_end.lng);
+ AltosGreatCircle g = new AltosGreatCircle(line_start.lat, line_start.lng,
+ line_end.lat, line_end.lng);
+
+ for (Point offset : mapTiles.keySet()) {
+ AltosSiteMapTile tile = mapTiles.get(offset);
+ Point2D.Double s, e;
+ s = translatePoint(start, tileCoordOffset(offset));
+ e = translatePoint(end, tileCoordOffset(offset));
+ tile.set_line(new Line2D.Double(s.x, s.y, e.x, e.y), g.distance);
+ }
+ } else {
+ for (AltosSiteMapTile tile : mapTiles.values())
+ tile.set_line(null, 0);
+ }
+ }
+
+ 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;
+
+ Rectangle zerozero = mapTiles.get(new Point(0, 0)).getBounds();
+
+ return latlng(-centre.x + e.getPoint().x - zerozero.x, -centre.y + e.getPoint().y - zerozero.y);
+ }
+
+ /* MouseMotionListener methods */
+ public void mouseDragged(MouseEvent e) {
+ if (!GrabNDrag.grab_n_drag(e)) {
+ LatLng loc = latlng(e);
+ line_end = loc;
+ set_line();
+ }
+ }
+
+ public void mouseMoved(MouseEvent e) {
+ }
+
+ /* MouseListener methods */
+ public void mouseClicked(MouseEvent e) {
+ }
+
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ public void mouseExited(MouseEvent e) {
+ }
+
+ public void mousePressed(MouseEvent e) {
+ if (!GrabNDrag.grab_n_drag(e)) {
+ LatLng loc = latlng(e);
+ line_start = loc;
+ line_end = null;
+ set_line();
+ }
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ }
+
+ private 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();
+ }
+