waba.ui
Class Window

java.lang.Object
  |
  +--waba.ui.Control
        |
        +--waba.ui.Container
              |
              +--waba.ui.Window
Direct Known Subclasses:
Calculator, Calendar, Calendar, ChoicesDialog, CompareWindow, InputDialog, Keyboard, MainWindow, MenuBar, MessageBox, MultiEditMenu, PopList, PopupMenu

public class Window
extends Container

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
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.
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

needsPaint

protected boolean needsPaint
True if some area of the window is invalidated

title

protected java.lang.String title
Window's title

beepIfOut

protected boolean beepIfOut
When this window is the top most and the user clicks outside, a beep is thrown. Set this to false do disable the beep.

flicker

protected boolean flicker
If true, the background is erased on each paint. If false, you must take care of erasing the background

topMost

protected static Window topMost
The last poped up window.

titleFont

protected Font titleFont
Font for the title. Usually, MainWindow.defaultFont bolded

borderStyle

protected byte borderStyle
The window's border style

menubar

protected Control menubar
The window's menu bar

canDrag

protected boolean canDrag
If true (default), the user can drag this window around

eraseBackgroundNow

public boolean eraseBackgroundNow
Force the background erasing.

imgCovered

protected Image imgCovered
The snapshot of the area covered by this window.

highResPrepared

protected boolean highResPrepared
Must set to true if your Window is prepared for 320x320 resolutions. If false (default), the Window is doubled size (and centered) to make controls fit.

_focus

protected Control _focus

highlighted

protected Control highlighted

mainSwapContainer

protected Container mainSwapContainer
Used in the swap method

lastSwappedContainer

protected Container lastSwappedContainer
Used in the swap method

NO_BORDER

public static final byte NO_BORDER
To be used in setBorderStyle

RECT_BORDER

public static final byte RECT_BORDER
To be used in setBorderStyle

ROUND_BORDER

public static final byte ROUND_BORDER
To be used in setBorderStyle. Important: the pixels placed in the four edges are not correctly shown if the setDoubleBuffer is true for this window. If you really need to set as double buffer, better chose another border type.

TAB_BORDER

public static final byte TAB_BORDER
To be used in setBorderStyle

TAB_ONLY_BORDER

public static final byte TAB_ONLY_BORDER
To be used in setBorderStyle

HIDE_STATE

public static final int HIDE_STATE
Used to hide the showing state in Palm OS

VK_HIDE

public static final int VK_HIDE
Used to hide the virtual keyboard

VK_TOP

public static final int VK_TOP
Used to place the keyboard on top of screen

VK_BOTTOM

public static final int VK_BOTTOM
Used to place the keyboard on bottom of screen

VK_SHOW

public static final int VK_SHOW
Used to show the virtual keyboard, without changing the position

zStack

public static Vector zStack
Stack of poped up windows. Dont mess with this, unless you want to crash the VM!

_keyEvent

protected static KeyEvent _keyEvent

_penEvent

protected static PenEvent _penEvent

_controlEvent

protected static ControlEvent _controlEvent

blockingCount

public static int blockingCount
Constructor Detail

Window

public Window()
Constructs a window.

Window

public Window(java.lang.String title,
              byte borderStyle)
Constructs a window with the given title and border borderStyle.
Method Detail

setTitleFont

public void setTitleFont(Font titleFont)
sets the title font

setTitle

public void setTitle(java.lang.String title)
sets the title and call repaint. if you want an imediate repaint, call paintTitle.

setBorderStyle

public void setBorderStyle(byte borderStyle)
sets the border borderStyle. use the constants XXXX_BORDER. sets the flag border accordingly to the borderStyle.
Overrides:
setBorderStyle in class Container

setDoubleBuffer

public void setDoubleBuffer(boolean doubleBuf)
Sets true if we have to use a double buffer to paint the screen. This method only works on Palm OS. On other operating systems that work under SDL, the are no direct screen access, and everything is already drawn in a buffer. This method will be removed in future releases, when SDL gets ported to Palm OS. Thus, to prevent unnecessary large SDL buffers allocation and their copy, double-buffering is disabled on the following SDL based platforms : WindowsCE, PocketPC, Win32, Symbian, Posix

getOffScreen

public 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. Initializes the buffer if necessary. The SuperWaba versions based on SDL are using SDL_SWSURFACE surfaces which have an implicit double-buffering feature, use a Graphics on any window even the main window instead insofar drawings become visible at next window refresh only.

makeUnmovable

public 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. It just set the canDrag member to false.

setFocus

public void setFocus(Control c)
Sets focus to the given control. When a user types a key, the control with focus get the key event. At any given time, only one control in a window can have focus. Calling this method will cause a FOCUS_OUT control event to be posted to the window's current focus control (if one exists) and will cause a FOCUS_IN control event to be posted to the new focus control.

swapFocus

protected void swapFocus(Control c)
Changes the focus to the desired control, without posting FOCUS_IN and FOCUS_OUT events
Since:
SuperWaba 4.01

getFocus

public Control getFocus()
Returns the focus control for this window. This will be the same of focusedControl, unless the last one has been changed manually.
See Also:
setFocus(waba.ui.Control)

damageRect

protected void damageRect(int x,
                          int y,
                          int width,
                          int height)
Adds a damage rectangle to the current list of areas that need repainting.

onClickedOutside

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. If false is returned and beepIfOut is true, then a beep is played and nothing more happens.
Since:
SuperWaba 1.2

