de.enough.polish.ui
Class FilteredList

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.List
                  extended by de.enough.polish.ui.FilteredList
All Implemented Interfaces:
AccessibleCanvas, Choice, ItemStateListener

public class FilteredList
extends List
implements ItemStateListener

Displays a list of choices that can be limited by the user by entering some input.

Copyright Enough Software 2007 - 2008

 history
        Jun 21, 2007 - michael creation
 

Author:
Michael Koch, Robert Virkus, j2mepolish@enough.de

Field Summary
protected  int filterMode
           
protected  int filterPosition
           
protected  TextField filterTextField
           
 
Fields inherited from class de.enough.polish.ui.List
choiceGroup, listType, 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
 
Fields inherited from interface de.enough.polish.ui.Choice
EXCLUSIVE, IMPLICIT, MULTIPLE, POPUP, TEXT_WRAP_DEFAULT, TEXT_WRAP_OFF, TEXT_WRAP_ON
 
Constructor Summary
FilteredList(java.lang.String title, int listType)
          Creates a new FilteredList
FilteredList(java.lang.String title, int listType, ChoiceItem[] items)
          Creates a new FilteredList
FilteredList(java.lang.String title, int listType, ChoiceItem[] items, Style style)
          Creates a new FilteredList
FilteredList(java.lang.String title, int listType, java.lang.String[] stringElements, javax.microedition.lcdui.Image[] imageElements)
          Creates a new FilteredList
FilteredList(java.lang.String title, int listType, java.lang.String[] stringElements, javax.microedition.lcdui.Image[] imageElements, Style style)
          Creates a new FilteredList
FilteredList(java.lang.String title, int listType, Style style)
          Creates a new FilteredList
 
Method Summary
 void animate(long currentTime, ClippingRegion repaintRegion)
          Animates this screen.
 int append(ChoiceItem item)
          Appends a ChoiceItem to the List.
protected  void calculateContentArea(int x, int y, int width, int height)
          Calculates and sets the content area for this screen.
 boolean containsChangesTo(boolean[] flags)
          Determines whether there are any changes compared to the specified boolean array.
protected  java.lang.String createCssSelector()
          Retrieves the CSS selector for this screen.
 void delete(int elementNum)
          Deletes the element referenced by elementNum.
 void deleteAll()
          Deletes all elements from this List.
 void focus(int index, boolean force)
          Focuses the specified item.
 void focus(int index, Item item, boolean force)
          Focuses the specified item.
 void focus(Item item, boolean force)
          Focuses the specified item.
 Item getCurrentItem()
          Retrieves the currently focused item.
 java.lang.String getFilterText()
           
 ChoiceItem getItem(int elementNum)
          Gets the ChoiceItem of the element referenced by elementNum.
 int getSelectedFlags(boolean[] selectedArray_return)
          Queries the state of a List and returns the state of all elements in the boolean array selectedArray_return.
 int getSelectedIndex()
          Returns the index number of an element in the List that is selected.
protected  boolean handleCommand(javax.microedition.lcdui.Command cmd)
          Tries to handle the specified command.
protected  boolean handleKeyPressed(int keyCode, int gameAction)
          Handles the key-pressed event.
protected  boolean handleKeyReleased(int keyCode, int gameAction)
          Handles the key-released event.
protected  boolean handleKeyRepeated(int keyCode, int gameAction)
          Handles the key-repeated event.
 void insert(int elementNum, ChoiceItem item)
          Inserts an element into the List just prior to the element specified.
 boolean isSelected(int elementNum)
          Gets a boolean value indicating whether this element is selected.
 void itemStateChanged(Item item)
          Called when internal state of an Item has been changed by the user.
protected  boolean matches(java.lang.String filterText, ChoiceItem cItem, boolean checkForSelectedRadioItem)
          Checks if the given item matches the current input text.
