Changeset 8554 in josm for trunk/src/org
- Timestamp:
- 2015-07-01T21:33:04+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java
r8540 r8554 32 32 import org.openstreetmap.josm.gui.MapFrame; 33 33 import org.openstreetmap.josm.gui.MapView; 34 import org.openstreetmap.josm.gui.NavigatableComponent;35 34 import org.openstreetmap.josm.gui.layer.Layer; 36 35 import org.openstreetmap.josm.gui.layer.MapViewPaintable; … … 424 423 // - Snap steps relative to the distance? 425 424 double snapDistance; 426 SystemOfMeasurement som = NavigatableComponent.getSystemOfMeasurement();425 SystemOfMeasurement som = SystemOfMeasurement.getSystemOfMeasurement(); 427 426 if (som.equals(SystemOfMeasurement.CHINESE)) { 428 427 snapDistance = snapDistanceChinese * SystemOfMeasurement.CHINESE.aValue; -
trunk/src/org/openstreetmap/josm/data/SystemOfMeasurement.java
r8540 r8554 8 8 import java.util.Locale; 9 9 import java.util.Map; 10 import java.util.concurrent.CopyOnWriteArrayList; 10 11 11 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 12 14 13 15 /** 14 16 * A system of units used to express length and area measurements. 17 * <p> 18 * This class also manages one globally set system of measurement stored in the {@link ProjectionPreference} 15 19 * @since 3406 (creation) 16 20 * @since 6992 (extraction in this package) 17 21 */ 18 22 public class SystemOfMeasurement { 23 24 /** 25 * Interface to notify listeners of the change of the system of measurement. 26 */ 27 public interface SoMChangeListener { 28 /** 29 * The current SoM has changed. 30 * @param oldSoM The old system of measurement 31 * @param newSoM The new (current) system of measurement 32 */ 33 void systemOfMeasurementChanged(String oldSoM, String newSoM); 34 } 19 35 20 36 /** … … 53 69 ALL_SYSTEMS.put(marktr("Imperial"), IMPERIAL); 54 70 ALL_SYSTEMS.put(marktr("Nautical Mile"), NAUTICAL_MILE); 71 } 72 73 private static final CopyOnWriteArrayList<SoMChangeListener> somChangeListeners = new CopyOnWriteArrayList<>(); 74 75 /** 76 * Removes a global SoM change listener 77 * 78 * @param listener the listener. Ignored if null or already absent 79 */ 80 public static void removeSoMChangeListener(SoMChangeListener listener) { 81 somChangeListeners.remove(listener); 82 } 83 84 /** 85 * Adds a SoM change listener 86 * 87 * @param listener the listener. Ignored if null or already registered. 88 */ 89 public static void addSoMChangeListener(SoMChangeListener listener) { 90 if (listener != null) { 91 somChangeListeners.addIfAbsent(listener); 92 } 93 } 94 95 protected static void fireSoMChanged(String oldSoM, String newSoM) { 96 for (SoMChangeListener l : somChangeListeners) { 97 l.systemOfMeasurementChanged(oldSoM, newSoM); 98 } 99 } 100 101 /** 102 * Returns the current global system of measurement. 103 * @return The current system of measurement (metric system by default). 104 */ 105 public static SystemOfMeasurement getSystemOfMeasurement() { 106 SystemOfMeasurement som = SystemOfMeasurement.ALL_SYSTEMS.get(ProjectionPreference.PROP_SYSTEM_OF_MEASUREMENT.get()); 107 if (som == null) 108 return SystemOfMeasurement.METRIC; 109 return som; 110 } 111 112 /** 113 * Sets the current global system of measurement. 114 * @param somKey The system of measurement key. Must be defined in {@link SystemOfMeasurement#ALL_SYSTEMS}. 115 * @throws IllegalArgumentException if {@code somKey} is not known 116 */ 117 public static void setSystemOfMeasurement(String somKey) { 118 if (!SystemOfMeasurement.ALL_SYSTEMS.containsKey(somKey)) { 119 throw new IllegalArgumentException("Invalid system of measurement: "+somKey); 120 } 121 String oldKey = ProjectionPreference.PROP_SYSTEM_OF_MEASUREMENT.get(); 122 if (ProjectionPreference.PROP_SYSTEM_OF_MEASUREMENT.put(somKey)) { 123 fireSoMChanged(oldKey, somKey); 124 } 55 125 } 56 126 -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r8513 r8554 54 54 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 55 55 import org.openstreetmap.josm.data.SystemOfMeasurement; 56 import org.openstreetmap.josm.data.SystemOfMeasurement.SoMChangeListener; 56 57 import org.openstreetmap.josm.data.coor.CoordinateFormat; 57 58 import org.openstreetmap.josm.data.coor.LatLon; … … 60 61 import org.openstreetmap.josm.data.osm.Way; 61 62 import org.openstreetmap.josm.data.preferences.ColorProperty; 62 import org.openstreetmap.josm.gui.NavigatableComponent.SoMChangeListener;63 63 import org.openstreetmap.josm.gui.help.Helpful; 64 64 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; … … 865 865 } 866 866 867 NavigatableComponent.addSoMChangeListener(somListener = new SoMChangeListener() {867 SystemOfMeasurement.addSoMChangeListener(somListener = new SoMChangeListener() { 868 868 @Override 869 869 public void systemOfMeasurementChanged(String oldSoM, String newSoM) { … … 908 908 */ 909 909 public void updateSystemOfMeasurement(String newsom) { 910 NavigatableComponent.setSystemOfMeasurement(newsom);910 SystemOfMeasurement.setSystemOfMeasurement(newsom); 911 911 if (Main.pref.getBoolean("statusbar.notify.change-system-of-measurement", true)) { 912 912 new Notification(tr("System of measurement changed to {0}", newsom)) … … 1020 1020 @Override 1021 1021 public void destroy() { 1022 NavigatableComponent.removeSoMChangeListener(somListener);1022 SystemOfMeasurement.removeSoMChangeListener(somListener); 1023 1023 Main.pref.removePreferenceChangeListener(this); 1024 1024 -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r8510 r8554 52 52 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 53 53 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 54 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;55 54 import org.openstreetmap.josm.tools.Predicate; 56 55 import org.openstreetmap.josm.tools.Utils; … … 79 78 * @since 6056 80 79 */ 81 public interface SoMChangeListener { 82 /** 83 * The current SoM has changed. 84 * @param oldSoM The old system of measurement 85 * @param newSoM The new (current) system of measurement 86 */ 87 void systemOfMeasurementChanged(String oldSoM, String newSoM); 80 @Deprecated 81 public interface SoMChangeListener extends SystemOfMeasurement.SoMChangeListener { 88 82 } 89 83 … … 138 132 } 139 133 140 private static final CopyOnWriteArrayList<SoMChangeListener> somChangeListeners = new CopyOnWriteArrayList<>();141 134 142 135 /** … … 146 139 * @since 6056 147 140 */ 141 @Deprecated 148 142 public static void removeSoMChangeListener(NavigatableComponent.SoMChangeListener listener) { 149 somChangeListeners.remove(listener);143 SystemOfMeasurement.removeSoMChangeListener(listener); 150 144 } 151 145 … … 156 150 * @since 6056 157 151 */ 152 @Deprecated 158 153 public static void addSoMChangeListener(NavigatableComponent.SoMChangeListener listener) { 159 if (listener != null) { 160 somChangeListeners.addIfAbsent(listener); 161 } 162 } 163 164 protected static void fireSoMChanged(String oldSoM, String newSoM) { 165 for (SoMChangeListener l : somChangeListeners) { 166 l.systemOfMeasurementChanged(oldSoM, newSoM); 167 } 168 } 169 170 /** 171 * The scale factor in x or y-units per pixel. This means, if scale = 10, 172 * every physical pixel on screen are 10 x or 10 y units in the 173 * northing/easting space of the projection. 174 */ 154 SystemOfMeasurement.addSoMChangeListener(listener); 155 } 156 157 /** 158 * Returns the current system of measurement. 159 * @return The current system of measurement (metric system by default). 160 * @since 3490 161 */ 162 @Deprecated 163 public static SystemOfMeasurement getSystemOfMeasurement() { 164 return SystemOfMeasurement.getSystemOfMeasurement(); 165 } 166 167 /** 168 * Sets the current system of measurement. 169 * @param somKey The system of measurement key. Must be defined in {@link SystemOfMeasurement#ALL_SYSTEMS}. 170 * @throws IllegalArgumentException if {@code somKey} is not known 171 * @since 6056 172 */ 173 @Deprecated 174 public static void setSystemOfMeasurement(String somKey) { 175 SystemOfMeasurement.setSystemOfMeasurement(somKey); 176 } 177 175 178 private double scale = Main.getProjection().getDefaultZoomInPPD(); 176 177 179 /** 178 180 * Center n/e coordinate of the desired screen center. … … 212 214 */ 213 215 public static String getDistText(double dist) { 214 return getSystemOfMeasurement().getDistText(dist);216 return SystemOfMeasurement.getSystemOfMeasurement().getDistText(dist); 215 217 } 216 218 … … 224 226 */ 225 227 public static String getDistText(final double dist, final NumberFormat format, final double threshold) { 226 return getSystemOfMeasurement().getDistText(dist, format, threshold);228 return SystemOfMeasurement.getSystemOfMeasurement().getDistText(dist, format, threshold); 227 229 } 228 230 … … 234 236 */ 235 237 public static String getAreaText(double area) { 236 return getSystemOfMeasurement().getAreaText(area);238 return SystemOfMeasurement.getSystemOfMeasurement().getAreaText(area); 237 239 } 238 240 … … 246 248 */ 247 249 public static String getAreaText(final double area, final NumberFormat format, final double threshold) { 248 return getSystemOfMeasurement().getAreaText(area, format, threshold);250 return SystemOfMeasurement.getSystemOfMeasurement().getAreaText(area, format, threshold); 249 251 } 250 252 … … 1435 1437 } 1436 1438 1437 /**1438 * Returns the current system of measurement.1439 * @return The current system of measurement (metric system by default).1440 * @since 34901441 */1442 public static SystemOfMeasurement getSystemOfMeasurement() {1443 SystemOfMeasurement som = SystemOfMeasurement.ALL_SYSTEMS.get(ProjectionPreference.PROP_SYSTEM_OF_MEASUREMENT.get());1444 if (som == null)1445 return SystemOfMeasurement.METRIC;1446 return som;1447 }1448 1449 /**1450 * Sets the current system of measurement.1451 * @param somKey The system of measurement key. Must be defined in {@link SystemOfMeasurement#ALL_SYSTEMS}.1452 * @throws IllegalArgumentException if {@code somKey} is not known1453 * @since 60561454 */1455 public static void setSystemOfMeasurement(String somKey) {1456 if (!SystemOfMeasurement.ALL_SYSTEMS.containsKey(somKey)) {1457 throw new IllegalArgumentException("Invalid system of measurement: "+somKey);1458 }1459 String oldKey = ProjectionPreference.PROP_SYSTEM_OF_MEASUREMENT.get();1460 if (ProjectionPreference.PROP_SYSTEM_OF_MEASUREMENT.put(somKey)) {1461 fireSoMChanged(oldKey, somKey);1462 }1463 }1464 1465 1439 private static class CursorInfo { 1466 1440 private final Cursor cursor; -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r8510 r8554 26 26 import org.openstreetmap.josm.actions.SaveActionBase; 27 27 import org.openstreetmap.josm.data.Bounds; 28 import org.openstreetmap.josm.data.SystemOfMeasurement; 28 29 import org.openstreetmap.josm.data.gpx.GpxConstants; 29 30 import org.openstreetmap.josm.data.gpx.GpxData; … … 150 151 info.append(getTimespanForTrack(trk)); 151 152 info.append("</td><td>"); 152 info.append( NavigatableComponent.getSystemOfMeasurement().getDistText(trk.length()));153 info.append(SystemOfMeasurement.getSystemOfMeasurement().getDistText(trk.length())); 153 154 info.append("</td><td>"); 154 155 if (trk.getAttributes().containsKey("url")) { … … 160 161 } 161 162 162 info.append(tr("Length: {0}", NavigatableComponent.getSystemOfMeasurement().getDistText(data.length()))).append("<br>")163 info.append(tr("Length: {0}", SystemOfMeasurement.getSystemOfMeasurement().getDistText(data.length()))).append("<br>") 163 164 .append(trn("{0} route, ", "{0} routes, ", data.routes.size(), data.routes.size())).append( 164 165 trn("{0} waypoint", "{0} waypoints", data.waypoints.size(), data.waypoints.size())).append("<br>"); … … 222 223 .append(trn("{0} route, ", "{0} routes, ", data.routes.size(), data.routes.size())) 223 224 .append(trn("{0} waypoint", "{0} waypoints", data.waypoints.size(), data.waypoints.size())).append("<br>") 224 .append(tr("Length: {0}", NavigatableComponent.getSystemOfMeasurement().getDistText(data.length())))225 .append(tr("Length: {0}", SystemOfMeasurement.getSystemOfMeasurement().getDistText(data.length()))) 225 226 .append("<br></html>"); 226 227 return info.toString(); -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java
r8510 r8554 33 33 34 34 import org.openstreetmap.josm.Main; 35 import org.openstreetmap.josm.data.SystemOfMeasurement; 35 36 import org.openstreetmap.josm.data.gpx.GpxConstants; 36 37 import org.openstreetmap.josm.data.gpx.GpxTrack; 37 38 import org.openstreetmap.josm.gui.ExtendedDialog; 38 import org.openstreetmap.josm.gui.NavigatableComponent;39 39 import org.openstreetmap.josm.gui.layer.GpxLayer; 40 40 import org.openstreetmap.josm.tools.GBC; … … 83 83 @Override 84 84 public String toString() { 85 return NavigatableComponent.getSystemOfMeasurement().getDistText(value);85 return SystemOfMeasurement.getSystemOfMeasurement().getDistText(value); 86 86 } 87 87 } -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java
r8540 r8554 30 30 import org.openstreetmap.josm.data.projection.CustomProjection; 31 31 import org.openstreetmap.josm.data.projection.Projection; 32 import org.openstreetmap.josm.gui.NavigatableComponent;33 32 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 34 33 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; … … 384 383 385 384 int i = unitsCombo.getSelectedIndex(); 386 NavigatableComponent.setSystemOfMeasurement(unitsValues[i]);385 SystemOfMeasurement.setSystemOfMeasurement(unitsValues[i]); 387 386 388 387 return false;
Note:
See TracChangeset
for help on using the changeset viewer.