Class CustomButton
- All Implemented Interfaces:
HasAllDragAndDropHandlers,HasAllFocusHandlers,HasAllGestureHandlers,HasAllKeyHandlers,HasAllMouseHandlers,HasAllTouchHandlers,HasBlurHandlers,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,HasHandlers,HasSafeHtml,EventListener,Focusable,HasEnabled,HasFocus,HasHTML,HasText,HasVisibility,IsWidget,SourcesClickEvents,SourcesFocusEvents,SourcesKeyboardEvents,SourcesMouseEvents
- Direct Known Subclasses:
PushButton,ToggleButton
down-hovering face, the button's style is
gwt-PushButton-down-hovering. The overall style name can be used to
change the style of the button irrespective of the current face.
Each button face can be assigned is own image, text, or html contents. If no
content is defined for a face, then the face will use the contents of another
face. For example, if down-hovering does not have defined
contents, it will use the contents defined by the down face.
The supported faces are defined below:
| CSS style name | Getter method | description of face | defaults to contents of face |
| up | getUpFace() |
face shown when button is up | none |
| down | getDownFace() |
face shown when button is down | up |
| up-hovering | getUpHoveringFace() |
face shown when button is up and hovering | up |
| up-disabled | getUpDisabledFace() |
face shown when button is up and disabled | up |
| down-hovering | getDownHoveringFace() |
face shown when button is down and hovering | down |
| down-disabled | getDownDisabledFace() |
face shown when button is down and disabled | down |
Use in UiBinder Templates
When working with CustomButton subclasses inUiBinder templates, you
can set text and assign ImageResources for their various faces via
child elements:
- <g:upFace>
- <g:downFace>
- <g:upHoveringFace>
- <g:downHoveringFace>
- <g:upDisabledFace>
- <g:downDisabledFace>
- <g:downFace>
image attribute
and an html body. For example:
<ui:image field='downButton'/> <!-- define an ImageResource -->
<g:PushButton ui:field='pushButton' enabled='true'>
<g:upFace>
<b>click me</b>
</gwt:upFace>
<g:upHoveringFace>
<b>Click ME!</b>
</gwt:upHoveringFace>
<g:downFace image='{downButton}'/>
<g:downHoveringFace image='{downButton}'/>
</g:PushButton>
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled -
Field Summary
Fields inherited from class com.google.gwt.user.client.ui.Widget
eventsToSinkFields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor forCustomButton.CustomButton(Image upImage) Constructor forCustomButton.CustomButton(Image upImage, ClickHandler handler) Constructor forCustomButton.CustomButton(Image upImage, ClickListener listener) Deprecated.CustomButton(Image upImage, Image downImage) Constructor forCustomButton.CustomButton(Image upImage, Image downImage, ClickHandler handler) Constructor forCustomButton.CustomButton(Image upImage, Image downImage, ClickListener listener) Deprecated.UseCustomButton(Image, Image, ClickHandler)insteadCustomButton(String upText) Constructor forCustomButton.CustomButton(String upText, ClickHandler handler) Constructor forCustomButton.CustomButton(String upText, ClickListener listener) Deprecated.UseCustomButton(String, ClickListener)insteadCustomButton(String upText, String downText) Constructor forCustomButton.CustomButton(String upText, String downText, ClickHandler handler) Constructor forCustomButton.CustomButton(String upText, String downText, ClickListener listener) Deprecated.UseCustomButton(String, String, ClickHandler)instead -
Method Summary
Modifier and TypeMethodDescription(package private) voidCommon setup between constructors.(package private) voidfireClickListeners(Event nativeEvent) (package private) CustomButton.FaceGets the current face of the button.final CustomButton.FaceGets the downDisabled face of the button.final CustomButton.FaceGets the down face of the button.final CustomButton.FaceGets the downHovering face of the button.getHTML()Gets the current face's html.intGets the tab index.getText()Gets the current face's text.final CustomButton.FaceGets the upDisabled face of the button.final CustomButton.FaceGets the up face of the button.final CustomButton.FaceGets the upHovering face of the button.protected booleanisDown()Is this button down?(package private) final booleanIs the mouse hovering over this button?protected voidonAttach()Overridden on attach to ensure that a button face has been chosen before the button is displayed.voidonBrowserEvent(Event event) Fired whenever a browser event is received.protected voidonClick()Called when the user finishes clicking on this button.protected voidCalled when the user aborts a click in progress; for example, by dragging the mouse outside of the button before releasing the mouse button.protected voidCalled when the user begins to click on this button.protected voidonDetach()This method is called when a widget is detached from the browser's document.voidsetAccessKey(char key) Sets the widget's 'access key'.(package private) voidsetCurrentFace(CustomButton.Face newFace) protected voidsetDown(boolean down) Sets whether this button is down.final voidsetEnabled(boolean enabled) Sets whether this button is enabled.voidsetFocus(boolean focused) Explicitly focus/unfocus this widget.(package private) final voidsetHovering(boolean hovering) Sets whether this button is hovering.voidSets this object's contents via known-safe HTML.voidSets the current face's html.voidsetTabIndex(int index) Sets the widget's position in the tab index.voidSets the current face's text.(package private) voidToggle the up/down attribute.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, isEnabled, removeClickListener, removeFocusListener, removeKeyboardListener, removeMouseListener, removeMouseWheelListenerMethods 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, onLoad, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEventsMethods 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
-
Constructor Details
-
CustomButton
Constructor forCustomButton.- Parameters:
upImage- image for the default (up) face of the button
-
CustomButton
Constructor forCustomButton.- Parameters:
upImage- image for the default (up) face of the buttonhandler- the click handler
-
CustomButton
Deprecated.UseCustomButton(Image, ClickHandler)insteadConstructor forCustomButton.- Parameters:
upImage- image for the default (up) face of the buttonlistener- the click listener
-
CustomButton
Constructor forCustomButton.- Parameters:
upImage- image for the default (up) face of the buttondownImage- image for the down face of the button
-
CustomButton
Constructor forCustomButton.- Parameters:
upImage- image for the default (up) face of the buttondownImage- image for the down face of the buttonhandler- clickListener
-
CustomButton
Deprecated.UseCustomButton(Image, Image, ClickHandler)insteadConstructor forCustomButton.- Parameters:
upImage- image for the default (up) face of the buttondownImage- image for the down face of the buttonlistener- clickListener
-
CustomButton
Constructor forCustomButton.- Parameters:
upText- the text for the default (up) face of the button
-
CustomButton
Constructor forCustomButton.- Parameters:
upText- the text for the default (up) face of the buttonhandler- the click handler
-
CustomButton
Deprecated.UseCustomButton(String, ClickListener)insteadConstructor forCustomButton.- Parameters:
upText- the text for the default (up) face of the buttonlistener- the click listener
-
CustomButton
Constructor forCustomButton.- Parameters:
upText- the text for the default (up) face of the buttondownText- the text for the down face of the button
-
CustomButton
Constructor forCustomButton.- Parameters:
upText- the text for the default (up) face of the buttondownText- the text for the down face of the buttonhandler- the click handler
-
CustomButton
Deprecated.UseCustomButton(String, String, ClickHandler)insteadConstructor forCustomButton.- Parameters:
upText- the text for the default (up) face of the buttondownText- the text for the down face of the buttonlistener- the click listener
-
CustomButton
protected CustomButton()Constructor forCustomButton.
-
-
Method Details
-
getDownDisabledFace
Gets the downDisabled face of the button.- Returns:
- the downDisabled face
-
getDownFace
Gets the down face of the button.- Returns:
- the down face
-
getDownHoveringFace
Gets the downHovering face of the button.- Returns:
- the downHovering face
-
getHTML
Gets the current face's html.- Specified by:
getHTMLin interfaceHasHTML- Overrides:
getHTMLin classButtonBase- Returns:
- current face's html
-
getTabIndex
public int getTabIndex()Description copied from class:FocusWidgetGets the tab index.- Specified by:
getTabIndexin interfaceFocusable- Overrides:
getTabIndexin classFocusWidget- Returns:
- the tab index
-
getText
Gets the current face's text.- Specified by:
getTextin interfaceHasText- Overrides:
getTextin classButtonBase- Returns:
- current face's text
-
getUpDisabledFace
Gets the upDisabled face of the button.- Returns:
- the upDisabled face
-
getUpFace
Gets the up face of the button.- Returns:
- the up face
-
getUpHoveringFace
Gets the upHovering face of the button.- Returns:
- the upHovering face
-
onBrowserEvent
Description copied from interface:EventListenerFired whenever a browser event is received.- Specified by:
onBrowserEventin interfaceEventListener- Overrides:
onBrowserEventin classWidget- Parameters:
event- the event received
-
setAccessKey
public void setAccessKey(char key) Description copied from interface:FocusableSets the widget's 'access key'. This key is used (in conjunction with a browser-specific modifier key) to automatically focus the widget.- Specified by:
setAccessKeyin interfaceFocusable- Overrides:
setAccessKeyin classFocusWidget- Parameters:
key- the widget's access key
-
setEnabled
public final void setEnabled(boolean enabled) Sets whether this button is enabled.- Specified by:
setEnabledin interfaceHasEnabled- Overrides:
setEnabledin classFocusWidget- Parameters:
enabled-trueto enable the button,falseto disable it
-
setFocus
public void setFocus(boolean focused) Description copied from interface:FocusableExplicitly focus/unfocus this widget. Only one widget can have focus at a time, and the widget that does will receive all keyboard events. NOTE: Most browsers fire FocusEvents asynchronously. Especially within GWT tests, you'll need to make your test asynchronous to properly do verifications. SeeGWTTestCase#delayTestFinishfor more information on how to do this.- Specified by:
setFocusin interfaceFocusable- Overrides:
setFocusin classFocusWidget- Parameters:
focused- whether this widget should take focus or release it
-
setHTML
Sets the current face's html.- Specified by:
setHTMLin interfaceHasHTML- Overrides:
setHTMLin classButtonBase- Parameters:
html- html to set
-
setTabIndex
public void setTabIndex(int index) Description copied from interface:FocusableSets the widget's position in the tab index. If more than one widget has the same tab index, each such widget will receive focus in an arbitrary order. Setting the tab index to-1will cause this widget to be removed from the tab order.- Specified by:
setTabIndexin interfaceFocusable- Overrides:
setTabIndexin classFocusWidget- Parameters:
index- the widget's tab index
-
setText
Sets the current face's text.- Specified by:
setTextin interfaceHasText- Overrides:
setTextin classButtonBase- Parameters:
text- text to set
-
isDown
protected boolean isDown()Is this button down?- Returns:
trueif the button is down
-
onAttach
protected void onAttach()Overridden on attach to ensure that a button face has been chosen before the button is displayed.- Overrides:
onAttachin classFocusWidget- See Also:
-
onClick
protected void onClick()Called when the user finishes clicking on this button. The default behavior is to fire the click event to listeners. Subclasses that overrideonClickStart()should override this method to restore the normal widget display. -
onClickCancel
protected void onClickCancel()Called when the user aborts a click in progress; for example, by dragging the mouse outside of the button before releasing the mouse button. Subclasses that overrideonClickStart()should override this method to restore the normal widget display. -
onClickStart
protected void onClickStart()Called when the user begins to click on this button. Subclasses may override this method to display the start of the click visually; such subclasses should also overrideonClick()andonClickCancel()to restore normal visual state. EachonClickStartwill eventually be followed by eitheronClickoronClickCancel, depending on whether the click is completed. -
onDetach
protected void onDetach()Description copied from class:WidgetThis method is called when a widget is detached from the browser's document. To receive notification before a Widget is removed from the document, override the
Widget.onUnload()method or useWidget.addAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler).It is strongly recommended that you override
Widget.onUnload()orWidget.doDetachChildren()instead of this method to avoid inconsistencies between logical and physical attachment states.Subclasses that override this method must call
super.onDetach()to ensure that the Widget has been detached from the underlying Element. Failure to do so will result in application memory leaks due to circular references between DOM Elements and JavaScript objects. -
setDown
protected void setDown(boolean down) Sets whether this button is down.- Parameters:
down-trueto press the button,falseotherwise
-
finishSetup
void finishSetup()Common setup between constructors. -
fireClickListeners
-
getCurrentFace
CustomButton.Face getCurrentFace()Gets the current face of the button.- Returns:
- the current face
-
isHovering
final boolean isHovering()Is the mouse hovering over this button?- Returns:
trueif the mouse is hovering
-
setCurrentFace
-
setHovering
final void setHovering(boolean hovering) Sets whether this button is hovering.- Parameters:
hovering- is this button hovering?
-
toggleDown
void toggleDown()Toggle the up/down attribute.
-
CustomButton(Image, ClickHandler)instead