protected  void paintScreen(javax.microedition.lcdui.Graphics g)
          Paints the screen.
 void set(int elementNum, ChoiceItem item)
          Sets the ChoiceItem of the element referenced by elementNum, replacing the previous one.
 void set(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 setFilterLabel(java.lang.String label)
           
 void setFilterStyle(Style filterStyle)
           
 void setFilterText(java.lang.String text)
           
protected  void setItemCommands(ArrayList commandsList, Item item)
          Sets the commands of the given item
 void setSelectedFlags(boolean[] selectedArray)
          Sets the selected state of all elements of the List.
 void setSelectedIndex(int elementNum, boolean selected)
          Sets the selected state of an element.
 void setStyle(Style style)
          Sets the style of this screen.
 void showNotify()
          Initialises this screen and informs all items about being painted soon.
 int size()
          Gets the number of elements in the List.
 java.lang.String toSelectionString(java.lang.String delimiter)
          Concats all strings from the selected elements together.
 
Methods inherited from class de.enough.polish.ui.List
append, append, getFitPolicy, getFont, getImage, getString, insert, insert, removeCommand, set, setFitPolicy, setFont, setSelectCommand
 
Methods inherited from class de.enough.polish.ui.Screen
addCommand, addCommand, addSubCommand, addSubCommand, animate, callCommandListener, checkForRequestInit, closeMenu, commandAction, focus, focus, getAvailableHeight, getCommandItem, getCommandListener, getCurrentIndex, getGameAction, getItemAt, getMenuBar, getPolishTicker, getRootItems, getScreenContentHeight, getScreenContentWidth, getScreenData, getScreenFullHeight, getScreenFullWidth, getScreenHeight, getScreenStyle, getScrollBarWidth, getScrollYOffset, getTitle, handlePointerPressed, handlePointerReleased, hideNotify, isGameActionFire, isKeyboardAccessible, isMenuOpened, isShown, isSoftKey, isSoftKey, isSoftKeyLeft, isSoftKeyMiddle, isSoftKeyRight, keyPressed, keyReleased, keyRepeated, notifyScreenStateChanged, notifyStateListener, paint, pointerDragged, pointerPressed, pointerReleased, releaseResources, removeAllCommands, removeItemCommands, requestInit, requestRepaint, requestRepaint, scrollRelative, setCommandListener, setFullScreenMode, setInfo, setItemStateListener, setItemStateListener, setMenuBarStyle, setMenuItemStyle, setPolishTicker, setPolishTicker, setScreenData, setScreenOrientation, setScreenStateListener, setScrollYOffset, setSubTitle, setTitle, setTitle, setTitle, 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

filterPosition

protected int filterPosition

filterMode

protected int filterMode

filterTextField

protected final TextField filterTextField
Constructor Detail

FilteredList

public FilteredList(java.lang.String title,
                    int listType)
Creates a new FilteredList

Parameters:
title - the title
listType - the type, either Choice.MULTIPLE, Choice.IMPLICIT or Choice.EXCLUSIVE

FilteredList

public FilteredList(java.lang.String title,
                    int listType,
                    Style style)
Creates a new FilteredList

Parameters:
title - the title
listType - the type, either Choice.MULTIPLE, Choice.IMPLICIT or Choice.EXCLUSIVE
style - style for the list

FilteredList

public FilteredList(java.lang.String title,
                    int listType,
                    java.lang.String[] stringElements,
                    javax.microedition.lcdui.Image[] imageElements)
Creates a new FilteredList

Parameters:
title - the title
listType - the type, either Choice.MULTIPLE, Choice.IMPLICIT or Choice.EXCLUSIVE
stringElements - list item texts
imageElements - list item images

FilteredList

public FilteredList(java.lang.String title,
                    int listType,
                    java.lang.String[] stringElements,
                    javax.microedition.lcdui.Image[] imageElements,
                    Style style)
Creates a new FilteredList

Parameters:
title - the title
listType - the type, either Choice.MULTIPLE, Choice.IMPLICIT or Choice.EXCLUSIVE
stringElements - list item texts
imageElements - list item images
style - style for the list

FilteredList

public FilteredList(java.lang.String title,
                    int listType,
                    ChoiceItem[] items)
Creates a new FilteredList

Parameters:
title - the title
listType - the type, either Choice.MULTIPLE, Choice.IMPLICIT or Choice.EXCLUSIVE
items - items of the list

FilteredList

public FilteredList(java.lang.String title,
                    int listType,
                    ChoiceItem[] items,
                    Style style)
Creates a new FilteredList

Parameters:
title - the title
listType - the type, either Choice.MULTIPLE, Choice.IMPLICIT or Choice.EXCLUSIVE
items - items of the list
style - style for the list
Method Detail

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 List
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

handleKeyReleased

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

Overrides:
handleKeyReleased in class Screen
Parameters:
keyCode - the code of the released key, e.g. Canvas.KEY_NUM2
gameAction - the corresponding game-action, e.g. Canvas.UP
Returns:
true when the key-event was processed

handleKeyRepeated

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

Overrides:
handleKeyRepeated in class Screen
Parameters:
keyCode - the code of the repeated key, e.g. Canvas.KEY_NUM2
gameAction - the corresponding game-action, e.g. Canvas.UP
Returns:
true when the key-event was processed

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

setItemCommands

protected void setItemCommands(ArrayList commandsList,
                               Item item)
Description copied from class: Screen
Sets the commands of the given item

Overrides:
setItemCommands in class Screen
item - the item which has at least one command
See Also:
Screen.removeItemCommands(Item)

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.

showNotify

public void showNotify()
Description copied from class: Screen
Initialises this screen and informs all items about being painted soon.

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

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.

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

append

public int append(ChoiceItem item)
Description copied from class: List
Appends a ChoiceItem to the List.

Overrides:
append in class List
Parameters:
item - ChoiceItem to be added
Returns:
the assigned index of the element

delete

public void delete(int elementNum)
Description copied from class: List
Deletes the element referenced by elementNum.

Specified by:
delete in interface Choice
Overrides:
delete in class List
Parameters:
elementNum - the index of the element to be deleted
See Also:
in interface Choice

deleteAll

public void deleteAll()
Description copied from class: List
Deletes all elements from this List.

Specified by:
deleteAll in interface Choice
Overrides:
deleteAll in class List
See Also:
in interface Choice

getItem

public ChoiceItem getItem(int elementNum)
Description copied from class: List
Gets the ChoiceItem of the element referenced by elementNum.

Overrides:
getItem in class List
Parameters:
elementNum - the number of the element to be queried
Returns:
the ChoiceItem of the element

getSelectedFlags

public int getSelectedFlags(boolean[] selectedArray_return)
Description copied from class: List
Queries the state of a List and returns the state of all elements in the boolean array selectedArray_return.

Specified by:
getSelectedFlags in interface Choice
Overrides:
getSelectedFlags in class List
Parameters:
selectedArray_return - array to contain the results
Returns:
the number of selected elements in the Choice
See Also:
in interface Choice, List.setSelectedFlags(boolean[])

containsChangesTo

public boolean containsChangesTo(boolean[] flags)
Determines whether there are any changes compared to the specified boolean array.

Parameters:
flags - an array indicating the expected state of this list - true array elements indicate "selected" items of this list
Returns:
true when there are changes in this list

getSelectedIndex

public int getSelectedIndex()
Description copied from class: List
Returns the index number of an element in the List that is selected.

Specified by:
getSelectedIndex in interface Choice
Overrides:
getSelectedIndex in class List
Returns:
index of selected element, or -1 if none is selected
See Also:
in interface Choice, List.setSelectedIndex(int, boolean)

insert

public void insert(int elementNum,
                   ChoiceItem item)
Description copied from class: List
Inserts an element into the List just prior to the element specified.

Overrides:
insert in class List
Parameters:
elementNum - the index of the element where insertion is to occur
item - ChoiceItem of the element to be inserted

set

public void set(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.

Overrides:
set in class List
Parameters:
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 for the new list element.
Throws:
java.lang.IndexOutOfBoundsException - if elementNum is invalid
java.lang.NullPointerException - if stringPart is null
See Also:
in interface Choice

set

public void set(int elementNum,
                ChoiceItem item)
Description copied from class: List
Sets the ChoiceItem of the element referenced by elementNum, replacing the previous one.

Overrides:
set in class List
Parameters:
elementNum - the index of the element to be set
item - ChoiceItem of the new element

setSelectedFlags

public void setSelectedFlags(boolean[] selectedArray)
Description copied from class: List
Sets the selected state of all elements of the List.

Specified by:
setSelectedFlags in interface Choice
Overrides:
setSelectedFlags in class List
Parameters:
selectedArray - an array in which the method collect the selection status
See Also:
in interface Choice, List.getSelectedFlags(boolean[])

setSelectedIndex

public void setSelectedIndex(int elementNum,
                             boolean selected)
Description copied from class: List
Sets the selected state of an element.

Specified by:
setSelectedIndex in interface Choice
Overrides:
setSelectedIndex in class List
Parameters:
elementNum - the index of the element, starting from zero
selected - the state of the element, where true means selected and false means not selected
See Also:
in interface Choice, List.getSelectedIndex()

focus

public void focus(int index,
                  boolean force)
Description copied from class: Screen
Focuses the specified item.

Overrides:
focus in class Screen
Parameters:
index - the index of the item which is already shown on this screen.
force - true when the item should be focused even when it is inactive (like a label for example)

focus

public void focus(Item item,
                  boolean force)
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.
force - true when the item should be focused even when it is inactive (like a label for example)

focus

public void focus(int index,
                  Item item,
                  boolean force)
Description copied from class: Screen
Focuses the specified item.

Overrides:
focus in class Screen
Parameters:
index - the index of the item which is already shown on this screen.
item - the item which is already shown on this screen.
force - true when the item should be focused even when it is inactive (like a label for example)

isSelected

public boolean isSelected(int elementNum)
Description copied from class: List
Gets a boolean value indicating whether this element is selected.

Specified by:
isSelected in interface Choice
Overrides:
isSelected in class List
Parameters:
elementNum - index to element to be queried
Returns:
selection state of the element
See Also:
in interface Choice

size

public int size()
Description copied from class: List
Gets the number of elements in the List.

Specified by:
size in interface Choice
Overrides:
size in class List
Returns:
the number of elements in the List
See Also:
in interface Choice

handleCommand

protected boolean handleCommand(javax.microedition.lcdui.Command cmd)
Description copied from class: Screen
Tries to handle the specified command. The default implementation forwards the call to the container. When the container is unable to process the command, it will be forwarded to an external command listener that has been set using setCommandListener(..)

Overrides:
handleCommand in class Screen
Parameters:
cmd - the command
Returns:
true when the command has been handled by this screen

setFilterLabel

public void setFilterLabel(java.lang.String label)

setFilterText

public void setFilterText(java.lang.String text)

getFilterText

public java.lang.String getFilterText()

setFilterStyle

public void setFilterStyle(Style filterStyle)
Parameters:
filterStyle -

matches

protected boolean matches(java.lang.String filterText,
                          ChoiceItem cItem,
                          boolean checkForSelectedRadioItem)
Checks if the given item matches the current input text. Subclasses can override this method for implementing specific filter strategies.

Parameters:
filterText - the current filter text
cItem - the ChoiceItem
checkForSelectedRadioItem - true when this is an exclusive list
Returns:
true for choice items that should be appended to the shown list.
See Also:
FILTER_STARTS_WITH, FILTER_INDEX_OF, List.setFitPolicy(int)

itemStateChanged

public void itemStateChanged(Item item)
Description copied from interface: ItemStateListener
Called when internal state of an Item has been changed by the user. This happens when the user:

It is up to the device to decide when it considers a new value to have been entered into an Item. For example, implementations of text editing within a TextField vary greatly from device to device.

In general, it is not expected that the listener will be called after every change is made. However, if an item's value has been changed, the listener will be called to notify the application of the change before it is called for a change on another item, and before a command is delivered to the Form's CommandListener. For implementations that have the concept of an input focus, the listener should be called no later than when the focus moves away from an item whose state has been changed. The listener should be called only if the item's value has actually been changed.

The listener is not called if the application changes the value of an interactive item.

Specified by:
itemStateChanged in interface ItemStateListener
Parameters:
item - the item that was changed

setStyle

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

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

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 List
Returns:
the name of the appropriate CSS Selector for this screen.

toSelectionString

public java.lang.String toSelectionString(java.lang.String delimiter)
Concats all strings from the selected elements together.

Parameters:
delimiter - the delimiter between elements
Returns:
the String including all selected elements or null when none is selected