altoslib/altosuilib: Get new Map display code running in altosui and telegps
authorKeith Packard <keithp@keithp.com>
Tue, 26 May 2015 07:29:53 +0000 (00:29 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 26 May 2015 07:29:53 +0000 (00:29 -0700)
Looks like the display is all hooked up. Still need to replace the
preload UIs.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosMap.java
altoslib/AltosMapInterface.java
altoslib/AltosMapLine.java
altoslib/AltosMapMark.java
altoslib/AltosMapTile.java
altoslib/AltosMapTileListener.java
altosuilib/AltosUIMapNew.java [new file with mode: 0644]
telegps/TeleGPS.java

index 7c7c7305438fab7595be6af0caad31e98db38f38..b54c66cf7a9d44e8f496f90b89b71ed3ef114f1b 100644 (file)
@@ -22,7 +22,7 @@ import java.lang.*;
 import java.util.*;
 import java.util.concurrent.*;
 
-public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, AltosMapStoreListener {
+public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
 
        public static final int px_size = 512;
 
@@ -54,18 +54,12 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos
 
        AltosMapCache           cache;
 
-       LinkedList<AltosMapMark> marks = new LinkedList<AltosMapMark>();
-
-       LinkedList<AltosMapZoomListener> zoom_listeners = new LinkedList<AltosMapZoomListener>();
+       public AltosMapCache cache() { return cache; }
 
-       public void add_zoom_listener(AltosMapZoomListener listener) {
-               if (!zoom_listeners.contains(listener))
-                       zoom_listeners.add(listener);
-       }
+       LinkedList<AltosMapMark> marks = new LinkedList<AltosMapMark>();
 
-       public void remove_zoom_listener(AltosMapZoomListener listener) {
-               zoom_listeners.remove(listener);
-       }
+       AltosMapPath    path;
+       AltosMapLine    line;
 
        boolean         have_boost = false;
        boolean         have_landed = false;
@@ -84,7 +78,7 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos
         */
        static final long auto_scroll_delay = 20 * 1000;
 
-       AltosMapTransform       transform;
+       public AltosMapTransform        transform;
        AltosLatLon             centre;
 
        public void reset() {
@@ -92,16 +86,14 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos
        }
 
        /* MapInterface wrapping functions */
-       public void set_units() {
-               map_interface.set_units();
-       }
 
-       public void repaint(AltosMapRectangle damage, int pad) {
-               map_interface.repaint(damage, pad);
+       public void repaint(int x, int y, int w, int h) {
+               map_interface.repaint(new AltosRectangle(x, y, w, h));
        }
 
-       public void repaint(double x, double y, double w, double h) {
-               map_interface.repaint(x, y, w, h);
+       public void repaint(AltosMapRectangle damage, int pad) {
+               AltosRectangle r = transform.screen(damage);
+               repaint(r.x - pad, r.y - pad, r.width + pad * 2, r.height + pad * 2);
        }
 
        public void repaint() {
@@ -156,30 +148,22 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos
                return false;
        }
 
-       public void font_size_changed(int font_size) {
-               map_interface.line().font_size_changed(font_size);
-               for (AltosMapTile tile : tiles.values())
-                       tile.font_size_changed(font_size);
+       public void set_transform() {
+               transform = new AltosMapTransform(width(), height(), zoom, centre);
                repaint();
        }
 
-       public void units_changed(boolean imperial_units) {
+       private void set_zoom_label() {
+               map_interface.set_zoom_label(String.format("Zoom %d", get_zoom() - default_zoom));
        }
 
-       private void set_transform() {
-               transform = new AltosMapTransform(width(), height(), zoom, centre);
-               repaint();
-       }
 
        public boolean set_zoom(int zoom) {
                if (AltosMap.min_zoom <= zoom && zoom <= AltosMap.max_zoom && zoom != this.zoom) {
                        this.zoom = zoom;
                        tiles.clear();
                        set_transform();
-
-                       for (AltosMapZoomListener listener : zoom_listeners)
-                               listener.zoom_changed(this.zoom);
-
+                       set_zoom_label();
                        return true;
                }
                return false;
@@ -211,7 +195,7 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos
                if (!gps.locked && gps.nsat < 4)
                        return;
 
-               AltosMapRectangle       damage = map_interface.path().add(gps.lat, gps.lon, state.state);
+               AltosMapRectangle       damage = path.add(gps.lat, gps.lon, state.state);
 
                switch (state.state) {
                case AltosLib.ao_flight_boost:
@@ -339,9 +323,9 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos
                                mark.paint(transform);
                }
 
-               map_interface.path().paint(transform);
+               path.paint(transform);
 
-               map_interface.line().paint(transform);
+               line.paint(transform);
        }
 
        /* AltosMapTileListener methods */
@@ -363,9 +347,58 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos
                }
        }
 
+       /* UI elements */
+
+       AltosPointInt   drag_start;
+
+       private void drag(int x, int y) {
+               if (drag_start == null)
+                       return;
+
+               int dx = x - drag_start.x;
+               int dy = y - drag_start.y;
+
+               AltosLatLon new_centre = transform.screen_lat_lon(new AltosPointInt(width() / 2 - dx, height() / 2 - dy));
+               centre(new_centre);
+               drag_start = new AltosPointInt(x, y);
+       }
+
+       private void drag_start(int x, int y) {
+               drag_start = new AltosPointInt(x, y);
+       }
+
+       private void line_start(int x, int y) {
+               line.pressed(new AltosPointInt(x, y), transform);
+               repaint();
+       }
+
+       private void line(int x, int y) {
+               line.dragged(new AltosPointInt(x, y), transform);
+               repaint();
+       }
+
+       public void touch_start(int x, int y, boolean is_drag) {
+               notice_user_input();
+               if (is_drag)
+                       drag_start(x, y);
+               else
+                       line_start(x, y);
+       }
+
+       public void touch_continue(int x, int y, boolean is_drag) {
+               notice_user_input();
+               if (is_drag)
+                       drag(x, y);
+               else
+                       line(x, y);
+       }
+
        public AltosMap(AltosMapInterface map_interface) {
                this.map_interface = map_interface;
                cache = new AltosMapCache(map_interface);
+               line = map_interface.new_line();
+               path = map_interface.new_path();
+               set_zoom_label();
                centre(0, 0);
        }
 }
index 0dcd646e37428ea2f29f71b4a793f2a94b677d46..195574e9b7950fb15f1eccaec7a678291ca874c4 100644 (file)
@@ -21,8 +21,9 @@ import java.io.*;
 import java.net.*;
 
 public interface AltosMapInterface {
-       public abstract AltosMapPath path();
-       public abstract AltosMapLine line();
+       public abstract AltosMapPath new_path();
+
+       public abstract AltosMapLine new_line();
 
        public abstract AltosImage load_image(File file) throws Exception;
 
@@ -36,9 +37,7 @@ public interface AltosMapInterface {
 
        public abstract void repaint();
 
-       public abstract void repaint(AltosMapRectangle damage, int pad);
-
-       public abstract void repaint(double x, double y, double w, double h);
+       public abstract void repaint(AltosRectangle damage);
 
-       public abstract void set_units();
+       public abstract void set_zoom_label(String label);
 }
index e727e3389d2c35ff4c33a4d283310451fda164a3..23a6f889dca74cef4e5e572fc9753a4b7a7a0c97 100644 (file)
@@ -22,13 +22,11 @@ import java.lang.Math;
 import java.util.*;
 import java.util.concurrent.*;
 
-public abstract class AltosMapLine implements AltosFontListener {
+public abstract class AltosMapLine {
        public AltosLatLon      start, end;
 
        static public int stroke_width = 6;
 
-       public abstract void font_size_changed(int font_size);
-
        public abstract void paint(AltosMapTransform t);
 
        private AltosLatLon lat_lon(AltosPointInt pt, AltosMapTransform t) {
index 5eb1907b2e1755ff64b299d2e4c09aac893fb998..74e6790f682b16c0c3096d19cb38aec884e34198 100644 (file)
@@ -24,8 +24,8 @@ import java.util.concurrent.*;
 
 public abstract class AltosMapMark {
 
-       AltosLatLon     lat_lon;
-       int             state;
+       public AltosLatLon      lat_lon;
+       public int              state;
 
        static public int stroke_width = 6;
 
index e61746f8bf0b14c240ab9d8a47b6d65285f25244..165f9e6f96827b7e139da1debc3f39b3b8650c42 100644 (file)
@@ -99,6 +99,7 @@ public abstract class AltosMapTile implements AltosFontListener {
        public AltosMapTile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) {
                this.listener = listener;
                this.upper_left = upper_left;
+               this.cache = listener.cache();
 
                while (center.lon < -180.0)
                        center.lon += 360.0;
index 60d92c7560204411f9ab167168cf2db4e9254c60..ed47e833f69e0d3659d240c721f00a36deb21b02 100644 (file)
@@ -19,4 +19,6 @@ package org.altusmetrum.altoslib_7;
 
 public interface AltosMapTileListener {
        abstract public void notify_tile(AltosMapTile tile, int status);
+
+       abstract public AltosMapCache cache();
 }
diff --git a/altosuilib/AltosUIMapNew.java b/altosuilib/AltosUIMapNew.java
new file mode 100644 (file)
index 0000000..4191a56
--- /dev/null
@@ -0,0 +1,539 @@
+/*
+ * Copyright © 2010 Anthony Towns <aj@erisian.com.au>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.altosuilib_7;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.image.*;
+import javax.swing.*;
+import java.io.*;
+import java.lang.Math;
+import java.awt.geom.*;
+import java.util.*;
+import java.util.concurrent.*;
+import javax.imageio.*;
+import org.altusmetrum.altoslib_7.*;
+
+public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, AltosMapInterface {
+
+       AltosMap        map;
+       Graphics2D      g;
+       Font            tile_font;
+       Font            line_font;
+
+       static Point2D.Double point2d(AltosPointDouble pt) {
+               return new Point2D.Double(pt.x, pt.y);
+       }
+
+       static final AltosPointDouble point_double(Point pt) {
+               return new AltosPointDouble(pt.x, pt.y);
+       }
+
+       class MapMark extends AltosMapMark {
+               public void paint(AltosMapTransform t) {
+                       AltosPointDouble pt = t.screen(lat_lon);
+
+                       g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                                          RenderingHints.VALUE_ANTIALIAS_ON);
+                       g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+
+                       if (0 <= state && state < AltosUIMapNew.stateColors.length)
+                               g.setColor(AltosUIMapNew.stateColors[state]);
+                       else
+                               g.setColor(AltosUIMapNew.stateColors[AltosLib.ao_flight_invalid]);
+
+                       g.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10);
+                       g.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40);
+                       g.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70);
+               }
+
+               MapMark(double lat, double lon, int state) {
+                       super(lat, lon, state);
+               }
+       }
+
+       class MapView extends JComponent implements MouseMotionListener, MouseListener, ComponentListener, MouseWheelListener {
+
+               private VolatileImage create_back_buffer() {
+                       return getGraphicsConfiguration().createCompatibleVolatileImage(getWidth(), getHeight());
+               }
+
+               private void do_paint(Graphics my_g) {
+                       g = (Graphics2D) my_g;
+
+                       map.paint();
+               }
+
+               public void paint(Graphics my_g) {
+                       VolatileImage   back_buffer = create_back_buffer();
+
+                       Graphics2D      top_g = (Graphics2D) my_g;
+
+                       do {
+                               GraphicsConfiguration gc = getGraphicsConfiguration();
+                               int code = back_buffer.validate(gc);
+                               if (code == VolatileImage.IMAGE_INCOMPATIBLE)
+                                       back_buffer = create_back_buffer();
+
+                               Graphics g_back = back_buffer.getGraphics();
+                               g_back.setClip(top_g.getClip());
+                               do_paint(g_back);
+                               g_back.dispose();
+
+                               top_g.drawImage(back_buffer, 0, 0, this);
+                       } while (back_buffer.contentsLost());
+                       back_buffer.flush();
+               }
+
+               public void repaint(AltosRectangle damage) {
+                       repaint(damage.x, damage.y, damage.width, damage.height);
+               }
+
+               private boolean is_drag_event(MouseEvent e) {
+                       return e.getModifiers() == InputEvent.BUTTON1_MASK;
+               }
+
+               /* MouseMotionListener methods */
+
+               public void mouseDragged(MouseEvent e) {
+                       map.touch_continue(e.getPoint().x, e.getPoint().y, is_drag_event(e));
+               }
+
+               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) {
+                       map.touch_start(e.getPoint().x, e.getPoint().y, is_drag_event(e));
+               }
+
+               public void mouseReleased(MouseEvent e) {
+               }
+
+               /* MouseWheelListener methods */
+
+               public void mouseWheelMoved(MouseWheelEvent e) {
+                       int     zoom_change = e.getWheelRotation();
+
+                       map.notice_user_input();
+                       AltosLatLon     mouse_lat_lon = map.transform.screen_lat_lon(new AltosPointInt(e.getPoint().x, e.getPoint().y));
+                       map.set_zoom(map.get_zoom() - zoom_change);
+
+                       AltosPointDouble        new_mouse = map.transform.screen(mouse_lat_lon);
+
+                       int     dx = getWidth()/2 - e.getPoint().x;
+                       int     dy = getHeight()/2 - e.getPoint().y;
+
+                       AltosLatLon     new_centre = map.transform.screen_lat_lon(new AltosPointInt((int) new_mouse.x + dx, (int) new_mouse.y + dy));
+
+                       map.centre(new_centre);
+               }
+
+               /* ComponentListener methods */
+
+               public void componentHidden(ComponentEvent e) {
+               }
+
+               public void componentMoved(ComponentEvent e) {
+               }
+
+               public void componentResized(ComponentEvent e) {
+                       map.set_transform();
+               }
+
+               public void componentShown(ComponentEvent e) {
+                       map.set_transform();
+               }
+
+               MapView() {
+                       addComponentListener(this);
+                       addMouseMotionListener(this);
+                       addMouseListener(this);
+                       addMouseWheelListener(this);
+               }
+       }
+
+       class MapLine extends AltosMapLine {
+
+               public void paint(AltosMapTransform t) {
+
+                       if (start == null || end == null)
+                               return;
+
+                       g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+
+                       Line2D.Double line = new Line2D.Double(point2d(t.screen(start)),
+                                                              point2d(t.screen(end)));
+
+                       g.setColor(Color.WHITE);
+                       g.setStroke(new BasicStroke(stroke_width+4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+                       g.draw(line);
+
+                       g.setColor(Color.BLUE);
+                       g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+                       g.draw(line);
+
+                       String  message = line_dist();
+                       Rectangle2D     bounds;
+                       bounds = line_font.getStringBounds(message, g.getFontRenderContext());
+
+                       float x = (float) line.x1;
+                       float y = (float) line.y1 + (float) bounds.getHeight() / 2.0f;
+
+                       if (line.x1 < line.x2) {
+                               x -= (float) bounds.getWidth() + 2.0f;
+                       } else {
+                               x += 2.0f;
+                       }
+
+                       g.setFont(line_font);
+                       g.setColor(Color.WHITE);
+                       for (int dy = -2; dy <= 2; dy += 2)
+                               for (int dx = -2; dx <= 2; dx += 2)
+                                       g.drawString(message, x + dx, y + dy);
+                       g.setColor(Color.BLUE);
+                       g.drawString(message, x, y);
+               }
+
+               public MapLine() {
+               }
+       }
+
+       class MapPath extends AltosMapPath {
+               public void paint(AltosMapTransform t) {
+                       Point2D.Double  prev = null;
+
+                       g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                                          RenderingHints.VALUE_ANTIALIAS_ON);
+                       g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+
+                       for (AltosMapPathPoint point : points) {
+                               Point2D.Double  cur = point2d(t.screen(point.lat_lon));
+                               if (prev != null) {
+                                       Line2D.Double   line = new Line2D.Double (prev, cur);
+                                       Rectangle       bounds = line.getBounds();
+
+                                       if (g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height)) {
+                                               if (0 <= point.state && point.state < AltosUIMapNew.stateColors.length)
+                                                       g.setColor(AltosUIMapNew.stateColors[point.state]);
+                                               else
+                                                       g.setColor(AltosUIMapNew.stateColors[AltosLib.ao_flight_invalid]);
+
+                                               g.draw(line);
+                                       }
+                               }
+                               prev = cur;
+                       }
+               }
+       }
+
+       class MapTile extends AltosMapTile {
+               public MapTile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) {
+                       super(listener, upper_left, center, zoom, maptype, px_size);
+               }
+
+               public void paint(AltosMapTransform t) {
+
+                       AltosPointDouble        point_double = t.screen(upper_left);
+                       Point                   point = new Point((int) (point_double.x + 0.5),
+                                                                 (int) (point_double.y + 0.5));
+
+                       if (!g.hitClip(point.x, point.y, px_size, px_size))
+                               return;
+
+                       AltosImage altos_image = cache.get(this, store, px_size, px_size);
+
+                       AltosUIImage    ui_image = (AltosUIImage) altos_image;
+
+                       Image image = null;
+
+                       if (ui_image != null)
+                               image = ui_image.image;
+
+                       if (image != null) {
+                               g.drawImage(image, point.x, point.y, null);
+                       } else {
+                               g.setColor(Color.GRAY);
+                               g.fillRect(point.x, point.y, px_size, px_size);
+
+                               if (t.has_location()) {
+                                       String  message = null;
+                                       switch (status) {
+                                       case AltosUIMapCache.loading:
+                                               message = "Loading...";
+                                               break;
+                                       case AltosUIMapCache.bad_request:
+                                               message = "Internal error";
+                                               break;
+                                       case AltosUIMapCache.failed:
+                                               message = "Network error, check connection";
+                                               break;
+                                       case AltosUIMapCache.forbidden:
+                                               message = "Too many requests, try later";
+                                               break;
+                                       }
+                                       if (message != null && tile_font != null) {
+                                               g.setFont(tile_font);
+                                               g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+                                               Rectangle2D bounds = tile_font.getStringBounds(message, g.getFontRenderContext());
+
+                                               float x = px_size / 2.0f;
+                                               float y = px_size / 2.0f;
+                                               x = x - (float) bounds.getWidth() / 2.0f;
+                                               y = y + (float) bounds.getHeight() / 2.0f;
+                                               g.setColor(Color.BLACK);
+                                               g.drawString(message, (float) point_double.x + x, (float) point_double.y + y);
+                                       }
+                               }
+                       }
+               }
+       }
+
+       public static final Color stateColors[] = {
+               Color.WHITE,  // startup
+               Color.WHITE,  // idle
+               Color.WHITE,  // pad
+               Color.RED,    // boost
+               Color.PINK,   // fast
+               Color.YELLOW, // coast
+               Color.CYAN,   // drogue
+               Color.BLUE,   // main
+               Color.BLACK,  // landed
+               Color.BLACK,  // invalid
+               Color.CYAN,   // stateless
+       };
+
+       /* AltosMapInterface functions */
+
+       public AltosMapPath new_path() {
+               return new MapPath();
+       }
+
+       public AltosMapLine new_line() {
+               return new MapLine();
+       }
+
+       public AltosImage load_image(File file) throws Exception {
+               return new AltosUIImage(ImageIO.read(file));
+       }
+
+       public AltosMapMark new_mark(double lat, double lon, int state) {
+               return new MapMark(lat, lon, state);
+       }
+
+       public AltosMapTile new_tile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) {
+               return new MapTile(listener, upper_left, center, zoom, maptype, px_size);
+       }
+
+       public int width() {
+               return view.getWidth();
+       }
+
+       public int height() {
+               return view.getHeight();
+       }
+
+       public void repaint() {
+               view.repaint();
+       }
+
+       public void repaint(AltosRectangle damage) {
+               view.repaint(damage);
+       }
+
+       public void set_zoom_label(String label) {
+               zoom_label.setText(label);
+       }
+
+       /* AltosFlightDisplay interface */
+
+       public void set_font() {
+               tile_font = AltosUILib.value_font;
+               line_font = AltosUILib.status_font;
+       }
+
+       public void font_size_changed(int font_size) {
+               set_font();
+               repaint();
+       }
+
+       public void units_changed(boolean imperial_units) {
+               repaint();
+       }
+
+       JLabel  zoom_label;
+
+       public void set_maptype(int type) {
+               map.set_maptype(type);
+               maptype_combo.setSelectedIndex(type);
+       }
+
+       /* AltosUIMapPreload functions */
+
+       public void set_zoom(int zoom) {
+               map.set_zoom(zoom);
+       }
+
+       public void add_mark(double lat, double lon, int status) {
+               map.add_mark(lat, lon, status);
+       }
+
+       public void clear_marks() {
+               map.clear_marks();
+       }
+
+       /* AltosFlightDisplay interface */
+       public void reset() {
+               // nothing
+       }
+
+       public void show(AltosState state, AltosListenerState listener_state) {
+               map.show(state, listener_state);
+       }
+
+       public String getName() {
+               return "Map";
+       }
+
+       /* internal layout bits */
+       private GridBagLayout layout = new GridBagLayout();
+
+       JComboBox<String>       maptype_combo;
+
+       public void set_load_params(double lat, double lon, int radius, AltosMapTileListener listener) {
+               map.set_load_params(lat, lon, radius, listener);
+       }
+
+       MapView view;
+
+       public AltosUIMapNew() {
+
+               set_font();
+
+               view = new MapView();
+
+               view.setPreferredSize(new Dimension(500,500));
+               view.setVisible(true);
+               view.setEnabled(true);
+
+               GridBagLayout   my_layout = new GridBagLayout();
+
+               setLayout(my_layout);
+
+               GridBagConstraints c = new GridBagConstraints();
+               c.anchor = GridBagConstraints.CENTER;
+               c.fill = GridBagConstraints.BOTH;
+               c.gridx = 0;
+               c.gridy = 0;
+               c.gridwidth = 1;
+               c.gridheight = 10;
+               c.weightx = 1;
+               c.weighty = 1;
+               add(view, c);
+
+               int     y = 0;
+
+               zoom_label = new JLabel("", JLabel.CENTER);
+
+               c = new GridBagConstraints();
+               c.anchor = GridBagConstraints.CENTER;
+               c.fill = GridBagConstraints.HORIZONTAL;
+               c.gridx = 1;
+               c.gridy = y++;
+               c.weightx = 0;
+               c.weighty = 0;
+               add(zoom_label, c);
+
+               JButton zoom_reset = new JButton("0");
+               zoom_reset.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       map.set_zoom(map.default_zoom);
+                               }
+                       });
+
+               c = new GridBagConstraints();
+               c.anchor = GridBagConstraints.CENTER;
+               c.fill = GridBagConstraints.HORIZONTAL;
+               c.gridx = 1;
+               c.gridy = y++;
+               c.weightx = 0;
+               c.weighty = 0;
+               add(zoom_reset, c);
+
+               JButton zoom_in = new JButton("+");
+               zoom_in.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       map.set_zoom(map.get_zoom() + 1);
+                               }
+                       });
+
+               c = new GridBagConstraints();
+               c.anchor = GridBagConstraints.CENTER;
+               c.fill = GridBagConstraints.HORIZONTAL;
+               c.gridx = 1;
+               c.gridy = y++;
+               c.weightx = 0;
+               c.weighty = 0;
+               add(zoom_in, c);
+
+               JButton zoom_out = new JButton("-");
+               zoom_out.addActionListener(new ActionListener() {
+                               public void actionPerformed(ActionEvent e) {
+                                       map.set_zoom(map.get_zoom() - 1);
+                               }
+                       });
+               c = new GridBagConstraints();
+               c.anchor = GridBagConstraints.CENTER;
+               c.fill = GridBagConstraints.HORIZONTAL;
+               c.gridx = 1;
+               c.gridy = y++;
+               c.weightx = 0;
+               c.weighty = 0;
+               add(zoom_out, c);
+
+               maptype_combo = new JComboBox<String>(map.maptype_labels);
+
+               maptype_combo.setEditable(false);
+               maptype_combo.setMaximumRowCount(maptype_combo.getItemCount());
+               maptype_combo.addItemListener(new ItemListener() {
+                               public void itemStateChanged(ItemEvent e) {
+                                       map.set_maptype(maptype_combo.getSelectedIndex());
+                               }
+                       });
+
+               c = new GridBagConstraints();
+               c.anchor = GridBagConstraints.CENTER;
+               c.fill = GridBagConstraints.HORIZONTAL;
+               c.gridx = 1;
+               c.gridy = y++;
+               c.weightx = 0;
+               c.weighty = 0;
+               add(maptype_combo, c);
+
+               map = new AltosMap(this);
+       }
+}
index 8ff5ac2847eb580cae6f3861b3a3962dbd03ab25..1e1349009fd260120231ed2248d65d1424cb21cd 100644 (file)
@@ -71,7 +71,7 @@ public class TeleGPS
 
        JTabbedPane             pane;
 
-       AltosUIMap              map;
+       AltosUIMapNew           map;
        TeleGPSInfo             gps_info;
        TeleGPSState            gps_state;
        AltosInfoTable          info_table;
@@ -542,7 +542,7 @@ public class TeleGPS
                c.gridwidth = 2;
                bag.add(pane, c);
 
-               map = new AltosUIMap();
+               map = new AltosUIMapNew();
                pane.add(map.getName(), map);
                displays.add(map);