Package totalcross.ui
Class MenuBarDropDown
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.Window
-
- totalcross.ui.MenuBarDropDown
-
public class MenuBarDropDown extends Window
Constructs a MenuBarDropDown with the given items. This class is used in conjunction with the MenuBar. However, you can also use it to create a stand alone "right click" menu. Here is an example of how to build the MenuBarDropDown for the DateBook:
MenuItem col1[] = // note that the first String is always skipped { new MenuItem("Record"), new MenuItem("NewEvent"), new MenuItem("Delete Note..."), new MenuItem("Purge..."), new MenuItem(), // create a dotted line new MenuItem("Beam Event"), }; MenuBarDropDown pop = new MenuBarDropDown(10,10,col1); pop.popupNonBlocking(); // a PRESSED event is generated when a item is selected. The Window // is closed when the user clicks outside or selects an item. Use the getSelectedIndex // method to discover the index of the MenuItem array that was selected (-1 if none).Note: the menu items must fit on screen. No clipping is applied. Also, the font and colors can be changed if desired.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
-
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, npback, numChildren, 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, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Constructor Summary
Constructors Constructor Description MenuBarDropDown(int x, int y, MenuItem[] items)Constructs a MenuBarDropDown that will show at the given x,y position the given items.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intgetNextSelectionIndex(KeyEvent ke)Returns the index of the next menu item that is to be selected based on the direction of the KeyEvent.intgetSelectedIndex()Returns the selected index when this window was closed or -1 if non was selectedintgetYPos(int index)protected booleanhandleFocusChangeKeys(KeyEvent ke)Called by the main event handler to handle the focus change keys.ControlhandleGeographicalFocusChangeKeys(KeyEvent ke)Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.protected voidloadBehind()This method repaints all windows from bottom to top.protected booleanonClickedOutside(PenEvent event)Close the popup list with a click outside its boundsprotected 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()Change the font and recompute some parametersvoidonPaint(Graphics g)Draws the border (if any).protected voidonPopup()Setup some important variablesprotected voidpostPopup()Placeholder called after the popup is done and after the repaint of this window.protected voidpostUnpop()Placeholder called after the unpop is done and after the repaint of the other window.voidscreenResized()Called when the screen is resized, probably caused by a rotation.voidsetCursorColor(int c)Sets the cursor color.intsetSelectedIndex(int index)Selects the given index.static MenuItem[]strings2items(java.lang.String[] strings)Converts an old Menu format into the new one.-
Methods inherited from class totalcross.ui.Window
_doPaint, _postEvent, destroyZStack, drawHighlight, fillBackground, getBorderStyle, getClientRect, getClientRect, getDefaultDragThreshold, getFocus, getHighlighted, getPopupCount, getPreferredHeight, getPreferredWidth, getSafeAreaInsets, getTitleFont, getTopMost, isScreenShifted, isSipShown, isSipShown4D, isTopMost, isVisible, makeUnmovable, onRobotKey, onUnpop, paintTitle, paintWindowBackground, popup, popupMenuBar, popupNonBlocking, postPressedEvent, pumpEvents, removeFocus, repaintActiveWindows, resize, resizeHeight, resizeWidth, 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, findChild, findNearestChild, findNextFocusControl, getChildren, getChildrenCount, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, remove, removeAll, setEnabled, setFocusTraversable, setHighlighting, setInsets, setNextTransitionEffect, setPressColor, setPressed, swapToTopmostWindow
-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, 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, isFloating, isInsideOrNear, isObscured, isVisibleAndInside, onBoundsChanged, onWindowPaintFinished, post, postEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Constructor Detail
-
MenuBarDropDown
public MenuBarDropDown(int x, int y, MenuItem[] items)Constructs a MenuBarDropDown that will show at the given x,y position the given items.
-
-
Method Detail
-
strings2items
public static MenuItem[] strings2items(java.lang.String[] strings)
Converts an old Menu format into the new one.
-
onFontChanged
protected void onFontChanged()
Change the font and recompute some parameters- Overrides:
onFontChangedin classControl
-
screenResized
public void screenResized()
Description copied from class:WindowCalled when the screen is resized, probably caused by a rotation. ATTENTION: THIS CALL CANNOT BE BLOCKED OR THE SYSTEM WILL LOCK!- Overrides:
screenResizedin classWindow
-
setSelectedIndex
public int setSelectedIndex(int index)
Selects the given index.
-
getYPos
public int getYPos(int index)
-
getSelectedIndex
public int getSelectedIndex()
Returns the selected index when this window was closed or -1 if non was selected
-
postPopup
protected void postPopup()
Description copied from class:WindowPlaceholder called after the popup is done and after the repaint of this window. The default implementation does nothing.
-
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.
-
onClickedOutside
protected boolean onClickedOutside(PenEvent event)
Close the popup list with a click outside its bounds- Overrides:
onClickedOutsidein classWindow
-
loadBehind
protected void loadBehind()
Description copied from class:WindowThis method repaints all windows from bottom to top. It is automaticaly used in the unpop method.- Overrides:
loadBehindin classWindow
-
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
-
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
-
onPaint
public void onPaint(Graphics g)
Description copied from class:ContainerDraws the border (if any). If you override this method, be sure to callsuper.onPaint(g);, or the border will not be drawn.
-
handleFocusChangeKeys
protected boolean handleFocusChangeKeys(KeyEvent ke)
Description copied from class:WindowCalled by the main event handler to handle the focus change keys. Only called when Settings.keyboardFocusNavigation is true.- Overrides:
handleFocusChangeKeysin classWindow
-
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
-
getNextSelectionIndex
protected int getNextSelectionIndex(KeyEvent ke)
Returns the index of the next menu item that is to be selected based on the direction of the KeyEvent.- Parameters:
ke- The key event- Returns:
- The index of the next menu item based on the direction of the key event.
-
-