X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Futils%2FColorUtil.java;h=300938261329fb6e98dc16073693c58ea15f7bb0;hp=8479cd717602650bf9531881cdb3156d1309e5de;hb=2e21c89c81d449bcc2301b3cf3cce4f2cd403a60;hpb=edbb4df64407826271ee6423451401684e9cd68c diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/ColorUtil.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/ColorUtil.java index 8479cd717..300938261 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/ColorUtil.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/ColorUtil.java @@ -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; + } }