com.sun.lwuit
Class Button

java.lang.Object
  extended by com.sun.lwuit.Component
      extended by com.sun.lwuit.Label
          extended by com.sun.lwuit.Button
All Implemented Interfaces:
Animation, StyleListener
Direct Known Subclasses:
CheckBox, RadioButton

public class Button
extends Label

Button is the base class for several UI widgets allowing clickability. It has 3 states: rollover, pressed and the default state it can also have ActionListeners that react when the Button is clicked.


Field Summary
static int STATE_DEFAULT
          Indicates the default state of a button which is neither pressed nor focused
static int STATE_PRESSED
          Indicates the pressed state of a button
static int STATE_ROLLOVER
          Indicates the rollover state of a button which is equivalent to focused for most uses
 
Fields inherited from class com.sun.lwuit.Component
BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, LEFT, RIGHT, TOP
 
Constructor Summary
Button()
          Constructs a button with an empty string for its text.
Button(Command cmd)
          Allows binding a command to a button for ease of use
Button(Image icon)
          Constructs a button with the specified image.
Button(java.lang.String text)
          Constructs a button with the specified text.
Button(java.lang.String text, Image icon)
          Constructor a button with text and image
 
Method Summary
 void addActionListener(ActionListener l)
          Adds a listener to the button which will cause an event to dispatch on click
 boolean animate()
          Allows the animation to reduce "repaint" calls when it returns false.
protected  Dimension calcPreferredSize()
          Calculates the preferred size based on component content.
protected  void dragInitiated()
          Invoked on the focus component to let it know that drag has started on the parent container for the case of a component that doesn't support scrolling
protected  void fireClicked()
          When working in 3 softbutton mode "fire" key (center softbutton) is sent to this method in order to allow 3 button devices to work properly.
protected  Border getBorder()
          Normally returns getStyle().getBorder() but some subclasses might use this to programmatically replace the border in runtime e.g. for a pressed border effect
 Command getCommand()
          This method return the Button Command if exists
 Image getDisabledIcon()
          Indicates the icon that is displayed on the button when the button is in the disabled state
 Image getIconFromState()
          Returns the icon for the button based on its current state
 Image getPressedIcon()
          Indicates the icon that is displayed on the button when the button is in pressed state
 Image getRolloverIcon()
          Indicates the icon that is displayed on the button when the button is in rolled over state
 Image getRolloverPressedIcon()
          Indicates the icon that is displayed on the button when the button is in pressed state and is selected.
 int getState()
          Returns the button state
 boolean isOppositeSide()
          Places the check box or radio button on the opposite side at the far end
protected  boolean isSelectableInteraction()
          This method allows a component to indicate that it is interested in an "implicit" select command to appear in the "fire" button when 3 softbuttons are defined in a device.
 boolean isSelected()
          Returns true if the button is selected for toggle buttons, throws an exception if this is not a toggle button
 boolean isToggle()
          Toggle button mode is only relevant for checkboxes/radio buttons.
 void keyPressed(int keyCode)
          If this Component is focused, the key pressed event will call this method
 void keyReleased(int keyCode)
          If this Component is focused, the key released event will call this method
 void keyRepeated(int keyCode)
          If this Component is focused, the key repeat event will call this method.
 void paint(Graphics g)
          This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.
 void pointerDragged(int x, int y)
          If this Component is focused, the pointer dragged event will call this method
 void pointerHover(int[] x, int[] y)
          Invoked for devices where the pointer can hover without actually clicking the display.
 void pointerHoverReleased(int[] x, int[] y)
          Invoked for devices where the pointer can hover without actually clicking the display.
 void pointerPressed(int x, int y)
          If this Component is focused, the pointer pressed event will call this method
 void pointerReleased(int x, int y)
          If this Component is focused, the pointer released event will call this method
 void pressed()
          Invoked to change the state of the button to the pressed state
 void released()
          Invoked to change the state of the button to the released state
 void released(int x, int y)
          Invoked to change the state of the button to the released state
 void removeActionListener(ActionListener l)
          Removes the given action listener from the button
 void setAlignment(int align)
          Deprecated. use the Style alignment instead
 void setCommand(Command cmd)
          Applies the given command to this button
 void setDisabledIcon(Image disabledIcon)
          Indicates the icon that is displayed on the button when the button is in the disabled state
 void setPressedIcon(Image pressedIcon)
          Indicates the icon that is displayed on the button when the button is in pressed state
 void setRolloverIcon(Image rolloverIcon)
          Indicates the icon that is displayed on the button when the button is in rolled over state
 void setRolloverPressedIcon(Image rolloverPressedIcon)
          Indicates the icon that is displayed on the button when the button is in pressed state and is selected.
 void setToggle(boolean toggle)
          Toggle button mode is only relevant for checkboxes/radio buttons.
 
Methods inherited from class com.sun.lwuit.Label
getAlignment, getBaselineResizeBehavior, getGap, getIcon, getShiftText, getText, getTextPosition, getVerticalAlignment, isDefaultTickerEnabled, isEndsWith3Points, isTickerEnabled, isTickerRunning, paramString, setDefaultTickerEnabled, setEndsWith3Points, setGap, setIcon, setShiftText, setText, setTextPosition, setTickerEnabled, setVerticalAlignment, shouldTickerStart, startTicker, startTicker, stopTicker
 
