KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > ARGBChannel


1 /*
2
3    Copyright 2001 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    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.batik.ext.awt.image;
19
20 import java.io.Serializable JavaDoc;
21
22 /**
23  * Enumerated type for an ARGB Channel selector.
24  *
25  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
26  * @version $Id: ARGBChannel.java,v 1.3 2004/08/18 07:13:48 vhardy Exp $
27  */

28 public final class ARGBChannel implements Serializable JavaDoc{
29     /**
30      * Types.
31      *
32      */

33     public static final int CHANNEL_A = 3;
34     public static final int CHANNEL_R = 2;
35     public static final int CHANNEL_G = 1;
36     public static final int CHANNEL_B = 0;
37
38     /**
39      * Strings used to get a more readable output when
40      * a value is displayed.
41      */

42     public static final String JavaDoc RED = "Red";
43     public static final String JavaDoc GREEN = "Green";
44     public static final String JavaDoc BLUE = "Blue";
45     public static final String JavaDoc ALPHA = "Alpha";
46
47     /**
48      * Channel values
49      */

50     public static final ARGBChannel R
51         = new ARGBChannel(CHANNEL_R, RED);
52     public static final ARGBChannel G
53         = new ARGBChannel(CHANNEL_G, GREEN);
54     public static final ARGBChannel B
55         = new ARGBChannel(CHANNEL_B, BLUE);
56     public static final ARGBChannel A
57         = new ARGBChannel(CHANNEL_A, ALPHA);
58
59     /**
60      * All values
61      */

62     private static final
63         ARGBChannel[] enumValues = {R, G, B, A};
64
65     private String JavaDoc desc;
66     private int val;
67
68     /**
69      * Constructor is private so that no instances other than
70      * the ones in the enumeration can be created.
71      * @see #readResolve
72      */

73     private ARGBChannel(int val, String JavaDoc desc){
74         this.desc = desc;
75         this.val = val;
76     }
77     
78     /**
79      * @return description
80      */

81     public String JavaDoc toString(){
82         return desc;
83     }
84
85     /**
86      * Convenience for enumeration switching
87      * @return value
88      */

89     public int toInt(){
90         return val;
91     }
92
93
94     /**
95      * This is called by the serialization code before it returns an unserialized
96      * object. To provide for unicity of instances, the instance that was read
97      * is replaced by its static equivalent
98      */

99     public Object JavaDoc readResolve() {
100         switch(val){
101         case CHANNEL_R:
102             return R;
103         case CHANNEL_G:
104             return G;
105         case CHANNEL_B:
106             return B;
107         case CHANNEL_A:
108             return A;
109         default:
110             throw new Error JavaDoc("Unknown ARGBChannel value");
111         }
112     }
113 }
114
Popular Tags