001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.css.dom;
020:
021: import org.apache.batik.css.engine.CSSEngine;
022: import org.apache.batik.css.engine.CSSStylableElement;
023: import org.apache.batik.css.engine.SVGCSSEngine;
024: import org.apache.batik.css.engine.value.Value;
025: import org.apache.batik.css.engine.value.svg.SVGColorManager;
026: import org.apache.batik.css.engine.value.svg.SVGPaintManager;
027: import org.w3c.dom.css.CSSValue;
028:
029: /**
030: * This class represents the computed style of an SVG element.
031: *
032: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
033: * @version $Id: CSSOMSVGComputedStyle.java 475477 2006-11-15 22:44:28Z cam $
034: */
035: public class CSSOMSVGComputedStyle extends CSSOMComputedStyle {
036:
037: /**
038: * Creates a new computed style.
039: */
040: public CSSOMSVGComputedStyle(CSSEngine e, CSSStylableElement elt,
041: String pseudoElt) {
042: super (e, elt, pseudoElt);
043: }
044:
045: /**
046: * Creates a CSSValue to manage the value at the given index.
047: */
048: protected CSSValue createCSSValue(int idx) {
049: if (idx > SVGCSSEngine.FINAL_INDEX) {
050: if (cssEngine.getValueManagers()[idx] instanceof SVGPaintManager) {
051: return new ComputedCSSPaintValue(idx);
052: }
053: if (cssEngine.getValueManagers()[idx] instanceof SVGColorManager) {
054: return new ComputedCSSColorValue(idx);
055: }
056: } else {
057: switch (idx) {
058: case SVGCSSEngine.FILL_INDEX:
059: case SVGCSSEngine.STROKE_INDEX:
060: return new ComputedCSSPaintValue(idx);
061:
062: case SVGCSSEngine.FLOOD_COLOR_INDEX:
063: case SVGCSSEngine.LIGHTING_COLOR_INDEX:
064: case SVGCSSEngine.STOP_COLOR_INDEX:
065: return new ComputedCSSColorValue(idx);
066: }
067: }
068: return super .createCSSValue(idx);
069: }
070:
071: /**
072: * To manage a computed color CSSValue.
073: */
074: protected class ComputedCSSColorValue extends CSSOMSVGColor
075: implements CSSOMSVGColor.ValueProvider {
076:
077: /**
078: * The index of the associated value.
079: */
080: protected int index;
081:
082: /**
083: * Creates a new ComputedCSSColorValue.
084: */
085: public ComputedCSSColorValue(int idx) {
086: super (null);
087: valueProvider = this ;
088: index = idx;
089: }
090:
091: /**
092: * Returns the Value associated with this object.
093: */
094: public Value getValue() {
095: return cssEngine.getComputedStyle(element, pseudoElement,
096: index);
097: }
098: }
099:
100: /**
101: * To manage a computed paint CSSValue.
102: */
103: public class ComputedCSSPaintValue extends CSSOMSVGPaint implements
104: CSSOMSVGPaint.ValueProvider {
105:
106: /**
107: * The index of the associated value.
108: */
109: protected int index;
110:
111: /**
112: * Creates a new ComputedCSSPaintValue.
113: */
114: public ComputedCSSPaintValue(int idx) {
115: super (null);
116: valueProvider = this ;
117: index = idx;
118: }
119:
120: /**
121: * Returns the Value associated with this object.
122: */
123: public Value getValue() {
124: return cssEngine.getComputedStyle(element, pseudoElement,
125: index);
126: }
127: }
128: }
|