ColorConverter { public static Color colorFromStr(String colorStr) { Color color = hex2Rgb(colorStr); if (color == null) { color = colorFromRgbStr(colorStr); if (color == null) { color = colorFromColorName(colorStr); } } return color; } private  ColorConverter(); static Color offsetHsbColor(Color color, float offsetHue, float offsetSaturation, float offsetBrightness); static Float getBrightness(Color color); static Float getSaturation(Color color); static Float getHue(Color color); static Color offsetRgbColor(Color bgColor, int offsetRed, int offsetGreen, int offsetBlue); static String formatColorStr(String colorStr); static Color colorFromStr(String colorStr); static Color colorFromColorName(String colorStr); static Color colorFromRgbStr(String colorStr); static Color hex2Rgb(String colorStr); static String hex2Rgb(Color color); static String rgb2Hex(Color color); static String rgb2Hsl(Color color);  }
@Test public void testColorFromStr() { System.out.println("------------ ColorFromStr ----------------"); String colorStr; Color result; Color expResult; colorStr = "#FFF"; expResult = Color.WHITE; result = ColorConverter.colorFromStr(colorStr); assertEquals(expResult, result); System.out.println("colorFromStr ["+ colorStr +"]"); colorStr = "#FFFFFF"; expResult = Color.WHITE; result = ColorConverter.colorFromStr(colorStr); assertEquals(expResult, result); System.out.println("colorFromStr ["+ colorStr +"]"); colorStr = "FFF"; expResult = Color.WHITE; result = ColorConverter.colorFromStr(colorStr); assertEquals(expResult, result); System.out.println("colorFromStr ["+ colorStr +"]"); colorStr = "FFFFFF"; expResult = Color.WHITE; result = ColorConverter.colorFromStr(colorStr); assertEquals(expResult, result); System.out.println("colorFromStr ["+ colorStr +"]"); colorStr = "rgb(255,255,255)"; expResult = Color.WHITE; result = ColorConverter.colorFromStr(colorStr); assertEquals(expResult, result); System.out.println("colorFromStr ["+ colorStr +"]"); colorStr = "rgb(139,0,139"; expResult = new Color(139,0,139); result = ColorConverter.colorFromStr(colorStr); assertEquals(expResult, result); System.out.println("colorFromStr ["+ colorStr +"]"); colorStr = "139,0,139"; expResult = new Color(139,0,139); result = ColorConverter.colorFromStr(colorStr); assertEquals(expResult, result); System.out.println("colorFromStr ["+ colorStr +"]"); colorStr = " wHite "; expResult = Color.WHITE; result = ColorConverter.colorFromStr(colorStr); assertEquals(expResult, result); System.out.println("colorFromStr ["+ colorStr +"]"); colorStr = " BlaCK "; expResult = Color.BLACK; result = ColorConverter.colorFromStr(colorStr); assertEquals(expResult, result); System.out.println("colorFromStr ["+ colorStr +"]"); colorStr = "darkmagenta"; expResult = new Color(139,0,139); result = ColorConverter.colorFromStr(colorStr); assertEquals(expResult, result); System.out.println("colorFromStr ["+ colorStr +"]"); System.out.println("--------------------------"); }