de.enough.polish.ui
Class TabbedList

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.TabbedList
All Implemented Interfaces:
AccessibleCanvas

public class TabbedList
extends Screen

Provides several lists in tabs.

Copyright Enough Software 2007 - 2008

 history
        Jun 27, 2007 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
static javax.microedition.lcdui.Command SELECT_COMMAND
           
 
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
TabbedList(java.lang.String title, int defaultListType)
           
TabbedList(java.lang.String title, int defaultListType, Style style)
           
 
Method Summary
 void animate(long currentTime, ClippingRegion repaintRegion)
          Animates this screen.
 int append(int tabIndex, java.lang.String stringPart, javax.microedition.lcdui.Image imagePart)
          Appends an element to the Choice.
 int append(int tabIndex, java.lang.String stringPart, javax.microedition.lcdui.Image imagePart, Style style)
          Appends an element to the Choice.
 int appendTab(javax.microedition.lcdui.Item item)
           
 int appendTab(Item item)
           
 int appendTab(Item item, int tabListType, Style style)
           
 int appendTab(Item item, Style style)
           
 int appendTab(java.lang.String text, javax.microedition.lcdui.Image icon)
           
 int appendTab(java.lang.String text, javax.microedition.lcdui.Image icon, Style style)
           
protected  void calculateContentArea(int x, int y, int width, int height)
          Calculates and sets the content area for this screen.
protected  java.lang.String createCssSelector()
          Retrieves the CSS selector for this screen.
 void delete(int tabIndex, int elementNum)
          Deletes the element referenced by elementNum.
 void deleteAll(int tabIndex)
          Deletes all elements from this Choice, leaving it with zero elements.
 void deleteTab(int tabIndex)
           
 int getCurrentTabIndex()
          Retrieves the index of the currently selected tab.
 javax.microedition.lcdui.Image getImage(int tabIndex, int elementNum)
          Gets the Image part of the element referenced by elementNum.
protected  Item[] getRootItems()
          Retrieves all root-items of this screen.
 int getSelectedFlags(int tabIndex, boolean[] selectedArray_return)
          Queries the state of a Choice and returns the state of all elements in the boolean array selectedArray_return.
 int getSelectedIndex(int tabIndex)
          Returns the index number of an element in the Choice that is selected.
 java.lang.String getString(int tabIndex, int elementNum)
          Gets the String part of the element referenced by elementNum.
 ChoiceGroup getTab(int tabIndex)
           
 int getTabNumber()
           
protected  boolean handleKeyPressed(int keyCode, int gameAction)
          Handles the key-pressed event.
protected  boolean handlePointerPressed(int x, int y)
          Handles the pressing of a pointer.
protected  boolean handlePointerReleased(int x, int y)
          Handles the release of a pointer.
 void hideNotify()
          Unregisters this screen and notifies all items that they will not be shown anymore.
 void insert(int tabIndex, int elementNum, ChoiceItem item, Style style)
          Inserts an element into the Choice just prior to the element specified.
 void insert(int tabIndex, int elementNum, java.lang.String stringPart, javax.microedition.lcdui.Image imagePart)
          Inserts an element into the Choice just prior to the element specified.
 void insert(int tabIndex, int elementNum, java.lang.String stringPart, javax.microedition.lcdui.Image imagePart, Style style)
          Inserts an element into the Choice just prior to the element specified.
 boolean isSelected(int tabIndex, int elementNum)
          Gets a boolean value indicating whether this element is selected.
protected  void paintScreen(javax.microedition.lcdui.Graphics g)
          Paints the screen.
 void set(int tabIndex, int elementNum, ChoiceItem item)
          Sets the String and Image parts of the element referenced by elementNum, replacing the previous contents of the element.
 void set(int tabIndex, int elementNum, ChoiceItem item, Style elementStyle)
          Sets the String and Image parts of the element referenced by elementNum, replacing the previous contents of the element.
 void set(int tabIndex, int elementNum, java.lang.String stringPart, javax.microedition.lcdui.Image imagePart)
          Sets the String and Image parts of the element referenced by elementNum, replacing the previous contents of the element.
 void set(int tabIndex, int elementNum, java.lang.String stringPart, javax.microedition.lcdui.Image imagePart, Style elementStyle)
          Sets the String and Image parts of the element referenced by elementNum, replacing the previous contents of the element.
 void setCurrentTab(int tabIndex)
           
 void setSelectCommand(javax.microedition.lcdui.Command selectCommand)
           
 void setSelectedFlags(int tabIndex, boolean[] selectedArray)
          Attempts to set the selected state of every element in the Choice.
 void setSelectedIndex(int tabIndex, int elementNum, boolean selected)
          For MULTIPLE, this simply sets an individual element's selected state.
 void setStyle(Style style)
          Sets the style of this screen.
 void setTabStyle(int tabIndex)
           
 void setTabStyle(int tabIndex, Style style)
           
 int size(int tabIndex)
          Gets the number of elements present.
 
