public abstract class Widget extends java.lang.Object implements Renderable
There are a number of important concepts involving widgets:
revalidate()
on
the widget.
Panel.validate()
,
which has the side-effect of performing any required repainting after validation. An application will normally invoke
Panel.revalidate()
after making a set of changes to widgets.
The validate(int, int)
method should not normally be invoked by applications or widget implementations. It
is used by the Panel
to propagate the validation request down through the widget hierarchy - widgets
with children propagate the call to their children.
repaint()
. If a widget has children it will ask them
to repaint. If the widget is transparent it will cause the relevant area of its parent to be repainted. Note that a
repaint request does not trigger validation, and the scope of the repainting that results from a call to
repaint()
will never exceed the widget itself, its children (recursively), and, if it is transparent, its
parent (recursively if the parent is also transparent).validate(int, int)
causes
the preferred size to be determined, normally with the assistance of a renderer. The preferred size is distinct from
the widget's actual size on the display (which may itself be subject to clipping).setSize(int, int)
or setBounds(int, int, int, int)
.Constructor and Description |
---|
Widget()
Creates a new widget.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(int x,
int y)
Gets
true if the (x,y) location is in the widget bounds, false otherwise. |
void |
gainFocus()
Notifies the widget that it is now the focus owner of its panel.
|
int |
getAbsoluteX()
Gets the absolute x coordinate of the widget.
|
int |
getAbsoluteX(int relativeX)
Gets the absolute x coordinate computed from the given x coordinate relative to the widget.
|
int |
getAbsoluteY()
Gets the absolute y coordinate of the widget.
|
int |
getAbsoluteY(int relativeY)
Gets the absolute y coordinate computed from the given y coordinate relative to the widget.
|
ej.microui.util.EventHandler |
getEventHandler()
Gets the event handler.
|
int |
getHeight()
Gets the height of this renderable.
|
Panel |
getPanel()
Gets the panel of this widget or
null if the widget is not in a panel. |
Composite |
getParent()
Gets the parent of this widget or
null if the widget is not in a hierarchy. |
int |
getPreferredHeight()
Gets the preferred height of the widget.
|
int |
getPreferredWidth()
Gets the preferred width of the widget.
|
int |
getRelativeX(int absoluteX)
Gets the x coordinate relative to the widget computed from the given absolute x coordinate.
|
int |
getRelativeY(int absoluteY)
Gets the y coordinate relative to the widget computed from the given absolute y coordinate.
|
Widget |
getWidgetAt(int x,
int y)
Gets the widget at the specified location.
|
int |
getWidth()
Gets the width of this renderable.
|
int |
getX()
Gets the x coordinate of this renderable, relative to its parent.
|
int |
getY()
Gets the y coordinate of this renderable, relative to its parent.
|
boolean |
handleEvent(int event)
Called by the system if the widget is the owner of the focus of the active panel.
|
boolean |
hasFocus()
Gets whether or not this widget is the focus owner of its panel and its panel is the active one.
|
void |
hideNotify()
This method is called as soon as the renderable is hidden.
|
void |
invalidate()
Declares that the panel containing this widget needs to be laid out.
|
boolean |
isEnabled()
Gets whether or not this widget is enabled.
|
boolean |
isShown()
Gets whether or not the widget is shown on a shown panel.
|
boolean |
isTransparent()
Gets whether this widget is transparent or not.
|
boolean |
isValid()
Gets whether this widget is valid.
|
boolean |
isVisible()
Gets whether this widget is visible or not.
|
void |
lostFocus()
Notifies the widget that it is no longer the focus owner of its panel.
|
void |
repaint()
Requests a repaint of this entire widget.
|
void |
repaint(int x,
int y,
int width,
int height)
Requests a repaint of a zone of this widget.
|
void |
requestFocus()
Sets this widget as the focus owner of its panel if it is enabled.
|
boolean |
requestFocus(int direction)
Sets this widget as the focus owner of its panel if it is enabled.
|
void |
revalidate()
Lays out all the hierarchy of the panel containing this widget if exists.
|
void |
setBounds(int x,
int y,
int width,
int height)
Sets the bounds of this widget.
|
void |
setEnabled(boolean enable)
Sets this widget to be enabled or not.
|
void |
setEventHandler(ej.microui.util.EventHandler eventHandler)
Sets the event handler.
|
void |
setLocation(int x,
int y)
Sets the location of this widget.
|
void |
setPreferredSize(int preferredWidth,
int preferredHeight)
Sets the preferred size of the widget.
|
void |
setSize(int width,
int height)
Sets the size of this widget.
|
void |
setVisible(boolean visible)
Sets this widget visible or not.
|
void |
showNotify()
This method is called as soon as the renderable is visible.
|
abstract void |
validate(int widthHint,
int heightHint)
Lays out this widget if visible.
|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
render
public Widget()
By default:
0
,public int getX()
Renderable
getX
in interface Renderable
public int getY()
Renderable
getY
in interface Renderable
public int getWidth()
If the widget is not visible, its width is always equals to 0
.
getWidth
in interface Renderable
public int getHeight()
If the widget is not visible, its height is always equals to 0
.
getHeight
in interface Renderable
public int getPreferredWidth()
The result returned is meaningful only if isValid()
is true
or if
setPreferredSize(int, int)
has been called explicitly.
public int getPreferredHeight()
The result returned is meaningful only if isValid()
is true
or if
setPreferredSize(int, int)
has been called explicitly.
public void setPreferredSize(int preferredWidth, int preferredHeight)
preferredWidth
- the width to set.preferredHeight
- the height to set.public void setLocation(int x, int y)
x
- the x coordinate to set.y
- the y coordinate to set.public void setSize(int width, int height)
width
- the width to set.height
- the height to set.public void setBounds(int x, int y, int width, int height)
x
- the x coordinate to set.y
- the y coordinate to set.width
- the width to set.height
- the height to set.public void showNotify()
Renderable
showNotify
in interface Renderable
public void hideNotify()
Renderable
hideNotify
in interface Renderable
public int getAbsoluteX() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if the widget is not connected to a Panel
.public int getAbsoluteY() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if the widget is not connected to a Panel
.public int getRelativeX(int absoluteX) throws java.lang.IllegalArgumentException
absoluteX
- the absolute x coordinate to convert.java.lang.IllegalArgumentException
- if the widget is not connected to a Panel
.public int getRelativeY(int absoluteY) throws java.lang.IllegalArgumentException
absoluteY
- the absolute y coordinate to convert.java.lang.IllegalArgumentException
- if the widget is not connected to a Panel
.public int getAbsoluteX(int relativeX)
relativeX
- the widget relative x coordinate to convert.public int getAbsoluteY(int relativeY)
relativeY
- the widget relative y coordinate to convert.public boolean isVisible()
true
if this widget is visible, false
otherwise.setVisible(boolean)
public void setVisible(boolean visible)
Declaring a widget as invisible means that it does not appear on the screen and its size is (0, 0)
.
If the widget is on a panel hierarchy, it is invalidated.
visible
- true
to set this widget visible, false
otherwise.isValid()
,
invalidate()
public boolean isTransparent()
By default, a widget is transparent.
A transparent widget means that it will not repaint ALL the rectangular zone defined by its bounds. Then each
time it needs to be repainted, its parent (recursively if also transparent) will be repainted within the bounds
of the widget.
Each time a non-transparent widget needs to be repainted, it is the only one to be repainted.
true
if this widget is transparent, false
otherwise.contains(int, int)
public boolean contains(int x, int y)
true
if the (x,y)
location is in the widget bounds, false
otherwise.
The location is considered here as a relative location to parent.
x
- x coordinate.y
- y coordinate.true
if the (x,y)
location is in widget bounds, false
otherwise.isTransparent()
public Widget getWidgetAt(int x, int y)
If this widget does not contains(x, y)
, null
is returned, else this widget is returned.
The location is considered here as a relative location to parent.
x
- x coordinate.y
- y coordinate.contains(x, y)
, null
otherwise.public boolean hasFocus()
Gets false
if this widget is not on a panel.
true
if this widget is the focus owner, false
otherwise.Panel.isActive()
public void requestFocus()
If the widget is not in a panel hierarchy, nothing is done.
public boolean requestFocus(int direction)
If the widget is not in a panel hierarchy, nothing is done.
The given direction must be one of MWT.UP
, MWT.DOWN
, MWT.LEFT
, MWT.RIGHT
.
Composed widgets can override this method in order to manage internal focus.
direction
- the direction followed by the focustrue
if the widget take the focus, false
otherwise.public void gainFocus()
The subclasses can override this method to add behavior.
public void lostFocus()
The subclasses can override this method to add behavior.
public boolean isEnabled()
A widget that is not enabled cannot get focus.
A widget that is not visible is also disabled.
true
if this widget is enabled, false
otherwise.public void setEnabled(boolean enable)
Requests a repaint of the widget.
enable
- true
if this widget is to be enabled, false
otherwise.repaint()
public void invalidate()
Panel.invalidate()
public void revalidate()
If the hierarchy is not declared as invalid, nothing is done.
Panel.revalidate()
public abstract void validate(int widthHint, int heightHint)
After this call the preferred size will have been established.
The parameters defines the maximum size available for this widget, or MWT.NONE
if there is no constraint.
widthHint
- the width available for this widget or MWT.NONE
heightHint
- the height available for this widget or MWT.NONE
isVisible()
,
setPreferredSize(int, int)
public boolean isValid()
A widget is valid if all of these conditions are meet :
true
if this widget is valid, false
otherwise.isVisible()
,
Panel.isValid()
public Composite getParent()
null
if the widget is not in a hierarchy.null
.public Panel getPanel()
null
if the widget is not in a panel.null
.public boolean isShown()
isShown
in interface Renderable
true
if the widget is shown, false
otherwise.getPanel()
,
Panel.isShown()
public void repaint()
If the widget is not shown, nothing is done.
If the widget is transparent, it requests a repaint of its parent within the widget's bounds.
repaint
in interface Renderable
public void repaint(int x, int y, int width, int height)
If the widget is not shown, nothing is done.
If the widget is transparent, it requests a repaint of its parent within the requested bounds.
repaint
in interface Renderable
x
- the relative x coordinate of the area to repaint.y
- the relative y coordinate of the area to repaint.width
- the width of the area to repaint.height
- the height of the area to repaint.public void setEventHandler(ej.microui.util.EventHandler eventHandler)
Renderable
setEventHandler
in interface Renderable
eventHandler
- the event handler to set.Renderable.handleEvent(int)
public ej.microui.util.EventHandler getEventHandler()
Renderable
getEventHandler
in interface Renderable
Renderable.handleEvent(int)
public boolean handleEvent(int event)
If an event handler is registered, its EventHandler.handleEvent(int)
method is called.
Otherwise, do nothing and return false
(do not consume event).
handleEvent
in interface Renderable
event
- the event to handle.true
if the widget has consumed the event, false
otherwise.setEventHandler(EventHandler)