KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > optional > image > ColorMapper


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.types.optional.image;
19
20 import java.awt.Color JavaDoc;
21
22 /**
23  *
24  * @see org.apache.tools.ant.taskdefs.optional.image.Image
25  */

26 public final class ColorMapper {
27     /** private constructor for Utility class */
28     private ColorMapper() {
29     }
30
31     /** black string */
32     public static final String JavaDoc COLOR_BLACK = "black";
33     /** blue string */
34     public static final String JavaDoc COLOR_BLUE = "blue";
35     /** cyan string */
36     public static final String JavaDoc COLOR_CYAN = "cyan";
37     /** black string */
38     public static final String JavaDoc COLOR_DARKGRAY = "darkgray";
39     /** gray string */
40     public static final String JavaDoc COLOR_GRAY = "gray";
41     /** lightgray string */
42     public static final String JavaDoc COLOR_LIGHTGRAY = "lightgray";
43     // Gotta atleast put in the proper spelling :-P
44
/** darkgrey string */
45     public static final String JavaDoc COLOR_DARKGREY = "darkgrey";
46     /** grey string */
47     public static final String JavaDoc COLOR_GREY = "grey";
48     /** lightgrey string */
49     public static final String JavaDoc COLOR_LIGHTGREY = "lightgrey";
50     /** green string */
51     public static final String JavaDoc COLOR_GREEN = "green";
52     /** magenta string */
53     public static final String JavaDoc COLOR_MAGENTA = "magenta";
54     /** orange string */
55     public static final String JavaDoc COLOR_ORANGE = "orange";
56     /** pink string */
57     public static final String JavaDoc COLOR_PINK = "pink";
58     /** reg string */
59     public static final String JavaDoc COLOR_RED = "red";
60     /** white string */
61     public static final String JavaDoc COLOR_WHITE = "white";
62     /** yellow string */
63     public static final String JavaDoc COLOR_YELLOW = "yellow";
64
65     /**
66      * Convert a color name to a color value.
67      * @param colorName a string repr of the color.
68      * @return the color value.
69      * @todo refactor to use an EnumeratedAttribute (maybe?)
70      */

71     public static Color JavaDoc getColorByName(String JavaDoc colorName) {
72         colorName = colorName.toLowerCase();
73
74         if (colorName.equals(COLOR_BLACK)) {
75             return Color.black;
76         } else if (colorName.equals(COLOR_BLUE)) {
77             return Color.blue;
78         } else if (colorName.equals(COLOR_CYAN)) {
79             return Color.cyan;
80         } else if (colorName.equals(COLOR_DARKGRAY) || colorName.equals(COLOR_DARKGREY)) {
81             return Color.darkGray;
82         } else if (colorName.equals(COLOR_GRAY) || colorName.equals(COLOR_GREY)) {
83             return Color.gray;
84         } else if (colorName.equals(COLOR_LIGHTGRAY) || colorName.equals(COLOR_LIGHTGREY)) {
85             return Color.lightGray;
86         } else if (colorName.equals(COLOR_GREEN)) {
87             return Color.green;
88         } else if (colorName.equals(COLOR_MAGENTA)) {
89             return Color.magenta;
90         } else if (colorName.equals(COLOR_ORANGE)) {
91             return Color.orange;
92         } else if (colorName.equals(COLOR_PINK)) {
93             return Color.pink;
94         } else if (colorName.equals(COLOR_RED)) {
95             return Color.red;
96         } else if (colorName.equals(COLOR_WHITE)) {
97             return Color.white;
98         } else if (colorName.equals(COLOR_YELLOW)) {
99             return Color.yellow;
100         }
101         return Color.black;
102     }
103
104 }
105
Popular Tags