WProperties extends Properties { public static Color hexadecimal2Color(String hexColor) { int intValue = 0xff000000; try { if (hexColor != null && hexColor.length() > 6) { intValue = (int) (Long.parseLong(hexColor, 16) & 0xffffffff); } else { intValue |= Integer.parseInt(hexColor, 16); } } catch (NumberFormatException e) { LOGGER.error("Cannot parse color {} into int", hexColor); } return new Color(intValue, true); } WProperties(); @Override synchronized Object setProperty(String key, String value); @Override String getProperty(String key); void resetProperty(String key, String defaultValue); void resetServiceProperty(String key, String defaultValue); void putIntProperty(String key, int value); int getIntProperty(String key, int def); void putLongProperty(String key, long value); long getLongProperty(String key, long def); void putBooleanProperty(String key, boolean value); boolean getBooleanProperty(String key, boolean def); void putFloatProperty(String key, float value); float getFloatProperty(String key, float def); void putDoubleProperty(String key, double value); double getDoubleProperty(String key, double def); Color getColorProperty(String key); void putColorProperty(String key, Color color); void putByteArrayProperty(String key, byte[] value); byte[] getByteArrayProperty(String key, byte[] def); static String color2Hexadecimal(Color c, boolean alpha); static Color hexadecimal2Color(String hexColor); static void setProperty(WProperties properties, String key, Preferences prefNode, String defaultValue);  }
@Test public void testHexadecimal2Color() { Assert.assertEquals(MAGENTA + " => magenta", Color.MAGENTA, WProperties.hexadecimal2Color(MAGENTA)); Assert.assertEquals(MAGENTA_ALPHA + " => magenta", Color.MAGENTA, WProperties.hexadecimal2Color(MAGENTA_ALPHA)); Assert.assertEquals(GREY_ALPHA + " => grey", COLOR_ALPHA, WProperties.hexadecimal2Color(GREY_ALPHA)); Assert.assertNotEquals(GREY + " => grey", COLOR_ALPHA, WProperties.hexadecimal2Color(GREY)); Assert.assertEquals("null => black", Color.BLACK, WProperties.hexadecimal2Color(null)); Assert.assertEquals("sf => black", Color.BLACK, WProperties.hexadecimal2Color("sf")); }