com.sybase.uep.bobclient.controls
Class Button

java.lang.Object
  extended by net.rim.device.api.ui.Field
      extended by com.sybase.uep.bobclient.controls.Button
All Implemented Interfaces:
Control, net.rim.device.api.ui.DrawStyle
Direct Known Subclasses:
ToolbarItem

public class Button
extends net.rim.device.api.ui.Field
implements net.rim.device.api.ui.DrawStyle, Control

This is a button control. It draws a custom button that gets laid out in the LayoutManager

A label can be assigned to the button to display.

An action can be assigned to the button to execute.

It can also display an image to the right side of the button.

Author:
tdang
See Also:
Control, LayoutManager, setAction(IBOBAction action), setImage(String image), setImage(Bitmap image), IBOBAction

Field Summary
protected  AppLoggerWrapper _appLogger
           
protected  int _controlID
           
protected  int _cushion
           
protected  CustomEventsHandler _customEventsHandler
           
protected  net.rim.device.api.system.EncodedImage _eImage
           
protected  FontStyle _focusFontStyle
           
protected  net.rim.device.api.system.Bitmap _image
          Encourage to use the _eImage, keep this field only for compatible with the interface
protected  int _imageAlignment
           
protected  int _orientation
           
protected  FontStyle _unfocusFontStyle
           
static int BUTTON_TOP_BOTTOM_CUSHION
           
static int IMAGE_ALIGN_CENTER
           
static int IMAGE_ALIGN_LEFT
           
static int IMAGE_ALIGN_RIGHT
           
 
Fields inherited from class net.rim.device.api.ui.Field
ACTION_INVOKE, EDITABLE, EDITABLE_MASK, FIELD_BOTTOM, FIELD_HALIGN_MASK, FIELD_HCENTER, FIELD_LEADING, FIELD_LEFT, FIELD_RIGHT, FIELD_TOP, FIELD_TRAILING, FIELD_VALIGN_MASK, FIELD_VCENTER, FOCUSABLE, FOCUSABLE_MASK, HIGHLIGHT_FOCUS, HIGHLIGHT_SELECT, NON_FOCUSABLE, NON_SPELLCHECKABLE, READONLY, SPELLCHECKABLE, SPELLCHECKABLE_MASK, STATUS_MOVE_FOCUS_HORIZONTALLY, STATUS_MOVE_FOCUS_VERTICALLY, USE_ALL_HEIGHT, USE_ALL_WIDTH, VISUAL_STATE_ACTIVE, VISUAL_STATE_DISABLED, VISUAL_STATE_DISABLED_FOCUS, VISUAL_STATE_FOCUS, VISUAL_STATE_NORMAL
 
Fields inherited from interface net.rim.device.api.ui.DrawStyle
BASELINE, BOTTOM, ELLIPSIS, HALIGN_MASK, HCENTER, HDEFAULT, HFULL, LEADING, LEFT, RIGHT, TOP, TRAILING, TRUNCATE_BEGINNING, VALIGN_MASK, VCENTER, VDEFAULT, VFULL
 
Constructor Summary
Button(long style)
          Constructor to create a button control
Button(long style, boolean isFocusable)
           
 
Method Summary
protected  void drawBorder(net.rim.device.api.ui.Graphics g, FontStyle buttonFontStyle)
           
protected  void drawButton(net.rim.device.api.ui.Graphics g, boolean isFocus)
          Draws this button.
protected  void drawFocus(net.rim.device.api.ui.Graphics g, boolean on)
          (non-Javadoc)
protected  void drawGradient(net.rim.device.api.ui.Graphics g, FontStyle buttonFontStyle, int height, int width)
           
 IBOBAction getAction()
          Retrieve the action assigned to this button
 int getBorderColor()
          Retrieve the border color
 int getButtonWidth()
          Retrieve button width based on the label and image
 int getColSpan()
          (non-Javadoc)
 int getControlID()
          Returns the control's ID
 ICustomEventsDelegate getCustomEventsDelegate()
          Returns the control's custom events delegate
 FontStyle getFocusFontStyle()
          Retrieve this focus font style
 long getHorizontalAlignment()
          (non-Javadoc)
 java.lang.String getName()
          (non-Javadoc)
 int getPreferredHeight()
          (non-Javadoc)
 int getPreferredWidth()
          (non-Javadoc)
 int getRowSpan()
          (non-Javadoc)
 FontStyle getUnfocusFontStyle()
          Retrieve this unfocus font style
 java.lang.Object getValue()
          (non-Javadoc)
 long getVerticalAlignment()
          (non-Javadoc)
