001package com.hfg.svg; 002 003 004 005import com.hfg.util.StringUtil; 006import com.hfg.util.collection.CollectionUtil; 007import com.hfg.xml.XMLAttribute; 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) 'marker' tag. 017 * <div> 018 * @author J. Alex Taylor, hairyfatguy.com 019 * </div> 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 SvgMarker extends AbstractSvgNode implements SvgNode 043{ 044 045 //########################################################################## 046 // CONSTRUCTORS 047 //########################################################################## 048 049 //--------------------------------------------------------------------------- 050 public SvgMarker() 051 { 052 super(SVG.marker); 053 } 054 055 //--------------------------------------------------------------------------- 056 public SvgMarker(XMLTag inXMLTag) 057 { 058 this(); 059 initFromXMLTag(inXMLTag); 060 } 061 062 //########################################################################## 063 // PUBLIC METHODS 064 //########################################################################## 065 066 067 //--------------------------------------------------------------------------- 068 public SvgMarker setId(String inValue) 069 { 070 setAttribute(SvgAttr.id, inValue); 071 return this; 072 } 073 074 //--------------------------------------------------------------------------- 075 public SvgMarker setMarkerUnits(MarkerCoordinateSystem inValue) 076 { 077 setAttribute(SvgAttr.markerUnits, inValue); 078 return this; 079 } 080 081 //--------------------------------------------------------------------------- 082 public SvgMarker setViewBox(Rectangle inValue) 083 { 084 setAttribute(SvgAttr.viewBox, 085 String.format("%d %d %d %d", (int)inValue.getMinX(), (int)inValue.getMinY(), 086 (int)inValue.getMaxX(), (int)inValue.getMaxY())); 087 return this; 088 } 089 090 //--------------------------------------------------------------------------- 091 public Rectangle getViewBox() 092 { 093 Rectangle rect = null; 094 String stringValue = getAttributeValue(SvgAttr.viewBox); 095 if (StringUtil.isSet(stringValue)) 096 { 097 String[] pieces = stringValue.split("\\s+"); 098 int x = Integer.parseInt(pieces[0]); 099 int y = Integer.parseInt(pieces[1]); 100 rect = new Rectangle(x, y, Integer.parseInt(pieces[2]) - x, Integer.parseInt(pieces[3]) - y); 101 } 102 103 return rect; 104 } 105 106 107 //--------------------------------------------------------------------------- 108 public SvgMarker setHeight(int inValue) 109 { 110 setAttribute(SvgAttr.markerHeight, inValue); 111 return this; 112 } 113 114 //--------------------------------------------------------------------------- 115 public SvgMarker setHeight(String inValue) 116 { 117 setAttribute(SvgAttr.markerHeight, inValue); 118 return this; 119 } 120 121 122 //--------------------------------------------------------------------------- 123 public SvgMarker setWidth(int inValue) 124 { 125 setAttribute(SvgAttr.markerWidth, inValue); 126 return this; 127 } 128 129 //--------------------------------------------------------------------------- 130 public SvgMarker setWidth(String inValue) 131 { 132 setAttribute(SvgAttr.markerWidth, inValue); 133 return this; 134 } 135 136 //--------------------------------------------------------------------------- 137 public SvgMarker setOrientation(String inValue) 138 { 139 setAttribute(SvgAttr.orient, inValue); 140 return this; 141 } 142 143 144 145 //--------------------------------------------------------------------------- 146 public SvgMarker setRefX(int inValue) 147 { 148 setAttribute(SvgAttr.refX, inValue); 149 return this; 150 } 151 152 //--------------------------------------------------------------------------- 153 public SvgMarker setRefX(String inValue) 154 { 155 setAttribute(SvgAttr.refX, inValue); 156 return this; 157 } 158 159 160 //--------------------------------------------------------------------------- 161 public SvgMarker setRefY(int inValue) 162 { 163 setAttribute(SvgAttr.refY, inValue); 164 return this; 165 } 166 167 //--------------------------------------------------------------------------- 168 public SvgMarker setRefY(String inValue) 169 { 170 setAttribute(SvgAttr.refY, inValue); 171 return this; 172 } 173 174 //--------------------------------------------------------------------------- 175 public SvgPath addPath() 176 { 177 SvgPath path = new SvgPath(); 178 addSubtag(path); 179 return path; 180 } 181 182}