Methods inherited from class com.sun.lwuit.Component
addFocusListener, calcScrollSize, contains, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, draggingOver, drawDraggedImage, drop, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getBaseline, getBottomGap, getBounds, getClientProperty, getComponentForm, getDirtyRegion, getDisabledStyle, getDragImage, getGridPosX, getGridPosY, getHeight, getLabelForComponent, getName, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getParent, getPreferredH, getPreferredSize, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypes, getPropertyValue, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSideGap, getStyle, getTensileLength, getUIID, getUnselectedStyle, getWidth, getVisibleBounds, getX, getY, growShrink, handlesInput, hasFocus, initComponent, initCustomStyle, installDefaultPainter, isAlwaysTensile, isDragActivated, isDragAndDropOperation, isDraggable, isDropTarget, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHideInPortrait, isInitialized, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSmoothScrolling, isSnapToGrid, isTactileTouch, isTactileTouch, isTensileDragEnabled, isVisible, laidOut, longKeyPress, longPointerPress, paintBackground, paintBackgrounds, paintBorder, paintComponent, paintComponent, paintLock, paintLockRelease, paintScrollbars, paintScrollbarX, paintScrollbarY, pointerDragged, pointerHoverPressed, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, removeFocusListener, repaint, repaint, requestFocus, scrollRectToVisible, scrollRectToVisible, setAlwaysTensile, setCellRenderer, setDirtyRegion, setDisabledStyle, setDraggable, setDropTarget, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHideInPortrait, setInitialized, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setPreferredH, setPreferredSize, setPreferredW, setPressedStyle, setPropertyValue, setRTL, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTactileTouch, setTensileDragEnabled, setTensileLength, setUIID, setUnselectedStyle, setWidth, setVisible, setX, setY, styleChanged, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATE_ROLLOVER

public static final int STATE_ROLLOVER
Indicates the rollover state of a button which is equivalent to focused for most uses

See Also:
Constant Field Values

STATE_PRESSED

public static final int STATE_PRESSED
Indicates the pressed state of a button

See Also:
Constant Field Values

STATE_DEFAULT

public static final int STATE_DEFAULT
Indicates the default state of a button which is neither pressed nor focused

See Also:
Constant Field Values
Constructor Detail

Button

public Button()
Constructs a button with an empty string for its text.


Button

public Button(java.lang.String text)
Constructs a button with the specified text.

Parameters:
text - label appearing on the button

Button

public Button(Command cmd)
Allows binding a command to a button for ease of use

Parameters:
cmd - command whose text would be used for the button and would recive action events from the button

Button

public Button(Image icon)
Constructs a button with the specified image.

Parameters:
icon - appearing on the button

Button

public Button(java.lang.String text,
              Image icon)
Constructor a button with text and image

Parameters:
text - label appearing on the button
icon - image appearing on the button
Method Detail

setCommand

public void setCommand(Command cmd)
Applies the given command to this button

Parameters:
cmd - the command on the button

getState

public int getState()
Returns the button state

Returns:
One of STATE_ROLLOVER, STATE_DEAFULT, STATE_PRESSED

getPressedIcon

public Image getPressedIcon()
Indicates the icon that is displayed on the button when the button is in pressed state

Returns:
icon used
See Also:
STATE_PRESSED

getRolloverPressedIcon

public Image getRolloverPressedIcon()
Indicates the icon that is displayed on the button when the button is in pressed state and is selected. This is ONLY applicable to toggle buttons

Returns:
icon used

setRolloverPressedIcon

public void setRolloverPressedIcon(Image rolloverPressedIcon)
Indicates the icon that is displayed on the button when the button is in pressed state and is selected. This is ONLY applicable to toggle buttons

Parameters:
rolloverPressedIcon - icon used

getDisabledIcon

public Image getDisabledIcon()
Indicates the icon that is displayed on the button when the button is in the disabled state

Returns:
icon used

getRolloverIcon

public Image getRolloverIcon()
Indicates the icon that is displayed on the button when the button is in rolled over state

Returns:
icon used
See Also:
STATE_ROLLOVER

setRolloverIcon

public void setRolloverIcon(Image rolloverIcon)
Indicates the icon that is displayed on the button when the button is in rolled over state

Parameters:
rolloverIcon - icon to use
See Also:
STATE_ROLLOVER

setPressedIcon

public void setPressedIcon(Image pressedIcon)
Indicates the icon that is displayed on the button when the button is in pressed state

Parameters:
pressedIcon - icon used
See Also:
STATE_PRESSED

setDisabledIcon

public void setDisabledIcon(Image disabledIcon)
Indicates the icon that is displayed on the button when the button is in the disabled state

Parameters:
disabledIcon - icon used

addActionListener

public void addActionListener(ActionListener l)
Adds a listener to the button which will cause an event to dispatch on click

Parameters:
l - implementation of the action listener interface

removeActionListener

public void removeActionListener(ActionListener l)
Removes the given action listener from the button

