Changeset 12952 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-10-08T18:10:17+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java
r12950 r12952 10 10 import java.awt.event.MouseAdapter; 11 11 import java.awt.event.MouseEvent; 12 import java.text.Collator; 12 13 import java.util.ArrayList; 14 import java.util.Collections; 13 15 import java.util.HashMap; 14 16 import java.util.List; 15 17 import java.util.Map; 16 import java.util.TreeMap;17 18 18 19 import javax.swing.BorderFactory; … … 72 73 private JButton remove; 73 74 74 private static class ColorEntry {75 private static class ColorEntry implements Comparable<ColorEntry> { 75 76 String key; 76 77 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 } 77 91 } 78 92 … … 158 172 tableModel.clear(); 159 173 // 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(); 164 180 if (key.startsWith("layer.")) { 165 colorKeyListLayer. put(getName(key), key);181 colorKeyListLayer.add(new ColorEntry(key, html)); 166 182 } 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)); 169 184 } else { 170 colorKeyList. put(getName(key), key);171 } 172 } 173 addColorRows(color Map, colorKeyList);174 addColorRows(color Map, colorKeyListMappaint);175 addColorRows(color Map, colorKeyListLayer);185 colorKeyList.add(new ColorEntry(key, html)); 186 } 187 } 188 addColorRows(colorKeyList); 189 addColorRows(colorKeyListMappaint); 190 addColorRows(colorKeyListLayer); 176 191 if (this.colors != null) { 177 192 this.colors.repaint(); … … 179 194 } 180 195 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); 193 199 } 194 200
Note:
See TracChangeset
for help on using the changeset viewer.