brf.j2me.dynaworks.ui
Class ListBox

java.lang.Object
  |
  +--brf.j2me.dynaworks.ui.BasicWidget
        |
        +--brf.j2me.dynaworks.ui.ListBox
All Implemented Interfaces:
UserWidget

public class ListBox
extends BasicWidget

Control to list an array of strings and to provide selection of entries.

Version:
1.0
Author:
Bernd R. Fix
See Also:
BasicWidget, UserWidget

Field Summary
protected  java.util.Vector allItems
          Items able to be displayed
private  ListItem currItem
          reference to currently active item.
private  int currItemIndex
           
protected  java.util.Vector displayedList
          The items in this List that are displayed.
protected  int displayNum
          Default value for how many items we can display.
private  int dragState
          current dragging mode
private  int dragX
          we are dragging from here
private  int dragY
           
private  int firstVisible
          index of first visible item
static int GROUP
           
private  int height
          height of a tree control.
private  ScrollBar hs
          reference to horizontal scrollbar.
static int MULTIPLE
           
static int SCR_HORZ
           
static int SCR_VERT
           
private  int scrollX
          horizontal scroll position.
private  int scrollXmax
          maximum x-scroll value for current layout
private  int scrollY
          vertical scroll position.
private  int scrollYmax
          maximum y-scroll value for current layout
private  int selMode
          selection mode for listbox.
static int SIMPLE
          Selection mode flags
static int SINGLE
           
private  int syncState
          status of synchronization: 0 = up-to-date
private  ScrollBar vs
          reference to vertical scrollbar.
private  int width
          width of the tree control.
 
Fields inherited from class brf.j2me.dynaworks.ui.BasicWidget
g, h, w, x, y
 
Constructor Summary
ListBox(int x, int y, int w, int h, int style)
          Creates an empty ListBox.
 
Method Summary
 void addItem(ListItem item)
          Inserts the item as an item in the list.
private  boolean addToDisplayedList(ListItem item)
          add an item to the list of displayed items.
 int getSelectedIndex()
          Return the index of the selected item.
 ListItem getSelectedItem()
          Return the selected item in the list, null if the list is empty.
 ActionEvent handlePenDown(int xc, int yc)
          Handle a "pen down" event.
 ActionEvent handlePenMove(int xc, int yc)
          Handle a "pen move" event.
 ActionEvent handlePenUp(int xc, int yc)
          Handle a "pen up" event.
private  void initStyle(int style)
          setup the style.
 void paint()
          paint the graphics area.
 void removeAll()
          deletes all items in the list.
 boolean removeItem(ListItem item)
          Deletes the item from the list of items.
 void selectItem(ListItem item, boolean redraw)
          selects the item
protected  void setHorizontalOffset(int offset)
          Sets the horizontal offset for painting the listbox and can be used e.g.
protected  void setVerticalOffset(int offset)
          Sets the vertical offset for painting the ListBox and can be used e.g.
private  void sync()
          synchronize inner state (list of displayed items.)
 
Methods inherited from class brf.j2me.dynaworks.ui.BasicWidget
, contains, handleKeyDown, handleSysKeyDown, hasFocus, loseFocus, setFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

SIMPLE

public static final int SIMPLE
Selection mode flags

SINGLE

public static final int SINGLE

GROUP

public static final int GROUP

MULTIPLE

public static final int MULTIPLE

SCR_VERT

public static final int SCR_VERT

SCR_HORZ

public static final int SCR_HORZ

selMode

private int selMode
selection mode for listbox.


width

private int width
width of the tree control.


height

private int height
height of a tree control.


hs

private ScrollBar hs
reference to horizontal scrollbar.


scrollX

private int scrollX
horizontal scroll position.


scrollXmax

private int scrollXmax
maximum x-scroll value for current layout


vs

private ScrollBar vs
reference to vertical scrollbar.


scrollY

private int scrollY
vertical scroll position.


scrollYmax

private int scrollYmax
maximum y-scroll value for current layout


dragState

private int dragState
current dragging mode


dragX

private int dragX
we are dragging from here


dragY

private int dragY

currItem

private ListItem currItem
reference to currently active item.


currItemIndex

private int currItemIndex

firstVisible

private int firstVisible
index of first visible item


displayedList

protected java.util.Vector displayedList
The items in this List that are displayed.


allItems

protected java.util.Vector allItems
Items able to be displayed


syncState

private int syncState
status of synchronization: 0 = up-to-date


displayNum

protected int displayNum
Default value for how many items we can display. Will be adjusted according to the control size.

Constructor Detail

ListBox

public ListBox(int x,
               int y,
               int w,
               int h,
               int style)
Creates an empty ListBox.

Parameters:
x - int - x-coordinate of upper-left corner.
y - int - y-coordinate of upper-left corner.
w - int - width of the control.
h - int - height of the control.
style - int - style mode.
Method Detail

paint

public void paint()
paint the graphics area.
Overrides:
paint in class BasicWidget

initStyle

private void initStyle(int style)
setup the style.

Parameters:
style - int - tree style to be used.

getSelectedItem

public ListItem getSelectedItem()
Return the selected item in the list, null if the list is empty.

Returns:
ListItem - reference to selected item or null

getSelectedIndex

public int getSelectedIndex()
Return the index of the selected item.

Returns:
int - index to selected item or -1.

setHorizontalOffset

protected void setHorizontalOffset(int offset)
Sets the horizontal offset for painting the listbox and can be used e.g. for a scrollbar.

Parameters:
offset - int - use value as new horizontal offset.

setVerticalOffset

protected void setVerticalOffset(int offset)
Sets the vertical offset for painting the ListBox and can be used e.g. for a scrollbar.

Parameters:
offset - int - use value as new vertical offset.

addItem

public void addItem(ListItem item)
Inserts the item as an item in the list.

Parameters:
item - ListItem - item to be inserted.

removeItem

public boolean removeItem(ListItem item)
Deletes the item from the list of items.

Parameters:
item - ListItem - item to be removed
Returns:
true if the argument was part of the list; false otherwise

removeAll

public void removeAll()
deletes all items in the list.


selectItem

public void selectItem(ListItem item,
                       boolean redraw)
selects the item
Parameters:
item - ListItem - item to be selected
redraw - boolean - redraw control?

addToDisplayedList

private boolean addToDisplayedList(ListItem item)
add an item to the list of displayed items.

Parameters:
item - ListItem - item to be added
Returns:
boolean - successful operation?

sync

private void sync()
synchronize inner state (list of displayed items.)


handlePenDown

public ActionEvent handlePenDown(int xc,
                                 int yc)
Handle a "pen down" event.

Overrides:
handlePenDown in class BasicWidget
Parameters:
xc - int - x coordinate of point
yc - int - y coordinate of point
Returns:
ActionEvent - ActionEvent code (or null)

handlePenMove

public ActionEvent handlePenMove(int xc,
                                 int yc)
Handle a "pen move" event.

Overrides:
handlePenMove in class BasicWidget
Parameters:
xc - int - x coordinate of current point
yc - int - y coordinate of current point
Returns:
ActionEvent - ActionEvent code (or null)

handlePenUp

public ActionEvent handlePenUp(int xc,
                               int yc)
Handle a "pen up" event.

Overrides:
handlePenUp in class BasicWidget
Parameters:
xc - int - x coordinate of current point
yc - int - y coordinate of current point
Returns:
ActionEvent - ActionEvent code (or null)