Package totalcross.ui.dialog
Class MessageBox
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.Window
-
- totalcross.ui.dialog.MessageBox
-
- Direct Known Subclasses:
ProgressBox
public class MessageBox extends Window
This class implements a scrollable message box window with customized buttons, delayed unpop and scrolling text.
for example, to create an automatic unpop after 5 seconds, do:MessageBox mb = new MessageBox("TotalCross","TotalCross is the most exciting tool for developing totally cross-platform programs.",null); mb.setUnpopDelay(5000); mb.popup(mb);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMessageBox.Builder-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description protected ContainerbaseContainerButton[]btnsintbuttonForeColorint[]buttonKeysIf you set the buttonCaptions array in the construction, you can also set this public field to an int array of the keys that maps to each of the buttons.intbuttonMarginThis is the button margin.FontbuttonsFontMessage box fonts.intcontButtonGapThis is the gap that is between some components.protected inthaprotected intlgapDeprecated.FontmessageFontMessage box fonts.intmessageForeColorprotected LabelmsgintpaddingBottomThe paddings of this component.intpaddingLeftThe paddings of this component.intpaddingRightThe paddings of this component.intpaddingTopThe paddings of this component.static java.lang.StringshowExceptionTitleTitle shown in the showException dialog.protected Label[]titleinttitleContGapThis is the gap that is between some components.FonttitleFontMessage box fonts.protected booleanusingOwnContprotected intwaprotected intxaprotected intyaintyPositionDefines the y position on screen where this window opens.-
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, titleAlign, titleColor, 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 MessageBox(java.lang.String title, java.lang.String msg)Constructs a message box with the text and one "Ok" button.MessageBox(java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions)Constructs a message box with the text and the specified button captions.MessageBox(java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions, boolean allSameWidth)Constructs a message box with the text and the specified button captions.MessageBox(java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions, int gap, int insideGap)Constructs a message box with the text and the specified button captions.MessageBox(Image image, java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions)MessageBox(Image image, java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions, boolean allSameWidth)MessageBox(Image image, java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions, boolean allSameWidth, int gap, int insideGap)Constructs a message box with the text and the specified button captions.MessageBox(Image image, java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions, int gap, int insideGap)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ButtongetButton(int index)Return the MessageBox buttons, so you can add events to it.ImagegetImage(Image image)intgetPressedButtonIndex()Returns the pressed button index, starting from 0voidonEvent(Event e)handle scroll buttons and normal buttonsprotected voidonFontChanged()Called after a setFontvoidonPaint(Graphics g)Draws the border (if any).voidonPopup()Placeholder called imediatly before the popup began.protected 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.voidreposition()Reposition this control, calling again setRect with the original parameters.voidsetDelayToShowButton(int ms)Calling this method will make the buttons initially hidden and will show them after the specified number of milisseconds.voidsetIcon(Image icon)Set an icon to be shown in the MessageBox's title, at left.voidsetImage(Image image)voidsetText(java.lang.String text)This method can be used to set the text AFTER the dialog was shown.voidsetTextAlignment(int align)Sets the alignment for the text.voidsetUnpopDelay(int unpopDelay)sets a delay for the unpop of this dialogstatic voidshowException(java.lang.Throwable t, boolean dumpToConsole)Shows the exception, with its name, message and stack trace in a new MessageBox.-
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, 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, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onColorsChanged, 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, handleGeographicalFocusChangeKeys, 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, 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
-
title
protected Label[] title
-
msg
protected Label msg
-
btns
public Button[] btns
-
buttonForeColor
public int buttonForeColor
-
messageForeColor
public int messageForeColor
-
xa
protected int xa
-
ya
protected int ya
-
wa
protected int wa
-
ha
protected int ha
-
usingOwnCont
protected boolean usingOwnCont
-
baseContainer
protected Container baseContainer
-
lgap
@Deprecated protected int lgap
Deprecated.
-
titleFont
public Font titleFont
Message box fonts. You can change it the way you want to control the font sizes.
-
messageFont
public Font messageFont
Message box fonts. You can change it the way you want to control the font sizes.
-
buttonsFont
public Font buttonsFont
Message box fonts. You can change it the way you want to control the font sizes.
-
paddingTop
public int paddingTop
The paddings of this component. You can change it the way you desire.
-
paddingBottom
public int paddingBottom
The paddings of this component. You can change it the way you desire.
-
paddingLeft
public int paddingLeft
The paddings of this component. You can change it the way you desire.
-
paddingRight
public int paddingRight
The paddings of this component. You can change it the way you desire.
-
buttonMargin
public int buttonMargin
This is the button margin.
-
titleContGap
public int titleContGap
This is the gap that is between some components.
-
contButtonGap
public int contButtonGap
This is the gap that is between some components.
-
yPosition
public int yPosition
Defines the y position on screen where this window opens. Can be changed to TOP or BOTTOM. Defaults to CENTER.- See Also:
Control.CENTER,Control.TOP,Control.BOTTOM
-
buttonKeys
public int[] buttonKeys
If you set the buttonCaptions array in the construction, you can also set this public field to an int array of the keys that maps to each of the buttons. For example, if you set the buttons to {"Ok","Cancel"}, you can map the enter key for the Ok button and the escape key for the Cancel button by assigning:buttonKeys = new int[]{SpecialKeys.ENTER,SpecialKeys.ESCAPE};Note that ENTER is also handled as ACTION, since the ENTER key is mapped to ACTION under some platforms.- Since:
- TotalCross 1.27
-
showExceptionTitle
public static java.lang.String showExceptionTitle
Title shown in the showException dialog.
-
-
Constructor Detail
-
MessageBox
public MessageBox(java.lang.String title, java.lang.String msg)Constructs a message box with the text and one "Ok" button. The text may be separated by '\n' as the line delimiters; otherwise, it is automatically splitted if its too big to fit on screen.
-
MessageBox
public MessageBox(java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions)Constructs a message box with the text and the specified button captions. The text may be separated by '\n' as the line delimiters; otherwise, it is automatically splitted if its too big to fit on screen. if buttonCaptions is null, no buttons are displayed and you must dismiss the dialog by calling unpop or by setting the delay using setUnpopDelay method
-
MessageBox
public MessageBox(Image image, java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions)
-
MessageBox
public MessageBox(java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions, boolean allSameWidth)Constructs a message box with the text and the specified button captions. The text may be separated by '\n' as the line delimiters; otherwise, it is automatically splitted if its too big to fit on screen. If buttonCaptions is null, no buttons are displayed and you must dismiss the dialog by calling unpop or by setting the delay using setUnpopDelay method. The parameters allSameWidth is the same as in the constructor for PushButtonGroup.- Since:
- TotalCross 1.27
-
MessageBox
public MessageBox(Image image, java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions, boolean allSameWidth)
-
MessageBox
public MessageBox(java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions, int gap, int insideGap)Constructs a message box with the text and the specified button captions. The text may be separated by '\n' as the line delimiters; otherwise, it is automatically splitted if its too big to fit on screen. If buttonCaptions is null, no buttons are displayed and you must dismiss the dialog by calling unpop or by setting the delay using setUnpopDelay method. The new parameters gap and insideGap are the same as in the constructor for PushButtonGroup.- Since:
- SuperWaba 4.11
-
MessageBox
public MessageBox(Image image, java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions, int gap, int insideGap)
-
MessageBox
public MessageBox(Image image, java.lang.String title, java.lang.String text, java.lang.String[] buttonCaptions, boolean allSameWidth, int gap, int insideGap)
Constructs a message box with the text and the specified button captions. The text may be separated by '\n' as the line delimiters; otherwise, it is automatically splitted if its too big to fit on screen. If buttonCaptions is null, no buttons are displayed and you must dismiss the dialog by calling unpop or by setting the delay using setUnpopDelay method. The parameters allSameWidth, gap and insideGap are the same as in the constructor for PushButtonGroup.- Since:
- TotalCross 1.27
-
-
Method Detail
-
setText
public void setText(java.lang.String text)
This method can be used to set the text AFTER the dialog was shown. However, the dialog will not be resized.- Since:
- TotalCross 1.3
-
setImage
public void setImage(Image image)
-
onPopup
public void onPopup()
Description copied from class:WindowPlaceholder called imediatly before the popup began. The default implementation does nothing.
-
getButton
public Button getButton(int index)
Return the MessageBox buttons, so you can add events to it.
-
reposition
public void reposition()
Description copied from class:ControlReposition this control, calling again setRect with the original parameters.- Overrides:
repositionin classControl
-
setIcon
public void setIcon(Image icon) throws ImageException
Set an icon to be shown in the MessageBox's title, at left. It only works if there's a title. If you really need an empty title, pass as title a String with a couple of spaces, like " ". The icon's width and height will be set to title's font ascent.- Throws:
ImageException- Since:
- TotalCross 1.3
-
setTextAlignment
public void setTextAlignment(int align)
Sets the alignment for the text. Must be CENTER (default), LEFT or RIGHT
-
setUnpopDelay
public void setUnpopDelay(int unpopDelay)
sets a delay for the unpop of this dialog
-
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.
-
onEvent
public void onEvent(Event e)
handle scroll buttons and normal buttons
-
getPressedButtonIndex
public int getPressedButtonIndex()
Returns the pressed button index, starting from 0
-
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.
-
showException
public static void showException(java.lang.Throwable t, boolean dumpToConsole)Shows the exception, with its name, message and stack trace in a new MessageBox.- Since:
- TotalCross 1.0
-
onFontChanged
protected void onFontChanged()
Description copied from class:ControlCalled after a setFont- Overrides:
onFontChangedin classControl
-
setDelayToShowButton
public void setDelayToShowButton(int ms)
Calling this method will make the buttons initially hidden and will show them after the specified number of milisseconds. Here's a sample:MessageBox mb = new MessageBox("Novo Tweet!",tweet); mb.setDelayToShowButton(7000); mb.popup();- Since:
- TotalCross 1.53
-
-