javax.swing.plaf.basic

Class BasicListUI


public class BasicListUI
extends ListUI

The Basic Look and Feel UI delegate for the JList.

Nested Class Summary

class
BasicListUI.FocusHandler
A helper class which listens for FocusEvents from the JList.
class
BasicListUI.ListDataHandler
A helper class which listens for ListDataEvents generated by the JList's ListModel.
class
BasicListUI.ListSelectionHandler
A helper class which listens for ListSelectionEvents from the JList's ListSelectionModel.
class
BasicListUI.MouseInputHandler
A helper class which listens for MouseEvents from the JList.
class
BasicListUI.PropertyChangeHandler
Helper class which listens to PropertyChangeEvents from the JList.

Field Summary

protected int
cellHeight
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 int
cellRendererChanged
A constant to indicate that the cellRenderer has changed.
protected int
cellWidth
The width of a single cell in the list.
protected static int
fixedCellHeightChanged
A constant to indicate that the fixedCellHeight has changed.
protected static int
fixedCellWidthChanged
A constant to indicate that the fixedCellWidth has changed.
protected FocusListener
focusListener
The current focus listener.
protected static int
fontChanged
A constant to indicate that the font has changed.
protected JList
list
Saved reference to the list this UI was created for.
protected ListDataListener
listDataListener
The data listener listening to the model.
protected ListSelectionListener
listSelectionListener
The selection listener listening to the selection model.
protected static int
modelChanged
A constant to indicate that the model has changed.
protected MouseInputListener
mouseInputListener
The mouse listener listening to the list.
protected PropertyChangeListener
propertyChangeListener
The property change listener listening to the list.
protected static int
prototypeCellValueChanged
A constant to indicate that the prototypeCellValue has changed.
protected CellRendererPane
rendererPane
The CellRendererPane that is used for painting.
protected static int
selectionModelChanged
A constant to indicate that the selection model has changed.
protected int
updateLayoutStateNeeded
A bitmask that indicates which properties of the JList have changed.

Constructor Summary

BasicListUI()
Creates a new BasicListUI object.

Method Summary

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.
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.
protected FocusListener
createFocusListener()
Creates and returns the focus listener for this UI.
protected ListDataListener
createListDataListener()
Creates and returns the list data listener for this UI.
protected ListSelectionListener
createListSelectionListener()
Creates and returns the list selection listener for this UI.
protected MouseInputListener
createMouseInputListener()
Creates and returns the mouse input listener for this UI.
protected PropertyChangeListener
createPropertyChangeListener()
Creates and returns the property change listener for this UI.
static ComponentUI
createUI(JComponent c)
Creates a new BasicListUI for the component.
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).
Dimension
getPreferredSize(JComponent c)
Gets the size this list would prefer to assume.
protected int
getRowHeight(int row)
Calculate the height of a particular row.
Point
indexToLocation(JList l, int index)
Determines the location of the specified cell.
protected void
installDefaults()
Installs various default settings (mostly colors) from the UIDefaults into the JList
protected void
installKeyboardActions()
Installs keyboard actions for this UI in the JList.
protected void
installListeners()
Attaches all the listeners we have in the UI class to the JList, its model and its selection model.
void
installUI(JComponent c)
Installs the various aspects of the UI in the JList.
int
locationToIndex(JList l, Point location)
Computes the index of a list cell given a point within the list.
protected void
maybeUpdateLayoutState()
Calls updateLayoutState() if updateLayoutStateNeeded is nonzero, then resets updateLayoutStateNeeded to zero.
void
paint(Graphics g, JComponent c)
Paints the list by repeatedly calling paintCell(Graphics,int,Rectangle,ListCellRenderer,ListModel,ListSelectionModel,int) for each visible cell in the list.
protected void
paintCell(Graphics g, int row, Rectangle bounds, ListCellRenderer rend, ListModel data, ListSelectionModel sel, int lead)
Paints a single cell in the list.
protected void
selectNextIndex()
Selects the next list item and force it to be visible.
protected void
selectPreviousIndex()
Selects the previous list item and force it to be visible.
protected void
uninstallDefaults()
Resets to null those defaults which were installed in installDefaults()
protected void
uninstallKeyboardActions()
Uninstalls keyboard actions for this UI in the JList.
protected void
uninstallListeners()
Detaches all the listeners we attached in installListeners().
void
uninstallUI(JComponent c)
Uninstalls all the aspects of the UI which were installed in installUI(JComponent).
protected void
updateLayoutState()
Recomputes the cellHeights, cellHeight, and cellWidth properties by examining the variouis properties of the JList.

