com.google.gwt.user.client.ui
Class ValueBoxBase<T>

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.FocusWidget
              extended by com.google.gwt.user.client.ui.ValueBoxBase<T>
Type Parameters:
T - the value type
All Implemented Interfaces:
HasAllFocusHandlers, HasAllKeyHandlers, HasAllMouseHandlers, HasBlurHandlers, HasChangeHandlers, HasClickHandlers, HasFocusHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasKeyUpHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasValueChangeHandlers<T>, HasHandlers, AutoDirectionHandler.Target, HasDirection, HasDirectionEstimator, EventListener, Focusable, HasFocus, HasName, HasText, HasValue<T>, SourcesChangeEvents, SourcesClickEvents, SourcesFocusEvents, SourcesKeyboardEvents, SourcesMouseEvents, TakesValue<T>
Direct Known Subclasses:
TextBoxBase, ValueBox

public class ValueBoxBase<T>
extends FocusWidget
implements SourcesChangeEvents, HasChangeHandlers, HasText, HasName, HasDirection, HasDirectionEstimator, HasValue<T>, AutoDirectionHandler.Target

Experimental API: This class is still under rapid development, and is very likely to be deleted. Use it at your own risk.

Abstract base class for all text entry widgets.

Use in UiBinder Templates

The names of the static members of TextBoxBase, as well as simple alignment names (left, center, right, justify), can be used as values for a textAlignment attribute.

For example,

 <g:TextBox textAlignment='ALIGN_RIGHT'/>
 <g:TextBox textAlignment='right'/>
 


Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
 
Nested classes/interfaces inherited from interface com.google.gwt.i18n.client.HasDirection
HasDirection.Direction
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Method Summary
 HandlerRegistration addChangeHandler(ChangeHandler handler)
          Adds a ChangeEvent handler.
 void addChangeListener(ChangeListener listener)
          Deprecated. Use addChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) instead
 HandlerRegistration addValueChangeHandler(ValueChangeHandler<T> handler)
          Adds a ValueChangeEvent handler.
 void cancelKey()
          If a keyboard event is currently being handled on this text box, calling this method will suppress it.
 int getCursorPos()
          Gets the current position of the cursor (this also serves as the beginning of the text selection).
 HasDirection.Direction getDirection()
          Gets the directionality of the widget.
 DirectionEstimator getDirectionEstimator()
          Gets the direction estimation model of the auto-dir handler.
 java.lang.String getName()
          Gets the widget's name.
 java.lang.String getSelectedText()
          Gets the text currently selected within this text box.
 int getSelectionLength()
          Gets the length of the current text selection.
 java.lang.String getText()
          Gets this object's text.
 T getValue()
          Return the parsed value, or null if the field is empty or parsing fails.
 T getValueOrThrow()
          Return the parsed value, or null if the field is empty.
 boolean isReadOnly()
          Determines whether or not the widget is read-only.
 void onBrowserEvent(Event event)
          Fired whenever a browser event is received.
 void removeChangeListener(ChangeListener listener)
          Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) instead
 void selectAll()
          Selects all of the text in the box.
 void setCursorPos(int pos)
          Sets the cursor position.
 void setDirection(HasDirection.Direction direction)
          Sets the directionality for a widget.
 void setDirectionEstimator(boolean enabled)
          Toggles on / off direction estimation.
 void setDirectionEstimator(DirectionEstimator directionEstimator)
          Sets the direction estimation model of the auto-dir handler.
 void setKey(char key)
          Deprecated. this method only works in IE and should not have been added to the API
 void setName(java.lang.String name)
          Sets the widget's name.
 void setReadOnly(boolean readOnly)
          Turns read-only mode on or off.
 void setSelectionRange(int pos, int length)
          Sets the range of text to be selected.
 void setText(java.lang.String text)
          Sets this object's text.
 void setTextAlignment(TextBoxBase.TextAlignConstant align)
          Sets the alignment of the text in the text box.
 void setValue(T value)
          Sets this object's value without firing any events.
 void setValue(T value, boolean fireEvents)
          Sets this object's value.
 
