001 /*
002 * This file is part of the Echo Point Project. This project is a
003 * collection of Components that have extended the Echo Web Application
004 * Framework Version 3.
005 *
006 * Version: MPL 1.1
007 *
008 * The contents of this file are subject to the Mozilla Public License Version
009 * 1.1 (the "License"); you may not use this file except in compliance with
010 * the License. You may obtain a copy of the License at
011 * http://www.mozilla.org/MPL/
012 *
013 * Software distributed under the License is distributed on an "AS IS" basis,
014 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
015 * for the specific language governing rights and limitations under the
016 * License.
017 */
018 package echopoint;
019
020 import nextapp.echo.app.Component;
021
022 /**
023 * A component that represents a HTML anchor tag. This component makes it
024 * easier to create regular HTML links without having to configure a {@link
025 * nextapp.echo.app.Button} component and an associated action listener. You
026 * can create a raw anchor tag using {@link echopoint.internal.AbstractHtmlComponent}
027 * implementations, but may find configuring styles not as convenient.
028 *
029 * <p><b>Note:</b> Since anchor tags cannot be fully styled using in-line
030 * styles, this component does not offer the ability to configure styles for
031 * hover, active or visited.</p>
032 *
033 * <p>The following shows sample usage of this component:</p>
034 * <pre>
035 * import echopoint.Anchor;
036 * import nextapp.echo.app.Color;
037 * import nextapp.echo.app.Extent;
038 * import nextapp.echo.app.Font;
039 *
040 * ...
041 * final Anchor anchor = new Anchor();
042 * anchor.setUri( "https://echopoint.dev.java.net/" );
043 * anchor.setColor( new Color( 0x2f2f4f );
044 * anchor.setFont( new Font( Font.HELVETICA, Font.BOLD, new Extent( 10 ) ) );
045 *
046 * container.add( anchor );
047 * </pre>
048 *
049 * @author Rakesh 2008-10-23
050 * @version $Id: Anchor.java 74 2008-10-26 00:14:00Z sptrakesh $
051 */
052 public class Anchor extends Component
053 {
054 private static final long serialVersionUID = 1l;
055
056 /** The options for specifying the {@link Anchor#PROPERTY_TARGET} property. */
057 public enum Target { _blank, _parent, _self, _top }
058
059 /** The target for the anchor tag. Use to control target window/frame. */
060 public static final String PROPERTY_TARGET = "target";
061
062 /** The text that is to be hyper-linked. */
063 public static final String PROPERTY_TEXT = "text";
064
065 /** The tooltip (title) for the anchor tag. */
066 public static final String PROPERTY_TOOL_TIP_TEXT = "toolTipText";
067
068 /** The destination URI to which the anchor tag points. */
069 public static final String PROPERTY_URI = "uri";
070
071 /**
072 * Return the target attribute for the anchor tag.
073 *
074 * @return The target value.
075 */
076 public String getTarget()
077 {
078 return (String) get( PROPERTY_TARGET );
079 }
080
081 /**
082 * Set the value for the target attribute to be applied to the anchor tag.
083 *
084 * @see #setTarget(echopoint.Anchor.Target)
085 * @param target The value to set.
086 */
087 public void setTarget( final String target )
088 {
089 set( PROPERTY_TARGET, target );
090 }
091
092 /**
093 * Set the value for the target attribute to be applied to the anchor tag.
094 * Use this method to specify standard target values.
095 *
096 * @param target The value to set.
097 */
098 public void setTarget( final Target target )
099 {
100 set( PROPERTY_TARGET, target.toString() );
101 }
102
103 /**
104 * Return the text that is to be hyper-linked.
105 *
106 * @return The text that is to be hyper-linked.
107 */
108 public String getText()
109 {
110 return (String) get( PROPERTY_TEXT );
111 }
112
113 /**
114 * Set the value of the text that is to be displayed as hyper-linked.
115 *
116 * @param text The value to set.
117 */
118 public void setText( final String text )
119 {
120 set( PROPERTY_TEXT, text );
121 }
122
123 /**
124 * Return the tool tip text displayed for the anchor tag.
125 *
126 * @return The tool tip text that is to be displayed.
127 */
128 public String getToolTipText()
129 {
130 return (String) get( PROPERTY_TOOL_TIP_TEXT );
131 }
132
133 /**
134 * Set the value of the tool tip text that is to be displayed.
135 *
136 * @param toolTipText The value to set.
137 */
138 public void setToolTipText( final String toolTipText )
139 {
140 set( PROPERTY_TOOL_TIP_TEXT, toolTipText );
141 }
142
143 /**
144 * Return the URI to which the anchor tag points.
145 *
146 * @return The uri value.
147 */
148 public String getUri()
149 {
150 return (String) get( PROPERTY_URI );
151 }
152
153 /**
154 * Set the value of the URI to which the the anchor tag points.
155 *
156 * @param uri The value to set.
157 */
158 public void setUri( final String uri )
159 {
160 set( PROPERTY_URI, uri );
161 }
162 }