diff options
| author | Anthony Towns <aj@erisian.com.au> | 2010-11-20 21:06:37 +1000 | 
|---|---|---|
| committer | Anthony Towns <aj@erisian.com.au> | 2010-11-20 21:06:37 +1000 | 
| commit | 58f8d069ce9488e2987b8e92caa69fe68cda7569 (patch) | |
| tree | 2c803b7a007f598fdfccfcfcaf5a3aaa61a980f9 /ao-tools | |
| parent | 74cab8503b51ba6fb05a4d12a031c749e870b0ef (diff) | |
AltosSiteMap: add autoscroll and grabndrag scroll
Diffstat (limited to 'ao-tools')
| -rw-r--r-- | ao-tools/altosui/AltosFlightUI.java | 4 | ||||
| -rw-r--r-- | ao-tools/altosui/AltosSiteMap.java | 38 | ||||
| -rw-r--r-- | ao-tools/altosui/AltosSiteMapTile.java | 32 | 
3 files changed, 61 insertions, 13 deletions
diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 6db6c67b..c85fc977 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -46,7 +46,6 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {  	private AltosFlightStatus flightStatus;  	private JScrollPane flightInfoPane; -	private JScrollPane sitemapPane;  	private AltosInfoTable flightInfo;  	static final int tab_pad = 1; @@ -192,8 +191,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {  		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; diff --git a/ao-tools/altosui/AltosSiteMap.java b/ao-tools/altosui/AltosSiteMap.java index df1cc246..1db83959 100644 --- a/ao-tools/altosui/AltosSiteMap.java +++ b/ao-tools/altosui/AltosSiteMap.java @@ -21,6 +21,7 @@ import java.awt.*;  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.*; @@ -31,7 +32,7 @@ import java.lang.Math;  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      } @@ -43,10 +44,40 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay {      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; @@ -56,8 +87,9 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay {              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);      }  } diff --git a/ao-tools/altosui/AltosSiteMapTile.java b/ao-tools/altosui/AltosSiteMapTile.java index c14fb93f..df57aa7d 100644 --- a/ao-tools/altosui/AltosSiteMapTile.java +++ b/ao-tools/altosui/AltosSiteMapTile.java @@ -65,21 +65,19 @@ public class AltosSiteMapTile extends JLabel {          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;      } @@ -167,8 +165,8 @@ public class AltosSiteMapTile extends JLabel {              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)) { @@ -185,6 +183,19 @@ public class AltosSiteMapTile extends JLabel {              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); @@ -198,6 +209,13 @@ public class AltosSiteMapTile extends JLabel {      }      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;      }  | 
