totalcross.ui
Class Control

totalcross.lang.Object
  extended by totalcross.ui.gfx.GfxSurface
      extended by totalcross.ui.Control
Direct Known Subclasses:
Animation, Button, Chart, Check, Container, Edit, ImageControl, Keypad, Label, ProgressBar, PushButtonGroup, Radio, Ruler, Spacer, SpinList, Whiteboard

public class Control
extends GfxSurface

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.
 Object appObj
          Application defined object.
protected  Container asContainer
          READ-ONLY property which is not null if this control is a container
protected  Window asWindow
          READ-ONLY property which is not null if this control is a window
protected  int backColor
          Background color of this control.
static int BEFORE
          Constant used in param x/y in setRect.
static int BOTTOM
          Constant used in param y in setRect.
static int BOTTOM_OF
          Constant used in param x/y in setRect.
static int CENTER
          Constant used in params x and y in setRect.
static int CENTER_OF
          Constant used in param x/y in setRect.
 int clearValueInt
          Default value when calling clear.
 String clearValueStr
          Default value when calling clear.
protected  boolean enabled
          True if the control is enabled (accepts events) or false if not
static boolean enableUpdateScreen
          Set to false to disallow the screen update.
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
          Stores the height of the current font.
protected  boolean focusHandler
          Stores the control that should handle the focus change key for this control
protected  boolean focusLess
          If true, this control will receive pen and key events but will never gain focus.
 boolean focusOnPenDown
          True means this control expects to get focus on a PEN_DOWN event.
 boolean focusTraversable
          Defines if this control can receive focus by using the arrow keys.
protected  Font font
          The font used by the control.
protected  int foreColor
          Foreground color of this control.
protected  int height
          The control's height
protected static boolean isHighlighting
          If true, the keyboard arrows will be used to highlight the controls until one is selected.
static int KEEP
          Constant used in params x/y/width/height in setRect.
static int LEFT
          Constant used in param x in setRect.
protected  boolean onEventFirst
          Set to true to call onEvent before calling the event listeners.
protected  Container parent
          The parent of the control.
static int PREFERRED
          Constant used in params width and height in setRect.
static int RANGE
           
protected  boolean repositionAllowed
           
static int RIGHT
          Constant used in param x in setRect.
static int RIGHT_OF
          Constant used in param x/y in setRect.
static int SAME
          Constant used in params x/y/width/height in setRect.
protected  Font setFont
           
protected  int setH
           
protected  Control setRel
           
protected  int setW
           
protected  int setX
           
protected  int setY
           
static int TOP
          Constant used in param y in setRect.
 boolean transparentBackground
          Set the background to be transparent, by not filling the control's area with the background color.
protected static boolean uiCE
          Shortcuts to test the UI style.
protected static boolean uiFlat
          Shortcuts to test the UI style.
protected static boolean uiPalm
          Shortcuts to test the UI style.
protected static boolean uiVista
          Shortcuts to test the UI style.
protected  boolean visible
          True if the control is visible, false otherwise
protected  int width
          The control's width
static int WILL_RESIZE
          Constant used in params width/height in setRect.
protected  int x
          The control's x location
protected  int y
          The control's y location
 
Constructor Summary
protected Control()
          creates the font for this control as the same font of the MainWindow.
 
