Package com.google.gwt.user.client.ui
Class ToggleButton
- java.lang.Object
-
- All Implemented Interfaces:
IsEditor<LeafValueEditor<java.lang.Boolean>>
,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
,HasValueChangeHandlers<java.lang.Boolean>
,HasHandlers
,HasSafeHtml
,EventListener
,TakesValue<java.lang.Boolean>
,Focusable
,HasEnabled
,HasFocus
,HasHTML
,HasText
,HasValue<java.lang.Boolean>
,HasVisibility
,IsWidget
,SourcesClickEvents
,SourcesFocusEvents
,SourcesKeyboardEvents
,SourcesMouseEvents
public class ToggleButton extends CustomButton implements HasValue<java.lang.Boolean>, IsEditor<LeafValueEditor<java.lang.Boolean>>
AToggleButton
is a stylish stateful button which allows the user to toggle betweenup
anddown
states.CSS Style Rules
- .gwt-ToggleButton-up/down/up-hovering/down-hovering/up-disabled/down-disabled {.html-face}
Example
public class ToggleButtonExample implements EntryPoint { public void onModuleLoad() { // Make a new button that does something when you click it. final ToggleButton toggleButton = new ToggleButton("Up", "Down"); toggleButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (toggleButton.isDown()) { Window.alert("I have been toggled down"); } else { Window.alert("I have been toggled up"); } } }); // In a real application, you would have to have css styles defined for // gwt-ToggleButton-up,gwt-ToggleButton-up-hovering,gwt-ToggleButton-up-disabled, // gwt-ToggleButton-down,.gwt-ToggleButton-down-hovering,.gwt-ToggleButton-down-disabled // Add the ToggleButton to the root panel. RootPanel.get().add(toggleButton); } }
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.CustomButton
CustomButton.Face
-
Nested 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
eventsToSink
-
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
-
-
Constructor Summary
Constructors Constructor Description ToggleButton()
Constructor forToggleButton
.ToggleButton(Image upImage)
Constructor forToggleButton
.ToggleButton(Image upImage, ClickHandler handler)
Constructor forToggleButton
.ToggleButton(Image upImage, ClickListener listener)
Deprecated.UseToggleButton(Image, ClickHandler)
insteadToggleButton(Image upImage, Image downImage)
Constructor forToggleButton
.ToggleButton(Image upImage, Image downImage, ClickHandler handler)
Constructor forToggleButton
.ToggleButton(Image upImage, Image downImage, ClickListener listener)
Deprecated.UseToggleButton(Image, Image, ClickHandler)
insteadToggleButton(java.lang.String upText)
Constructor forToggleButton
.ToggleButton(java.lang.String upText, ClickHandler handler)
Constructor forToggleButton
.ToggleButton(java.lang.String upText, ClickListener listener)
Deprecated.UseToggleButton(String, ClickHandler)
insteadToggleButton(java.lang.String upText, java.lang.String downText)
Constructor forToggleButton
.ToggleButton(java.lang.String upText, java.lang.String downText, ClickHandler handler)
Constructor forToggleButton
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HandlerRegistration
addValueChangeHandler(ValueChangeHandler<java.lang.Boolean> handler)
Adds aValueChangeEvent
handler.LeafValueEditor<java.lang.Boolean>
asEditor()
Returns the Editor encapsulated by the view object.java.lang.Boolean
getValue()
Determines whether this button is currently down.boolean
isDown()
Is this button down?protected void
onClick()
Called when the user finishes clicking on this button.void
setDown(boolean down)
Sets whether this button is down.void
setValue(java.lang.Boolean value)
Sets whether this button is down.void
setValue(java.lang.Boolean value, boolean fireEvents)
Sets whether this button is down, firingValueChangeEvent
if appropriate.-
Methods inherited from class com.google.gwt.user.client.ui.CustomButton
finishSetup, fireClickListeners, getCurrentFace, getDownDisabledFace, getDownFace, getDownHoveringFace, getHTML, getTabIndex, getText, getUpDisabledFace, getUpFace, getUpHoveringFace, isHovering, onAttach, onBrowserEvent, onClickCancel, onClickStart, onDetach, setAccessKey, setCurrentFace, setEnabled, setFocus, setHovering, setHTML, setHTML, setTabIndex, setText, toggleDown
-
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, removeMouseWheelListener
-
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, onLoad, 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
-
-
-
-
Constructor Detail
-
ToggleButton
public ToggleButton()
Constructor forToggleButton
.
-
ToggleButton
public ToggleButton(Image upImage)
Constructor forToggleButton
. The supplied image is used to construct the default face.- Parameters:
upImage
- image for the default face of the button
-
ToggleButton
public ToggleButton(Image upImage, ClickHandler handler)
Constructor forToggleButton
. The supplied image is used to construct the default face of the button.- Parameters:
upImage
- image for the default (up) face of the buttonhandler
- the click handler
-
ToggleButton
@Deprecated public ToggleButton(Image upImage, ClickListener listener)
Deprecated.UseToggleButton(Image, ClickHandler)
insteadConstructor forToggleButton
. The supplied image is used to construct the default face of the button.- Parameters:
upImage
- image for the default (up) face of the buttonlistener
- the click listener
-
ToggleButton
public ToggleButton(Image upImage, Image downImage)
Constructor forToggleButton
.- Parameters:
upImage
- image for the default(up) face of the buttondownImage
- image for the down face of the button
-
ToggleButton
public ToggleButton(Image upImage, Image downImage, ClickHandler handler)
Constructor forToggleButton
.- Parameters:
upImage
- image for the default(up) face of the buttondownImage
- image for the down face of the buttonhandler
- the click handler
-
ToggleButton
@Deprecated public ToggleButton(Image upImage, Image downImage, ClickListener listener)
Deprecated.UseToggleButton(Image, Image, ClickHandler)
insteadConstructor forToggleButton
.- Parameters:
upImage
- image for the default(up) face of the buttondownImage
- image for the down face of the buttonlistener
- clickListener
-
ToggleButton
public ToggleButton(java.lang.String upText)
Constructor forToggleButton
. The supplied text is used to construct the default face of the button.- Parameters:
upText
- the text for the default (up) face of the button.
-
ToggleButton
public ToggleButton(java.lang.String upText, ClickHandler handler)
Constructor forToggleButton
. The supplied text is used to construct the default face of the button.- Parameters:
upText
- the text for the default (up) face of the buttonhandler
- the click handler
-
ToggleButton
@Deprecated public ToggleButton(java.lang.String upText, ClickListener listener)
Deprecated.UseToggleButton(String, ClickHandler)
insteadConstructor forToggleButton
. The supplied text is used to construct the default face of the button.- Parameters:
upText
- the text for the default (up) face of the buttonlistener
- the click listener
-
ToggleButton
public ToggleButton(java.lang.String upText, java.lang.String downText)
Constructor forToggleButton
.- Parameters:
upText
- the text for the default (up) face of the buttondownText
- the text for down face of the button
-
ToggleButton
public ToggleButton(java.lang.String upText, java.lang.String downText, ClickHandler handler)
Constructor forToggleButton
.- Parameters:
upText
- the text for the default (up) face of the buttondownText
- the text for down face of the buttonhandler
- the click handler
-
-
Method Detail
-
addValueChangeHandler
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<java.lang.Boolean> handler)
Description copied from interface:HasValueChangeHandlers
Adds aValueChangeEvent
handler.- Specified by:
addValueChangeHandler
in interfaceHasValueChangeHandlers<java.lang.Boolean>
- Parameters:
handler
- the handler- Returns:
- the registration for the event
-
asEditor
public LeafValueEditor<java.lang.Boolean> asEditor()
Description copied from interface:IsEditor
Returns the Editor encapsulated by the view object.- Specified by:
asEditor
in interfaceIsEditor<LeafValueEditor<java.lang.Boolean>>
- Returns:
- an
Editor
of type E
-
getValue
public java.lang.Boolean getValue()
Determines whether this button is currently down.- Specified by:
getValue
in interfaceHasValue<java.lang.Boolean>
- Specified by:
getValue
in interfaceTakesValue<java.lang.Boolean>
- Returns:
true
if the button is pressed, false otherwise. Will not return null- See Also:
TakesValue.setValue(V)
-
isDown
public boolean isDown()
Description copied from class:CustomButton
Is this button down?- Overrides:
isDown
in classCustomButton
- Returns:
true
if the button is down
-
setDown
public void setDown(boolean down)
Sets whether this button is down. Does not fireValueChangeEvent
. (If you want the event to fire, usesetValue(Boolean, boolean)
)- Overrides:
setDown
in classCustomButton
- Parameters:
down
-true
to press the button,false
otherwise
-
setValue
public void setValue(java.lang.Boolean value)
Sets whether this button is down.- Specified by:
setValue
in interfaceHasValue<java.lang.Boolean>
- Specified by:
setValue
in interfaceTakesValue<java.lang.Boolean>
- Parameters:
value
- true to press the button, false otherwise; null value implies false- See Also:
TakesValue.getValue()
-
setValue
public void setValue(java.lang.Boolean value, boolean fireEvents)
Sets whether this button is down, firingValueChangeEvent
if appropriate.- Specified by:
setValue
in interfaceHasValue<java.lang.Boolean>
- Parameters:
value
- true to press the button, false otherwise; null value implies falsefireEvents
- If true, and value has changed, fire aValueChangeEvent
-
onClick
protected void onClick()
Description copied from class:CustomButton
Called when the user finishes clicking on this button. The default behavior is to fire the click event to listeners. Subclasses that overrideCustomButton.onClickStart()
should override this method to restore the normal widget display.- Overrides:
onClick
in classCustomButton
-
-