Methods inherited from class de.enough.polish.ui.Screen
addCommand, addCommand, addSubCommand, addSubCommand, animate, callCommandListener, checkForRequestInit, closeMenu, commandAction, focus, focus, focus, focus, focus, getAvailableHeight, getCommandItem, getCommandListener, getCurrentIndex, getCurrentItem, getGameAction, getItemAt, getMenuBar, getPolishTicker, getScreenContentHeight, getScreenContentWidth, getScreenData, getScreenFullHeight, getScreenFullWidth, getScreenHeight, getScreenStyle, getScrollBarWidth, getScrollYOffset, getTitle, handleCommand, handleKeyReleased, handleKeyRepeated, isGameActionFire, isKeyboardAccessible, isMenuOpened, isShown, isSoftKey, isSoftKey, isSoftKeyLeft, isSoftKeyMiddle, isSoftKeyRight, keyPressed, keyReleased, keyRepeated, notifyScreenStateChanged, notifyStateListener, paint, 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, sizeChanged
 
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
 

Field Detail

SELECT_COMMAND

public static javax.microedition.lcdui.Command SELECT_COMMAND
Constructor Detail

TabbedList

public TabbedList(java.lang.String title,
                  int defaultListType)
Parameters:
title -

TabbedList

public TabbedList(java.lang.String title,
                  int defaultListType,
                  Style style)
Parameters:
title -
Method Detail

appendTab

public int appendTab(javax.microedition.lcdui.Item item)

appendTab

public int appendTab(java.lang.String text,
                     javax.microedition.lcdui.Image icon)

appendTab

public int appendTab(java.lang.String text,
                     javax.microedition.lcdui.Image icon,
                     Style style)

appendTab

public int appendTab(Item item)

appendTab

public int appendTab(Item item,
                     Style style)

appendTab

public int appendTab(Item item,
                     int tabListType,
                     Style style)

deleteTab

public void deleteTab(int tabIndex)

setCurrentTab

public void setCurrentTab(int tabIndex)

setTabStyle

public void setTabStyle(int tabIndex)

setTabStyle

public void setTabStyle(int tabIndex,
                        Style style)

getTab

public ChoiceGroup getTab(int tabIndex)

getTabNumber

public int getTabNumber()

setSelectCommand

public void setSelectCommand(javax.microedition.lcdui.Command selectCommand)

calculateContentArea

protected void calculateContentArea(int x,
                                    int y,
                                    int width,
                                    int height)
Description copied from class: Screen
Calculates and sets the content area for this screen. Usually no items are painted outside of the specified area. This method knows about the title, subtitle, infoarea and ticker and adjusts the content area accordingly

Overrides:
calculateContentArea in class Screen
Parameters:
x - left start of the content area, might later be adjusted by an external scrollindicator
y - top start of the content area, is adjusted by the top margin, title height, subtitle height, info height and maybe ticker height (when the ticker should be painted at the top).
width - width of the content area, might later be adjusted by an external scrollindicator
height - height of the content area, is adjusted by the title height, subtitle height, info height and ticker height.

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

handlePointerPressed

protected boolean handlePointerPressed(int x,
                                       int y)
Description copied from class: Screen
Handles the pressing of a pointer. This method should be overwritten only when the polish.hasPointerEvents preprocessing symbol is defined. When the screen could handle the pointer pressing, it needs to return true. The default implementation returns the result of calling the container's handlePointerPressed-method

Overrides:
handlePointerPressed in class Screen
Parameters:
x - the absolute x position of the pointer pressing
y - the absolute y position of the pointer pressing
Returns:
true when the pressing of the pointer was actually handled by this item.

