Package com.google.gwt.user.client.ui
Class ValueBoxBase<T>
- java.lang.Object
-
- com.google.gwt.user.client.ui.UIObject
-
- com.google.gwt.user.client.ui.Widget
-
- com.google.gwt.user.client.ui.FocusWidget
-
- com.google.gwt.user.client.ui.ValueBoxBase<T>
-
- Type Parameters:
T- the value type
- All Implemented Interfaces:
IsEditor<ValueBoxEditor<T>>,HasAllDragAndDropHandlers,HasAllFocusHandlers,HasAllGestureHandlers,HasAllKeyHandlers,HasAllMouseHandlers,HasAllTouchHandlers,HasBlurHandlers,HasChangeHandlers,HasClickHandlers,HasDoubleClickHandlers,HasDragEndHandlers,HasDragEnterHandlers,HasDragHandlers,HasDragLeaveHandlers,HasDragOverHandlers,HasDragStartHandlers,HasDropHandlers,HasFocusHandlers,HasGestureChangeHandlers,HasGestureEndHandlers,HasGestureStartHandlers,HasKeyDownHandlers,HasKeyPressHandlers,HasKeyUpHandlers,HasMouseDownHandlers,HasMouseMoveHandlers,HasMouseOutHandlers,HasMouseOverHandlers,HasMouseUpHandlers,HasMouseWheelHandlers,HasTouchCancelHandlers,HasTouchEndHandlers,HasTouchMoveHandlers,HasTouchStartHandlers,HasAttachHandlers,HasValueChangeHandlers<T>,HasHandlers,AutoDirectionHandler.Target,HasDirection,HasDirectionEstimator,EventListener,TakesValue<T>,Focusable,HasEnabled,HasFocus,HasName,HasText,HasValue<T>,HasVisibility,IsWidget,SourcesClickEvents,SourcesFocusEvents,SourcesKeyboardEvents,SourcesMouseEvents
- Direct Known Subclasses:
TextBoxBase,ValueBox
public class ValueBoxBase<T> extends FocusWidget implements HasChangeHandlers, HasName, HasDirectionEstimator, HasValue<T>, HasText, AutoDirectionHandler.Target, IsEditor<ValueBoxEditor<T>>
Abstract base class for all text entry widgets.Use in UiBinder Templates
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classValueBoxBase.TextAlignmentAlignment values forsetAlignment(com.google.gwt.user.client.ui.ValueBoxBase.TextAlignment).-
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.Widget
eventsToSink
-
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HandlerRegistrationaddChangeHandler(ChangeHandler handler)Adds aChangeEventhandler.HandlerRegistrationaddValueChangeHandler(ValueChangeHandler<T> handler)Adds aValueChangeEventhandler.ValueBoxEditor<T>asEditor()Returns an Editor that is backed by the ValueBoxBase.voidcancelKey()If a keyboard event is currently being handled on this text box, calling this method will suppress it.intgetCursorPos()Gets the current position of the cursor (this also serves as the beginning of the text selection).HasDirection.DirectiongetDirection()Gets the directionality of the widget.DirectionEstimatorgetDirectionEstimator()Gets the direction estimation model of the auto-dir handler.protected com.google.gwt.user.client.ui.impl.TextBoxImplgetImpl()java.lang.StringgetName()Gets the widget's name.java.lang.StringgetSelectedText()Gets the text currently selected within this text box.intgetSelectionLength()Gets the length of the current text selection.java.lang.StringgetText()Gets this object's text.TgetValue()Return the parsed value, or null if the field is empty or parsing fails.TgetValueOrThrow()Return the parsed value, or null if the field is empty.booleanisReadOnly()Determines whether or not the widget is read-only.voidonBrowserEvent(Event event)Fired whenever a browser event is received.protected voidonLoad()This method is called immediately after a widget becomes attached to the browser's document.voidremoveChangeListener(ChangeListener listener)Deprecated.Use theHandlerRegistration.removeHandler()method on the object returned byaddChangeHandler(com.google.gwt.event.dom.client.ChangeHandler)insteadvoidselectAll()Selects all of the text in the box.voidsetAlignment(ValueBoxBase.TextAlignment align)voidsetCursorPos(int pos)Sets the cursor position.voidsetDirection(HasDirection.Direction direction)Sets the directionality for a widget.voidsetDirectionEstimator(boolean enabled)Toggles on / off direction estimation.voidsetDirectionEstimator(DirectionEstimator directionEstimator)Sets the direction estimation model of the auto-dir handler.voidsetKey(char key)Deprecated.this method only works in IE and should not have been added to the APIvoidsetName(java.lang.String name)Sets the widget's name.voidsetReadOnly(boolean readOnly)Turns read-only mode on or off.voidsetSelectionRange(int pos, int length)Sets the range of text to be selected.voidsetText(java.lang.String text)Sets this object's text.voidsetValue(T value)Sets this object's value without firing any events.voidsetValue(T value, boolean fireEvents)Sets this object's value.-
Methods inherited from class com.google.gwt.user.client.ui.FocusWidget
addBlurHandler, addClickHandler, addClickListener, addDoubleClickHandler, addDragEndHandler, addDragEnterHandler, addDragHandler, addDragLeaveHandler, addDragOverHandler, addDragStartHandler, addDropHandler, addFocusHandler, addFocusListener, addGestureChangeHandler, addGestureEndHandler, addGestureStartHandler, addKeyboardListener, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addMouseDownHandler, addMouseListener, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addMouseWheelListener, addTouchCancelHandler, addTouchEndHandler, addTouchMoveHandler, addTouchStartHandler, getFocusImpl, getTabIndex, isEnabled, onAttach, removeClickListener, removeFocusListener, removeKeyboardListener, removeMouseListener, removeMouseWheelListener, setAccessKey, setEnabled, setFocus, setTabIndex
-
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isAttached, isOrWasAttached, onDetach, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEvents
-
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
-
Methods inherited from interface com.google.gwt.event.dom.client.HasKeyUpHandlers
addKeyUpHandler
-
-
-
-
Method Detail
-
addChangeHandler
public HandlerRegistration addChangeHandler(ChangeHandler handler)
Description copied from interface:HasChangeHandlersAdds aChangeEventhandler.- Specified by:
addChangeHandlerin interfaceHasChangeHandlers- Parameters:
handler- the change handler- Returns:
HandlerRegistrationused to remove this handler
-
addValueChangeHandler
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<T> handler)
Description copied from interface:HasValueChangeHandlersAdds aValueChangeEventhandler.- Specified by:
addValueChangeHandlerin interfaceHasValueChangeHandlers<T>- Parameters:
handler- the handler- Returns:
- the registration for the event
-
asEditor
public ValueBoxEditor<T> asEditor()
Returns an Editor that is backed by the ValueBoxBase. The default implementation returnsValueBoxEditor.of(ValueBoxBase). Subclasses may override this method to provide custom error-handling when using the Editor framework.
-
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:HasDirectionGets the directionality of the widget.- Specified by:
getDirectionin interfaceHasDirection- Returns:
RTLif the directionality is right-to-left,LTRif the directionality is left-to-right, orDEFAULTif the directionality is not explicitly specified
-
getDirectionEstimator
public DirectionEstimator getDirectionEstimator()
Gets the direction estimation model of the auto-dir handler.- Specified by:
getDirectionEstimatorin interfaceHasDirectionEstimator
-
getName
public java.lang.String getName()
Description copied from interface:HasNameGets 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:HasTextGets this object's text.- Specified by:
getTextin interfaceAutoDirectionHandler.Target- Specified by:
getTextin interfaceHasText- 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:
getValuein interfaceHasValue<T>- Specified by:
getValuein interfaceTakesValue<T>- Returns:
- the object's value
- See Also:
TakesValue.setValue(V)
-
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:
trueif the widget is currently read-only,falseif the widget is currently editable
-
onBrowserEvent
public void onBrowserEvent(Event event)
Description copied from interface:EventListenerFired whenever a browser event is received.- Specified by:
onBrowserEventin interfaceEventListener- Overrides:
onBrowserEventin classWidget- Parameters:
event- the event received
-
removeChangeListener
@Deprecated public void removeChangeListener(ChangeListener listener)
Deprecated.Use theHandlerRegistration.removeHandler()method on the object returned byaddChangeHandler(com.google.gwt.event.dom.client.ChangeHandler)instead
-
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.
-
setAlignment
public void setAlignment(ValueBoxBase.TextAlignment align)
-
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:HasDirectionSets the directionality for a widget.- Specified by:
setDirectionin interfaceHasDirection- Parameters:
direction-RTLif the directionality should be set to right-to-left,LTRif the directionality should be set to left-to-rightDEFAULTif the directionality should not be explicitly set
-
setDirectionEstimator
public void setDirectionEstimator(boolean enabled)
Toggles on / off direction estimation.- Specified by:
setDirectionEstimatorin interfaceHasDirectionEstimator- Parameters:
enabled- Whether to enable direction estimation. Iftrue, sets theDirectionEstimatorobject to a defaultDirectionEstimator.
-
setDirectionEstimator
public void setDirectionEstimator(DirectionEstimator directionEstimator)
Sets the direction estimation model of the auto-dir handler.- Specified by:
setDirectionEstimatorin interfaceHasDirectionEstimator- Parameters:
directionEstimator- TheDirectionEstimatorto be set.nullmeans 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 APIIf 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:HasNameSets the widget's name.
-
setReadOnly
public void setReadOnly(boolean readOnly)
Turns read-only mode on or off.- Parameters:
readOnly- iftrue, the widget becomes read-only; iffalsethe 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 selectedlength- 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\rfrom the text, except IE which will add a\rbefore each\n. UsegetText()to get the text directly from the widget.- Specified by:
setTextin interfaceAutoDirectionHandler.Target- Specified by:
setTextin interfaceHasText- Parameters:
text- the object's new text
-
setValue
public void setValue(T value)
Description copied from interface:HasValueSets 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.
Widgets must accept null as a valid value. By convention, setting a widget to null clears value, calling getValue() on a cleared widget returns null. Widgets that can not be cleared (e.g.
CheckBox) must find another valid meaning for null input.- Specified by:
setValuein interfaceHasValue<T>- Specified by:
setValuein interfaceTakesValue<T>- Parameters:
value- the object's new value- See Also:
TakesValue.getValue()
-
setValue
public void setValue(T value, boolean fireEvents)
Description copied from interface:HasValueSets this object's value. FiresValueChangeEventwhen 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.
-
getImpl
protected com.google.gwt.user.client.ui.impl.TextBoxImpl getImpl()
-
-