X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosuilib%2FAltosUIMapPreloadNew.java;h=b16659da5b79f6fb1854dde89cef1d50cec503ab;hb=97adfff4cfb67c17a96f3ff46606b4e439422b01;hp=20cb3888f611e3b7b92e810fd12f732da1d0cc8c;hpb=b49b74847ad55e14d1dbf2872ebbe313147e9fd3;p=fw%2Faltos diff --git a/altosuilib/AltosUIMapPreloadNew.java b/altosuilib/AltosUIMapPreloadNew.java index 20cb3888..b16659da 100644 --- a/altosuilib/AltosUIMapPreloadNew.java +++ b/altosuilib/AltosUIMapPreloadNew.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib_7; +package org.altusmetrum.altosuilib_11; import java.awt.*; import java.awt.event.*; @@ -26,7 +26,7 @@ import java.text.*; import java.lang.Math; import java.net.URL; import java.net.URLConnection; -import org.altusmetrum.altoslib_7.*; +import org.altusmetrum.altoslib_11.*; class AltosUIMapPos extends Box { AltosUIFrame owner; @@ -121,38 +121,45 @@ class AltosUIMapPos extends Box { public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener, ItemListener, AltosLaunchSiteListener, AltosMapLoaderListener { AltosUIFrame owner; AltosUIMapNew map; - AltosMapCache cache; AltosUIMapPos lat; AltosUIMapPos lon; JProgressBar pbar; - AltosMapLoader loader; - JLabel site_list_label; JComboBox site_list; JToggleButton load_button; - boolean loading; JButton close_button; JCheckBox[] maptypes = new JCheckBox[AltosMap.maptype_terrain - AltosMap.maptype_hybrid + 1]; JComboBox min_zoom; JComboBox max_zoom; - JComboBox radius; + JComboBox radius; + int scale = 1; Integer[] zooms = { -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6 }; - Integer[] radii = { 1, 2, 3, 4, 5 }; + + Double[] radius_mi = { 1.0, 2.0, 5.0, 10.0, 20.0 }; + Double radius_def_mi = 5.0; + Double[] radius_km = { 2.0, 5.0, 10.0, 20.0, 30.0 }; + Double radius_def_km = 10.0; + + AltosMapLoader loader; static final String[] lat_hemi_names = { "N", "S" }; static final String[] lon_hemi_names = { "E", "W" }; double latitude, longitude; + long loader_notify_time; + /* AltosMapLoaderListener interfaces */ public void loader_start(final int max) { + loader_notify_time = System.currentTimeMillis(); + SwingUtilities.invokeLater(new Runnable() { public void run() { pbar.setMaximum(max); @@ -165,6 +172,13 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener } public void loader_notify(final int cur, final int max, final String name) { + long now = System.currentTimeMillis(); + + if (now - loader_notify_time < 100) + return; + + loader_notify_time = now; + SwingUtilities.invokeLater(new Runnable() { public void run() { pbar.setValue(cur); @@ -174,16 +188,22 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener } public void loader_done(int max) { + loader = null; SwingUtilities.invokeLater(new Runnable() { public void run() { pbar.setValue(0); pbar.setString(""); load_button.setSelected(false); - loading = false; } }); } + public void debug(String format, Object ... arguments) { + if (AltosSerial.debug) + System.out.printf(format, arguments); + } + + private int all_types() { int all_types = 0; for (int t = AltosMap.maptype_hybrid; t <= AltosMap.maptype_terrain; t++) @@ -208,11 +228,14 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); - if (cmd.equals("close")) + if (cmd.equals("close")) { + if (loader != null) + loader.abort(); setVisible(false); + } if (cmd.equals("load")) { - if (!loading) { + if (loader == null) { try { latitude = lat.get_value(); longitude = lon.get_value(); @@ -220,10 +243,20 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener int max_z = (Integer) max_zoom.getSelectedItem(); if (max_z < min_z) max_z = min_z; - int r = (Integer) radius.getSelectedItem(); - loading = true; + Double r = (Double) radius.getSelectedItem(); + + if (AltosPreferences.imperial_units()) + r = AltosConvert.miles_to_meters(r); + else + r = r * 1000; + + map.map.centre(new AltosLatLon(latitude, longitude)); + + loader = new AltosMapLoader(this, + latitude, longitude, + min_z, max_z, r, + all_types(), scale); - loader.load(latitude, longitude, min_z, max_z, r, all_types()); } catch (ParseException pe) { load_button.setSelected(false); } @@ -255,9 +288,6 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener pane.setLayout(new GridBagLayout()); map = new AltosUIMapNew(); - cache = new AltosMapCache(map); - - loader = new AltosMapLoader(map.map, cache, this); c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; @@ -432,13 +462,21 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener c.gridy = 3; pane.add(max_zoom, c); - JLabel radius_label = new JLabel("Tile Radius"); + JLabel radius_label = new JLabel(String.format("Map Radius (%s)", + AltosPreferences.imperial_units() ? "miles" : "km")); c.gridx = 4; c.gridy = 4; pane.add(radius_label, c); - radius = new JComboBox(radii); - radius.setSelectedItem(radii[4]); + Double[] radii; + Double radius_default; + + if (AltosPreferences.imperial_units()) + radii = radius_mi; + else + radii = radius_km; + radius = new JComboBox(radii); + radius.setSelectedItem(radii[2]); radius.setEditable(true); c.gridx = 5; c.gridy = 4;