com.google.gwt.i18n.client

## Class AutoDirectionHandler

- java.lang.Object
- - com.google.gwt.i18n.client.AutoDirectionHandler

All Implemented Interfaces:
  KeyUpHandler, EventHandler, HasDirectionEstimator

    public class AutoDirectionHandler
    extends java.lang.Object
    implements KeyUpHandler, HasDirectionEstimator

Utility class for handling auto-direction adjustment. This class is useful for automatically adjusting the direction of an object that takes text input, while the text is being entered.

### Nested Class Summary

Nested Classes
`static interface` `AutoDirectionHandler.Target` The interface an object must implement in order to add an AutoDirectionHandler to it.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static AutoDirectionHandler` `addTo(AutoDirectionHandler.Target target)` Operates like `addTo(Target, DirectionEstimator)`, but always uses a default DirectionEstimator, `WordCountDirectionEstimator`.
`static AutoDirectionHandler` `addTo(AutoDirectionHandler.Target target, boolean enabled)` Operates like `addTo(Target, DirectionEstimator)`, but uses a default DirectionEstimator, `WordCountDirectionEstimator` if `enabled`, or else a null DirectionEstimator, which means disabling direction estimation.
`static AutoDirectionHandler` `addTo(AutoDirectionHandler.Target target, DirectionEstimator directionEstimator)` Adds auto-direction adjustment to a given object: - Creates an AutoDirectionHandler.
`DirectionEstimator` `getDirectionEstimator()` Returns the DirectionEstimator object.
`void` `onKeyUp(KeyUpEvent event)` Automatically adjusts hasDirection's direction on KeyUpEvent events.
`void` `refreshDirection()` Adjusts target's direction according to the estimated direction of the text it supplies.
`void` `setDirectionEstimator(boolean enabled)` Toggles direction estimation on (using a default estimator) and off.
`void` `setDirectionEstimator(DirectionEstimator directionEstimator)` Sets the DirectionEstimator object.

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

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

### Method Detail

#### addTo

    public static AutoDirectionHandler addTo(AutoDirectionHandler.Target target)

Operates like `addTo(Target, DirectionEstimator)`, but always uses a default DirectionEstimator, `WordCountDirectionEstimator`.

Parameters:
  `target` - Object whose direction should be automatically adjusted on relevant events.
Returns:
  AutoDirectionHandler An instance of AutoDirectionHandler for the given object.

#### addTo

    public static AutoDirectionHandler addTo(AutoDirectionHandler.Target target,
                                             boolean enabled)

Operates like `addTo(Target, DirectionEstimator)`, but uses a default DirectionEstimator, `WordCountDirectionEstimator` if `enabled`, or else a null DirectionEstimator, which means disabling direction estimation.

Parameters:
  `target` - Object whose direction should be automatically adjusted on relevant events.
  `enabled` - Whether the handler is enabled upon creation.
Returns:
  AutoDirectionHandler An instance of AutoDirectionHandler for the given object.

#### addTo

    public static AutoDirectionHandler addTo(AutoDirectionHandler.Target target,
                                             DirectionEstimator directionEstimator)

Adds auto-direction adjustment to a given object: - Creates an AutoDirectionHandler. - Initializes it with the given DirectionEstimator. - Adds it as an event handler for the relevant events on the given object. - Returns the AutoDirectionHandler, so its setAutoDir() method can be called when the object's text changes by means other than the handled events.

Parameters:
  `target` - Object whose direction should be automatically adjusted on relevant events.
  `directionEstimator` - A DirectionEstimator object used for direction estimation (use null to disable direction estimation).
Returns:
  AutoDirectionHandler An instance of AutoDirectionHandler for the given object.

#### getDirectionEstimator

    public DirectionEstimator getDirectionEstimator()

Returns the DirectionEstimator object.

Specified by:
  `getDirectionEstimator` in interface `HasDirectionEstimator`

#### onKeyUp

    public void onKeyUp(KeyUpEvent event)

Automatically adjusts hasDirection's direction on KeyUpEvent events. Implementation of KeyUpHandler interface method.

Specified by:
  `onKeyUp` in interface `KeyUpHandler`
Parameters:
  `event` - the `KeyUpEvent` that was fired

#### refreshDirection

    public void refreshDirection()

Adjusts target's direction according to the estimated direction of the text it supplies.

#### setDirectionEstimator

    public void setDirectionEstimator(boolean enabled)

Toggles direction estimation on (using a default estimator) and off.

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)

Sets the DirectionEstimator object.

Specified by:
  `setDirectionEstimator` in interface `HasDirectionEstimator`
Parameters:
  `directionEstimator` - The `DirectionEstimator` to be set. `null` means turning off direction estimation.