jcontrol.ui.wombat
Class Button

java.lang.Object
  extended by jcontrol.ui.wombat.Component
      extended by jcontrol.ui.wombat.AbstractFocusComponent
          extended by jcontrol.ui.wombat.Button
All Implemented Interfaces:
EventListener, ActionProducer, KeyListener, TouchListener, IFocusable

public class Button
extends AbstractFocusComponent

Instances of this class represent a keyboard/touchpad selectable user interface object that issues notification when pressed and released.

(c) Copyright 2005-2007 DOMOLOGIC GmbH


Field Summary
 
Fields inherited from class jcontrol.ui.wombat.AbstractFocusComponent
BORDER_WIDTH, listener
 
Fields inherited from class jcontrol.ui.wombat.Component
backgroundColor, COLOR_COMPONENT_BACKGROUND, COLOR_COMPONENT_BACKGROUND_HIGHLIGHTED, COLOR_COMPONENT_DARK_SHADOW, COLOR_COMPONENT_FOREGROUND, COLOR_COMPONENT_FOREGROUND_INACTIVE, COLOR_COMPONENT_HIGHLIGHT_SHADOW, COLOR_COMPONENT_LIGHT_SHADOW, COLOR_COMPONENT_LIST_BACKGROUND, COLOR_COMPONENT_NORMAL_SHADOW, COLOR_COMPONENT_SELECTION_TEXT, COLOR_COMPONENT_SELECTION_TEXT_BACKGROUND, COLOR_COMPONENT_SELECTION_TEXT_BACKGROUND_INACTIVE, COLOR_COMPONENT_SELECTION_TEXT_INACTIVE, eventQueue, font, foregroundColor, frame, height, parent, RESERVED1, RESERVED2, RESERVED3, RESERVED4, RESERVED5, RESERVED6, state, STATE_ABORT_UPDATE, STATE_ANIMATED, STATE_BG_COLOR_SET, STATE_COVERED, STATE_DIRTY_MASK, STATE_DIRTY_PAINTALL, STATE_DIRTY_REPAINT, STATE_DIRTY_UPDATE, STATE_DISABLED, STATE_DISPOSED, STATE_FG_COLOR_SET, STATE_FOCUS, STATE_HEIGHT_FIXED, STATE_NO_REDRAW, STATE_REVALIDATE, STATE_SELECTED, STATE_SIZE_FIXED, STATE_UPDATED, STATE_VISIBLE, STATE_WIDTH_FIXED, transparentColor, width, x, y
 
Fields inherited from interface jcontrol.ui.wombat.IFocusable
TRANSFER_FOCUS_BACKWARD, TRANSFER_FOCUS_FORWARD
 
Fields inherited from interface jcontrol.ui.wombat.event.TouchListener
RESULT_ACCEPTED, RESULT_EXECUTED, RESULT_NONE
 
Constructor Summary
Button(String text, int x, int y)
          Constructs a new button.
Button(String text, int x, int y, int width, int height)
          Constructs a new button with fixed size.
 
Method Summary
 KeyEvent onKeyEvent(KeyEvent e)
          If a KeyEvent accurs, this method is called.
 int onTouchEvent(TouchEvent e)
          If a TouchEvent accurs, this method is called.
 void paint(XGraphics g)
          Paint the button.
 void press(boolean onoff)
          This method can be used to change the pressed state of the button from outside.
 void setImage(Resource image)
          Change the button's image.
 void setText(String label)
          Change the button's text.
 
Methods inherited from class jcontrol.ui.wombat.AbstractFocusComponent
clearCorners, drawBevelRect, drawButton, drawDottedRect, drawFocusRect, getActionListener, onActionEvent, requestFocus, setActionListener, setEnabled, setVisible
 
Methods inherited from class jcontrol.ui.wombat.Component
drawDisabledImage, getFrame, isEnabled, isVisible, isVisibleInternal, redrawInternalAndParent, repaint, repaintAll, safeExec, setBackgroundColor, setBackgroundColorInternal, setBounds, setDirty, setFont, setForegroundColor, setForegroundColorInternal, setParametersInternal, setRedraw, setTransparentColor, unsafeExec, update
 
Methods inherited from class java.lang.Object
clone, equals, getClass, notifyAll, toString, wait
 

Constructor Detail

Button

public Button(String text,
              int x,
              int y)
Constructs a new button. The size will be calculated as big as is fits the given text.

Parameters:
text - the text to display on the button.
x - the x-coordinate of the button's top-left corner
y - the y-coordinate of the button's top-left corner

Button

public Button(String text,
              int x,
              int y,
              int width,
              int height)
Constructs a new button with fixed size.

Parameters:
text - the label to display on the button.
x - the x-coordinate of the button's top-left corner
y - the y-coordinate of the button's top-left corner
width - the width of the button
height - the height of the button
Method Detail

setText

public void setText(String label)
Change the button's text. The size will be re-calculated if it has not been specified with the setBounds()-method or in the constructor.

Parameters:
text - the new text to set.

setImage

public void setImage(Resource image)
Change the button's image. The size will be re-calculated if it has not been specified with the setBounds()-method or in the constructor.

Parameters:
image - the new image to set.

press

public void press(boolean onoff)
This method can be used to change the pressed state of the button from outside. No ActionEvent is fired when this method is called.

Parameters:
onoff - press or release.

paint

public void paint(XGraphics g)
Paint the button. Don't call this method directly.

Overrides:
paint in class Component
Parameters:
g - the global graphics object

onKeyEvent

public KeyEvent onKeyEvent(KeyEvent e)
If a KeyEvent accurs, this method is called.

Specified by:
onKeyEvent in interface KeyListener
Specified by:
onKeyEvent in class AbstractFocusComponent
Parameters:
e - the KeyEvent.
Returns:
null if the KeyEvent has been consumed by the KeyListener,
or the the specified KeyEvent if it should be passed on to the next KeyListener.

onTouchEvent

public int onTouchEvent(TouchEvent e)
If a TouchEvent accurs, this method is called.

Specified by:
onTouchEvent in interface TouchListener
Specified by:
onTouchEvent in class AbstractFocusComponent
Parameters:
e - the TouchEvent.
Returns:
RESULT_ACCEPTED if the TouchEvent has been consumed by the TouchListener,
RESULT_EXECUTED if the TouchEvent has been consumed by the TouchListener and some important action has been performed, e.g. an action event has been invoked,
RESULT_NONE if the TouchEvent should be passed on to the next TouchListener.