handlePointerReleased

protected boolean handlePointerReleased(int x,
                                        int y)
Description copied from class: Screen
Handles the release of a pointer. This method should be overwritten only when the polish.hasPointerEvents preprocessing symbol is defined. When the screen could handle the pointer release, it needs to return true. The default implementation returns the result of calling the container's handlePointerReleased-method

Overrides:
handlePointerReleased in class Screen
Parameters:
x - the absolute x position of the pointer pressing
y - the absolute y position of the pointer pressing
Returns:
true when the pressing of the pointer was actually handled by this item.

paintScreen

protected void paintScreen(javax.microedition.lcdui.Graphics g)
Description copied from class: Screen
Paints the screen. This method also needs to set the protected variables paintScrollIndicator, paintScrollIndicatorUp and paintScrollIndicatorDown.

Overrides:
paintScreen in class Screen
Parameters:
g - the graphics on which the screen should be painted
See Also:
Screen.contentX, Screen.contentY, Screen.contentWidth, Screen.contentHeight, Screen.paintScrollIndicator, Screen.paintScrollIndicatorUp, Screen.paintScrollIndicatorDown

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

animate

public void animate(long currentTime,
                    ClippingRegion repaintRegion)
Description copied from class: Screen
Animates this screen. Subclasses can override this method to create animations. All embedded items are also animated.

Overrides:
animate in class Screen
Parameters:
currentTime - the current time in milliseconds
repaintRegion - the repaint area that needs to be updated when this item is animated

getRootItems

protected Item[] getRootItems()
Description copied from class: Screen
Retrieves all root-items of this screen. The root items are those in first hierarchy, in a Form this is a Container for example. The default implementation does return an empty array, since apart from the container no additional items are used. Subclasses which use more root items than the container needs to override this method.

Overrides:
getRootItems in class Screen
Returns:
the root items an array, the array can be empty but not null.

hideNotify

public void hideNotify()
Description copied from class: Screen
Unregisters this screen and notifies all items that they will not be shown anymore.

Specified by:
hideNotify in interface AccessibleCanvas
Overrides:
hideNotify in class Screen

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

Specified by:
createCssSelector in class Screen
Returns:
the name of the appropriate CSS Selector for this screen.

size

public int size(int tabIndex)
Gets the number of elements present.

Returns:
the number of elements in the Choice

getString

public java.lang.String getString(int tabIndex,
                                  int elementNum)
Gets the String part of the element referenced by elementNum. The elementNum parameter must be within the range [0..size()-1], inclusive.

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element to be queried
Returns:
the string part of the element
Throws:
java.lang.IndexOutOfBoundsException - - if elementNum is invalid
See Also:
getImage(int, int)

getImage

public javax.microedition.lcdui.Image getImage(int tabIndex,
                                               int elementNum)
Gets the Image part of the element referenced by elementNum. The elementNum parameter must be within the range [0..size()-1], inclusive.

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element to be queried
Returns:
the image part of the element, or null if there is no image
Throws:
java.lang.IndexOutOfBoundsException - - if elementNum is invalid
See Also:
getString(int, int)

append

public int append(int tabIndex,
                  java.lang.String stringPart,
                  javax.microedition.lcdui.Image imagePart)
Appends an element to the Choice. The added element will be the last element of the Choice. The size of the Choice grows by one.

Parameters:
tabIndex - the index of the tab
stringPart - the string part of the element to be added
imagePart - the image part of the element to be added, or null if there is no image part
Returns:
the assigned index of the element
Throws:
java.lang.NullPointerException - - if stringPart is null

append

public int append(int tabIndex,
                  java.lang.String stringPart,
                  javax.microedition.lcdui.Image imagePart,
                  Style style)
Appends an element to the Choice. The added element will be the last element of the Choice. The size of the Choice grows by one.

Parameters:
tabIndex - the index of the tab
stringPart - the string part of the element to be added
imagePart - the image part of the element to be added, or null if there is no image part
Returns:
the assigned index of the element
Throws:
java.lang.NullPointerException - - if stringPart is null

insert

public void insert(int tabIndex,
                   int elementNum,
                   java.lang.String stringPart,
                   javax.microedition.lcdui.Image imagePart)
