java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.Hyperlink
Known Direct Subclasses

Class Overview

A widget that serves as an "internal" hyperlink. That is, it is a link to another state of the running application. When clicked, it will create a new history frame using newItem(String), but without reloading the page.

If you want an HTML hyperlink (<a> tag) without interacting with the history system, use Anchor instead.

Being a true hyperlink, it is also possible for the user to "right-click, open link in new window", which will cause the application to be loaded in a new window at the state specified by the hyperlink.

Built-in Bidi Text Support

This widget is capable of automatically adjusting its direction according to its content. This feature is controlled by setDirectionEstimator(boolean) or passing a DirectionEstimator parameter to the constructor, and is off by default.

CSS Style Rules

  • .gwt-Hyperlink { }

Example

{@example com.google.gwt.examples.HistoryExample}

See Also

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Fields
public static final DirectionEstimator DEFAULT_DIRECTION_ESTIMATOR
protected final DirectionalTextHelper directionalTextHelper
Public Constructors
Hyperlink()
Creates an empty hyperlink.
Hyperlink(SafeHtml html, String targetHistoryToken)
Creates a hyperlink with its html and target history token specified.
Hyperlink(SafeHtml html, HasDirection.Direction dir, String targetHistoryToken)
Creates a hyperlink with its html and target history token specified.
Hyperlink(SafeHtml html, DirectionEstimator directionEstimator, String targetHistoryToken)
Creates a hyperlink with its html and target history token specified.
Hyperlink(String text, String targetHistoryToken)
Creates a hyperlink with its text and target history token specified.
Hyperlink(String text, HasDirection.Direction dir, String targetHistoryToken)
Creates a hyperlink with its text and target history token specified.
Hyperlink(String text, DirectionEstimator directionEstimator, String targetHistoryToken)
Creates a hyperlink with its text and target history token specified.
Hyperlink(String text, boolean asHTML, String targetHistoryToken)
Creates a hyperlink with its text and target history token specified.
Protected Constructors
Hyperlink(Element elem)
Public Methods
HandlerRegistration addClickHandler(ClickHandler handler)
This method is deprecated. Use addClickHandler(ClickHandler) instead and call History.newItem from the handler if you need to process the click before the history token is set.
void addClickListener(ClickListener listener)
This method is deprecated. Use addClickHandler(ClickHandler) instead and call History.newItem from the handler if you need to process the click before the history token is set.
DirectionEstimator getDirectionEstimator()
Returns the DirectionEstimator object.
String getHTML()
Gets this object's contents as HTML.
String getTargetHistoryToken()
Gets the history token referenced by this hyperlink.
String getText()
Gets this object's text.
HasDirection.Direction getTextDirection()
Gets the direction of this object's text.
void onBrowserEvent(Event event)
Fired whenever a browser event is received.
void removeClickListener(ClickListener listener)
This method is deprecated. Use the removeHandler() method on the object returned by an add*Handler method instead
void setDirectionEstimator(DirectionEstimator directionEstimator)
Sets the DirectionEstimator object.

Note: DirectionEstimator should be set before the widget has any content; it's highly recommended to set it using a constructor.

void setDirectionEstimator(boolean enabled)
Toggles on / off direction estimation.

See note at setDirectionEstimator(DirectionEstimator).

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(String html)
Sets this object's contents via HTML.
void setTargetHistoryToken(String targetHistoryToken)
Sets the history token referenced by this hyperlink.
void setText(String text, HasDirection.Direction dir)
Sets this object's text, also declaring its direction.
void setText(String text)
Sets this object's text.
Protected Methods
void onEnsureDebugId(String baseID)
Affected Elements:
  • -wrapper = the div around the link.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.event.dom.client.HasClickHandlers
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.i18n.shared.HasDirectionEstimator
From interface com.google.gwt.safehtml.client.HasSafeHtml
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.ui.HasDirectionalSafeHtml
From interface com.google.gwt.user.client.ui.HasDirectionalText
From interface com.google.gwt.user.client.ui.HasHTML
From interface com.google.gwt.user.client.ui.HasText
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.SourcesClickEvents

Fields

public static final DirectionEstimator DEFAULT_DIRECTION_ESTIMATOR

protected final DirectionalTextHelper directionalTextHelper

Public Constructors

public Hyperlink ()

Creates an empty hyperlink.

public Hyperlink (SafeHtml html, String targetHistoryToken)

Creates a hyperlink with its html and target history token specified.

Parameters
html the hyperlink's safe html
targetHistoryToken the history token to which it will link

public Hyperlink (SafeHtml html, HasDirection.Direction dir, String targetHistoryToken)

Creates a hyperlink with its html and target history token specified.

Parameters
html the hyperlink's safe html
dir the html's direction
targetHistoryToken the history token to which it will link