Method Summary
 void _onEvent(Event e)
          Calls the event listeners and the onEvent method for this control.
 void addFocusListener(FocusListener listener)
          Adds a listener for Focus events.
 void addGridListener(GridListener listener)
          Adds a listener for Grid events.
 void addHighlightListener(HighlightListener listener)
          Adds a listener for Highlight events.
 void addKeyListener(KeyListener listener)
          Adds a listener for Key events.
 void addPenListener(PenListener listener)
          Adds a listener for Pen events.
 void addPressListener(PressListener listener)
          Adds a listener for Press events.
 TimerEvent addTimer(int millis)
          Adds a timer to a control.
 void addTimer(TimerEvent t, int millis)
          Add a timer to a control.
 void addTimerListener(TimerListener listener)
          Adds a listener for Timer events.
 void addWindowListener(WindowListener listener)
          Adds a listener for Window events.
 void changeHighlighted(Container p, boolean forward)
          Transfers the focus to the next or previous control.
 void clear()
          Placeholder for the clear method.
 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.
 Rect getAbsoluteRect()
          Returns the absolute coordinates of this control relative to the MainWindow.
 int getBackColor()
          Get the desired background color of this control.
 Vector getEventListeners()
          Returns the event listeners array.
 Font getFont()
          Gets the font of this control.
 int getForeColor()
          Get the desired foreground color of this control.
 Graphics getGraphics()
          Returns a Graphics object which can be used to draw in the control.
 int getHeight()
          Returns the control's height.
 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 null 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 preferred height of this control.
 int getPreferredWidth()
          Returns the preferred width of this control.
protected  ControlEvent getPressedEvent(Control target)
          Creates a ControlEvent.PRESSED if not yet created and returns it.
 Control getPrev()
          Returns the previous child in the parent's list of controls.
 Rect getRect()
          Returns a copy of the control's rectangle, relative to its parent.
 Coord getSize()
          Returns the current size (width,height) of this control
 int getWidth()
          Returns the control's width.
 int getX()
          Returns the control's x position.
 int getX2()
          Returns x+width-1
 int getY()
          Returns the control's y position.
 int getY2()
          Returns y+height-1
 Control handleGeographicalFocusChangeKeys(KeyEvent ke)
          Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.
 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 isInsideOrNear(int x, int y)
          Returns true if the point lies inside this control.
 boolean isVisible()
          Returns true if this control is visible, false otherwise
 boolean isVisibleAndInside(int x0, int y0, int xf, int yf)
          Returns true of this control is visible and inside these bounds
protected  void onBoundsChanged(boolean screenChanged)
          Called after a 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.
 void postPressedEvent()
          Posts a ControlEvent.PRESSED event whith this control as target.
 void removeFocusListener(FocusListener listener)
          Removes a listener for Focus events.
 void removeGridListener(GridListener listener)
          Removes a listener for Grid events.
 void removeHighlightListener(HighlightListener listener)
          Removes a listener for Highlight events.
 void removeKeyListener(KeyListener listener)
          Removes a listener for Key events.
 void removePenListener(PenListener listener)
          Removes a listener for Pen events.
 void removePressListener(PressListener listener)
          Removes a listener for Press events.
 boolean removeTimer(TimerEvent timer)
          Removes a timer from a control.
 void removeTimerListener(TimerListener listener)
          Removes a listener for Timer events.
 void removeWindowListener(WindowListener listener)
          Removes a listener for Window events.
static void repaint()
          Marks all controls in the screen for repaint.
 void repaintNow()
          Redraws the control immediately.
 void reposition()
          Reposition this control, calling again setRect with the original parameters.