protected  void layout(int width, int height)
          (non-Javadoc)
protected  boolean navigationClick(int status, int time)
          (non-Javadoc)
protected  boolean navigationMovement(int dx, int dy, int status, int time)
          (non-Javadoc)
protected  boolean navigationUnclick(int status, int time)
          (non-Javadoc)
protected  void onFocus(int direction)
          (non-Javadoc)
protected  void onUnfocus()
          (non-Javadoc)
protected  void paint(net.rim.device.api.ui.Graphics g)
          (non-Javadoc)
 void refresh()
          (non-Javadoc)
 void refreshFooter(java.lang.String valueToBeDisplay)
          Refresh the footer field from the screen that contains the text of the button.
 void runAction()
          Run the action assigned to this button
 void setAction(IBOBAction action)
          Set the action assigned to this button
 void setBackgroundColor(int bgcolor)
          (non-Javadoc)
 void setBorderColor(int color)
          Set the border color
 void setColSpan(int colspan)
          (non-Javadoc)
 void setControlID(int controlID)
          Sets the control's ID
 void setCustomEventsDelegate(ICustomEventsDelegate delegate, int eventsFlags)
          Sets the control's custom events delegate for the given events
 void setFocusFontStyle(FontStyle fontStyle)
          Set the focus font style for this control
 void setFooterField(FooterField field)
          Set the footer field
 void setImage(net.rim.device.api.system.Bitmap image)
          Add image to the button
 void setImage(net.rim.device.api.system.Bitmap image, int alignment)
          Add image to the button
 void setImage(java.lang.String image)
          Add image to the button
 void setImage(java.lang.String image, int alignment)
          Add image to the button
 void setImageAlignment(int alignment)
          Set the image alignment
 void setLabel(int labelRID)
          Set the label for this button by localization resource id
 void setLabel(java.lang.String label)
          Set the label for this button
 void setLayoutHeight(int height)
          (non-Javadoc)
 void setLayoutWidth(int width)
          (non-Javadoc)
 void setProperty(int key, net.rim.device.api.system.Bitmap image)
          Set the property action for this button
 void setProperty(int key, IBOBAction action)
          Set the property action for this button
 void setProperty(int key, java.lang.String value)
          Set the property values for this button
 void setRowSpan(int rowspan)
          (non-Javadoc)
 void setUnfocusFontStyle(FontStyle fontStyle)
          Set the unfocus font style for this control
 void setVariableLabel(ControlVariable variable)
          Set the variable for the label
 java.lang.String toString()
          Return the label of the button
protected  boolean touchEvent(net.rim.device.api.ui.TouchEvent message)
          (non-Javadoc)
 
Methods inherited from class net.rim.device.api.ui.Field
drawHighlightRegion, fieldChangeNotify, focusAdd, focusChangeNotify, focusRemove, getAccessibleContext, getBackground, getBackground, getBorder, getBorder, getBorder, getChangeListener, getContentHeight, getContentLeft, getContentRect, getContentRect, getContentTop, getContentWidth, getContextMenu, getContextMenu, getCookie, getExtent, getExtent, getFieldStyle, getFocusListener, getFocusRect, getFont, getHeight, getIndex, getLeafFieldWithFocus, getLeft, getManager, getMargin, getMarginBottom, getMarginLeft, getMarginRight, getMarginTop, getOriginal, getPadding, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getScreen, getState, getStyle, getTop, getVisualState, getWidth, invalidate, invalidate, invalidateAll, invokeAction, isDataValid, isDirty, isEditable, isFocus, isFocusable, isMuddy, isPasteable, isSelectable, isSelecting, isSelectionCopyable, isSelectionCutable, isSelectionDeleteable, isSpellCheckable, isStyle, isVisible, keyChar, keyControl, keyDown, keyRepeat, keyStatus, keyUp, makeContextMenu, makeContextMenu, moveFocus, moveFocus, onDisplay, onExposed, onMenuDismissed, onMenuDismissed, onObscured, onUndisplay, onVisibilityChange, paintBackground, paste, select, selectionCopy, selectionCut, selectionDelete, setBackground, setBackground, setBorder, setBorder, setBorder, setBorder, setBorder, setChangeListener, setCookie, setDirty, setEditable, setExtent, setFocus, setFocusListener, setFont, setFont, setMargin, setMargin, setMuddy, setNonSpellCheckable, setPadding, setPadding, setPosition, setVisualState, trackwheelClick, trackwheelUnclick, updateLayout
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IMAGE_ALIGN_LEFT

