waba.ui
Class Control

java.lang.Object
  |
  +--waba.ui.Control
Direct Known Subclasses:
Animation, BigNumber, Button, Check, Container, Edit, GPS, Label, ProgressBar, PushButtonGroup, Radio, SpinList, ToolTip

public class Control
extends Object
implements ISurface

Control is the base class for user-interface objects.


Field Summary
static int AFTER
          Constant used in param x/y in setRect.
 int appId
          Application defined constant.
protected  Container asContainer
           
protected  Window asWindow
           
protected  Color backColor
          Background color of this control.
protected  Color backDis
          Disabled fore and back colors
static int BEFORE
          Constant used in param x/y in setRect.
static int BOTTOM
          Constant used in param y in setRect.
static int CENTER
          Constant used in params x and y in setRect.
protected  boolean enabled
          True if the control is enabled (accepts events) or false if not
static int FILL
          Constant used in params width and height in setRect.
static int FIT
          Constant used in params width and height in setRect.
 FontMetrics fm
          The fontMetrics corresponding to the controls font.
protected  int fmH
          Equivalent to fm.getHeight().
protected  boolean focusLess
          If true, this control will receive pen and key events but will never gain focus
protected  Font font
          The font used by the control.
protected  Color foreColor
          Foreground color of this control.
protected  Color foreDis
          Disabled fore and back colors
protected  int height
          The control's height
static int LEFT
          Constant used in param x in setRect.
protected  Container parent
          The parent of the control.
static int PREFERRED
          Constant used in params width and height in setRect.
static int RANGE
           
static int RIGHT
          Constant used in param x in setRect.
static int SAME
          Constant used in params x/y/width/height in setRect.
static int TOP
          Constant used in param y in setRect.
protected  boolean visible
          True if the control is visible, false otherwise
protected  int width
          The control's width
protected  int x
          The control's x location
protected  int x2
          x+width-1
protected  int y
          The control's y location
protected  int y2
          y+height-1
 
Constructor Summary
protected Control()
          creates the font for this control as the same font of the MainWindow.
 
Method Summary
 Timer addTimer(int millis)
          Adds a timer to a control.
 boolean contains(int x, int y)
          Returns true if the given x and y coordinate in the parent's coordinate system is contained within this control.
 Graphics createGraphics()
          Creates a Graphics object which can be used to draw in the control.
 Rect getAbsoluteRect()
          Returns the absolute coordinates of this control relative to the MainWindow.
 Color getBackColor()
          Get the desired background color of this control.
 Font getFont()
          Gets the font of this conrol.
 FontMetrics getFontMetrics(Font font)
          Returns the font metrics for a given font.
 Color getForeColor()
          Get the desired foreground color of this control.
 Control getNext()
          Returns the next child in the parent's list of controls.
 Container getParent()
          Returns the control's parent container.
 Window getParentWindow()
          Returns the control's parent Window or topMost if there's no parent (eg: the control still not added to any container).
 Coord getPos()
          Returns the current position (x,y) of this control
 int getPreferredHeight()
          Returns the preffered height of this control.
 int getPreferredWidth()
          Returns the preffered width of this control.
 Rect getRect()
          Returns a copy of the control's rectangle.
 Coord getSize()
          Returns the current size (width,height) of this control
 boolean isDisplayed()
          Return true if the parent of this Control is added to somewhere.
 boolean isEnabled()
          Returns if this control can or not accept events
 boolean isVisible()
          Returns true if this control is visible, false otherwise
protected  void onBoundsChanged()
          Called after an setRect.
protected  void onColorsChanged(boolean colorsChanged)
          Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.
 void onEvent(Event event)
          Called to process key, pen, control and other posted events.
protected  void onFontChanged()
          Called after a setFont
 void onPaint(Graphics g)
          Called to draw the control.
protected  void onWindowPaintFinished()
          Called after the window has finished a paint.
 void postEvent(Event event)
          Posts an event.
 boolean removeTimer(Timer timer)
          Removes a timer from a control.
 void repaint()
          Marks the control for repaint.
 void repaintNow()
          Redraws the control immediately.
 void requestFocus()
          Sets the focus to this control
 void setBackColor(Color c)
          Set the background color of this control.
 void setBackForeColors(Color back, Color fore)
          Set the background and foreground colors at once
 void setEnabled(boolean enabled)
          Sets if this control can or not accept events.
 void setFocusLess(boolean on)
          Sets this control to be focusless.
 void setFont(Font font)
          sets the font of this conrol.
 void setForeColor(Color c)
          Set the foreground color of this control.
 void setRect(int x, int y, int width, int height)
          Sets or changes a control's position and size.
 void setRect(int x, int y, int width, int height, Control relative)
          Sets or changes a control's position and size.
 void setRect(Rect r)
          Sets or changes a control's position and size.
 void setVisible(boolean visible)
          Shows or "hides" this control.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, toString, wait, wait
 

