de.enough.polish.ui
Class TabbedForm

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Canvas
          extended by de.enough.polish.ui.Screen
              extended by de.enough.polish.ui.Form
                  extended by de.enough.polish.ui.TabbedForm
All Implemented Interfaces:
AccessibleCanvas

public class TabbedForm
extends Form

Separates a form into several tabs.

Copyright (c) Enough Software 2005 - 2008

 history
        23-Jan-2005 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de, Craig Newton for dynamic adding and removing of tabs

Field Summary
 
Fields inherited from class de.enough.polish.ui.Screen
background, border, container, contentHeight, contentWidth, contentX, contentY, cssSelector, fullScreenHeight, ignoreRepaintRequests, infoHeight, isInitRequested, isRepaintRequested, isScrollBackground, isSetFullScreenCalled, itemStateListener, keyPressedProcessed, keyReleasedProcessed, lastInteractionTime, lastTriggeredCommand, menuBarHeight, originalScreenHeight, paintScrollBarOnRightSide, screenHeight, screenOrientationDegrees, screenStateListener, screenWidth, scrollBar, scrollBarVisible, style, subTitleHeight, title, titleHeight, triggerReleasedKeyCode, triggerReleasedTime
 
Fields inherited from class javax.microedition.lcdui.Canvas
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP
 
Constructor Summary
TabbedForm(java.lang.String title, java.lang.String[] tabNames, javax.microedition.lcdui.Image[] tabImages)
          Creates a new tabbed form without a style.
TabbedForm(java.lang.String title, java.lang.String[] tabNames, javax.microedition.lcdui.Image[] tabImages, Style style)
          Creates a new tabbed form.
 
Method Summary
 void addNewTab(int index, java.lang.String tabName, javax.microedition.lcdui.Image tabImage)
          Adds a new tab with a container to the TabbedForm.
 void addNewTab(int index, java.lang.String tabName, javax.microedition.lcdui.Image tabImage, Style tabStyle)
          Adds a new tab with a container to the TabbedForm.
 int addNewTab(java.lang.String tabName, javax.microedition.lcdui.Image tabImage)
          Adds a new tab with a container to the TabbedForm.
 int addNewTab(java.lang.String tabName, javax.microedition.lcdui.Image tabImage, Style tabStyle)
          Adds a new tab with a container to the TabbedForm.
 void append(int tabIndex, javax.microedition.lcdui.Item item)
          Adds the item to this form.
 int append(int tabIndex, Item item)
          Adds the item to this form.
 int append(int tabIndex, Item item, Style itemStyle)
          Adds the item to this form.
 int append(Item item, Style itemStyle)
          Adds the item to the first tab of this form.
protected  java.lang.String createCssSelector()
          Retrieves the CSS selector for this screen.
 void delete(int tabIndex, int itemIndex)
          Deletes the item from this form.
 void delete(int tabIndex, javax.microedition.lcdui.Item item)
          Deletes the item from this form.
 void delete(int tabIndex, Item item)
          Deletes the item from this form.
 void deleteAll(int tabIndex)
          Deletes the all items from the specified tab.
 void focus(Item item)
          Focuses the specified item.
 javax.microedition.lcdui.Item get(int tabIndex, int itemNum)
          Gets the item at given position within the specified tab.
 int getActiveTab()
          Retrieves the index of the currently active tab.
 Item getCurrentItem()
          Retrieves the currently focused item.
 int getSelectedTab()
          Deprecated.  
 int getTabCount()
          Retrieves the number of tabs in this TabbedForm.
 Item getTabItem(int tabIndex)
          Retrieves the item that renders the tab