public static final int IMAGE_ALIGN_LEFT
See Also:
Constant Field Values

IMAGE_ALIGN_RIGHT

public static final int IMAGE_ALIGN_RIGHT
See Also:
Constant Field Values

IMAGE_ALIGN_CENTER

public static final int IMAGE_ALIGN_CENTER
See Also:
Constant Field Values

BUTTON_TOP_BOTTOM_CUSHION

public static final int BUTTON_TOP_BOTTOM_CUSHION
See Also:
Constant Field Values

_image

protected net.rim.device.api.system.Bitmap _image
Encourage to use the _eImage, keep this field only for compatible with the interface


_eImage

protected net.rim.device.api.system.EncodedImage _eImage

_imageAlignment

protected int _imageAlignment

_unfocusFontStyle

protected FontStyle _unfocusFontStyle

_focusFontStyle

protected FontStyle _focusFontStyle

_appLogger

protected AppLoggerWrapper _appLogger

_cushion

protected int _cushion

_customEventsHandler

protected CustomEventsHandler _customEventsHandler

_controlID

protected int _controlID

_orientation

protected int _orientation
Constructor Detail

Button

public Button(long style)
Constructor to create a button control

Parameters:
style - long value for the style of the label control Can be Field.FIELD_LEFT, Field.FIELD_RIGHT, Field.FIELD_HCENTER, etc.
See Also:
net.rim.device.api.ui.Field.FIELD_LEFT, net.rim.device.api.ui.Field.FIELD_RIGHT, net.rim.device.api.ui.Field.FIELD_HCENTER

Button

public Button(long style,
              boolean isFocusable)
Method Detail

setBackgroundColor

public void setBackgroundColor(int bgcolor)
(non-Javadoc)

Specified by:
setBackgroundColor in interface Control
Parameters:
bgcolor - int value of the color in HEX. For example: 0x00000000, 0x00FF0000, 0x00FFFFFF
See Also:
Control.setBackgroundColor(int bgcolor)

setColSpan

public void setColSpan(int colspan)
(non-Javadoc)

Specified by:
setColSpan in interface Control
Parameters:
colspan - int value of the column span
See Also:
Control.setColSpan(int colspan)

getColSpan

public int getColSpan()
(non-Javadoc)

Specified by:
getColSpan in interface Control
Returns:
int value of the column span
See Also:
Control.getColSpan()

setRowSpan

public void setRowSpan(int rowspan)
(non-Javadoc)

Specified by:
setRowSpan in interface Control
Parameters:
rowspan - int value of the row span
See Also:
Control.setRowSpan(int rowspan)

getRowSpan

public int getRowSpan()
(non-Javadoc)

Specified by:
getRowSpan in interface Control
Returns:
int value of the row span
See Also:
Control.getRowSpan()

getHorizontalAlignment

public long getHorizontalAlignment()
(non-Javadoc)

Specified by:
getHorizontalAlignment in interface Control
Returns:
long value of the horizontal alignment. Possible values could be Field.FIELD_HCENTER, Field.FIELD_RIGHT, or Field.FIELD_LEFT
See Also:
Control.getHorizontalAlignment()

getVerticalAlignment

public long getVerticalAlignment()
(non-Javadoc)

Specified by:
getVerticalAlignment in interface Control
Returns:
long value of the vertical alignment Possible values could be Field.FIELD_TOP, Field.FIELD_BOTTOM, or Field.FIELD_VCENTER
See Also:
Control.getVerticalAlignment()

setVariableLabel

public void setVariableLabel(ControlVariable variable)
Set the variable for the label

Parameters:
variable - ControlVariable object
See Also:
ControlVariable

getUnfocusFontStyle

public FontStyle getUnfocusFontStyle()
Retrieve this unfocus font style

Returns:
FontStyle object
See Also:
FontStyle

setUnfocusFontStyle

public void setUnfocusFontStyle(FontStyle fontStyle)
Set the unfocus font style for this control

Parameters:
fontStyle - FontStyle font style object
See Also:
FontStyle

getFocusFontStyle

public FontStyle getFocusFontStyle()
Retrieve this focus font style

Returns:
FontStyle font style object
See Also:
FontStyle

setFocusFontStyle

public void setFocusFontStyle(FontStyle fontStyle)
Set the focus font style for this control

Parameters:
fontStyle - FontStyle font style object
See Also:
FontStyle

onFocus

