Package totalcross.ui
Class ButtonMenu
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.ScrollContainer
-
- totalcross.ui.ButtonMenu
-
- All Implemented Interfaces:
EventHandler,PressListener,UpdateListener,Scrollable
public class ButtonMenu extends ScrollContainer implements PressListener
This class adds a multi-button menu that can be scrolled horizontally (single-row) or vertically (multiple-rows), using a scrollbar or flicking. The buttons can have almost all properties present in the Button class, like:- textPosition
- borderType
- cornerRadius3DG
- borderWidth3DG
- borderColor3DG
- topColor3DG
- bottomColor3DG
- textGap
- buttonVertGap
- buttonHorizGap
- imageSize
- borderGap
- Since:
- TotalCross 1.3
- See Also:
pagePositionDisposition
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description intborderColor3DGintborderGapThe gap between the text or image and the button borders, in percentage of the font's height.byteborderTypeintborderWidth3DGintbottomColor3DGintbuttonHorizGapThe gap between two horizontal buttons, in percentage of the font's height.intbuttonVertGapThe gap between two vertical buttons, in percentage of the font's height.intcornerRadius3DGintimageSizeThe size of the image, in percentage of the font's height.static intMULTIPLE_HORIZONTALUsed in the disposition member of the constructor.static intMULTIPLE_VERTICALUsed in the disposition member of the constructor.static intNO_PAGEPOSITIONUsed in the pagePositionDisposition.protected PagePositionpageposThe control that keeps track of the current position.static intPAGEPOSITION_AT_BOTTOMUsed in the pagePositionDisposition.static intPAGEPOSITION_AT_TOPUsed in the pagePositionDisposition.intpagePositionDispositionIf disposition is a MULTIPLE_HORIZONTAL, set how the PagePosition will replace the ScrollPosition control.intpressedColorstatic intSINGLE_COLUMNUsed in the disposition member of the constructor.static intSINGLE_ROWUsed in the disposition member of the constructor.inttextGapThe gap between the image and the text, in percentage of the font's height.inttextPositionWhere to place the text (supports only LEFT, TOP, RIGHT, BOTTOM, CENTER - no adjustments!).inttopColor3DG-
Fields inherited from class totalcross.ui.ScrollContainer
autoScroll, bag, bag0, disabledFlick, flick, hsIgnoreAutoScroll, lastH, lastV, sbH, sbV, shrink2size
-
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, borderRadius, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastScreenWidth, lastW, lastX, lastY, npback, numChildren, started, tabOrder, tail, TRANSITION_TIME
-
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 ButtonMenu(java.lang.String[] names, int disposition)Constructs an ButtonMenu with the giving names and no images.ButtonMenu(Image[] images, int disposition)Constructs an ButtonMenu with the giving images and no names.ButtonMenu(Image[] images, java.lang.String[] names, int disposition)Constructs an ButtonMenu with the giving images ant names.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcontrolPressed(ControlEvent e)A PRESSED event was dispatched.protected ButtoncreateButton(java.lang.String name, Image img, int textPosition, int tg)ButtongetButton(int idx)Returns the button at the given index.intgetPreferredHeight()Returns the preferred height as if all images were in a single row.intgetPreferredHeight(int rows)Returns the preferred height for the given number of rows.intgetPreferredWidth()Returns the preferred width as if all images were in a single row.intgetPreferredWidth(int cols)Returns the preferred width for the given number of columns.intgetSelectedIndex()voidinitUI()Called to initialize the User Interface of this container.voidonFontChanged()Creates and resizes all Button and images.voidreplaceWith(Image[] images, java.lang.String[] names)Changes all the buttons to the given parameters.voidreposition()Reposition this control, calling again setRect with the original parameters.-
Methods inherited from class totalcross.ui.ScrollContainer
add, addScrollEventHandler, bagSetRect, canScrollContent, canShowScrollBars, disableFlick, enableFlick, flickEnded, flickStarted, getBagChildren, getBagInitialHeight, getBagInitialWidth, getClientRect, getFlick, getRealClientRect, getScrollDistance, getScrollPosition, moveFocusToNextControl, onBoundsChanged, onColorsChanged, onEvent, onPaint, remove, removeAll, removeScrollEventHandler, resize, resize, scrollContent, scrollPage, scrollToControl, scrollToOrigin, scrollToPage, setBorderStyle, setHandlersVisibility, setHandlersVisibility, setHValue, setScrollBars, setVValue, updateListenerTriggered, wasScrolled
-
Methods inherited from class totalcross.ui.Container
add, add, add, add, broadcastEvent, clear, fillBackground, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getBorderStyle, getChildren, getChildrenCount, getClientRect, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, isPressed, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, resizeHeight, resizeWidth, setBorderRadius, setEnabled, setFocusTraversable, setHighlighting, setInsets, 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, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, 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
-
-
-
-
Field Detail
-
pagepos
protected PagePosition pagepos
The control that keeps track of the current position.
-
textGap
public int textGap
The gap between the image and the text, in percentage of the font's height. Defaults to 25 (%).
-
buttonVertGap
public int buttonVertGap
The gap between two vertical buttons, in percentage of the font's height. Also used as gap between the button and the ButtonMenu's border. Defaults to 100 (%).
-
buttonHorizGap
public int buttonHorizGap
The gap between two horizontal buttons, in percentage of the font's height. Also used as gap between the button and the ButtonMenu's border. Defaults to 100 (%).
-
imageSize
public int imageSize
The size of the image, in percentage of the font's height. Defaults to 200 (%). Set to -1 to keep the original size.
-
borderGap
public int borderGap
The gap between the text or image and the button borders, in percentage of the font's height. Defaults to 10 (%).
-
PAGEPOSITION_AT_BOTTOM
public static final int PAGEPOSITION_AT_BOTTOM
Used in the pagePositionDisposition. Place it at bottom.- See Also:
- Constant Field Values
-
PAGEPOSITION_AT_TOP
public static final int PAGEPOSITION_AT_TOP
Used in the pagePositionDisposition. Place it at top.- See Also:
- Constant Field Values
-
NO_PAGEPOSITION
public static final int NO_PAGEPOSITION
Used in the pagePositionDisposition. Don't use a PagePosition, use the ScrollPosition instead.- See Also:
- Constant Field Values
-
pagePositionDisposition
public int pagePositionDisposition
If disposition is a MULTIPLE_HORIZONTAL, set how the PagePosition will replace the ScrollPosition control.- See Also:
PAGEPOSITION_AT_BOTTOM,PAGEPOSITION_AT_TOP,NO_PAGEPOSITION
-
textPosition
public int textPosition
Where to place the text (supports only LEFT, TOP, RIGHT, BOTTOM, CENTER - no adjustments!). Also supports RIGHT_OF (relativeToText is computed automatically). Defaults to CENTER.
-
borderType
public byte borderType
- See Also:
Button.setBorder(byte)
-
cornerRadius3DG
public int cornerRadius3DG
- See Also:
Button.cornerRadius3DG
-
borderWidth3DG
public int borderWidth3DG
- See Also:
Button.borderWidth3DG
-
borderColor3DG
public int borderColor3DG
- See Also:
Button.borderColor3DG
-
topColor3DG
public int topColor3DG
- See Also:
Button.topColor3DG
-
bottomColor3DG
public int bottomColor3DG
- See Also:
Button.bottomColor3DG
-
pressedColor
public int pressedColor
- See Also:
Button.setPressedColor(int)
-
SINGLE_COLUMN
public static final int SINGLE_COLUMN
Used in the disposition member of the constructor. The menu will have a single column and multiple rows and will scroll vertically.- See Also:
- Constant Field Values
-
SINGLE_ROW
public static final int SINGLE_ROW
Used in the disposition member of the constructor. The menu will have a single row and multiple columns and will scroll horizontally.- See Also:
- Constant Field Values
-
MULTIPLE_HORIZONTAL
public static final int MULTIPLE_HORIZONTAL
Used in the disposition member of the constructor. The menu will have multiple columns and rows and will scroll horizontally.- See Also:
- Constant Field Values
-
MULTIPLE_VERTICAL
public static final int MULTIPLE_VERTICAL
Used in the disposition member of the constructor. The menu will have multiple columns and rows and will scroll vertically.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ButtonMenu
public ButtonMenu(Image[] images, int disposition)
Constructs an ButtonMenu with the giving images and no names.- See Also:
SINGLE_COLUMN,SINGLE_ROW,MULTIPLE_HORIZONTAL,MULTIPLE_VERTICAL
-
ButtonMenu
public ButtonMenu(java.lang.String[] names, int disposition)Constructs an ButtonMenu with the giving names and no images.- See Also:
SINGLE_COLUMN,SINGLE_ROW,MULTIPLE_HORIZONTAL,MULTIPLE_VERTICAL
-
ButtonMenu
public ButtonMenu(Image[] images, java.lang.String[] names, int disposition)
Constructs an ButtonMenu with the giving images ant names.- See Also:
SINGLE_COLUMN,SINGLE_ROW,MULTIPLE_HORIZONTAL,MULTIPLE_VERTICAL
-
-
Method Detail
-
replaceWith
public void replaceWith(Image[] images, java.lang.String[] names)
Changes all the buttons to the given parameters. If you don't want to set the images or the names, pass null in the proper place. Calls onFontChanged and initUI to reset the buttons.- Since:
- TotalCross 1.66
-
getButton
public Button getButton(int idx)
Returns the button at the given index. You may customize it.- Since:
- TotalCross 2.0
-
onFontChanged
public void onFontChanged()
Creates and resizes all Button and images. For better performance, call setFont for this control BEFORE calling add or setRect (this is a general rule for all other controls as well).- Overrides:
onFontChangedin classScrollContainer
-
createButton
protected Button createButton(java.lang.String name, Image img, int textPosition, int tg)
-
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 classScrollContainer
-
getPreferredWidth
public int getPreferredWidth()
Returns the preferred width as if all images were in a single row.- Overrides:
getPreferredWidthin classScrollContainer
-
getPreferredWidth
public int getPreferredWidth(int cols)
Returns the preferred width for the given number of columns.
-
getPreferredHeight
public int getPreferredHeight()
Returns the preferred height as if all images were in a single row.- Overrides:
getPreferredHeightin classScrollContainer
-
getPreferredHeight
public int getPreferredHeight(int rows)
Returns the preferred height for the given number of rows. For example:add(ib2,LEFT+10,CENTER,FILL-10,ib2.getPreferredHeight(4));
-
getSelectedIndex
public int getSelectedIndex()
-
controlPressed
public void controlPressed(ControlEvent e)
Description copied from interface:PressListenerA PRESSED event was dispatched.- Specified by:
controlPressedin interfacePressListener- See Also:
ControlEvent
-
-