private AltosFlightStatus flightStatus;
private JScrollPane flightInfoPane;
- private JScrollPane sitemapPane;
private AltosInfoTable flightInfo;
static final int tab_pad = 1;
pane.add("Table", flightInfoPane);
sitemap = new AltosSiteMap();
- sitemapPane = new JScrollPane(sitemap);
- pane.add("Site Map", sitemapPane);
+ pane.add("Site Map", sitemap);
c.gridx = 0;
c.gridy = 2;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
+import javax.swing.event.MouseInputAdapter;
import javax.imageio.ImageIO;
import javax.swing.table.*;
import java.io.*;
import java.awt.geom.Point2D;
import java.awt.geom.Line2D;
-public class AltosSiteMap extends JComponent implements AltosFlightDisplay {
+public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay {
public void reset() {
// nothing
}
AltosSiteMapTile [] mapTiles = new AltosSiteMapTile[9];
+ class GrabNDrag extends MouseInputAdapter {
+ private JComponent scroll;
+ private Point startPt = new Point();
+
+ public GrabNDrag(JComponent parent) {
+ scroll = parent;
+ }
+
+ public void mousePressed(MouseEvent e) {
+ startPt.setLocation(e.getPoint());
+ }
+ public void mouseDragged(MouseEvent e) {
+ int xd = e.getX() - startPt.x;
+ int yd = e.getY() - startPt.y;
+
+ Rectangle r = scroll.getVisibleRect();
+ r.x -= xd;
+ r.y -= yd;
+ scroll.scrollRectToVisible(r);
+ }
+ }
+
public AltosSiteMap() {
+ JComponent comp = new JComponent() {
+ GrabNDrag scroller = new GrabNDrag(this);
+ {
+ addMouseMotionListener(scroller);
+ addMouseListener(scroller);
+ setAutoscrolls(true);
+ }
+ };
GridBagLayout layout = new GridBagLayout();
- setLayout(layout);
+ comp.setLayout(layout);
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.CENTER;
c.gridx = x % 3; c.gridy = x / 3;
mapTiles[x] = new AltosSiteMapTile((x%3)-1, (x/3)-1);
layout.setConstraints(mapTiles[x], c);
- add(mapTiles[x]);
+ comp.add(mapTiles[x]);
}
+ setViewportView(comp);
}
}
Point2D.Double map_latlng;
map_latlng = latlng(new Point2D.Double(px_size/2, px_size/2));
- BufferedImage myPicture;
File pngfile = new File(AltosPreferences.logdir(),
FileCoord(map_latlng, zoom));
try {
+ BufferedImage myPicture;
myPicture = ImageIO.read(pngfile);
+ setIcon(new ImageIcon( myPicture ));
System.out.printf("# Found file %s\n", pngfile);
+ g2d = myPicture.createGraphics();
} catch (Exception e) {
// throw new RuntimeException(e);
System.out.printf("# Failed to find file %s\n", pngfile);
System.out.printf(" wget -O '%s' 'http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32'\n", pngfile, map_latlng.x, map_latlng.y, zoom, px_size, px_size);
- myPicture = new BufferedImage(px_size, px_size,
- BufferedImage.TYPE_INT_RGB);
}
- setIcon(new ImageIcon( myPicture ));
- g2d = myPicture.createGraphics();
return true;
}
return;
if (!state.gps_ready && state.pad_lat == 0 && state.pad_lon == 0)
return;
- double plat = (int)(state.pad_lat*200)/200.0;
- double plon = (int)(state.pad_lon*200)/200.0;
+ double plat = state.pad_lat;
+ double plon = state.pad_lon;
if (last_pt == null) {
if (!setLocation(plat, plon)) {
g2d.draw(new Line2D.Double(last_pt, pt));
}
+ if (0 <= pt.x && pt.x < px_size) {
+ if (0 <= pt.y && pt.y < px_size) {
+ int dx = 500, dy = 250;
+ if (last_pt != null && state.state > 2) {
+ dx = Math.min(200, 20 + (int) Math.abs(last_pt.x - pt.x));
+ dy = Math.min(100, 10 + (int) Math.abs(last_pt.y - pt.y));
+ }
+ Rectangle r = new Rectangle((int)pt.x-dx, (int)pt.y-dy,
+ dx*2, dy*2);
+ scrollRectToVisible(r);
+ }
+ }
+
if (state.state == 8 && !drawn_landed_circle) {
drawn_landed_circle = true;
g2d.setColor(Color.RED);
}
public AltosSiteMapTile(int x_tile_offset, int y_tile_offset) {
+ BufferedImage myPicture = new BufferedImage(px_size, px_size,
+ BufferedImage.TYPE_INT_RGB);
+ setIcon(new ImageIcon( myPicture ));
+ g2d = myPicture.createGraphics();
+ g2d.setColor(Color.GRAY);
+ g2d.fillRect(0, 0, px_size, px_size);
+
off_x = x_tile_offset;
off_y = y_tile_offset;
}