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)
Gets the next widget in the focus order following the 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.
|
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)
Sets a widget in this composite as the focus owner of its panel, if it is enabled, following the direction.
|
boolean |
requestFocusFrom(int from,
int direction)
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.
|
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, hasFocus, invalidate, isEnabled, isShown, isTransparent, isValid, isVisible, lostFocus, repaint, repaint, revalidate, revalidateSubTree, setBounds, setEnabled, setEventHandler, setLocation, setPreferredSize, setSize, setVisibleclone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitrenderpublic Composite()
0.protected void add(@NonNull
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 is already in a hierarchy (already contained in a composite or panel).Widget.invalidate(),
Panel.setWidget(Widget)protected void remove(@NonNull
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 RenderableshowNotify in class Widgetpublic void hideNotify()
Notifies its children widgets that they are hidden.
hideNotify in interface RenderablehideNotify in class Widget@Nullable 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 Widgetx - x coordinatey - y coordinatenull if no widget is found in this composite hierarchy.@NonNull public java.util.Iterator<Widget> iterator()
The Iterator.remove() is not implemented (throws a UnsupportedOperationException).
@NonNull public Widget getWidget(int index) throws java.lang.IndexOutOfBoundsException
index - the index of the element to return.java.lang.IndexOutOfBoundsException - if the index is out of range ((index < 0 || index >= getWidgetsCount())@NonNull public Widget[] getWidgets()
public int getWidgetsCount()
public void requestFocus()
If the composite does not contain 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 Widgetpublic boolean requestFocus(int direction)
throws java.lang.IllegalArgumentException
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 Widgetdirection - 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.IndexOutOfBoundsException,
java.lang.IllegalArgumentException
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.IndexOutOfBoundsException - 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.IndexOutOfBoundsException,
java.lang.IllegalArgumentException
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.IndexOutOfBoundsException - if from is not a valid indexjava.lang.IllegalArgumentException - if direction is not a valid directiongetFocusIndex()@Nullable public Widget getFocus()
nullpublic int getFocusIndex()
MWT.EMPTY if the focus owner is not in the composite hierarchy.MWT.EMPTYpublic 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 WidgetwidthHint - the width available for this widget or MWT.NONEheightHint - the height available for this widget or MWT.NONEWidget.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 RenderablehandleEvent in class Widgetevent - the event to handletrue if the composite consume the event, false otherwiseWidget.setEventHandler(EventHandler)