if ( b > 255 ) b = 255;
return new Color(r, g, b, c.getAlpha());
- }
+ }
+
+ public static Color hexColor(String hex) {
+ if(hex.startsWith("#")) {
+ if(hex.length() == 4) {
+ int r = Character.digit(hex.charAt(1), 16);
+ int g = Character.digit(hex.charAt(2), 16);
+ int b = Character.digit(hex.charAt(3), 16);
+ return new Color(r+(r<<4), g+(g<<4), b+(b<<4));
+ } else if(hex.length() == 7) {
+ return new Color(Integer.parseInt(hex.substring(1), 16));
+ }
+ }
+ return Color.BLACK;
+ }
}