protected void onFocus(int direction)
(non-Javadoc)

Overrides:
onFocus in class net.rim.device.api.ui.Field
See Also:
Field.onFocus(int direction)

onUnfocus

protected void onUnfocus()
(non-Javadoc)

Overrides:
onUnfocus in class net.rim.device.api.ui.Field
See Also:
Field.onUnfocus()

navigationClick

protected boolean navigationClick(int status,
                                  int time)
(non-Javadoc)

Overrides:
navigationClick in class net.rim.device.api.ui.Field
See Also:
Field.navigationClick(int status, int time)

navigationUnclick

protected boolean navigationUnclick(int status,
                                    int time)
(non-Javadoc)

Overrides:
navigationUnclick in class net.rim.device.api.ui.Field
See Also:
Field.navigationUnclick(int status, int time)

navigationMovement

protected boolean navigationMovement(int dx,
                                     int dy,
                                     int status,
                                     int time)
(non-Javadoc)

Overrides:
navigationMovement in class net.rim.device.api.ui.Field
See Also:
Field.navigationMovement(int dx, int dy, int status, int time)

touchEvent

protected boolean touchEvent(net.rim.device.api.ui.TouchEvent message)
(non-Javadoc)

Overrides:
touchEvent in class net.rim.device.api.ui.Field
See Also:
Field.touchEvent(TouchEvent message)

drawFocus

protected void drawFocus(net.rim.device.api.ui.Graphics g,
                         boolean on)
(non-Javadoc)

Overrides:
drawFocus in class net.rim.device.api.ui.Field
See Also:
Field.drawFocus(Graphics g, boolean on)

getAction

public IBOBAction getAction()
Retrieve the action assigned to this button

Returns:
IBOBAction action object
See Also:
IBOBAction

setAction

public void setAction(IBOBAction action)
Set the action assigned to this button

Parameters:
action - IBOBAction action to be perform when the button is clicked on
See Also:
IBOBAction

runAction

public void runAction()
Run the action assigned to this button


setLabel

public void setLabel(java.lang.String label)
Set the label for this button

Parameters:
label - String value for this label

setLabel

public void setLabel(int labelRID)
Set the label for this button by localization resource id

Parameters:
labelRID - localization resource ID for the label to be displayed on the button

setImage

public void setImage(java.lang.String image)
Add image to the button

Parameters:
image - String value for the file name of the image

setImage

public void setImage(java.lang.String image,
                     int alignment)
Add image to the button

