de.enough.polish.ui
Class TabBar

java.lang.Object
  extended by de.enough.polish.ui.Item
      extended by de.enough.polish.ui.TabBar

public class TabBar
extends Item

Manages and paints the tabs of a tabbed form (or another Screen).

Copyright (c) Enough Software 2005 - 2008

 history
        23-Jan-2005 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
protected  boolean handlePointerReleaseEvent
           
 
Fields inherited from class de.enough.polish.ui.Item
_bbField, _bbFieldAdded, appearanceMode, background, backgroundHeight, backgroundWidth, backgroundYOffset, border, borderWidth, BUTTON, colSpan, commands, completeBackground, completeBackgroundPadding, completeBorder, contentHeight, contentWidth, contentX, contentY, cssSelector, defaultCommand, focusedStyle, HORIZONTAL, HYPERLINK, includeLabel, INTERACTIVE, internalHeight, internalWidth, internalX, internalY, isFocused, isInitialized, isInvisible, isLayoutCenter, isLayoutExpand, isLayoutRight, isPressed, isShown, isStyleInitialised, itemCommandListener, itemHeight, itemWidth, label, labelStyle, layout, LAYOUT_2, LAYOUT_BOTTOM, LAYOUT_CENTER, LAYOUT_DEFAULT, LAYOUT_EXPAND, LAYOUT_LEFT, LAYOUT_NEWLINE_AFTER, LAYOUT_NEWLINE_BEFORE, LAYOUT_RIGHT, LAYOUT_SHRINK, LAYOUT_TOP, LAYOUT_VCENTER, LAYOUT_VEXPAND, LAYOUT_VSHRINK, marginBottom, marginLeft, marginRight, marginTop, maximumHeight, maximumWidth, minimumHeight, minimumWidth, NO_POSITION_SET, opacity, opacityPaintNormally, opacityRgbData, paddingBottom, paddingHorizontal, paddingLeft, paddingRight, paddingTop, paddingVertical, parent, PLAIN, preferredHeight, preferredWidth, preserveViewType, relativeX, relativeY, rowSpan, screen, style, TRANSPARENT, useSingleRow, VERTICAL, view
 
Constructor Summary
TabBar(java.lang.String[] tabNames, javax.microedition.lcdui.Image[] tabImages)
          Creates a new tab bar.
TabBar(java.lang.String[] tabNames, javax.microedition.lcdui.Image[] tabImages, Style style)
          Creates a new tab bar.
 
Method Summary
 void addNewTab(int index, java.lang.String tabName, javax.microedition.lcdui.Image tabImage)
          Creates a new tab on the tab bar.
 void addNewTab(int index, java.lang.String tabName, javax.microedition.lcdui.Image tabImage, Style tabStyle)
          Creates a new tab on the tab bar.
 void addNewTab(java.lang.String tabName, javax.microedition.lcdui.Image tabImage)
          Creates a new tab on the tab bar.
 void addNewTab(java.lang.String tabName, javax.microedition.lcdui.Image tabImage, Style tabStyle)
          Creates a new tab on the tab bar.
protected  java.lang.String createCssSelector()
          Retrieves the CSS selector for this item.
protected  void defocus(Style originalStyle)
          Removes the focus from this item.
protected  Style focus(Style newStyle, int direction)
          Focuses this item.
 int getNextTab()
          Retrieves the index of the currently selected tab.
 Item getTabItem(int tabIndex)
          Retrieves a tab item
protected  boolean handleKeyPressed(int keyCode, int gameAction)
          Handles the key-pressed event.
protected  boolean handlePointerPressed(int x, int y)
          Handles the event when a pointer has been pressed at the specified position.
protected  boolean handlePointerReleased(int x, int y)
          Handles the event when a pointer has been released at the specified position.
protected  void initContent(int firstLineWidth, int lineWidth)
          Initialises this item.
protected  void paintContent(int x, int y, int leftBorder, int rightBorder, javax.microedition.lcdui.Graphics g)
          Paints the content of this item.
 void removeTab(int index)
          Removes a tab from the tab bar.
 void setActiveTab(int index)
          Changes the active/selected tab.
 void setImage(int tabIndex, javax.microedition.lcdui.Image image)
          Sets the image for the specified tab.
 void setStyle(Style style)
          Sets the style of this item.
 void setTabItem(int tabIndex, Item item)
          Sets a tab item
 void setText(int tabIndex, java.lang.String text)
          Sets the text for the specified tab.
 
