001package com.hfg.svg;
002
003
004import com.hfg.util.collection.CollectionUtil;
005import com.hfg.xml.XMLAttribute;
006import com.hfg.xml.XMLTag;
007
008import java.awt.*;
009
010//------------------------------------------------------------------------------
011/**
012 * Object representation of an SVG (Scalable Vector Graphics) 'defs' tag.
013  <div>
014   See <a href='http://www.w3.org/TR/SVG11/struct.html#Head'>http://www.w3.org/TR/SVG11/struct.html#Head</a>
015  </div>
016  <div>
017   @author J. Alex Taylor, hairyfatguy.com
018  </div>
019 */
020//------------------------------------------------------------------------------
021// com.hfg XML/HTML Coding Library
022//
023// This library is free software; you can redistribute it and/or
024// modify it under the terms of the GNU Lesser General Public
025// License as published by the Free Software Foundation; either
026// version 2.1 of the License, or (at your option) any later version.
027//
028// This library is distributed in the hope that it will be useful,
029// but WITHOUT ANY WARRANTY; without even the implied warranty of
030// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
031// Lesser General Public License for more details.
032//
033// You should have received a copy of the GNU Lesser General Public
034// License along with this library; if not, write to the Free Software
035// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
036//
037// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
038// jataylor@hairyfatguy.com
039//------------------------------------------------------------------------------
040
041public class SvgDefs extends AbstractSvgNode implements SvgNode
042{
043
044   //##########################################################################
045   // CONSTRUCTORS
046   //##########################################################################
047
048   //---------------------------------------------------------------------------
049   public SvgDefs()
050   {
051      super(SVG.defs);
052   }
053
054   //---------------------------------------------------------------------------
055   public SvgDefs(XMLTag inXMLTag)
056   {
057      this();
058
059      inXMLTag.verifyTagName(getTagName());
060
061      if (CollectionUtil.hasValues(inXMLTag.getAttributes()))
062      {
063         for (XMLAttribute attr : inXMLTag.getAttributes())
064         {
065            setAttribute(attr.clone());
066         }
067      }
068
069      java.util.List<XMLTag> subtags = inXMLTag.getSubtags();
070      if (CollectionUtil.hasValues(subtags))
071      {
072         for (XMLTag subtag : subtags)
073         {
074            addSubtag(SVG.constructFromXMLTag(subtag));
075         }
076      }
077   }
078
079   //##########################################################################
080   // PUBLIC METHODS
081   //##########################################################################
082
083   //--------------------------------------------------------------------------
084   @Override
085   public void draw(Graphics2D g2)
086   {
087      // Do nothing. Definitions are only rendered where they are referenced.
088   }
089
090   //---------------------------------------------------------------------------
091   public SvgFilter addFilter()
092   {
093      SvgFilter newFilter = new SvgFilter();
094      addSubtag(newFilter);
095      return newFilter;
096   }
097
098   //---------------------------------------------------------------------------
099   public SvgGroup addGroup()
100   {
101      SvgGroup newGroup = new SvgGroup();
102      addSubtag(newGroup);
103      return newGroup;
104   }
105
106   //---------------------------------------------------------------------------
107   public SvgLink addLink(CharSequence inURL)
108   {
109      SvgLink newLink = new SvgLink(inURL);
110      addSubtag(newLink);
111      return newLink;
112   }
113
114   //---------------------------------------------------------------------------
115   public SvgLine addLine(Point inStart, Point inEnd)
116   {
117      SvgLine line = new SvgLine(inStart, inEnd);
118      addSubtag(line);
119      return line;
120   }
121
122   //---------------------------------------------------------------------------
123   public SvgRect addRect(Rectangle inRect)
124   {
125      SvgRect rect = new SvgRect(inRect);
126      addSubtag(rect);
127      return rect;
128   }
129
130   //---------------------------------------------------------------------------
131   public SvgSymbol addSymbol()
132   {
133      SvgSymbol symbol = new SvgSymbol();
134      addSubtag(symbol);
135      return symbol;
136   }
137
138   //---------------------------------------------------------------------------
139   public SvgText addText(String inText, Font inFont, Point inLocation)
140   {
141      SvgText text = new SvgText(inText, inFont, inLocation);
142      addSubtag(text);
143      return text;
144   }
145
146   //---------------------------------------------------------------------------
147   public Point getMaxXY()
148   {
149      return new Point(0, 0);
150   }
151
152}