public class Anchor extends FocusWidget implements HasHorizontalAlignment, HasName, HasHTML, HasWordWrap, HasDirection, HasDirectionEstimator, HasDirectionalSafeHtml
If you want use this anchor only for changing history states, use
Hyperlink
instead.
setDirectionEstimator(boolean)
or
passing a DirectionEstimator parameter to the constructor, and is off by
default.
Hyperlink
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
HasHorizontalAlignment.AutoHorizontalAlignmentConstant, HasHorizontalAlignment.HorizontalAlignmentConstant
HasDirection.Direction
Modifier and Type | Field and Description |
---|---|
static DirectionEstimator |
DEFAULT_DIRECTION_ESTIMATOR |
eventsToSink
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
ALIGN_CENTER, ALIGN_DEFAULT, ALIGN_JUSTIFY, ALIGN_LEFT, ALIGN_LOCALE_END, ALIGN_LOCALE_START, ALIGN_RIGHT
Modifier | Constructor and Description |
---|---|
|
Anchor()
Creates an empty anchor.
|
|
Anchor(boolean useDefaultHref)
Creates an anchor.
|
protected |
Anchor(Element element)
This constructor may be used by subclasses to explicitly use an existing
element.
|
|
Anchor(SafeHtml html)
Creates an anchor for scripting.
|
|
Anchor(SafeHtml html,
DirectionEstimator directionEstimator)
Creates an anchor for scripting.
|
|
Anchor(SafeHtml html,
DirectionEstimator directionEstimator,
SafeUri href)
Creates an anchor with its html and href (target URL) specified.
|
|
Anchor(SafeHtml html,
DirectionEstimator directionEstimator,
java.lang.String href)
Creates an anchor with its html and href (target URL) specified.
|
|
Anchor(SafeHtml html,
HasDirection.Direction dir)
Creates an anchor for scripting.
|
|
Anchor(SafeHtml html,
HasDirection.Direction dir,
SafeUri href)
Creates an anchor with its html and href (target URL) specified.
|
|
Anchor(SafeHtml html,
HasDirection.Direction dir,
java.lang.String href)
Creates an anchor with its html and href (target URL) specified.
|
|
Anchor(SafeHtml html,
SafeUri href)
Creates an anchor with its html and href (target URL) specified.
|
|
Anchor(SafeHtml html,
SafeUri href,
java.lang.String target)
Creates a source anchor (link to URI).
|
|
Anchor(SafeHtml html,
java.lang.String href)
Creates an anchor with its html and href (target URL) specified.
|
|
Anchor(SafeHtml html,
java.lang.String href,
java.lang.String target)
Creates a source anchor (link to URI).
|
|
Anchor(java.lang.String text)
Creates an anchor for scripting.
|
|
Anchor(java.lang.String text,
boolean asHtml)
Creates an anchor for scripting.
|
|
Anchor(java.lang.String text,
boolean asHTML,
java.lang.String href)
Creates an anchor with its text and href (target URL) specified.
|
|
Anchor(java.lang.String text,
boolean asHtml,
java.lang.String href,
java.lang.String target)
Creates a source anchor (link to URI).
|
|
Anchor(java.lang.String text,
DirectionEstimator directionEstimator)
Creates an anchor for scripting.
|
|
Anchor(java.lang.String text,
DirectionEstimator directionEstimator,
java.lang.String href)
Creates an anchor with its text and href (target URL) specified.
|
|
Anchor(java.lang.String text,
HasDirection.Direction dir)
Creates an anchor for scripting.
|
|
Anchor(java.lang.String text,
HasDirection.Direction dir,
java.lang.String href)
Creates an anchor with its text and href (target URL) specified.
|
|
Anchor(java.lang.String text,
java.lang.String href)
Creates an anchor with its text and href (target URL) specified.
|
|
Anchor(java.lang.String text,
java.lang.String href,
java.lang.String target)
Creates a source anchor with a frame target.
|
Modifier and Type | Method and Description |
---|---|
HasDirection.Direction |
getDirection()
Gets the directionality of the widget.
|
DirectionEstimator |
getDirectionEstimator()
Returns the
DirectionEstimator object. |
HasHorizontalAlignment.HorizontalAlignmentConstant |
getHorizontalAlignment()
Gets the horizontal alignment.
|
java.lang.String |
getHref()
Gets the anchor's href (the url to which it links).
|
java.lang.String |
getHTML()
Gets this object's contents as HTML.
|
java.lang.String |
getName()
Gets the widget's name.
|
int |
getTabIndex()
Gets the tab index.
|
java.lang.String |
getTarget()
Gets the anchor's target frame (the frame in which navigation will occur
when the link is selected).
|
java.lang.String |
getText()
Gets this object's text.
|
HasDirection.Direction |
getTextDirection()
Gets the direction of this object's text.
|
boolean |
getWordWrap()
Gets whether word-wrapping is enabled.
|
void |
setAccessKey(char key)
Sets the widget's 'access key'.
|
void |
setDirection(HasDirection.Direction direction)
Deprecated.
Use
setDirectionEstimator(boolean) and / or pass explicit
direction to setText(java.lang.String) , setHTML(com.google.gwt.safehtml.shared.SafeHtml) instead |
void |
setDirectionEstimator(boolean enabled)
Toggles on / off direction estimation.
|
void |
setDirectionEstimator(DirectionEstimator directionEstimator)
Sets the
DirectionEstimator object. |
void |
setFocus(boolean focused)
Explicitly focus/unfocus this widget.
|
void |
setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant align)
Sets the horizontal alignment.
|
void |
setHref(SafeUri href)
Sets the anchor's href (the url to which it links).
|
void |
setHref(java.lang.String href)
Sets the anchor's href (the url to which it links).
|
void |
setHTML(SafeHtml html)
Sets this object's contents via known-safe HTML.
|
void |
setHTML(SafeHtml html,
HasDirection.Direction dir)
Sets this object's html, also declaring its direction.
|
void |
setHTML(java.lang.String html)
Sets this object's contents via HTML.
|
void |
setName(java.lang.String name)
Sets the widget's name.
|
void |
setTabIndex(int index)
Sets the widget's position in the tab index.
|
void |
setTarget(java.lang.String target)
Sets the anchor's target frame (the frame in which navigation will occur
when the link is selected).
|
void |
setText(java.lang.String text)
Sets this object's text.
|
void |
setText(java.lang.String text,
HasDirection.Direction dir)
Sets this object's text, also declaring its direction.
|
void |
setWordWrap(boolean wrap)
Sets whether word-wrapping is enabled.
|
static Anchor |
wrap(Element element)
Creates an Anchor widget that wraps an existing <a> element.
|
addBlurHandler, addClickHandler, addClickListener, addDoubleClickHandler, addDragEndHandler, addDragEnterHandler, addDragHandler, addDragLeaveHandler, addDragOverHandler, addDragStartHandler, addDropHandler, addFocusHandler, addFocusListener, addGestureChangeHandler, addGestureEndHandler, addGestureStartHandler, addKeyboardListener, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addMouseDownHandler, addMouseListener, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addMouseWheelListener, addTouchCancelHandler, addTouchEndHandler, addTouchMoveHandler, addTouchStartHandler, getFocusImpl, isEnabled, onAttach, removeClickListener, removeFocusListener, removeKeyboardListener, removeMouseListener, removeMouseWheelListener, setEnabled
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isAttached, isOrWasAttached, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEvents
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
fireEvent
public static final DirectionEstimator DEFAULT_DIRECTION_ESTIMATOR
public Anchor()
The anchor's href is not set, which means that the widget will not
not be styled with the browser's native link styles (such as underline and
font color). Use Anchor(boolean)
to add a default no-op href that
does not open a link but ensures the native link styles are applied.
Anchor(boolean)
public Anchor(boolean useDefaultHref)
javascript:;
, based on
the expectation that listeners will be added to the anchor.useDefaultHref
- true to set the default href to
javascript:;
, false to leave it blankpublic Anchor(SafeHtml html)
html
- the anchor's htmlpublic Anchor(SafeHtml html, HasDirection.Direction dir)
javascript : ;
, based on the
expectation that listeners will be added to the anchor.html
- the anchor's htmldir
- the html's directionpublic Anchor(SafeHtml html, DirectionEstimator directionEstimator)
javascript : ;
, based on the
expectation that listeners will be added to the anchor.html
- the anchor's htmldirectionEstimator
- A DirectionEstimator object used for automatic
direction adjustment. For convenience,
DEFAULT_DIRECTION_ESTIMATOR
can be used.public Anchor(java.lang.String text)
javascript:;
, based on the
expectation that listeners will be added to the anchor.text
- the anchor's textpublic Anchor(java.lang.String text, HasDirection.Direction dir)
javascript : ;
, based on the
expectation that listeners will be added to the anchor.text
- the anchor's textdir
- the text's directionpublic Anchor(java.lang.String text, DirectionEstimator directionEstimator)
javascript : ;
, based on the
expectation that listeners will be added to the anchor.text
- the anchor's textdirectionEstimator
- A DirectionEstimator object used for automatic
direction adjustment. For convenience,
DEFAULT_DIRECTION_ESTIMATOR
can be used.public Anchor(java.lang.String text, boolean asHtml)
javascript:;
, based on the
expectation that listeners will be added to the anchor.text
- the anchor's textasHtml
- true
to treat the specified text as htmlpublic Anchor(SafeHtml html, java.lang.String href)
html
- the anchor's htmlhref
- the url to which it will linkpublic Anchor(SafeHtml html, SafeUri href)
html
- the anchor's htmlhref
- the url to which it will linkpublic Anchor(SafeHtml html, HasDirection.Direction dir, java.lang.String href)
html
- the anchor's htmldir
- the html's directionhref
- the url to which it will linkpublic Anchor(SafeHtml html, HasDirection.Direction dir, SafeUri href)
html
- the anchor's htmldir
- the html's directionhref
- the url to which it will linkpublic Anchor(SafeHtml html, DirectionEstimator directionEstimator, java.lang.String href)
html
- the anchor's htmldirectionEstimator
- A DirectionEstimator object used for automatic
direction adjustment. For convenience,
DEFAULT_DIRECTION_ESTIMATOR
can be used.href
- the url to which it will linkpublic Anchor(SafeHtml html, DirectionEstimator directionEstimator, SafeUri href)
html
- the anchor's htmldirectionEstimator
- A DirectionEstimator object used for automatic
direction adjustment. For convenience,
DEFAULT_DIRECTION_ESTIMATOR
can be used.href
- the url to which it will linkpublic Anchor(java.lang.String text, java.lang.String href)
text
- the anchor's texthref
- the url to which it will linkpublic Anchor(java.lang.String text, HasDirection.Direction dir, java.lang.String href)
text
- the anchor's textdir
- the text's directionhref
- the url to which it will linkpublic Anchor(java.lang.String text, DirectionEstimator directionEstimator, java.lang.String href)
text
- the anchor's textdirectionEstimator
- A DirectionEstimator object used for automatic
direction adjustment. For convenience,
DEFAULT_DIRECTION_ESTIMATOR
can be used.href
- the url to which it will linkpublic Anchor(java.lang.String text, boolean asHTML, java.lang.String href)
text
- the anchor's textasHTML
- true
to treat the specified text as htmlhref
- the url to which it will linkpublic Anchor(SafeHtml html, java.lang.String href, java.lang.String target)
html
- the anchor's htmlhref
- the url to which it will linktarget
- the target frame (e.g. "_blank" to open the link in a new
window)public Anchor(SafeHtml html, SafeUri href, java.lang.String target)
html
- the anchor's htmlhref
- the url to which it will linktarget
- the target frame (e.g. "_blank" to open the link in a new
window)public Anchor(java.lang.String text, java.lang.String href, java.lang.String target)
text
- the anchor's texthref
- the url to which it will linktarget
- the target frame (e.g. "_blank" to open the link in a new
window)public Anchor(java.lang.String text, boolean asHtml, java.lang.String href, java.lang.String target)
text
- the anchor's textasHtml
- asHTML true
to treat the specified text as htmlhref
- the url to which it will linktarget
- the target frame (e.g. "_blank" to open the link in a new
window)protected Anchor(Element element)
element
- the element to be usedpublic static Anchor wrap(Element element)
RootPanel.detachNow(Widget)
.element
- the element to be wrappedpublic HasDirection.Direction getDirection()
HasDirection
getDirection
in interface HasDirection
RTL
if the directionality is right-to-left,
LTR
if the directionality is left-to-right, or
DEFAULT
if the directionality is not explicitly specifiedpublic DirectionEstimator getDirectionEstimator()
HasDirectionEstimator
DirectionEstimator
object.getDirectionEstimator
in interface HasDirectionEstimator
public HasHorizontalAlignment.HorizontalAlignmentConstant getHorizontalAlignment()
HasHorizontalAlignment
getHorizontalAlignment
in interface HasHorizontalAlignment
HasHorizontalAlignment.ALIGN_LEFT
,
HasHorizontalAlignment.ALIGN_CENTER
,
HasHorizontalAlignment.ALIGN_RIGHT
,
HasHorizontalAlignment.ALIGN_JUSTIFY
, or
null).public java.lang.String getHref()
public java.lang.String getHTML()
HasHTML
public java.lang.String getName()
HasName
public int getTabIndex()
FocusWidget
getTabIndex
in interface Focusable
getTabIndex
in class FocusWidget
public java.lang.String getTarget()
public java.lang.String getText()
HasText
public HasDirection.Direction getTextDirection()
HasDirectionalText
getTextDirection
in interface HasDirectionalText
public boolean getWordWrap()
HasWordWrap
getWordWrap
in interface HasWordWrap
true
if word-wrapping is enabled.public void setAccessKey(char key)
Focusable
setAccessKey
in interface Focusable
setAccessKey
in class FocusWidget
key
- the widget's access key@Deprecated public void setDirection(HasDirection.Direction direction)
setDirectionEstimator(boolean)
and / or pass explicit
direction to setText(java.lang.String)
, setHTML(com.google.gwt.safehtml.shared.SafeHtml)
insteadHasDirection
setDirection
in interface HasDirection
direction
- RTL
if the directionality should be set to right-to-left,
LTR
if the directionality should be set to left-to-right
DEFAULT
if the directionality should not be explicitly setpublic void setDirectionEstimator(boolean enabled)
See note at setDirectionEstimator(DirectionEstimator)
.
setDirectionEstimator
in interface HasDirectionEstimator
enabled
- Whether to enable direction estimation. If true
,
sets the DirectionEstimator
object to a default
DirectionEstimator
.public void setDirectionEstimator(DirectionEstimator directionEstimator)
DirectionEstimator
object.
Note: DirectionEstimator should be set before the widget has any content; it's highly recommended to set it using a constructor. Reason: if the widget already has non-empty content, this will update its direction according to the new estimator's result. This may cause flicker, and thus should be avoided.
setDirectionEstimator
in interface HasDirectionEstimator
directionEstimator
- The DirectionEstimator
to be set. null
means turning off direction estimation.public void setFocus(boolean focused)
Focusable
GWTTestCase#delayTestFinish
for more information on how to do this.setFocus
in interface Focusable
setFocus
in class FocusWidget
focused
- whether this widget should take focus or release itpublic void setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant align)
HasHorizontalAlignment
Use null
to clear horizontal alignment, allowing it to be
determined by the standard HTML mechanisms such as inheritance and CSS
rules.
setHorizontalAlignment
in interface HasHorizontalAlignment
align
- the horizontal alignment (
HasHorizontalAlignment.ALIGN_LEFT
,
HasHorizontalAlignment.ALIGN_CENTER
,
HasHorizontalAlignment.ALIGN_RIGHT
,
HasHorizontalAlignment.ALIGN_JUSTIFY
,
HasHorizontalAlignment.ALIGN_LOCALE_START
, or
HasHorizontalAlignment.ALIGN_LOCALE_END
).public void setHref(SafeUri href)
href
- the anchor's hrefpublic void setHref(java.lang.String href)
href
- the anchor's hrefpublic void setHTML(SafeHtml html)
HasSafeHtml
The object will behave exactly the same as when a widget's
HasHTML.setHTML(String)
method is
invoked; however the SafeHtml
passed to this method observes the
contract that it can be used in an HTML context without causing unsafe
script execution. Thus, unlike
HasHTML.setHTML(String)
, using this
method cannot result in Cross-Site Scripting security vulnerabilities.
setHTML
in interface HasSafeHtml
html
- the object's new HTML, represented as a SafeHtml
objectpublic void setHTML(java.lang.String html)
HasHTML
HasText.setText(String)
whenever possible.public void setHTML(SafeHtml html, HasDirection.Direction dir)
HasDirectionalSafeHtml
setHTML
in interface HasDirectionalSafeHtml
html
- the object's new htmldir
- the html's directionpublic void setName(java.lang.String name)
HasName
public void setTabIndex(int index)
Focusable
-1
will cause this widget to
be removed from the tab order.setTabIndex
in interface Focusable
setTabIndex
in class FocusWidget
index
- the widget's tab indexpublic void setTarget(java.lang.String target)
target
- the target framepublic void setText(java.lang.String text)
HasText
public void setText(java.lang.String text, HasDirection.Direction dir)
HasDirectionalText
setText
in interface HasDirectionalText
text
- the object's new textdir
- the text's directionpublic void setWordWrap(boolean wrap)
HasWordWrap
setWordWrap
in interface HasWordWrap
wrap
- true
to enable word-wrapping.