KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > elementprocessor > impl > poi > hssf > elements > ColorCode


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

16
17 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements;
18
19 import java.io.IOException JavaDoc;
20
21 import java.util.StringTokenizer JavaDoc;
22
23 /**
24  * Color codes
25  *
26  * @author Marc Johnson (marc_johnson27591@hotmail.com)
27  * @author Andrew C. Oliver (acoliver2@users.sourceforge.net)
28  * @version CVS $Id: ColorCode.java 30932 2004-07-29 17:35:38Z vgritsenko $
29  */

30 public class ColorCode {
31     private static final int _red = 0;
32     private static final int _green = 1;
33     private static final int _blue = 2;
34     private static final int _component_count = 3;
35     private int[] _components = new int[ _component_count ];
36     private String JavaDoc rgbstring = null;
37
38     /**
39      * construct the ColorCode object
40      *
41      * @param value the string containing the colors
42      *
43      * @exception IOException if the string is badly formed
44      */

45
46     public ColorCode(final String JavaDoc value) throws IOException JavaDoc {
47         rgbstring = value;
48         if (value == null) {
49             throw new IOException JavaDoc("cannot process a null color code");
50         }
51         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value.trim(), ":");
52
53         if (tokenizer.countTokens() != _component_count) {
54             throw new IOException JavaDoc("color code must have exactly "
55                       + _component_count + " components, no more, no less");
56         }
57         for (int j = 0; j < _component_count; j++) {
58             try {
59                 _components[j] = Integer.parseInt(tokenizer.nextToken(), 16);
60             } catch (Exception JavaDoc e) {
61                 throw new IOException JavaDoc("cannot parse component #" + j + " ("
62                                       + e.getMessage() + ")");
63             }
64             if (_components[j] < 0 || _components[j] > 65535) {
65                 throw new IOException JavaDoc("Component #" + j + " is out of range");
66             }
67         }
68     }
69
70     /**
71      * @return red component
72      */

73
74     public int getRed() {
75         return _components[_red];
76     }
77
78     /**
79      * @return green component
80      */

81
82     public int getGreen() {
83         return _components[_green];
84     }
85
86     /**
87      * @return blue component
88      */

89
90     public int getBlue() {
91         return _components[_blue];
92     }
93     
94     public String JavaDoc toString() {
95         return rgbstring;
96     }
97 } // end public class ColorCode
98
Popular Tags