totalcross.ui
Class ComboBox

totalcross.lang.Object
  extended by totalcross.ui.gfx.GfxSurface
      extended by totalcross.ui.Control
          extended by totalcross.ui.Container
              extended by totalcross.ui.ComboBox
Direct Known Subclasses:
ComboBoxEditable

public class ComboBox
extends Container

ComboBox is an implementation of a ComboBox, with the drop down window implemented by the ComboBoxDropDown class.

Note: the color used in the setBackground method will be used in the button only. The background color of the control will be a lighter version of the given color.


Field Summary
 boolean fullHeight
          If set to true, the popup window will have the height of the screen
 boolean fullWidth
          If set to true, the popup window will have the width of the screen
protected  ComboBoxDropDown pop
           
 
Fields inherited from class totalcross.ui.Container
alwaysEraseBackground, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_SIMPLE, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, lastX, lastY, nextTransitionEffect, started, tabOrder, tail, TRANSITION_CLOSE, TRANSITION_NONE, TRANSITION_OPEN, transitionEffect
 
Fields inherited from class totalcross.ui.Control
AFTER, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, CENTER, CENTER_OF, clearValueInt, clearValueStr, enabled, enableUpdateScreen, FILL, FIT, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, foreColor, height, isHighlighting, KEEP, LEFT, onEventFirst, parent, PREFERRED, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, setFont, setH, setRel, setW, setX, setY, TOP, transparentBackground, uiCE, uiFlat, uiPalm, uiVista, visible, width, WILL_RESIZE, x, y
 
Constructor Summary
ComboBox()
          Creates an empty ComboBox
ComboBox(ComboBoxDropDown userPopList)
          Constructs a ComboBox with the given PopList.
ComboBox(ListBox userListBox)
          Creates a ComboBox with a PopList containing the given ListBox.
ComboBox(Object[] items)
          Creates a ComboBox with the given items
 
Method Summary
 void add(Control control)
          Does nothing
 void add(Object item)
          Adds an totalcross.lang.Object to the Listbox.
 void add(Object[] items)
          Adds an array of Objects to the Listbox
 void add(Object[] items, int startAt, int size)
          Adds an array of Objects to the Listbox
 void clear()
          Clears this control, selecting index clearValueInt (0 by default).
protected  void drawSelectedItem(Graphics g)
           
 void enableHorizontalScroll()
          Adds support for horizontal scroll on this listbox.
 void getFocusableControls(Vector v)
          Get a list of child controls of this container which are focus candidates
 Object getItemAt(int i)
          Get the totalcross.lang.Object at the given Index
 Object[] getItems()
          Returns all items in this ComboBox
 ListBox getListBox()
          Returns the ListBox used when this combobox is opened.
 int getPreferredHeight()
          Returns the preferred height of this control.
 int getPreferredWidth()
          Returns the preferred width of this control.
 int getSelectedIndex()
          Returns the position of the selected item of the ListBox
 Object getSelectedItem()
          Returns the selected item of the ListBox
 Control handleGeographicalFocusChangeKeys(KeyEvent ke)
          Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.
 int indexOf(Object name)
          Returns the index of the item specified by the name
 void insert(Object item, int index)
          Adds an totalcross.lang.Object to the Listbox at the given index
protected  void onBoundsChanged(boolean screenChanged)
          Called after a setRect.
protected  void onColorsChanged(boolean colorsChanged)
          Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.
 void onEvent(Event event)
          Called to process key, pen, control and other posted events.
protected  void onFontChanged()
          Passes the font to the pop list
 void onPaint(Graphics g)
          paint the combo's border and the current selected item
 void popup()
          Pops up the ComboBoxDropDown
 void qsort()
          Sorts the items of this combobox, and then unselects the current item.
 void qsort(boolean caseless)
          Sorts the elements of this ListBox.
 void remove(Control control)
          Does nothing
 void remove(int itemIndex)
          Removes an totalcross.lang.Object from the Listbox at the given index.
 void remove(Object item)
          Removes an totalcross.lang.Object from the Listbox
 void removeAll()
          Empties the ListBox
 void selectLast()
          Selects the last item added to this combobox, doing a scroll if needed.
 void setBackForeItemColors(IntHashtable ihtFore, IntHashtable ihtBack)
          Sets the ihtForeColors and ihtBackColors for the ListBox used with this ComboBox.
 void setCursorColor(int color)
          Sets the cursor color for this ComboBox.
 void setItemAt(int i, Object s)
          Sets the totalcross.lang.Object at the given Index, starting from 0
 void setSelectedIndex(int i)
          Select the given index.
 void setSelectedItem(Object name)
          Selects an item.
 boolean setSelectedItemStartingWith(String text, boolean caseInsensitive)
          Selects the item that starts with the given text
 int size()
          Returns the number of items
 void unpop()
          Unpops the ComboBoxDropDown.