Inserts an element into the Choice just prior to the element specified. The size of the Choice grows by one. The elementNum parameter must be within the range [0..size()], inclusive. The index of the last element is size()-1, and so there is actually no element whose index is size(). If this value is used for elementNum, the new element is inserted immediately after the last element. In this case, the effect is identical to append().

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element where insertion is to occur
stringPart - the string part of the element to be inserted
imagePart - the image part of the element to be inserted, or null if there is no image part
Throws:
java.lang.IndexOutOfBoundsException - - if elementNum is invalid
java.lang.NullPointerException - - if stringPart is null

insert

public void insert(int tabIndex,
                   int elementNum,
                   java.lang.String stringPart,
                   javax.microedition.lcdui.Image imagePart,
                   Style style)
Inserts an element into the Choice just prior to the element specified. The size of the Choice grows by one. The elementNum parameter must be within the range [0..size()], inclusive. The index of the last element is size()-1, and so there is actually no element whose index is size(). If this value is used for elementNum, the new element is inserted immediately after the last element. In this case, the effect is identical to append().

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element where insertion is to occur
stringPart - the string part of the element to be inserted
imagePart - the image part of the element to be inserted, or null if there is no image part
Throws:
java.lang.IndexOutOfBoundsException - if elementNum is invalid
java.lang.NullPointerException - if stringPart is null

insert

public void insert(int tabIndex,
                   int elementNum,
                   ChoiceItem item,
                   Style style)
Inserts an element into the Choice just prior to the element specified. The size of the Choice grows by one. The elementNum parameter must be within the range [0..size()], inclusive. The index of the last element is size()-1, and so there is actually no element whose index is size(). If this value is used for elementNum, the new element is inserted immediately after the last element. In this case, the effect is identical to append().

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element where insertion is to occur
item - the item
style - the style oft the item
Throws:
java.lang.IndexOutOfBoundsException - if elementNum is invalid
java.lang.NullPointerException - if stringPart is null

delete

public void delete(int tabIndex,
                   int elementNum)
Deletes the element referenced by elementNum. The size of the Choice shrinks by one. It is legal to delete all elements from a Choice. The elementNum parameter must be within the range [0..size()-1], inclusive.

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element to be deleted
Throws:
java.lang.IndexOutOfBoundsException - if elementNum is invalid

deleteAll

public void deleteAll(int tabIndex)
Deletes all elements from this Choice, leaving it with zero elements. This method does nothing if the Choice is already empty.

Parameters:
tabIndex - the index of the tab
Since:
MIDP 2.0

set

public void set(int tabIndex,
                int elementNum,
                java.lang.String stringPart,
                javax.microedition.lcdui.Image imagePart)
Sets the String and Image parts of the element referenced by elementNum, replacing the previous contents of the element. The elementNum parameter must be within the range [0..size()-1], inclusive. The font attribute of the element is left unchanged.

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element to be set
stringPart - the string part of the new element
imagePart - the image part of the element, or null if there is no image part
Throws:
java.lang.IndexOutOfBoundsException - if elementNum is invalid
java.lang.NullPointerException - if stringPart is null

set

public void set(int tabIndex,
                int elementNum,
                java.lang.String stringPart,
                javax.microedition.lcdui.Image imagePart,
                Style elementStyle)
Sets the String and Image parts of the element referenced by elementNum, replacing the previous contents of the element. The elementNum parameter must be within the range [0..size()-1], inclusive. The font attribute of the element is left unchanged.

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element to be set
stringPart - the string part of the new element
imagePart - the image part of the element, or null if there is no image part
elementStyle - the style of the new element
Throws:
java.lang.IndexOutOfBoundsException - if elementNum is invalid
java.lang.NullPointerException - if stringPart is null

set

public void set(int tabIndex,
                int elementNum,
                ChoiceItem item)
Sets the String and Image parts of the element referenced by elementNum, replacing the previous contents of the element. The elementNum parameter must be within the range [0..size()-1], inclusive. The font attribute of the element is left unchanged.

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element to be set
item - the element
Throws:
java.lang.IndexOutOfBoundsException - if elementNum is invalid
java.lang.NullPointerException - if stringPart is null

set