Methods inherited from class de.enough.polish.ui.Item
addCommand, addCommand, addCommands, addRelativeToBackgroundRegion, addRelativeToBackgroundRegion, addRelativeToContentRegion, animate, animate, containsCommand, getAbsoluteX, getAbsoluteY, getAppearanceMode, getAttribute, getAttributes, getBackgroundHeight, getBackgroundWidth, getBackgroundX, getBackgroundY, getContentHeight, getContentWidth, getContentX, getContentY, getDefaultCommand, getFocusedStyle, getItemAt, getItemCommandListener, getItemCommands, getItemHeight, getItemStateListener, getItemWidth, getLabel, getLabelItem, getLayout, getMinimumHeight, getMinimumWidth, getParent, getPreferredHeight, getPreferredWidth, getScreen, getStyle, handleCommand, handleKeyReleased, handleKeyRepeated, hideNotify, init, initStyle, isInContentArea, isInItemArea, isInItemArea, isInitialized, isVisible, notifyItemPressedEnd, notifyItemPressedStart, notifyStateChanged, paint, paintBackground, paintBackgroundAndBorder, paintBorder, releaseResources, removeCommand, repaint, repaint, repaintFully, requestInit, setAppearanceMode, setAttribute, setDefaultCommand, setItemCommandListener, setItemCommandListener, setItemStateListener, setLabel, setLayout, setParent, setParent, setPreferredSize, setVisible, show, showCommands, showNotify, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

handlePointerReleaseEvent

protected boolean handlePointerReleaseEvent
Constructor Detail

TabBar

public TabBar(java.lang.String[] tabNames,
              javax.microedition.lcdui.Image[] tabImages)
Creates a new tab bar.

Parameters:
tabNames - the names of the tabs
tabImages - the images of the tabs, can be null

TabBar

public TabBar(java.lang.String[] tabNames,
              javax.microedition.lcdui.Image[] tabImages,
              Style style)
Creates a new tab bar.

Parameters:
tabNames - the names of the tabs
tabImages - the images of the tabs, can be null
style - the style of the bar
Method Detail

setActiveTab

public void setActiveTab(int index)
Changes the active/selected tab.

Parameters:
index - the index of the active tab, the first tab has the index 0.

focus

protected Style focus(Style newStyle,
                      int direction)
Description copied from class: Item
Focuses this item.

Overrides:
focus in class Item
Parameters:
newStyle - the style which is used to indicate the focused state
direction - the direction from which this item is focused, either Canvas.UP, Canvas.DOWN, Canvas.LEFT, Canvas.RIGHT or 0. When 0 is given, the direction is unknown.
Returns:
the current style of this item

defocus

protected void defocus(Style originalStyle)
Description copied from class: Item
Removes the focus from this item.

Overrides:
defocus in class Item
Parameters:
originalStyle - the original style which will be restored.

initContent

protected void initContent(int firstLineWidth,
                           int lineWidth)
Description copied from class: Item
Initialises this item. The implementation needs to calculate and set the contentWidth and contentHeight fields. The implementation should take the fields preferredWidth and preferredHeight into account.

Specified by:
initContent in class Item
Parameters:
firstLineWidth - the maximum width of the first line
lineWidth - the maximum width of any following lines
See Also:
Item.contentWidth, Item.contentHeight, Item.preferredWidth, Item.preferredHeight

paintContent

protected void paintContent(int x,
                            int y,
                            int leftBorder,
                            int rightBorder,
                            javax.microedition.lcdui.Graphics g)
Description copied from class: Item
Paints the content of this item. The background has already been painted and the border will be added after this method returns.

Specified by:
paintContent in class Item
Parameters:
x - the left start position
y - the upper start position
leftBorder - the left border, nothing must be painted left of this position
rightBorder - the right border, nothing must be painted right of this position
g - the Graphics on which this item should be painted.

createCssSelector

protected java.lang.String createCssSelector()
Description copied from class: Item
Retrieves the CSS selector for this item. The CSS selector is used for the dynamic assignment of styles - that is the styles are assigned by the usage of the item and not by a predefined style-name. With the #style preprocessing command styles are set fix, this method yields in a faster GUI and is recommended. When in a style-sheet dynamic styles are used, e.g. "Form>p", than the selector of the item is needed.
This abstract method needs only be implemented, when dynamic styles are used: #ifdef polish.useDynamicStyles
The returned selector needs to be in lower case.

Specified by:
createCssSelector in class Item
Returns:
the appropriate CSS selector for this item. The selector needs to be in lower case.

setStyle

public void setStyle(Style style)
Description copied from class: Item
Sets the style of this item.

Overrides:
setStyle in class Item
Parameters:
style - the new style for this item.

handleKeyPressed

protected boolean handleKeyPressed(int keyCode,
                                   int gameAction)
