X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosuilib%2FAltosUIMapPreloadNew.java;h=3e4a604fa80cd6356bb25a0b37cb6a25831aebaf;hp=a7d1273763cf1f8ea65e9265d5457a93e761adb9;hb=c5f49d0ac254047f13c6c1ecfb5520eff72109ac;hpb=ccba2bb2f193ffd6c3a3d934a46bc06466b4b258 diff --git a/altosuilib/AltosUIMapPreloadNew.java b/altosuilib/AltosUIMapPreloadNew.java index a7d12737..3e4a604f 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; @@ -118,155 +118,99 @@ class AltosUIMapPos extends Box { } } -public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener, ItemListener, AltosMapTileListener, AltosLaunchSiteListener { +public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener, ItemListener, AltosLaunchSiteListener, AltosMapLoaderListener { AltosUIFrame owner; AltosUIMapNew map; - AltosMapCache cache; AltosUIMapPos lat; AltosUIMapPos lon; JProgressBar pbar; - int pbar_max; - int pbar_cur; 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; 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" }; - class updatePbar implements Runnable { - String s; + double latitude, longitude; - public updatePbar(String in_s) { - s = in_s; - } + long loader_notify_time; - public void run() { - int n = ++pbar_cur; + /* AltosMapLoaderListener interfaces */ + public void loader_start(final int max) { + loader_notify_time = System.currentTimeMillis(); - pbar.setMaximum(pbar_max); - pbar.setValue(n); - pbar.setString(s); - } + SwingUtilities.invokeLater(new Runnable() { + public void run() { + pbar.setMaximum(max); + pbar.setValue(0); + pbar.setString(""); + map.clear_marks(); + map.add_mark(latitude, longitude, AltosLib.ao_flight_boost); + } + }); } - double latitude, longitude; - int min_z; - int max_z; - int cur_z; - int all_types; - int cur_type; - int r; - - int tiles_per_layer; - int tiles_loaded; - int layers_total; - int layers_loaded; - - - private void do_load() { - tiles_loaded = 0; - map.set_zoom(cur_z + AltosMap.default_zoom); - map.set_maptype(cur_type); - map.set_load_params(latitude, longitude, r, this); - } + public void loader_notify(final int cur, final int max, final String name) { + long now = System.currentTimeMillis(); - private int next_type(int start) { - int next_type; - for (next_type = start; - next_type <= AltosMap.maptype_terrain && (all_types & (1 << next_type)) == 0; - next_type++) - ; - return next_type; - } + if (now - loader_notify_time < 100) + return; - private void next_load() { - int next_type = next_type(cur_type + 1); + loader_notify_time = now; - if (next_type > AltosMap.maptype_terrain) { - if (cur_z == max_z) { - return; - } else { - cur_z++; - } - next_type = next_type(0); - } - cur_type = next_type; - do_load(); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + pbar.setValue(cur); + pbar.setString(name); + } + }); } - private void start_load() { - cur_z = min_z; - int ntype = 0; - all_types = 0; - for (int t = AltosMap.maptype_hybrid; t <= AltosMap.maptype_terrain; t++) - if (maptypes[t].isSelected()) { - all_types |= (1 << t); - ntype++; - } - if (ntype == 0) { - all_types |= (1 << AltosMap.maptype_hybrid); - ntype = 1; - } - - cur_type = next_type(0); - tiles_per_layer = (r * 2 + 1) * (r * 2 + 1); - layers_total = (max_z - min_z + 1) * ntype; - layers_loaded = 0; - pbar_max = layers_total * tiles_per_layer; - pbar_cur = 0; - - map.clear_marks(); - map.add_mark(latitude,longitude, AltosLib.ao_flight_boost); - do_load(); + public void loader_done(int max) { + loader = null; + SwingUtilities.invokeLater(new Runnable() { + public void run() { + pbar.setValue(0); + pbar.setString(""); + load_button.setSelected(false); + } + }); } - /* AltosMapTileListener methods */ + public void debug(String format, Object ... arguments) { + if (AltosSerial.debug) + System.out.printf(format, arguments); + } - public synchronized void notify_tile(AltosMapTile tile, int status) { - if (status == AltosMapTile.loading) - return; - SwingUtilities.invokeLater(new updatePbar(tile.store.file.toString())); - ++tiles_loaded; - if (tiles_loaded == tiles_per_layer) { - ++layers_loaded; - if (layers_loaded == layers_total) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - pbar.setValue(0); - pbar.setString(""); - load_button.setSelected(false); - loading = false; - } - }); - } else { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - next_load(); - } - }); - } - } + 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; } - public AltosMapCache cache() { return cache; } - public void itemStateChanged(ItemEvent e) { int state = e.getStateChange(); @@ -283,24 +227,35 @@ 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(); - min_z = (Integer) min_zoom.getSelectedItem(); - max_z = (Integer) max_zoom.getSelectedItem(); + int min_z = (Integer) min_zoom.getSelectedItem(); + int max_z = (Integer) max_zoom.getSelectedItem(); if (max_z < min_z) max_z = min_z; - 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; + + loader = new AltosMapLoader(map.map, this, + latitude, longitude, + min_z, max_z, r, all_types()); + } catch (ParseException pe) { load_button.setSelected(false); } - start_load(); } } } @@ -329,7 +284,6 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener pane.setLayout(new GridBagLayout()); map = new AltosUIMapNew(); - cache = new AltosMapCache(map); c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; @@ -504,13 +458,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;