001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.ext.awt.image;
020:
021: import java.io.Serializable;
022:
023: /**
024: * Enumerated type for an ARGB Channel selector.
025: *
026: * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
027: * @version $Id: ARGBChannel.java 475477 2006-11-15 22:44:28Z cam $
028: */
029: public final class ARGBChannel implements Serializable {
030: /**
031: * Types.
032: *
033: */
034: public static final int CHANNEL_A = 3;
035: public static final int CHANNEL_R = 2;
036: public static final int CHANNEL_G = 1;
037: public static final int CHANNEL_B = 0;
038:
039: /**
040: * Strings used to get a more readable output when
041: * a value is displayed.
042: */
043: public static final String RED = "Red";
044: public static final String GREEN = "Green";
045: public static final String BLUE = "Blue";
046: public static final String ALPHA = "Alpha";
047:
048: /**
049: * Channel values
050: */
051: public static final ARGBChannel R = new ARGBChannel(CHANNEL_R, RED);
052: public static final ARGBChannel G = new ARGBChannel(CHANNEL_G,
053: GREEN);
054: public static final ARGBChannel B = new ARGBChannel(CHANNEL_B, BLUE);
055: public static final ARGBChannel A = new ARGBChannel(CHANNEL_A,
056: ALPHA);
057:
058: private String desc;
059: private int val;
060:
061: /**
062: * Constructor is private so that no instances other than
063: * the ones in the enumeration can be created.
064: * @see #readResolve
065: */
066: private ARGBChannel(int val, String desc) {
067: this .desc = desc;
068: this .val = val;
069: }
070:
071: /**
072: * @return description
073: */
074: public String toString() {
075: return desc;
076: }
077:
078: /**
079: * Convenience for enumeration switching
080: * @return value
081: */
082: public int toInt() {
083: return val;
084: }
085:
086: /**
087: * This is called by the serialization code before it returns an unserialized
088: * object. To provide for unicity of instances, the instance that was read
089: * is replaced by its static equivalent
090: */
091: public Object readResolve() {
092: switch (val) {
093: case CHANNEL_R:
094: return R;
095: case CHANNEL_G:
096: return G;
097: case CHANNEL_B:
098: return B;
099: case CHANNEL_A:
100: return A;
101: default:
102: throw new Error("Unknown ARGBChannel value");
103: }
104: }
105: }
|