]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/ColorUtil.java
Dynamic terminals and connections
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / utils / ColorUtil.java
index 8479cd717602650bf9531881cdb3156d1309e5de..300938261329fb6e98dc16073693c58ea15f7bb0 100644 (file)
@@ -81,6 +81,20 @@ public class ColorUtil {
            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;
+    }
 
 }