Changeset 6624 in josm


Ignore:
Timestamp:
2014-01-04T14:56:55+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9521 - Colors no more displayed in preferences dialog since [6578]+[6580]

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

Legend:

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

    r6617 r6624  
    852852    }
    853853
     854    /**
     855     * Returns the color for the given key.
     856     * @param key The color key
     857     * @return the color
     858     */
    854859    public Color getColor(ColorKey key) {
    855860        return getColor(key.getColorName(), key.getSpecialName(), key.getDefaultValue());
     
    870875        }
    871876        String colStr = specName != null ? get("color."+specName) : "";
    872         if(colStr.isEmpty()) {
    873             colStr = get("color." + colKey, "");
     877        if (colStr.isEmpty()) {
     878            colStr = get("color." + colKey, ColorHelper.color2html(def));
    874879        }
    875880        return colStr.isEmpty() ? def : ColorHelper.html2color(colStr);
  • trunk/src/org/openstreetmap/josm/gui/conflict/ConflictColors.java

    r6616 r6624  
    4949    private final Color defaultColor;
    5050
    51     private static Color backgroundColorCache = null;
    52 
    5351    private ConflictColors(String name, Color defaultColor) {
    5452        this.name = name;
     
    7169    }
    7270
     71    /**
     72     * Returns the color.
     73     * @return the color
     74     */
    7375    public Color get() {
    7476        return Main.pref.getColor(this);
    7577    }
    7678
     79    /**
     80     * Loads all colors from preferences.
     81     */
    7782    public static void getColors() {
    78         for (ConflictColors c:values()) {
     83        for (ConflictColors c : values()) {
    7984            c.get();
    8085        }
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java

    r6529 r6624  
    1414import java.util.List;
    1515import java.util.Map;
    16 import java.util.Map.Entry;
    1716import java.util.TreeMap;
    1817import java.util.Vector;
     
    7877     */
    7978    public void setColorModel(Map<String, String> colorMap) {
    80         if(tableModel == null) {
     79        if (tableModel == null) {
    8180            tableModel = new DefaultTableModel();
    8281            tableModel.addColumn(tr("Name"));
     
    8584
    8685        // clear old model:
    87         while(tableModel.getRowCount() > 0) {
     86        while (tableModel.getRowCount() > 0) {
    8887            tableModel.removeRow(0);
    8988        }
     
    9291        Map<String, String> colorKeyList_mappaint = new TreeMap<String, String>();
    9392        Map<String, String> colorKeyList_layer = new TreeMap<String, String>();
    94         for(String key : colorMap.keySet()) {
    95             if(key.startsWith("layer ")) {
     93        for (String key : colorMap.keySet()) {
     94            if (key.startsWith("layer ")) {
    9695                colorKeyList_layer.put(getName(key), key);
    97             } else if(key.startsWith("mappaint.")) {
    98                 /* use getName(key)+key, as getName() may be ambiguous */
     96            } else if (key.startsWith("mappaint.")) {
     97                // use getName(key)+key, as getName() may be ambiguous
    9998                colorKeyList_mappaint.put(getName(key)+key, key);
    10099            } else {
     
    102101            }
    103102        }
    104         for (Entry<String, String> k : colorKeyList.entrySet()) {
     103        addColorRows(colorMap, colorKeyList);
     104        addColorRows(colorMap, colorKeyList_mappaint);
     105        addColorRows(colorMap, colorKeyList_layer);
     106        if (this.colors != null) {
     107            this.colors.repaint();
     108        }
     109    }
     110   
     111    private void addColorRows(Map<String, String> colorMap, Map<String, String> keyMap) {
     112        for (String value : keyMap.values()) {
    105113            Vector<Object> row = new Vector<Object>(2);
    106             row.add(k.getValue());
    107             row.add(ColorHelper.html2color(colorMap.get(k.getValue())));
     114            String html = colorMap.get(value);
     115            Color color = ColorHelper.html2color(html);
     116            if (color == null) {
     117                Main.warn("Unable to get color from '"+html+"' for color preference '"+value+"'");
     118            }
     119            row.add(value);
     120            row.add(color);
    108121            tableModel.addRow(row);
    109         }
    110         for (Entry<String, String> k : colorKeyList_mappaint.entrySet()) {
    111             Vector<Object> row = new Vector<Object>(2);
    112             row.add(k.getValue());
    113             row.add(ColorHelper.html2color(colorMap.get(k.getValue())));
    114             tableModel.addRow(row);
    115         }
    116         for (Entry<String, String> k : colorKeyList_layer.entrySet()) {
    117             Vector<Object> row = new Vector<Object>(2);
    118             row.add(k.getValue());
    119             row.add(ColorHelper.html2color(colorMap.get(k.getValue())));
    120             tableModel.addRow(row);
    121         }
    122         if(this.colors != null) {
    123             this.colors.repaint();
    124122        }
    125123    }
Note: See TracChangeset for help on using the changeset viewer.