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