001/********************************************** 002 * Copyright (C) 2010 Lukas Laag 003 * This file is part of lib-gwt-svg. 004 * 005 * libgwtsvg is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * libgwtsvg is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with libgwtsvg. If not, see http://www.gnu.org/licenses/ 017 **********************************************/ 018/* 019 * Copyright (c) 2004 World Wide Web Consortium, 020 * 021 * (Massachusetts Institute of Technology, European Research Consortium for 022 * Informatics and Mathematics, Keio University). All Rights Reserved. This 023 * work is distributed under the W3C(r) Software License [1] in the hope that 024 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied 025 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 026 * 027 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 028 */ 029 030package org.vectomatic.dom.svg; 031 032import org.vectomatic.dom.svg.impl.SVGPaintParser; 033import org.vectomatic.dom.svg.utils.SVGConstants; 034 035import com.google.gwt.core.client.JavaScriptException; 036 037/** 038 * <p>The {@link org.vectomatic.dom.svg.OMSVGColor} interface corresponds 039 * to color value definition for properties <code>stop-color</code>, <code>flood-color</code> 040 * and <code>lighting-color</code> and is a base class for interface {@link 041 * org.vectomatic.dom.svg.OMSVGPaint}. It incorporates SVG's extended notion 042 * of color, which incorporates ICC-based color specifications.</p> <p>Interface 043 * {@link org.vectomatic.dom.svg.OMSVGColor} does <em>not</em> correspond 044 * to the <a href='types.html#DataTypeColor'><color></a> basic data 045 * type. For the <a href='types.html#DataTypeColor'><color></a> basic 046 * data type, the applicable DOM interfaces are defined in <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/'>DOM 047 * Level 2 Style</a>; in particular, see the <code>RGBColor</code> interface 048 * ([<a href='refs.html#ref-DOM2STYLE'>DOM2STYLE</a>], section 2.2).</p> <p>Note: 049 * The {@link org.vectomatic.dom.svg.OMSVGColor} interface is deprecated, 050 * and may be dropped from future versions of the SVG specification.</p> 051 */ 052public abstract class OMSVGColor extends OMCSSValue { 053/** 054 * The color type is not one of predefined types. It is invalid to attempt 055 * to define a new value of this type or to attempt to switch an existing 056 * value to this type. 057 */ 058 public static final short SVG_COLORTYPE_UNKNOWN = 0; 059/** 060 * An sRGB color has been specified without an alterICC color specification. 061 */ 062 public static final short SVG_COLORTYPE_RGBCOLOR = 1; 063/** 064 * An sRGB color has been specified along with an alterICC color specification. 065 */ 066 public static final short SVG_COLORTYPE_RGBCOLOR_ICCCOLOR = 2; 067/** 068 * Corresponds to when keyword <span class='attr-value'>currentColor</span> 069 * has been specified. 070 */ 071 public static final short SVG_COLORTYPE_CURRENTCOLOR = 3; 072 073 protected short colorType; 074 protected OMRGBColor rgbColor; 075 protected OMSVGICCColor iccColor; 076 077 protected OMSVGColor() { 078 super(CSS_CUSTOM); 079 } 080 081 // Implementation of the svg::SVGColor W3C IDL interface 082 /** 083 * The type of the value as specified by one of the SVG_COLORTYPE_ constants 084 * defined on this interface. 085 */ 086 public final short getColorType() { 087 return this.colorType; 088 } 089 /** 090 * The color specified in the sRGB color space. 091 */ 092 public final OMRGBColor getRgbColor() { 093 return rgbColor; 094 } 095 /** 096 * The alternate ICC color specification. 097 */ 098 public final OMSVGICCColor getIccColor() { 099 return iccColor; 100 } 101 /** 102 * Modifies the color value to be the specified sRGB color without an alternate 103 * ICC color specification. 104 * @param rgbColor A string that matches <a href='types.html#DataTypeColor'><color></a>, 105 * which specifies the new sRGB color value. 106 * @throws SVGException(SVG_INVALID_VALUE_ERR) Raised if <var>rgbColor</var> 107 * does not match <a href='types.html#DataTypeColor'><color></a>. 108 */ 109 public final void setRGBColor(String rgbColor) throws JavaScriptException { 110 setColor(SVG_COLORTYPE_RGBCOLOR, rgbColor, null); 111 } 112 /** 113 * Modifies the color value to be the specified sRGB color with an alternate 114 * ICC color specification. 115 * @param rgbColor A string that matches <a href='types.html#DataTypeColor'><color></a>, 116 * which specifies the new sRGB color value. 117 * @param iccColor A string that matches <a href='types.html#DataTypeICCColor'><icccolor></a>, 118 * which specifies the alternate ICC color specification. 119 * @throws SVGException(SVG_INVALID_VALUE_ERR) Raised if <var>rgbColor</var> 120 * does not match <a href='types.html#DataTypeColor'><color></a> or 121 * if <var>iccColor</var> does not match <a href='types.html#DataTypeICCColor'><icccolor></a>. 122 */ 123 public final void setRGBColorICCColor(String rgbColor, String iccColor) throws JavaScriptException { 124 setColor(SVG_COLORTYPE_RGBCOLOR_ICCCOLOR, rgbColor, iccColor); 125 } 126 /** 127 * Sets the color value as specified by the parameters. If <var>colorType</var> 128 * requires an <code>RGBColor</code>, then <var>rgbColor</var> must be a string 129 * that matches <a href='types.html#DataTypeColor'><color></a>; otherwise, 130 * <var>rgbColor</var>. must be null. If <var>colorType</var> requires an 131 * {@link org.vectomatic.dom.svg.OMSVGICCColor}, then <var>iccColor</var> 132 * must be a string that matches <a href='types.html#DataTypeICCColor'><icccolor></a>; 133 * otherwise, <var>iccColor</var> must be null. 134 * @param colorType One of the defined constants for {@link org.vectomatic.dom.svg.OMSVGColor#getColorType()}. 135 * @param rgbColor The specification of an sRGB color, or null. 136 * @param iccColor The specification of an ICC color, or null. 137 * @throws SVGException(SVG_INVALID_VALUE_ERR) Raised if one of the parameters 138 * has an invalid value. 139 */ 140 public final void setColor(short colorType, String rgbColor, String iccColor) throws JavaScriptException { 141// GWT.log("OMSVGColor.setColor(" + colorType + ", '" + rgbColor + "', '" + iccColor + "')"); 142 if (colorType == SVG_COLORTYPE_RGBCOLOR_ICCCOLOR && iccColor != null && rgbColor != null) { 143 this.iccColor = SVGPaintParser.INSTANCE.iccColor(iccColor); 144 this.rgbColor = SVGPaintParser.INSTANCE.rgbColor(rgbColor); 145 setCssText(rgbColor.trim() + " " + iccColor); 146 } else if (colorType == SVG_COLORTYPE_RGBCOLOR && rgbColor != null && iccColor == null) { 147 this.iccColor = null; 148 this.rgbColor = SVGPaintParser.INSTANCE.rgbColor(rgbColor); 149 setCssText(rgbColor); 150 } else if (colorType == SVG_COLORTYPE_CURRENTCOLOR && rgbColor == null && iccColor == null) { 151 this.iccColor = null; 152 this.rgbColor = null; 153 setCssText(SVGConstants.CSS_CURRENTCOLOR_VALUE); 154 } else if (colorType == SVG_COLORTYPE_UNKNOWN && rgbColor == null && iccColor == null) { 155 this.iccColor = null; 156 this.rgbColor = null; 157 setCssText(SVGConstants.CSS_NONE_VALUE); 158 } else { 159 throw new JavaScriptException("Invalid color spec"); 160 } 161 this.colorType = colorType; 162 } 163 164}