public class BasicXListUI extends BasicListUI
ListUI
for JXList.
BasicXListUI
instances cannot be shared between multiple
lists.The heart of added functionality is to support sorting/filtering, that is keep model-selection and RowSorter state synchronized. The details are delegated to a ListSortUI, but this class is responsible to manage the sortUI on changes of list properties, model and view selection (same strategy as in JXTable).
Note: this delegate is mostly a 1:1 copy of BasicListUI. The difference is that it accesses the list elements and list elementCount exclusively through the JXList api. This allows a clean implementation of sorting/filtering.
The differences (goal was to touch as little code as possible as this needs to be updated on every change to core until that is changed to not access the list's model directly, sigh) for core functionality:
Modifier and Type | Class and Description |
---|---|
private static class |
BasicXListUI.Actions |
class |
BasicXListUI.FocusHandler
This inner class is marked "public" due to a compiler bug.
|
private class |
BasicXListUI.Handler |
class |
BasicXListUI.ListDataHandler
The ListDataListener that's added to the JLists model at
installUI time, and whenever the JList.model property changes.
|
class |
BasicXListUI.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 |
BasicXListUI.ListTransferHandler |
class |
BasicXListUI.MouseInputHandler
Mouse input, and focus handling for JList.
|
class |
BasicXListUI.PropertyChangeHandler
The PropertyChangeListener that's added to the JList at
installUI time.
|
Modifier and Type | Field and Description |
---|---|
private static StringBuilder |
BASELINE_COMPONENT_KEY |
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 TransferHandler |
defaultTransferHandler |
private static int |
DROP_LINE_THICKNESS |
private static int |
EXTEND_SELECTION
Used by IncrementLeadSelectionAction.
|
protected static int |
fixedCellHeightChanged |
protected static int |
fixedCellWidthChanged |
protected FocusListener |
focusListener |
protected static int |
fontChanged |
private BasicXListUI.Handler |
handler |
private static int |
heightChanged |
private boolean |
isFileList
Local cache of JList's client property "List.isFileList"
|
private boolean |
isLeftToRight
Local cache of JList's component orientation property
|
private int |
layoutOrientation
The layout orientation of the list.
|
private static int |
layoutOrientationChanged |
protected JXList |
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 |
private ListModel |
modelX |
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 PropertyChangeListener |
propertyChangeListener |
protected static int |
prototypeCellValueChanged |
protected CellRendererPane |
rendererPane |
private int |
rowsPerColumn
Number of rows per column.
|
protected static int |
selectionModelChanged |
private ListSortUI |
sortUI |
private long |
timeFactor
The time factor to treate the series of typed alphanumeric key
as prefix for first letter navigation.
|
protected int |
updateLayoutStateNeeded |
private static int |
widthChanged |
Constructor and Description |
---|
BasicXListUI() |
Modifier and Type | Method and Description |
---|---|
private static int |
adjustIndex(int index,
JList list) |
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.
|
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 BasicXListUI.
|
int |
getBaseline(JComponent c,
int width,
int height)
Returns the baseline.
|
Component.BaselineResizeBehavior |
getBaselineResizeBehavior(JComponent c)
Returns an enum indicating how the baseline of the component
changes as the size changes.
|
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) |
private Rectangle |
getDropLineRect(JList.DropLocation loc) |
protected Object |
getElementAt(int viewIndex) |
protected int |
getElementCount() |
private BasicXListUI.Handler |
getHandler() |
private int |
getHeight(int column,
int row)
Returns the height of the cell at the passed in location.
|
(package private) InputMap |
getInputMap(int condition) |
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.
|
protected ListSortUI |
getSortUI() |
protected ListModel |
getViewModel()
Compatibility Wrapper: a synthetic model which delegates to list api and throws
|
Point |
indexToLocation(JList list,
int index) |
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
BasicXListUI is associated with. |
protected void |
installListeners()
Create and install the listeners for the JList, its model, and its
selectionModel.
|
protected void |
installSortUI()
Installs SortUI if the list has a rowSorter.
|
void |
installUI(JComponent c)
Initializes
this.list by calling installDefaults() ,
installListeners() , and installKeyboardActions()
in order. |
void |
invalidateCellSizeCache()
Invalidates the cell size cache and revalidates/-paints the list.
|
static void |
loadActionMap(LazyActionMap map) |
int |
locationToIndex(JList list,
Point 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 |
paintDropLine(Graphics g) |
private void |
paintImpl(Graphics g,
JComponent c) |
protected boolean |
processedBySortUI(ListDataEvent e)
Returns a boolean indicating whether or not the event has been processed
by the sortUI.
|
protected boolean |
processedBySortUI(ListSelectionEvent e)
Returns a boolean indicating whether or not the event has been processed
by the sortUI.
|
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.
|
protected void |
uninstallSortUI()
Dispose and null's the sortUI if installed.
|
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.
|
private void |
updateIsFileList() |
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.
|
protected void |
updateSortUI(String property)
Called from the PropertyChangeHandler.
|
private void |
updateSortUIToRowSorterProperty() |
contains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, update
private static final StringBuilder BASELINE_COMPONENT_KEY
protected CellRendererPane rendererPane
protected FocusListener focusListener
protected MouseInputListener mouseInputListener
protected ListSelectionListener listSelectionListener
protected ListDataListener listDataListener
protected PropertyChangeListener propertyChangeListener
private BasicXListUI.Handler handler
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
private long timeFactor
private boolean isFileList
private boolean isLeftToRight
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 DROP_LINE_THICKNESS
private ListSortUI sortUI
private static final int CHANGE_LEAD
private static final int CHANGE_SELECTION
private static final int EXTEND_SELECTION
private static final TransferHandler defaultTransferHandler
public BasicXListUI()
public static void loadActionMap(LazyActionMap map)
protected ListModel getViewModel()
protected int getElementCount()
protected Object getElementAt(int viewIndex)
protected ListSortUI getSortUI()
protected void installSortUI()
protected void uninstallSortUI()
protected void updateSortUI(String property)
property
- the name of the changed property.private void updateSortUIToRowSorterProperty()
protected boolean processedBySortUI(ListDataEvent e)
e
- protected boolean processedBySortUI(ListSelectionEvent e)
e
- public void invalidateCellSizeCache()
protected void paintCell(Graphics g, int row, Rectangle rowBounds, ListCellRenderer cellRenderer, ListModel dataModel, ListSelectionModel selModel, int leadIndex)
paintCell
in class BasicListUI
paint(java.awt.Graphics, javax.swing.JComponent)
public void paint(Graphics g, JComponent c)
private void paintImpl(Graphics g, JComponent c)
private void paintDropLine(Graphics g)
private Rectangle getDropLineRect(JList.DropLocation loc)
public int getBaseline(JComponent c, int width, int height)
getBaseline
in class BasicListUI
NullPointerException
IllegalArgumentException
JComponent.getBaseline(int, int)
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
getBaselineResizeBehavior
in class BasicListUI
NullPointerException
JComponent.getBaseline(int, 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 BasicListUI
c
- The JList component.protected void selectPreviousIndex()
selectPreviousIndex
in class BasicListUI
JList.ensureIndexIsVisible(int)
protected void selectNextIndex()
selectNextIndex
in class BasicListUI
JList.ensureIndexIsVisible(int)
protected void installKeyboardActions()
JList
that the
BasicXListUI
is associated with. This method is called at
installUI() time.installKeyboardActions
in class BasicListUI
installUI(javax.swing.JComponent)
InputMap getInputMap(int condition)
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.uninstallKeyboardActions
in class BasicListUI
installUI(javax.swing.JComponent)
protected void installListeners()
installListeners
in class BasicListUI
installUI(javax.swing.JComponent)
,
uninstallListeners()
protected void uninstallListeners()
uninstallListeners
in class BasicListUI
uninstallUI(javax.swing.JComponent)
,
installListeners()
protected void installDefaults()
installDefaults
in class BasicListUI
uninstallDefaults()
,
installUI(javax.swing.JComponent)
,
CellRendererPane
private void updateIsFileList()
protected void uninstallDefaults()
uninstallDefaults
in class BasicListUI
installDefaults()
,
uninstallUI(javax.swing.JComponent)
,
CellRendererPane
public void installUI(JComponent c)
this.list
by calling installDefaults()
,
installListeners()
, and installKeyboardActions()
in order.installUI
in class BasicListUI
installDefaults()
,
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 BasicListUI
uninstallListeners()
,
uninstallKeyboardActions()
,
uninstallDefaults()
public static ComponentUI createUI(JComponent list)
public int locationToIndex(JList list, Point location)
locationToIndex
in class BasicListUI
NullPointerException
public Point indexToLocation(JList list, int index)
indexToLocation
in class BasicListUI
public Rectangle getCellBounds(JList list, int index1, int index2)
getCellBounds
in class BasicListUI
private Rectangle getCellBounds(JList list, int index)
index
is not valid.protected int getRowHeight(int row)
getRowHeight
in class BasicListUI
convertYToRow(int)
,
convertRowToY(int)
,
updateLayoutState()
protected int convertYToRow(int y0)
convertYToRow
in class BasicListUI
getRowHeight(int)
,
updateLayoutState()
protected int convertRowToY(int row)
convertRowToY
in class BasicListUI
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()
maybeUpdateLayoutState
in class BasicListUI
updateLayoutState()
protected void updateLayoutState()
updateLayoutState
in class BasicListUI
maybeUpdateLayoutState()
private void updateHorizontalLayoutState(int fixedCellWidth, int fixedCellHeight)
This updates the rowsPerColumn,
columnCount
,
preferredHeight
and potentially cellHeight
instance variables.
private BasicXListUI.Handler getHandler()
protected MouseInputListener createMouseInputListener()
class MyListUI extends BasicXListUI { 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); } } }
createMouseInputListener
in class BasicListUI
BasicXListUI.MouseInputHandler
,
installUI(javax.swing.JComponent)
protected FocusListener createFocusListener()
createFocusListener
in class BasicListUI
protected ListSelectionListener createListSelectionListener()
class MyListUI extends BasicXListUI { 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); } } }
createListSelectionListener
in class BasicListUI
BasicXListUI.ListSelectionHandler
,
installUI(javax.swing.JComponent)
private void redrawList()
protected ListDataListener createListDataListener()
class MyListUI extends BasicXListUI { 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); } } }
createListDataListener
in class BasicListUI
ListDataListener
,
JList.getModel()
,
installUI(javax.swing.JComponent)
protected PropertyChangeListener createPropertyChangeListener()
class MyListUI extends BasicXListUI { 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); } } }
createPropertyChangeListener
in class BasicListUI
PropertyChangeListener
,
installUI(javax.swing.JComponent)
private static int adjustIndex(int index, JList list)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses