001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.app;
031:
032: import java.io.Serializable;
033:
034: /**
035: * A representation of a 24-bit RGB color.
036: */
037: public class Color implements Serializable {
038:
039: /** The color black. */
040: public static final Color BLACK = new Color(0x00, 0x00, 0x00);
041:
042: /** The color blue. */
043: public static final Color BLUE = new Color(0x00, 0x00, 0xff);
044:
045: /** The color green. */
046: public static final Color GREEN = new Color(0x00, 0xff, 0x00);
047:
048: /** The color cyan. */
049: public static final Color CYAN = new Color(0x00, 0xff, 0xff);
050:
051: /** The color red. */
052: public static final Color RED = new Color(0xff, 0x00, 0x00);
053:
054: /** The color magenta. */
055: public static final Color MAGENTA = new Color(0xff, 0x00, 0xff);
056:
057: /** The color yellow. */
058: public static final Color YELLOW = new Color(0xff, 0xff, 0x00);
059:
060: /** The color white. */
061: public static final Color WHITE = new Color(0xff, 0xff, 0xff);
062:
063: /** The color dark gray. */
064: public static final Color DARKGRAY = new Color(0x7f, 0x7f, 0x7f);
065:
066: /** The color light gray. */
067: public static final Color LIGHTGRAY = new Color(0xaf, 0xaf, 0xaf);
068:
069: /** The color orange. */
070: public static final Color ORANGE = new Color(0xff, 0xaf, 0x00);
071:
072: /** The color pink. */
073: public static final Color PINK = new Color(0xff, 0xaf, 0xaf);
074:
075: private int rgb;
076:
077: /**
078: * Creates a new color from an integer value.
079: * The value should be of the for 0xRRGGBB.
080: *
081: * @param rgb an integer representation for a color
082: */
083: public Color(int rgb) {
084: this .rgb = rgb;
085: }
086:
087: /**
088: * Creates a new color with specified red, green, and blue values. Each
089: * value may range from 0 to 255.
090: *
091: * @param r the red component value
092: * @param g the green component value
093: * @param b the blue component value
094: */
095: public Color(int r, int g, int b) {
096: this .rgb = ((r & 0xff) << 16) | ((g & 0xff) << 8) | b & 0xff;
097: }
098:
099: /**
100: * @see java.lang.Object#equals(java.lang.Object)
101: */
102: public boolean equals(Object o) {
103: boolean equal;
104:
105: if (this == o) {
106: equal = true;
107: } else if (o instanceof Color) {
108: Color that = (Color) o;
109: equal = this .rgb == that.rgb;
110: } else {
111: equal = false;
112: }
113:
114: return equal;
115: }
116:
117: /**
118: * Returns the blue component value of this color.
119: *
120: * @return the blue component value of this color, from 0 to 255
121: */
122: public int getBlue() {
123: return rgb & 0xff;
124: }
125:
126: /**
127: * Returns the green component value of this color.
128: *
129: * @return the green component value of this color, from 0 to 255
130: */
131: public int getGreen() {
132: return (rgb >> 8) & 0xff;
133: }
134:
135: /**
136: * Returns the red component value of this color.
137: *
138: * @return the red component value of this color, from 0 to 255
139: */
140: public int getRed() {
141: return rgb >> 16;
142: }
143:
144: /**
145: * Returns the color as an RGB value.
146: *
147: * @return the color as an RGB value
148: */
149: public int getRgb() {
150: return rgb;
151: }
152:
153: /**
154: * @see java.lang.Object#hashCode()
155: */
156: public int hashCode() {
157: return getRgb();
158: }
159:
160: /**
161: * @see java.lang.Object#toString()
162: */
163: public String toString() {
164: return getClass().getName() + " [r=" + getRed() + ",g="
165: + getGreen() + ",b=" + getBlue() + "]";
166: }
167: }
|