Field Detail

x

protected int x
The control's x location

y

protected int y
The control's y location

width

protected int width
The control's width

height

protected int height
The control's height

parent

protected Container parent
The parent of the control.

enabled

protected boolean enabled
True if the control is enabled (accepts events) or false if not

font

protected Font font
The font used by the control.

fm

public FontMetrics fm
The fontMetrics corresponding to the controls font.

visible

protected boolean visible
True if the control is visible, false otherwise

foreColor

protected Color foreColor
Foreground color of this control. When the control is added, its foreground is set to be the same of the parent's.

backColor

protected Color backColor
Background color of this control. When the control is added, its background is set to be the same of the parent's.

appId

public int appId
Application defined constant. This constant is not used; its only a placeholder for the application so it can set to any value it wants

PREFERRED

public static final int PREFERRED
Constant used in params width and height in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: PREFERRED+2 or PREFERRED-1.

LEFT

public static final int LEFT
Constant used in param x in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: LEFT+2 or LEFT-1.

CENTER

public static final int CENTER
Constant used in params x and y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: CENTER+2 or CENTER-1.

RIGHT

public static final int RIGHT
Constant used in param x in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: RIGHT+2 or RIGHT-1.

TOP

public static final int TOP
Constant used in param y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: TOP+2 or TOP-1.

BOTTOM

public static final int BOTTOM
Constant used in param y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: BOTTOM+2 or BOTTOM-1.

FILL

public static final int FILL
Constant used in params width and height in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: FILL+2 or FILL-1. Note that FILL cannot be used with other x/y positioning constants.

BEFORE

public static final int BEFORE
Constant used in param x/y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: BEFORE+2 or BEFORE-1.

SAME

public static final int SAME
Constant used in params x/y/width/height in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: SAME+2 or SAME-1.

AFTER

public static final int AFTER
Constant used in param x/y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: AFTER+2 or AFTER-1.

FIT

public static final int FIT
Constant used in params width and height in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: FIT+2 or FIT-1. Note that FIT cannot be used with other x/y positioning constants. FIT will make the control fit between the desired position and the last added control position.

fmH

protected int fmH
Equivalent to fm.getHeight(). Since this is widely used...

foreDis

protected Color foreDis
Disabled fore and back colors

backDis

protected Color backDis
Disabled fore and back colors

x2

protected int x2
x+width-1

y2

protected int y2
y+height-1

focusLess

protected boolean focusLess
If true, this control will receive pen and key events but will never gain focus

RANGE

public static final int RANGE

asContainer

protected Container asContainer

asWindow

protected Window asWindow
Constructor Detail

Control

protected Control()
creates the font for this control as the same font of the MainWindow.
Method Detail

addTimer

public Timer addTimer(int millis)
Adds a timer to a control. Each time the timer ticks, a TIMER event will be posted to the control. The timer does not interrupt the program during its execution at the timer interval, it is scheduled along with application events. The timer object returned from this method can be passed to removeTimer() to remove the timer. Under Windows, the timer has a minimum resolution of 55ms due to the native Windows system clock resolution of 55ms. Under Palm OS, the minimum timer resolution is 10ms.
Parameters:
millis - the timer tick interval in milliseconds
See Also:
ControlEvent

removeTimer

public boolean removeTimer(Timer timer)
Removes a timer from a control. True is returned if the timer was found and removed and false is returned if the timer could not be found (meaning it was not active).

setFont

public void setFont(Font font)
sets the font of this conrol.

getFont

public Font getFont()
Gets the font of this conrol.

getPreferredWidth

public int getPreferredWidth()
Returns the preffered width of this control.

getPreferredHeight

public int getPreferredHeight()
Returns the preffered height of this control.

getFontMetrics

public FontMetrics getFontMetrics(Font font)
Returns the font metrics for a given font.

setRect

public void setRect(Rect r)
Sets or changes a control's position and size.

setRect

public void setRect(int x,
                    int y,
                    int width,
                    int height)
Sets or changes a control's position and size. The control used is the last control added. You may use the constants to make it easier. EG: here is an example of relative positioning:
 add(new Label("1"),CENTER,CENTER);
 add(new Label("2"),AFTER,SAME);
 add(new Label("3"),SAME,AFTER);
 add(new Label("4"),BEFORE,SAME);
 add(new Label("5"),BEFORE,BEFORE);
 
You will see this on screen:
 512
  43
 
Note: add(control, x,y) does: add(control); control.setRect(x,y,PREFERRED,PREFERRED);

Important! Always add the control to the container before doing a setRect.

The relative positioning does not work well if the control is placed outside screen bounds.


setRect

public void setRect(int x,
                    int y,
                    int width,
                    int height,
                    Control relative)
