JavaTM 2 Platform
Standard Edition

javax.swing.plaf.basic
Class BasicListUI

java.lang.Object
  |
  +--javax.swing.plaf.ComponentUI
        |
        +--javax.swing.plaf.ListUI
              |
              +--javax.swing.plaf.basic.BasicListUI

public class BasicListUI
extends ListUI

A Windows L&F implementation of ListUI.


Inner Class Summary
 class BasicListUI.FocusHandler
          This inner class is marked "public" due to a compiler bug.
 class BasicListUI.ListDataHandler
          The ListDataListener that's added to the JLists model at installUI time, and whenever the JList.model property changes.
 class BasicListUI.ListSelectionHandler
          The ListSelectionListener that's added to the JLists selection model at installUI time, and whenever the JList.selectionModel property changes.
 class BasicListUI.MouseInputHandler
          Mouse input, and focus handling for JList.
 class BasicListUI.PropertyChangeHandler
          The PropertyChangeListener that's added to the JList at installUI time.
 
Field Summary
protected  int cellHeight
           
protected  int[] cellHeights
           
protected static int cellRendererChanged
           
protected  int cellWidth
           
protected static int fixedCellHeightChanged
           
protected static int fixedCellWidthChanged
           
protected  FocusListener focusListener
           
protected static int fontChanged
           
protected  JList list
           
protected  ListDataListener listDataListener
           
protected  ListSelectionListener listSelectionListener
           
protected static int modelChanged
           
protected  MouseInputListener mouseInputListener
           
protected  PropertyChangeListener propertyChangeListener
           
protected static int prototypeCellValueChanged
           
protected  CellRendererPane rendererPane
           
protected static int selectionModelChanged
           
protected  int updateLayoutStateNeeded
           
 
Constructor Summary
BasicListUI()
           
 
Method Summary
protected  int convertRowToY(int row)
          Return the JList relative Y coordinate of the origin of the specified row or -1 if row isn't valid.
protected  int convertYToRow(int y0)
          Convert the JList relative coordinate to the row that contains it, based on the current layout.
protected  FocusListener createFocusListener()
           
protected  ListDataListener createListDataListener()
          Creates an instance of ListDataListener that's added to the JLists by model as needed.
protected  ListSelectionListener createListSelectionListener()
          Creates an instance of ListSelectionHandler that's added to the JLists by selectionModel as needed.
protected  MouseInputListener createMouseInputListener()
          Creates a delegate that implements MouseInputListener.
protected  PropertyChangeListener createPropertyChangeListener()
          Creates an instance of PropertyChangeHandler that's added to the JList by installUI().
static ComponentUI createUI(JComponent list)
          Returns a new instance of BasicListUI.
 Rectangle getCellBounds(JList list, int index1, int index2)
          Returns the bounds of the specified item in JList coordinates, null if index isn't valid.
 Dimension getMaximumSize(JComponent c)
           
 Dimension getMinimumSize(JComponent c)
           
 Dimension getPreferredSize(JComponent c)
          The preferredSize of a list is total height of the rows and the maximum width of the cells.
protected  int getRowHeight(int row)
          Returns the height of the specified row based on the current layout.
 Point indexToLocation(JList list, int index)
          Returns the origin of the specified item in JList coordinates, null if index isn't valid.
protected  void installDefaults()
          Initialize JList properties, e.g.
protected  void installKeyboardActions()
          Register keyboard actions for the up and down arrow keys.
protected  void installListeners()
          Create and install the listeners for the JList, its model, and its selectionModel.
 void installUI(JComponent c)
          Initializes this.list by calling installDefaults(), installListeners(), and installKeyboardActions() in order.
 int locationToIndex(JList list, Point location)
          Convert a point in JList coordinates to the index of the cell at that location.
protected  void maybeUpdateLayoutState()
          If updateLayoutStateNeeded is non zero, call updateLayoutState() and reset updateLayoutStateNeeded.
 void paint(Graphics g, JComponent c)
          Paint the rows that intersect the Graphics objects clipRect.
