1 /********************************************** 2 * Copyright (C) 2010 Lukas Laag 3 * This file is part of lib-gwt-svg. 4 * 5 * libgwtsvg is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Lesser General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * libgwtsvg is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with libgwtsvg. If not, see http://www.gnu.org/licenses/ 17 **********************************************/ 18 package org.vectomatic.dom.svg; 19 20 import org.vectomatic.dom.svg.impl.CSSHelper; 21 import org.vectomatic.dom.svg.impl.DashArrayParser; 22 import org.vectomatic.dom.svg.impl.SVGPaintParser; 23 import org.vectomatic.dom.svg.utils.SVGConstants; 24 25 import com.google.gwt.core.client.GWT; 26 import com.google.gwt.dom.client.Style; 27 import com.google.gwt.dom.client.TagName; 28 29 /** 30 * Class to represent a CSS style 31 * @author laaglu 32 */ 33 @TagName("style") 34 public class OMSVGStyle extends Style { 35 protected static CSSHelper cssHelper = GWT.create(CSSHelper.class); 36 /** 37 * Constructor 38 */ 39 protected OMSVGStyle() { 40 } 41 /** 42 * Clears the value of a named property, causing it to 43 * revert to its default. 44 * @param name The property name 45 */ 46 public final void clearSVGProperty(String name) { 47 cssHelper.setProperty(this, name, ""); 48 } 49 50 /** 51 * Gets the value of a named property. 52 * @param name The property name 53 * @return The property name 54 */ 55 public final String getSVGProperty(String name) { 56 return cssHelper.getProperty(this, name); 57 } 58 59 /** 60 * Sets the value of a named property. 61 * @param name The property name 62 * @param value The property name 63 */ 64 public final void setSVGProperty(String name, String value) { 65 cssHelper.setProperty(this, name, value); 66 } 67 68 /** 69 * Gets the value of a named property as a CSS value. 70 * This method can be applied to get the value of the 71 * 'fill' and 'paint' properties, which will be returned 72 * as {@link org.vectomatic.dom.svg.OMSVGPaint} values. 73 * @param name 74 * The name of CSS property 75 * @return 76 * The property value 77 */ 78 public final OMCSSValue getSVGPropertyCSS(String name) { 79 String cssText = getSVGProperty(name); 80 return SVGConstants.CSS_STROKE_DASHARRAY_PROPERTY.equals(name) 81 ? DashArrayParser.INSTANCE.parse(cssText) 82 : SVGPaintParser.INSTANCE.parse(cssText); 83 } 84 }