1 23 24 package org.infoglue.deliver.util.graphics; 25 26 import java.awt.Color ; 27 import java.util.StringTokenizer ; 28 29 import org.infoglue.deliver.util.MathHelper; 30 31 35 36 public class ColorHelper 37 { 38 public ColorHelper() 39 { 40 } 41 42 45 46 public Color getColor(int r, int g, int b) 47 { 48 return new Color (r, g, b); 49 } 50 51 52 55 56 public Color getHexColor(String hexadecimalValue) 57 { 58 return new Color (new MathHelper().hexToDecimal(hexadecimalValue)); 59 } 60 61 67 public static Color getColor( String colonSeparatedRGBA ) 68 { 69 return ColorHelper.getColor( colonSeparatedRGBA, ":" ); 70 } 71 72 80 81 public static Color getColor( String separatedRGBA, String delimiter ) 82 { 83 StringTokenizer st = new StringTokenizer ( separatedRGBA, delimiter, false ); 85 int r = 0, g = 0, b = 0, a = 0; 86 if ( st.hasMoreTokens() ) 87 { 88 r = Integer.parseInt( st.nextToken().trim() ); 89 } 90 if ( st.hasMoreTokens() ) 91 { 92 g = Integer.parseInt( st.nextToken().trim() ); 93 } 94 if ( st.hasMoreTokens() ) 95 { 96 b = Integer.parseInt( st.nextToken().trim() ); 97 } 98 if ( st.hasMoreTokens() ) 99 { 100 a = Integer.parseInt( st.nextToken().trim() ); 101 } 102 return new Color ( r, g, b, a ); 104 } 105 106 } 107 | Popular Tags |