@Test public void testParseRGBA() { Color rgba = ColorUtil.parseColor("rgba(255,0,0,0.5)"); Assert.assertTrue(128 == rgba.getAlpha()); Assert.assertTrue(Transparency.TRANSLUCENT == rgba.getTransparency()); }
public static Color parseColor(String color) { if (color == null || color.isEmpty()) { return null; } if (color.charAt(0) == '#') { return new Color(parseHEX(color)); } Matcher matcher = RGBA.matcher(color); if (matcher.matches()){ return new Color(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3)), (int) (Float.parseFloat(matcher.group(4)) * 255 + 0.5) ); } matcher = RGB.matcher(color); if (matcher.matches()) { return new Color(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3))); } return new Color(parseHEX(color)); }
ColorUtil { public static Color parseColor(String color) { if (color == null || color.isEmpty()) { return null; } if (color.charAt(0) == '#') { return new Color(parseHEX(color)); } Matcher matcher = RGBA.matcher(color); if (matcher.matches()){ return new Color(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3)), (int) (Float.parseFloat(matcher.group(4)) * 255 + 0.5) ); } matcher = RGB.matcher(color); if (matcher.matches()) { return new Color(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3))); } return new Color(parseHEX(color)); } }
ColorUtil { public static Color parseColor(String color) { if (color == null || color.isEmpty()) { return null; } if (color.charAt(0) == '#') { return new Color(parseHEX(color)); } Matcher matcher = RGBA.matcher(color); if (matcher.matches()){ return new Color(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3)), (int) (Float.parseFloat(matcher.group(4)) * 255 + 0.5) ); } matcher = RGB.matcher(color); if (matcher.matches()) { return new Color(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3))); } return new Color(parseHEX(color)); }  }
ColorUtil { public static Color parseColor(String color) { if (color == null || color.isEmpty()) { return null; } if (color.charAt(0) == '#') { return new Color(parseHEX(color)); } Matcher matcher = RGBA.matcher(color); if (matcher.matches()){ return new Color(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3)), (int) (Float.parseFloat(matcher.group(4)) * 255 + 0.5) ); } matcher = RGB.matcher(color); if (matcher.matches()) { return new Color(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3))); } return new Color(parseHEX(color)); }  static Color parseColor(String color); }
ColorUtil { public static Color parseColor(String color) { if (color == null || color.isEmpty()) { return null; } if (color.charAt(0) == '#') { return new Color(parseHEX(color)); } Matcher matcher = RGBA.matcher(color); if (matcher.matches()){ return new Color(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3)), (int) (Float.parseFloat(matcher.group(4)) * 255 + 0.5) ); } matcher = RGB.matcher(color); if (matcher.matches()) { return new Color(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3))); } return new Color(parseHEX(color)); }  static Color parseColor(String color);  }