Changeset 16985 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-08-30T22:19:00+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/SystemOfMeasurement.java
r15661 r16985 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.marktr; 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 6 7 import java.text.NumberFormat; … … 127 128 /** 128 129 * Sets the current global system of measurement. 129 * @param som Key The system of measurement key. Must be defined in {@link SystemOfMeasurement#ALL_SYSTEMS}.130 * @param som The system of measurement to set. Must be defined in {@link SystemOfMeasurement#ALL_SYSTEMS}. 130 131 * @throws IllegalArgumentException if {@code somKey} is not known 131 * @since 8554 132 */ 133 public static void setSystemOfMeasurement(String somKey) { 132 * @since xxx (signature) 133 */ 134 public static void setSystemOfMeasurement(SystemOfMeasurement som) { 135 String somKey = som.getName(); 134 136 if (!SystemOfMeasurement.ALL_SYSTEMS.containsKey(somKey)) { 135 137 throw new IllegalArgumentException("Invalid system of measurement: "+somKey); … … 285 287 286 288 /** 289 * Returns the localized name of this system of measurement 290 * @return the localized name 291 */ 292 @Override 293 public String toString() { 294 return tr(name); 295 } 296 297 /** 287 298 * Returns the default system of measurement for the current country. 288 299 * @return the default system of measurement for the current country -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r16625 r16985 35 35 import java.util.ArrayList; 36 36 import java.util.Collection; 37 import java.util.Comparator; 37 38 import java.util.ConcurrentModificationException; 38 39 import java.util.Iterator; 39 40 import java.util.List; 40 41 import java.util.Objects; 41 import java.util.TreeSet;42 42 import java.util.concurrent.BlockingQueue; 43 43 import java.util.concurrent.LinkedBlockingQueue; 44 import java.util.stream.Collectors; 44 45 45 46 import javax.swing.AbstractAction; … … 128 129 private static final AbstractProperty<Boolean> SHOW_ID = new BooleanProperty("osm-primitives.showid", false); 129 130 131 private static final List<SystemOfMeasurement> SORTED_SYSTEM_OF_MEASUREMENTS = SystemOfMeasurement.ALL_SYSTEMS.values().stream() 132 .sorted(Comparator.comparing(SystemOfMeasurement::toString)) 133 .collect(Collectors.toList()); 134 130 135 /** 131 136 * Property for map status background color. … … 801 806 802 807 MapStatusPopupMenu() { 803 for (final S tring key : new TreeSet<>(SystemOfMeasurement.ALL_SYSTEMS.keySet())) {804 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new AbstractAction( key) {808 for (final SystemOfMeasurement som : SORTED_SYSTEM_OF_MEASUREMENTS) { 809 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new AbstractAction(som.toString()) { 805 810 @Override 806 811 public void actionPerformed(ActionEvent e) { 807 updateSystemOfMeasurement( key);812 updateSystemOfMeasurement(som); 808 813 } 809 814 }); … … 919 924 if (Config.getPref().getBoolean("statusbar.change-system-of-measurement-on-click", true)) { 920 925 distText.addMouseListener(new MouseAdapter() { 921 private final List<String> soms = new ArrayList<>(new TreeSet<>(SystemOfMeasurement.ALL_SYSTEMS.keySet()));922 923 926 @Override 924 927 public void mouseClicked(MouseEvent e) { 925 928 if (!e.isPopupTrigger() && e.getButton() == MouseEvent.BUTTON1) { 926 String som = SystemOfMeasurement.PROP_SYSTEM_OF_MEASUREMENT.get(); 927 String newsom = soms.get((soms.indexOf(som)+1) % soms.size()); 929 SystemOfMeasurement som = SystemOfMeasurement.getSystemOfMeasurement(); 930 int i = (SORTED_SYSTEM_OF_MEASUREMENTS.indexOf(som) + 1) % SORTED_SYSTEM_OF_MEASUREMENTS.size(); 931 SystemOfMeasurement newsom = SORTED_SYSTEM_OF_MEASUREMENTS.get(i); 928 932 updateSystemOfMeasurement(newsom); 929 933 } … … 997 1001 /** 998 1002 * Updates the system of measurement and displays a notification. 999 * @param newsom The new system of measurement to set1003 * @param som The new system of measurement to set 1000 1004 * @since 6960 1001 1005 */ 1002 public void updateSystemOfMeasurement(S tring newsom) {1003 SystemOfMeasurement.setSystemOfMeasurement( newsom);1006 public void updateSystemOfMeasurement(SystemOfMeasurement som) { 1007 SystemOfMeasurement.setSystemOfMeasurement(som); 1004 1008 if (Config.getPref().getBoolean("statusbar.notify.change-system-of-measurement", true)) { 1005 new Notification(tr("System of measurement changed to {0}", newsom))1009 new Notification(tr("System of measurement changed to {0}", som.toString())) 1006 1010 .setDuration(Notification.TIME_SHORT) 1007 1011 .show(); -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java
r16438 r16985 2 2 package org.openstreetmap.josm.gui.preferences.projection; 3 3 4 import static org.openstreetmap.josm.data.SystemOfMeasurement.ALL_SYSTEMS;5 4 import static org.openstreetmap.josm.tools.I18n.tr; 6 5 … … 11 10 import java.util.Collection; 12 11 import java.util.Collections; 12 import java.util.Comparator; 13 13 import java.util.HashMap; 14 14 import java.util.List; … … 296 296 private static final StringProperty PROP_COORDINATES = new StringProperty("coordinates", null); 297 297 private static final ListProperty PROP_SUB_PROJECTION_DEFAULT = new ListProperty("projection.default.sub", null); 298 private static final String[] unitsValues = ALL_SYSTEMS.keySet().toArray(new String[ALL_SYSTEMS.size()]);299 private static final String[] unitsValuesTr = new String[unitsValues.length];300 static {301 for (int i = 0; i < unitsValues.length; ++i) {302 unitsValuesTr[i] = tr(unitsValues[i]);303 }304 }305 298 306 299 /** … … 314 307 private final JosmComboBox<ICoordinateFormat> coordinatesCombo; 315 308 316 private final JosmComboBox<String> unitsCombo = new JosmComboBox<>(unitsValuesTr); 309 /** 310 * Combobox with all system of measurements 311 */ 312 private final JosmComboBox<SystemOfMeasurement> unitsCombo = new JosmComboBox<>( 313 SystemOfMeasurement.ALL_SYSTEMS.values().stream() 314 .sorted(Comparator.comparing(SystemOfMeasurement::toString)) 315 .toArray(SystemOfMeasurement[]::new)); 317 316 318 317 /** … … 359 358 .ifPresent(coordinatesCombo::setSelectedIndex); 360 359 361 IntStream.range(0, unitsValues.length) 362 .filter(i -> unitsValues[i].equals(SystemOfMeasurement.PROP_SYSTEM_OF_MEASUREMENT.get())).findFirst() 363 .ifPresent(unitsCombo::setSelectedIndex); 360 unitsCombo.setSelectedItem(SystemOfMeasurement.getSystemOfMeasurement()); 364 361 365 362 projPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); … … 448 445 } 449 446 450 int i = unitsCombo.getSelectedIndex(); 451 SystemOfMeasurement.setSystemOfMeasurement(unitsValues[i]); 447 SystemOfMeasurement.setSystemOfMeasurement(((SystemOfMeasurement) unitsCombo.getSelectedItem())); 452 448 453 449 return false;
Note:
See TracChangeset
for help on using the changeset viewer.