totalcross.ui
Class ColorList

totalcross.lang.Object
  extended by totalcross.ui.gfx.GfxSurface
      extended by totalcross.ui.Control
          extended by totalcross.ui.Container
              extended by totalcross.ui.ListBox
                  extended by totalcross.ui.ColorList

public class ColorList
extends ListBox

Implements a ListBox where colors can be choosen from. The only functional methods are setColors, getSelectedItem and getSelectedColor. Next an example of how to use this class as a combobox color chooser:

 add(foreCombo = new ComboBox(new ColorList()), CENTER, BOTTOM);
 


Nested Class Summary
static class ColorList.Item
          Item added to the ListBox, containing the color as totalcross.lang.String and as int.
 
Field Summary
 
Fields inherited from class totalcross.ui.ListBox
back0, back1, btnX, btnX0, dragScroll, EXTRA_HEIGHT_FACTOR, extraHorizScrollButtonHeight, ihtBackColors, ihtForeColors, itemCount, items, offset, sbar, selectedIndex, simpleBorder, useFullWidthOnSelection, visibleItems, visibleLines, xOffset
 
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
ColorList()
           
 
Method Summary
protected  void drawCursor(Graphics g, int sel, boolean on)
          This method is used to draw the cursor around the desired item
protected  void drawItem(Graphics g, int index, int dx, int dy)
          You can extend ListBox and overide this method to draw the items
protected  void drawSelectedItem(Graphics g, int index, int dx, int dy)
          You can extend ListBox and overide this method to draw the items
protected  int getItemWidth(int index)
          Returns the width of the given item index with the current fontmetrics.
 int getPreferredWidth()
          Returns the preferred width, ie, the size of the largest item plus the size of the scrollbar.
 int getSelectedColor()
          Returns the selected color or black if no one is selected.
 Object getSelectedItem()
          Returns the selected Item object, or a black Item representing the black color if none was selected.
 void setColors(int[] newColors)
          Sets the colors that will be displayed.
 
Methods inherited from class totalcross.ui.ListBox
add, add, add, add, clear, drawSelectedItem, enableHorizontalScroll, endSelection, find, getCursorColor, getFocusableControls, getItemAt, getItems, getPreferredHeight, getSelectedIndex, getText, handleGeographicalFocusChangeKeys, handleSelection, hideScrollBarIfNotNeeded, indexOf, insert, leftReached, onBoundsChanged, onColorsChanged, onEvent, onPaint, qsort, qsort, remove, remove, remove, removeAll, selectLast, setCursorColor, setEnabled, setItemAt, setSelectedIndex, setSelectedItem, setSelectedItemStartingWith, setSimpleBorder, size
 
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, 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, onFontChanged, 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
 

Constructor Detail

ColorList

public ColorList()
Method Detail

setColors

public void setColors(int[] newColors)
Sets the colors that will be displayed.


drawItem

protected void drawItem(Graphics g,
                        int index,
                        int dx,
                        int dy)
Description copied from class: ListBox
You can extend ListBox and overide this method to draw the items

Overrides:
drawItem in class ListBox

drawSelectedItem

protected void drawSelectedItem(Graphics g,
                                int index,
                                int dx,
                                int dy)
Description copied from class: ListBox
You can extend ListBox and overide this method to draw the items

Overrides:
drawSelectedItem in class ListBox

drawCursor

protected void drawCursor(Graphics g,
                          int sel,
                          boolean on)
Description copied from class: ListBox
This method is used to draw the cursor around the desired item

Overrides:
drawCursor in class ListBox

getPreferredWidth

public int getPreferredWidth()
Description copied from class: ListBox
Returns the preferred width, ie, the size of the largest item plus the size of the scrollbar.

Overrides:
getPreferredWidth in class ListBox

getItemWidth

protected int getItemWidth(int index)
Description copied from class: ListBox
Returns the width of the given item index with the current fontmetrics. Note: if you overide this class you must implement this method.

Overrides:
getItemWidth in class ListBox

getSelectedItem

public Object getSelectedItem()
Returns the selected Item object, or a black Item representing the black color if none was selected. From the Item you can retrieve the color as int. Use the getSelectedColor method to retrieve the color directly.

Overrides:
getSelectedItem in class ListBox

getSelectedColor

public int getSelectedColor()
Returns the selected color or black if no one is selected.