altosuilib: Allow for no transform in map mouse wheel function
[fw/altos] / altosuilib / AltosUIMapNew.java
index 4191a562ffef8c7d0230179ff423c3258094c266..5f63a3c226f5871dfd8656a2d177052b695226b5 100644 (file)
@@ -140,17 +140,23 @@ public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, Alt
                        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));
+                       AltosLatLon     mouse_lat_lon = null;
+
+                       if (map.transform != null)
+                               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);
+                       if (mouse_lat_lon != null) {
+                               AltosPointDouble        new_mouse = map.transform.screen(mouse_lat_lon);
 
-                       int     dx = getWidth()/2 - e.getPoint().x;
-                       int     dy = getHeight()/2 - e.getPoint().y;
+                               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));
+                               AltosLatLon     new_centre = map.transform.screen_lat_lon(new AltosPointInt((int) new_mouse.x + dx, (int) new_mouse.y + dy));
 
-                       map.centre(new_centre);
+                               map.centre(new_centre);
+                       }
                }
 
                /* ComponentListener methods */
@@ -283,16 +289,16 @@ public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, Alt
                                if (t.has_location()) {
                                        String  message = null;
                                        switch (status) {
-                                       case AltosUIMapCache.loading:
+                                       case AltosMapTile.loading:
                                                message = "Loading...";
                                                break;
-                                       case AltosUIMapCache.bad_request:
+                                       case AltosMapTile.bad_request:
                                                message = "Internal error";
                                                break;
-                                       case AltosUIMapCache.failed:
+                                       case AltosMapTile.failed:
                                                message = "Network error, check connection";
                                                break;
-                                       case AltosUIMapCache.forbidden:
+                                       case AltosMapTile.forbidden:
                                                message = "Too many requests, try later";
                                                break;
                                        }
@@ -369,6 +375,10 @@ public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, Alt
                zoom_label.setText(label);
        }
 
+       public void debug(String format, Object ... arguments) {
+               System.out.printf(format, arguments);
+       }
+
        /* AltosFlightDisplay interface */
 
        public void set_font() {
@@ -419,15 +429,16 @@ public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, Alt
                return "Map";
        }
 
+       /* AltosGraphUI interface */
+       public void centre(AltosState state) {
+               map.centre(state);
+       }
+
        /* 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() {