Methods inherited from class com.google.gwt.user.client.ui.FocusWidget
addBlurHandler, addClickHandler, addClickListener, addFocusHandler, addFocusListener, addKeyboardListener, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addMouseDownHandler, addMouseListener, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addMouseWheelListener, getTabIndex, isEnabled, removeClickListener, removeFocusListener, removeKeyboardListener, removeMouseListener, removeMouseWheelListener, setAccessKey, setEnabled, setFocus, setTabIndex
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
fireEvent, getLayoutData, getParent, isAttached, removeFromParent, setLayoutData, sinkEvents
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.event.dom.client.HasKeyUpHandlers
addKeyUpHandler
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 

Method Detail

addChangeHandler

public HandlerRegistration addChangeHandler(ChangeHandler handler)
Description copied from interface: HasChangeHandlers
Adds a ChangeEvent handler.

Specified by:
addChangeHandler in interface HasChangeHandlers
Parameters:
handler - the change handler
Returns:
HandlerRegistration used to remove this handler

addChangeListener

@Deprecated
public void addChangeListener(ChangeListener listener)
Deprecated. Use addChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) instead

Description copied from interface: SourcesChangeEvents
Adds a listener interface to receive change events.

Specified by:
addChangeListener in interface SourcesChangeEvents
Parameters:
listener - the listener interface to add

addValueChangeHandler

public HandlerRegistration addValueChangeHandler(ValueChangeHandler<T> handler)
Description copied from interface: HasValueChangeHandlers
Adds a ValueChangeEvent handler.

Specified by:
addValueChangeHandler in interface HasValueChangeHandlers<T>
Parameters:
handler - the handler
Returns:
the registration for the event

cancelKey

public void cancelKey()
If a keyboard event is currently being handled on this text box, calling this method will suppress it. This allows listeners to easily filter keyboard input.


getCursorPos

public int getCursorPos()
Gets the current position of the cursor (this also serves as the beginning of the text selection).

Returns:
the cursor's position

getDirection

public HasDirection.Direction getDirection()
Description copied from interface: HasDirection
Gets the directionality of the widget.

Specified by:
getDirection in interface HasDirection
Returns:
RTL if the directionality is right-to-left, LTR if the directionality is left-to-right, or DEFAULT if the directionality is not explicitly specified

getDirectionEstimator

public DirectionEstimator getDirectionEstimator()
Gets the direction estimation model of the auto-dir handler.

Specified by:
getDirectionEstimator in interface HasDirectionEstimator
Returns:
the DirectionEstimator object.

getName

public java.lang.String getName()
Description copied from interface: HasName
Gets the widget's name.

Specified by:
getName in interface HasName
Returns:
the widget's name

getSelectedText

public java.lang.String getSelectedText()
Gets the text currently selected within this text box.

Returns:
the selected text, or an empty string if none is selected

getSelectionLength

public int getSelectionLength()
Gets the length of the current text selection.

Returns:
the text selection length

getText

public java.lang.String getText()
Description copied from interface: HasText
Gets this object's text.

Specified by:
getText in interface HasText
Returns:
the object's text

getValue

public T getValue()
Return the parsed value, or null if the field is empty or parsing fails.

Specified by:
getValue in interface HasValue<T>
Specified by:
getValue in interface TakesValue<T>
Returns:
the object's value

getValueOrThrow

public T getValueOrThrow()
                  throws java.text.ParseException
Return the parsed value, or null if the field is empty.

Throws:
java.text.ParseException - if the value cannot be parsed

isReadOnly

public boolean isReadOnly()
Determines whether or not the widget is read-only.

Returns:
true if the widget is currently read-only, false if the widget is currently editable

onBrowserEvent

