altoslib: When flashing hardware, pull USB data from device if needed
[fw/altos] / altosuilib / AltosUIMapPreload.java
index 42fdd301b9d780853b339e5268105a6554de4f6c..ffd974acd16855aaa6f8386b70a25a81aae596a7 100644 (file)
@@ -3,7 +3,8 @@
  *
  * 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.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,7 +16,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altosuilib_11;
+package org.altusmetrum.altosuilib_13;
 
 import java.awt.*;
 import java.awt.event.*;
@@ -26,9 +27,10 @@ import java.text.*;
 import java.lang.Math;
 import java.net.URL;
 import java.net.URLConnection;
-import org.altusmetrum.altoslib_11.*;
+import org.altusmetrum.altoslib_13.*;
 
-class AltosUIMapPos extends Box {
+class AltosUIMapPos extends Box implements ActionListener {
+       AltosUIMapPreload       preload;
        AltosUIFrame    owner;
        JLabel          label;
        JComboBox       hemi;
@@ -37,6 +39,11 @@ class AltosUIMapPos extends Box {
        JTextField      min;
        JLabel          min_label;
 
+       /* ActionListener interface */
+       public void actionPerformed(ActionEvent e) {
+               preload.center_map();
+       }
+
        public void set_value(double new_value) {
                double  d, m;
                int     h;
@@ -88,19 +95,23 @@ class AltosUIMapPos extends Box {
        }
 
        public AltosUIMapPos(AltosUIFrame in_owner,
-                          String label_value,
-                          String[] hemi_names,
-                          double default_value) {
+                            AltosUIMapPreload preload,
+                            String label_value,
+                            String[] hemi_names,
+                            double default_value) {
                super(BoxLayout.X_AXIS);
                owner = in_owner;
+               this.preload = preload;
                label = new JLabel(label_value);
                hemi = new JComboBox<String>(hemi_names);
                hemi.setEditable(false);
                deg = new JTextField(5);
+               deg.addActionListener(this);
                deg.setMinimumSize(deg.getPreferredSize());
                deg.setHorizontalAlignment(JTextField.RIGHT);
                deg_label = new JLabel("°");
                min = new JTextField(9);
+               min.addActionListener(this);
                min.setMinimumSize(min.getPreferredSize());
                min_label = new JLabel("'");
                set_value(default_value);
@@ -133,7 +144,9 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I
        JToggleButton   load_button;
        JButton         close_button;
 
+/*
        JCheckBox[]     maptypes = new JCheckBox[AltosMap.maptype_terrain - AltosMap.maptype_hybrid + 1];
+*/
 
        JComboBox<Integer>      min_zoom;
        JComboBox<Integer>      max_zoom;
@@ -166,8 +179,6 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I
                                        pbar.setMaximum(max);
                                        pbar.setValue(0);
                                        pbar.setString("");
-                                       map.clear_marks();
-                                       map.add_mark(latitude, longitude, AltosLib.ao_flight_boost);
                                }
                        });
        }
@@ -206,11 +217,27 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I
 
 
        private int all_types() {
+/*
                int all_types = 0;
                for (int t = AltosMap.maptype_hybrid; t <= AltosMap.maptype_terrain; t++)
                        if (maptypes[t].isSelected())
                                all_types |= (1 << t);
                return all_types;
+*/
+               return 1 << AltosMap.maptype_hybrid;
+       }
+
+       void center_map(double latitude, double longitude) {
+               map.map.centre(new AltosLatLon(latitude, longitude));
+               map.clear_marks();
+               map.add_mark(latitude, longitude, AltosLib.ao_flight_boost);
+       }
+
+       void center_map() {
+               try {
+                       center_map(lat.get_value(), lon.get_value());
+               } catch (ParseException pe) {
+               }
        }
 
        public void itemStateChanged(ItemEvent e) {
@@ -222,6 +249,7 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I
                                AltosLaunchSite site = (AltosLaunchSite) o;
                                lat.set_value(site.latitude);
                                lon.set_value(site.longitude);
+                               center_map(site.latitude, site.longitude);
                        }
                }
        }
@@ -251,7 +279,7 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I
                                        else
                                                r = r * 1000;
 
-                                       map.map.centre(new AltosLatLon(latitude, longitude));
+                                       center_map(latitude, longitude);
 
                                        loader = new AltosMapLoader(this,
                                                                    latitude, longitude,
@@ -393,7 +421,7 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I
 
                pane.add(site_list, c);
 
-               lat = new AltosUIMapPos(owner,
+               lat = new AltosUIMapPos(owner, this,
                                        "Latitude:",
                                        lat_hemi_names,
                                        37.167833333);
@@ -410,7 +438,7 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I
 
                pane.add(lat, c);
 
-               lon = new AltosUIMapPos(owner,
+               lon = new AltosUIMapPos(owner, this,
                                        "Longitude:",
                                        lon_hemi_names,
                                        -97.73975);
@@ -462,6 +490,7 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I
 
                pane.add(close_button, c);
 
+/*
                JLabel  types_label = new JLabel("Map Types");
                c.gridx = 2;
                c.gridwidth = 2;
@@ -478,6 +507,7 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I
                        c.gridy = (type & 1) + 3;
                        pane.add(maptypes[type], c);
                }
+*/
 
                JLabel  min_zoom_label = new JLabel("Minimum Zoom");
                c.gridx = 4;