public void set(int tabIndex,
                int elementNum,
                ChoiceItem item,
                Style elementStyle)
Sets the String and Image parts of the element referenced by elementNum, replacing the previous contents of the element. The elementNum parameter must be within the range [0..size()-1], inclusive. The font attribute of the element is left unchanged.

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element to be set
item - the element
elementStyle - the style of the item
Throws:
java.lang.IndexOutOfBoundsException - if elementNum is invalid
java.lang.NullPointerException - if stringPart is null

isSelected

public boolean isSelected(int tabIndex,
                          int elementNum)
Gets a boolean value indicating whether this element is selected. The elementNum parameter must be within the range [0..size()-1], inclusive.

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element to be queried
Returns:
selection state of the element
Throws:
java.lang.IndexOutOfBoundsException - if elementNum is invalid

getSelectedIndex

public int getSelectedIndex(int tabIndex)
Returns the index number of an element in the Choice that is selected. For Choice types EXCLUSIVE, POPUP, and IMPLICIT there is at most one element selected, so this method is useful for determining the user's choice. Returns -1 if the Choice has no elements (and therefore has no selected elements).

For MULTIPLE, this always returns -1 because no single value can in general represent the state of such a Choice. To get the complete state of a MULTIPLE Choice, see getSelectedFlags.

Parameters:
tabIndex - the index of the tab
Returns:
index of selected element, or -1 if none
See Also:
setSelectedIndex(int, int, boolean)

getSelectedFlags

public int getSelectedFlags(int tabIndex,
                            boolean[] selectedArray_return)
Queries the state of a Choice and returns the state of all elements in the boolean array selectedArray_return. Note: this is a result parameter. It must be at least as long as the size of the Choice as returned by size(). If the array is longer, the extra elements are set to false.

This call is valid for all types of Choices. For MULTIPLE, any number of elements may be selected and set to true in the result array. For EXCLUSIVE, POPUP, and IMPLICIT exactly one element will be selected (unless there are zero elements in the Choice).

Parameters:
tabIndex - the index of the tab
selectedArray_return - - array to contain the results
Returns:
the number of selected elements in the Choice
Throws:
java.lang.IllegalArgumentException - - if selectedArray_return is shorter than the size of the Choice.
java.lang.NullPointerException - - if selectedArray_return is null
See Also:
setSelectedFlags(int, boolean[])

setSelectedIndex

public void setSelectedIndex(int tabIndex,
                             int elementNum,
                             boolean selected)
For MULTIPLE, this simply sets an individual element's selected state.

For EXCLUSIVE and POPUP, this can be used only to select any element, that is, the selected parameter must be true . When an element is selected, the previously selected element is deselected. If selected is false , this call is ignored. If element was already selected, the call has no effect.

For IMPLICIT, this can be used only to select any element, that is, the selected parameter must be true . When an element is selected, the previously selected element is deselected. If selected is false , this call is ignored. If element was already selected, the call has no effect.

The call to setSelectedIndex does not cause implicit activation of any Command.

For all list types, the elementNum parameter must be within the range [0..size()-1], inclusive.

Parameters:
tabIndex - the index of the tab
elementNum - the index of the element, starting from zero
selected - the state of the element, where true means selected and false means not selected
Throws:
java.lang.IndexOutOfBoundsException - if elementNum is invalid
See Also:
getSelectedIndex(int)

setSelectedFlags

public void setSelectedFlags(int tabIndex,
                             boolean[] selectedArray)
Attempts to set the selected state of every element in the Choice. The array must be at least as long as the size of the Choice. If the array is longer, the additional values are ignored.

For Choice objects of type MULTIPLE, this sets the selected state of every element in the Choice. An arbitrary number of elements may be selected.

For Choice objects of type EXCLUSIVE, POPUP, and IMPLICIT, exactly one array element must have the value true. If no element is true, the first element in the Choice will be selected. If two or more elements are true, the implementation will choose the first true element and select it.

Parameters:
tabIndex - the index of the tab
selectedArray - an array in which the method collect the selection status
Throws:
java.lang.IllegalArgumentException - if selectedArray is shorter than the size of the Choice
java.lang.NullPointerException - if selectedArray is null
See Also:
getSelectedFlags(int, boolean[])

getCurrentTabIndex

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

Returns:
the index of the current tab