Package com.google.gwt.user.client.ui
Class DirectionalTextHelper
java.lang.Object
com.google.gwt.user.client.ui.DirectionalTextHelper
- All Implemented Interfaces:
HasDirectionEstimator
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DirectionEstimatorA default direction estimator instance. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns theDirectionEstimatorobject.getHtml()Get the inner html of the element, taking the inner span wrap into consideration, if needed.getText()Get the inner text of the element, taking the inner span wrap into consideration, if needed.getTextOrHtml(boolean isHtml) Get the inner text or html of the element, taking the inner span wrap into consideration, if needed.voidsetDirection(HasDirection.Direction direction) Deprecated.voidsetDirectionEstimator(boolean enabled) voidsetDirectionEstimator(DirectionEstimator directionEstimator) Note: if the element already has non-empty content, this will update its direction according to the new estimator's result.voidSets the element's content to the given value (html).voidsetHtml(SafeHtml content, HasDirection.Direction dir) Sets the element's content to the given value (html), applying the given direction.voidSets the element's content to the given value (html).voidsetHtml(String content, HasDirection.Direction dir) Sets the element's content to the given value (html), applying the given direction.voidSets the element's content to the given value (plain text).voidsetText(String content, HasDirection.Direction dir) Sets the element's content to the given value (plain text), applying the given direction.voidsetTextOrHtml(String content, boolean isHtml) Sets the element's content to the given value (either plain text or HTML).voidsetTextOrHtml(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.
-
Field Details
-
DEFAULT_DIRECTION_ESTIMATOR
A default direction estimator instance.
-
-
Constructor Details
-
DirectionalTextHelper
- Parameters:
element- The widget's element holding text.isElementInline- Whether the element is an inline element.
-
-
Method Details
-
getDirectionEstimator
Description copied from interface:HasDirectionEstimatorReturns theDirectionEstimatorobject.- Specified by:
getDirectionEstimatorin interfaceHasDirectionEstimator
-
getTextDirection
-
getText
Get the inner text of the element, taking the inner span wrap into consideration, if needed.- Returns:
- the text
-
getHtml
Get the inner html of the element, taking the inner span wrap into consideration, if needed.- Returns:
- the html
-
getTextOrHtml
Get the inner text or html of the element, taking the inner span wrap into consideration, if needed. Prefer usinggetText()orgetHtml()instead of this method.- Parameters:
isHtml- true to get the inner html, false to get the inner text- Returns:
- the text or html
-
setDirection
Deprecated.Provides implementation for HasDirection's method setDirection (normally deprecated), dealing with backwards compatibility issues. -
setDirectionEstimator
public void setDirectionEstimator(boolean enabled) - Specified by:
setDirectionEstimatorin interfaceHasDirectionEstimator- Parameters:
enabled- Whether to enable direction estimation. Iftrue, sets theDirectionEstimatorobject to a defaultDirectionEstimator.
-
setText
Sets the element's content to the given value (plain text). If direction estimation is off, the direction is verified to match the element's initial direction. Otherwise, the direction is affected as described atsetText(String, Direction).- Parameters:
content- the element's new content
-
setHtml
Sets the element's content to the given value (html). If direction estimation is off, the direction is verified to match the element's initial direction. Otherwise, the direction is affected as described atsetHtml(String, Direction).- Parameters:
content- the element's new content
-
setTextOrHtml
Sets the element's content to the given value (either plain text or HTML). Prefer usingsetTextorsetHtmlinstead of this method.- Parameters:
content- the element's new contentisHtml- whether the content is HTML
-
setText
Sets the element's content to the given value (plain text), 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
BidiFormatterfor more details.
- Parameters:
content- the element's new contentdir- the content's direction
-
setHtml
Sets the element's content to the given value (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
BidiFormatterfor more details.
- Parameters:
content- the element's new contentdir- the content's direction
-
setTextOrHtml
Sets the element's content to the given value (either plain text or HTML), applying the given direction. Prefer usingsetTextorsetHtmlinstead of this method.- Parameters:
content- the element's new contentdir- the content's directionisHtml- whether the content is HTML
-