1 29 30 package nextapp.echo2.app; 31 32 import java.io.Serializable ; 33 34 37 public class Color 38 implements Serializable { 39 40 41 public static final Color BLACK = new Color(0x00, 0x00, 0x00); 42 43 44 public static final Color BLUE = new Color(0x00, 0x00, 0xff); 45 46 47 public static final Color GREEN = new Color(0x00, 0xff, 0x00); 48 49 50 public static final Color CYAN = new Color(0x00, 0xff, 0xff); 51 52 53 public static final Color RED = new Color(0xff, 0x00, 0x00); 54 55 56 public static final Color MAGENTA = new Color(0xff, 0x00, 0xff); 57 58 59 public static final Color YELLOW = new Color(0xff, 0xff, 0x00); 60 61 62 public static final Color WHITE = new Color(0xff, 0xff, 0xff); 63 64 65 public static final Color DARKGRAY = new Color(0x7f, 0x7f, 0x7f); 66 67 68 public static final Color LIGHTGRAY = new Color(0xaf, 0xaf, 0xaf); 69 70 71 public static final Color ORANGE = new Color(0xff, 0xaf, 0x00); 72 73 74 public static final Color PINK = new Color(0xff, 0xaf, 0xaf); 75 76 private int rgb; 77 78 84 public Color(int rgb) { 85 this.rgb = rgb; 86 } 87 88 96 public Color(int r, int g, int b) { 97 this.rgb = ((r & 0xff) << 16) | ((g & 0xff) << 8) | b & 0xff; 98 } 99 100 103 public boolean equals(Object o) { 104 boolean equal; 105 106 if (this == o) { 107 equal = true; 108 } else if (o instanceof Color) { 109 Color that = (Color) o; 110 equal = this.rgb == that.rgb; 111 } else { 112 equal = false; 113 } 114 115 return equal; 116 } 117 118 123 public int getBlue() { 124 return rgb & 0xff; 125 } 126 127 132 public int getGreen() { 133 return (rgb >> 8) & 0xff; 134 } 135 136 141 public int getRed() { 142 return rgb >> 16; 143 } 144 145 150 public int getRgb() { 151 return rgb; 152 } 153 154 157 public int hashCode() { 158 return getRgb(); 159 } 160 161 164 public String toString() { 165 return getClass().getName() + " [r=" + getRed() + ",g=" + getGreen() + ",b=" + getBlue() + "]"; 166 } 167 } 168 | Popular Tags |