protected  boolean handleKeyPressed(int keyCode, int gameAction)
          Handles the key-pressed event.
 void insert(int tabIndex, int itemNum, javax.microedition.lcdui.Item item)
          Inserts an item into this form just prior to the item specified on the specified tab.
 void insert(int tabIndex, int itemNum, Item item)
          Inserts an item into this form just prior to the item specified on the specified tab.
 void insert(int tabIndex, int itemNum, javax.microedition.lcdui.Item item, Style itemStyle)
          Inserts an item into this form just prior to the item specified on the specified tab.
 void insert(int tabIndex, int itemNum, Item item, Style itemStyle)
          Inserts an item into this form just prior to the item specified on the specified tab.
 void notifyTabbedChangeCompleted(int oldTabIndex, int newTabIndex)
          Notifies the TabbedFormListener that a tab change is completed.
 boolean notifyTabbedChangeRequested(int oldTabIndex, int newTabIndex)
          Notifies the TabbedFormListener that a tab change was requested.
 void removeTab(int index)
          Removes a tab and its container from the TabbedForm.
 void set(int tabIndex, int itemIndex, javax.microedition.lcdui.Item item)
          Changes the item of a tab.
 void set(int tabIndex, int itemIndex, Item item)
          Changes the item of a tab.
 void set(int itemIndex, Item item)
          Changes the item of the first tab.
 void setActiveTab(int tabIndex)
          Focuses the specified tab.
 void setActiveTab(int tabIndex, boolean focusTabBar)
          Focuses the specified tab.
 void setStyle(Style style)
          Sets the style of this screen.
 void setTabbedFormListener(TabbedFormListener listener)
          Sets the TabbedFormListener to be notified when tab changes happen.
 void setTabImage(int tabIndex, javax.microedition.lcdui.Image image)
          Sets the image for the specified tab.
 void setTabItem(int tabIndex, Item item)
          Sets the item that renders the specified tab
 void setTabItem(int tabIndex, javax.microedition.lcdui.Item item)
          Sets the item that renders the specified tab
 void setText(int tabIndex, java.lang.String text)
          Sets the text for the specified tab.
 int size(int tabIndex)
          Retrieves the number of elements within the specified tab.
 void sizeChanged(int width, int height)
           
 
Methods inherited from class de.enough.polish.ui.Form
append, append, append, append, append, append, delete, deleteAll, get, insert, insert, set, size
 
Methods inherited from class de.enough.polish.ui.Screen
addCommand, addCommand, addSubCommand, addSubCommand, animate, animate, calculateContentArea, callCommandListener, checkForRequestInit, closeMenu, commandAction, focus, focus, focus, focus, getAvailableHeight, getCommandItem, getCommandListener, getCurrentIndex, getGameAction, getItemAt, getMenuBar, getPolishTicker, getRootItems, getScreenContentHeight, getScreenContentWidth, getScreenData, getScreenFullHeight, getScreenFullWidth, getScreenHeight, getScreenStyle, getScrollBarWidth, getScrollYOffset, getTitle, handleCommand, handleKeyReleased, handleKeyRepeated, handlePointerPressed, handlePointerReleased, hideNotify, isGameActionFire, isKeyboardAccessible, isMenuOpened, isShown, isSoftKey, isSoftKey, isSoftKeyLeft, isSoftKeyMiddle, isSoftKeyRight, keyPressed, keyReleased, keyRepeated, notifyScreenStateChanged, notifyStateListener, paint, paintScreen, pointerDragged, pointerPressed, pointerReleased, releaseResources, removeAllCommands, removeCommand, removeItemCommands, requestInit, requestRepaint, requestRepaint, scrollRelative, setCommandListener, setFullScreenMode, setInfo, setItemCommands, setItemStateListener, setItemStateListener, setMenuBarStyle, setMenuItemStyle, setPolishTicker, setPolishTicker, setScreenData, setScreenOrientation, setScreenStateListener, setScrollYOffset, setSubTitle, setTitle, setTitle, setTitle, showNotify
 
Methods inherited from class javax.microedition.lcdui.Canvas
getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, isDoubleBuffered, repaint, repaint, serviceRepaints
 
Methods inherited from class javax.microedition.lcdui.Displayable
getHeight, getTicker, getWidth, setTicker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TabbedForm

public TabbedForm(java.lang.String title,
                  java.lang.String[] tabNames,
                  javax.microedition.lcdui.Image[] tabImages)
Creates a new tabbed form without a style.

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

TabbedForm

public TabbedForm(java.lang.String title,
                  java.lang.String[] tabNames,
                  javax.microedition.lcdui.Image[] tabImages,
                  Style style)
Creates a new tabbed form.

Parameters:
title - the title of the form.
tabNames - the names of the tabs
tabImages - the images of the tabs, can be null
style - the style of this tabbed form.
Throws:
java.lang.NullPointerException - if tabNames is null
Method Detail

append

public void append(int tabIndex,
                   javax.microedition.lcdui.Item item)
Adds the item to this form.

Parameters:
tabIndex - the index of the tab to which the item should be added, the first tab has the index 0.
item - the item which should be added.

set

public void set(int tabIndex,
                int itemIndex,
                javax.microedition.lcdui.Item item)
Changes the item of a tab.

Parameters:
tabIndex - the index of the tab, the first tab has the index 0.
itemIndex - the index of the item in the tab
item - the item which should be added.

delete

public void delete(int tabIndex,
                   javax.microedition.lcdui.Item item)
Deletes the item from this form.

Parameters:
tabIndex - the index of the tab from which the item should be removed, the first tab has the index 0.
item - the item which should be removed.

