public class Window extends Container
A window cannot be added to a container; use popup or popupNonBlocking to show it on screen. Trying to add it to a container will raise a RuntimeException.
The following example creates a popup window class:
class TestWindow extends Window { Button btnHi; public TestWindow() { super("Test",RECT_BORDER); // with caption and borders setRect(CENTER,CENTER,Settings.screenWidth/2,Settings.screenHeight/4); add(btnHi=new Button("Hi!"),CENTER,CENTER); } public void onEvent(Event event) { if (event.type == ControlEvent.PRESSED && event.target == btnHi) unpop(); // a WINDOW_CLOSED event will be posted to this PARENT window. } }To use it in the normal way (blocking):
public class Launcher extends MainWindow { Button btn; public void onEvent(Event e) { if (e.target == btn) { TestWindow tw = new TestWindow(); tw.popup(); // this line is only executed after the window is closed. } } }To use it non-blocking (the execution continues right after the popup command, even with the window still open):
public class Launcher extends MainWindow { TestWindow tw; public void initUI() { tw = new TestWindow(); tw.popupNonBlocking(); // this line is executed immediately } public void onEvent(Event event) { if (event.target == tw && event.type == ControlEvent.WINDOW_CLOSED) { // any stuff break; } } }Blocking popup may be use in InputBox/MessageBox classes, while non-blocking popup is used in MenuBar and other classes.
Important note: you can't use popup with a delay to unpop it. In this case, the correct would be to use popupNonBlocking:
mb = new MessageBox(...); mb.popupNonBlocking(); Vm.sleep(5000); // or do something else mb.unpop;If you use popup in this specific case, the Vm will hang.
Control.TranslucentShape
Modifier and Type | Field and Description |
---|---|
protected ControlEvent |
_controlEvent |
protected DragEvent |
_dragEvent |
protected Control |
_focus |
protected KeyEvent |
_keyEvent |
protected MouseEvent |
_mouseEvent |
protected MultiTouchEvent |
_multiEvent |
protected PenEvent |
_penEvent |
protected static int |
androidBorderThickness |
protected boolean |
beepIfOut
When this window is the top most and the user clicks outside, a beep is thrown.
|
protected boolean |
blocking
True if the last popup mode was blocking.
|
protected byte |
borderStyle
The window's border style
|
static boolean |
cancelPenUp
If true, the next pen_up event will be ignored.
|
protected boolean |
canDrag
If true (default), the user can drag this window around
|
static int |
dragThreshold |
boolean |
fadeOtherWindows
Set to true to make the other windows be faded when this window appears.
|
static int |
fadeValue
The value used to fade the other windows.
|
Control |
firstFocus
the control that should get focus when a focus traversal key is pressed and none have focus
|
static boolean |
flickEnabled
Deprecated.
Flick is now enabled by default; just remove the reference to it.
|
protected Control |
focusOnPenUp |
int |
footerColor
Set the header and the footer colors when in Android style and border type is ROUND_BORDER.
|
protected int |
footerH |
int |
gradientTitleEndColor
The starting and ending colors used to fill the gradient title.
|
int |
gradientTitleStartColor
The starting and ending colors used to fill the gradient title.
|
int |
headerColor
Set the header and the footer colors when in Android style and border type is ROUND_BORDER.
|
protected Control |
highlighted |
protected boolean |
highResPrepared
Deprecated.
|
static byte |
HORIZONTAL_GRADIENT
To be used in setBorderStyle.
|
static int |
ignoreEventOfType
Used internally.
|
static KeyListener |
keyHook
A key listener that have priority over all other listeners.
|
static int |
lastShiftY |
protected Container |
lastSwappedContainer
Used in the swap method
|
protected Container |
mainSwapContainer
Used in the swap method
|
protected Control |
menubar
The window's menu bar
|
protected boolean |
multiTouching |
static boolean |
needsPaint
True if some area of any window is invalidated
|
static byte |
NO_BORDER
To be used in setBorderStyle
|
static int |
ORIENTATION_INVERTED |
static int |
ORIENTATION_LANDSCAPE |
static int |
ORIENTATION_PORTRAIT
Force the orientation during runtime.
|
protected boolean |
popped
Used in popup
|
static byte |
RECT_BORDER
To be used in setBorderStyle
|
static boolean |
repaintOnSwap
During a swap, the container is repainted.
|
static UIRobot |
robot
The UIRobot instance that is being used to record or play events.
|
static byte |
ROUND_BORDER
To be used in setBorderStyle.
|
protected Rect |
rTitle |
boolean |
sameBackgroundColor
Use the same color in border and in body
|
static int |
shiftH |
static int |
shiftY |
static int |
SIP_BOTTOM
Used to place the virtual keyboard on bottom of screen.
|
static int |
SIP_HIDE
Used to hide the virtual keyboard
|
static int |
SIP_SHOW
Used to show the virtual keyboard, without changing the position
|
static int |
SIP_TOP
Used to place the virtual keyboard on top of screen.
|
static byte |
TAB_BORDER
To be used in setBorderStyle
|
static byte |
TAB_ONLY_BORDER
To be used in setBorderStyle
|
java.lang.String |
tempTitle
A temporary title that will be displayed when this Windows pops up.
|
protected java.lang.String |
title
Window's title
|
int |
titleAlign
The title horizontal alignment in the Window's title area.
|
int |
titleColor
The title color.
|
protected Font |
titleFont
Font for the title.
|
int |
titleGap
A vertical gap used to increase the title area.
|
protected static Window |
topMost
The last poped up window.
|
static byte |
VERTICAL_GRADIENT
To be used in setBorderStyle.
|
static Vector |
zStack
Stack of poped up windows.
|
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, lastH, lastScreenWidth, lastW, numChildren, started, tabOrder, tail, TRANSITION_TIME
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 and Description |
---|
Window()
Constructs a window with no title and no border.
|
Window(java.lang.String title,
byte borderStyle)
Constructs a window with the given title and border.
|
Modifier and Type | Method and Description |
---|---|
void |
_doPaint()
Called by the VM to repaint an area.
|
void |
_postEvent(int type,
int key,
int x,
int y,
int modifiers,
int timeStamp)
Called by the VM to post key and pen events.
|
static void |
destroyZStack()
This method is for internal use only.
|
void |
drawHighlight()
Avoid drawing the highlight on a Window
|
byte |
getBorderStyle()
Returns the border style of this window.
|
Rect |
getClientRect()
Returns the client rect, ie, the rect minus the border and title area, in relative coords
|
protected void |
getClientRect(Rect r)
Returns the client rect, ie, the rect minus the border and title area, in relative coords
In this version, you provide the created Rect to be filled with the coords.
|
static int |
getDefaultDragThreshold() |
Control |
getFocus()
Returns the focus control for this window.
|
Control |
getHighlighted()
Gets the currently highlighted control.
|
static int |
getPopupCount()
Returns the number of windows that are popped up.
|
int |
getPreferredHeight()
Returns the size of the title if any plus the size of the border.
|
int |
getPreferredWidth()
Returns the size of the title if any plus the size of the border.
|
Font |
getTitleFont()
Gets the title font
|
static Window |
getTopMost()
Returns the topmost window
|
protected boolean |
handleFocusChangeKeys(KeyEvent ke)
Called by the main event handler to handle the focus change keys.
|
static boolean |
isScreenShifted() |
static boolean |
isSipShown() |
static boolean |
isSipShown4D() |
boolean |
isTopMost()
Returns true if this window is the top-level window
|
boolean |
isVisible()
True if this is the topmost window
|
protected void |
loadBehind()
This method repaints all windows from bottom to top.
|
void |
makeUnmovable()
Makes this window static, i.e., the user will not be able to move it around
the screen by dragging the title area.
|
protected boolean |
onClickedOutside(PenEvent event)
called when the user clicks outside the bounds of this window.
|
protected void |
onPopup()
Placeholder called imediatly before the popup began.
|
static void |
onRobotKey()
Called when a robot key is pressed.
|
protected void |
onUnpop()
Placeholder called imediatly before the unpop began.
|
protected void |
paintTitle(java.lang.String title,
Graphics gg)
Paints the title and border.
|
void |
paintWindowBackground(Graphics gg) |
void |
popup()
Pops up this window, blocking the execution until the window closes.
|
void |
popupMenuBar()
Open the menu bar that is associated with this window
|
void |
popupNonBlocking()
Pops up this window, but the program execution continues right after, before the window is dismissed.
|
protected void |
postPopup()
Placeholder called after the popup is done and after the repaint of this window.
|
void |
postPressedEvent()
Posts a ControlEvent.PRESSED event on the focused control.
|
protected void |
postUnpop()
Placeholder called after the unpop is done and after the repaint of the other window.
|
static void |
pumpEvents()
Let the VM handle all the events in the event queue.
|
void |
removeFocus()
Calling this method will cause a FOCUS_OUT control event
to be posted to the window's current focus control (if one exists)
|
static void |
repaintActiveWindows()
Repaints the window stack from 0 to zStack.size().
|
void |
resize()
This method resizes the Window to the needed bounds, based on added childs.
|
void |
resizeHeight()
This method resizes the Container's width to the needed bounds, based on added childs.
|
void |
resizeWidth()
This method resizes the Container's width to the needed bounds, based on added childs.
|
void |
screenResized()
Called when the screen is resized, probably caused by a rotation.
|
void |
setBorderStyle(byte borderStyle)
Sets the border borderStyle.
|
static void |
setDeviceTitle(java.lang.String title)
Sets the title text in the task bar for non-Palm OS operating systems.
|
void |
setFocus(Control c)
Sets focus to the given control.
|
void |
setGrabPenEvents(Control c)
Set to a control to redirect all pen events directly to it.
|
void |
setHighlighted(Control c)
Sets the currently highlighted control which will gain focus if the ACTION button
is pressed.
|
void |
setMenuBar(Control menubar)
Sets the menu bar for this window
|
static void |
setOrientation(int orientation) |
static void |
setSIP(int sipOption,
Control edit,
boolean numeric)
Used to set the position of the Soft Input Panel.
|
void |
setTitle(java.lang.String title)
Sets the title and call repaint.
|
void |
setTitleFont(Font titleFont)
Sets the title font
|
void |
shiftScreen(Control c,
int deltaY) |
void |
swap(Container newContainer)
Used to swap containers from the Window.
|
protected void |
swapFocus(Control c)
Changes the focus to the desired control, without posting FOCUS_IN and FOCUS_OUT events
|
void |
unpop()
Hides this window.
|
void |
validate()
Calls _doPaint if the window needs painting.
|
add, add, add, add, add, broadcastEvent, clear, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getChildren, getChildrenCount, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onColorsChanged, onPaint, onRemove, onSwapFinished, paintChildren, remove, removeAll, setBorderRadius, setEnabled, setFocusTraversable, setHighlighting, setInsets, setPressColor, setPressed, swapToTopmostWindow
_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, onEvent, onFontChanged, 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
public static boolean needsPaint
protected java.lang.String title
protected boolean beepIfOut
protected static Window topMost
protected Font titleFont
protected byte borderStyle
protected Control menubar
protected boolean canDrag
@Deprecated protected boolean highResPrepared
public java.lang.String tempTitle
@Deprecated public static boolean flickEnabled
protected Control _focus
protected Control focusOnPenUp
public Control firstFocus
protected Rect rTitle
protected Control highlighted
protected int footerH
public boolean sameBackgroundColor
public static boolean cancelPenUp
protected boolean blocking
public int gradientTitleStartColor
HORIZONTAL_GRADIENT
,
VERTICAL_GRADIENT
public int gradientTitleEndColor
HORIZONTAL_GRADIENT
,
VERTICAL_GRADIENT
public int titleColor
public int titleGap
public int titleAlign
public int headerColor
public int footerColor
public boolean fadeOtherWindows
public static int fadeValue
public static UIRobot robot
public static boolean repaintOnSwap
protected static int androidBorderThickness
protected boolean popped
protected Container mainSwapContainer
protected Container lastSwappedContainer
public static final byte NO_BORDER
public static final byte RECT_BORDER
public static final byte ROUND_BORDER
public static final byte TAB_BORDER
public static final byte TAB_ONLY_BORDER
public static final byte HORIZONTAL_GRADIENT
public static final byte VERTICAL_GRADIENT
public static final int SIP_HIDE
public static final int SIP_TOP
public static final int SIP_BOTTOM
public static final int SIP_SHOW
public static Vector zStack
public static int ignoreEventOfType
Event.clearQueue(int)
protected KeyEvent _keyEvent
protected PenEvent _penEvent
protected ControlEvent _controlEvent
protected DragEvent _dragEvent
protected MouseEvent _mouseEvent
protected MultiTouchEvent _multiEvent
protected boolean multiTouching
public static int shiftY
public static int shiftH
public static int lastShiftY
public static int dragThreshold
public static KeyListener keyHook
public static final int ORIENTATION_PORTRAIT
public static final int ORIENTATION_LANDSCAPE
public static final int ORIENTATION_INVERTED
public Window()
public Window(java.lang.String title, byte borderStyle)
public void setGrabPenEvents(Control c)
public void setTitleFont(Font titleFont)
public Font getTitleFont()
public void setTitle(java.lang.String title)
public static final void setDeviceTitle(java.lang.String title)
public static final void setOrientation(int orientation)
public void setBorderStyle(byte borderStyle)
setBorderStyle
in class Container
NO_BORDER
,
RECT_BORDER
,
ROUND_BORDER
,
TAB_BORDER
,
TAB_ONLY_BORDER
,
HORIZONTAL_GRADIENT
,
VERTICAL_GRADIENT
public byte getBorderStyle()
getBorderStyle
in class Container
public void makeUnmovable()
public void setFocus(Control c)
public void removeFocus()
protected void swapFocus(Control c)
public Control getFocus()
setFocus(totalcross.ui.Control)
protected boolean onClickedOutside(PenEvent event)
beepIfOut
is true, then a beep is played and nothing more happens.public void validate()
public final void _postEvent(int type, int key, int x, int y, int modifiers, int timeStamp)
protected void getClientRect(Rect r)
getClientRect
in class Container
public Rect getClientRect()
getClientRect
in class Container
Container.getClientRect(Rect)
protected void paintTitle(java.lang.String title, Graphics gg)
public void paintWindowBackground(Graphics gg)
public void _doPaint()
public void unpop()
public static void pumpEvents()
while(someCondition) { Event.pumpEvents(); }
public boolean isTopMost()
public static Window getTopMost()
protected void onPopup()
protected void postPopup()
protected void onUnpop()
protected void postUnpop()
public boolean isVisible()
public static final void setSIP(int sipOption, Control edit, boolean numeric)
sipOption
- One of the SIP_xxx values.edit
- control (Edit or MultiEdit) (iPhone only)numeric
- enable numeric keyboard (Android only)SIP_HIDE
,
SIP_SHOW
,
SIP_TOP
,
SIP_BOTTOM
,
Edit.mapKeys(java.lang.String, java.lang.String)
public void setMenuBar(Control menubar)
public void popupMenuBar()
protected void loadBehind()
public static void destroyZStack()
public void swap(Container newContainer)
public int getPreferredWidth()
getPreferredWidth
in class Control
public int getPreferredHeight()
getPreferredHeight
in class Control
public static void repaintActiveWindows()
protected boolean handleFocusChangeKeys(KeyEvent ke)
public void setHighlighted(Control c)
public Control getHighlighted()
public void drawHighlight()
public void popupNonBlocking()
public void popup()
public void postPressedEvent()
postPressedEvent
in class Control
public void screenResized()
public void resize()
public class TestWindow extends Window { public TestWindow() { ... call constructor setRect(CENTER,CENTER,Screen.width-40,1000); // height will be resized later } public void initUI() { setInsets(5,5,5,5); ... add controls resize(); } }In this sample, since the height is variable, you can't use BOTTOM on
y
nor FILL on height
,
otherwise resize will not work as expected. Same counts if you have a variable width.resize
in class Container
Container.resizeWidth()
,
Container.resizeHeight()
public void resizeWidth()
Container
// this sample will center two buttons of different sizes on screen Container c = new Container(); add(c, CENTER,BOTTOM,1000,1000); c.add(new Button("Ok"),LEFT,TOP); c.add(new Button("Cancel"),AFTER+5,SAME); c.resize();Note: differently of Window.resize, this method does not call setRect again, it only changes the width by direct assignment.
resizeWidth
in class Container
Container.resize()
,
Container.resizeHeight()
public void resizeHeight()
Container
// this sample will center two buttons of different sizes on screen Container c = new Container(); add(c, CENTER,BOTTOM,1000,1000); c.add(new Button("Ok"),LEFT,TOP); c.add(new Button("Cancel"),AFTER+5,SAME); c.resize();Note: differently of Window.resize, this method does not call setRect again, it only changes the height by direct assignment.
resizeHeight
in class Container
Container.resizeWidth()
,
Container.resize()
public static int getDefaultDragThreshold()
public static int getPopupCount()
public static void onRobotKey()
Settings.deviceRobotSpecialKey
public void shiftScreen(Control c, int deltaY)
public static boolean isScreenShifted()
public static boolean isSipShown()
public static boolean isSipShown4D()