001package com.hfg.svg;
002
003import com.hfg.util.collection.CollectionUtil;
004import com.hfg.xml.XMLNode;
005import com.hfg.xml.XMLAttribute;
006import com.hfg.xml.XMLNamespace;
007import com.hfg.html.HTML;
008import com.hfg.xml.XMLTag;
009import com.hfg.xml.XMLizable;
010
011import java.awt.*;
012import java.util.regex.Matcher;
013
014//------------------------------------------------------------------------------
015/**
016 * Object representation of an SVG (Scalable Vector Graphics) 'g' tag.
017 *
018 * @author J. Alex Taylor, hairyfatguy.com
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 SvgLink extends AbstractSvgNode implements SvgNode
042{
043   //**************************************************************************
044   // CONSTRUCTORS
045   //**************************************************************************
046
047   //---------------------------------------------------------------------------
048   private SvgLink()
049   {
050      super(SVG.anchor);
051   }
052
053   //---------------------------------------------------------------------------
054   public SvgLink(CharSequence inURL)
055   {
056      this();
057      XMLAttribute attr = new XMLAttribute(HTML.HREF, inURL);
058      attr.setNamespace(XMLNamespace.XLINK);
059      setAttribute(attr);
060   }
061
062   //---------------------------------------------------------------------------
063   public SvgLink(XMLTag inXMLTag)
064   {
065      this();
066
067      inXMLTag.verifyTagName(getTagName());
068
069      if (CollectionUtil.hasValues(inXMLTag.getAttributes()))
070      {
071         for (XMLAttribute attr : inXMLTag.getAttributes())
072         {
073            setAttribute(attr.clone());
074         }
075      }
076
077      java.util.List<XMLTag> subtags = inXMLTag.getSubtags();
078      if (CollectionUtil.hasValues(subtags))
079      {
080         for (XMLTag subtag : subtags)
081         {
082            addSubtag(SVG.constructFromXMLTag(subtag));
083         }
084      }
085   }
086
087   //**************************************************************************
088   // PUBLIC METHODS
089   //**************************************************************************
090
091
092   //---------------------------------------------------------------------------
093   public SvgLink setFont(Font inFont)
094   {
095      setStyle("font-family: " + inFont.getName() + "; font-size:" + inFont.getSize() + "pt;");
096      return this;
097   }
098
099   //---------------------------------------------------------------------------
100   public SvgLink setStyle(String inValue)
101   {
102      setAttribute(SvgAttr.style, inValue);
103      return this;
104   }
105
106   //---------------------------------------------------------------------------
107   public SvgLink setTransform(String inValue)
108   {
109      setAttribute(SvgAttr.transform, inValue);
110      return this;
111   }
112
113   //---------------------------------------------------------------------------
114   public SvgLine addLine(Point inStart, Point inEnd)
115   {
116      SvgLine line = new SvgLine(inStart, inEnd);
117      addSubtag(line);
118      return line;
119   }
120
121   //---------------------------------------------------------------------------
122   public SvgRect addRect(Rectangle inRect)
123   {
124      SvgRect rect = new SvgRect(inRect);
125      addSubtag(rect);
126      return rect;
127   }
128
129   //---------------------------------------------------------------------------
130   public SvgText addText(String inText, Font inFont, Point inLocation)
131   {
132      SvgText text = new SvgText(inText, inFont, inLocation);
133      addSubtag(text);
134      return text;
135   }
136}