validate

public void validate()
Calls _doPaint if the window needs painting.
Since:
SuperWaba 4.0

_postEvent

public void _postEvent(int type,
                       int key,
                       int x,
                       int y,
                       int modifiers,
                       int timeStamp)
Called by the VM to post key and pen events.

_postSoundEvent

public void _postSoundEvent(SoundClipEvent event)
Called by the VM to post sound related events.

getClientRect

public void getClientRect(Rect r)
Returns the client rect, ie, the rect minus the border and title area, in relative coords
Overrides:
getClientRect in class Container

getClientRect

public 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.
Overrides:
getClientRect in class Container

paintTitle

protected void paintTitle(java.lang.String title,
                          Graphics gg)
paints the title immediatly.

_doPaint

public void _doPaint(int x,
                     int y,
                     int width,
                     int height)
Called by the VM to repaint an area. If doubleBuf is true, paints the whole screen in a buffer and draws it on screen.

unpop

public final void unpop()
Hides this window. Calling unpop when only the MainWindow is active does nothing.

pumpEvents

public static void pumpEvents()
Let the VM handle all the events in the event queue. This method is used to implement a blocking Window. Here is an example:
 while(someCondition)
 {
    Event.pumpEvents();
 }
 

_doPaint

public void _doPaint()
paints the top-level window. called by MainWindow

isTopMost

public boolean isTopMost()
returns true if this window is the top-level window

getTopMost

public static Window getTopMost()
returns the topmost window

onPopup

protected void onPopup()
Placeholder called imediatly before the popup began. the default implementation does nothing.

postPopup

protected void postPopup()
Placeholder called after the popup is done and after the repaint of this window. the default implementation does nothing.

onUnpop

protected void onUnpop()
Placeholder called imediatly before the unpop began. the default implementation does nothing.

postUnpop

protected void postUnpop()
Placeholder called after the unpop is done and after the repaint of the other window. the default implementation does nothing.

isVisible

public boolean isVisible()
true if this is the topmost window
Overrides:
isVisible in class Control

setStatePosition

public void setStatePosition(int x,
                             int y)
Used to set the position where the status chars will be displayed. The chars are 8x11 (or 16x22 if double density) pixels. This method must be called so the status can be displayed. These positions must be relative to this window, because they are absolute coordinates. If the user moves this Window, you must update the positions. Use setStatePosition(Window.HIDE_STATE,Window.HIDE_STATE) to remove the display of the state. Note: in SuperWaba 2.0, this only works on PalmOS >= 3.5.
Parameters:
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.

setMenuBar

public void setMenuBar(Control menubar)
sets the menu bar for this window

popupMenuBar

protected void popupMenuBar()
Open the menu bar that is associated with this window

dontSaveBehind

public void dontSaveBehind(boolean repaintOnClose)
Sets the saveBehindWhenPopup flag to false. If repaintOnClose is true, the window calls repaint on the parent window when it closes. This method is important if you popup a window on the onStart method before the MainWindow is drawn.

saveBehind

protected void saveBehind()
This method tries to save the area behind the window before it is popped up. It is used in the popupModal method so the area can be restored when the window is unpopped. If an out of memory error occurs, the window will be repainted instead of saved.
Since:
SuperWaba2.0beta4

loadBehind

protected void loadBehind(boolean release)
This method loads the saved area behind of the current window. It is automaticaly used in the unpop method.
Parameters:
release - if true, the memory used is released
Since:
SuperWaba2.0beta4

destroyZStack

public static void destroyZStack()
this method is for internal use only. calling it directly will cause the VM to crash.

swap

public void swap(Container newContainer)
Used to swap containers from the
Window. To restore the first container, pass null as parameter. See samples/ui/ContainerSwitch.

getPreferredWidth

public int getPreferredWidth()
Returns the size of the title if any plus the size of the border. Note that the value returned here does not handle the controls inside the window.
Overrides:
getPreferredWidth in class Control

getPreferredHeight

public int getPreferredHeight()
Returns the size of the title if any plus the size of the border. Note that the value returned here does not handle the controls inside the window.
Overrides:
getPreferredHeight in class Control

updateScreen

public static void updateScreen()
This method causes the immediate screen update. This is required for SDL, since the screen is saved in a buffer and then transfered to the screen.
Since:
SuperWaba 5.0

handleFocusChangeKeys

protected boolean handleFocusChangeKeys(KeyEvent ke)
Called by the main event handler to handle the focus change keys. Only called when Settings.keyboardFocusNavigation is true.
Since:
SuperWaba 5.5

setHighlighted

public void setHighlighted(Control c)
Sets the currently highlighted control which will gain focus if the ACTION button is pressed. It may be the same of the one that holds focus.
Since:
SuperWaba 5.5

getHighlighted

public Control getHighlighted()
Gets the currently highlighted control.
Since:
SuperWaba 5.5

drawHighlight

public void drawHighlight()
Avoid drawing the highlight on a Window
Overrides:
drawHighlight in class Control

popupModal

public void popupModal()
Pops up this window, but the program execution continues right after.
Since:
SuperWaba 5.5

popupBlockingModal

public void popupBlockingModal()
Pops up this window, blocking the program execution until the window closes.
Since:
SuperWaba 5.5

postPressedEvent

protected void postPressedEvent()
Posts a ControlEvent.PRESSED event on the focused control.
Since:
SuperWaba 5.8