Changeset 15158 in josm


Ignore:
Timestamp:
2019-06-03T22:39:22+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #17781 - filter imagery list by (localized) country name

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r15059 r15158  
    1111import java.util.Collections;
    1212import java.util.EnumMap;
     13import java.util.HashMap;
    1314import java.util.List;
    1415import java.util.Locale;
     
    700701    }
    701702
     703    private static final Map<String, String> localizedCountriesCache = new HashMap<>();
     704    static {
     705        localizedCountriesCache.put("", tr("Worldwide"));
     706    }
     707
     708    /**
     709     * Returns a localized name for the given country code, or "Worldwide" if empty.
     710     * This function falls back on the English name, and uses the ISO code as a last-resortvalue.
     711     *
     712     * @param countryCode An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code
     713     * @return The name of the country appropriate to the current locale.
     714     * @see Locale#getDisplayCountry
     715     * @since 15158
     716     */
     717    public static String getLocalizedCountry(String countryCode) {
     718        return localizedCountriesCache.computeIfAbsent(countryCode, code -> new Locale("en", code).getDisplayCountry());
     719    }
     720
    702721    @Override
    703722    public String toString() {
    704         return "ImageryInfo{" +
    705                 "name='" + name + '\'' +
    706                 ", countryCode='" + countryCode + '\'' +
    707                 ", url='" + url + '\'' +
    708                 ", imageryType=" + imageryType +
    709                 '}';
     723        // Used in imagery preferences filtering, so must be efficient
     724        return new StringBuilder("ImageryInfo{")
     725                .append("name='").append(name).append('\'')
     726                .append(", countryCode='").append(countryCode).append('\'')
     727                // appending the localized country in toString() allows us to filter imagery preferences table with it!
     728                .append(", localizedCountry='").append(getLocalizedCountry(countryCode)).append('\'')
     729                .append(", url='").append(url).append('\'')
     730                .append(", imageryType=").append(imageryType)
     731                .append('}').toString();
    710732    }
    711733
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryProvidersPanel.java

    r15153 r15158  
    2020import java.util.HashSet;
    2121import java.util.List;
    22 import java.util.Locale;
    2322import java.util.Map;
    2423import java.util.Optional;
     
    189188    private static class ImageryCountryTableCellRenderer extends ImageryProvidersPanel.ImageryTableCellRenderer<String> {
    190189        ImageryCountryTableCellRenderer() {
    191             super(code -> code, code -> code.isEmpty() ? tr("Worldwide") : new Locale("en", code).getDisplayCountry(), null);
     190            super(code -> code, ImageryInfo::getLocalizedCountry, null);
    192191        }
    193192    }
     
    686685
    687686        @Override
     687        public Class<?> getColumnClass(int columnIndex) {
     688            switch (columnIndex) {
     689            case 0:
     690                return ImageryCategory.class;
     691            case 1:
     692                return String.class;
     693            case 2:
     694                return ImageryInfo.class;
     695            case 3:
     696                return String.class;
     697            default:
     698                return super.getColumnClass(columnIndex);
     699            }
     700        }
     701
     702        @Override
    688703        public Object getValueAt(int row, int column) {
    689704            ImageryInfo info = layerInfo.getAllDefaultLayers().get(row);
Note: See TracChangeset for help on using the changeset viewer.