001package com.hfg.svg.filtereffect;
002
003import com.hfg.svg.AbstractSvgNode;
004import com.hfg.svg.SVG;
005import com.hfg.svg.SvgAttr;
006import com.hfg.graphics.ColorUtil;
007import com.hfg.xml.XMLTag;
008
009import java.awt.Color;
010
011//------------------------------------------------------------------------------
012/**
013 Object representation of an SVG (Scalable Vector Graphics) 'feDiffuseLighting' filter effect tag.
014
015 @author J. Alex Taylor, hairyfatguy.com
016 */
017//------------------------------------------------------------------------------
018// com.hfg XML/HTML Coding Library
019//
020// This library is free software; you can redistribute it and/or
021// modify it under the terms of the GNU Lesser General Public
022// License as published by the Free Software Foundation; either
023// version 2.1 of the License, or (at your option) any later version.
024//
025// This library is distributed in the hope that it will be useful,
026// but WITHOUT ANY WARRANTY; without even the implied warranty of
027// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
028// Lesser General Public License for more details.
029//
030// You should have received a copy of the GNU Lesser General Public
031// License along with this library; if not, write to the Free Software
032// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
033//
034// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
035// jataylor@hairyfatguy.com
036//------------------------------------------------------------------------------
037
038public class SvgFeDiffuseLighting extends AbstractSvgNode
039{
040
041   private SvgLightSource mLightSource;
042
043   //###########################################################################
044   // CONSTRUCTORS
045   //###########################################################################
046
047   //---------------------------------------------------------------------------
048   public SvgFeDiffuseLighting()
049   {
050      super(SVG.feDiffuseLighting);
051   }
052
053   //---------------------------------------------------------------------------
054   public SvgFeDiffuseLighting(XMLTag inXMLTag)
055   {
056      this();
057      initFromXMLTag(inXMLTag);
058   }
059
060   //###########################################################################
061   // PUBLIC METHODS
062   //###########################################################################
063
064
065   //---------------------------------------------------------------------------
066   /**
067    Sets the light source - an instance of SvgFeDistantLight, SvgFePointLight, or SvgFeSpotLight.
068    */
069   public SvgFeDiffuseLighting setLightSource(SvgLightSource inValue)
070   {
071      if (mLightSource != null)
072      {
073         removeSubtag(mLightSource);
074      }
075
076      mLightSource = inValue;
077      addSubtag(mLightSource);
078
079      return this;
080   }
081
082   //---------------------------------------------------------------------------
083   public SvgLightSource getLightSource()
084   {
085      return mLightSource;
086   }
087
088
089   //---------------------------------------------------------------------------
090   public SvgFeDiffuseLighting setLightingColor(Color inValue)
091   {
092      setAttribute(SvgAttr.lightingColor, "#" + ColorUtil.colorToHex(inValue));
093      return this;
094   }
095
096   //---------------------------------------------------------------------------
097   /**
098    Sets the height of surface when A<sub>in</sub> = 1.
099    If the attribute is not specified, then the effect is as if a value of 1 were specified.
100    */
101   public SvgFeDiffuseLighting setSurfaceScale(int inValue)
102   {
103      setAttribute(SvgAttr.surfaceScale, inValue);
104      return this;
105   }
106
107   //---------------------------------------------------------------------------
108   /**
109    Sets the kd in Phong lighting model. In SVG, this can be any non-negative number.
110    If the attribute is not specified, then the effect is as if a value of 1 were specified.
111    */
112   public SvgFeDiffuseLighting setDiffuseConstant(float inValue)
113   {
114      setAttribute(SvgAttr.diffuseConstant, inValue);
115      return this;
116   }
117
118   //---------------------------------------------------------------------------
119   /**
120    Sets the first number as the &lt;dx&gt; value and the optionsl second number as
121    the &lt;dygt; value. If the &lt;dygt; value is not specified, it defaults to the
122    same value as &lt;dx&gt;. Indicates the intended distance in current filter units
123    (i.e., units as determined by the value of attribute primitiveUnits) for dx and
124    dy, respectively, in the surface normal calculation formulas. By specifying
125    value(s) for kernelUnitLength, the kernel becomes defined in a scalable,
126    abstract coordinate system. If kernelUnitLength is not specified, the dx and
127    dy values should represent very small deltas relative to a given (x,y) position,
128    which might be implemented in some cases as one pixel in the intermediate image
129    offscreen bitmap, which is a pixel-based coordinate system, and thus potentially
130    not scalable. For some level of consistency across display media and user agents,
131    it is necessary that a value be provided for at least one of filterRes and kernelUnitLength.
132    A negative or zero value is an error
133    */
134   public SvgFeDiffuseLighting setKernelUnitLength(String inValue)
135   {
136      setAttribute(SvgAttr.kernelUnitLength, inValue);
137      return this;
138   }
139
140   //---------------------------------------------------------------------------
141   public SvgFeDiffuseLighting setIn(FeInput inValue)
142   {
143      setAttribute(SvgAttr.in, inValue);
144      return this;
145   }
146
147   //---------------------------------------------------------------------------
148   public SvgFeDiffuseLighting setHeight(int inValue)
149   {
150      setAttribute(SvgAttr.height, inValue);
151      return this;
152   }
153
154   //---------------------------------------------------------------------------
155   public SvgFeDiffuseLighting setHeight(String inValue)
156   {
157      setAttribute(SvgAttr.height, inValue);
158      return this;
159   }
160
161   //---------------------------------------------------------------------------
162   public SvgFeDiffuseLighting setResult(String inValue)
163   {
164      setAttribute(SvgAttr.result, inValue);
165      return this;
166   }
167
168   //---------------------------------------------------------------------------
169   public SvgFeDiffuseLighting setWidth(int inValue)
170   {
171      setAttribute(SvgAttr.width, inValue);
172      return this;
173   }
174
175   //---------------------------------------------------------------------------
176   public SvgFeDiffuseLighting setWidth(String inValue)
177   {
178      setAttribute(SvgAttr.width, inValue);
179      return this;
180   }
181
182   //---------------------------------------------------------------------------
183   public SvgFeDiffuseLighting setX(int inValue)
184   {
185      setAttribute(SvgAttr.x, inValue);
186      return this;
187   }
188
189   //---------------------------------------------------------------------------
190   public SvgFeDiffuseLighting setX(String inValue)
191   {
192      setAttribute(SvgAttr.x, inValue);
193      return this;
194   }
195
196
197   //---------------------------------------------------------------------------
198   public SvgFeDiffuseLighting setY(int inValue)
199   {
200      setAttribute(SvgAttr.y, inValue);
201      return this;
202   }
203
204   //---------------------------------------------------------------------------
205   public SvgFeDiffuseLighting setY(String inValue)
206   {
207      setAttribute(SvgAttr.y, inValue);
208      return this;
209   }
210}