Package com.google.gwt.user.client.ui

## Class DirectionalTextHelper

- java.lang.Object
- - com.google.gwt.user.client.ui.DirectionalTextHelper

- All Implemented Interfaces:
    `HasDirectionEstimator`

      public class DirectionalTextHelper
      extends java.lang.Object
      implements 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

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static DirectionEstimator` | `DEFAULT_DIRECTION_ESTIMATOR` | A default direction estimator instance.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DirectionalTextHelper​(Element element, boolean isElementInline)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `DirectionEstimator` | `getDirectionEstimator()` | Returns the `DirectionEstimator` object.
    `java.lang.String` | `getHtml()` | Get the inner html of the element, taking the inner span wrap into consideration, if needed.
    `java.lang.String` | `getText()` | Get the inner text of the element, taking the inner span wrap into consideration, if needed.
    `HasDirection.Direction` | `getTextDirection()` |
    `java.lang.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)` | Deprecated.
    `void` | `setDirectionEstimator​(boolean enabled)` | See note at `setDirectionEstimator(com.google.gwt.i18n.shared.DirectionEstimator)`.
    `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` | `setHtml​(SafeHtml content)` | Sets the element's content to the given value (html).
    `void` | `setHtml​(SafeHtml content, HasDirection.Direction dir)` | Sets the element's content to the given value (html), applying the given direction.
    `void` | `setHtml​(java.lang.String content)` | Sets the element's content to the given value (html).
    `void` | `setHtml​(java.lang.String content, HasDirection.Direction dir)` | Sets the element's content to the given value (html), applying the given direction.
    `void` | `setText​(java.lang.String content)` | Sets the element's content to the given value (plain text).
    `void` | `setText​(java.lang.String content, HasDirection.Direction dir)` | Sets the element's content to the given value (plain text), applying the given direction.
    `void` | `setTextOrHtml​(java.lang.String content, boolean isHtml)` | Sets the element's content to the given value (either plain text or HTML).
    `void` | `setTextOrHtml​(java.lang.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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_DIRECTION_ESTIMATOR

          public static final DirectionEstimator DEFAULT_DIRECTION_ESTIMATOR

      A default direction estimator instance.

  - ### Constructor Detail

    - #### DirectionalTextHelper

          public DirectionalTextHelper​(Element element,
                                       boolean isElementInline)

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

  - ### Method Detail

    - #### getDirectionEstimator

          public DirectionEstimator getDirectionEstimator()

      Description copied from interface: `HasDirectionEstimator`
      Returns the `DirectionEstimator` object.
      Specified by:
        `getDirectionEstimator` in interface `HasDirectionEstimator`

    - #### getTextDirection

          public HasDirection.Direction getTextDirection()

    - #### getText

          public java.lang.String getText()

      Get the inner text of the element, taking the inner span wrap into consideration, if needed.
      Returns:
        the text

    - #### getHtml

          public java.lang.String getHtml()

      Get the inner html of the element, taking the inner span wrap into consideration, if needed.
      Returns:
        the html

    - #### getTextOrHtml

          public java.lang.String getTextOrHtml​(boolean isHtml)

      Get the inner text or html of the element, taking the inner span wrap into consideration, if needed. Prefer using `getText()` or `getHtml()` 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
          public void setDirection​(HasDirection.Direction direction)

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

    - #### setDirectionEstimator

          public void setDirectionEstimator​(boolean enabled)

      See note at `setDirectionEstimator(com.google.gwt.i18n.shared.DirectionEstimator)`.
      Specified by:
        `setDirectionEstimator` in interface `HasDirectionEstimator`
      Parameters:
        `enabled` - Whether to enable direction estimation. If `true`, sets the `DirectionEstimator` object to a default `DirectionEstimator`.

    - #### setDirectionEstimator

          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.
      Specified by:
        `setDirectionEstimator` in interface `HasDirectionEstimator`
      Parameters:
        `directionEstimator` - The `DirectionEstimator` to be set. `null` means turning off direction estimation.

    - #### setText

          public void setText​(java.lang.String content)

      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 at `setText(String, Direction)`.
      Parameters:
        `content` - the element's new content

    - #### setHtml

          public void setHtml​(SafeHtml content)

      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 at `setHtml(String, Direction)`.
      Parameters:
        `content` - the element's new content

    - #### setHtml

          public void setHtml​(java.lang.String content)

      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 at `setHtml(String, Direction)`.
      Parameters:
        `content` - the element's new content

    - #### setTextOrHtml

          public void setTextOrHtml​(java.lang.String content,
                                    boolean isHtml)

      Sets the element's content to the given value (either plain text or HTML). Prefer using `setText` or `setHtml` instead of this method.
      Parameters:
        `content` - the element's new content
        `isHtml` - whether the content is HTML

    - #### setText

          public void setText​(java.lang.String content,
                              HasDirection.Direction dir)

      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 `BidiFormatter` for more details.
      Parameters:
        `content` - the element's new content
        `dir` - the content's direction

    - #### setHtml

          public void setHtml​(SafeHtml content,
                              HasDirection.Direction dir)

      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 `BidiFormatter` for more details.
      Parameters:
        `content` - the element's new content
        `dir` - the content's direction

    - #### setHtml

          public void setHtml​(java.lang.String content,
                              HasDirection.Direction dir)

      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 `BidiFormatter` for more details.
      Parameters:
        `content` - the element's new content
        `dir` - the content's direction

    - #### setTextOrHtml

          public void setTextOrHtml​(java.lang.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. Prefer using `setText` or `setHtml` instead of this method.
      Parameters:
        `content` - the element's new content
        `dir` - the content's direction
        `isHtml` - whether the content is HTML