Description copied from class: Item
Handles the key-pressed event. Please note, that implementation should first try to handle the given key-code, before the game-action is processed. The default implementation just handles the FIRE game-action when a default-command and an item-command-listener have been registered.

Overrides:
handleKeyPressed in class Item
Parameters:
keyCode - the code of the pressed key, e.g. Canvas.KEY_NUM2
gameAction - the corresponding game-action, e.g. Canvas.UP
Returns:
true when the key has been handled / recognized

handlePointerPressed

protected boolean handlePointerPressed(int x,
                                       int y)
Description copied from class: Item
Handles the event when a pointer has been pressed at the specified position. The default method discards this event when relX/relY is outside of the item's area. When the event took place inside of the content area, the pointer-event is translated into an artificial FIRE game-action keyPressed event, which is subsequently handled bu the handleKeyPressed(-1, Canvas.FIRE) method. This method needs should be overwritten only when the "polish.hasPointerEvents" preprocessing symbol is defined: "//#ifdef polish.hasPointerEvents".

Overrides:
handlePointerPressed in class Item
Parameters:
x - the x position of the pointer pressing relative to this item's left position
y - the y position of the pointer pressing relative to this item's top position
Returns:
true when the pressing of the pointer was actually handled by this item.
See Also:
this method is used for determining whether the event belongs to this item, for a helper method for determining whether the event took place into the actual content area, Item.handleKeyPressed(int, int), for calculating the horizontal position relative to the content (relX - contentX), for calculating the vertical position relative to the content (relY - contentY)

handlePointerReleased

protected boolean handlePointerReleased(int x,
                                        int y)
Description copied from class: Item
Handles the event when a pointer has been released at the specified position. The default method discards this event when relX/relY is outside of the item's area. When the event took place inside of the content area, the pointer-event is translated into an artificial FIRE game-action keyReleased event, which is subsequently handled bu the handleKeyPressed(-1, Canvas.FIRE) method. This method needs should be overwritten only when the "polish.hasPointerEvents" preprocessing symbol is defined: "//#ifdef polish.hasPointerEvents".

Overrides:
handlePointerReleased in class Item
Parameters:
x - the x position of the pointer pressing relative to this item's left position
y - the y position of the pointer pressing relative to this item's top position
Returns:
true when the pressing of the pointer was actually handled by this item.
See Also:
this method is used for determining whether the event belongs to this item, for a helper method for determining whether the event took place into the actual content area, Item.handleKeyPressed(int, int), for calculating the horizontal position relative to the content (relX - contentX), for calculating the vertical position relative to the content (relY - contentY)

setImage

public void setImage(int tabIndex,
                     javax.microedition.lcdui.Image image)
Sets the image for the specified tab.

Parameters:
tabIndex - the index of the tab
image - the image

setText

public void setText(int tabIndex,
                    java.lang.String text)
Sets the text for the specified tab.

Parameters:
tabIndex - the index of the tab
text - the text

getNextTab

public int getNextTab()
Retrieves the index of the currently selected tab.

Returns:
the index of the currently selected tab, 0 is the index of the first tab.

addNewTab

public void addNewTab(java.lang.String tabName,
                      javax.microedition.lcdui.Image tabImage)
Creates a new tab on the tab bar.

Parameters:
tabName - the name of the new tab
tabImage - the image of the new tab, can be null

addNewTab

public void addNewTab(java.lang.String tabName,
                      javax.microedition.lcdui.Image tabImage,
                      Style tabStyle)
Creates a new tab on the tab bar.

Parameters:
tabName - the name of the new tab
tabImage - the image of the new tab, can be null
tabStyle - the style of the tab

addNewTab

public void addNewTab(int index,
                      java.lang.String tabName,
                      javax.microedition.lcdui.Image tabImage)
Creates a new tab on the tab bar.

Parameters:
tabName - the name of the new tab
tabImage - the image of the new tab, can be null

addNewTab

public void addNewTab(int index,
                      java.lang.String tabName,
                      javax.microedition.lcdui.Image tabImage,
                      Style tabStyle)
Creates a new tab on the tab bar.

Parameters:
tabName - the name of the new tab
tabImage - the image of the new tab, can be null
tabStyle - the style of the tab

removeTab

public void removeTab(int index)
Removes a tab from the tab bar.

Parameters:
index - the index of the tab to remove

getTabItem

public Item getTabItem(int tabIndex)
Retrieves a tab item

Parameters:
tabIndex - the index of the tab item
Returns:
the tab item

setTabItem

public void setTabItem(int tabIndex,
                       Item item)
Sets a tab item

Parameters:
tabIndex - the index of the tab
item - the item