1 18 package org.apache.batik.css.dom; 19 20 import org.apache.batik.css.engine.CSSEngine; 21 import org.apache.batik.css.engine.SVGCSSEngine; 22 import org.apache.batik.css.engine.value.Value; 23 import org.apache.batik.css.engine.value.svg.SVGColorManager; 24 import org.apache.batik.css.engine.value.svg.SVGPaintManager; 25 import org.w3c.dom.DOMException ; 26 import org.w3c.dom.css.CSSRule; 27 import org.w3c.dom.css.CSSValue; 28 29 35 public class CSSOMSVGStyleDeclaration extends CSSOMStyleDeclaration { 36 37 40 protected CSSEngine cssEngine; 41 42 45 public CSSOMSVGStyleDeclaration(ValueProvider vp, 46 CSSRule parent, 47 CSSEngine eng) { 48 super(vp, parent); 49 cssEngine = eng; 50 } 51 52 55 protected CSSValue createCSSValue(String name) { 56 int idx = cssEngine.getPropertyIndex(name); 57 if (idx > SVGCSSEngine.FINAL_INDEX) { 58 if (cssEngine.getValueManagers()[idx] instanceof SVGPaintManager) { 59 return new StyleDeclarationPaintValue(name); 60 } 61 if (cssEngine.getValueManagers()[idx] instanceof SVGColorManager) { 62 return new StyleDeclarationColorValue(name); 63 } 64 } else { 65 switch (idx) { 66 case SVGCSSEngine.FILL_INDEX: 67 case SVGCSSEngine.STROKE_INDEX: 68 return new StyleDeclarationPaintValue(name); 69 70 case SVGCSSEngine.FLOOD_COLOR_INDEX: 71 case SVGCSSEngine.LIGHTING_COLOR_INDEX: 72 case SVGCSSEngine.STOP_COLOR_INDEX: 73 return new StyleDeclarationColorValue(name); 74 } 75 } 76 return super.createCSSValue(name); 77 } 78 79 82 public class StyleDeclarationColorValue 83 extends CSSOMSVGColor 84 implements CSSOMSVGColor.ValueProvider { 85 86 89 protected String property; 90 91 94 public StyleDeclarationColorValue(String prop) { 95 super(null); 96 valueProvider = this; 97 setModificationHandler(new AbstractModificationHandler() { 98 protected Value getValue() { 99 return StyleDeclarationColorValue.this.getValue(); 100 } 101 public void textChanged(String text) throws DOMException { 102 if (handler == null) { 103 throw new DOMException 104 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 105 } 106 String prio = getPropertyPriority(property); 107 CSSOMSVGStyleDeclaration.this. 108 handler.propertyChanged(property, text, prio); 109 } 110 }); 111 112 property = prop; 113 } 114 115 117 120 public Value getValue() { 121 return CSSOMSVGStyleDeclaration.this. 122 valueProvider.getValue(property); 123 } 124 125 } 126 127 130 public class StyleDeclarationPaintValue 131 extends CSSOMSVGPaint 132 implements CSSOMSVGPaint.ValueProvider { 133 134 137 protected String property; 138 139 142 public StyleDeclarationPaintValue(String prop) { 143 super(null); 144 valueProvider = this; 145 setModificationHandler(new AbstractModificationHandler() { 146 protected Value getValue() { 147 return StyleDeclarationPaintValue.this.getValue(); 148 } 149 public void textChanged(String text) throws DOMException { 150 if (handler == null) { 151 throw new DOMException 152 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 153 } 154 String prio = getPropertyPriority(property); 155 CSSOMSVGStyleDeclaration.this. 156 handler.propertyChanged(property, text, prio); 157 } 158 }); 159 160 property = prop; 161 } 162 163 165 168 public Value getValue() { 169 return CSSOMSVGStyleDeclaration.this. 170 valueProvider.getValue(property); 171 } 172 173 } 174 175 } 176 | Popular Tags |