package org.oskari.print.util;

import java.awt.Color;

public class ColorUtil {
    public static Color parseColor(String rrggbb) {
        if (rrggbb == null || rrggbb.isEmpty()) {
            return null;
        }
        return new Color(parseRGB(rrggbb));
    }

    public static int parseRGB(String rrggbb) {
        if (rrggbb.charAt(0) == '#') {
            rrggbb = rrggbb.substring(1);
        }
        return Integer.parseInt(rrggbb, 16);
    }

}

@@ -52,33 +52,375 @@
 or;%0A
-%0Apublic class ColorUtil %7B
+import java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Apublic class ColorUtil %7B%0A    // rgb(255,0,0)%0A    private static final Pattern RGB = Pattern.compile(%22rgb *%5C%5C( *(%5B0-9%5D+), *(%5B0-9%5D+), *(%5B0-9%5D+) *%5C%5C)%22);%0A    // rgba(255,0,0,0.5)%0A    private static final Pattern RGBA = Pattern.compile(%22rgba *%5C%5C( *(%5B0-9%5D+), *(%5B0-9%5D+), *(%5B0-9%5D+), *(%5B0,1%5D%5B.%5D?%5B0-9%5D*) *%5C%5C)%22);%0A
 %0A   
@@ -450,38 +450,37 @@
 rseColor(String 
-rrggbb
+color
 ) %7B%0A        if (
@@ -479,22 +479,21 @@
     if (
-rrggbb
+color
  == null
@@ -496,22 +496,21 @@
 null %7C%7C 
-rrggbb
+color
 .isEmpty
@@ -562,61 +562,754 @@
     
-return new Color(parseRGB(rrggbb));%0A    %7D%0A%0A    public
+if (color.charAt(0) == '#') %7B%0A            return new Color(parseHEX(color));%0A        %7D%0A        Matcher matcher = RGBA.matcher(color);%0A        if (matcher.matches())%7B%0A            return new Color(Integer.valueOf(matcher.group(1)),%0A                    Integer.valueOf(matcher.group(2)),%0A                    Integer.valueOf(matcher.group(3)),%0A                    (int) (Float.parseFloat(matcher.group(4)) * 255 + 0.5) );%0A        %7D%0A        matcher = RGB.matcher(color);%0A        if (matcher.matches()) %7B%0A            return new Color(Integer.valueOf(matcher.group(1)),%0A                    Integer.valueOf(matcher.group(2)),%0A                    Integer.valueOf(matcher.group(3)));%0A        %7D%0A        return new Color(parseHEX(color));%0A%0A    %7D%0A%0A    private
  sta
@@ -1321,19 +1321,19 @@
 nt parse
-RGB
+HEX
 (String 

add support for rgb and rgba