Changeset 16985 in josm


Ignore:
Timestamp:
2020-08-30T22:19:00+02:00 (4 weeks ago)
Author:
simon04
Message:

fix #19736 - MapStatus displays non-localized SystemOfMeasurement name

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/SystemOfMeasurement.java

    r15661 r16985  
    33
    44import static org.openstreetmap.josm.tools.I18n.marktr;
     5import static org.openstreetmap.josm.tools.I18n.tr;
    56
    67import java.text.NumberFormat;
     
    127128    /**
    128129     * Sets the current global system of measurement.
    129      * @param somKey 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}.
    130131     * @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();
    134136        if (!SystemOfMeasurement.ALL_SYSTEMS.containsKey(somKey)) {
    135137            throw new IllegalArgumentException("Invalid system of measurement: "+somKey);
     
    285287
    286288    /**
     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    /**
    287298     * Returns the default system of measurement for the current country.
    288299     * @return the default system of measurement for the current country
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r16625 r16985  
    3535import java.util.ArrayList;
    3636import java.util.Collection;
     37import java.util.Comparator;
    3738import java.util.ConcurrentModificationException;
    3839import java.util.Iterator;
    3940import java.util.List;
    4041import java.util.Objects;
    41 import java.util.TreeSet;
    4242import java.util.concurrent.BlockingQueue;
    4343import java.util.concurrent.LinkedBlockingQueue;
     44import java.util.stream.Collectors;
    4445
    4546import javax.swing.AbstractAction;
     
    128129    private static final AbstractProperty<Boolean> SHOW_ID = new BooleanProperty("osm-primitives.showid", false);
    129130
     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
    130135    /**
    131136     * Property for map status background color.
     
    801806
    802807        MapStatusPopupMenu() {
    803             for (final String 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()) {
    805810                    @Override
    806811                    public void actionPerformed(ActionEvent e) {
    807                         updateSystemOfMeasurement(key);
     812                        updateSystemOfMeasurement(som);
    808813                    }
    809814                });
     
    919924        if (Config.getPref().getBoolean("statusbar.change-system-of-measurement-on-click", true)) {
    920925            distText.addMouseListener(new MouseAdapter() {
    921                 private final List<String> soms = new ArrayList<>(new TreeSet<>(SystemOfMeasurement.ALL_SYSTEMS.keySet()));
    922 
    923926                @Override
    924927                public void mouseClicked(MouseEvent e) {
    925928                    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);
    928932                        updateSystemOfMeasurement(newsom);
    929933                    }
     
    9971001    /**
    9981002     * Updates the system of measurement and displays a notification.
    999      * @param newsom The new system of measurement to set
     1003     * @param som The new system of measurement to set
    10001004     * @since 6960
    10011005     */
    1002     public void updateSystemOfMeasurement(String newsom) {
    1003         SystemOfMeasurement.setSystemOfMeasurement(newsom);
     1006    public void updateSystemOfMeasurement(SystemOfMeasurement som) {
     1007        SystemOfMeasurement.setSystemOfMeasurement(som);
    10041008        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()))
    10061010                .setDuration(Notification.TIME_SHORT)
    10071011                .show();
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java

    r16438 r16985  
    22package org.openstreetmap.josm.gui.preferences.projection;
    33
    4 import static org.openstreetmap.josm.data.SystemOfMeasurement.ALL_SYSTEMS;
    54import static org.openstreetmap.josm.tools.I18n.tr;
    65
     
    1110import java.util.Collection;
    1211import java.util.Collections;
     12import java.util.Comparator;
    1313import java.util.HashMap;
    1414import java.util.List;
     
    296296    private static final StringProperty PROP_COORDINATES = new StringProperty("coordinates", null);
    297297    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     }
    305298
    306299    /**
     
    314307    private final JosmComboBox<ICoordinateFormat> coordinatesCombo;
    315308
    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));
    317316
    318317    /**
     
    359358                .ifPresent(coordinatesCombo::setSelectedIndex);
    360359
    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());
    364361
    365362        projPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
     
    448445        }
    449446
    450         int i = unitsCombo.getSelectedIndex();
    451         SystemOfMeasurement.setSystemOfMeasurement(unitsValues[i]);
     447        SystemOfMeasurement.setSystemOfMeasurement(((SystemOfMeasurement) unitsCombo.getSelectedItem()));
    452448
    453449        return false;
  • trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    r16913 r16985  
    546546        // Make sure we're using the metric system
    547547        if (metric) {
    548             SystemOfMeasurement.setSystemOfMeasurement(SystemOfMeasurement.METRIC.getName());
     548            SystemOfMeasurement.setSystemOfMeasurement(SystemOfMeasurement.METRIC);
    549549        }
    550550
Note: See TracChangeset for help on using the changeset viewer.