KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > value > svg > ICCColor


1 /*
2
3    Copyright 2002-2003 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.css.engine.value.svg;
19
20 import org.apache.batik.css.engine.value.AbstractValue;
21 import org.w3c.dom.DOMException JavaDoc;
22 import org.w3c.dom.css.CSSValue;
23
24 /**
25  * This class represents an ICC color value.
26  *
27  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
28  * @version $Id: ICCColor.java,v 1.4 2004/08/18 07:12:57 vhardy Exp $
29  */

30 public class ICCColor extends AbstractValue {
31     
32     /**
33      * The color profile.
34      */

35     protected String JavaDoc colorProfile;
36
37     /**
38      * The color count.
39      */

40     protected int count;
41
42     /**
43      * The colors.
44      */

45     protected float[] colors = new float[5];
46
47     /**
48      * Creates a new ICCColor.
49      */

50     public ICCColor(String JavaDoc name) {
51         colorProfile = name;
52     }
53
54     /**
55      * Implements {@link
56      * org.apache.batik.css.engine.value.Value#getCssValueType()}.
57      */

58     public short getCssValueType() {
59         return CSSValue.CSS_CUSTOM;
60     }
61
62     /**
63      * Returns the color name.
64      */

65     public String JavaDoc getColorProfile() throws DOMException JavaDoc {
66         return colorProfile;
67     }
68
69     /**
70      * Returns the number of colors.
71      */

72     public int getNumberOfColors() throws DOMException JavaDoc {
73         return count;
74     }
75
76     /**
77      * Returns the color at the given index.
78      */

79     public float getColor(int i) throws DOMException JavaDoc {
80         return colors[i];
81     }
82
83     /**
84      * A string representation of the current value.
85      */

86     public String JavaDoc getCssText() {
87         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
88         sb.append("icc-color(");
89         sb.append(colorProfile);
90         for (int i = 0; i < count; i++) {
91             sb.append(", ");
92             sb.append(colors[i]);
93         }
94         sb.append(")");
95         return sb.toString();
96     }
97
98     /**
99      * Appends a color to the list.
100      */

101     public void append(float c) {
102         if (count == colors.length) {
103             float[] t = new float[count * 2];
104             for (int i = 0; i < count; i++) {
105                 t[i] = colors[i];
106             }
107             colors = t;
108         }
109         colors[count++] = c;
110     }
111 }
112
Popular Tags