X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosuilib%2FAltosUIMapPreloadNew.java;h=7cdba3824d6d3ec6889612f8ba95a0a6b947b6e4;hp=ba559534e3f8226826a8475a72f8f545a1bbf2e3;hb=2ec7e14f0104e3a227ff566fa2fc1f6286ddd9d0;hpb=643c2fb03833d658320f476ef731bbb06fe3cc31 diff --git a/altosuilib/AltosUIMapPreloadNew.java b/altosuilib/AltosUIMapPreloadNew.java index ba559534..7cdba382 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_10; 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_10.*; class AltosUIMapPos extends Box { AltosUIFrame owner; @@ -127,13 +127,10 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener 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]; @@ -141,6 +138,7 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener JComboBox min_zoom; JComboBox max_zoom; 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 }; @@ -149,14 +147,19 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener 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); @@ -169,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); @@ -178,18 +188,19 @@ 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) { - System.out.printf(format, arguments); + if (AltosSerial.debug) + System.out.printf(format, arguments); } @@ -217,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(); @@ -232,12 +246,17 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener Double r = (Double) radius.getSelectedItem(); if (AltosPreferences.imperial_units()) - r = AltosConvert.distance.inverse(r); + r = AltosConvert.miles_to_meters(r); else r = r * 1000; - loading = true; - loader.load(latitude, longitude, min_z, max_z, r, all_types()); + map.map.centre(new AltosLatLon(latitude, longitude)); + + loader = new AltosMapLoader(this, + latitude, longitude, + min_z, max_z, r, + all_types(), scale); + } catch (ParseException pe) { load_button.setSelected(false); } @@ -270,8 +289,6 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener map = new AltosUIMapNew(); - loader = new AltosMapLoader(map.map, this); - c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; c.insets = i;