public class

DirectionalTextHelper

extends Object
implements HasDirectionEstimator
java.lang.Object
   ↳ com.google.gwt.user.client.ui.DirectionalTextHelper

Class Overview

A helper class for displaying bidi (i.e. potentially opposite-direction) text or HTML in an element. Note: this class assumes that callers perform all their text/html and direction manipulations through it alone.

Summary

Fields
public static final DirectionEstimator DEFAULT_DIRECTION_ESTIMATOR A default direction estimator instance.
Public Constructors
DirectionalTextHelper(Element element, boolean isElementInline)
Public Methods
DirectionEstimator getDirectionEstimator()
Returns the DirectionEstimator object.
HasDirection.Direction getTextDirection()
String getTextOrHtml(boolean isHtml)
Get the inner text or html of the element, taking the inner span wrap into consideration, if needed.
void setDirection(HasDirection.Direction direction)
This method is deprecated. No replacement.
void setDirectionEstimator(DirectionEstimator directionEstimator)
Note: if the element already has non-empty content, this will update its direction according to the new estimator's result.
void setDirectionEstimator(boolean enabled)
void setTextOrHtml(String content, HasDirection.Direction dir, boolean isHtml)
Sets the element's content to the given value (either plain text or HTML), applying the given direction.
void setTextOrHtml(String content, boolean isHtml)
Sets the element's content to the given value (either plain text or HTML).
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.gwt.i18n.shared.HasDirectionEstimator

Fields

public static final DirectionEstimator DEFAULT_DIRECTION_ESTIMATOR

A default direction estimator instance.

Public Constructors

public DirectionalTextHelper (Element element, boolean isElementInline)

Parameters
element The widget's element holding text.
isElementInline Whether the element is an inline element.

Public Methods

public DirectionEstimator getDirectionEstimator ()

Returns the DirectionEstimator object.

public HasDirection.Direction getTextDirection ()

public String getTextOrHtml (boolean isHtml)

Get the inner text or html of the element, taking the inner span wrap into consideration, if needed.

Parameters
isHtml true to get the inner html, false to get the inner text
Returns
  • the text or html

public void setDirection (HasDirection.Direction direction)

This method is deprecated.
No replacement.

Provides implementation for HasDirection's method setDirection (normally deprecated), dealing with backwards compatibility issues.

public void setDirectionEstimator (DirectionEstimator directionEstimator)

Note: if the element 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; DirectionEstimator should be set before the element has any content.

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

public void setDirectionEstimator (boolean enabled)

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

public void setTextOrHtml (String content, HasDirection.Direction dir, boolean isHtml)

Sets the element's content to the given value (either plain text or HTML), applying the given direction.

Implementation details:

  • If the element is a block element, sets its dir attribute according to the given direction.
  • Otherwise (i.e. the element is inline), the direction is set using a nested <span dir=...> element which holds the content of the element. This nested span may be followed by a zero-width Unicode direction character (LRM or RLM). This manipulation is necessary to prevent garbling in case the direction of the element is opposite to the direction of its context. See BidiFormatter for more details.

Parameters
content the element's new content
dir the content's direction
isHtml whether the content is HTML

public void setTextOrHtml (String content, boolean isHtml)

Sets the element's content to the given value (either plain text or HTML). If direction estimation is off, the direction is verified to match the element's initial direction. Otherwise, the direction is affected as described at setTextOrHtml(String, Direction, boolean).

Parameters
content the element's new content
isHtml whether the content is HTML