|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--waba.ui.Control
|
+--waba.ui.Container
|
+--waba.ui.Window
Window is a "floating" top-level window. This class IS functional like a modal window.
Attention! Is not a good practice use this class as a Container, adding it to other Window. Use this class only as a popup window, or strange things can happen!
Important: the popupModal method is not blocking, but the popupBlockingModal is
blocking. In other words, after you call popupModal, the process
continues immediately to the next line. You'll need to catch the WINDOW_CLOSED event
to do things after the user had really closed the window.
If you want to block until the Window is dismissed, just use popupBlockingModal
Very important! popupBlockingModal can't be used on the program startup, ie, in the
constructor, onStart or other application initialization methods. The main event loop must have been initialized
in order to use it. Otherwise, the whole application will just hang!
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 by the Window class.
}
}
To use it (non-blocking):
public class Main extends MainWindow
{
TestWindow tw;
public void onStart()
{
tw = new TestWindow();
tw.dontSaveBehind(true); // dont save behind (theres still nothing to be saved) and call repaint when window is closed - only needed when opening windows in onStart
tw.popupModal();
// this line is executed immediately
}
public void onEvent(Event event)
{
if (event.target == tw && event.type == ControlEvent.WINDOW_CLOSED)
{
// any stuff
}
}
}
To use it (blocking):
public class Main extends MainWindow
{
Button btn;
public void onEvent(Event e)
{
if (e.target == btn)
{
TestWindow tw = new TestWindow();
tw.popupBlockingModal();
// this line is only executed after the window is closed.
}
}
}
PopupBlockingModal may be use in InputDialog/MessageBox classes, while PopupModal
is used in MenuBar and other classes.
Important note: you can't use popupBlockingModal with a delay to unpop it. In this case, the correct would be to use popupModal:
mb = new MessageBox(...); mb.popupModal(); Vm.sleep(5000); mb.unpop;If you use popupBlockingModal in this specific case, the Vm will hang.
There's also a clipping issue regarding the Window class. Do NOT create Windows with the same width or height of the screen, otherwise, if the user try to drag it beyond screen boundaries, the device will hang. This is a problem in the complex drawBitmap routine, and can be easily avoided by setting the window's bounds at least 1 pixel less than the screen bounds.
| Field Summary | |
protected static ControlEvent |
_controlEvent
|
protected Control |
_focus
|
protected static KeyEvent |
_keyEvent
|
protected static PenEvent |
_penEvent
|
protected boolean |
beepIfOut
When this window is the top most and the user clicks outside, a beep is thrown. |
static int |
blockingCount
|
protected byte |
borderStyle
The window's border style |
protected boolean |
canDrag
If true (default), the user can drag this window around |
boolean |
eraseBackgroundNow
Force the background erasing. |
protected boolean |
flicker
If true, the background is erased on each paint. |
static int |
HIDE_STATE
Used to hide the showing state in Palm OS |
protected Control |
highlighted
|
protected boolean |
highResPrepared
Must set to true if your Window is prepared for 320x320 resolutions. |
protected Image |
imgCovered
The snapshot of the area covered by this window. |
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 |
needsPaint
True if some area of the window is invalidated |
static byte |
NO_BORDER
To be used in setBorderStyle |
static byte |
RECT_BORDER
To be used in setBorderStyle |
static byte |
ROUND_BORDER
To be used in setBorderStyle. |
static byte |
TAB_BORDER
To be used in setBorderStyle |
static byte |
TAB_ONLY_BORDER
To be used in setBorderStyle |
protected java.lang.String |
title
Window's title |
protected Font |
titleFont
Font for the title. |
protected static Window |
topMost
The last poped up window. |
static int |
VK_BOTTOM
Used to place the keyboard on bottom of screen |
static int |
VK_HIDE
Used to hide the virtual keyboard |
static int |
VK_SHOW
Used to show the virtual keyboard, without changing the position |
static int |
VK_TOP
Used to place the keyboard on top of screen |
static Vector |
zStack
Stack of poped up windows. |
| Fields inherited from class waba.ui.Container |
BORDER_LOWERED,
BORDER_NONE,
BORDER_RAISED,
BORDER_SIMPLE,
children,
lastH,
lastW,
lastX,
lastY,
parentWindow,
started,
tabOrder,
tail |
| Fields inherited from class waba.ui.Control |
AFTER,
appId,
appObj,
asContainer,
asWindow,
backColor,
backDis,
BEFORE,
BOTTOM,
CENTER,
clearValueInt,
clearValueStr,
enabled,
FILL,
FIT,
fm,
fmH,
focusLess,
focusTraversable,
font,
foreColor,
foreDis,
height,
highlightRectsCount,
isHighlighting,
LEFT,
parent,
PREFERRED,
RANGE,
RIGHT,
SAME,
TOP,
uiCE,
uiFlat,
uiPalm,
uiVista,
visible,
width,
x,
x2,
y,
y2 |
| Constructor Summary | |
Window()
Constructs a window. |
|
Window(java.lang.String title,
byte borderStyle)
Constructs a window with the given title and border borderStyle. |
|
| Method Summary | |
void |
_doPaint()
paints the top-level window. called by MainWindow |
void |
_doPaint(int x,
int y,
int width,
int height)
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. |
void |
_postSoundEvent(SoundClipEvent event)
Called by the VM to post sound related events. |
protected void |
damageRect(int x,
int y,
int width,
int height)
Adds a damage rectangle to the current list of areas that need repainting. |
static void |
destroyZStack()
this method is for internal use only. calling it directly will cause the VM to crash. |
void |
dontSaveBehind(boolean repaintOnClose)
Sets the saveBehindWhenPopup flag to false. |
void |
drawHighlight()
Avoid drawing the highlight on a Window |
Rect |
getClientRect()
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. |
void |
getClientRect(Rect r)
Returns the client rect, ie, the rect minus the border and title area, in relative coords |
Control |
getFocus()
Returns the focus control for this window. |
Control |
getHighlighted()
Gets the currently highlighted control. |
Image |
getOffScreen()
Returns the image that is used for the offscreen (double buffering). if there is no double buffer or an out of memory problem occurs, returns null. |
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. |
static Window |
getTopMost()
returns the topmost window |
protected boolean |
handleFocusChangeKeys(KeyEvent ke)
Called by the main event handler to handle the focus change keys. |
boolean |
isTopMost()
returns true if this window is the top-level window |
boolean |
isVisible()
true if this is the topmost window |
protected void |
loadBehind(boolean release)
This method loads the saved area behind of the current window. |
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(int x,
int y)
called when the user clicks outside the bounds of this window. must return true if the event was handled, false otherwise. |
protected void |
onPopup()
Placeholder called imediatly before the popup began. the default implementation does nothing. |
protected void |
onUnpop()
Placeholder called imediatly before the unpop began. the default implementation does nothing. |
protected void |
paintTitle(java.lang.String title,
Graphics gg)
paints the title immediatly. |
void |
popupBlockingModal()
Pops up this window, blocking the program execution until the window closes. |
protected void |
popupMenuBar()
Open the menu bar that is associated with this window |
void |
popupModal()
Pops up this window, but the program execution continues right after. |
protected void |
postPopup()
Placeholder called after the popup is done and after the repaint of this window. the default implementation does nothing. |
protected 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. the default implementation does nothing. |
static void |
pumpEvents()
Let the VM handle all the events in the event queue. |
protected void |
saveBehind()
This method tries to save the area behind the window before it is popped up. |
void |
setBorderStyle(byte borderStyle)
sets the border borderStyle. use the constants XXXX_BORDER. sets the flag border accordingly to the borderStyle. |
void |
setDoubleBuffer(boolean doubleBuf)
Sets true if we have to use a double buffer to paint the screen. |
void |
setFocus(Control c)
Sets focus to the given control. |
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 |
void |
setStatePosition(int x,
int y)
Used to set the position where the status chars will be displayed. |
void |
setTitle(java.lang.String title)
sets the title and call repaint. if you want an imediate repaint, call paintTitle. |
void |
setTitleFont(Font titleFont)
sets the title font |
void |
swap(Container newContainer)
Used to swap containers from the |
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. |
static void |
updateScreen()
This method causes the immediate screen update. |
void |
validate()
Calls _doPaint if the window needs painting. |
| Methods inherited from class waba.ui.Container |
add,
add,
add,
broadcastEvent,
clear,
findChild,
getChildren,
onAdd,
onColorsChanged,
onPaint,
onRemove,
onStart,
paintChildren,
remove,
setEnabled,
setHighlighting,
swapToTopmostWindow |
| Methods inherited from class waba.ui.Control |
addTimer,
changeHighlighted,
contains,
createGraphics,
getAbsoluteRect,
getBackColor,
getFont,
getFontMetrics,
getForeColor,
getNext,
getParent,
getParentWindow,
getPos,
getRect,
getSize,
isDisplayed,
isEnabled,
onBoundsChanged,
onEvent,
onFontChanged,
onWindowPaintFinished,
postEvent,
removeTimer,
repaint,
repaintNow,
requestFocus,
setBackColor,
setBackForeColors,
setFocusLess,
setFont,
setForeColor,
setRect,
setRect,
setRect,
setVisible,
translateFromOrigin,
uiStyleChanged |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
protected boolean needsPaint
protected java.lang.String title
protected boolean beepIfOut
protected boolean flicker
protected static Window topMost
protected Font titleFont
protected byte borderStyle
protected Control menubar
protected boolean canDrag
public boolean eraseBackgroundNow
protected Image imgCovered
protected boolean highResPrepared
protected Control _focus
protected Control highlighted
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 int HIDE_STATE
public static final int VK_HIDE
public static final int VK_TOP
public static final int VK_BOTTOM
public static final int VK_SHOW
public static Vector zStack
protected static KeyEvent _keyEvent
protected static PenEvent _penEvent
protected static ControlEvent _controlEvent
public static int blockingCount
| Constructor Detail |
public Window()
public Window(java.lang.String title,
byte borderStyle)
| Method Detail |
public void setTitleFont(Font titleFont)
public void setTitle(java.lang.String title)
public void setBorderStyle(byte borderStyle)
public void setDoubleBuffer(boolean doubleBuf)
public Image getOffScreen()
public void makeUnmovable()
public void setFocus(Control c)
protected void swapFocus(Control c)
public Control getFocus()
setFocus(waba.ui.Control)
protected void damageRect(int x,
int y,
int width,
int height)
protected boolean onClickedOutside(int x,
int y)
beepIfOut
is true, then a beep is played and nothing more happens.public void validate()
public void _postEvent(int type,
int key,
int x,
int y,
int modifiers,
int timeStamp)
public void _postSoundEvent(SoundClipEvent event)
public void getClientRect(Rect r)
public Rect getClientRect()
protected void paintTitle(java.lang.String title,
Graphics gg)
public void _doPaint(int x,
int y,
int width,
int height)
public final void unpop()
public static void pumpEvents()
while(someCondition)
{
Event.pumpEvents();
}
public void _doPaint()
public boolean isTopMost()
public static Window getTopMost()
protected void onPopup()
protected void postPopup()
protected void onUnpop()
protected void postUnpop()
public boolean isVisible()
public void setStatePosition(int x,
int y)
x - the absolute coordinate to position the control (relative coordinates are now allowed), or HIDE_STATE.y - the absolute coordinate to position the control (relative coordinates are now allowed), or HIDE_STATE.public void setMenuBar(Control menubar)
protected void popupMenuBar()
public void dontSaveBehind(boolean repaintOnClose)
protected void saveBehind()
protected void loadBehind(boolean release)
release - if true, the memory used is releasedpublic static void destroyZStack()
public void swap(Container newContainer)
public int getPreferredWidth()
public int getPreferredHeight()
public static void updateScreen()
protected boolean handleFocusChangeKeys(KeyEvent ke)
public void setHighlighted(Control c)
public Control getHighlighted()
public void drawHighlight()
public void popupModal()
public void popupBlockingModal()
protected void postPressedEvent()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||