protected  void updatePopRect()
           
 
Methods inherited from class totalcross.ui.Container
add, add, add, add, broadcastEvent, findChild, findNearestChild, findNextFocusControl, getBorderStyle, getChildren, getClientRect, getClientRect, getInsets, incLastX, incLastY, initUI, onAddAgain, onRemove, paintChildren, resize, resizeHeight, resizeWidth, setBorderStyle, setEnabled, setHighlighting, setInsets, swapToTopmostWindow
 
Methods inherited from class totalcross.ui.Control
_onEvent, addFocusListener, addGridListener, addHighlightListener, addKeyListener, addPenListener, addPressListener, addTimer, addTimer, addTimerListener, addWindowListener, changeHighlighted, contains, getAbsoluteRect, getBackColor, getEventListeners, getFont, getForeColor, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getWidth, getX, getX2, getY, getY2, isDisplayed, isEnabled, isInsideOrNear, isVisible, isVisibleAndInside, onWindowPaintFinished, postEvent, postPressedEvent, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removePenListener, removePressListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, requestFocus, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setVisible, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary
 
Methods inherited from class totalcross.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pop

protected ComboBoxDropDown pop

fullHeight

public boolean fullHeight
If set to true, the popup window will have the height of the screen


fullWidth

public boolean fullWidth
If set to true, the popup window will have the width of the screen

Constructor Detail

ComboBox

public ComboBox()
Creates an empty ComboBox


ComboBox

public ComboBox(Object[] items)
Creates a ComboBox with the given items


ComboBox

public ComboBox(ListBox userListBox)
Creates a ComboBox with a PopList containing the given ListBox. You can extend the ListBox to draw the items by yourself and use this constructor so the PopList will use your class and not the default ListBox one. This constructor forces the ListBox.simpleBorder to true. Note: the listbox items must be already set.


ComboBox

public ComboBox(ComboBoxDropDown userPopList)
Constructs a ComboBox with the given PopList.

Method Detail

add

public void add(Control control)
Does nothing

Overrides:
add in class Container

remove

public void remove(Control control)
Does nothing

Overrides:
remove in class Container

add

public void add(Object[] items)
Adds an array of Objects to the Listbox


add

public void add(Object[] items,
                int startAt,
                int size)
Adds an array of Objects to the Listbox


add

public void add(Object item)
Adds an totalcross.lang.Object to the Listbox. This method is very slow if used in loop; use the add(totalcross.lang.Object[]) to add a bunch of objects instead.


insert

public void insert(Object item,
                   int index)
Adds an totalcross.lang.Object to the Listbox at the given index


removeAll

public void removeAll()
Empties the ListBox

Overrides:
removeAll in class Container

remove

public void remove(Object item)
Removes an totalcross.lang.Object from the Listbox


remove

public void remove(int itemIndex)
Removes an totalcross.lang.Object from the Listbox at the given index.


setItemAt

public void setItemAt(int i,
                      Object s)
Sets the totalcross.lang.Object at the given Index, starting from 0


getItemAt

public Object getItemAt(int i)
Get the totalcross.lang.Object at the given Index


getSelectedItem

public Object getSelectedItem()
Returns the selected item of the ListBox


getSelectedIndex

public int getSelectedIndex()
Returns the position of the selected item of the ListBox


getItems

public Object[] getItems()
Returns all items in this ComboBox


indexOf

public int indexOf(Object name)
Returns the index of the item specified by the name


setCursorColor

