- Timestamp:
- 2013-07-07T00:21:33+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r6020 r6056 287 287 } 288 288 289 // MapFrame gets destroyed when the last layer is removed, but the status line background 290 // thread that collects the information doesn't get destroyed automatically. 291 if(statusLine.thread != null) { 292 try { 293 statusLine.thread.interrupt(); 294 } catch (Exception e) { 295 e.printStackTrace(); 296 } 297 } 289 statusLine.destroy(); 298 290 mapView.destroy(); 299 291 } -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r5991 r6056 28 28 import java.util.ConcurrentModificationException; 29 29 import java.util.List; 30 import java.util.TreeSet; 30 31 31 32 import javax.swing.AbstractAction; … … 50 51 import org.openstreetmap.josm.data.osm.OsmPrimitive; 51 52 import org.openstreetmap.josm.data.osm.Way; 53 import org.openstreetmap.josm.gui.NavigatableComponent.SoMChangeListener; 52 54 import org.openstreetmap.josm.gui.help.Helpful; 55 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 53 56 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 54 57 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor.ProgressMonitorDialog; … … 56 59 import org.openstreetmap.josm.gui.widgets.ImageLabel; 57 60 import org.openstreetmap.josm.gui.widgets.JosmTextField; 61 import org.openstreetmap.josm.tools.Destroyable; 58 62 import org.openstreetmap.josm.tools.GBC; 59 63 import org.openstreetmap.josm.tools.ImageProvider; … … 72 76 * @author imi 73 77 */ 74 public class MapStatus extends JPanel implements Helpful {78 public class MapStatus extends JPanel implements Helpful, Destroyable { 75 79 76 80 /** … … 142 146 public final BackgroundProgressMonitor progressMonitor = new BackgroundProgressMonitor(); 143 147 144 private MouseListener jumpToOnLeftClick; 148 private final MouseListener jumpToOnLeftClick; 149 private final SoMChangeListener somListener; 150 151 private double distValue; // Distance value displayed in distText, stored if refresh needed after a change of system of measurement 145 152 146 153 /** 147 154 * This is the thread that runs in the background and collects the information displayed. 148 * It gets destroyed by MapFrame.java/destroy() when the MapFrame itself is destroyed.155 * It gets destroyed by destroy() when the MapFrame itself is destroyed. 149 156 */ 150 p ublicThread thread;157 private Thread thread; 151 158 152 159 private final List<StatusTextHistory> statusText = new ArrayList<StatusTextHistory>(); … … 751 758 add(angleText, GBC.std().insets(3,0,0,0)); 752 759 add(distText, GBC.std().insets(3,0,0,0)); 753 760 761 distText.addMouseListener(new MouseAdapter() { 762 private final List<String> soms = new ArrayList<String>(new TreeSet<String>(NavigatableComponent.SYSTEMS_OF_MEASUREMENT.keySet())); 763 764 @Override 765 public void mouseClicked(MouseEvent e) { 766 String som = ProjectionPreference.PROP_SYSTEM_OF_MEASUREMENT.get(); 767 String newsom = soms.get((soms.indexOf(som)+1)%soms.size()); 768 NavigatableComponent.setSystemOfMeasurement(newsom); 769 } 770 }); 771 772 NavigatableComponent.addSoMChangeListener(somListener = new SoMChangeListener() { 773 @Override public void systemOfMeasurementChanged(String oldSoM, String newSoM) { 774 setDist(distValue); 775 } 776 }); 777 754 778 latText.addMouseListener(jumpToOnLeftClick); 755 779 lonText.addMouseListener(jumpToOnLeftClick); … … 840 864 */ 841 865 public void setDist(double dist) { 866 distValue = dist; 842 867 distText.setText(dist < 0 ? "--" : NavigatableComponent.getDistText(dist)); 843 868 } … … 863 888 angleText.setBackground(activeFlag ? ImageLabel.backColorActive : ImageLabel.backColor); 864 889 } 890 891 @Override 892 public void destroy() { 893 NavigatableComponent.removeSoMChangeListener(somListener); 894 895 // MapFrame gets destroyed when the last layer is removed, but the status line background 896 // thread that collects the information doesn't get destroyed automatically. 897 if (thread != null) { 898 try { 899 thread.interrupt(); 900 } catch (Exception e) { 901 e.printStackTrace(); 902 } 903 } 904 } 865 905 } -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r5952 r6056 64 64 void zoomChanged(); 65 65 } 66 66 67 /** 68 * Interface to notify listeners of the change of the system of measurement. 69 * @since 6056 70 */ 71 public interface SoMChangeListener { 72 /** 73 * The current SoM has changed. 74 * @param oldSoM The old system of measurement 75 * @param newSoM The new (current) system of measurement 76 */ 77 void systemOfMeasurementChanged(String oldSoM, String newSoM); 78 } 79 67 80 /** 68 81 * Simple data class that keeps map center and scale in one object. … … 127 140 for (ZoomChangeListener l : zoomChangeListeners) { 128 141 l.zoomChanged(); 142 } 143 } 144 145 /** 146 * the SoM listeners 147 */ 148 private static final CopyOnWriteArrayList<SoMChangeListener> somChangeListeners = new CopyOnWriteArrayList<SoMChangeListener>(); 149 150 /** 151 * Removes a SoM change listener 152 * 153 * @param listener the listener. Ignored if null or already absent 154 * @since 6056 155 */ 156 public static void removeSoMChangeListener(NavigatableComponent.SoMChangeListener listener) { 157 somChangeListeners.remove(listener); 158 } 159 160 /** 161 * Adds a SoM change listener 162 * 163 * @param listener the listener. Ignored if null or already registered. 164 * @since 6056 165 */ 166 public static void addSoMChangeListener(NavigatableComponent.SoMChangeListener listener) { 167 if (listener != null) { 168 somChangeListeners.addIfAbsent(listener); 169 } 170 } 171 172 protected static void fireSoMChanged(String oldSoM, String newSoM) { 173 for (SoMChangeListener l : somChangeListeners) { 174 l.systemOfMeasurementChanged(oldSoM, newSoM); 129 175 } 130 176 } … … 1229 1275 return METRIC_SOM; 1230 1276 return som; 1277 } 1278 1279 /** 1280 * Sets the current system of measurement. 1281 * @param somKey The system of measurement key. Must be defined in {@link NavigatableComponent#SYSTEMS_OF_MEASUREMENT}. 1282 * @since 6056 1283 * @throws IllegalArgumentException if {@code somKey} is not known 1284 */ 1285 public static void setSystemOfMeasurement(String somKey) { 1286 if (!SYSTEMS_OF_MEASUREMENT.containsKey(somKey)) { 1287 throw new IllegalArgumentException("Invalid system of measurement: "+somKey); 1288 } 1289 String oldKey = ProjectionPreference.PROP_SYSTEM_OF_MEASUREMENT.get(); 1290 if (ProjectionPreference.PROP_SYSTEM_OF_MEASUREMENT.put(somKey)) { 1291 fireSoMChanged(oldKey, somKey); 1292 } 1231 1293 } 1232 1294 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java
r5891 r6056 371 371 372 372 int i = unitsCombo.getSelectedIndex(); 373 PROP_SYSTEM_OF_MEASUREMENT.put(unitsValues[i]);373 NavigatableComponent.setSystemOfMeasurement(unitsValues[i]); 374 374 375 375 return false;
Note:
See TracChangeset
for help on using the changeset viewer.