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.SVGCSSEngine;
023: import org.apache.batik.css.engine.value.Value;
024: import org.apache.batik.css.engine.value.svg.SVGColorManager;
025: import org.apache.batik.css.engine.value.svg.SVGPaintManager;
026: import org.w3c.dom.DOMException;
027: import org.w3c.dom.css.CSSRule;
028: import org.w3c.dom.css.CSSValue;
029:
030: /**
031: * This class represents a SVG style declaration.
032: *
033: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
034: * @version $Id: CSSOMSVGStyleDeclaration.java 475477 2006-11-15 22:44:28Z cam $
035: */
036: public class CSSOMSVGStyleDeclaration extends CSSOMStyleDeclaration {
037:
038: /**
039: * The CSS engine.
040: */
041: protected CSSEngine cssEngine;
042:
043: /**
044: * Creates a new CSSOMSVGStyleDeclaration.
045: */
046: public CSSOMSVGStyleDeclaration(ValueProvider vp, CSSRule parent,
047: CSSEngine eng) {
048: super (vp, parent);
049: cssEngine = eng;
050: }
051:
052: /**
053: * Creates the CSS value associated with the given property.
054: */
055: protected CSSValue createCSSValue(String name) {
056: int idx = cssEngine.getPropertyIndex(name);
057: if (idx > SVGCSSEngine.FINAL_INDEX) {
058: if (cssEngine.getValueManagers()[idx] instanceof SVGPaintManager) {
059: return new StyleDeclarationPaintValue(name);
060: }
061: if (cssEngine.getValueManagers()[idx] instanceof SVGColorManager) {
062: return new StyleDeclarationColorValue(name);
063: }
064: } else {
065: switch (idx) {
066: case SVGCSSEngine.FILL_INDEX:
067: case SVGCSSEngine.STROKE_INDEX:
068: return new StyleDeclarationPaintValue(name);
069:
070: case SVGCSSEngine.FLOOD_COLOR_INDEX:
071: case SVGCSSEngine.LIGHTING_COLOR_INDEX:
072: case SVGCSSEngine.STOP_COLOR_INDEX:
073: return new StyleDeclarationColorValue(name);
074: }
075: }
076: return super .createCSSValue(name);
077: }
078:
079: /**
080: * This class represents a CSS value returned by this declaration.
081: */
082: public class StyleDeclarationColorValue extends CSSOMSVGColor
083: implements CSSOMSVGColor.ValueProvider {
084:
085: /**
086: * The property name.
087: */
088: protected String property;
089:
090: /**
091: * Creates a new StyleDeclarationColorValue.
092: */
093: public StyleDeclarationColorValue(String prop) {
094: super (null);
095: valueProvider = this ;
096: setModificationHandler(new AbstractModificationHandler() {
097: protected Value getValue() {
098: return StyleDeclarationColorValue.this .getValue();
099: }
100:
101: public void textChanged(String text)
102: throws DOMException {
103: if (handler == null) {
104: throw new DOMException(
105: DOMException.NO_MODIFICATION_ALLOWED_ERR,
106: "");
107: }
108: String prio = getPropertyPriority(property);
109: CSSOMSVGStyleDeclaration.this .handler
110: .propertyChanged(property, text, prio);
111: }
112: });
113:
114: property = prop;
115: }
116:
117: // ValueProvider ///////////////////////////////
118:
119: /**
120: * Returns the current value associated with this object.
121: */
122: public Value getValue() {
123: return CSSOMSVGStyleDeclaration.this .valueProvider
124: .getValue(property);
125: }
126:
127: }
128:
129: /**
130: * This class represents a CSS value returned by this declaration.
131: */
132: public class StyleDeclarationPaintValue extends CSSOMSVGPaint
133: implements CSSOMSVGPaint.ValueProvider {
134:
135: /**
136: * The property name.
137: */
138: protected String property;
139:
140: /**
141: * Creates a new StyleDeclarationPaintValue.
142: */
143: public StyleDeclarationPaintValue(String prop) {
144: super (null);
145: valueProvider = this ;
146: setModificationHandler(new AbstractModificationHandler() {
147: protected Value getValue() {
148: return StyleDeclarationPaintValue.this .getValue();
149: }
150:
151: public void textChanged(String text)
152: throws DOMException {
153: if (handler == null) {
154: throw new DOMException(
155: DOMException.NO_MODIFICATION_ALLOWED_ERR,
156: "");
157: }
158: String prio = getPropertyPriority(property);
159: CSSOMSVGStyleDeclaration.this .handler
160: .propertyChanged(property, text, prio);
161: }
162: });
163:
164: property = prop;
165: }
166:
167: // ValueProvider ///////////////////////////////
168:
169: /**
170: * Returns the current value associated with this object.
171: */
172: public Value getValue() {
173: return CSSOMSVGStyleDeclaration.this.valueProvider
174: .getValue(property);
175: }
176:
177: }
178: }
|