public void setCursorColor(int color)
Sets the cursor color for this ComboBox. The default is equal to the background slightly darker.


setSelectedItem

public void setSelectedItem(Object name)
Selects an item. If the name is not found, the currently selected item is not changed.

Since:
SuperWaba 4.01

setSelectedIndex

public void setSelectedIndex(int i)
Select the given index. Choose "-1" if you want to blank the ComboBox view box.


size

public int size()
Returns the number of items


getPreferredWidth

public int getPreferredWidth()
Description copied from class: Control
Returns the preferred width of this control.

Overrides:
getPreferredWidth in class Control

getPreferredHeight

public int getPreferredHeight()
Description copied from class: Control
Returns the preferred height of this control.

Overrides:
getPreferredHeight in class Control

onFontChanged

protected void onFontChanged()
Passes the font to the pop list

Overrides:
onFontChanged in class Control

setBackForeItemColors

public void setBackForeItemColors(IntHashtable ihtFore,
                                  IntHashtable ihtBack)
Sets the ihtForeColors and ihtBackColors for the ListBox used with this ComboBox. Note that null is a valid value, used when you always want to use the default color.

Since:
TotalCross 1.0 beta 4

onBoundsChanged

protected void onBoundsChanged(boolean screenChanged)
Description copied from class: Control
Called after a setRect.

Overrides:
onBoundsChanged in class Control
Parameters:
screenChanged - If the bounds were changed due to a screen change (rotation, collapse)

onEvent

public void onEvent(Event event)
Description copied from class: Control
Called to process key, pen, control and other posted events.

Overrides:
onEvent in class Control
Parameters:
event - the event to process
See Also:
Event, KeyEvent, PenEvent

updatePopRect

protected void updatePopRect()

popup

public void popup()
Pops up the ComboBoxDropDown


unpop

public void unpop()
Unpops the ComboBoxDropDown.

Since:
TotalCross 1.2

onColorsChanged

protected void onColorsChanged(boolean colorsChanged)
Description copied from class: Control
Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled

Overrides:
onColorsChanged in class Container

onPaint

public void onPaint(Graphics g)
paint the combo's border and the current selected item

Overrides:
onPaint in class Container
Parameters:
g - the graphics object for drawing
See Also:
Graphics

drawSelectedItem

protected void drawSelectedItem(Graphics g)

qsort

public void qsort()
Sorts the items of this combobox, and then unselects the current item.


qsort

public void qsort(boolean caseless)
Sorts the elements of this ListBox. The current selection is cleared.

Parameters:
caseless - Pass true to make a caseless sort, if the items are Strings.

enableHorizontalScroll

public void enableHorizontalScroll()
Adds support for horizontal scroll on this listbox. Two buttons will appear below the vertical scrollbar. The add, replace and remove operations will be a bit slower because the string's width will have to be computed in order to correctly set the maximum horizontal scroll.

Since:
SuperWaba 5.6

selectLast

public void selectLast()
Selects the last item added to this combobox, doing a scroll if needed. Calls repaintNow.

Since:
SuperWaba 5.6

clear

public void clear()
Clears this control, selecting index clearValueInt (0 by default).

Overrides:
clear in class Container

getFocusableControls

public void getFocusableControls(Vector v)
Description copied from class: Container
Get a list of child controls of this container which are focus candidates

Overrides:
getFocusableControls in class Container
Parameters:
v - A vector into which to add the focus candidates.

handleGeographicalFocusChangeKeys

public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Description copied from class: Control
Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.

Overrides:
handleGeographicalFocusChangeKeys in class Control
Parameters:
ke - The KeyEvent to be processed
Returns:
The control that should get focus as a result of this KeyEvent. Null if this control did not handle the KeyEvent.
See Also:
Settings.geographicalFocus

getListBox

public ListBox getListBox()
Returns the ListBox used when this combobox is opened.


setSelectedItemStartingWith

public boolean setSelectedItemStartingWith(String text,
                                           boolean caseInsensitive)
Selects the item that starts with the given text

Parameters:
text - The text string to search for
caseInsensitive - If true, the text and all searched strings are first converted to lowercase.
Returns:
If an item was found and selected.
Since:
TotalCross 1.13