public Hyperlink (SafeHtml html, DirectionEstimator directionEstimator, String targetHistoryToken)

Creates a hyperlink with its html and target history token specified.

Parameters
html the hyperlink's safe html
directionEstimator A DirectionEstimator object used for automatic direction adjustment. For convenience, DEFAULT_DIRECTION_ESTIMATOR can be used.
targetHistoryToken the history token to which it will link

public Hyperlink (String text, String targetHistoryToken)

Creates a hyperlink with its text and target history token specified.

Parameters
text the hyperlink's text
targetHistoryToken the history token to which it will link, which may not be null (use Anchor instead if you don't need history processing)

public Hyperlink (String text, HasDirection.Direction dir, String targetHistoryToken)

Creates a hyperlink with its text and target history token specified.

Parameters
text the hyperlink's text
dir the text's direction
targetHistoryToken the history token to which it will link, which may not be null (use Anchor instead if you don't need history processing)

public Hyperlink (String text, DirectionEstimator directionEstimator, String targetHistoryToken)

Creates a hyperlink with its text and target history token specified.

Parameters
text the hyperlink's text
directionEstimator A DirectionEstimator object used for automatic direction adjustment. For convenience, DEFAULT_DIRECTION_ESTIMATOR can be used.
targetHistoryToken the history token to which it will link, which may not be null (use Anchor instead if you don't need history processing)

public Hyperlink (String text, boolean asHTML, String targetHistoryToken)

Creates a hyperlink with its text and target history token specified.

Parameters
text the hyperlink's text
asHTML true to treat the specified text as html
targetHistoryToken the history token to which it will link

Protected Constructors

protected Hyperlink (Element elem)

Public Methods

public HandlerRegistration addClickHandler (ClickHandler handler)

This method is deprecated.
Use addClickHandler(ClickHandler) instead and call History.newItem from the handler if you need to process the click before the history token is set.

Adds a ClickEvent handler.

Parameters
handler the click handler
Returns

public void addClickListener (ClickListener listener)

This method is deprecated.
Use addClickHandler(ClickHandler) instead and call History.newItem from the handler if you need to process the click before the history token is set.

Adds a listener interface to receive click events.

Parameters
listener the listener interface to add

public DirectionEstimator getDirectionEstimator ()

Returns the DirectionEstimator object.

public String getHTML ()

Gets this object's contents as HTML.

Returns
  • the object's HTML

public String getTargetHistoryToken ()

Gets the history token referenced by this hyperlink.

Returns
  • the target history token

public String getText ()

Gets this object's text.

Returns
  • the object's text

public HasDirection.Direction getTextDirection ()

Gets the direction of this object's text.

Returns
  • the direction of this object's text

public void onBrowserEvent (Event event)

Fired whenever a browser event is received.

Parameters
event the event received

public void removeClickListener (ClickListener listener)

This method is deprecated.
Use the removeHandler() method on the object returned by an add*Handler method instead

Removes a previously added listener interface.

Parameters
listener the listener interface to remove

public void setDirectionEstimator (DirectionEstimator directionEstimator)

Sets the 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.

Parameters
directionEstimator The {code DirectionEstimator} to be set. null means turning off direction estimation.

public void setDirectionEstimator (boolean enabled)

Toggles on / off direction estimation.

See note at setDirectionEstimator(DirectionEstimator).

Parameters
enabled Whether to enable direction estimation. If true, sets the DirectionEstimator object to a default DirectionEstimator.

public void setHTML (SafeHtml html)

Sets this object's contents via known-safe HTML.

The object will behave exactly the same as when a widget's 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 setHTML(String), using this method cannot result in Cross-Site Scripting security vulnerabilities.

Parameters
html the object's new HTML, represented as a SafeHtml object

public void setHTML (SafeHtml html, HasDirection.Direction dir)

Sets this object's html, also declaring its direction.

Parameters
html the object's new html
dir the html's direction

public void setHTML (String html)

Sets this object's contents via HTML. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using setText(String) whenever possible.

Parameters
html the object's new HTML

public void setTargetHistoryToken (String targetHistoryToken)

Sets the history token referenced by this hyperlink. This is the history token that will be passed to newItem(String) when this link is clicked.

Parameters
targetHistoryToken the new history token, which may not be null (use Anchor instead if you don't need history processing)

public void setText (String text, HasDirection.Direction dir)

Sets this object's text, also declaring its direction.

Parameters
text the object's new text
dir the text's direction

public void setText (String text)

Sets this object's text.

Parameters
text the object's new text

Protected Methods

protected void onEnsureDebugId (String baseID)

Affected Elements:

  • -wrapper = the div around the link.

Parameters
baseID the base ID used by the main element