Parameters:
image - String for the file name of the image
alignment - int value for the alignment of the button. Can be IMAGE_ALIGN_LEFT (image will be to the left of the text if any), IMAGE_ALIGN_RIGHT (image will be to the right of the text if any), or IMAGE_ALIGN_CENTER (image will be to the center and there shouldn't be text otherwise it will paint over the text)
See Also:
Button.IMAGE_ALIGN_LEFT, Button.IMAGE_ALIGN_RIGHT, Button.IMAGE_ALIGN_CENTER

setImage

public void setImage(net.rim.device.api.system.Bitmap image)
Add image to the button

Parameters:
image - Bitmap of the image
See Also:
Bitmap

setImage

public void setImage(net.rim.device.api.system.Bitmap image,
                     int alignment)
Add image to the button

Parameters:
image - Bitmap of the image
alignment - int value for the alignment. Can be IMAGE_ALIGN_LEFT (image will be to the left of the text if any), IMAGE_ALIGN_RIGHT (image will be to the right of the text if any), or IMAGE_ALIGN_CENTER (image will be to the center and there shouldn't be text otherwise it will paint over the text)
See Also:
Bitmap, Button.IMAGE_ALIGN_LEFT, Button.IMAGE_ALIGN_RIGHT, Button.IMAGE_ALIGN_CENTER

setImageAlignment

public void setImageAlignment(int alignment)
Set the image alignment

Parameters:
alignment - int value for the alignment. Can be IMAGE_ALIGN_LEFT (image will be to the left of the text if any), IMAGE_ALIGN_RIGHT (image will be to the right of the text if any), or IMAGE_ALIGN_CENTER (image will be to the center and there shouldn't be text otherwise it will paint over the text)
See Also:
Bitmap, Button.IMAGE_ALIGN_LEFT, Button.IMAGE_ALIGN_RIGHT, Button.IMAGE_ALIGN_CENTER

setBorderColor

public void setBorderColor(int color)
Set the border color

Parameters:
color - int HEX value for the border color. Examples of colors are 0x00FFFFFF, 0x00FF0000, 0x00000000

getBorderColor

public int getBorderColor()
Retrieve the border color

Returns:
int HEX value for the border scolor

getValue

public java.lang.Object getValue()
(non-Javadoc)

Specified by:
getValue in interface Control
Returns:
Object of the value set for this control
See Also:
Control.getValue()

getName

public java.lang.String getName()
(non-Javadoc)

Specified by:
getName in interface Control
Returns:
String value of the key name
See Also:
Control.getName()

setLayoutWidth

public void setLayoutWidth(int width)
(non-Javadoc)

Specified by:
setLayoutWidth in interface Control
Parameters:
width - int value of the available layout width
See Also:
Control.setLayoutWidth(int width)

setLayoutHeight

public void setLayoutHeight(int height)
(non-Javadoc)

Specified by:
setLayoutHeight in interface Control
Parameters:
height - int value of the available layout height
See Also:
Control.setLayoutHeight(int height)

setProperty

public void setProperty(int key,
                        IBOBAction action)
Set the property action for this button

Parameters:
key - int key of a specific button attribute
action - IBOBAction action object
See Also:
IBOBAction

setProperty

public void setProperty(int key,
                        net.rim.device.api.system.Bitmap image)
Set the property action for this button

Parameters:
key - int int value for the key of a specific attribute
image - Bitmap image for this button

setProperty

public void setProperty(int key,
                        java.lang.String value)
Set the property values for this button

Parameters:
key - int value for the key pertaining to a specific attribute of this control
value - String value for this attribute

getButtonWidth

public int getButtonWidth()
Retrieve button width based on the label and image

Returns:
int value for the width of the button

getPreferredWidth

public int getPreferredWidth()
(non-Javadoc)

Specified by:
getPreferredWidth in interface Control
Overrides:
getPreferredWidth in class net.rim.device.api.ui.Field
Returns:
int value of the available layout width
See Also:
Control.getPreferredWidth()

getPreferredHeight

public int getPreferredHeight()
(non-Javadoc)

Specified by:
getPreferredHeight in interface Control
Overrides:
getPreferredHeight in class net.rim.device.api.ui.Field
Returns:
int value of the available layout height
See Also:
Control.getPreferredHeight()

layout

protected void layout(int width,
                      int height)
(non-Javadoc)

Specified by:
layout in class net.rim.device.api.ui.Field
See Also:
Field.layout(int width, int height)

paint

protected void paint(net.rim.device.api.ui.Graphics g)
(non-Javadoc)

Specified by:
paint in class net.rim.device.api.ui.Field
See Also:
Field.paint(Graphics g)

drawButton

protected void drawButton(net.rim.device.api.ui.Graphics g,
                          boolean isFocus)
Draws this button.

Parameters:
graphics - Graphics object context for repainting this field.
isFocus - true if the button is focused, otherwise false
See Also:
net.rim.device.api.ui.Graphicss

drawGradient

protected void drawGradient(net.rim.device.api.ui.Graphics g,
                            FontStyle buttonFontStyle,
                            int height,
                            int width)

drawBorder

protected void drawBorder(net.rim.device.api.ui.Graphics g,
                          FontStyle buttonFontStyle)

refresh

public void refresh()
(non-Javadoc)

Specified by:
refresh in interface Control
See Also:
Control.refresh()

refreshFooter

public void refreshFooter(java.lang.String valueToBeDisplay)
Refresh the footer field from the screen that contains the text of the button.

Parameters:
valueToBeDisplay - String value for the text displayed in the footer

setFooterField

public void setFooterField(FooterField field)
Set the footer field

Parameters:
{@link - FooterField} footer field to put the text of the textinput into. This is useful for long text, so it can be displayed in the footer. null value if there is no footer.
See Also:
FooterField

toString

public java.lang.String toString()
Return the label of the button

Overrides:
toString in class java.lang.Object
Returns:
String value for the button labels

getCustomEventsDelegate

public ICustomEventsDelegate getCustomEventsDelegate()
Returns the control's custom events delegate

Returns:
the control's custom events delegate

setCustomEventsDelegate

public void setCustomEventsDelegate(ICustomEventsDelegate delegate,
                                    int eventsFlags)
Sets the control's custom events delegate for the given events

Parameters:
delegate - custom events delegate
eventsFlags - the events to set delegate to

getControlID

public int getControlID()
Returns the control's ID

Returns:
the control's Id

setControlID

public void setControlID(int controlID)
Sets the control's ID

Parameters:
controlId - control ID