buoy.widget

Class BList


public class BList
extends Widget

A BList is a Widget that displays a list of objects for the user to select. Typically the objects are Strings, but other types of objects can be used as well. It supports both single and multiple selection modes. There are methods for adding and removing objects in the list. Alternatively, you can set a ListModel to provide more complex behaviors.

BList does not provide scrolling automatically. Normally, it is used inside a BScrollPane.

In addition to the event types generated by all Widgets, BLists generate the following event types:

Author:
Peter Eastman

Constructor Summary

BList()
Create a new BList containing no objects.
BList(ListModel model)
Create a new BList whose contents are determined by a ListModel.
BList(contents[] )
Create a new BList containing the objects in an array.
BList(contents[] )
Create a new BList containing the objects in a Collection.

Method Summary

void
add(Object o)
Add an object to the end of the list.
void
add(int index, Object o)
Add an object at specified position in the middle of the list.
void
clearSelection()
Deselect all objects in the list.
Object
getItem(int index)
Get the item at a specific position in the list.
int
getItemCount()
Get the number of items in the list.
Dimension
getMaximumSize()
Get the largest size at which this Widget can reasonably be drawn.
ListModel
getModel()
Get the ListModel which controls the contents of this BList.
int
getPreferredVisibleRows()
Get the preferred number of rows which should be visible without using a scrollbar.
int
getSelectedIndex()
Get the index of the first selected object, or -1 if nothing is selected.
int[]
getSelectedIndices()
Get the indices of all selected objects, in increasing order.
Object
getSelectedValue()
Get the first selected object, or null if nothing is selected.
Object[]
getSelectedValues()
Get an array of all selected objects, in order of increasing index.
boolean
isMultipleSelectionEnabled()
Determine whether this list allows multiple objects to be selected.
boolean
isSelected(int index)
Determine whether a particular object in the list is selected.
void
remove(int index)
Remove an object from the list.
void
removeAll()
Remove all objects from the list.
void
replace(int index, Object o)
Replace the object at a specified position in the list with a new one.
void
scrollToItem(int index)
Scroll the BList's parent BScrollPane to ensure that a particular list entry is visible.
void
setContents(Collection c)
Set the contents of the list to the objects in a Collection.
void
setContents(o[] )
Set the contents of the list to the objects in an array.
void
setModel(ListModel model)
Set the ListModel which controls the contents of this BList.
void
setMultipleSelectionEnabled(boolean multiple)
Set whether this list should allow multiple objects to be selected.
void
setPreferredVisibleRows(int rows)
Set the preferred number of rows which should be visible without using a scrollbar.
void
setSelected(int index, boolean selected)
Set whether a particular object should be selected.

Methods inherited from class buoy.widget.Widget

addEventLink, dispatchEvent, getBackground, getBounds, getComponent, getCursor, getFont, getMaximumSize, getMinimumSize, getName, getParent, getPreferredSize, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setBackground, setCursor, setEnabled, setFocusable, setFont, setName, setVisible

Methods inherited from class buoy.event.EventSource

addEventLink, addEventLink, addEventLink, dispatchEvent, removeEventLink

Constructor Details

BList

public BList()
Create a new BList containing no objects.

BList

public BList(ListModel model)
Create a new BList whose contents are determined by a ListModel.

BList

public BList(contents[] )
Create a new BList containing the objects in an array.

BList

public BList(contents[] )
Create a new BList containing the objects in a Collection. The objects will be added in the order they are returned by the Collection's Iterator.

Method Details

add

public void add(Object o)
Add an object to the end of the list.

If you have set a custom model for this list, either by passing it to the constructor or by calling setModel(), this method has no effect.

Parameters:
o - the object to add

add

public void add(int index,
                Object o)
Add an object at specified position in the middle of the list.

If you have set a custom model for this list, either by passing it to the constructor or by calling setModel(), this method has no effect.

Parameters:
index - the position at which to add the object
o - the object to add

clearSelection

public void clearSelection()
Deselect all objects in the list.

getItem

public Object getItem(int index)
Get the item at a specific position in the list.

getItemCount

public int getItemCount()
Get the number of items in the list.

getMaximumSize

public Dimension getMaximumSize()
Get the largest size at which this Widget can reasonably be drawn. When a WidgetContainer lays out its contents, it will attempt never to make this Widget larger than its maximum size.
Overrides:
getMaximumSize in interface Widget

getModel

public ListModel getModel()
Get the ListModel which controls the contents of this BList.

getPreferredVisibleRows

public int getPreferredVisibleRows()
Get the preferred number of rows which should be visible without using a scrollbar.

getSelectedIndex

public int getSelectedIndex()
Get the index of the first selected object, or -1 if nothing is selected.

getSelectedIndices

public int[] getSelectedIndices()
Get the indices of all selected objects, in increasing order.

getSelectedValue

public Object getSelectedValue()
Get the first selected object, or null if nothing is selected.

getSelectedValues

public Object[] getSelectedValues()
Get an array of all selected objects, in order of increasing index.

isMultipleSelectionEnabled

public boolean isMultipleSelectionEnabled()
Determine whether this list allows multiple objects to be selected.

isSelected

public boolean isSelected(int index)
Determine whether a particular object in the list is selected.

remove

public void remove(int index)
Remove an object from the list.

If you have set a custom model for this list, either by passing it to the constructor or by calling setModel(), this method has no effect.

Parameters:
index - the position from which to remove the object

removeAll

public void removeAll()
Remove all objects from the list.

If you have set a custom model for this list, either by passing it to the constructor or by calling setModel(), this method has no effect.


replace

public void replace(int index,
                    Object o)
Replace the object at a specified position in the list with a new one.

If you have set a custom model for this list, either by passing it to the constructor or by calling setModel(), this method has no effect.

Parameters:
index - the position at which to set the object
o - the new object to add

scrollToItem

public void scrollToItem(int index)
Scroll the BList's parent BScrollPane to ensure that a particular list entry is visible. If the parent is not a BScrollPane, the results of calling this method are undefined, but usually it will have no effect at all.

setContents

public void setContents(Collection c)
Set the contents of the list to the objects in a Collection. This completely replaces the contents of the list, removing any objects that were previously in it. The objects will be added in the order they are returned by the Collection's Iterator.

If you have set a custom model for this list, either by passing it to the constructor or by calling setModel(), this method has no effect.

Parameters:
c - the objects to put in the list

setContents

public void setContents(o[] )
Set the contents of the list to the objects in an array. This completely replaces the contents of the list, removing any objects that were previously in it.

If you have set a custom model for this list, either by passing it to the constructor or by calling setModel(), this method has no effect.

Parameters:

setModel

public void setModel(ListModel model)
Set the ListModel which controls the contents of this BList.

setMultipleSelectionEnabled

public void setMultipleSelectionEnabled(boolean multiple)
Set whether this list should allow multiple objects to be selected.

setPreferredVisibleRows

public void setPreferredVisibleRows(int rows)
Set the preferred number of rows which should be visible without using a scrollbar.

setSelected

public void setSelected(int index,
                        boolean selected)
Set whether a particular object should be selected.

Written by Peter Eastman.