Changeset 12952 in josm


Ignore:
Timestamp:
2017-10-08T18:10:17+02:00 (12 days ago)
Author:
bastiK
Message:

see #15410 - don't map translated values to keys; locale sensitive sorting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java

    r12950 r12952  
    1010import java.awt.event.MouseAdapter;
    1111import java.awt.event.MouseEvent;
     12import java.text.Collator;
    1213import java.util.ArrayList;
     14import java.util.Collections;
    1315import java.util.HashMap;
    1416import java.util.List;
    1517import java.util.Map;
    16 import java.util.TreeMap;
    1718
    1819import javax.swing.BorderFactory;
     
    7273    private JButton remove;
    7374
    74     private static class ColorEntry {
     75    private static class ColorEntry implements Comparable<ColorEntry> {
    7576        String key;
    7677        Color color;
     78
     79        public ColorEntry(String key, String colorHtml) {
     80            this.key = key;
     81            this.color = ColorHelper.html2color(colorHtml);
     82            if (this.color == null) {
     83                Logging.warn("Unable to get color from '"+colorHtml+"' for color preference '"+key+'\'');
     84            }
     85        }
     86
     87        @Override
     88        public int compareTo(ColorEntry o) {
     89            return Collator.getInstance().compare(getName(key), getName(o.key));
     90        }
    7791    }
    7892
     
    158172        tableModel.clear();
    159173        // fill model with colors:
    160         Map<String, String> colorKeyList = new TreeMap<>();
    161         Map<String, String> colorKeyListMappaint = new TreeMap<>();
    162         Map<String, String> colorKeyListLayer = new TreeMap<>();
    163         for (String key : colorMap.keySet()) {
     174        List<ColorEntry> colorKeyList = new ArrayList<>();
     175        List<ColorEntry> colorKeyListMappaint = new ArrayList<>();
     176        List<ColorEntry> colorKeyListLayer = new ArrayList<>();
     177        for (Map.Entry<String, String> e : colorMap.entrySet()) {
     178            String key = e.getKey();
     179            String html = e.getValue();
    164180            if (key.startsWith("layer.")) {
    165                 colorKeyListLayer.put(getName(key), key);
     181                colorKeyListLayer.add(new ColorEntry(key, html));
    166182            } else if (key.startsWith("mappaint.")) {
    167                 // use getName(key)+key, as getName() may be ambiguous
    168                 colorKeyListMappaint.put(getName(key)+key, key);
     183                colorKeyListMappaint.add(new ColorEntry(key, html));
    169184            } else {
    170                 colorKeyList.put(getName(key), key);
    171             }
    172         }
    173         addColorRows(colorMap, colorKeyList);
    174         addColorRows(colorMap, colorKeyListMappaint);
    175         addColorRows(colorMap, colorKeyListLayer);
     185                colorKeyList.add(new ColorEntry(key, html));
     186            }
     187        }
     188        addColorRows(colorKeyList);
     189        addColorRows(colorKeyListMappaint);
     190        addColorRows(colorKeyListLayer);
    176191        if (this.colors != null) {
    177192            this.colors.repaint();
     
    179194    }
    180195
    181     private void addColorRows(Map<String, String> colorMap, Map<String, String> keyMap) {
    182         for (String value : keyMap.values()) {
    183             ColorEntry entry = new ColorEntry();
    184             String html = colorMap.get(value);
    185             Color color = ColorHelper.html2color(html);
    186             if (color == null) {
    187                 Logging.warn("Unable to get color from '"+html+"' for color preference '"+value+'\'');
    188             }
    189             entry.key = value;
    190             entry.color = color;
    191             tableModel.addEntry(entry);
    192         }
     196    private void addColorRows(List<ColorEntry> entries) {
     197        Collections.sort(entries);
     198        entries.forEach(tableModel::addEntry);
    193199    }
    194200
Note: See TracChangeset for help on using the changeset viewer.