01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
10: http://www.apache.org/licenses/LICENSE-2.0
11:
12: Unless required by applicable law or agreed to in writing, software
13: distributed under the License is distributed on an "AS IS" BASIS,
14: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: See the License for the specific language governing permissions and
16: limitations under the License.
17:
18: */
19: package org.apache.batik.css.engine.value;
20:
21: import org.w3c.dom.DOMException;
22: import org.w3c.dom.css.CSSPrimitiveValue;
23:
24: /**
25: * This class represents RGB colors.
26: *
27: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
28: * @version $Id: RGBColorValue.java 478160 2006-11-22 13:35:06Z dvholten $
29: */
30: public class RGBColorValue extends AbstractValue {
31:
32: /**
33: * The red component.
34: */
35: protected Value red;
36:
37: /**
38: * The green component.
39: */
40: protected Value green;
41:
42: /**
43: * The blue component.
44: */
45: protected Value blue;
46:
47: /**
48: * Creates a new RGBColorValue.
49: */
50: public RGBColorValue(Value r, Value g, Value b) {
51: red = r;
52: green = g;
53: blue = b;
54: }
55:
56: /**
57: * The type of the value.
58: */
59: public short getPrimitiveType() {
60: return CSSPrimitiveValue.CSS_RGBCOLOR;
61: }
62:
63: /**
64: * A string representation of the current value.
65: */
66: public String getCssText() {
67: return "rgb(" + red.getCssText() + ", " + green.getCssText()
68: + ", " + blue.getCssText() + ')';
69: }
70:
71: /**
72: * Implements {@link Value#getRed()}.
73: */
74: public Value getRed() throws DOMException {
75: return red;
76: }
77:
78: /**
79: * Implements {@link Value#getGreen()}.
80: */
81: public Value getGreen() throws DOMException {
82: return green;
83: }
84:
85: /**
86: * Implements {@link Value#getBlue()}.
87: */
88: public Value getBlue() throws DOMException {
89: return blue;
90: }
91:
92: /**
93: * Returns a printable representation of the color.
94: */
95: public String toString() {
96: return getCssText();
97: }
98: }
|