Ignore:
Timestamp:
2015-06-19T17:26:18+02:00 (9 years ago)
Author:
simon04
Message:

fix #5509 - Presets: sort property lists by display name

Sorting is on by default and can be controlled with preference key
taggingpreset.sortvalues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java

    r8415 r8493  
    6565import org.openstreetmap.josm.gui.widgets.QuadStateCheckBox;
    6666import org.openstreetmap.josm.gui.widgets.UrlLabel;
     67import org.openstreetmap.josm.tools.AlphanumComparator;
    6768import org.openstreetmap.josm.tools.GBC;
    6869import org.openstreetmap.josm.tools.ImageProvider;
     
    9394    private static final Map<String,String> LAST_VALUES = new HashMap<>();
    9495
    95     public static class PresetListEntry {
     96    public static class PresetListEntry implements Comparable<PresetListEntry> {
    9697        public String value;
    9798        /** The context used for translating {@link #value} */
     
    168169                return DIFFERENT;
    169170            return getDisplayValue(true).replaceAll("<.*>", ""); // remove additional markup, e.g. <br>
     171        }
     172
     173        @Override
     174        public int compareTo(PresetListEntry o) {
     175            return AlphanumComparator.getInstance().compare(this.getDisplayValue(true), o.getDisplayValue(true));
    170176        }
    171177    }
     
    10641070        }
    10651071
    1066         private String[] initListEntriesFromAttributes() {
     1072        private void initListEntriesFromAttributes() {
    10671073            char delChar = getDelChar();
    10681074
     
    11101116            }
    11111117
     1118            final List<PresetListEntry> entries = new ArrayList<>(value_array.length);
    11121119            for (int i = 0; i < value_array.length; i++) {
    11131120                final PresetListEntry e = new PresetListEntry(value_array[i]);
    11141121                e.locale_display_value = locale_display_values != null
    11151122                        ? display_array[i]
    1116                                 : trc(values_context, fixPresetString(display_array[i]));
    1117                         if (short_descriptions_array != null) {
    1118                             e.locale_short_description = locale_short_descriptions != null
    1119                                     ? short_descriptions_array[i]
    1120                                             : tr(fixPresetString(short_descriptions_array[i]));
    1121                         }
    1122                         lhm.put(value_array[i], e);
    1123                         display_array[i] = e.getDisplayValue(true);
    1124             }
    1125 
    1126             return display_array;
     1123                        : trc(values_context, fixPresetString(display_array[i]));
     1124                if (short_descriptions_array != null) {
     1125                    e.locale_short_description = locale_short_descriptions != null
     1126                            ? short_descriptions_array[i]
     1127                            : tr(fixPresetString(short_descriptions_array[i]));
     1128                }
     1129
     1130                entries.add(e);
     1131            }
     1132
     1133            if (Main.pref.getBoolean("taggingpreset.sortvalues", true)) {
     1134                Collections.sort(entries);
     1135            }
     1136
     1137            for (PresetListEntry i : entries) {
     1138                lhm.put(i.value, i);
     1139            }
     1140
    11271141        }
    11281142
Note: See TracChangeset for help on using the changeset viewer.