From: Keith Packard Date: Wed, 25 May 2016 06:40:47 +0000 (-0700) Subject: altosuilib: Have map preload respond to units and font size changes X-Git-Tag: 1.6.4~1^2~31 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=59a9bdd73b580a9c934a574be7bf45c5033e14b5 altosuilib: Have map preload respond to units and font size changes Just add suitable listeners so that the display updates when preferences change. Signed-off-by: Keith Packard --- diff --git a/altosuilib/AltosUIMapPreloadNew.java b/altosuilib/AltosUIMapPreloadNew.java index b16659da..d043e9e3 100644 --- a/altosuilib/AltosUIMapPreloadNew.java +++ b/altosuilib/AltosUIMapPreloadNew.java @@ -118,7 +118,7 @@ class AltosUIMapPos extends Box { } } -public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener, ItemListener, AltosLaunchSiteListener, AltosMapLoaderListener { +public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener, ItemListener, AltosLaunchSiteListener, AltosMapLoaderListener, AltosUnitsListener, AltosFontListener { AltosUIFrame owner; AltosUIMapNew map; @@ -137,6 +137,7 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener JComboBox min_zoom; JComboBox max_zoom; + JLabel radius_label; JComboBox radius; int scale = 1; @@ -276,6 +277,35 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener }); } + private void set_radius_values() { + radius_label.setText(String.format("Map Radius (%s)", + AltosPreferences.imperial_units() ? "mi" : "km")); + + Double[] radii; + + if (AltosPreferences.imperial_units()) + radii = radius_mi; + else + radii = radius_km; + + radius.removeAllItems(); + for (Double r : radii) { + System.out.printf("adding radius %f\n",r); + radius.addItem(r); + } + radius.setSelectedItem(radii[2]); + radius.setMaximumRowCount(radii.length); + } + + public void units_changed(boolean imperial_units) { + map.units_changed(imperial_units); + set_radius_values(); + } + + public void font_size_changed(int font_size) { + map.font_size_changed(font_size); + } + public AltosUIMapPreloadNew(AltosUIFrame in_owner) { owner = in_owner; @@ -287,6 +317,18 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener pane.setLayout(new GridBagLayout()); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + AltosUIPreferences.unregister_font_listener(AltosUIMapPreloadNew.this); + AltosPreferences.unregister_units_listener(AltosUIMapPreloadNew.this); + } + }); + + + AltosPreferences.register_units_listener(this); + AltosUIPreferences.register_font_listener(this); + map = new AltosUIMapNew(); c.fill = GridBagConstraints.BOTH; @@ -462,26 +504,20 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener c.gridy = 3; pane.add(max_zoom, c); - JLabel radius_label = new JLabel(String.format("Map Radius (%s)", - AltosPreferences.imperial_units() ? "miles" : "km")); + radius_label = new JLabel(); + c.gridx = 4; c.gridy = 4; pane.add(radius_label, c); - 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 = new JComboBox(); radius.setEditable(true); c.gridx = 5; c.gridy = 4; pane.add(radius, c); + set_radius_values(); + pack(); setLocationRelativeTo(owner); setVisible(true);