1 30 31 package rcm.awt; 32 33 import java.util.Hashtable ; 34 import java.awt.Color ; 35 36 public abstract class Colors { 37 38 static Hashtable colors = new Hashtable (); 39 static { 40 colors.put ("black", Color.black); 41 colors.put ("blue", Color.blue); 42 colors.put ("cyan", Color.cyan); 43 colors.put ("darkGray", Color.darkGray); 44 colors.put ("gray", Color.gray); 45 colors.put ("green", Color.green); 46 colors.put ("lightGray", Color.lightGray); 47 colors.put ("magenta", Color.magenta); 48 colors.put ("orange", Color.orange); 49 colors.put ("pink", Color.pink); 50 colors.put ("red", Color.red); 51 colors.put ("white", Color.white); 52 colors.put ("yellow", Color.yellow); 53 } 54 55 public static Color parseColor (String name) { 56 if (name == null) 57 return null; 58 59 Color c = (Color )colors.get (name); 60 61 if (c != null) 62 return c; 63 else if (name.startsWith ("#") && name.length() == 7) { 64 c = new Color (Integer.parseInt(name.substring (1, 3), 16), 65 Integer.parseInt(name.substring (3, 5), 16), 66 Integer.parseInt(name.substring (5, 7), 16)); 67 colors.put (name, c); 68 return c; 69 } 70 else 71 return null; } 73 74 } 75 | Popular Tags |