Parameters:
l - implementation of the action listener interface

getIconFromState

public Image getIconFromState()
Returns the icon for the button based on its current state

Returns:
the button icon based on its current state

pressed

public void pressed()
Invoked to change the state of the button to the pressed state


released

public void released()
Invoked to change the state of the button to the released state


released

public void released(int x,
                     int y)
Invoked to change the state of the button to the released state

Parameters:
x - the x position if a touch event triggered this, -1 if this isn't relevant
y - the y position if a touch event triggered this, -1 if this isn't relevant

keyPressed

public void keyPressed(int keyCode)
Description copied from class: Component
If this Component is focused, the key pressed event will call this method

Overrides:
keyPressed in class Component
Parameters:
keyCode - the key code value to indicate a physical key.

keyReleased

public void keyReleased(int keyCode)
Description copied from class: Component
If this Component is focused, the key released event will call this method

Overrides:
keyReleased in class Component
Parameters:
keyCode - the key code value to indicate a physical key.

keyRepeated

public void keyRepeated(int keyCode)
Description copied from class: Component
If this Component is focused, the key repeat event will call this method.

Overrides:
keyRepeated in class Component
Parameters:
keyCode - the key code value to indicate a physical key.

fireClicked

protected void fireClicked()
Description copied from class: Component
When working in 3 softbutton mode "fire" key (center softbutton) is sent to this method in order to allow 3 button devices to work properly. When overriding this method you should also override isSelectableInteraction to indicate that a command is placed appropriately on top of the fire key for 3 soft button phones.

Overrides:
fireClicked in class Component

isSelectableInteraction

protected boolean isSelectableInteraction()
Description copied from class: Component
This method allows a component to indicate that it is interested in an "implicit" select command to appear in the "fire" button when 3 softbuttons are defined in a device.

Overrides:
isSelectableInteraction in class Component
Returns:
true if this is a selectable interaction

pointerHover

public void pointerHover(int[] x,
                         int[] y)
Description copied from class: Component
Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.

Overrides:
pointerHover in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

pointerHoverReleased

public void pointerHoverReleased(int[] x,
                                 int[] y)
Description copied from class: Component
Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.

Overrides:
pointerHoverReleased in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

pointerPressed

public void pointerPressed(int x,
                           int y)
Description copied from class: Component
If this Component is focused, the pointer pressed event will call this method

Overrides:
pointerPressed in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

pointerReleased

public void pointerReleased(int x,
                            int y)
Description copied from class: Component
If this Component is focused, the pointer released event will call this method

Overrides:
pointerReleased in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

dragInitiated

protected void dragInitiated()
Description copied from class: Component
Invoked on the focus component to let it know that drag has started on the parent container for the case of a component that doesn't support scrolling

Overrides:
dragInitiated in class Component

pointerDragged

public void pointerDragged(int x,
                           int y)
Description copied from class: Component
If this Component is focused, the pointer dragged event will call this method

Overrides:
pointerDragged in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

paint

public void paint(Graphics g)
Description copied from class: Component
This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

Specified by:
paint in interface Animation
Overrides:
paint in class Label
Parameters:
g - the component graphics

calcPreferredSize

protected Dimension calcPreferredSize()
Description copied from class: Component
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Overrides:
calcPreferredSize in class Label
Returns:
the calculated preferred size based on component content

getBorder

protected Border getBorder()
Description copied from class: Component
Normally returns getStyle().getBorder() but some subclasses might use this to programmatically replace the border in runtime e.g. for a pressed border effect

Overrides:
getBorder in class Component
Returns:
the border that is drawn according to the current component state

getCommand

public Command getCommand()
This method return the Button Command if exists

Returns:
Command Object or null if a Command not exists

isSelected

public boolean isSelected()
Returns true if the button is selected for toggle buttons, throws an exception if this is not a toggle button

Returns:
true if the button is selected

setAlignment

public void setAlignment(int align)
Deprecated. use the Style alignment instead

Description copied from class: Label
Sets the Alignment of the Label to one of: CENTER, LEFT, RIGHT

Overrides:
setAlignment in class Label
Parameters:
align - alignment value
See Also:
Component.CENTER, Component.LEFT, Component.RIGHT

isToggle

public boolean isToggle()
Toggle button mode is only relevant for checkboxes/radio buttons. When pressed a toggle button stays pressed and when pressed again it moves to releleased state.

Returns:
the toggle

setToggle

public void setToggle(boolean toggle)
Toggle button mode is only relevant for checkboxes/radio buttons. When pressed a toggle button stays pressed and when pressed again it moves to releleased state. Setting toggle implicitly changes the UIID to "ToggleButton"

Parameters:
toggle - the toggle to set

animate

public boolean animate()
Description copied from interface: Animation
Allows the animation to reduce "repaint" calls when it returns false. It is called once for every frame. Frames are defined by the Display class.

Specified by:
animate in interface Animation
Overrides:
animate in class Label
Returns:
true if a repaint is desired or false if no repaint is necessary

isOppositeSide

public boolean isOppositeSide()
Places the check box or radio button on the opposite side at the far end

Returns:
the oppositeSide