Package totalcross.ui
Class PopupMenu
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.Window
-
- totalcross.ui.PopupMenu
-
public class PopupMenu extends Window
Creates a popup menu with a single line list and some radio buttons at right, like in the Android combobox styles. This is a sample of how to use it:String[] items = { "Always", "Never", "Only in Silent mode", "Only when not in Silent mode", "Non of the answers above", }; PopupMenu pm = new PopupMenu("Vibrate",items); pm.popup();A PRESSED event is sent when an item is selected. Note: the colors must be set before the control's bounds are defined using setRect or add.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringcancelStringThe string of the button; defaults to "Cancel"intcheckColorThe check color used to fill the radio button used in Android.intdataColIf the items is a String matrix (String[][]), this field sets the column that will be shown.booleanenableCancelSet to false BEFORE popping up the window to disable the Cancel button.booleanenableSearchSet to true BEFORE popping up the window to enable search on the items of this PopupMenu.intitemCountSets the number of elements should be used from the items array passed in the constructor.booleankeepIndexOnCancelSet to true to keep the selected index unchanged if user press the Cancel button-
Fields inherited from class totalcross.ui.Window
_controlEvent, _dragEvent, _focus, _keyEvent, _mouseEvent, _multiEvent, _penEvent, androidBorderThickness, beepIfOut, blocking, borderStyle, cancelPenUp, canDrag, dragThreshold, fadeOtherWindows, fadeValue, firstFocus, flickEnabled, focusOnPenUp, footerColor, footerH, gradientTitleEndColor, gradientTitleStartColor, headerColor, highlighted, highResPrepared, HORIZONTAL_GRADIENT, ignoreEventOfType, keyHook, lastShiftY, lastSwappedContainer, mainSwapContainer, menubar, multiTouching, needsPaint, NO_BORDER, ORIENTATION_INVERTED, ORIENTATION_LANDSCAPE, ORIENTATION_PORTRAIT, popped, RECT_BORDER, repaintOnSwap, robot, ROUND_BORDER, rTitle, sameBackgroundColor, shiftH, shiftY, SIP_BOTTOM, SIP_HIDE, SIP_SHOW, SIP_TOP, TAB_BORDER, TAB_ONLY_BORDER, tempTitle, title, titleAlign, titleColor, titleFont, titleGap, topMost, VERTICAL_GRADIENT, zStack
-
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, 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 PopupMenu(java.lang.String caption, java.lang.Object[] items)Constructs a PopupMenu with the given parameters and without multiple selection support.PopupMenu(java.lang.String caption, java.lang.Object[] items, boolean multipleSelection)Constructs a PopupMenu with the given parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetSelectedIndex()Returns the selected index when this window was closed or -1 if non was selectedvoidinitUI()Called to initialize the User Interface of this container.voidonEvent(Event event)Called to process key, pen, control and other posted events.protected voidonPopup()Setup some important variablesprotected voidpostUnpop()Placeholder called after the unpop is done and after the repaint of the other window.voidreposition()Reposition this control, calling again setRect with the original parameters.voidsetCursorColor(int c)Sets the cursor color.intsetSelectedIndex(int index)Selects the given index.-
Methods inherited from class totalcross.ui.Window
_doPaint, _postEvent, destroyZStack, drawHighlight, getBorderStyle, getClientRect, getClientRect, getDefaultDragThreshold, getFocus, getHighlighted, getPopupCount, getPreferredHeight, getPreferredWidth, getSafeAreaInsets, getTitleFont, getTopMost, handleFocusChangeKeys, isScreenShifted, isSipShown, isSipShown4D, isTopMost, isVisible, loadBehind, makeUnmovable, onClickedOutside, onRobotKey, onUnpop, paintTitle, paintWindowBackground, popup, popupMenuBar, popupNonBlocking, postPopup, postPressedEvent, pumpEvents, removeFocus, repaintActiveWindows, resize, resizeHeight, resizeWidth, screenResized, setBorderStyle, setDeviceTitle, setFocus, setGrabPenEvents, setHighlighted, setMenuBar, setOrientation, setSIP, setTitle, setTitleFont, shiftScreen, swap, swapFocus, unpop, validate
-
Methods inherited from class totalcross.ui.Container
add, add, add, add, add, applyTransitionEffect, broadcastEvent, clear, fillBackground, fillBackground, findChild, findNearestChild, findNextFocusControl, getChildren, getChildrenCount, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onColorsChanged, onPaint, onRemove, onSwapFinished, paintChildren, remove, removeAll, 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, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isInsideOrNear, isObscured, isVisibleAndInside, onBoundsChanged, onFontChanged, onWindowPaintFinished, post, postEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, 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
-
cancelString
public static java.lang.String cancelString
The string of the button; defaults to "Cancel"
-
dataCol
public int dataCol
If the items is a String matrix (String[][]), this field sets the column that will be shown.
-
itemCount
public int itemCount
Sets the number of elements should be used from the items array passed in the constructor. Defaults toitems.length.
-
checkColor
public int checkColor
The check color used to fill the radio button used in Android. Defaults to the fore color.- Since:
- TotalCross 1.3
-
enableSearch
public boolean enableSearch
Set to true BEFORE popping up the window to enable search on the items of this PopupMenu. Note that it only works if the items are ORDERED.- Since:
- TotalCross 1.5
-
enableCancel
public boolean enableCancel
Set to false BEFORE popping up the window to disable the Cancel button.- Since:
- TotalCross 1.65
-
keepIndexOnCancel
public boolean keepIndexOnCancel
Set to true to keep the selected index unchanged if user press the Cancel button- Since:
- TotalCross 2.0
-
-
Constructor Detail
-
PopupMenu
public PopupMenu(java.lang.String caption, java.lang.Object[] items) throws IOException, ImageExceptionConstructs a PopupMenu with the given parameters and without multiple selection support.- Throws:
IOExceptionImageException
-
PopupMenu
public PopupMenu(java.lang.String caption, java.lang.Object[] items, boolean multipleSelection) throws IOException, ImageExceptionConstructs a PopupMenu with the given parameters.- Throws:
IOExceptionImageException
-
-
Method Detail
-
initUI
public void initUI()
Description copied from class:ContainerCalled to initialize the User Interface of this container. This differs from the onAddAgain method by that this method is called only once, at the first time the control is added to the parent. When the container is being setup, the initUI method is called; then, the onAddAgain is called every time the container is added again.
-
reposition
public void reposition()
Description copied from class:ControlReposition this control, calling again setRect with the original parameters.- Overrides:
repositionin classControl
-
setSelectedIndex
public int setSelectedIndex(int index)
Selects the given index.
-
getSelectedIndex
public int getSelectedIndex()
Returns the selected index when this window was closed or -1 if non was selected
-
postUnpop
protected void postUnpop()
Description copied from class:WindowPlaceholder called after the unpop is done and after the repaint of the other window. The default implementation does nothing.
-
onEvent
public void onEvent(Event event)
Description copied from class:ControlCalled to process key, pen, control and other posted events.
-
setCursorColor
public void setCursorColor(int c)
Sets the cursor color. By default, it is based in the background color
-
-