Class WAnchor
- Direct Known Subclasses:
IndexAnchor
public class WAnchor extends WContainerWidget
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()
. 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
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Field Summary
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_
-
Constructor Summary
Constructors Constructor Description WAnchor()
Creates an anchor.WAnchor(WContainerWidget parent)
Creates an anchor.WAnchor(WLink link)
Creates an anchor for the given link.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(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(WResource resource)
Creates an anchor linking to a resource (deprecated).WAnchor(WResource resource, WContainerWidget parent)
Deprecated.WAnchor(WResource resource, WImage image)
Creates an anchor linking to a resource with an image (deprecated).WAnchor(WResource resource, WImage image, WContainerWidget parent)
Deprecated.UseWAnchor()
instead.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.UseWAnchor()
instead.WAnchor(java.lang.String ref)
Creates an anchor linking to a URL (deprecated).WAnchor(java.lang.String ref, WContainerWidget parent)
Deprecated.UseWAnchor()
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.UseWAnchor()
instead.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.UseWAnchor()
instead. -
Method Summary
Modifier and Type Method Description protected void
enableAjax()
Progresses to an Ajax-enabled widget.WImage
getImage()
Returns the image.WLink
getLink()
Returns the link.WResource
getResource()
Deprecated.UsegetLink()
instead.int
getTabIndex()
Returns the tab index.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.boolean
isCanReceiveFocus()
Returns whether the widget can receive focus.boolean
isSetFirstFocus()
Set focus on the widget's first descendant.protected void
propagateSetEnabled(boolean enabled)
Propagates that a widget was enabled or disabled through children.void
setImage(WImage image)
Sets an image.void
setLink(WLink link)
Sets the link.void
setRef(java.lang.String url)
Deprecated.UsesetLink()
instead.void
setRefInternalPath(java.lang.String path)
Deprecated.UsesetLink()
instead.void
setResource(WResource resource)
Deprecated.UsesetLink()
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, createDomElement, getContentAlignment, getCount, getDomChanges, getIndexOf, getLayout, getPadding, getScrollLeft, getScrollTop, getWidget, insertBefore, insertWidget, isGlobalUnfocussed, isList, isOrderedList, isUnorderedList, parentResized, remove, removeWidget, scrolled, setContentAlignment, setContentAlignment, setFormData, setGlobalUnfocused, 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, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggable
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, blurred, callJavaScriptMember, childrenChanged, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isThemeStyleEnabled, isVisible, jsStringLiteral, jsStringLiteral, parentResized, propagateSetVisible, refresh, removeScript, removeStyleClass, render, resize, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setOffsets, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, updateSignalConnection, voidEventSignal
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isLayoutSizeAware, layoutSizeChanged, needsRerender, positionAt, positionAt, removeChild, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setObjectName, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getObjectName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WAnchor
Creates an anchor. -
WAnchor
public WAnchor()Creates an anchor. -
WAnchor
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
Creates an anchor for the given link. -
WAnchor
Deprecated.UseWAnchor()
instead.Creates an anchor linking to a URL (deprecated). -
WAnchor
public WAnchor(java.lang.String ref)Creates an anchor linking to a URL (deprecated). -
WAnchor
Deprecated.UseWAnchor()
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
Creates an anchor linking to a resource (deprecated). -
WAnchor
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
Creates an anchor for the given link with a text. -
WAnchor
Deprecated.UseWAnchor()
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). -
WAnchor
Deprecated.UseWAnchor()
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
Creates an anchor linking to a resource with a text (deprecated). -
WAnchor
Creates an anchor for the given link with an image.- See Also:
setLink(WLink link)
,setImage(WImage image)
-
WAnchor
Creates an anchor for the given link with an image. -
WAnchor
Deprecated.UseWAnchor()
instead.Creates an anchor linking to a URL with an image (deprecated). -
WAnchor
Creates an anchor linking to a URL with an image (deprecated). -
WAnchor
Deprecated.UseWAnchor()
instead.Creates an anchor linking to a resource with an image (deprecated). -
WAnchor
Creates an anchor linking to a resource with an image (deprecated).
-
-
Method Details
-
setLink
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 theapplication's internal path
or open a new session with the given path asinitial 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
Returns the link.- See Also:
setLink(WLink link)
-
setRef
public void setRef(java.lang.String url)Deprecated.UsesetLink()
instead.Sets the linked URL (deprecated). -
setRefInternalPath
public void setRefInternalPath(java.lang.String path)Deprecated.UsesetLink()
instead.Sets a link to an internal path (deprecated). -
setResource
Deprecated.UsesetLink()
instead.Sets a destination resource (deprecated).The anchor does not assume ownership of the resource.
-
getResource
Deprecated.UsegetLink()
instead.Returns the destination resource (deprecated).Returns
null
if no resource has been set. -
setText
public void setText(java.lang.CharSequence text)Sets the label text.If no text was previously set, a new
WText
widget is added usingWContainerWidget#addWidget()
. -
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
istrue
, the text set withsetText()
may be broken up over multiple lines. WhenwordWrap
isfalse
, 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
Configures the text format.The default text format is XHTMLText.
-
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
Sets an image.If an image was previously set, it is deleted. The
image
is added usingWContainerWidget#addWidget()
.Ownership of the image is transferred to the anchor.
-
getImage
Returns the image.Returns
null
if no image is set.- See Also:
setImage(WImage image)
-
setTarget
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
toAnchorTarget.TargetNewWindow
, the destination is displayed in a new browser window or tab.- See Also:
getTarget()
-
getTarget
Returns the location where the linked content should be displayed.- See Also:
setTarget(AnchorTarget target)
-
isCanReceiveFocus
public boolean isCanReceiveFocus()Description copied from class:WWidget
Returns whether the widget can receive focus.- Overrides:
isCanReceiveFocus
in classWWebWidget
- See Also:
WWidget.setCanReceiveFocus(boolean enabled)
-
getTabIndex
public int getTabIndex()Description copied from class:WWidget
Returns the tab index.- Overrides:
getTabIndex
in classWWebWidget
- See Also:
WWidget.setTabIndex(int index)
-
isSetFirstFocus
public boolean isSetFirstFocus()Description copied from class:WWidget
Set focus on the widget's first descendant.Set focus on the widget itself, or on a first descendant which can receive focus.
Returns whether focus could be set.
- Overrides:
isSetFirstFocus
in classWWebWidget
-
propagateSetEnabled
protected void propagateSetEnabled(boolean enabled)Description copied from class:WWidget
Propagates that a widget was enabled or disabled through children.When enabling or disabling a widget, you usually also want to disable contained children. This method is called by
setDisabled()
to propagate its state to all children.You may want to reimplement this method if they wish to render differently when a widget is disabled. The default implementation will propagate the signal to all children.
- Overrides:
propagateSetEnabled
in classWInteractWidget
-
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 classWWebWidget
- See Also:
WApplication.enableAjax()
-
WAnchor()
instead.