Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java
r16292 r16293 25 25 import org.openstreetmap.josm.data.preferences.CachingProperty; 26 26 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 27 import org.openstreetmap.josm.tools.ColorHelper; 27 28 import org.openstreetmap.josm.tools.I18n; 28 29 import org.openstreetmap.josm.tools.Pair; 29 import org.openstreetmap.josm.tools.Utils;30 30 31 31 /** … … 123 123 enableHTML = true; 124 124 // U+25A0 BLACK SQUARE 125 String escaped = Utils.escapeReservedCharactersHTML(str); 126 str = "<html><body><span color='" + escaped + "'>\u25A0</span> " + escaped + "</body></html>"; 125 final String color = str.matches("#[0-9A-Fa-f]{3,8}") 126 ? str 127 : ColorHelper.color2html(ColorHelper.html2color(str)); 128 str = "<html><body><span color='" + color + "'>\u25A0</span> " + color + "</body></html>"; 127 129 } 128 130 ((JLabel) c).putClientProperty("html.disable", enableHTML ? null : Boolean.TRUE); // Fix #8730 -
trunk/src/org/openstreetmap/josm/tools/ColorHelper.java
r16252 r16293 3 3 4 4 import java.awt.Color; 5 6 import org.openstreetmap.josm.gui.mappaint.mapcss.CSSColors; 5 7 6 8 /** … … 14 16 15 17 /** 16 * Returns the {@code Color} for the given HTML code .18 * Returns the {@code Color} for the given HTML code, also evaluates CSS color names using {@link CSSColors}. 17 19 * @param html the color code 18 20 * @return the color … … 22 24 html = html.substring(1); 23 25 if (html.length() == 3) { 24 return html2color(new String( 25 new char[]{html.charAt(0), html.charAt(0), html.charAt(1), html.charAt(1), html.charAt(2), html.charAt(2)})); 26 html = new String(new char[]{ 27 html.charAt(0), html.charAt(0), 28 html.charAt(1), html.charAt(1), 29 html.charAt(2), html.charAt(2)}); 26 30 } 27 31 if (html.length() != 6 && html.length() != 8) 28 return null;32 return CSSColors.get(html); 29 33 try { 30 34 return new Color( … … 34 38 html.length() == 8 ? Integer.parseInt(html.substring(6, 8), 16) : 255); 35 39 } catch (NumberFormatException e) { 36 return null;40 return CSSColors.get(html); 37 41 } 38 42 } -
trunk/test/unit/org/openstreetmap/josm/tools/ColorHelperTest.java
r16252 r16293 26 26 assertEquals(Color.CYAN, ColorHelper.html2color("#00ffff")); 27 27 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")); 28 31 assertEquals(new Color(0x12345678, true), ColorHelper.html2color("#34567812")); 29 32 }
Note:
See TracChangeset
for help on using the changeset viewer.