Package com.google.gwt.user.client.ui
Class WidgetCollection
- java.lang.Object
-
- com.google.gwt.user.client.ui.WidgetCollection
-
- All Implemented Interfaces:
java.lang.Iterable<Widget>
public class WidgetCollection extends java.lang.Object implements java.lang.Iterable<Widget>
A simple collection of widgets to be used bypanelsandcomposites.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 aniteratorthat supports removal of widgets.
-
-
Constructor Summary
Constructors Constructor Description WidgetCollection(HasWidgets parent)Constructs a new widget collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Widget w)Adds a widget to the end of this collection.booleancontains(Widget w)Determines whether a given widget is contained in this collection.Widgetget(int index)Gets the widget at the given index.intindexOf(Widget w)Gets the index of the specified index.voidinsert(Widget w, int beforeIndex)Inserts a widget before the specified index.java.util.Iterator<Widget>iterator()Gets an iterator on this widget collection.voidremove(int index)Removes the widget at the specified index.voidremove(Widget w)Removes the specified widget.intsize()Gets the number of widgets in this collection.
-
-
-
Constructor Detail
-
WidgetCollection
public WidgetCollection(HasWidgets parent)
Constructs a new widget collection.- Parameters:
parent- the container whoseHasWidgets.remove(Widget)will be delegated to by the iterator'sIterator.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- Returns:
trueif the widget is present
-
get
public Widget get(int index)
Gets the widget at the given index.- Parameters:
index- the index to be retrieved- Returns:
- the widget at the specified index
- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range
-
indexOf
public int indexOf(Widget w)
Gets the index of the specified index.- Parameters:
w- the widget to be found- Returns:
- the index of the specified widget, or
-1if 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 insertedbeforeIndex- the index before which the widget will be inserted- Throws:
java.lang.IndexOutOfBoundsException- ifbeforeIndexis out of range
-
iterator
public java.util.Iterator<Widget> iterator()
Gets an iterator on this widget collection. This iterator is guaranteed to implement remove() in terms of its containingHasWidgets.- Specified by:
iteratorin interfacejava.lang.Iterable<Widget>- Returns:
- 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- Throws:
java.lang.IndexOutOfBoundsException- ifindexis out of range
-
remove
public void remove(Widget w)
Removes the specified widget.- Parameters:
w- the widget to be removed- Throws:
java.util.NoSuchElementException- if the widget is not present
-
size
public int size()
Gets the number of widgets in this collection.- Returns:
- the number of widgets
-
-