001package com.hfg.html;
002
003
004import com.hfg.xml.XMLNode;
005
006//------------------------------------------------------------------------------
007/**
008 * Represents a link (<a>) tag.
009 *
010 * @author J. Alex Taylor, hairyfatguy.com
011 */
012//------------------------------------------------------------------------------
013// com.hfg XML/HTML Coding Library
014//
015// This library is free software; you can redistribute it and/or
016// modify it under the terms of the GNU Lesser General Public
017// License as published by the Free Software Foundation; either
018// version 2.1 of the License, or (at your option) any later version.
019//
020// This library is distributed in the hope that it will be useful,
021// but WITHOUT ANY WARRANTY; without even the implied warranty of
022// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
023// Lesser General Public License for more details.
024//
025// You should have received a copy of the GNU Lesser General Public
026// License along with this library; if not, write to the Free Software
027// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
028//
029// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
030// jataylor@hairyfatguy.com
031//------------------------------------------------------------------------------
032
033public class Link extends HTMLTagWithCoreEvents
034{
035   //##########################################################################
036   // CONSTRUCTORS
037   //##########################################################################
038
039   //--------------------------------------------------------------------------
040   public Link()
041   {
042      super(HTML.A);
043   }
044
045   //--------------------------------------------------------------------------
046   public Link(CharSequence inURL)
047   {
048      this();
049      setURL(inURL);
050   }
051
052   //--------------------------------------------------------------------------
053   public Link(CharSequence inURL, String inContent)
054   {
055      this(inURL);
056      addContent(inContent);
057   }
058
059   //--------------------------------------------------------------------------
060   public Link(CharSequence inURL, HTMLTag inContentTag)
061   {
062      this(inURL);
063      addSubtag(inContentTag);
064   }
065
066   //--------------------------------------------------------------------------
067   public Link(XMLNode inXMLNode)
068   {
069      this();
070      initFromXMLNode(inXMLNode);
071   }
072
073   //##########################################################################
074   // PUBLIC METHODS
075   //##########################################################################
076
077   //--------------------------------------------------------------------------
078   public Link setURL(CharSequence inValue)
079   {
080      setAttribute(HTML.HREF, inValue);
081
082      return this;
083   }
084
085   //--------------------------------------------------------------------------
086   public String getURL()
087   {
088      return getAttributeValue(HTML.HREF);
089   }
090
091   //--------------------------------------------------------------------------
092   /**
093    The target for the link can be set to one of several special values or a tab/window name of your choosing.
094    (The Target class has constants for the special values.)
095    <pre>
096    _blank      Opens the linked document in a new window or tab
097    _self       Opens the linked document in the same frame as it was clicked (this is default)
098    _parent     Opens the linked document in the parent frame
099    _top        Opens the linked document in the full body of the window
100    framename   Opens the linked document in a named frame
101    </pre>
102
103    @param inValue the target name
104    @return this Link object to enable method chaining
105    */
106   public Link setTarget(String inValue)
107   {
108      setAttribute(HTML.TARGET, inValue);
109
110      return this;
111   }
112
113   //--------------------------------------------------------------------------
114   public String getTarget()
115   {
116      return getAttributeValue(HTML.TARGET);
117   }
118
119   //--------------------------------------------------------------------------
120   public Link setName(String inValue)
121   {
122      setAttribute(HTML.NAME, inValue);
123
124      return this;
125   }
126
127
128   //--------------------------------------------------------------------------
129   public String getName()
130   {
131      return getAttributeValue(HTML.NAME);
132   }
133
134   //--------------------------------------------------------------------------
135   public Link setTitle(String inValue)
136   {
137      setAttribute(HTML.TITLE, inValue);
138      return this;
139   }
140
141
142   //--------------------------------------------------------------------------
143   public Span addSpan()
144   {
145      Span span = new Span();
146      addSubtag(span);
147
148      return span;
149   }
150
151   //--------------------------------------------------------------------------
152   public Span addSpan(String inContent)
153   {
154      Span span = new Span(inContent);
155      addSubtag(span);
156
157      return span;
158   }
159
160   //--------------------------------------------------------------------------
161   public Img addImage(String inSrc)
162   {
163      Img image = new Img(inSrc);
164      addSubtag(image);
165
166      return image;
167   }
168
169
170   // Overrides for HTMLTag setters to allow method chaining.
171
172   //--------------------------------------------------------------------------
173   @Override
174   public Link addClass(String inValue)
175   {
176      return (Link) super.addClass(inValue);
177   }
178
179   //--------------------------------------------------------------------------
180   @Override
181   public Link setClass(String inValue)
182   {
183      return (Link) super.setClass(inValue);
184   }
185
186   //--------------------------------------------------------------------------
187   @Override
188   public Link setId(String inValue)
189   {
190      return (Link) super.setId(inValue);
191   }
192
193   //--------------------------------------------------------------------------
194   @Override
195   public Link setStyle(CharSequence inValue)
196   {
197      return (Link) super.setStyle(inValue);
198   }
199
200   //--------------------------------------------------------------------------
201   @Override
202   public Link addStyle(String inValue)
203   {
204      return (Link) super.addStyle(inValue);
205   }
206
207   // Overrides for HTMLTagWithCoreEvents setters to allow method chaining.
208
209   //--------------------------------------------------------------------------
210   @Override
211   public Link setOnClick(String inValue)
212   {
213      return (Link) super.setOnClick(inValue);
214   }
215
216   //--------------------------------------------------------------------------
217   @Override
218   public Link setOnDblClick(String inValue)
219   {
220      return (Link) super.setOnDblClick(inValue);
221   }
222
223   //--------------------------------------------------------------------------
224   @Override
225   public Link setOnMouseDown(String inValue)
226   {
227      return (Link) super.setOnMouseDown(inValue);
228   }
229
230   //--------------------------------------------------------------------------
231   @Override
232   public Link setOnMouseMove(String inValue)
233   {
234      return (Link) super.setOnMouseMove(inValue);
235   }
236
237   //--------------------------------------------------------------------------
238   @Override
239   public Link setOnMouseOut(String inValue)
240   {
241      return (Link) super.setOnMouseOut(inValue);
242   }
243
244   //--------------------------------------------------------------------------
245   @Override
246   public Link setOnMouseOver(String inValue)
247   {
248      return (Link) super.setOnMouseOver(inValue);
249   }
250
251   //--------------------------------------------------------------------------
252   @Override
253   public Link setOnMouseUp(String inValue)
254   {
255      return (Link) super.setOnMouseUp(inValue);
256   }
257
258   //--------------------------------------------------------------------------
259   @Override
260   public Link setOnKeyDown(String inValue)
261   {
262      return (Link) super.setOnKeyDown(inValue);
263   }
264
265   //--------------------------------------------------------------------------
266   @Override
267   public Link setOnKeyPress(String inValue)
268   {
269      return (Link) super.setOnKeyPress(inValue);
270   }
271
272   //--------------------------------------------------------------------------
273   @Override
274   public Link setOnKeyUp(String inValue)
275   {
276      return (Link) super.setOnKeyUp(inValue);
277   }
278
279}