protected  void paintCell(Graphics g, int row, Rectangle rowBounds, ListCellRenderer cellRenderer, ListModel dataModel, ListSelectionModel selModel, int leadIndex)
          Paint one List cell: compute the relevant state, get the "rubber stamp" cell renderer component, and then use the CellRendererPane to paint it.
protected  void selectNextIndex()
          Selected the previous row and force it to be visible.
protected  void selectPreviousIndex()
          Selected the previous row and force it to be visible.
protected  void uninstallDefaults()
          Set the JList properties that haven't been explicitly overriden to null.
protected  void uninstallKeyboardActions()
          Unregister keyboard actions for the up and down arrow keys.
protected  void uninstallListeners()
          Remove the listeners for the JList, its model, and its selectionModel.
 void uninstallUI(JComponent c)
          Uninitializes this.list by calling uninstallListeners(), uninstallKeyboardActions(), and uninstallDefaults() in order.
protected  void updateLayoutState()
          Recompute the value of cellHeight or cellHeights based and cellWidth, based on the current font and the current values of fixedCellWidth, fixedCellHeight, and prototypeCellValue.
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

list

protected JList list

rendererPane

protected CellRendererPane rendererPane

focusListener

protected FocusListener focusListener

mouseInputListener

protected MouseInputListener mouseInputListener

listSelectionListener

protected ListSelectionListener listSelectionListener

listDataListener

protected ListDataListener listDataListener

propertyChangeListener

protected PropertyChangeListener propertyChangeListener

cellHeights

protected int[] cellHeights

cellHeight

protected int cellHeight

cellWidth

protected int cellWidth

updateLayoutStateNeeded

protected int updateLayoutStateNeeded

modelChanged

protected static final int modelChanged

selectionModelChanged

protected static final int selectionModelChanged

fontChanged

protected static final int fontChanged

fixedCellWidthChanged

protected static final int fixedCellWidthChanged

fixedCellHeightChanged

protected static final int fixedCellHeightChanged

prototypeCellValueChanged

protected static final int prototypeCellValueChanged

cellRendererChanged

protected static final int cellRendererChanged
Constructor Detail

BasicListUI

public BasicListUI()
Method Detail

paintCell

protected void paintCell(Graphics g,
                         int row,
                         Rectangle rowBounds,
                         ListCellRenderer cellRenderer,
                         ListModel dataModel,
                         ListSelectionModel selModel,
                         int leadIndex)
Paint one List cell: compute the relevant state, get the "rubber stamp" cell renderer component, and then use the CellRendererPane to paint it. Subclasses may want to override this method rather than paint().
See Also:
paint(java.awt.Graphics, javax.swing.JComponent)

paint

public void paint(Graphics g,
                  JComponent c)
Paint the rows that intersect the Graphics objects clipRect. This method calls paintCell as necessary. Subclasses may want to override these methods.
Overrides:
paint in class ComponentUI
See Also:
paintCell(java.awt.Graphics, int, java.awt.Rectangle, javax.swing.ListCellRenderer, javax.swing.ListModel, javax.swing.ListSelectionModel, int)

getPreferredSize

public Dimension getPreferredSize(JComponent c)
The preferredSize of a list is total height of the rows and the maximum width of the cells. If JList.fixedCellHeight is specified then the total height of the rows is just (cellVerticalMargins + fixedCellHeight) * model.getSize() where rowVerticalMargins is the space we allocate for drawing the yellow focus outline. Similarly if JListfixedCellWidth is specified then we just use that plus the horizontal margins.
Overrides:
getPreferredSize in class ComponentUI
Parameters:
c - The JList component.
Returns:
The total size of the list.

getMinimumSize

public Dimension getMinimumSize(JComponent c)
Overrides:
getMinimumSize in class ComponentUI
See Also:
getPreferredSize(javax.swing.JComponent)

getMaximumSize

public Dimension getMaximumSize(JComponent c)
Overrides:
getMaximumSize in class ComponentUI
See Also:
getPreferredSize(javax.swing.JComponent)

selectPreviousIndex

protected void selectPreviousIndex()
Selected the previous row and force it to be visible. Called by the KeyEvent.VK_UP keyboard action.
See Also:
installKeyboardActions(), JList.ensureIndexIsVisible(int)

