Class WidgetCollection

public class WidgetCollection
extends Object
A simple collection of widgets to be used by panels and composites.

The main purpose of this specialized collection is to implement Iterator.remove() in a way that delegates removal to its panel. This makes it much easier for the panel to implement an iterator that supports removal of widgets.

Constructors

WidgetCollection(HasWidgets)Constructs a new widget collection.

Methods

add(Widget)Adds a widget to the end of this collection.
contains(Widget)Determines whether a given widget is contained in this collection.
get(int)Gets the widget at the given index.
indexOf(Widget)Gets the index of the specified index.
insert(Widget, int)Inserts a widget before the specified index.
iterator()Gets an iterator on this widget collection.
remove(int)Removes the widget at the specified index.
remove(Widget)Removes the specified widget.
size()Gets the number of widgets in this collection.

Constructor Detail

WidgetCollection

public WidgetCollection(HasWidgets parent)
Constructs a new widget collection.

Parameters

parent
the container whose HasWidgets.remove(Widget) will be delegated to by the iterator's Iterator.remove() method.

Method Detail

add

public void add(Widget w)
Adds a widget to the end of this collection.

Parameters

w
the widget to be added

contains

public boolean contains(Widget w)
Determines whether a given widget is contained in this collection.

Parameters

w
the widget to be searched for

Return Value

true if the widget is present

get

public Widget get(int index)
Gets the widget at the given index.

Parameters

index
the index to be retrieved

Return Value

the widget at the specified index

indexOf

public int indexOf(Widget w)
Gets the index of the specified index.

Parameters

w
the widget to be found

Return Value

the index of the specified widget, or -1 if it is not found

insert

public void insert(Widget w, int beforeIndex)
Inserts a widget before the specified index.

Parameters

w
the widget to be inserted
beforeIndex
the index before which the widget will be inserted

iterator

public Iterator iterator()
Gets an iterator on this widget collection. This iterator is guaranteed to implement remove() in terms of its containing HasWidgets.

Return Value

an iterator

remove

public void remove(int index)
Removes the widget at the specified index.

Parameters

index
the index of the widget to be removed

remove

public void remove(Widget w)
Removes the specified widget.

Parameters

w
the widget to be removed

size

public int size()
Gets the number of widgets in this collection.

Return Value

the number of widgets