001: /* SwingML
002: * Copyright (C) 2002 SwingML Team
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: *
019: * Authors:
020: * Ezequiel Cuellar <ecuellar@crosslogic.com>
021: * Marcelo W. Lopez Cremona <marcelo_java@argentina.com>
022: * Hamdi Mohs Yusof <hamdi@medical-online.net>
023: */
024:
025: package org.swingml.component;
026:
027: import java.awt.*;
028:
029: import org.swingml.*;
030:
031: public class ColorComponent extends Color {
032:
033: public static ColorComponent getColorByName(String color) {
034: ColorComponent theColorComponent = null;
035: if (color.equalsIgnoreCase(Constants.BLACK)) {
036: theColorComponent = new ColorComponent(Color.BLACK.getRGB());
037: }
038: if (color.equalsIgnoreCase(Constants.BLUE)) {
039: theColorComponent = new ColorComponent(Color.BLUE.getRGB());
040: }
041: if (color.equalsIgnoreCase(Constants.CYAN)) {
042: theColorComponent = new ColorComponent(Color.CYAN.getRGB());
043: }
044: if (color.equalsIgnoreCase(Constants.GRAY)) {
045: theColorComponent = new ColorComponent(Color.GRAY.getRGB());
046: }
047: if (color.equalsIgnoreCase(Constants.GREEN)) {
048: theColorComponent = new ColorComponent(Color.GREEN.getRGB());
049: }
050: if (color.equalsIgnoreCase(Constants.MAGENTA)) {
051: theColorComponent = new ColorComponent(Color.MAGENTA
052: .getRGB());
053: }
054: if (color.equalsIgnoreCase(Constants.ORANGE)) {
055: theColorComponent = new ColorComponent(Color.ORANGE
056: .getRGB());
057: }
058: if (color.equalsIgnoreCase(Constants.PINK)) {
059: theColorComponent = new ColorComponent(Color.PINK.getRGB());
060: }
061: if (color.equalsIgnoreCase(Constants.RED)) {
062: theColorComponent = new ColorComponent(Color.RED.getRGB());
063: }
064: if (color.equalsIgnoreCase(Constants.WHITE)) {
065: theColorComponent = new ColorComponent(Color.WHITE.getRGB());
066: }
067: if (color.equalsIgnoreCase(Constants.YELLOW)) {
068: theColorComponent = new ColorComponent(Color.YELLOW
069: .getRGB());
070: }
071: if (color.charAt(0) == '#') {
072: theColorComponent = new ColorComponent(Integer
073: .parseInt(color.substring(1)));
074: }
075: return theColorComponent;
076: }
077:
078: public ColorComponent(int aRgb) {
079: super (aRgb);
080: }
081:
082: public ColorComponent(int r, int g, int b) {
083: super (r, g, b);
084: }
085:
086: public String toString() {
087: String theColor = "";
088: if (this .equals(Color.BLACK)) {
089: theColor = "black";
090: }
091: if (this .equals(Color.BLUE)) {
092: theColor = "blue";
093: }
094: if (this .equals(Color.CYAN)) {
095: theColor = "cyan";
096: }
097: if (this .equals(Color.GRAY)) {
098: theColor = "gray";
099: }
100: if (this .equals(Color.GREEN)) {
101: theColor = "green";
102: }
103: if (this .equals(Color.MAGENTA)) {
104: theColor = "magenta";
105: }
106: if (this .equals(Color.ORANGE)) {
107: theColor = "orange";
108: }
109: if (this .equals(Color.PINK)) {
110: theColor = "pink";
111: }
112: if (this .equals(Color.RED)) {
113: theColor = "red";
114: }
115: if (this .equals(Color.WHITE)) {
116: theColor = "white";
117: }
118: if (this .equals(Color.YELLOW)) {
119: theColor = "yellow";
120: }
121: return theColor;
122: }
123:
124: }
|