append

public int append(Item item,
                  Style itemStyle)
Adds the item to the first tab of this form.

Overrides:
append in class Form
Parameters:
item - the item which should be added.
itemStyle - the style for that item
Returns:
the assigned index of the Item within the specified tab

append

public int append(int tabIndex,
                  Item item)
Adds the item to this form.

Parameters:
tabIndex - the index of the tab to which the item should be added, the first tab has the index 0.
item - the item which should be added.
Returns:
the assigned index of the Item within the specified tab

append

public int append(int tabIndex,
                  Item item,
                  Style itemStyle)
Adds the item to this form.

Parameters:
tabIndex - the index of the tab to which the item should be added, the first tab has the index 0.
item - the item which should be added.
itemStyle - the style for that item
Returns:
the assigned index of the Item within the specified tab

insert

public void insert(int tabIndex,
                   int itemNum,
                   javax.microedition.lcdui.Item item)
Inserts an item into this form just prior to the item specified on the specified tab.

Parameters:
tabIndex - the index of the tab to which the item should be added, the first tab has the index 0.
itemNum - the index where insertion is to occur
item - the item to be inserted

insert

public void insert(int tabIndex,
                   int itemNum,
                   Item item)
Inserts an item into this form just prior to the item specified on the specified tab.

Parameters:
tabIndex - the index of the tab to which the item should be added, the first tab has the index 0.
itemNum - the index where insertion is to occur
item - the item to be inserted

insert

public void insert(int tabIndex,
                   int itemNum,
                   javax.microedition.lcdui.Item item,
                   Style itemStyle)
Inserts an item into this form just prior to the item specified on the specified tab.

Parameters:
tabIndex - the index of the tab to which the item should be added, the first tab has the index 0.
itemNum - the index where insertion is to occur
item - the item to be inserted
itemStyle - the style of the item

insert

public void insert(int tabIndex,
                   int itemNum,
                   Item item,
                   Style itemStyle)
Inserts an item into this form just prior to the item specified on the specified tab.

Parameters:
tabIndex - the index of the tab to which the item should be added, the first tab has the index 0.
itemNum - the index where insertion is to occur
item - the item to be inserted
itemStyle - the style of the item

set

public void set(int itemIndex,
                Item item)
Changes the item of the first tab.

Overrides:
set in class Form
Parameters:
itemIndex - the index of the item in the tab
item - the item which should be added.

set

public void set(int tabIndex,
                int itemIndex,
                Item item)
Changes the item of a tab.

Parameters:
tabIndex - the index of the tab, the first tab has the index 0.
itemIndex - the index of the item in the tab
item - the item which should be added.

get

public javax.microedition.lcdui.Item get(int tabIndex,
                                         int itemNum)
Gets the item at given position within the specified tab. The contents of the TabbedForm are left unchanged. The itemNum parameter must be within the range [0..size()-1], inclusive.

Parameters:
tabIndex - the index of the tab, the first tab has the index 0.
itemNum - the index of item
Returns:
the item at the given position
Throws:
java.lang.IndexOutOfBoundsException - - if itemNum is invalid

delete

public void delete(int tabIndex,
                   Item item)
Deletes the item from this form.

Parameters:
tabIndex - the index of the tab from which the item should be removed, the first tab has the index 0.
item - the item which should be removed.

delete

public void delete(int tabIndex,
                   int itemIndex)
Deletes the item from this form.

Parameters:
tabIndex - the index of the tab from which the item should be removed, the first tab has the index 0.
itemIndex - the index of the item which should be removed.

deleteAll

public void deleteAll(int tabIndex)
Deletes the all items from the specified tab.

Parameters:
tabIndex - the index of the tab from which all items should be removed, the first tab has the index 0.

size

public int size(int tabIndex)
Retrieves the number of elements within the specified tab.

Parameters:
tabIndex - the tab, the first tab has the index 0
Returns:
the number of elements within that tab

getTabCount

public int getTabCount()
Retrieves the number of tabs in this TabbedForm.

Returns:
the number of tabs

setActiveTab

public void setActiveTab(int tabIndex)
Focuses the specified tab.

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

setActiveTab

public void setActiveTab(int tabIndex,
                         boolean focusTabBar)
Focuses the specified tab.

Parameters:
tabIndex - the index of the tab, the first tab has the index 0.
focusTabBar - true when the tabbar should be focused - this only has an effect when polish.TabbedForm.allowTabSelection is set to true

setTabImage

