001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.swing.plaf.synth;
019:
020: import org.apache.harmony.x.swing.internal.nls.Messages;
021:
022: /**
023: * The class used to mark the states in coloring JComponents
024: */
025: public class ColorType {
026:
027: public static final ColorType FOCUS = new ColorType("focus"); //$NON-NLS-1$
028:
029: public static final ColorType BACKGROUND = new ColorType(
030: "background"); //$NON-NLS-1$
031:
032: public static final ColorType FOREGROUND = new ColorType(
033: "foreground"); //$NON-NLS-1$
034:
035: public static final ColorType TEXT_BACKGROUND = new ColorType(
036: "text_background"); //$NON-NLS-1$
037:
038: public static final ColorType TEXT_FOREGROUND = new ColorType(
039: "text_foreground"); //$NON-NLS-1$
040:
041: /**
042: * The maximum number of created color types. This field exist for
043: * compatibility with RI only
044: */
045: public static final int MAX_COUNT = 5;
046:
047: /**
048: * The field is used for ID calculation
049: */
050: private static int count = 0;
051:
052: /**
053: * Textual description for ColorType
054: */
055: private String description;
056:
057: private int id;
058:
059: protected ColorType(String description) {
060: this .description = description;
061: this .id = count;
062: count++;
063: }
064:
065: /** @return The unique number id of the current ColorType */
066: public final int getID() {
067: return id;
068: }
069:
070: /** @return String describes ColorType */
071: @Override
072: public String toString() {
073: return this .description;
074: }
075:
076: /**
077: * The method works for predefined (static fields) ColorTypes
078: *
079: * @param key
080: * The ColorType name (description)
081: * @return corresponding to name ColorType.
082: */
083: static ColorType calculateColorType(String key) {
084:
085: if (key == null) {
086: return null;
087: }
088:
089: key = key.toUpperCase().intern();
090:
091: if (key == "BACKGROUND") { //$NON-NLS-1$
092: return BACKGROUND;
093: } else if (key == "FOREGROUND") { //$NON-NLS-1$
094: return FOREGROUND;
095: } else if (key == "TEXT_BACKGROUND") { //$NON-NLS-1$
096: return TEXT_BACKGROUND;
097: } else if (key == "TEXT_FOREGROUND") { //$NON-NLS-1$
098: return TEXT_FOREGROUND;
099: } else if (key == "FOCUS") { //$NON-NLS-1$
100: return FOCUS;
101: }
102: throw new IllegalStateException(Messages
103: .getString("swing.err.1C") //$NON-NLS-1$
104: + key);
105: }
106:
107: }
|