selectNextIndex

protected void selectNextIndex()
Selected the previous row and force it to be visible. Called by the KeyEvent.VK_DOWN keyboard action.
See Also:
installKeyboardActions(), JList.ensureIndexIsVisible(int)

installKeyboardActions

protected void installKeyboardActions()
Register keyboard actions for the up and down arrow keys. The actions just call out to protected methods, subclasses that want to override or extend keyboard behavior should consider just overriding those methods. This method is called at installUI() time.
See Also:
selectPreviousIndex(), selectNextIndex(), installUI(javax.swing.JComponent)

uninstallKeyboardActions

protected void uninstallKeyboardActions()
Unregister keyboard actions for the up and down arrow keys. This method is called at uninstallUI() time - subclassess should ensure that all of the keyboard actions registered at installUI time are removed here.
See Also:
selectPreviousIndex(), selectNextIndex(), installUI(javax.swing.JComponent)

installListeners

protected void installListeners()
Create and install the listeners for the JList, its model, and its selectionModel. This method is called at installUI() time.
See Also:
installUI(javax.swing.JComponent), uninstallListeners()

uninstallListeners

protected void uninstallListeners()
Remove the listeners for the JList, its model, and its selectionModel. All of the listener fields, are reset to null here. This method is called at uninstallUI() time, it should be kept in sync with installListeners.
See Also:
uninstallUI(javax.swing.JComponent), installListeners()

installDefaults

protected void installDefaults()
Initialize JList properties, e.g. font, foreground, and background, and add the CellRendererPane. The font, foreground, and background properties are only set if their current value is either null or a UIResource, other properties are set if the current value is null.
See Also:
uninstallDefaults(), installUI(javax.swing.JComponent), CellRendererPane

uninstallDefaults

protected void uninstallDefaults()
Set the JList properties that haven't been explicitly overriden to null. A property is considered overridden if its current value is not a UIResource.
See Also:
installDefaults(), uninstallUI(javax.swing.JComponent), CellRendererPane

installUI

public void installUI(JComponent c)
Initializes this.list by calling installDefaults(), installListeners(), and installKeyboardActions() in order.
Overrides:
installUI in class ComponentUI
See Also:
installDefaults(), installListeners(), installKeyboardActions()

uninstallUI

public void uninstallUI(JComponent c)
Uninitializes this.list by calling uninstallListeners(), uninstallKeyboardActions(), and uninstallDefaults() in order. Sets this.list to null.
Overrides:
uninstallUI in class ComponentUI
See Also:
uninstallListeners(), uninstallKeyboardActions(), uninstallDefaults()

createUI

public static ComponentUI createUI(JComponent list)
Returns a new instance of BasicListUI. BasicListUI delegates are allocated one per JList.
Returns:
A new ListUI implementation for the Windows look and feel.

locationToIndex

public int locationToIndex(JList list,
                           Point location)
Description copied from class: ListUI
Convert a point in JList coordinates to the index of the cell at that location. Returns -1 if there's no cell the specified location.
Overrides:
locationToIndex in class ListUI
Returns:
The index of the cell at location, or -1.
See Also:
ListUI.locationToIndex(javax.swing.JList, java.awt.Point)

indexToLocation

public Point indexToLocation(JList list,
                             int index)
Description copied from class: ListUI
Returns the origin of the specified item in JList coordinates, null if index isn't valid.
Overrides:
indexToLocation in class ListUI
Returns:
The origin of the index'th cell.
See Also:
ListUI.indexToLocation(javax.swing.JList, int)

getCellBounds

public Rectangle getCellBounds(JList list,
                               int index1,
                               int index2)
Description copied from class: ListUI
Returns the bounds of the specified item in JList coordinates, null if index isn't valid.
Overrides:
getCellBounds in class ListUI
Returns:
The bounds of the index'th cell.
See Also:
ListUI.getCellBounds(javax.swing.JList, int, int)

getRowHeight

