/** * Automatically adjusts hasDirection's direction on KeyUpEvent events. * Implementation of KeyUpHandler interface method. */ public void onKeyUp(KeyUpEvent event) { refreshDirection(); }
/** * 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. * * @param target Object whose direction should be automatically adjusted on * relevant events. * @param directionEstimator A DirectionEstimator object used for direction * estimation (use null to disable direction estimation). * @return AutoDirectionHandler An instance of AutoDirectionHandler for the * given object. */ public static AutoDirectionHandler addTo(Target target, DirectionEstimator directionEstimator) { return new AutoDirectionHandler(target, directionEstimator); }
/** * Operates like {@link #addTo(Target, DirectionEstimator)}, but always uses * a default DirectionEstimator, {@link * com.google.gwt.i18n.shared.WordCountDirectionEstimator}. * * @param target Object whose direction should be automatically adjusted on * relevant events. * @return AutoDirectionHandler An instance of AutoDirectionHandler for the * given object. */ public static AutoDirectionHandler addTo(Target target) { return addTo(target, true); }
/** * Toggles on / off direction estimation. */ public void setDirectionEstimator(boolean enabled) { autoDirHandler.setDirectionEstimator(enabled); }
/** * Gets the direction estimation model of the auto-dir handler. */ public DirectionEstimator getDirectionEstimator() { return autoDirHandler.getDirectionEstimator(); }
/** * Sets the direction estimation model of the auto-dir handler. */ public void setDirectionEstimator(DirectionEstimator directionEstimator) { autoDirHandler.setDirectionEstimator(directionEstimator); }
/** * Gets the direction estimation model of the auto-dir handler. */ public DirectionEstimator getDirectionEstimator() { return autoDirHandler.getDirectionEstimator(); }
@Override protected void onLoad() { super.onLoad(); autoDirHandler.refreshDirection(); } }
/** * Private constructor. Instantiate using one of the addTo() methods. * * @param target Object whose direction should be automatically adjusted on * relevant events. * @param directionEstimator A DirectionEstimator object used for direction * estimation. */ private AutoDirectionHandler(Target target, DirectionEstimator directionEstimator) { this.target = target; this.handlerRegistration = null; setDirectionEstimator(directionEstimator); }
/** * Creates a value box that wraps the given browser element handle. This is * only used by subclasses. * * @param elem the browser element to wrap */ protected ValueBoxBase(Element elem, Renderer<T> renderer, Parser<T> parser) { super(elem); autoDirHandler = AutoDirectionHandler.addTo(this, BidiPolicy.isBidiEnabled()); this.renderer = renderer; this.parser = parser; }
/** * Gets the direction estimation model of the auto-dir handler. */ public DirectionEstimator getDirectionEstimator() { return autoDirHandler.getDirectionEstimator(); }
/** * 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. * * @param target Object whose direction should be automatically adjusted on * relevant events. * @param directionEstimator A DirectionEstimator object used for direction * estimation (use null to disable direction estimation). * @return AutoDirectionHandler An instance of AutoDirectionHandler for the * given object. */ public static AutoDirectionHandler addTo(Target target, DirectionEstimator directionEstimator) { return new AutoDirectionHandler(target, directionEstimator); }
/** * Sets this object's text. Note that some browsers will manipulate the text * before adding it to the widget. For example, most browsers will strip all * <code>\r</code> from the text, except IE which will add a <code>\r</code> * before each <code>\n</code>. Use {@link #getText()} to get the text * directly from the widget. * * @param text the object's new text */ public void setText(String text) { getElement().setPropertyString("value", text != null ? text : ""); autoDirHandler.refreshDirection(); }
/** * Toggles direction estimation on (using a default estimator) and off. */ public void setDirectionEstimator(boolean enabled) { setDirectionEstimator(enabled ? WordCountDirectionEstimator.get() : null); }
/** * Operates like {@link #addTo(Target, DirectionEstimator)}, but uses a * default DirectionEstimator, {@link * com.google.gwt.i18n.shared.WordCountDirectionEstimator} if {@code enabled}, * or else a null DirectionEstimator, which means disabling direction * estimation. * * @param target Object whose direction should be automatically adjusted on * relevant events. * @param enabled Whether the handler is enabled upon creation. * @return AutoDirectionHandler An instance of AutoDirectionHandler for the * given object. */ public static AutoDirectionHandler addTo(Target target, boolean enabled) { return addTo(target, enabled ? WordCountDirectionEstimator.get() : null); }
/** * 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. * * @param target Object whose direction should be automatically adjusted on * relevant events. * @param directionEstimator A DirectionEstimator object used for direction * estimation (use null to disable direction estimation). * @return AutoDirectionHandler An instance of AutoDirectionHandler for the * given object. */ public static AutoDirectionHandler addTo(Target target, DirectionEstimator directionEstimator) { return new AutoDirectionHandler(target, directionEstimator); }
/** * Sets the DirectionEstimator object. */ public void setDirectionEstimator(DirectionEstimator directionEstimator) { this.directionEstimator = directionEstimator; if ((directionEstimator == null) != (handlerRegistration == null)) { if (directionEstimator == null) { handlerRegistration.removeHandler(); handlerRegistration = null; } else { handlerRegistration = target.addKeyUpHandler(this); } } refreshDirection(); } }
/** * Sets the direction estimation model of the auto-dir handler. */ public void setDirectionEstimator(DirectionEstimator directionEstimator) { autoDirHandler.setDirectionEstimator(directionEstimator); }
/** * Operates like {@link #addTo(Target, DirectionEstimator)}, but always uses * a default DirectionEstimator, {@link * com.google.gwt.i18n.shared.WordCountDirectionEstimator}. * * @param target Object whose direction should be automatically adjusted on * relevant events. * @return AutoDirectionHandler An instance of AutoDirectionHandler for the * given object. */ public static AutoDirectionHandler addTo(Target target) { return addTo(target, true); }
/** * Automatically adjusts hasDirection's direction on KeyUpEvent events. * Implementation of KeyUpHandler interface method. */ public void onKeyUp(KeyUpEvent event) { refreshDirection(); }