Google Web Toolkit
Search Google Code:

# Class CustomButton

public class CustomButton
extends ButtonBase
implements SourcesKeyboardEvents
// Superclass of `PushButton`, `ToggleButton`
Custom Button is a base button class with built in support for a set number of button faces. Each face has its own style modifier. For example, the state for down and hovering is assigned the CSS modifier down-hovering. So, if the button's overall style name is gwt-PushButton then when showing the `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

## Nested Classes

CustomButton.Face | Represents a button's face.

## Constructors

CustomButton(Image) | Constructor for `CustomButton`.
CustomButton(Image, Image) | Constructor for `CustomButton`.
CustomButton(Image, Image, ClickListener) | Constructor for `CustomButton`.
CustomButton(Image, ClickListener) | Constructor for `CustomButton`.
CustomButton(String) | Constructor for `CustomButton`.
CustomButton(String, ClickListener) | Constructor for `CustomButton`.
CustomButton(String, String) | Constructor for `CustomButton`.
CustomButton(String, String, ClickListener) | Constructor for `CustomButton`.
CustomButton() | Constructor for `CustomButton`.

## Methods

getDownDisabledFace() | Gets the downDisabled face of the button.
getDownFace() | Gets the down face of the button.
getDownHoveringFace() | Gets the downHovering face of the button.
getHTML() | Gets the current face's html.
getTabIndex() |
getText() | Gets the current face's text.
getUpDisabledFace() | Gets the upDisabled face of the button.
getUpFace() | Gets the up face of the button.
getUpHoveringFace() | Gets the upHovering face of the button.
isDown() | Is this button down?
onAttach() | Overridden on attach to ensure that a button face has been chosen before the button is displayed.
onBrowserEvent(Event) |
onClick() | Called when the user finishes clicking on this button.
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.
onClickStart() | Called when the user begins to click on this button.
onDetach() | This method is called when a widget is detached from the browser's document.
setAccessKey(char) |
setDown(boolean) | Sets whether this button is down.
setEnabled(boolean) | Sets whether this button is enabled.
setFocus(boolean) |
setHTML(String) | Sets the current face's html.
setTabIndex(int) |
setText(String) | Sets the current face's text.

## Constructor Detail

### CustomButton

public CustomButton(Image upImage)
Constructor for `CustomButton`.

#### Parameters

upImage
  image for the default (up) face of the button

### CustomButton

public CustomButton(Image upImage, Image downImage)
Constructor for `CustomButton`.

#### Parameters

upImage
  image for the default (up) face of the button
downImage
  image for the down face of the button

### CustomButton

public CustomButton(Image upImage, Image downImage, ClickListener listener)
Constructor for `CustomButton`.

#### Parameters

upImage
  image for the default (up) face of the button
downImage
  image for the down face of the button
listener
  clickListener

### CustomButton

public CustomButton(Image upImage, ClickListener listener)
Constructor for `CustomButton`.

#### Parameters

upImage
  image for the default (up) face of the button
listener
  the click listener

### CustomButton

public CustomButton(String upText)
Constructor for `CustomButton`.

#### Parameters

upText
  the text for the default (up) face of the button.

### CustomButton

public CustomButton(String upText, ClickListener listener)
Constructor for `CustomButton`.

#### Parameters

upText
  the text for the default (up) face of the button
listener
  the click listener

### CustomButton

public CustomButton(String upText, String downText)
Constructor for `CustomButton`.

#### Parameters

upText
  the text for the default (up) face of the button
downText
  the text for the down face of the button

### CustomButton

public CustomButton(String upText, String downText, ClickListener listener)
Constructor for `CustomButton`.

#### Parameters

upText
  the text for the default (up) face of the button
downText
  the text for the down face of the button
listener
  the click listener

### CustomButton

protected CustomButton()
Constructor for `CustomButton`.

## Method Detail

### getDownDisabledFace

public final CustomButton.Face getDownDisabledFace()
Gets the downDisabled face of the button.

#### Return Value

the downDisabled face

### getDownFace

public final CustomButton.Face getDownFace()
Gets the down face of the button.

#### Return Value

the down face

### getDownHoveringFace

public final CustomButton.Face getDownHoveringFace()
Gets the downHovering face of the button.

#### Return Value

the downHovering face

### getHTML

public String getHTML()
Gets the current face's html.

#### Return Value

current face's html

### getTabIndex

public int getTabIndex()

### getText

public String getText()
Gets the current face's text.

#### Return Value

current face's text

### getUpDisabledFace

public final CustomButton.Face getUpDisabledFace()
Gets the upDisabled face of the button.

#### Return Value

the upDisabled face

### getUpFace

public final CustomButton.Face getUpFace()
Gets the up face of the button.

#### Return Value

the up face

### getUpHoveringFace

public final CustomButton.Face getUpHoveringFace()
Gets the upHovering face of the button.

#### Return Value

the upHovering face

### isDown

protected boolean isDown()
Is this button down?

#### Return Value

`true` if 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.

### onBrowserEvent

public void onBrowserEvent(Event event)

#### Parameters

event

### 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 override onClickStart() 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 override onClickStart() 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 override 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.

### onDetach

protected void onDetach()
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 onUnload method.

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.

### setAccessKey

public void setAccessKey(char key)

#### Parameters

key

### setDown

protected void setDown(boolean down)
Sets whether this button is down.

#### Parameters

down
  `true` to press the button, `false` otherwise

### setEnabled

public final void setEnabled(boolean enabled)
Sets whether this button is enabled.

#### Parameters

enabled
  `true` to enable the button, `false` to disable it

### setFocus

public void setFocus(boolean focused)

#### Parameters

focused

### setHTML

public void setHTML(String html)
Sets the current face's html.

#### Parameters

html
  html to set

### setTabIndex

public void setTabIndex(int index)

#### Parameters

index

### setText

public void setText(String text)
Sets the current face's text.

#### Parameters

text
  text to set