public abstract class CustomButton extends ButtonBase
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 |
UiBinder
templates, you
can set text and assign ImageResources for their various faces via
child elements:
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>
Modifier and Type | Class and Description |
---|---|
class |
CustomButton.Face
Represents a button's face.
|
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
eventsToSink
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
Modifier | Constructor and Description |
---|---|
protected |
CustomButton()
Constructor for
CustomButton . |
|
CustomButton(Image upImage)
Constructor for
CustomButton . |
|
CustomButton(Image upImage,
ClickHandler handler)
Constructor for
CustomButton . |
|
CustomButton(Image upImage,
ClickListener listener)
Deprecated.
Use
CustomButton(Image, ClickHandler) instead |
|
CustomButton(Image upImage,
Image downImage)
Constructor for
CustomButton . |
|
CustomButton(Image upImage,
Image downImage,
ClickHandler handler)
Constructor for
CustomButton . |
|
CustomButton(Image upImage,
Image downImage,
ClickListener listener)
Deprecated.
Use
CustomButton(Image, Image, ClickHandler) instead |
|
CustomButton(java.lang.String upText)
Constructor for
CustomButton . |
|
CustomButton(java.lang.String upText,
ClickHandler handler)
Constructor for
CustomButton . |
|
CustomButton(java.lang.String upText,
ClickListener listener)
Deprecated.
Use
CustomButton(String, ClickListener) instead |
|
CustomButton(java.lang.String upText,
java.lang.String downText)
Constructor for
CustomButton . |
|
CustomButton(java.lang.String upText,
java.lang.String downText,
ClickHandler handler)
Constructor for
CustomButton . |
|
CustomButton(java.lang.String upText,
java.lang.String downText,
ClickListener listener)
Deprecated.
Use
CustomButton(String, String, ClickHandler) instead |
Modifier and Type | Method and Description |
---|---|
(package private) void |
finishSetup()
Common setup between constructors.
|
(package private) void |
fireClickListeners(Event nativeEvent) |
(package private) CustomButton.Face |
getCurrentFace()
Gets the current face of the button.
|
CustomButton.Face |
getDownDisabledFace()
Gets the downDisabled face of the button.
|
CustomButton.Face |
getDownFace()
Gets the down face of the button.
|
CustomButton.Face |
getDownHoveringFace()
Gets the downHovering face of the button.
|
java.lang.String |
getHTML()
Gets the current face's html.
|
int |
getTabIndex()
Gets the tab index.
|
java.lang.String |
getText()
Gets the current face's text.
|
CustomButton.Face |
getUpDisabledFace()
Gets the upDisabled face of the button.
|
CustomButton.Face |
getUpFace()
Gets the up face of the button.
|
CustomButton.Face |
getUpHoveringFace()
Gets the upHovering face of the button.
|
protected boolean |
isDown()
Is this button down?
|
(package private) boolean |
isHovering()
Is the mouse hovering over this button?
|
protected void |
onAttach()
Overridden on attach to ensure that a button face has been chosen before
the button is displayed.
|
void |
onBrowserEvent(Event event)
Fired whenever a browser event is received.
|
protected void |
onClick()
Called when the user finishes clicking on this button.
|
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.
|
protected void |
onClickStart()
Called when the user begins to click on this button.
|
protected void |
onDetach()
This method is called when a widget is detached from the browser's
document.
|
void |
setAccessKey(char key)
Sets the widget's 'access key'.
|
(package private) void |
setCurrentFace(CustomButton.Face newFace) |
protected void |
setDown(boolean down)
Sets whether this button is down.
|
void |
setEnabled(boolean enabled)
Sets whether this button is enabled.
|
void |
setFocus(boolean focused)
Explicitly focus/unfocus this widget.
|
(package private) void |
setHovering(boolean hovering)
Sets whether this button is hovering.
|
void |
setHTML(SafeHtml html)
Sets this object's contents via known-safe HTML.
|
void |
setHTML(java.lang.String html)
Sets the current face's html.
|
void |
setTabIndex(int index)
Sets the widget's position in the tab index.
|
void |
setText(java.lang.String text)
Sets the current face's text.
|
(package private) void |
toggleDown()
Toggle the up/down attribute.
|
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, removeMouseWheelListener
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, unsinkEvents
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
fireEvent
public CustomButton(Image upImage)
CustomButton
.upImage
- image for the default (up) face of the buttonpublic CustomButton(Image upImage, ClickHandler handler)
CustomButton
.upImage
- image for the default (up) face of the buttonhandler
- the click handler@Deprecated public CustomButton(Image upImage, ClickListener listener)
CustomButton(Image, ClickHandler)
insteadCustomButton
.upImage
- image for the default (up) face of the buttonlistener
- the click listenerpublic CustomButton(Image upImage, Image downImage)
CustomButton
.upImage
- image for the default (up) face of the buttondownImage
- image for the down face of the buttonpublic CustomButton(Image upImage, Image downImage, ClickHandler handler)
CustomButton
.upImage
- image for the default (up) face of the buttondownImage
- image for the down face of the buttonhandler
- clickListener@Deprecated public CustomButton(Image upImage, Image downImage, ClickListener listener)
CustomButton(Image, Image, ClickHandler)
insteadCustomButton
.upImage
- image for the default (up) face of the buttondownImage
- image for the down face of the buttonlistener
- clickListenerpublic CustomButton(java.lang.String upText)
CustomButton
.upText
- the text for the default (up) face of the buttonpublic CustomButton(java.lang.String upText, ClickHandler handler)
CustomButton
.upText
- the text for the default (up) face of the buttonhandler
- the click handler@Deprecated public CustomButton(java.lang.String upText, ClickListener listener)
CustomButton(String, ClickListener)
insteadCustomButton
.upText
- the text for the default (up) face of the buttonlistener
- the click listenerpublic CustomButton(java.lang.String upText, java.lang.String downText)
CustomButton
.upText
- the text for the default (up) face of the buttondownText
- the text for the down face of the buttonpublic CustomButton(java.lang.String upText, java.lang.String downText, ClickHandler handler)
CustomButton
.upText
- the text for the default (up) face of the buttondownText
- the text for the down face of the buttonhandler
- the click handler@Deprecated public CustomButton(java.lang.String upText, java.lang.String downText, ClickListener listener)
CustomButton(String, String, ClickHandler)
insteadCustomButton
.upText
- the text for the default (up) face of the buttondownText
- the text for the down face of the buttonlistener
- the click listenerprotected CustomButton()
CustomButton
.public final CustomButton.Face getDownDisabledFace()
public final CustomButton.Face getDownFace()
public final CustomButton.Face getDownHoveringFace()
public java.lang.String getHTML()
getHTML
in interface HasHTML
getHTML
in class ButtonBase
public int getTabIndex()
FocusWidget
getTabIndex
in interface Focusable
getTabIndex
in class FocusWidget
public java.lang.String getText()
getText
in interface HasText
getText
in class ButtonBase
public final CustomButton.Face getUpDisabledFace()
public final CustomButton.Face getUpFace()
public final CustomButton.Face getUpHoveringFace()
public void onBrowserEvent(Event event)
EventListener
onBrowserEvent
in interface EventListener
onBrowserEvent
in class Widget
event
- the event receivedpublic void setAccessKey(char key)
Focusable
setAccessKey
in interface Focusable
setAccessKey
in class FocusWidget
key
- the widget's access keypublic final void setEnabled(boolean enabled)
setEnabled
in interface HasEnabled
setEnabled
in class FocusWidget
enabled
- true
to enable the button, false
to disable itpublic void setFocus(boolean focused)
Focusable
GWTTestCase#delayTestFinish
for more information on how to do this.setFocus
in interface Focusable
setFocus
in class FocusWidget
focused
- whether this widget should take focus or release itpublic void setHTML(SafeHtml html)
HasSafeHtml
The object will behave exactly the same as when a widget's
HasHTML.setHTML(String)
method is
invoked; however the SafeHtml
passed to this method observes the
contract that it can be used in an HTML context without causing unsafe
script execution. Thus, unlike
HasHTML.setHTML(String)
, using this
method cannot result in Cross-Site Scripting security vulnerabilities.
setHTML
in interface HasSafeHtml
setHTML
in class ButtonBase
html
- the object's new HTML, represented as a SafeHtml
objectpublic void setHTML(java.lang.String html)
setHTML
in interface HasHTML
setHTML
in class ButtonBase
html
- html to setpublic void setTabIndex(int index)
Focusable
-1
will cause this widget to
be removed from the tab order.setTabIndex
in interface Focusable
setTabIndex
in class FocusWidget
index
- the widget's tab indexpublic void setText(java.lang.String text)
setText
in interface HasText
setText
in class ButtonBase
text
- text to setprotected boolean isDown()
true
if the button is downprotected void onAttach()
onAttach
in class FocusWidget
Widget.onLoad()
,
Widget.doAttachChildren()
protected void onClick()
onClickStart()
should override this method to restore the normal
widget display.protected void onClickCancel()
onClickStart()
should override this
method to restore the normal widget display.protected void onClickStart()
onClick()
and
onClickCancel()
to restore normal visual state. Each
onClickStart
will eventually be followed by either
onClick
or onClickCancel
, depending on whether
the click is completed.protected void onDetach()
Widget
This 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 use Widget.addAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler)
.
It is strongly recommended that you override Widget.onUnload()
or
Widget.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.
onDetach
in class Widget
Widget.onUnload()
,
Widget.doDetachChildren()
protected void setDown(boolean down)
down
- true
to press the button, false
otherwisevoid finishSetup()
void fireClickListeners(Event nativeEvent)
CustomButton.Face getCurrentFace()
final boolean isHovering()
true
if the mouse is hoveringvoid setCurrentFace(CustomButton.Face newFace)
final void setHovering(boolean hovering)
hovering
- is this button hovering?void toggleDown()