Sets or changes a control's position and size. The relative positioning will be made with the given control (relative). Note that in this case, only the SAME,BEFORE,AFTER are affected by the given control. You may use the constants to make it easier. EG: here is an example of relative positioning:

Important note: you can't use FILL/FIT with BEFORE/RIGHT/BOTTOM (for x,y).

 add(new Label("1"),CENTER,CENTER);
 add(new Label("2"),AFTER,SAME);
 add(new Label("3"),SAME,AFTER);
 add(new Label("4"),BEFORE,SAME);
 add(new Label("5"),BEFORE,BEFORE);
 
You will see this on screen:
 512
  43
 
Note: add(control, x,y) does: add(control); control.setRect(x,y,PREFERRED,PREFERRED);

Important! Always add the control to the container before doing a setRect.

The relative positioning does not work well if the control is placed outside screen bounds.


getSize

public Coord getSize()
Returns the current size (width,height) of this control

getPos

public Coord getPos()
Returns the current position (x,y) of this control

setVisible

public void setVisible(boolean visible)
Shows or "hides" this control. The "hide" works setting the control's size to zero. it remains attached to its container. unhidding restores the original size. you can change the controls size when hided if you want. calls repaint.

isVisible

public boolean isVisible()
Returns true if this control is visible, false otherwise

getRect

public Rect getRect()
Returns a copy of the control's rectangle. A control's rectangle defines its location and size.

getAbsoluteRect

public Rect getAbsoluteRect()
Returns the absolute coordinates of this control relative to the MainWindow.

getParentWindow

public Window getParentWindow()
Returns the control's parent Window or topMost if there's no parent (eg: the control still not added to any container).

getParent

public Container getParent()
Returns the control's parent container.

getNext

public Control getNext()
Returns the next child in the parent's list of controls.

contains

public boolean contains(int x,
                        int y)
Returns true if the given x and y coordinate in the parent's coordinate system is contained within this control.

repaint

public void repaint()
Marks the control for repaint. Important note: when you call repaint, the absolute area of the control regarding its parent Window is invalidated (marked for repaint); then, the next time a event (a keypress, a timer, a pen event) occurs, the screen is updated. If you call repaint and the control isn't effectively repainted, you have 2 choices: call Window._doPaint(), or, use Control.repaintNow.

repaintNow

public void repaintNow()
Redraws the control immediately. If this control is a Window, the whole window area is marked for repaint (useful if you're removing some controls from a container)
Since:
SuperWaba2.0beta4release3

createGraphics

public Graphics createGraphics()
Creates a Graphics object which can be used to draw in the control. This method finds the surface associated with the control, creates a graphics associated with it and translates the graphics to the origin of the control. It does not set a clipping rectangle on the graphics.

postEvent

public void postEvent(Event event)
Posts an event. The event pass will be posted to this control and all the parent controls of this control (all the containers this control is within).
See Also:
Event

setEnabled

public void setEnabled(boolean enabled)
Sets if this control can or not accept events. It changes the appearance of many controls to indicate they are disabled. Also, this method must be used after adding the control to its parent container.

isEnabled

public boolean isEnabled()
Returns if this control can or not accept events

onEvent

public void onEvent(Event event)
Called to process key, pen, control and other posted events.
Parameters:
event - the event to process
See Also:
Event, KeyEvent, PenEvent

onPaint

public void onPaint(Graphics g)
Called to draw the control. When this method is called, the graphics object passed has been translated into the coordinate system of the control and the area behind the control has already been painted. The background is painted by the top-level window control.
Parameters:
g - the graphics object for drawing
See Also:
Graphics

onBoundsChanged

protected void onBoundsChanged()
Called after an setRect.

onColorsChanged

protected void onColorsChanged(boolean colorsChanged)
Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled

onWindowPaintFinished

protected void onWindowPaintFinished()
Called after the window has finished a paint.

onFontChanged

protected void onFontChanged()
Called after a setFont

setBackForeColors

public void setBackForeColors(Color back,
                              Color fore)
Set the background and foreground colors at once

setForeColor

public void setForeColor(Color c)
Set the foreground color of this control.
Since:
SuperWaba2.0

setBackColor

public void setBackColor(Color c)
Set the background color of this control.
Since:
SuperWaba2.0

getForeColor

public Color getForeColor()
Get the desired foreground color of this control.
Since:
SuperWaba2.0

getBackColor

public Color getBackColor()
Get the desired background color of this control.
Since:
SuperWaba2.0

isDisplayed

public boolean isDisplayed()
Return true if the parent of this Control is added to somewhere. Some containers, like the TabPanel, has n child containers, but only one is added at a time. With this method, you can discover if your container is the one available.

requestFocus

public void requestFocus()
Sets the focus to this control

setFocusLess

public void setFocusLess(boolean on)
Sets this control to be focusless. If this control is a container, sets all its children to be focusless too.