protected  void reposition(boolean recursive)
          Repositions this control, and dives into other controls if this is a container and recursive is true.
 void requestFocus()
          Sets the focus to this control.
 void setBackColor(int c)
          Set the background color of this control.
 void setBackForeColors(int back, int 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 control.
 void setForeColor(int 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(int x, int y, int width, int height, Control relative, boolean screenChanged)
          The relative positioning will be made with the given control (relative).
 void setRect(Rect r)
          Sets or changes a control's position and size.
 void setVisible(boolean visible)
          Shows or "hides" this control.
 void translateFromOrigin(Coord z)
          Sets the given Point to the absolute coordinate relative to the origin Window.
static void uiStyleChanged()
          Internal use only
static void updateScreen()
          This method causes the immediate screen update.
protected  void updateTemporary()
           
 
Methods inherited from class totalcross.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, 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 int 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 int 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


appObj

public Object appObj
Application defined object. This field is not used; its only a placeholder for the application so it can set to any value it wants


clearValueStr

public String clearValueStr
Default value when calling clear. When the control will use a numeric value or a String, depends on the type of control. Defaults to an empty string.


clearValueInt

public int clearValueInt
Default value when calling clear. When the control will use a numeric value or a String, depends on the type of control. Defaults to zero.


RANGE

public static final int RANGE
See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

CENTER_OF

public static final int CENTER_OF
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: CENTER_OF+2 or CENTER_OF-1. CENTER_OF is related to a control, while CENTER is related to the screen. CENTER_OF cannot be used with FILL/FIT in the widths.

See Also:
Constant Field Values

RIGHT_OF

public static final int RIGHT_OF
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: RIGHT_OF+2 or RIGHT_OF-1. RIGHT_OF is related to a control, while RIGHT is related to the screen. RIGHT_OF cannot be used with FILL/FIT in the widths.

See Also:
Constant Field Values

BOTTOM_OF

public static final int BOTTOM_OF
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: BOTTOM_OF+2 or BOTTOM_OF-1. BOTTOM_OF is related to a control, while BOTTOM is related to the screen. BOTTOM_OF cannot be used with FILL/FIT in the widths.

See Also:
Constant Field Values

WILL_RESIZE

public static final int WILL_RESIZE
Constant used in params width/height in setRect. It informs that the parent's last width/height should not be updated now, because it will be resized later. Note that it does NOT support increment nor decrement. Sample:
 Container c;
 add(c = new Container(), LEFT+5, AFTER+5, FILL-5, WILL_RESIZE);
 // add controls to c
 c.resizeHeight();
 

Since:
TotalCross 1.14
See Also:
Constant Field Values

KEEP

public static final int KEEP
Constant used in params x/y/width/height in setRect. It keeps the current value. Note that it does NOT support increment nor decrement. KEEP differs from SAME in the manner that KEEP applies to the coordinates of this control, while SAME applies to the coordinates of another control.

Since:
TotalCross 1.14
See Also:
Constant Field Values

enableUpdateScreen

public static boolean enableUpdateScreen
Set to false to disallow the screen update.


fmH

protected int fmH
Stores the height of the current font. The same of fm.height.


focusHandler

protected boolean focusHandler
Stores the control that should handle the focus change key for this control


isHighlighting

protected static boolean isHighlighting
If true, the keyboard arrows will be used to highlight the controls until one is selected. This will cause the KeyEvent to be intercepted and handled by the method changeHighlighted. When the user press the ACTION (or ENTER) key to use the control, this flag is set to false and the focus will be set to the control, so it be able to use the arrows to navigate inside it. The control must then set this to true when the finish using it or press the ACTION button again (which then sets the flag to true).

Since:
SuperWaba 5.5

focusTraversable

public boolean focusTraversable
Defines if this control can receive focus by using the arrow keys.

Since:
SuperWaba 5.5

uiPalm

protected static boolean uiPalm
Shortcuts to test the UI style. Use the setUIStyle method to change them accordingly.


uiCE

protected static boolean uiCE
Shortcuts to test the UI style. Use the setUIStyle method to change them accordingly.


uiFlat

protected static boolean uiFlat
Shortcuts to test the UI style. Use the setUIStyle method to change them accordingly.


uiVista

protected static boolean uiVista
Shortcuts to test the UI style. Use the setUIStyle method to change them accordingly.


focusLess

protected boolean focusLess
If true, this control will receive pen and key events but will never gain focus. This is useful to create keypads. See totalcross.ui.Calculator.


setX

protected int setX

setY

protected int setY

setW

protected int setW

setH

protected int setH

setFont

protected Font setFont

setRel

protected Control setRel

repositionAllowed

protected boolean repositionAllowed

onEventFirst

protected boolean onEventFirst
Set to true to call onEvent before calling the event listeners. By default, the event listener is called before the onEvent.


asContainer

protected Container asContainer
READ-ONLY property which is not null if this control is a container


asWindow

protected Window asWindow
READ-ONLY property which is not null if this control is a window


transparentBackground

public boolean transparentBackground
Set the background to be transparent, by not filling the control's area with the background color.

Since:
TotalCross 1.0

focusOnPenDown

public boolean focusOnPenDown
True means this control expects to get focus on a PEN_DOWN event. If focusOnPenDown is false, focus will be set on PEN_UP instead. This can be used for things like drag-scrollable list controls that contain controls as list items, to avoid setting focus to an item (and therefore changing the selection) during a drag-scroll.

Constructor Detail

Control

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

Method Detail

isInsideOrNear

public boolean isInsideOrNear(int x,
                              int y)
Returns true if the point lies inside this control. If it don't lies, but the device is a finger touch one, checks if the distance is below the touch tolerance.

Since:
TotalCross 1.2
See Also:
Settings.touchTolerance, Settings.fingerTouch

postPressedEvent

public void postPressedEvent()
Posts a ControlEvent.PRESSED event whith this control as target.

Since:
TotalCross 1.14

getPressedEvent

protected ControlEvent getPressedEvent(Control target)
Creates a ControlEvent.PRESSED if not yet created and returns it.

Since:
TotalCross 1.14

addTimer

public TimerEvent 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 and other platforms, the minimum timer resolution is 10ms.

If the control that holds the timer is removed from screen, the timer is also disabled. Consider using the dispatch-listener event model (addTimerListener) instead of creating a control just to catch the event (if this is the case).

Parameters:
millis - the timer tick interval in milliseconds
See Also:
TimerEvent

addTimer

public void addTimer(TimerEvent t,
                     int millis)
Add a timer to a control. This method allows you to create an instance TimerEvent (or any descendant) ahead of time and add it to the control.

Parameters:
t - the TimerEvent instance
millis - the timer tick interval in milliseconds
See Also:
TimerEvent

removeTimer

public boolean removeTimer(TimerEvent 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 control.


getFont

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


getPreferredWidth

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


getPreferredHeight

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


setRect

public void setRect(Rect r)
Sets or changes a control's position and size.
 setRect(r.x,r.y,r.width,r.height,null,false)
 

See Also:
setRect(int, int, int, int, Control, boolean)

setRect

public void setRect(int x,
                    int y,
                    int width,
                    int height)
Sets or changes a control's position and size. Same of
 setRect(x,y,width,height,null,false)
 

See Also:
setRect(int, int, int, int, Control, boolean)

setRect

public void setRect(int x,
                    int y,
                    int width,
                    int height,
                    Control relative)
Sets or changes a control's position and size.
 setRect(x,y,width,height,relative,false)
 

See Also:
setRect(int, int, int, int, Control, boolean)

setRect

public void setRect(int x,
                    int y,
                    int width,
                    int height,
                    Control relative,
                    boolean screenChanged)
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. 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.

Parameters:
x - One of the relative positioning constants: LEFT, RIGHT, SAME, BEFORE, AFTER, CENTER, with a small adjustment. You can also use an absolute value, but this is strongly discouraged.
y - One of the relative positioning constants: TOP, BOTTOM, SAME, BEFORE, AFTER, CENTER, with a small adjustment. You can also use an absolute value, but this is strongly discouraged.
width - One of the relative positioning constants: PREFERRED, FILL, FIT, SAME. You can also use an absolute value, but this is strongly discouraged.
height - One of the relative positioning constants: PREFERRED, FILL, FIT, SAME. You can also use an absolute value, but this is strongly discouraged.
relative - To whom the position should be relative to; or null to be relative to the last control.
screenChanged - Indicates that a screen change (resize, collapse) occured and the reposition method is calling this method. Set by the system. If you call this method directly, always pass false to it.
See Also:
LEFT, TOP, RIGHT, BOTTOM, BEFORE, AFTER, CENTER, SAME, FILL, PREFERRED, FIT, CENTER_OF, RIGHT_OF, BOTTOM_OF, Container.add(Control, int, int), Container.add(Control, int, int, Control)

updateTemporary

protected void updateTemporary()

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. Note that it remains attached to its container. 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, relative to its parent. 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 null if there's no parent (eg: the control still not added to any container). If this control is a window, will return itself.


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.


getPrev

public Control getPrev()
Returns the previous 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 static void repaint()
Marks all controls in the screen for repaint. Important note: when you call repaint, a flag is set indicating that the screen must be repainted; 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 can use the Control.repaintNow method.

If you want to avoid a method call, you can do
 Window.needsPaint = true;
 

See Also:
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). This method affects only this control, while the repaint method affects the whole screen.

Since:
SuperWaba 2.0 beta 4 release 3
See Also:
repaint()

translateFromOrigin

public void translateFromOrigin(Coord z)
Sets the given Point to the absolute coordinate relative to the origin Window.

Since:
SuperWaba 5.5

getGraphics

public Graphics getGraphics()
Returns a Graphics object which can be used to draw in the control. This method updates the single Graphics object with the current control font and bounds. It sets a clipping rectangle on the graphics, clipping it against all parent areas.


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.


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.

Parameters:
g - the graphics object for drawing
See Also:
Graphics

onBoundsChanged

protected void onBoundsChanged(boolean screenChanged)
Called after a setRect.

Parameters:
screenChanged - If the bounds were changed due to a screen change (rotation, collapse)

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. Only called to the focused control and the parent's window.


onFontChanged

protected void onFontChanged()
Called after a setFont


setBackForeColors

public void setBackForeColors(int back,
                              int fore)
Set the background and foreground colors at once. Calling this method is faster than calling setBackColor and setForeColor separately.


setForeColor

public void setForeColor(int c)
Set the foreground color of this control.

Since:
SuperWaba 2.0

setBackColor

public void setBackColor(int c)
Set the background color of this control.

Since:
SuperWaba 2.0

getForeColor

public int getForeColor()
Get the desired foreground color of this control.

Since:
SuperWaba 2.0

getBackColor

public int getBackColor()
Get the desired background color of this control.

Since:
SuperWaba 2.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 being shown.


requestFocus

public void requestFocus()
Sets the focus to this control. Note that in penless devices its also needed to set isHighlighting = false.


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. A focusless control can receive and dispatch events, but cannot receive focus. Here's an example of how to use it to create a keypad:
         // class fields
         private PushButtonGroup numericPad;
         private KeyEvent ke = new KeyEvent();

         // in the initUI method:
         totalcross.lang.String []numerics = {"1","2","3","4","5","6","7","8","9","0",".","-"};
         add(numericPad=new PushButtonGroup(numerics, false, -1, -1, 6, 4, true,
                                             PushButtonGroup.BUTTON), RIGHT-2, TOP+2);
         numericPad.setFocusLess(true);

         // in the onEvent method
         Control focus;
         if (e.target == numericPad && (focus=getParentWindow().getFocus()) instanceof Edit)
         {
            totalcross.lang.String s = numericPad.getSelectedCaption();
            if (s != null)
            {
               ke.key = s.charAt(0);
               ke.target = focus;
               focus.onEvent(ke);
            }
         }
 


uiStyleChanged

public static void uiStyleChanged()
Internal use only


changeHighlighted

public void changeHighlighted(Container p,
                              boolean forward)
Transfers the focus to the next or previous control.

Since:
SuperWaba 5.5

clear

public void clear()
Placeholder for the clear method. The class that inherits control is responsible for cleaning it up.


updateScreen

public static void updateScreen()
This method causes the immediate screen update. The screen is saved in a buffer and, when this method is called, the buffer is transfered to the screen, using the nextTransitionEffect set.

Since:
SuperWaba 5.0
See Also:
Container.nextTransitionEffect

getWidth

public int getWidth()
Returns the control's width.

Specified by:
getWidth in class GfxSurface

getHeight

public int getHeight()
Returns the control's height.

Specified by:
getHeight in class GfxSurface

getX

public int getX()
Returns the control's x position.

Specified by:
getX in class GfxSurface

getY

public int getY()
Returns the control's y position.

Specified by:
getY in class GfxSurface

getX2

public int getX2()
Returns x+width-1

Since:
TotalCross 1.14

getY2

public int getY2()
Returns y+height-1

Since:
TotalCross 1.14

reposition

protected void reposition(boolean recursive)
Repositions this control, and dives into other controls if this is a container and recursive is true.


reposition

public void reposition()
Reposition this control, calling again setRect with the original parameters.


_onEvent

public void _onEvent(Event e)
Calls the event listeners and the onEvent method for this control.


addPenListener

public void addPenListener(PenListener listener)
Adds a listener for Pen events.

See Also:
PenListener

addWindowListener

public void addWindowListener(WindowListener listener)
Adds a listener for Window events.

See Also:
WindowListener

addGridListener

public void addGridListener(GridListener listener)
Adds a listener for Grid events.

See Also:
GridListener

addFocusListener

public void addFocusListener(FocusListener listener)
Adds a listener for Focus events.

See Also:
FocusListener

addPressListener

public void addPressListener(PressListener listener)
Adds a listener for Press events.

See Also:
PressListener

addTimerListener

public void addTimerListener(TimerListener listener)
Adds a listener for Timer events.

See Also:
TimerListener

addKeyListener

public void addKeyListener(KeyListener listener)
Adds a listener for Key events.

See Also:
KeyListener

addHighlightListener

public void addHighlightListener(HighlightListener listener)
Adds a listener for Highlight events.

See Also:
HighlightListener

removePenListener

public void removePenListener(PenListener listener)
Removes a listener for Pen events.

Since:
TotalCross 1.22
See Also:
PenListener

removeWindowListener

public void removeWindowListener(WindowListener listener)
Removes a listener for Window events.

Since:
TotalCross 1.22
See Also:
WindowListener

removeGridListener

public void removeGridListener(GridListener listener)
Removes a listener for Grid events.

Since:
TotalCross 1.22
See Also:
GridListener

removeFocusListener

public void removeFocusListener(FocusListener listener)
Removes a listener for Focus events.

Since:
TotalCross 1.22
See Also:
FocusListener

removePressListener

public void removePressListener(PressListener listener)
Removes a listener for Press events.

Since:
TotalCross 1.22
See Also:
PressListener

removeTimerListener

public void removeTimerListener(TimerListener listener)
Removes a listener for Timer events.

Since:
TotalCross 1.22
See Also:
TimerListener

removeKeyListener

public void removeKeyListener(KeyListener listener)
Removes a listener for Key events.

Since:
TotalCross 1.22
See Also:
KeyListener

removeHighlightListener

public void removeHighlightListener(HighlightListener listener)
Removes a listener for Highlight events.

Since:
TotalCross 1.22
See Also:
HighlightListener

handleGeographicalFocusChangeKeys

public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.

Parameters:
ke - The KeyEvent to be processed
Returns:
The control that should get focus as a result of this KeyEvent. Null if this control did not handle the KeyEvent.
See Also:
Settings.geographicalFocus

getEventListeners

public Vector getEventListeners()
Returns the event listeners array. Note that each element is an instance of Control.Listener.

See Also:
Listener

isVisibleAndInside

public boolean isVisibleAndInside(int x0,
                                  int y0,
                                  int xf,
                                  int yf)
Returns true of this control is visible and inside these bounds

Since:
TotalCross 1.15