public class

WidgetCollection

extends Object
implements Iterable<T>
java.lang.Object
   ↳ com.google.gwt.user.client.ui.WidgetCollection

Class Overview

A simple collection of widgets to be used by panels and composites.

The main purpose of this specialized collection is to implement 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.

Summary

Public Constructors
WidgetCollection(HasWidgets parent)
Constructs a new widget collection.
Public Methods
void add(Widget w)
Adds a widget to the end of this collection.
boolean contains(Widget w)
Determines whether a given widget is contained in this collection.
Widget get(int index)
Gets the widget at the given index.
int indexOf(Widget w)
Gets the index of the specified index.
void insert(Widget w, int beforeIndex)
Inserts a widget before the specified index.
Iterator<Widget> iterator()
Gets an iterator on this widget collection.
void remove(int index)
Removes the widget at the specified index.
void remove(Widget w)
Removes the specified widget.
int size()
Gets the number of widgets in this collection.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Iterable

Public Constructors

public WidgetCollection (HasWidgets parent)

Constructs a new widget collection.

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

Public Methods

public void add (Widget w)

Adds a widget to the end of this collection.

Parameters
w the widget to be added

public boolean contains (Widget w)

Determines whether a given widget is contained in this collection.

Parameters
w the widget to be searched for
Returns
  • true if the widget is present

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
IndexOutOfBoundsException if the index is out of range

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 -1 if it is not found

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
Throws
IndexOutOfBoundsException if beforeIndex is out of range

public Iterator<Widget> iterator ()

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

Returns
  • an iterator

public void remove (int index)

Removes the widget at the specified index.

Parameters
index the index of the widget to be removed
Throws
IndexOutOfBoundsException if index is out of range

public void remove (Widget w)

Removes the specified widget.

Parameters
w the widget to be removed
Throws
NoSuchElementException if the widget is not present

public int size ()

Gets the number of widgets in this collection.

Returns
  • the number of widgets