001package polaris.sdk.ui;
002/** ARGB colors. No additional color library or JavaFX dependency. */
003public final class Colors {
004 public static final int BLACK=0xff000000,WHITE=0xffffffff,TRANSPARENT=0;
005 public static int rgb(int r,int g,int b){return rgba(r,g,b,255);}
006 public static int rgba(int r,int g,int b,int a){check(r);check(g);check(b);check(a);return a<<24|r<<16|g<<8|b;}
007 /** Accepts #RRGGBB or #AARRGGBB, not CSS #RRGGBBAA. */
008 public static int hex(String value){if(value==null)throw new NullPointerException("color");String s=value.startsWith("#")?value.substring(1):value;if(!s.matches("[0-9a-fA-F]{6}([0-9a-fA-F]{2})?"))throw new IllegalArgumentException("Expected RRGGBB or AARRGGBB");long n=Long.parseLong(s,16);return (int)(s.length()==6?n|0xff000000L:n);}
009 private static void check(int v){if(v<0||v>255)throw new IllegalArgumentException("Channel must be 0..255");}
010 private Colors(){}
011}