Methods inherited from class javax.swing.plaf.ListUI

getCellBounds, indexToLocation, locationToIndex

Methods inherited from class javax.swing.plaf.ComponentUI

contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI, update

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

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 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 cellHeight is used.

cellRendererChanged

protected static final int cellRendererChanged
A constant to indicate that the cellRenderer has changed.
Field Value:
64

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.
Field Value:
16

fixedCellWidthChanged

protected static final int fixedCellWidthChanged
A constant to indicate that the fixedCellWidth has changed.
Field Value:
8

focusListener

protected FocusListener focusListener
The current focus listener.

fontChanged

protected static final int fontChanged
A constant to indicate that the font has changed.
Field Value:
4

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.
Field Value:
1

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.
Field Value:
32

rendererPane

protected CellRendererPane rendererPane
The CellRendererPane that is used for painting.

selectionModelChanged

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

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.

Constructor Details

BasicListUI

public BasicListUI()
Creates a new BasicListUI object.

Method Details

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

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.
Overrides:
createUI in interface ComponentUI
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).
Overrides:
getCellBounds in interface ListUI
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 getCellBounds(JList,int,int) over the entire list.
Overrides:
getPreferredSize in interface ComponentUI
Parameters:
c - Ignored; uses the saved JList reference
Returns:
DOCUMENT ME!

getRowHeight

protected int getRowHeight(int row)
Calculate the height of a particular row. If there is a fixed cellHeight, return it; otherwise return the specific row height requested from the 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)
Determines the location of the specified cell.
Overrides:
indexToLocation in interface ListUI
Parameters:
index - the zero-based index of the cell whose location shall be determined.
Returns:
the position of the top left corner of the cell in the JList coordinate system, or null if cell does not designate a valid cell.

installDefaults

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

installKeyboardActions

protected void installKeyboardActions()
Installs keyboard actions for this UI in the JList.

installListeners

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

installUI

public void installUI(JComponent c)
Installs the various aspects of the UI in the JList. In particular, calls installDefaults(), installListeners() and installKeyboardActions(). Also saves a reference to the provided component, cast to a JList.
Overrides:
installUI in interface ComponentUI
Parameters:
c - The 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.
Overrides:
locationToIndex in interface ListUI
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 updateLayoutState() if updateLayoutStateNeeded is nonzero, then resets updateLayoutStateNeeded to zero.

paint

public void paint(Graphics g,
                  JComponent c)
Paints the list by repeatedly calling paintCell(Graphics,int,Rectangle,ListCellRenderer,ListModel,ListSelectionModel,int) for each visible cell in the list.
Overrides:
paint in interface ComponentUI
Parameters:
g - The graphics context to paint with
c - Ignored; uses the saved 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 installDefaults()

uninstallKeyboardActions

protected void uninstallKeyboardActions()
Uninstalls keyboard actions for this UI in the JList.

uninstallListeners

protected void uninstallListeners()
Detaches all the listeners we attached in installListeners().

uninstallUI

public void uninstallUI(JComponent c)
Uninstalls all the aspects of the UI which were installed in installUI(JComponent). When finished uninstalling, drops the saved reference to the JList.
Overrides:
uninstallUI in interface ComponentUI
Parameters:
c - Ignored; the UI is uninstalled from the JList reference saved during the call to installUI(JComponent)

updateLayoutState

protected void updateLayoutState()
Recomputes the cellHeights, cellHeight, and cellWidth properties by examining the variouis properties of the JList.

BasicListUI.java -- Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.