protected int getRowHeight(int row)
Returns the height of the specified row based on the current layout.
Returns:
The specified row height or -1 if row isn't valid.
See Also:
convertYToRow(int), convertRowToY(int), updateLayoutState()

convertYToRow

protected int convertYToRow(int y0)
Convert the JList relative coordinate to the row that contains it, based on the current layout. If y0 doesn't fall within any row, return -1.
Returns:
The row that contains y0, or -1.
See Also:
getRowHeight(int), updateLayoutState()

convertRowToY

protected int convertRowToY(int row)
Return the JList relative Y coordinate of the origin of the specified row or -1 if row isn't valid.
Returns:
The Y coordinate of the origin of row, or -1.
See Also:
getRowHeight(int), updateLayoutState()

maybeUpdateLayoutState

protected void maybeUpdateLayoutState()
If updateLayoutStateNeeded is non zero, call updateLayoutState() and reset updateLayoutStateNeeded. This method should be called by methods before doing any computation based on the geometry of the list. For example it's the first call in paint() and getPreferredSize().
See Also:
updateLayoutState()

updateLayoutState

protected void updateLayoutState()
Recompute the value of cellHeight or cellHeights based and cellWidth, based on the current font and the current values of fixedCellWidth, fixedCellHeight, and prototypeCellValue.
See Also:
maybeUpdateLayoutState()

createMouseInputListener

protected MouseInputListener createMouseInputListener()
Creates a delegate that implements MouseInputListener. The delegate is added to the corresponding java.awt.Component listener lists at installUI() time. Subclasses can override this method to return a custom MouseInputListener, e.g.
 class MyListUI extends BasicListUI {
    protected MouseInputListener createMouseInputListener() {
        return new MyMouseInputHandler();
    }
    public class MyMouseInputHandler extends MouseInputHandler {
        public void mouseMoved(MouseEvent e) {
            // do some extra work when the mouse moves
            super.mouseMoved(e);
        }
    }
 }
 
See Also:
BasicListUI.MouseInputHandler, installUI(javax.swing.JComponent)

createFocusListener

protected FocusListener createFocusListener()

createListSelectionListener

protected ListSelectionListener createListSelectionListener()
Creates an instance of ListSelectionHandler that's added to the JLists by selectionModel as needed. Subclasses can override this method to return a custom ListSelectionListener, e.g.
 class MyListUI extends BasicListUI {
    protected ListSelectionListener createListSelectionListener() {
        return new MySelectionListener();
    }
    public class MySelectionListener extends ListSelectionHandler {
        public void valueChanged(ListSelectionEvent e) {
            // do some extra work when the selection changes
            super.valueChange(e);
        }
    }
 }
 
See Also:
BasicListUI.ListSelectionHandler, installUI(javax.swing.JComponent)

createListDataListener

protected ListDataListener createListDataListener()
Creates an instance of ListDataListener that's added to the JLists by model as needed. Subclasses can override this method to return a custom ListDataListener, e.g.
 class MyListUI extends BasicListUI {
    protected ListDataListener createListDataListener() {
        return new MyListDataListener();
    }
    public class MyListDataListener extends ListDataHandler {
        public void contentsChanged(ListDataEvent e) {
            // do some extra work when the models contents change
            super.contentsChange(e);
        }
    }
 }
 
See Also:
ListDataListener, JList.getModel(), installUI(javax.swing.JComponent)

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Creates an instance of PropertyChangeHandler that's added to the JList by installUI(). Subclasses can override this method to return a custom PropertyChangeListener, e.g.
 class MyListUI extends BasicListUI {
    protected PropertyChangeListener createPropertyChangeListener() {
        return new MyPropertyChangeListener();
    }
    public class MyPropertyChangeListener extends PropertyChangeHandler {
        public void propertyChange(PropertyChangeEvent e) {
            if (e.getPropertyName().equals("model")) {
                // do some extra work when the model changes
            }
            super.propertyChange(e);
        }
    }
 }
 
See Also:
PropertyChangeListener, installUI(javax.swing.JComponent)

JavaTM 2 Platform
Standard Edition

Submit a bug or feature
Java, Java 2D, and JDBC are a trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.