|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.plaf.ComponentUI javax.swing.plaf.ListUI javax.swing.plaf.basic.BasicListUI
A Windows L&F implementation of ListUI.
Nested Class Summary | |
private static class |
BasicListUI.ClearSelectionAction
Action to clear the selection in the list. |
private static class |
BasicListUI.EndAction
Action to move the selection to the last item in the list. |
class |
BasicListUI.FocusHandler
This inner class is marked "public" due to a compiler bug. |
private static class |
BasicListUI.HomeAction
Action to move the selection to the first item in the list. |
private static class |
BasicListUI.IncrementLeadByColumnAction
IncrementLeadByColumnAction extends the selection to the next column. |
private static class |
BasicListUI.IncrementLeadSelectionAction
Action to increment the selection in the list up/down a row at a type. |
private static class |
BasicListUI.KeyHandler
|
class |
BasicListUI.ListDataHandler
The ListDataListener that's added to the JLists model at installUI time, and whenever the JList.model property changes. |
(package private) static class |
BasicListUI.ListDragGestureRecognizer
Drag gesture recognizer for JList components |
(package private) class |
BasicListUI.ListDropTargetListener
A DropTargetListener to extend the default Swing handling of drop operations by moving the list selection to the nearest location to the mouse pointer. |
class |
BasicListUI.ListSelectionHandler
The ListSelectionListener that's added to the JLists selection model at installUI time, and whenever the JList.selectionModel property changes. |
(package private) static class |
BasicListUI.ListTransferHandler
|
class |
BasicListUI.MouseInputHandler
Mouse input, and focus handling for JList. |
private static class |
BasicListUI.PageDownAction
Action to move down one page. |
private static class |
BasicListUI.PageUpAction
Action to move up one page. |
class |
BasicListUI.PropertyChangeHandler
The PropertyChangeListener that's added to the JList at installUI time. |
private static class |
BasicListUI.SelectAllAction
Action to select all the items in the list. |
Field Summary | |
protected int |
cellHeight
|
protected int[] |
cellHeights
|
protected static int |
cellRendererChanged
|
protected int |
cellWidth
|
private static int |
CHANGE_LEAD
Used by IncrementLeadSelectionAction. |
private static int |
CHANGE_SELECTION
Used by IncrementLeadSelectionAction. |
private int |
columnCount
Number of columns to create. |
private static int |
componentOrientationChanged
|
private static BasicListUI.ListDragGestureRecognizer |
defaultDragRecognizer
|
private static TransferHandler |
defaultTransferHandler
|
private static int |
EXTEND_SELECTION
Used by IncrementLeadSelectionAction. |
protected static int |
fixedCellHeightChanged
|
protected static int |
fixedCellWidthChanged
|
protected FocusListener |
focusListener
|
protected static int |
fontChanged
|
private static int |
heightChanged
|
private KeyListener |
keyListener
|
private int |
layoutOrientation
The layout orientation of the list. |
private static int |
layoutOrientationChanged
|
protected JList |
list
|
protected ListDataListener |
listDataListener
|
private int |
listHeight
Height of the list. |
protected ListSelectionListener |
listSelectionListener
|
private int |
listWidth
Width of the list. |
protected static int |
modelChanged
|
protected MouseInputListener |
mouseInputListener
|
private int |
preferredHeight
Preferred height to make the list, this is only used if the the list is layed out horizontally. |
protected java.beans.PropertyChangeListener |
propertyChangeListener
|
protected static int |
prototypeCellValueChanged
|
protected CellRendererPane |
rendererPane
|
private int |
rowsPerColumn
Number of rows per column. |
protected static int |
selectionModelChanged
|
protected int |
updateLayoutStateNeeded
|
private static int |
widthChanged
|
Constructor Summary | |
BasicListUI()
|
Method Summary | |
private int |
convertLocationToColumn(int x,
int y)
Returns the closest column to the passed in location. |
private int |
convertLocationToModel(int x,
int y)
Returns the closest location to the model index of the passed in location. |
private int |
convertLocationToRow(int x,
int y0,
boolean closest)
Returns the row at location x/y. |
private int |
convertLocationToRowInColumn(int y,
int column)
Returns the closest row that starts at the specified y-location in the passed in column. |
private int |
convertModelToColumn(int index)
Returns the column that the model index index will be
displayed in. |
private int |
convertModelToRow(int index)
Returns the row that the model index index will be
displayed in.. |
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. |
(package private) ActionMap |
createActionMap()
|
protected FocusListener |
createFocusListener()
|
private KeyListener |
createKeyListener()
Creates an instance of KeyHandler that's added to the JList by installUI(). |
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 java.beans.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. |
(package private) ActionMap |
getActionMap()
|
private Rectangle |
getCellBounds(JList list,
int index)
Gets the bounds of the specified model index, returning the resulting bounds, or null if index is not valid. |
Rectangle |
getCellBounds(JList list,
int index1,
int index2)
Returns the bounds of the specified item in JList coordinates, null if index isn't valid. |
private int |
getHeight(int column,
int row)
Returns the height of the cell at the passed in location. |
(package private) InputMap |
getInputMap(int condition)
|
Dimension |
getMaximumSize(JComponent c)
Returns the specified component's maximum size appropriate for the look and feel. |
Dimension |
getMinimumSize(JComponent c)
Returns the specified component's minimum size appropriate for the look and feel. |
private int |
getModelIndex(int column,
int row)
Returns the model index for the specified display location. |
Dimension |
getPreferredSize(JComponent c)
The preferredSize of the list depends upon the layout orientation. |
private int |
getRowCount(int column)
Returns the number of rows in the given column. |
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. font, foreground, and background, and add the CellRendererPane. |
protected void |
installKeyboardActions()
Registers the keyboard bindings on the JList that the
BasicListUI is associated with. |
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 closest 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. |
private void |
redrawList()
|
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 overridden to null. |
protected void |
uninstallKeyboardActions()
Unregisters keyboard actions installed from installKeyboardActions .
|
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. |
private void |
updateHorizontalLayoutState(int fixedCellWidth,
int fixedCellHeight)
Invoked when the list is layed out horizontally to determine how many columns to create. |
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 |
protected JList list
protected CellRendererPane rendererPane
protected FocusListener focusListener
protected MouseInputListener mouseInputListener
protected ListSelectionListener listSelectionListener
protected ListDataListener listDataListener
protected java.beans.PropertyChangeListener propertyChangeListener
private KeyListener keyListener
protected int[] cellHeights
protected int cellHeight
protected int cellWidth
protected int updateLayoutStateNeeded
private int listHeight
private int listWidth
private int layoutOrientation
private int columnCount
private int preferredHeight
private int rowsPerColumn
protected static final int modelChanged
protected static final int selectionModelChanged
protected static final int fontChanged
protected static final int fixedCellWidthChanged
protected static final int fixedCellHeightChanged
protected static final int prototypeCellValueChanged
protected static final int cellRendererChanged
private static final int layoutOrientationChanged
private static final int heightChanged
private static final int widthChanged
private static final int componentOrientationChanged
private static final int CHANGE_LEAD
private static final int CHANGE_SELECTION
private static final int EXTEND_SELECTION
private static final BasicListUI.ListDragGestureRecognizer defaultDragRecognizer
private static final TransferHandler defaultTransferHandler
Constructor Detail |
public BasicListUI()
Method Detail |
protected void paintCell(Graphics g, int row, Rectangle rowBounds, ListCellRenderer cellRenderer, ListModel dataModel, ListSelectionModel selModel, int leadIndex)
paint(java.awt.Graphics, javax.swing.JComponent)
public void paint(Graphics g, JComponent c)
paint
in class ComponentUI
g
- the Graphics
context in which to paintc
- the component being painted;
this argument is often ignored,
but might be used if the UI object is stateless
and shared by multiple componentspaintCell(java.awt.Graphics, int, java.awt.Rectangle, javax.swing.ListCellRenderer, javax.swing.ListModel, javax.swing.ListSelectionModel, int)
public Dimension getPreferredSize(JComponent c)
Layout Orientation | Preferred Size |
---|---|
JList.VERTICAL | The preferredSize of the 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 fixedCellWidth is specified then we just use that. |
JList.VERTICAL_WRAP | If the visible row count is greater than zero, the preferredHeight is the maximum cell height * visibleRowCount. If the visible row count is <= 0, the preferred height is either the current height of the list, or the maximum cell height, whichever is bigger. The preferred width is than the maximum cell width * number of columns needed. Where the number of columns needs is list.height / max cell height. Max cell height is either the fixed cell height, or is determined by iterating through all the cells to find the maximum height from the ListCellRenderer. |
JList.HORIZONTAL_WRAP | If the visible row count is greater than zero, the preferredHeight
is the maximum cell height * adjustedRowCount. Where
visibleRowCount is used to determine the number of columns.
Because this lays out horizontally the number of rows is
then determined from the column count. For example, lets say
you have a model with 10 items and the visible row count is 8.
The number of columns needed to display this is 2, but you no
longer need 8 rows to display this, you only need 5, thus
the adjustedRowCount is 5.
If the visible row
count is <= 0, the preferred height is dictated by the
number of columns, which will be as many as can fit in the width
of the |
Insets
are determined from
list.getInsets()
.
getPreferredSize
in class ComponentUI
c
- The JList component.
JComponent.getPreferredSize()
,
LayoutManager.preferredLayoutSize(java.awt.Container)
public Dimension getMinimumSize(JComponent c)
ComponentUI
null
is returned, the minimum
size will be calculated by the component's layout manager instead
(this is the preferred approach for any component with a specific
layout manager installed). The default implementation of this
method invokes getPreferredSize
and returns that value.
getMinimumSize
in class ComponentUI
c
- the component whose minimum size is being queried;
this argument is often ignored,
but might be used if the UI object is stateless
and shared by multiple components
getPreferredSize(javax.swing.JComponent)
public Dimension getMaximumSize(JComponent c)
ComponentUI
null
is returned, the maximum
size will be calculated by the component's layout manager instead
(this is the preferred approach for any component with a specific
layout manager installed). The default implementation of this
method invokes getPreferredSize
and returns that value.
getMaximumSize
in class ComponentUI
c
- the component whose maximum size is being queried;
this argument is often ignored,
but might be used if the UI object is stateless
and shared by multiple components
getPreferredSize(javax.swing.JComponent)
protected void selectPreviousIndex()
JList.ensureIndexIsVisible(int)
protected void selectNextIndex()
JList.ensureIndexIsVisible(int)
protected void installKeyboardActions()
JList
that the
BasicListUI
is associated with. This method is called at
installUI() time.
installUI(javax.swing.JComponent)
InputMap getInputMap(int condition)
ActionMap getActionMap()
ActionMap createActionMap()
protected void uninstallKeyboardActions()
installKeyboardActions
.
This method is called at uninstallUI() time - subclassess should
ensure that all of the keyboard actions registered at installUI
time are removed here.
installUI(javax.swing.JComponent)
protected void installListeners()
installUI(javax.swing.JComponent)
,
uninstallListeners()
protected void uninstallListeners()
uninstallUI(javax.swing.JComponent)
,
installListeners()
protected void installDefaults()
uninstallDefaults()
,
installUI(javax.swing.JComponent)
,
CellRendererPane
protected void uninstallDefaults()
installDefaults()
,
uninstallUI(javax.swing.JComponent)
,
CellRendererPane
public void installUI(JComponent c)
this.list
by calling installDefaults()
,
installListeners()
, and installKeyboardActions()
in order.
installUI
in class ComponentUI
c
- the component where this UI delegate is being installedinstallDefaults()
,
installListeners()
,
installKeyboardActions()
public void uninstallUI(JComponent c)
this.list
by calling uninstallListeners()
,
uninstallKeyboardActions()
, and uninstallDefaults()
in order. Sets this.list to null.
uninstallUI
in class ComponentUI
c
- the component from which this UI delegate is being removed;
this argument is often ignored,
but might be used if the UI object is stateless
and shared by multiple componentsuninstallListeners()
,
uninstallKeyboardActions()
,
uninstallDefaults()
public static ComponentUI createUI(JComponent list)
public int locationToIndex(JList list, Point location)
JList
coordinates to the closest index
of the cell at that location. To determine if the cell actually
contains the specified location use a combination of this method and
getCellBounds
. Returns -1 if the model is empty.
locationToIndex
in class ListUI
location
- The JList relative coordinates of the cell
ListUI.locationToIndex(javax.swing.JList, java.awt.Point)
public Point indexToLocation(JList list, int index)
ListUI
indexToLocation
in class ListUI
index
- The index of the JList cell.
ListUI.indexToLocation(javax.swing.JList, int)
public Rectangle getCellBounds(JList list, int index1, int index2)
ListUI
getCellBounds
in class ListUI
ListUI.getCellBounds(javax.swing.JList, int, int)
private Rectangle getCellBounds(JList list, int index)
index
is not valid.
protected int getRowHeight(int row)
convertYToRow(int)
,
convertRowToY(int)
,
updateLayoutState()
protected int convertYToRow(int y0)
getRowHeight(int)
,
updateLayoutState()
protected int convertRowToY(int row)
getRowHeight(int)
,
updateLayoutState()
private int getHeight(int column, int row)
private int convertLocationToRow(int x, int y0, boolean closest)
closest
- If true and the location doesn't exactly match a
particular location, this will return the closest row.private int convertLocationToRowInColumn(int y, int column)
private int convertLocationToModel(int x, int y)
private int getRowCount(int column)
private int getModelIndex(int column, int row)
column
xrow
is beyond the length of the
model, this will return the model size - 1.
private int convertLocationToColumn(int x, int y)
private int convertModelToRow(int index)
index
will be
displayed in..
private int convertModelToColumn(int index)
index
will be
displayed in.
protected void maybeUpdateLayoutState()
updateLayoutState()
protected void updateLayoutState()
maybeUpdateLayoutState()
private void updateHorizontalLayoutState(int fixedCellWidth, int fixedCellHeight)
This updates the rowsPerColumn,
columnCount
,
preferredHeight
and potentially cellHeight
instance variables.
protected MouseInputListener createMouseInputListener()
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); } } }
BasicListUI.MouseInputHandler
,
installUI(javax.swing.JComponent)
protected FocusListener createFocusListener()
protected ListSelectionListener createListSelectionListener()
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); } } }
BasicListUI.ListSelectionHandler
,
installUI(javax.swing.JComponent)
private void redrawList()
protected ListDataListener createListDataListener()
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); } } }
ListDataListener
,
JList.getModel()
,
installUI(javax.swing.JComponent)
protected java.beans.PropertyChangeListener createPropertyChangeListener()
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); } } }
PropertyChangeListener
,
installUI(javax.swing.JComponent)
private KeyListener createKeyListener()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |