Package totalcross.ui
Class ComboBox
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.ComboBox
-
- All Implemented Interfaces:
MaterialEffect.SideEffect,TimerListener
- Direct Known Subclasses:
ComboBoxEditable
public class ComboBox extends Container implements TimerListener, MaterialEffect.SideEffect
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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description static intarrowStylestatic intARROWSTYLE_DOWNDOTstatic intARROWSTYLE_PAGEFLIPjava.lang.StringcaptionThe caption to draw when this ComboBox is empty.intcaptionColorThe caption's color.ImagecaptionIconAn optional caption's iconCaptionPresscaptionPressHandler for the CustomPressintcheckColorThe check color used to fill the radio button used in Android.static intdefaultClearValueIntThe default value that is set to the clearValueInt of all ComboBox.booleanenableSearchParameter passed to PopupMenu.booleanfullHeightIf set to true, the popup window will have the height of the screenbooleanfullWidthIf set to true, the popup window will have the width of the screenprotected ComboBoxDropDownpopjava.lang.StringpopupTitleThe title of the PopupMenu when in Android user interface style.static booleanusePopupMenuSet to false to don't use the PopupMenu when the user interface style is Android.-
Fields inherited from class totalcross.ui.Container
alwaysEraseBackground, BACKGROUND_CYLINDRIC_SHADED, BACKGROUND_SHADED, BACKGROUND_SHADED_INV, BACKGROUND_SOLID, backgroundStyle, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_ROUNDED, BORDER_SIMPLE, BORDER_TOP, borderColor, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, lastX, lastY, started, tabOrder, tail, TRANSITION_CLOSE, TRANSITION_FADE, TRANSITION_NONE, TRANSITION_OPEN, TRANSITION_TIME, transitionEffect
-
Fields inherited from class totalcross.ui.Control
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, nextTabControl, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Constructor Summary
Constructors Constructor Description ComboBox()Creates an empty ComboBoxComboBox(java.lang.Object[] items)Creates a ComboBox with the given itemsComboBox(ComboBoxDropDown userPopList)Constructs a ComboBox with the given PopList.ComboBox(ListBox userListBox)Creates a ComboBox with a PopList containing the given ListBox.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(java.lang.Object item)Adds an Object to the Listbox.voidadd(java.lang.Object[] items)Adds an array of Objects to the Listboxvoidadd(java.lang.Object[] items, int startAt, int size)Deprecated.Useadd(Object[])instead.voidadd(Control control)Does nothingintaddWrapping(java.lang.String text)Adds the given text to this ListBox, breaking the text if it goes beyond the ListBox' limits, and also breaking if it contains \n.voidclear()Clears this control, selecting index clearValueInt (0 by default); uses clearValueStr if set, instead.protected voiddrawSelectedItem(Graphics g)voidenableHorizontalScroll()Adds support for horizontal scroll on this listbox.booleanequals(java.lang.Object o)protected intgetArrowColor()Used to determine the arrow color in Material UI when its drawing.voidgetFocusableControls(Vector v)Get a list of child controls of this container which are focus candidatesjava.lang.ObjectgetItemAt(int i)Get the Object at the given Indexjava.lang.Object[]getItems()Returns all items in this ComboBoxListBoxgetListBox()Returns the ListBox used when this combobox is opened.intgetPreferredHeight()Returns the preferred height of this control.intgetPreferredWidth()Returns the preferred width of this control.intgetSelectedIndex()Returns the position of the selected item of the ListBoxjava.lang.ObjectgetSelectedItem()Returns the selected item of the ListBoxControlhandleGeographicalFocusChangeKeys(KeyEvent ke)Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.intindexOf(java.lang.Object name)Returns the index of the item specified by the namevoidinsert(java.lang.Object item, int index)Adds an Object to the Listbox at the given indexprotected voidonBoundsChanged(boolean screenChanged)Called after a setRect.protected voidonColorsChanged(boolean colorsChanged)Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.voidonEvent(Event event)Called to process key, pen, control and other posted events.protected voidonFontChanged()Passes the font to the pop listvoidonPaint(Graphics g)paint the combo's border and the current selected itemvoidpopup()Pops up the ComboBoxDropDownvoidqsort()Sorts the items of this combobox, and then unselects the current item.voidqsort(boolean caseless)Sorts the elements of this ListBox.voidremove(int itemIndex)Removes an Object from the Listbox at the given index.voidremove(java.lang.Object item)Removes an Object from the Listboxvoidremove(Control control)Does nothingvoidremoveAll()Empties the ListBoxvoidselectLast()Selects the last item added to this combobox, doing a scroll if needed.voidsetBackForeItemColors(IntHashtable ihtFore, IntHashtable ihtBack)Sets the ihtForeColors and ihtBackColors for the ListBox used with this ComboBox.voidsetCursorColor(int color)Sets the cursor color for this ComboBox.voidsetItemAt(int i, java.lang.Object s)Sets the Object at the given Index, starting from 0voidsetPop(ComboBoxDropDown lb)Replaces the original ComboBoxDropDown by the given one.voidsetSelectedIndex(int i)Select the given index.voidsetSelectedIndex(int i, boolean sendPressEvent)Select the given index, and optionally sends a PRESSED event.voidsetSelectedItem(java.lang.Object name)Selects an item.voidsetSelectedItem(java.lang.Object name, boolean sendPress)Selects an item.booleansetSelectedItemStartingWith(java.lang.String text, boolean caseInsensitive)Selects the item that starts with the given textbooleansetSelectedItemStartingWith(java.lang.String text, boolean caseInsensitive, boolean sendPress)Selects the item that starts with the given textvoidsidePaint(Graphics g, int alpha)voidsideStart()voidsideStop()intsize()Returns the number of itemsvoidtimerTriggered(TimerEvent e)A TRIGGERED event was dispatched.voidunpop()Unpops the ComboBoxDropDown.protected voidupdatePopRect()-
Methods inherited from class totalcross.ui.Container
add, add, add, add, applyTransitionEffect, broadcastEvent, fillBackground, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderStyle, getChildren, getChildrenCount, getClientRect, getClientRect, getFirstChild, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, resize, resizeHeight, resizeWidth, setBorderStyle, setEnabled, setFocusTraversable, setHighlighting, setInsets, setNextTransitionEffect, setPressColor, setPressed, swapToTopmostWindow
-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addGridListener, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addTimer, addTimer, addTimerListener, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
ARROWSTYLE_DOWNDOT
public static final int ARROWSTYLE_DOWNDOT
- See Also:
- Constant Field Values
-
ARROWSTYLE_PAGEFLIP
public static final int ARROWSTYLE_PAGEFLIP
- See Also:
- Constant Field Values
-
arrowStyle
public static int arrowStyle
-
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
-
captionPress
public CaptionPress captionPress
Handler for the CustomPress
-
defaultClearValueInt
public static int defaultClearValueInt
The default value that is set to the clearValueInt of all ComboBox. Usually this value is 0, but sometimes you may wish set it to -1, to unselect the ComboBox when clear is called.
-
checkColor
public int checkColor
The check color used to fill the radio button used in Android. Defaults to the fore color. In material UI, the arrow will be filled with this color when it has focus- Since:
- TotalCross 1.3
-
popupTitle
public java.lang.String popupTitle
The title of the PopupMenu when in Android user interface style.- Since:
- TotalCross 1.3
-
enableSearch
public boolean enableSearch
Parameter passed to PopupMenu. Defauts to true.- See Also:
PopupMenu.enableSearch
-
caption
public java.lang.String caption
The caption to draw when this ComboBox is empty. In Material UI, you must set the caption BEFORE you add this control to the container; also remember to set the height to at least PREFERRED, it is 75% taller.- See Also:
captionColor
-
captionColor
public int captionColor
The caption's color.
-
captionIcon
public Image captionIcon
An optional caption's icon
-
usePopupMenu
public static boolean usePopupMenu
Set to false to don't use the PopupMenu when the user interface style is Android. This affects all ComboBoxes. If you want to change a particular ComboBox to use the standard popup list, but keep others with the PopupMenu, you can do something like:// at the begining of your program: ComboBox.usePopupMenu = true; // when you want to create the standalone ComboBox ComboBox.usePopupMenu = false; // turn flag off .. create the ComboBox ComboBox.usePopupMenu = true; // turn flag on again
An internal copy of the flag is set at the constructor.- Since:
- TotalCross 1.5
-
-
Constructor Detail
-
ComboBox
public ComboBox()
Creates an empty ComboBox
-
ComboBox
public ComboBox(java.lang.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(java.lang.Object[] items)
Adds an array of Objects to the Listbox
-
add
@Deprecated public void add(java.lang.Object[] items, int startAt, int size)Deprecated.Useadd(Object[])instead.Adds an array of Objects to the Listbox
-
add
public void add(java.lang.Object item)
Adds an Object to the Listbox. This method is very slow if used in loop; use theadd(Object[])to add a bunch of objects instead.
-
addWrapping
public int addWrapping(java.lang.String text)
Adds the given text to this ListBox, breaking the text if it goes beyond the ListBox' limits, and also breaking if it contains \n. Returns the number of lines. Note that each part of the text is considered a new item. This method is slower than the otheraddmethods.- Since:
- TotalCross 1.24
-
insert
public void insert(java.lang.Object item, int index)Adds an Object to the Listbox at the given index
-
remove
public void remove(java.lang.Object item)
Removes an Object from the Listbox
-
remove
public void remove(int itemIndex)
Removes an Object from the Listbox at the given index.
-
setItemAt
public void setItemAt(int i, java.lang.Object s)Sets the Object at the given Index, starting from 0
-
getItemAt
public java.lang.Object getItemAt(int i)
Get the Object at the given Index
-
getSelectedItem
public java.lang.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 java.lang.Object[] getItems()
Returns all items in this ComboBox
-
indexOf
public int indexOf(java.lang.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(java.lang.Object name)
Selects an item. If the name is not found, the currently selected item is not changed.- Since:
- SuperWaba 4.01
-
setSelectedItem
public void setSelectedItem(java.lang.Object name, boolean sendPress)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.
-
setSelectedIndex
public void setSelectedIndex(int i, boolean sendPressEvent)Select the given index, and optionally sends a PRESSED event. 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:ControlReturns the preferred width of this control.- Overrides:
getPreferredWidthin classControl
-
getPreferredHeight
public int getPreferredHeight()
Description copied from class:ControlReturns the preferred height of this control.- Overrides:
getPreferredHeightin classControl
-
onFontChanged
protected void onFontChanged()
Passes the font to the pop list- Overrides:
onFontChangedin classControl
-
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:ControlCalled after a setRect.- Overrides:
onBoundsChangedin classControl- Parameters:
screenChanged- If the bounds were changed due to a screen change (rotation, collapse)
-
onEvent
public void onEvent(Event event)
Description copied from class:ControlCalled to process key, pen, control and other posted events.
-
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:ControlCalled 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:
onColorsChangedin classContainer
-
getArrowColor
protected int getArrowColor()
Used to determine the arrow color in Material UI when its drawing.
-
onPaint
public void onPaint(Graphics g)
paint the combo's border and the current selected item
-
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); uses clearValueStr if set, instead.
-
getFocusableControls
public void getFocusableControls(Vector v)
Description copied from class:ContainerGet a list of child controls of this container which are focus candidates- Overrides:
getFocusableControlsin classContainer- Parameters:
v- A vector into which to add the focus candidates.
-
handleGeographicalFocusChangeKeys
public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Description copied from class:ControlUsed by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.- Overrides:
handleGeographicalFocusChangeKeysin classControl- 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(java.lang.String text, boolean caseInsensitive)Selects the item that starts with the given text- Parameters:
text- The text string to search forcaseInsensitive- 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
-
setSelectedItemStartingWith
public boolean setSelectedItemStartingWith(java.lang.String text, boolean caseInsensitive, boolean sendPress)Selects the item that starts with the given text- Parameters:
text- The text string to search forcaseInsensitive- If true, the text and all searched strings are first converted to lowercase.sendPress- If true, sends the PRESSED event- Returns:
- If an item was found and selected.
- Since:
- TotalCross 1.13
-
setPop
public void setPop(ComboBoxDropDown lb)
Replaces the original ComboBoxDropDown by the given one.- Since:
- TotalCross 1.5
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
timerTriggered
public void timerTriggered(TimerEvent e)
Description copied from interface:TimerListenerA TRIGGERED event was dispatched.- Specified by:
timerTriggeredin interfaceTimerListener- See Also:
TimerEvent
-
sideStart
public void sideStart()
- Specified by:
sideStartin interfaceMaterialEffect.SideEffect
-
sideStop
public void sideStop()
- Specified by:
sideStopin interfaceMaterialEffect.SideEffect
-
sidePaint
public void sidePaint(Graphics g, int alpha)
- Specified by:
sidePaintin interfaceMaterialEffect.SideEffect
-
-