|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
totalcross.lang.Objecttotalcross.ui.gfx.GfxSurface
totalcross.ui.Control
public class Control
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 |
|---|
protected int x
protected int y
protected int width
protected int height
protected Container parent
protected boolean enabled
protected Font font
public FontMetrics fm
protected boolean visible
protected int foreColor
protected int backColor
public int appId
public Object appObj
public String clearValueStr
public int clearValueInt
public static final int RANGE
public static final int PREFERRED
public static final int LEFT
public static final int CENTER
public static final int RIGHT
public static final int TOP
public static final int BOTTOM
public static final int FILL
public static final int BEFORE
public static final int SAME
public static final int AFTER
public static final int FIT
public static final int CENTER_OF
public static final int RIGHT_OF
public static final int BOTTOM_OF
public static final int WILL_RESIZE
Container c; add(c = new Container(), LEFT+5, AFTER+5, FILL-5, WILL_RESIZE); // add controls to c c.resizeHeight();
public static final int KEEP
public static boolean enableUpdateScreen
protected int fmH
fm.height.
protected boolean focusHandler
protected static boolean isHighlighting
public boolean focusTraversable
protected static boolean uiPalm
protected static boolean uiCE
protected static boolean uiFlat
protected static boolean uiVista
protected boolean focusLess
protected int setX
protected int setY
protected int setW
protected int setH
protected Font setFont
protected Control setRel
protected boolean repositionAllowed
protected boolean onEventFirst
protected Container asContainer
protected Window asWindow
public boolean transparentBackground
public boolean focusOnPenDown
| Constructor Detail |
|---|
protected Control()
| Method Detail |
|---|
public boolean isInsideOrNear(int x,
int y)
Settings.touchTolerance,
Settings.fingerTouchpublic void postPressedEvent()
protected ControlEvent getPressedEvent(Control target)
public TimerEvent addTimer(int millis)
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).
millis - the timer tick interval in millisecondsTimerEvent
public void addTimer(TimerEvent t,
int millis)
t - the TimerEvent instancemillis - the timer tick interval in millisecondsTimerEventpublic boolean removeTimer(TimerEvent timer)
public void setFont(Font font)
public Font getFont()
public int getPreferredWidth()
public int getPreferredHeight()
public void setRect(Rect r)
setRect(r.x,r.y,r.width,r.height,null,false)
setRect(int, int, int, int, Control, boolean)
public void setRect(int x,
int y,
int width,
int height)
setRect(x,y,width,height,null,false)
setRect(int, int, int, int, Control, boolean)
public void setRect(int x,
int y,
int width,
int height,
Control relative)
setRect(x,y,width,height,relative,false)
setRect(int, int, int, int, Control, boolean)
public void setRect(int x,
int y,
int width,
int height,
Control relative,
boolean screenChanged)
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 43Note: 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.
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.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)protected void updateTemporary()
public Coord getSize()
public Coord getPos()
public void setVisible(boolean visible)
public boolean isVisible()
public Rect getRect()
public Rect getAbsoluteRect()
public Window getParentWindow()
public Container getParent()
public Control getNext()
public Control getPrev()
public boolean contains(int x,
int y)
public static void repaint()
Window.needsPaint = true;
repaintNow()public void repaintNow()
repaint()public void translateFromOrigin(Coord z)
public Graphics getGraphics()
public void postEvent(Event event)
Eventpublic void setEnabled(boolean enabled)
public boolean isEnabled()
public void onEvent(Event event)
event - the event to processEvent,
KeyEvent,
PenEventpublic void onPaint(Graphics g)
g - the graphics object for drawingGraphicsprotected void onBoundsChanged(boolean screenChanged)
screenChanged - If the bounds were changed due to a screen change (rotation, collapse)protected void onColorsChanged(boolean colorsChanged)
protected void onWindowPaintFinished()
protected void onFontChanged()
public void setBackForeColors(int back,
int fore)
public void setForeColor(int c)
public void setBackColor(int c)
public int getForeColor()
public int getBackColor()
public boolean isDisplayed()
public void requestFocus()
isHighlighting = false.
public void setFocusLess(boolean on)
// 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);
}
}
public static void uiStyleChanged()
public void changeHighlighted(Container p,
boolean forward)
public void clear()
public static void updateScreen()
Container.nextTransitionEffectpublic int getWidth()
getWidth in class GfxSurfacepublic int getHeight()
getHeight in class GfxSurfacepublic int getX()
getX in class GfxSurfacepublic int getY()
getY in class GfxSurfacepublic int getX2()
public int getY2()
protected void reposition(boolean recursive)
public void reposition()
public void _onEvent(Event e)
public void addPenListener(PenListener listener)
PenListenerpublic void addWindowListener(WindowListener listener)
WindowListenerpublic void addGridListener(GridListener listener)
GridListenerpublic void addFocusListener(FocusListener listener)
FocusListenerpublic void addPressListener(PressListener listener)
PressListenerpublic void addTimerListener(TimerListener listener)
TimerListenerpublic void addKeyListener(KeyListener listener)
KeyListenerpublic void addHighlightListener(HighlightListener listener)
HighlightListenerpublic void removePenListener(PenListener listener)
PenListenerpublic void removeWindowListener(WindowListener listener)
WindowListenerpublic void removeGridListener(GridListener listener)
GridListenerpublic void removeFocusListener(FocusListener listener)
FocusListenerpublic void removePressListener(PressListener listener)
PressListenerpublic void removeTimerListener(TimerListener listener)
TimerListenerpublic void removeKeyListener(KeyListener listener)
KeyListenerpublic void removeHighlightListener(HighlightListener listener)
HighlightListenerpublic Control handleGeographicalFocusChangeKeys(KeyEvent ke)
ke - The KeyEvent to be processed
Settings.geographicalFocuspublic Vector getEventListeners()
Listener
public boolean isVisibleAndInside(int x0,
int y0,
int xf,
int yf)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||