public void onBrowserEvent(Event event)
Description copied from interface: EventListener
Fired whenever a browser event is received.

Specified by:
onBrowserEvent in interface EventListener
Overrides:
onBrowserEvent in class Widget
Parameters:
event - the event received

removeChangeListener

@Deprecated
public void removeChangeListener(ChangeListener listener)
Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) instead

Description copied from interface: SourcesChangeEvents
Removes a previously added listener interface.

Specified by:
removeChangeListener in interface SourcesChangeEvents
Parameters:
listener - the listener interface to remove

selectAll

public void selectAll()
Selects all of the text in the box. This will only work when the widget is attached to the document and not hidden.


setCursorPos

public void setCursorPos(int pos)
Sets the cursor position. This will only work when the widget is attached to the document and not hidden.

Parameters:
pos - the new cursor position

setDirection

public void setDirection(HasDirection.Direction direction)
Description copied from interface: HasDirection
Sets the directionality for a widget.

Specified by:
setDirection in interface HasDirection
Parameters:
direction - RTL if the directionality should be set to right-to-left, LTR if the directionality should be set to left-to-right DEFAULT if the directionality should not be explicitly set

setDirectionEstimator

public void setDirectionEstimator(boolean enabled)
Toggles on / off direction estimation.

Specified by:
setDirectionEstimator in interface HasDirectionEstimator
Parameters:
enabled - Whether to enable direction estimation. If , sets the DirectionEstimator object to a default .

setDirectionEstimator

public void setDirectionEstimator(DirectionEstimator directionEstimator)
Sets the direction estimation model of the auto-dir handler.

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

setKey

@Deprecated
public void setKey(char key)
Deprecated. this method only works in IE and should not have been added to the API

If a keyboard event is currently being handled by the text box, this method replaces the unicode character or key code associated with it. This allows listeners to easily filter keyboard input.

Parameters:
key - the new key value

setName

public void setName(java.lang.String name)
Description copied from interface: HasName
Sets the widget's name.

Specified by:
setName in interface HasName
Parameters:
name - the widget's new name

setReadOnly

public void setReadOnly(boolean readOnly)
Turns read-only mode on or off.

Parameters:
readOnly - if true, the widget becomes read-only; if false the widget becomes editable

setSelectionRange

public void setSelectionRange(int pos,
                              int length)
Sets the range of text to be selected. This will only work when the widget is attached to the document and not hidden.

Parameters:
pos - the position of the first character to be selected
length - the number of characters to be selected

setText

public void setText(java.lang.String text)
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 \r from the text, except IE which will add a \r before each \n. Use getText() to get the text directly from the widget.

Specified by:
setText in interface HasText
Parameters:
text - the object's new text

setTextAlignment

public void setTextAlignment(TextBoxBase.TextAlignConstant align)
Sets the alignment of the text in the text box.

Parameters:
align - the text alignment (as specified by #ALIGN_CENTER, #ALIGN_JUSTIFY, #ALIGN_LEFT, and #ALIGN_RIGHT)

setValue

public void setValue(T value)
Description copied from interface: HasValue
Sets this object's value without firing any events. This should be identical to calling setValue(value, false).

It is acceptable to fail assertions or throw (documented) unchecked exceptions in response to bad values.

By convention, GWT widgets that can be cleared accept null for value, but it is acceptable for widgets that cannot be cleared to throw an exception for null values.

Specified by:
setValue in interface HasValue<T>
Specified by:
setValue in interface TakesValue<T>
Parameters:
value - the object's new value

setValue

public void setValue(T value,
                     boolean fireEvents)
Description copied from interface: HasValue
Sets this object's value. Fires ValueChangeEvent when fireEvents is true and the new value does not equal the existing value.

It is acceptable to fail assertions or throw (documented) unchecked exceptions in response to bad values.

Specified by:
setValue in interface HasValue<T>
Parameters:
value - the object's new value
fireEvents - fire events if true and value is new