001: /*
002:
003: ============================================================================
004: The Apache Software License, Version 1.1
005: ============================================================================
006:
007: Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
008:
009: Redistribution and use in source and binary forms, with or without modifica-
010: tion, are permitted provided that the following conditions are met:
011:
012: 1. Redistributions of source code must retain the above copyright notice,
013: this list of conditions and the following disclaimer.
014:
015: 2. Redistributions in binary form must reproduce the above copyright notice,
016: this list of conditions and the following disclaimer in the documentation
017: and/or other materials provided with the distribution.
018:
019: 3. The end-user documentation included with the redistribution, if any, must
020: include the following acknowledgment: "This product includes software
021: developed by the Apache Software Foundation (http://www.apache.org/)."
022: Alternately, this acknowledgment may appear in the software itself, if
023: and wherever such third-party acknowledgments normally appear.
024:
025: 4. The names "Batik" and "Apache Software Foundation" must not be
026: used to endorse or promote products derived from this software without
027: prior written permission. For written permission, please contact
028: apache@apache.org.
029:
030: 5. Products derived from this software may not be called "Apache", nor may
031: "Apache" appear in their name, without prior written permission of the
032: Apache Software Foundation.
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
035: INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
036: FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
037: APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
038: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
039: DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
040: OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
041: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
042: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
043: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
044:
045: This software consists of voluntary contributions made by many individuals
046: on behalf of the Apache Software Foundation. For more information on the
047: Apache Software Foundation, please see <http://www.apache.org/>.
048:
049: */
050:
051: package org.apache.batik.css.engine.value;
052:
053: import org.w3c.dom.DOMException; // BEGIN RAVE MODIFICATIONS
054: import org.w3c.dom.css.CSSPrimitiveValue;
055:
056: // END RAVE MODIFICATIONS
057:
058: /**
059: * This class represents a computed property value.
060: *
061: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
062: * @version $Id$
063: */
064: public class ComputedValue implements Value {
065:
066: /**
067: * The cascaded value.
068: */
069: protected Value cascadedValue;
070:
071: /**
072: * The computed value.
073: */
074: protected Value computedValue;
075:
076: /**
077: * Creates a new ComputedValue object.
078: * @param cv The cascaded value.
079: */
080: public ComputedValue(Value cv) {
081: cascadedValue = cv;
082: }
083:
084: /**
085: * Returns the computed value.
086: */
087: public Value getComputedValue() {
088: return computedValue;
089: }
090:
091: /**
092: * Returns the cascaded value.
093: */
094: public Value getCascadedValue() {
095: return cascadedValue;
096: }
097:
098: /**
099: * Sets the computed value.
100: */
101: public void setComputedValue(Value v) {
102: computedValue = v;
103: }
104:
105: /**
106: * Implements {@link Value#getCssText()}.
107: */
108: public String getCssText() {
109: return computedValue.getCssText();
110: }
111:
112: /**
113: * Implements {@link Value#getCssValueType()}.
114: */
115: public short getCssValueType() {
116: return computedValue.getCssValueType();
117: }
118:
119: /**
120: * Implements {@link Value#getPrimitiveType()}.
121: */
122: public short getPrimitiveType() {
123: return computedValue.getPrimitiveType();
124: }
125:
126: /**
127: * Implements {@link Value#getFloatValue()}.
128: */
129: public float getFloatValue() throws DOMException {
130: return computedValue.getFloatValue();
131: }
132:
133: /**
134: * Implements {@link Value#getStringValue()}.
135: */
136: public String getStringValue() throws DOMException {
137: return computedValue.getStringValue();
138: }
139:
140: /**
141: * Implements {@link Value#getRed()}.
142: */
143: public Value getRed() throws DOMException {
144: return computedValue.getRed();
145: }
146:
147: /**
148: * Implements {@link Value#getGreen()}.
149: */
150: public Value getGreen() throws DOMException {
151: return computedValue.getGreen();
152: }
153:
154: /**
155: * Implements {@link Value#getBlue()}.
156: */
157: public Value getBlue() throws DOMException {
158: return computedValue.getBlue();
159: }
160:
161: /**
162: * Implements {@link Value#getLength()}.
163: */
164: public int getLength() throws DOMException {
165: return computedValue.getLength();
166: }
167:
168: /**
169: * Implements {@link Value#item(int)}.
170: */
171: public Value item(int index) throws DOMException {
172: return computedValue.item(index);
173: }
174:
175: /**
176: * Implements {@link Value#getTop()}.
177: */
178: public Value getTop() throws DOMException {
179: return computedValue.getTop();
180: }
181:
182: /**
183: * Implements {@link Value#getRight()}.
184: */
185: public Value getRight() throws DOMException {
186: return computedValue.getRight();
187: }
188:
189: /**
190: * Implements {@link Value#getBottom()}.
191: */
192: public Value getBottom() throws DOMException {
193: return computedValue.getBottom();
194: }
195:
196: /**
197: * Implements {@link Value#getLeft()}.
198: */
199: public Value getLeft() throws DOMException {
200: return computedValue.getLeft();
201: }
202:
203: /**
204: * Implements {@link Value#getIdentifier()}.
205: */
206: public String getIdentifier() throws DOMException {
207: return computedValue.getIdentifier();
208: }
209:
210: /**
211: * Implements {@link Value#getListStyle()}.
212: */
213: public String getListStyle() throws DOMException {
214: return computedValue.getListStyle();
215: }
216:
217: /**
218: * Implements {@link Value#getSeparator()}.
219: */
220: public String getSeparator() throws DOMException {
221: return computedValue.getSeparator();
222: }
223:
224: // BEGIN RAVE MODIFICATIONS
225: public String toString() {
226: switch (getPrimitiveType()) {
227: case CSSPrimitiveValue.CSS_NUMBER:
228: case CSSPrimitiveValue.CSS_PX:
229: case CSSPrimitiveValue.CSS_MM:
230: case CSSPrimitiveValue.CSS_CM:
231: case CSSPrimitiveValue.CSS_IN:
232: case CSSPrimitiveValue.CSS_PT:
233: case CSSPrimitiveValue.CSS_PC:
234: case CSSPrimitiveValue.CSS_EMS:
235: case CSSPrimitiveValue.CSS_EXS:
236: case CSSPrimitiveValue.CSS_PERCENTAGE:
237: return String.valueOf(getFloatValue());
238:
239: case CSSPrimitiveValue.CSS_STRING:
240: case CSSPrimitiveValue.CSS_IDENT:
241: case CSSPrimitiveValue.CSS_URI:
242: return getStringValue();
243:
244: case CSSPrimitiveValue.CSS_RGBCOLOR:
245: return "rgb(" + getRed() + "," + getGreen() + ","
246: + getBlue() + ")"; // NOI18N
247: }
248: return super .toString() + "[type=" + getPrimitiveType() + "]";
249: }
250: // END RAVE MODIFICATIONS
251: }
|