public abstract class Composite extends Widget
Widget
instances, following the composite pattern.
The children are stored in a list. The order of the list defines the front-to-back stacking order of the widgets within the composite. The first widget in the list is at the back of the stacking order.
A widget cannot be added two times in a hierarchy.
Constructor and Description |
---|
Composite()
Creates a new composite.
Its bounds will be set to 0 . |
Modifier and Type | Method and Description |
---|---|
protected void |
add(Widget widget)
Adds the specified widget to the end of the list of children of this composite.
|
Widget |
getFocus()
Gets the widget that is the focus owner or that owns (recursively) the focus owner in this composite.
|
int |
getFocusIndex()
Gets the index of the widget that is the focus owner or that is (recursively) the focus owner parent in the
composite.
|
int |
getNext(int from,
int direction)
|
Widget |
getWidget(int index)
Gets the widget at the specified position in this composite.
|
Widget |
getWidgetAt(int x,
int y)
Returns the child widget that is at the specified location.
|
Widget[] |
getWidgets()
Gets the list of children in this composite.
|
int |
getWidgetsCount()
Gets the number of children in this composite.
|
boolean |
handleEvent(int event)
Called by the system if a child of this composite is the owner of the focus of the active panel (recursively) and
have not consumed the specified event.
|
boolean |
hasFocus()
Gets whether or not this composite or one of its children (recursively) is the focus owner of its panel.
|
void |
hideNotify()
This method is called as soon as the renderable is hidden.
|
java.util.Iterator<Widget> |
iterator()
Gets an iterator over the composite children widgets in proper sequence.
|
protected void |
remove(Widget widget)
Removes the specified widget from the list of children of this composite.
|
protected void |
removeAllWidgets()
Removes all the widgets from the list of children of this composite.
|
void |
requestFocus()
Requests that the first child of this composite be set as the focus owner of its panel.
|
boolean |
requestFocus(int direction)
|
boolean |
requestFocusFrom(int from,
int direction)
|
void |
showNotify()
This method is called as soon as the renderable is visible.
|
abstract void |
validate(int widthHint,
int heightHint)
Lays out this composite and all its children.
|
contains, gainFocus, getAbsoluteX, getAbsoluteX, getAbsoluteY, getAbsoluteY, getEventHandler, getHeight, getPanel, getParent, getPreferredHeight, getPreferredWidth, getRelativeX, getRelativeY, getWidth, getX, getY, invalidate, isEnabled, isShown, isTransparent, isValid, isVisible, lostFocus, repaint, repaint, revalidate, setBounds, setEnabled, setEventHandler, setLocation, setPreferredSize, setSize, setVisible
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
render
public Composite()
0
.protected void add(Widget widget) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
If the composite is on a panel hierarchy, it is invalidated.
widget
- the widget to add.java.lang.NullPointerException
- if the specified widget is null
.java.lang.IllegalArgumentException
- if the specified widget or one of its children is already connected to a Panel
.Widget.invalidate()
protected void remove(Widget widget) throws java.lang.NullPointerException
If the composite is on a panel hierarchy, it is invalidated.
If the widget is not in the list of children of the composite, nothing is done.
widget
- the widget to removejava.lang.NullPointerException
- if the specified widget is nullWidget.invalidate()
protected void removeAllWidgets()
If the composite is on a panel hierarchy, it is invalidated.
Widget.invalidate()
public void showNotify()
Notifies its children widgets that they are shown.
showNotify
in interface Renderable
showNotify
in class Widget
public void hideNotify()
Notifies its children widgets that they are hidden.
hideNotify
in interface Renderable
hideNotify
in class Widget
public Widget getWidgetAt(int x, int y)
If Widget.contains(int, int)
is false
for this composite, null
is returned.
Otherwise, if there is a child for which Widget.contains(int, int)
returns true
then the
result of invoking Widget.getWidgetAt(int, int)
on that widget is returned. Otherwise this composite is
returned.
The location is relative to the location of this composite's parent.
getWidgetAt
in class Widget
x
- x coordinatey
- y coordinatenull
if no widget is found in this composite hierarchy.public java.util.Iterator<Widget> iterator()
The Iterator.remove()
is not implemented (throws a UnsupportedOperationException
).
public Widget getWidget(int index) throws java.lang.ArrayIndexOutOfBoundsException
index
- the index of the element to return.java.lang.ArrayIndexOutOfBoundsException
- if the index is out of range ((index < 0 || index >= getWidgetsCount()
)public Widget[] getWidgets()
public int getWidgetsCount()
public boolean hasFocus()
false
if this composite is not on a panel.hasFocus
in class Widget
true
if this composite is a parent of the focus owner, false
otherwisePanel.isActive()
public void requestFocus()
Requests that the first child of this composite be set as the focus owner of its panel.
If the composite does not contains any widgets, nothing is done.
If the composite is not in a panel hierarchy, nothing is done.
Identical to calling requestFocusFrom(int, int)
with MWT.RIGHT
as direction and 0
as from.
requestFocus
in class Widget
public boolean requestFocus(int direction) throws java.lang.IllegalArgumentException
Sets a widget in this composite as the focus owner of its panel, if it is enabled, following the direction.
The given direction must be one of MWT.UP
, MWT.DOWN
, MWT.LEFT
, MWT.RIGHT
.
If the widget is not in a panel hierarchy, nothing is done.
Identical to calling requestFocusFrom(int, int)
with one of MWT.DOWN
or MWT.RIGHT
as
direction and 0
as from, or one of MWT.LEFT
or MWT.UP
and
(getWidgetsCount() - 1)
as from.
requestFocus
in class Widget
direction
- the direction followed by the focustrue
if the composite take the focus, false
otherwisejava.lang.IllegalArgumentException
- if direction
is not a valid directionpublic boolean requestFocusFrom(int from, int direction) throws java.lang.ArrayIndexOutOfBoundsException, java.lang.IllegalArgumentException
Gives the focus to the first enabled widget that is in the list of this composite's children from the widget at
the specified index following the direction.
The given direction must be one of MWT.UP
, MWT.DOWN
, MWT.LEFT
, MWT.RIGHT
.
from
- the index to start searchdirection
- the direction followed by the focustrue
if a new widget has been given focus, false
otherwisejava.lang.ArrayIndexOutOfBoundsException
- if from
is not a valid indexjava.lang.IllegalArgumentException
- if direction
is not a valid directiongetNext(int, int)
public int getNext(int from, int direction) throws java.lang.ArrayIndexOutOfBoundsException, java.lang.IllegalArgumentException
Gets the next widget in the focus order following the direction.
If there is no more widget to focus in this direction, it returns MWT.EMPTY
.
The given direction must be one of MWT.UP
, MWT.DOWN
, MWT.LEFT
, MWT.RIGHT
.
from
- the index of the current widgetdirection
- the direction to followjava.lang.ArrayIndexOutOfBoundsException
- if from
is not a valid indexjava.lang.IllegalArgumentException
- if direction
is not a valid directiongetFocusIndex()
public Widget getFocus()
null
public int getFocusIndex()
MWT.EMPTY
if the focus owner is not in the composite hierarchy.MWT.EMPTY
public abstract void validate(int widthHint, int heightHint)
The parameters defines the maximum size available for this composite, or MWT.NONE
if there is no
constraint.
After this call the preferred size will have been established.
validate
in class Widget
widthHint
- the width available for this widget or MWT.NONE
heightHint
- the height available for this widget or MWT.NONE
Widget.isVisible()
,
Widget.setPreferredSize(int, int)
public boolean handleEvent(int event)
Command.UP
, Command.DOWN
,
Command.LEFT
, and Command.RIGHT
commands to manage navigation in its children.handleEvent
in interface Renderable
handleEvent
in class Widget
event
- the event to handletrue
if the composite consume the event, false
otherwiseWidget.setEventHandler(EventHandler)