buoy.widget
Class BList

java.lang.Object
  extended by buoy.event.EventSource
      extended by buoy.widget.Widget
          extended by buoy.widget.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(java.util.Collection contents)
          Create a new BList containing the objects in a Collection.
BList(javax.swing.ListModel model)
          Create a new BList whose contents are determined by a ListModel.
BList(java.lang.Object[] contents)
          Create a new BList containing the objects in an array.
 
Method Summary
 void add(int index, java.lang.Object o)
          Add an object at specified position in the middle of the list.
 void add(java.lang.Object o)
          Add an object to the end of the list.
 void clearSelection()
          Deselect all objects in the list.
 javax.swing.JList getComponent()
          Get the java.awt.Component corresponding to this Widget.
 java.lang.Object getItem(int index)
          Get the item at a specific position in the list.
 int getItemCount()
          Get the number of items in the list.
 java.awt.Dimension getMaximumSize()
          Get the largest size at which this Widget can reasonably be drawn.
 javax.swing.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.
 java.lang.Object getSelectedValue()
          Get the first selected object, or null if nothing is selected.
 java.lang.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, java.lang.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(java.util.Collection c)
          Set the contents of the list to the objects in a Collection.
 void setContents(java.lang.Object[] o)
          Set the contents of the list to the objects in an array.
 void setModel(javax.swing.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, getCursor, getFont, 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, removeEventLink
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BList

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


BList

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


BList

public BList(java.util.Collection 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.


BList

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

Method Detail

getComponent

public javax.swing.JList getComponent()
Description copied from class: Widget
Get the java.awt.Component corresponding to this Widget.

Overrides:
getComponent in class Widget

setContents

public void setContents(java.lang.Object[] 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:
o - the objects to put in the list

setContents

public void setContents(java.util.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

add

public void add(java.lang.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,
                java.lang.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

replace

public void replace(int index,
                    java.lang.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

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.


getModel

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


setModel

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


getItemCount

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


getItem

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


isMultipleSelectionEnabled

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


setMultipleSelectionEnabled

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


getPreferredVisibleRows

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


setPreferredVisibleRows

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


isSelected

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


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 java.lang.Object getSelectedValue()
Get the first selected object, or null if nothing is selected.


getSelectedValues

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


clearSelection

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


setSelected

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


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.


getMaximumSize

public java.awt.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 class Widget


Written by Peter Eastman.