public void setTabImage(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

createCssSelector

protected java.lang.String createCssSelector()
Description copied from class: Screen
Retrieves the CSS selector for this screen. The CSS selector is used for the dynamic assignment of styles - that is the styles are assigned by the usage of the screen and not by a predefined style-name. With the #style preprocessing command styles are set in a static way, 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 screen is needed. This abstract method needs only be implemented, when dynamic styles are used: #ifdef polish.useDynamicStyles

Overrides:
createCssSelector in class Form
Returns:
the name of the appropriate CSS Selector for this screen.

handleKeyPressed

protected boolean handleKeyPressed(int keyCode,
                                   int gameAction)
Description copied from class: Screen
Handles the key-pressed event. Please note, that implementation should first try to handle the given key-code, before the game-action is processed.

Overrides:
handleKeyPressed in class Screen
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-event was processed

focus

public void focus(Item item)
Description copied from class: Screen
Focuses the specified item.

Overrides:
focus in class Screen
Parameters:
item - the item which is already shown on this screen.

getSelectedTab

public int getSelectedTab()
Deprecated. 

Retrieves the index of the currently active tab.

Returns:
the index of the currently active tab, 0 is the first tab.
See Also:
getActiveTab()

getActiveTab

public int getActiveTab()
Retrieves the index of the currently active tab.

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

notifyTabbedChangeRequested

public boolean notifyTabbedChangeRequested(int oldTabIndex,
                                           int newTabIndex)
Notifies the TabbedFormListener that a tab change was requested. Then TabbedFormListener can now allow or disallow the tab change.

Parameters:
oldTabIndex - the index of the old tab
newTabIndex - the index of the new tab
Returns:
true if a tab change is okay, false otherwise

notifyTabbedChangeCompleted

public void notifyTabbedChangeCompleted(int oldTabIndex,
                                        int newTabIndex)
Notifies the TabbedFormListener that a tab change is completed.

Parameters:
oldTabIndex - the index of the old tab
newTabIndex - the index of the new tab

setTabbedFormListener

public void setTabbedFormListener(TabbedFormListener listener)
Sets the TabbedFormListener to be notified when tab changes happen.

Parameters:
listener - the listener that is notified whenever the user selects another tab,

getCurrentItem

public Item getCurrentItem()
Description copied from class: Screen
Retrieves the currently focused item.

Overrides:
getCurrentItem in class Screen
Returns:
the currently focused item, null when none is focused.

sizeChanged

public void sizeChanged(int width,
                        int height)
Specified by:
sizeChanged in interface AccessibleCanvas
Overrides:
sizeChanged in class Screen

setStyle

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

Overrides:
setStyle in class Screen
Parameters:
style - the style

addNewTab

public int addNewTab(java.lang.String tabName,
                     javax.microedition.lcdui.Image tabImage)
Adds a new tab with a container to the TabbedForm.

Parameters:
tabName - The name of the new tab
tabImage - The optional image
Returns:
The index of the new tab

addNewTab

public int addNewTab(java.lang.String tabName,
                     javax.microedition.lcdui.Image tabImage,
                     Style tabStyle)
Adds a new tab with a container to the TabbedForm. This method also assigns a style or uses the default if style is set to null.

Parameters:
tabName - The name of the new tab
tabImage - The optional image
tabStyle - The initial style of the tab
Returns:
The index of the new tab

addNewTab

public void addNewTab(int index,
                      java.lang.String tabName,
                      javax.microedition.lcdui.Image tabImage)
Adds a new tab with a container to the TabbedForm.

Parameters:
index - the index at which the tab should be added. 0 adds the tab at the beginning.
tabName - The name of the new tab
tabImage - The optional image

addNewTab

public void addNewTab(int index,
                      java.lang.String tabName,
                      javax.microedition.lcdui.Image tabImage,
                      Style tabStyle)
Adds a new tab with a container to the TabbedForm. This method also assigns a style or uses the default if style is set to null.

Parameters:
tabName - The name of the new tab
tabImage - The optional image
tabStyle - The initial style of the tab

removeTab

public void removeTab(int index)
Removes a tab and its container from the TabbedForm.

Parameters:
index - The tab at the index to remove

getTabItem

public Item getTabItem(int tabIndex)
Retrieves the item that renders the tab

Parameters:
tabIndex - the tab position
Returns:
the tab item

setTabItem

public void setTabItem(int tabIndex,
                       Item item)
Sets the item that renders the specified tab

Parameters:
tabIndex - the tab position
item - the tab item

setTabItem

public void setTabItem(int tabIndex,
                       javax.microedition.lcdui.Item item)
Sets the item that renders the specified tab

Parameters:
tabIndex - the tab position
item - the tab item