eu.webtoolkit.jwt
Class WAnchor

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WWidget
          extended by eu.webtoolkit.jwt.WWebWidget
              extended by eu.webtoolkit.jwt.WInteractWidget
                  extended by eu.webtoolkit.jwt.WContainerWidget
                      extended by eu.webtoolkit.jwt.WAnchor

public class WAnchor
extends WContainerWidget

A widget that represents an HTML anchor (to link to other documents).

Use an anchor to link to another web page, document, internal application path or a resource (which specifies application-dependent content that may be generated by your application on demand). The anchor may contain a label text, an image, or any other widget (as it inherits from WContainerWidget). If you link to a document or external url, and do not want the application to terminate when the user follows the anchor, you must use setTarget(TargetNewWindow). Even for non-HTML documents, this may be important since pending Ajax requests are cancelled if documents are not served within the browser window in certain browsers.

WAnchor is an inline widget.

Note: If you set a text or image using one of the API methods like setText() or setImage() or a constructor, you should not attempt to remove all contents (using WContainerWidget#clear(), or provide a layout (using WContainerWidget#setLayout()), as this will result in undefined behaviour: the text or image are simply inserted as widgets into the container.

CSS

The widget corresponds to the HTML <a> tag and does not provide styling. It can be styled using inline or external CSS as appropriate.


Nested Class Summary
 
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WContainerWidget
WContainerWidget.Overflow
 
Constructor Summary
WAnchor()
          Creates an anchor.
WAnchor(java.lang.String ref)
          Creates an anchor linking to a URL (deprecated).
WAnchor(java.lang.String ref, java.lang.CharSequence text)
          Creates an anchor linking to a URL with a text (deprecated).
WAnchor(java.lang.String ref, java.lang.CharSequence text, WContainerWidget parent)
          Deprecated. Use WAnchor() instead.
WAnchor(java.lang.String ref, WContainerWidget parent)
          Deprecated. Use WAnchor() instead.
WAnchor(java.lang.String ref, WImage image)
          Creates an anchor linking to a URL with an image (deprecated).
WAnchor(java.lang.String ref, WImage image, WContainerWidget parent)
          Deprecated. Use WAnchor() instead.
WAnchor(WContainerWidget parent)
          Creates an anchor.
WAnchor(WLink link)
          Creates an anchor for the given link.
WAnchor(WLink link, java.lang.CharSequence text)
          Creates an anchor for the given link with a text.
WAnchor(WLink link, java.lang.CharSequence text, WContainerWidget parent)
          Creates an anchor for the given link with a text.
WAnchor(WLink link, WContainerWidget parent)
          Creates an anchor for the given link.
WAnchor(WLink link, WImage image)
          Creates an anchor for the given link with an image.
WAnchor(WLink link, WImage image, WContainerWidget parent)
          Creates an anchor for the given link with an image.
WAnchor(WResource resource)
          Creates an anchor linking to a resource (deprecated).
WAnchor(WResource resource, java.lang.CharSequence text)
          Creates an anchor linking to a resource with a text (deprecated).
WAnchor(WResource resource, java.lang.CharSequence text, WContainerWidget parent)
          Deprecated. Use WAnchor() instead.
WAnchor(WResource resource, WContainerWidget parent)
          Deprecated. Use WAnchor() instead.
WAnchor(WResource resource, WImage image)
          Creates an anchor linking to a resource with an image (deprecated).
WAnchor(WResource resource, WImage image, WContainerWidget parent)
          Deprecated. Use WAnchor() instead.
 
Method Summary
protected  void enableAjax()
          Progresses to an Ajax-enabled widget.
 WImage getImage()
          Returns the image.
 WLink getLink()
          Returns the link.
 AnchorTarget getTarget()
          Returns the location where the linked content should be displayed.
 WString getText()
          Returns the label text.
 TextFormat getTextFormat()
          Returns the text format.
 boolean hasWordWrap()
          Returns whether the widget may break lines.
 void remove()
          Destructor.
 void setImage(WImage image)
          Sets an image.
 void setLink(WLink link)
          Sets the link.
 void setRef(java.lang.String url)
          Deprecated. Use setLink() instead.
 void setRefInternalPath(java.lang.String path)
          Deprecated. Use setLink() instead.
 void setResource(WResource resource)
          Deprecated. Use setLink() instead.
 void setTarget(AnchorTarget target)
          Sets the location where the linked content should be displayed.
 void setText(java.lang.CharSequence text)
          Sets the label text.
 void setTextFormat(TextFormat textFormat)
          Configures the text format.
 void setWordWrap(boolean wordWrap)
          Configures text word wrapping.
 
Methods inherited from class eu.webtoolkit.jwt.WContainerWidget
addWidget, clear, getContentAlignment, getCount, getIndexOf, getLayout, getPadding, getWidget, insertBefore, insertWidget, isList, isOrderedList, isUnorderedList, removeWidget, scrolled, setContentAlignment, setContentAlignment, setLayout, setLayout, setLayout, setList, setList, setOverflow, setOverflow, setOverflow, setPadding, setPadding, setPadding
 
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, setDraggable, setDraggable, setDraggable, setDraggable, touchEnded, touchMoved, touchStarted
 
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, callJavaScriptMember, childrenChanged, doJavaScript, domCanBeSaved, escapeText, escapeText, escapeText, escapeText, find, getAttributeValue, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isVisible, jsStringLiteral, jsStringLiteral, refresh, removeScript, removeStyleClass, render, resize, setAttributeValue, setClearSides, setDecorationStyle, setDisabled, setFloatSide, setHidden, setHiddenKeepsGeometry, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setOffsets, setPopup, setPositionScheme, setSelectable, setStyleClass, setTabIndex, setToolTip, setVerticalAlignment, updateSignalConnection
 
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, containsExposed, disable, dropEvent, enable, getDrop, getJsRef, getParent, hide, htmlText, isLayoutSizeAware, layoutSizeChanged, positionAt, positionAt, removeStyleClass, resize, setClearSides, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
 
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getObjectName, setObjectName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WAnchor

public WAnchor(WContainerWidget parent)
Creates an anchor.


WAnchor

public WAnchor()
Creates an anchor.

Calls this((WContainerWidget)null)


WAnchor

public WAnchor(WLink link,
               WContainerWidget parent)
Creates an anchor for the given link.

The link may point to a URL, a dynamic resource, or an internal path.

See Also:
setLink(WLink link)

WAnchor

public WAnchor(WLink link)
Creates an anchor for the given link.

Calls this(link, (WContainerWidget)null)


WAnchor

public WAnchor(java.lang.String ref,
               WContainerWidget parent)
Deprecated. Use WAnchor() instead.

Creates an anchor linking to a URL (deprecated).


WAnchor

public WAnchor(java.lang.String ref)
Creates an anchor linking to a URL (deprecated).

Calls this(ref, (WContainerWidget)null)


WAnchor

public WAnchor(WResource resource,
               WContainerWidget parent)
Deprecated. Use WAnchor() instead.

Creates an anchor linking to a resource (deprecated).

The resource specifies application-dependent content that may be generated by your application on demand.

The anchor does not assume ownership of resource, so that you may share the same resources for several anchors.


WAnchor

public WAnchor(WResource resource)
Creates an anchor linking to a resource (deprecated).

Calls this(resource, (WContainerWidget)null)


WAnchor

public WAnchor(WLink link,
               java.lang.CharSequence text,
               WContainerWidget parent)
Creates an anchor for the given link with a text.

The link may point to a URL, a dynamic resource, or an internal path.

See Also:
setLink(WLink link), setText(CharSequence text)

WAnchor

public WAnchor(WLink link,
               java.lang.CharSequence text)
Creates an anchor for the given link with a text.

Calls this(link, text, (WContainerWidget)null)


WAnchor

public WAnchor(java.lang.String ref,
               java.lang.CharSequence text,
               WContainerWidget parent)
Deprecated. Use WAnchor() instead.

Creates an anchor linking to a URL with a text (deprecated).


WAnchor

public WAnchor(java.lang.String ref,
               java.lang.CharSequence text)
Creates an anchor linking to a URL with a text (deprecated).

Calls this(ref, text, (WContainerWidget)null)


WAnchor

public WAnchor(WResource resource,
               java.lang.CharSequence text,
               WContainerWidget parent)
Deprecated. Use WAnchor() instead.

Creates an anchor linking to a resource with a text (deprecated).

The resource specifies application-dependent content that may be generated by your application on demand.

The anchor does not assume ownership of resource, so that you may share the same resources for several anchors.


WAnchor

public WAnchor(WResource resource,
               java.lang.CharSequence text)
Creates an anchor linking to a resource with a text (deprecated).

Calls this(resource, text, (WContainerWidget)null)


WAnchor

public WAnchor(WLink link,
               WImage image,
               WContainerWidget parent)
Creates an anchor for the given link with an image.

See Also:
setLink(WLink link), setImage(WImage image)

WAnchor

public WAnchor(WLink link,
               WImage image)
Creates an anchor for the given link with an image.

Calls this(link, image, (WContainerWidget)null)


WAnchor

public WAnchor(java.lang.String ref,
               WImage image,
               WContainerWidget parent)
Deprecated. Use WAnchor() instead.

Creates an anchor linking to a URL with an image (deprecated).


WAnchor

public WAnchor(java.lang.String ref,
               WImage image)
Creates an anchor linking to a URL with an image (deprecated).

Calls this(ref, image, (WContainerWidget)null)


WAnchor

public WAnchor(WResource resource,
               WImage image,
               WContainerWidget parent)
Deprecated. Use WAnchor() instead.

Creates an anchor linking to a resource with an image (deprecated).


WAnchor

public WAnchor(WResource resource,
               WImage image)
Creates an anchor linking to a resource with an image (deprecated).

Calls this(resource, image, (WContainerWidget)null)

Method Detail

remove

public void remove()
Description copied from class: WContainerWidget
Destructor.

Overrides:
remove in class WContainerWidget
See Also:
WContainerWidget.removeWidget(WWidget widget)

setLink

public void setLink(WLink link)
Sets the link.

The link may hold a URL, a resource, or an internal path.

When the link points to a resource, the contents of the link may be generated by your application on demand.

When the link points to an internal path, activating the anchor will change the application's internal path or open a new session with the given path as initial path). This is the easiest way to let the application participate in browser history, and generate URLs that are bookmarkable and search engine friendly.


getLink

public WLink getLink()
Returns the link.

See Also:
setLink(WLink link)

setRef

public void setRef(java.lang.String url)
Deprecated. Use setLink() instead.

Sets the linked URL (deprecated).


setRefInternalPath

public void setRefInternalPath(java.lang.String path)
Deprecated. Use setLink() instead.

Sets a link to an internal path (deprecated).


setResource

public void setResource(WResource resource)
Deprecated. Use setLink() instead.

Sets a destination resource (deprecated).

The anchor does not assume ownership of the resource.


setText

public void setText(java.lang.CharSequence text)
Sets the label text.

If no text was previously set, a new WText widget is added using WContainerWidget#addWidget().


getText

public WString getText()
Returns the label text.

Returns an empty string if no label was set.

See Also:
setText(CharSequence text)

setWordWrap

public void setWordWrap(boolean wordWrap)
Configures text word wrapping.

When wordWrap is true, the text set with setText() may be broken up over multiple lines. When wordWrap is false, the text will displayed on a single line, unless the text contains <br /> tags or other block-level tags.

The default value is true.

See Also:
hasWordWrap()

setTextFormat

public void setTextFormat(TextFormat textFormat)
Configures the text format.

The default text format is XHTMLText.

See Also:
WText.setTextFormat(TextFormat textFormat)

getTextFormat

public TextFormat getTextFormat()
Returns the text format.

See Also:
setTextFormat(TextFormat textFormat)

hasWordWrap

public boolean hasWordWrap()
Returns whether the widget may break lines.

See Also:
setWordWrap(boolean wordWrap)

setImage

public void setImage(WImage image)
Sets an image.

If an image was previously set, it is deleted. The image is added using WContainerWidget#addWidget().

Ownership of the image is transferred to the anchor.


getImage

public WImage getImage()
Returns the image.

Returns null if no image is set.

See Also:
setImage(WImage image)

setTarget

public void setTarget(AnchorTarget target)
Sets the location where the linked content should be displayed.

By default, the linked content is displayed in the application ( AnchorTarget.TargetSelf). When the destination is an HTML document, the application is replaced with the new document. When the link is to a document that cannot be displayed in the browser, it is offered for download or opened using an external program, depending on browser settings.

By setting target to AnchorTarget.TargetNewWindow, the destination is displayed in a new browser window or tab.

See Also:
getTarget()

getTarget

public AnchorTarget getTarget()
Returns the location where the linked content should be displayed.

See Also:
setTarget(AnchorTarget target)

enableAjax

protected void enableAjax()
Description copied from class: WWidget
Progresses to an Ajax-enabled widget.

This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.

You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.

Overrides:
enableAjax in class WWebWidget
See Also:
WApplication.enableAjax()