Changeset 16319 in josm for trunk


Ignore:
Timestamp:
2020-04-17T15:01:21+02:00 (5 years ago)
Author:
simon04
Message:

see #8352 - PropertiesDialog: fix 3-char CSS color names such as "red"

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java

    r16308 r16319  
    2525import org.openstreetmap.josm.data.preferences.CachingProperty;
    2626import org.openstreetmap.josm.data.preferences.NamedColorProperty;
     27import org.openstreetmap.josm.gui.mappaint.mapcss.CSSColors;
    2728import org.openstreetmap.josm.tools.ColorHelper;
    2829import org.openstreetmap.josm.tools.I18n;
     
    125126                final String color = str.matches("#[0-9A-Fa-f]{3,8}")
    126127                        ? str
    127                         : ColorHelper.color2html(ColorHelper.html2color(str));
    128                 str = "<html><body><span color='" + color + "'>\u25A0</span> " + str + "</body></html>";
     128                        : ColorHelper.color2html(CSSColors.get(str));
     129                if (color != null) {
     130                    str = "<html><body><span color='" + color + "'>\u25A0</span> " + str + "</body></html>";
     131                }
    129132            }
    130133            ((JLabel) c).putClientProperty("html.disable", enableHTML ? null : Boolean.TRUE); // Fix #8730
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Combo.java

    r16315 r16319  
    1515import org.openstreetmap.josm.data.tagging.ac.AutoCompletionPriority;
    1616import org.openstreetmap.josm.gui.MainApplication;
     17import org.openstreetmap.josm.gui.mappaint.mapcss.CSSColors;
    1718import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    1819import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
     
    135136
    136137    protected Color getColor() {
    137         return ColorHelper.html2color(String.valueOf(getSelectedItem()));
     138        String colorString = String.valueOf(getSelectedItem());
     139        return colorString.startsWith("#")
     140                ? ColorHelper.html2color(colorString)
     141                : CSSColors.get(colorString);
    138142    }
    139143
  • trunk/src/org/openstreetmap/josm/tools/ColorHelper.java

    r16293 r16319  
    33
    44import java.awt.Color;
    5 
    6 import org.openstreetmap.josm.gui.mappaint.mapcss.CSSColors;
    75
    86/**
     
    1614
    1715    /**
    18      * Returns the {@code Color} for the given HTML code, also evaluates CSS color names using {@link CSSColors}.
     16     * Returns the {@code Color} for the given HTML code.
    1917     * @param html the color code
    2018     * @return the color
     
    3028        }
    3129        if (html.length() != 6 && html.length() != 8)
    32             return CSSColors.get(html);
     30            return null;
    3331        try {
    3432            return new Color(
     
    3836                    html.length() == 8 ? Integer.parseInt(html.substring(6, 8), 16) : 255);
    3937        } catch (NumberFormatException e) {
    40             return CSSColors.get(html);
     38            return null;
    4139        }
    4240    }
  • trunk/test/unit/org/openstreetmap/josm/tools/ColorHelperTest.java

    r16293 r16319  
    2626        assertEquals(Color.CYAN, ColorHelper.html2color("#00ffff"));
    2727        assertEquals(Color.CYAN, ColorHelper.html2color("#00FFFF"));
    28         assertEquals(Color.CYAN, ColorHelper.html2color("cyan"));
    29         assertEquals(new Color(0xa52a2a), ColorHelper.html2color("brown"));
    30         assertEquals(new Color(0x6495ed), ColorHelper.html2color("cornflowerblue"));
    3128        assertEquals(new Color(0x12345678, true), ColorHelper.html2color("#34567812"));
    3229    }
Note: See TracChangeset for help on using the changeset viewer.