X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosuilib%2FAltosUIMapPreloadNew.java;h=ba559534e3f8226826a8475a72f8f545a1bbf2e3;hp=a7d1273763cf1f8ea65e9265d5457a93e761adb9;hb=d015cfc1499a263549f52d46e9e5b934fcb94f53;hpb=ccba2bb2f193ffd6c3a3d934a46bc06466b4b258 diff --git a/altosuilib/AltosUIMapPreloadNew.java b/altosuilib/AltosUIMapPreloadNew.java index a7d12737..ba559534 100644 --- a/altosuilib/AltosUIMapPreloadNew.java +++ b/altosuilib/AltosUIMapPreloadNew.java @@ -118,17 +118,16 @@ 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; + + AltosMapLoader loader; JLabel site_list_label; JComboBox site_list; @@ -141,132 +140,67 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener 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 }; - static final String[] lat_hemi_names = { "N", "S" }; - static final String[] lon_hemi_names = { "E", "W" }; + 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; - class updatePbar implements Runnable { - String s; - public updatePbar(String in_s) { - s = in_s; - } + static final String[] lat_hemi_names = { "N", "S" }; + static final String[] lon_hemi_names = { "E", "W" }; - public void run() { - int n = ++pbar_cur; + double latitude, longitude; - pbar.setMaximum(pbar_max); - pbar.setValue(n); - pbar.setString(s); - } + /* AltosMapLoaderListener interfaces */ + public void loader_start(final int max) { + 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) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + pbar.setValue(cur); + pbar.setString(name); + } + }); } - 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; + public void loader_done(int max) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + pbar.setValue(0); + pbar.setString(""); + load_button.setSelected(false); + loading = false; + } + }); } - private void next_load() { - int next_type = next_type(cur_type + 1); - - 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(); + public void debug(String format, Object ... arguments) { + System.out.printf(format, arguments); } - private void start_load() { - cur_z = min_z; - int ntype = 0; - all_types = 0; + + private int all_types() { + int all_types = 0; for (int t = AltosMap.maptype_hybrid; t <= AltosMap.maptype_terrain; t++) - if (maptypes[t].isSelected()) { + 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(); + return all_types; } - /* AltosMapTileListener methods */ - - 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(); - } - }); - } - } - } - - public AltosMapCache cache() { return cache; } - public void itemStateChanged(ItemEvent e) { int state = e.getStateChange(); @@ -291,16 +225,22 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener 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(); + Double r = (Double) radius.getSelectedItem(); + + if (AltosPreferences.imperial_units()) + r = AltosConvert.distance.inverse(r); + else + r = r * 1000; loading = true; + + loader.load(latitude, longitude, min_z, max_z, r, all_types()); } catch (ParseException pe) { load_button.setSelected(false); } - start_load(); } } } @@ -329,7 +269,8 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener pane.setLayout(new GridBagLayout()); map = new AltosUIMapNew(); - cache = new AltosMapCache(map); + + loader = new AltosMapLoader(map.map, this); c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; @@ -504,13 +445,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;