javax.swing.plaf.basic

Class BasicListUI

public class BasicListUI extends ListUI

The Basic Look and Feel UI delegate for the JList.
Nested Class Summary
classBasicListUI.FocusHandler
A helper class which listens for {@link FocusEvent}s from the JList.
classBasicListUI.ListDataHandler
A helper class which listens for {@link ListDataEvent}s generated by the {@link JList}'s {@link ListModel}.
classBasicListUI.ListSelectionHandler
A helper class which listens for {@link ListSelectionEvent}s from the {@link JList}'s {@link ListSelectionModel}.
classBasicListUI.MouseInputHandler
A helper class which listens for {@link MouseEvent}s from the {@link JList}.
classBasicListUI.PropertyChangeHandler
Helper class which listens to {@link PropertyChangeEvent}s from the {@link JList}.
Field Summary
protected intcellHeight
The height of a single cell in the list.
protected int[]cellHeights
An array of varying heights of cells in the list, in cases where each cell might have a different height.
protected static intcellRendererChanged
A constant to indicate that the cellRenderer has changed.
protected intcellWidth
The width of a single cell in the list.
protected static intfixedCellHeightChanged
A constant to indicate that the fixedCellHeight has changed.
protected static intfixedCellWidthChanged
A constant to indicate that the fixedCellWidth has changed.
protected FocusListenerfocusListener
The current focus listener.
protected static intfontChanged
A constant to indicate that the font has changed.
protected JListlist
Saved reference to the list this UI was created for.
protected ListDataListenerlistDataListener
The data listener listening to the model.
protected ListSelectionListenerlistSelectionListener
The selection listener listening to the selection model.
protected static intmodelChanged
A constant to indicate that the model has changed.
protected MouseInputListenermouseInputListener
The mouse listener listening to the list.
protected PropertyChangeListenerpropertyChangeListener
The property change listener listening to the list.
protected static intprototypeCellValueChanged
A constant to indicate that the prototypeCellValue has changed.
protected CellRendererPanerendererPane
The {@link CellRendererPane} that is used for painting.
protected static intselectionModelChanged
A constant to indicate that the selection model has changed.
protected intupdateLayoutStateNeeded
A bitmask that indicates which properties of the JList have changed.
Constructor Summary
BasicListUI()
Creates a new BasicListUI object.
Method Summary
protected intconvertRowToY(int row)
Calculate the Y coordinate of the upper edge of a particular row, considering the Y coordinate 0 to occur at the top of the list.
protected intconvertYToRow(int y0)
Calculate the row number containing a particular Y coordinate, considering the Y coodrinate 0 to occur at the top of the list.
protected FocusListenercreateFocusListener()
Creates and returns the focus listener for this UI.
protected ListDataListenercreateListDataListener()
Creates and returns the list data listener for this UI.
protected ListSelectionListenercreateListSelectionListener()
Creates and returns the list selection listener for this UI.
protected MouseInputListenercreateMouseInputListener()
Creates and returns the mouse input listener for this UI.
protected PropertyChangeListenercreatePropertyChangeListener()
Creates and returns the property change listener for this UI.
static ComponentUIcreateUI(JComponent c)
Creates a new BasicListUI for the component.
RectanglegetCellBounds(JList l, int index1, int index2)
Calculate the bounds of a particular cell, considering the upper left corner of the list as the origin position (0,0).
DimensiongetPreferredSize(JComponent c)
Gets the size this list would prefer to assume.
protected intgetRowHeight(int row)
Calculate the height of a particular row.
PointindexToLocation(JList l, int index)
protected voidinstallDefaults()
Installs various default settings (mostly colors) from the {@link UIDefaults} into the {@link JList}
protected voidinstallKeyboardActions()
Installs keyboard actions for this UI in the {@link JList}.
protected voidinstallListeners()
Attaches all the listeners we have in the UI class to the {@link JList}, its model and its selection model.
voidinstallUI(JComponent c)
Installs the various aspects of the UI in the {@link JList}.
intlocationToIndex(JList l, Point location)
Computes the index of a list cell given a point within the list.
protected voidmaybeUpdateLayoutState()
Calls {@link #updateLayoutState} if {@link #updateLayoutStateNeeded} is nonzero, then resets {@link #updateLayoutStateNeeded} to zero.
voidpaint(Graphics g, JComponent c)
Paints the list by repeatedly calling {@link #paintCell} for each visible cell in the list.
protected voidpaintCell(Graphics g, int row, Rectangle bounds, ListCellRenderer rend, ListModel data, ListSelectionModel sel, int lead)
Paints a single cell in the list.
protected voidselectNextIndex()
Selects the next list item and force it to be visible.
protected voidselectPreviousIndex()
Selects the previous list item and force it to be visible.
protected voiduninstallDefaults()
Resets to null those defaults which were installed in {@link #installDefaults}
protected voiduninstallKeyboardActions()
Uninstalls keyboard actions for this UI in the {@link JList}.
protected voiduninstallListeners()
Detaches all the listeners we attached in {@link #installListeners}.
voiduninstallUI(JComponent c)
Uninstalls all the aspects of the UI which were installed in {@link #installUI}.
protected voidupdateLayoutState()
Recomputes the {@link #cellHeights}, {@link #cellHeight}, and {@link #cellWidth} properties by examining the variouis properties of the {@link JList}.

Field Detail

cellHeight

protected int cellHeight
The height of a single cell in the list. This field is used when the fixedCellHeight property of the list is set. Otherwise this field is set to -1 and {@link #cellHeights} is used instead.

cellHeights

protected int[] cellHeights
An array of varying heights of cells in the list, in cases where each cell might have a different height. This field is used when the fixedCellHeight property of the list is not set. Otherwise this field is null and {@link #cellHeight} is used.

cellRendererChanged

protected static final int cellRendererChanged
A constant to indicate that the cellRenderer has changed.

cellWidth

protected int cellWidth
The width of a single cell in the list.

fixedCellHeightChanged

protected static final int fixedCellHeightChanged
A constant to indicate that the fixedCellHeight has changed.

fixedCellWidthChanged

protected static final int fixedCellWidthChanged
A constant to indicate that the fixedCellWidth has changed.

focusListener

protected FocusListener focusListener
The current focus listener.

fontChanged

protected static final int fontChanged
A constant to indicate that the font has changed.

list

protected JList list
Saved reference to the list this UI was created for.

listDataListener

protected ListDataListener listDataListener
The data listener listening to the model.

listSelectionListener

protected ListSelectionListener listSelectionListener
The selection listener listening to the selection model.

modelChanged

protected static final int modelChanged
A constant to indicate that the model has changed.

mouseInputListener

protected MouseInputListener mouseInputListener
The mouse listener listening to the list.

propertyChangeListener

protected PropertyChangeListener propertyChangeListener
The property change listener listening to the list.

prototypeCellValueChanged

protected static final int prototypeCellValueChanged
A constant to indicate that the prototypeCellValue has changed.

rendererPane

protected CellRendererPane rendererPane
The {@link CellRendererPane} that is used for painting.

selectionModelChanged

protected static final int selectionModelChanged
A constant to indicate that the selection model has changed.

updateLayoutStateNeeded

protected int updateLayoutStateNeeded
A bitmask that indicates which properties of the JList have changed. When nonzero, indicates that the UI class is out of date with respect to the underlying list, and must recalculate the list layout before painting or performing size calculations.

See Also: modelChanged selectionModelChanged fontChanged fixedCellWidthChanged fixedCellHeightChanged prototypeCellValueChanged cellRendererChanged

Constructor Detail

BasicListUI

public BasicListUI()
Creates a new BasicListUI object.

Method Detail

convertRowToY

protected int convertRowToY(int row)
Calculate the Y coordinate of the upper edge of a particular row, considering the Y coordinate 0 to occur at the top of the list.

Parameters: row The row to calculate the Y coordinate of

Returns: The Y coordinate of the specified row, or -1 if the specified row number is invalid

convertYToRow

protected int convertYToRow(int y0)
Calculate the row number containing a particular Y coordinate, considering the Y coodrinate 0 to occur at the top of the list.

Parameters: y0 The Y coordinate to calculate the row number for

Returns: The row number containing the specified Y value, or -1 if the list model is empty

UNKNOWN: This method is specified to return -1 for an invalid Y coordinate. However, some simple tests show that the behaviour is to return the index of the last list element for an Y coordinate that lies outside of the list bounds (even for negative indices). -1 is only returned if the list model is empty.

createFocusListener

protected FocusListener createFocusListener()
Creates and returns the focus listener for this UI.

Returns: the focus listener for this UI

createListDataListener

protected ListDataListener createListDataListener()
Creates and returns the list data listener for this UI.

Returns: the list data listener for this UI

createListSelectionListener

protected ListSelectionListener createListSelectionListener()
Creates and returns the list selection listener for this UI.

Returns: the list selection listener for this UI

createMouseInputListener

protected MouseInputListener createMouseInputListener()
Creates and returns the mouse input listener for this UI.

Returns: the mouse input listener for this UI

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Creates and returns the property change listener for this UI.

Returns: the property change listener for this UI

createUI

public static ComponentUI createUI(JComponent c)
Creates a new BasicListUI for the component.

Parameters: c The component to create a UI for

Returns: A new UI

getCellBounds

public Rectangle getCellBounds(JList l, int index1, int index2)
Calculate the bounds of a particular cell, considering the upper left corner of the list as the origin position (0,0).

Parameters: l Ignored; calculates over this.list index1 The first row to include in the bounds index2 The last row to incude in the bounds

Returns: A rectangle encompassing the range of rows between index1 and index2 inclusive, or null such a rectangle couldn't be calculated for the given indexes.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Gets the size this list would prefer to assume. This is calculated by calling {@link #getCellBounds} over the entire list.

Parameters: c Ignored; uses the saved {@link JList} reference

Returns: DOCUMENT ME!

getRowHeight

protected int getRowHeight(int row)
Calculate the height of a particular row. If there is a fixed {@link #cellHeight}, return it; otherwise return the specific row height requested from the {@link #cellHeights} array. If the requested row is invalid, return -1.

Parameters: row The row to get the height of

Returns: The height, in pixels, of the specified row

indexToLocation

public Point indexToLocation(JList l, int index)

installDefaults

protected void installDefaults()
Installs various default settings (mostly colors) from the {@link UIDefaults} into the {@link JList}

See Also: BasicListUI

installKeyboardActions

protected void installKeyboardActions()
Installs keyboard actions for this UI in the {@link JList}.

installListeners

protected void installListeners()
Attaches all the listeners we have in the UI class to the {@link JList}, its model and its selection model.

See Also: BasicListUI

installUI

public void installUI(JComponent c)
Installs the various aspects of the UI in the {@link JList}. In particular, calls {@link #installDefaults}, {@link #installListeners} and {@link #installKeyboardActions}. Also saves a reference to the provided component, cast to a {@link JList}.

Parameters: c The {@link JList} to install the UI into

locationToIndex

public int locationToIndex(JList l, Point location)
Computes the index of a list cell given a point within the list. If the location lies outside the bounds of the list, the greatest index in the list model is returned.

Parameters: l the list which on which the computation is based on location the coordinates

Returns: the index of the list item that is located at the given coordinates or -1 if the list model is empty

maybeUpdateLayoutState

protected void maybeUpdateLayoutState()
Calls {@link #updateLayoutState} if {@link #updateLayoutStateNeeded} is nonzero, then resets {@link #updateLayoutStateNeeded} to zero.

paint

public void paint(Graphics g, JComponent c)
Paints the list by repeatedly calling {@link #paintCell} for each visible cell in the list.

Parameters: g The graphics context to paint with c Ignored; uses the saved {@link JList} reference

paintCell

protected void paintCell(Graphics g, int row, Rectangle bounds, ListCellRenderer rend, ListModel data, ListSelectionModel sel, int lead)
Paints a single cell in the list.

Parameters: g The graphics context to paint in row The row number to paint bounds The bounds of the cell to paint, assuming a coordinate system beginning at (0,0) in the upper left corner of the list rend A cell renderer to paint with data The data to provide to the cell renderer sel A selection model to provide to the cell renderer lead The lead selection index of the list

selectNextIndex

protected void selectNextIndex()
Selects the next list item and force it to be visible.

selectPreviousIndex

protected void selectPreviousIndex()
Selects the previous list item and force it to be visible.

uninstallDefaults

protected void uninstallDefaults()
Resets to null those defaults which were installed in {@link #installDefaults}

uninstallKeyboardActions

protected void uninstallKeyboardActions()
Uninstalls keyboard actions for this UI in the {@link JList}.

uninstallListeners

protected void uninstallListeners()
Detaches all the listeners we attached in {@link #installListeners}.

uninstallUI

public void uninstallUI(JComponent c)
Uninstalls all the aspects of the UI which were installed in {@link #installUI}. When finished uninstalling, drops the saved reference to the {@link JList}.

Parameters: c Ignored; the UI is uninstalled from the {@link JList} reference saved during the call to {@link #installUI}

updateLayoutState

protected void updateLayoutState()
Recomputes the {@link #cellHeights}, {@link #cellHeight}, and {@link #cellWidth} properties by examining the variouis properties of the {@link JList}.