Methods Summary |
---|
private int | convertLocationToColumn(int x, int y)Returns the closest column to the passed in location.
if (cellWidth > 0) {
if (layoutOrientation == JList.VERTICAL) {
return 0;
}
Insets insets = list.getInsets();
int col;
if (isLeftToRight) {
col = (x - insets.left) / cellWidth;
} else {
col = (list.getWidth() - x - insets.right - 1) / cellWidth;
}
if (col < 0) {
return 0;
}
else if (col >= columnCount) {
return columnCount - 1;
}
return col;
}
return 0;
|
private int | convertLocationToModel(int x, int y)Returns the closest location to the model index of the passed in
location.
int row = convertLocationToRow(x, y, true);
int column = convertLocationToColumn(x, y);
if (row >= 0 && column >= 0) {
return getModelIndex(column, row);
}
return -1;
|
private int | convertLocationToRow(int x, int y0, boolean closest)Returns the row at location x/y.
int size = list.getModel().getSize();
if (size <= 0) {
return -1;
}
Insets insets = list.getInsets();
if (cellHeights == null) {
int row = (cellHeight == 0) ? 0 :
((y0 - insets.top) / cellHeight);
if (closest) {
if (row < 0) {
row = 0;
}
else if (row >= size) {
row = size - 1;
}
}
return row;
}
else if (size > cellHeights.length) {
return -1;
}
else {
int y = insets.top;
int row = 0;
if (closest && y0 < y) {
return 0;
}
int i;
for (i = 0; i < size; i++) {
if ((y0 >= y) && (y0 < y + cellHeights[i])) {
return row;
}
y += cellHeights[i];
row += 1;
}
return i - 1;
}
|
private int | convertLocationToRowInColumn(int y, int column)Returns the closest row that starts at the specified y-location
in the passed in column.
int x = 0;
if (layoutOrientation != JList.VERTICAL) {
if (isLeftToRight) {
x = column * cellWidth;
} else {
x = list.getWidth() - (column+1)*cellWidth - list.getInsets().right;
}
}
return convertLocationToRow(x, y, true);
|
private int | convertModelToColumn(int index)Returns the column that the model index index will be
displayed in.
int size = list.getModel().getSize();
if ((index < 0) || (index >= size)) {
return -1;
}
if (layoutOrientation != JList.VERTICAL && rowsPerColumn > 0 &&
columnCount > 1) {
if (layoutOrientation == JList.VERTICAL_WRAP) {
return index / rowsPerColumn;
}
return index % columnCount;
}
return 0;
|
private int | convertModelToRow(int index)Returns the row that the model index index will be
displayed in..
int size = list.getModel().getSize();
if ((index < 0) || (index >= size)) {
return -1;
}
if (layoutOrientation != JList.VERTICAL && columnCount > 1 &&
rowsPerColumn > 0) {
if (layoutOrientation == JList.VERTICAL_WRAP) {
return index % rowsPerColumn;
}
return index / columnCount;
}
return index;
|
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.
if (row >= getRowCount(0) || row < 0) {
return -1;
}
Rectangle bounds = getCellBounds(list, row, row);
return bounds.y;
|
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.
return convertLocationToRow(0, y0, false);
|
protected java.awt.event.FocusListener | createFocusListener()
return getHandler();
|
protected javax.swing.event.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);
}
}
}
return getHandler();
|
protected javax.swing.event.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);
}
}
}
return getHandler();
|
protected javax.swing.event.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);
}
}
}
return getHandler();
|
protected java.beans.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);
}
}
}
return getHandler();
|
public static javax.swing.plaf.ComponentUI | createUI(javax.swing.JComponent list)Returns a new instance of BasicListUI. BasicListUI delegates are
allocated one per JList.
return new BasicListUI();
|
public java.awt.Rectangle | getCellBounds(javax.swing.JList list, int index1, int index2)
maybeUpdateLayoutState();
int minIndex = Math.min(index1, index2);
int maxIndex = Math.max(index1, index2);
if (minIndex >= list.getModel().getSize()) {
return null;
}
Rectangle minBounds = getCellBounds(list, minIndex);
if (minBounds == null) {
return null;
}
if (minIndex == maxIndex) {
return minBounds;
}
Rectangle maxBounds = getCellBounds(list, maxIndex);
if (maxBounds != null) {
if (layoutOrientation == JList.HORIZONTAL_WRAP) {
int minRow = convertModelToRow(minIndex);
int maxRow = convertModelToRow(maxIndex);
if (minRow != maxRow) {
minBounds.x = 0;
minBounds.width = list.getWidth();
}
}
else if (minBounds.x != maxBounds.x) {
// Different columns
minBounds.y = 0;
minBounds.height = list.getHeight();
}
minBounds.add(maxBounds);
}
return minBounds;
|
private java.awt.Rectangle | getCellBounds(javax.swing.JList list, int index)Gets the bounds of the specified model index, returning the resulting
bounds, or null if index is not valid.
maybeUpdateLayoutState();
int row = convertModelToRow(index);
int column = convertModelToColumn(index);
if (row == -1 || column == -1) {
return null;
}
Insets insets = list.getInsets();
int x;
int w = cellWidth;
int y = insets.top;
int h;
switch (layoutOrientation) {
case JList.VERTICAL_WRAP:
case JList.HORIZONTAL_WRAP:
if (isLeftToRight) {
x = insets.left + column * cellWidth;
} else {
x = list.getWidth() - insets.right - (column+1) * cellWidth;
}
y += cellHeight * row;
h = cellHeight;
break;
default:
x = insets.left;
if (cellHeights == null) {
y += (cellHeight * row);
}
else if (row >= cellHeights.length) {
y = 0;
}
else {
for(int i = 0; i < row; i++) {
y += cellHeights[i];
}
}
w = list.getWidth() - (insets.left + insets.right);
h = getRowHeight(index);
break;
}
return new Rectangle(x, y, w, h);
|
private javax.swing.plaf.basic.BasicListUI$Handler | getHandler()
if (handler == null) {
handler = DRAG_FIX ? new DragFixHandler() : new Handler();
}
return handler;
|
private int | getHeight(int column, int row)Returns the height of the cell at the passed in location.
if (column < 0 || column > columnCount || row < 0) {
return -1;
}
if (layoutOrientation != JList.VERTICAL) {
return cellHeight;
}
if (row >= list.getModel().getSize()) {
return -1;
}
return (cellHeights == null) ? cellHeight :
((row < cellHeights.length) ? cellHeights[row] : -1);
|
javax.swing.InputMap | getInputMap(int condition)
if (condition == JComponent.WHEN_FOCUSED) {
InputMap keyMap = (InputMap)DefaultLookup.get(
list, this, "List.focusInputMap");
InputMap rtlKeyMap;
if (isLeftToRight ||
((rtlKeyMap = (InputMap)DefaultLookup.get(list, this,
"List.focusInputMap.RightToLeft")) == null)) {
return keyMap;
} else {
rtlKeyMap.setParent(keyMap);
return rtlKeyMap;
}
}
return null;
|
private int | getModelIndex(int column, int row)Returns the model index for the specified display location.
If column xrow is beyond the length of the
model, this will return the model size - 1.
switch (layoutOrientation) {
case JList.VERTICAL_WRAP:
return Math.min(list.getModel().getSize() - 1, rowsPerColumn *
column + Math.min(row, rowsPerColumn-1));
case JList.HORIZONTAL_WRAP:
return Math.min(list.getModel().getSize() - 1, row * columnCount +
column);
default:
return row;
}
|
public java.awt.Dimension | getPreferredSize(javax.swing.JComponent c)The preferredSize of the list depends upon the layout orientation.
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 JList (width / max cell width), with at
least one column. The preferred height then becomes the
model size / number of columns * maximum 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.
|
The above specifies the raw preferred width and height. The resulting
preferred width is the above width + insets.left + insets.right and
the resulting preferred height is the above height + insets.top +
insets.bottom. Where the Insets are determined from
list.getInsets() .
maybeUpdateLayoutState();
int lastRow = list.getModel().getSize() - 1;
if (lastRow < 0) {
return new Dimension(0, 0);
}
Insets insets = list.getInsets();
int width = cellWidth * columnCount + insets.left + insets.right;
int height;
if (layoutOrientation != JList.VERTICAL) {
height = preferredHeight;
}
else {
Rectangle bounds = getCellBounds(list, lastRow);
if (bounds != null) {
height = bounds.y + bounds.height + insets.bottom;
}
else {
height = 0;
}
}
return new Dimension(width, height);
|
private int | getRowCount(int column)Returns the number of rows in the given column.
if (column < 0 || column >= columnCount) {
return -1;
}
if (layoutOrientation == JList.VERTICAL ||
(column == 0 && columnCount == 1)) {
return list.getModel().getSize();
}
if (column >= columnCount) {
return -1;
}
if (layoutOrientation == JList.VERTICAL_WRAP) {
if (column < (columnCount - 1)) {
return rowsPerColumn;
}
return list.getModel().getSize() - (columnCount - 1) *
rowsPerColumn;
}
// JList.HORIZONTAL_WRAP
int diff = columnCount - (columnCount * rowsPerColumn -
list.getModel().getSize());
if (column >= diff) {
return Math.max(0, rowsPerColumn - 1);
}
return rowsPerColumn;
|
protected int | getRowHeight(int row)Returns the height of the specified row based on the current layout.
return getHeight(0, row);
|
public java.awt.Point | indexToLocation(javax.swing.JList list, int index)
maybeUpdateLayoutState();
Rectangle rect = getCellBounds(list, index, index);
if (rect != null) {
return new Point(rect.x, rect.y);
}
return null;
|
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.
list.setLayout(null);
LookAndFeel.installBorder(list, "List.border");
LookAndFeel.installColorsAndFont(list, "List.background", "List.foreground", "List.font");
LookAndFeel.installProperty(list, "opaque", Boolean.TRUE);
if (list.getCellRenderer() == null) {
list.setCellRenderer((ListCellRenderer)(UIManager.get("List.cellRenderer")));
}
Color sbg = list.getSelectionBackground();
if (sbg == null || sbg instanceof UIResource) {
list.setSelectionBackground(UIManager.getColor("List.selectionBackground"));
}
Color sfg = list.getSelectionForeground();
if (sfg == null || sfg instanceof UIResource) {
list.setSelectionForeground(UIManager.getColor("List.selectionForeground"));
}
Long l = (Long)UIManager.get("List.timeFactor");
timeFactor = (l!=null) ? l.longValue() : 1000L;
updateIsFileList();
isLeftToRight = list.getComponentOrientation().isLeftToRight();
|
protected void | installKeyboardActions()Registers the keyboard bindings on the JList that the
BasicListUI is associated with. This method is called at
installUI() time.
InputMap inputMap = getInputMap(JComponent.WHEN_FOCUSED);
SwingUtilities.replaceUIInputMap(list, JComponent.WHEN_FOCUSED,
inputMap);
LazyActionMap.installLazyActionMap(list, BasicListUI.class,
"List.actionMap");
|
protected void | installListeners()Create and install the listeners for the JList, its model, and its
selectionModel. This method is called at installUI() time.
TransferHandler th = list.getTransferHandler();
if (th == null || th instanceof UIResource) {
list.setTransferHandler(defaultTransferHandler);
}
DropTarget dropTarget = list.getDropTarget();
if (dropTarget instanceof UIResource) {
try {
dropTarget.addDropTargetListener(new ListDropTargetListener());
} catch (TooManyListenersException tmle) {
// should not happen... swing drop target is multicast
}
}
focusListener = createFocusListener();
mouseInputListener = createMouseInputListener();
propertyChangeListener = createPropertyChangeListener();
listSelectionListener = createListSelectionListener();
listDataListener = createListDataListener();
list.addFocusListener(focusListener);
if (!DRAG_FIX) {
list.addMouseListener(defaultDragRecognizer);
list.addMouseMotionListener(defaultDragRecognizer);
}
list.addMouseListener(mouseInputListener);
list.addMouseMotionListener(mouseInputListener);
list.addPropertyChangeListener(propertyChangeListener);
list.addKeyListener(getHandler());
ListModel model = list.getModel();
if (model != null) {
model.addListDataListener(listDataListener);
}
ListSelectionModel selectionModel = list.getSelectionModel();
if (selectionModel != null) {
selectionModel.addListSelectionListener(listSelectionListener);
}
|
public void | installUI(javax.swing.JComponent c)Initializes this.list by calling installDefaults() ,
installListeners() , and installKeyboardActions()
in order.
list = (JList)c;
layoutOrientation = list.getLayoutOrientation();
rendererPane = new CellRendererPane();
list.add(rendererPane);
columnCount = 1;
installDefaults();
installListeners();
installKeyboardActions();
|
static void | loadActionMap(javax.swing.plaf.basic.LazyActionMap map)
map.put(new Actions(Actions.SELECT_PREVIOUS_COLUMN));
map.put(new Actions(Actions.SELECT_PREVIOUS_COLUMN_EXTEND));
map.put(new Actions(Actions.SELECT_PREVIOUS_COLUMN_CHANGE_LEAD));
map.put(new Actions(Actions.SELECT_NEXT_COLUMN));
map.put(new Actions(Actions.SELECT_NEXT_COLUMN_EXTEND));
map.put(new Actions(Actions.SELECT_NEXT_COLUMN_CHANGE_LEAD));
map.put(new Actions(Actions.SELECT_PREVIOUS_ROW));
map.put(new Actions(Actions.SELECT_PREVIOUS_ROW_EXTEND));
map.put(new Actions(Actions.SELECT_PREVIOUS_ROW_CHANGE_LEAD));
map.put(new Actions(Actions.SELECT_NEXT_ROW));
map.put(new Actions(Actions.SELECT_NEXT_ROW_EXTEND));
map.put(new Actions(Actions.SELECT_NEXT_ROW_CHANGE_LEAD));
map.put(new Actions(Actions.SELECT_FIRST_ROW));
map.put(new Actions(Actions.SELECT_FIRST_ROW_EXTEND));
map.put(new Actions(Actions.SELECT_FIRST_ROW_CHANGE_LEAD));
map.put(new Actions(Actions.SELECT_LAST_ROW));
map.put(new Actions(Actions.SELECT_LAST_ROW_EXTEND));
map.put(new Actions(Actions.SELECT_LAST_ROW_CHANGE_LEAD));
map.put(new Actions(Actions.SCROLL_UP));
map.put(new Actions(Actions.SCROLL_UP_EXTEND));
map.put(new Actions(Actions.SCROLL_UP_CHANGE_LEAD));
map.put(new Actions(Actions.SCROLL_DOWN));
map.put(new Actions(Actions.SCROLL_DOWN_EXTEND));
map.put(new Actions(Actions.SCROLL_DOWN_CHANGE_LEAD));
map.put(new Actions(Actions.SELECT_ALL));
map.put(new Actions(Actions.CLEAR_SELECTION));
map.put(new Actions(Actions.ADD_TO_SELECTION));
map.put(new Actions(Actions.TOGGLE_AND_ANCHOR));
map.put(new Actions(Actions.EXTEND_TO));
map.put(new Actions(Actions.MOVE_SELECTION_TO));
map.put(TransferHandler.getCutAction().getValue(Action.NAME),
TransferHandler.getCutAction());
map.put(TransferHandler.getCopyAction().getValue(Action.NAME),
TransferHandler.getCopyAction());
map.put(TransferHandler.getPasteAction().getValue(Action.NAME),
TransferHandler.getPasteAction());
|
public int | locationToIndex(javax.swing.JList list, java.awt.Point location)Convert a point in 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.
maybeUpdateLayoutState();
return convertLocationToModel(location.x, location.y);
|
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().
if (updateLayoutStateNeeded != 0) {
updateLayoutState();
updateLayoutStateNeeded = 0;
}
|
public void | paint(java.awt.Graphics g, javax.swing.JComponent c)Paint the rows that intersect the Graphics objects clipRect. This
method calls paintCell as necessary. Subclasses
may want to override these methods.
switch (layoutOrientation) {
case JList.VERTICAL_WRAP:
if (list.getHeight() != listHeight) {
updateLayoutStateNeeded |= heightChanged;
redrawList();
}
break;
case JList.HORIZONTAL_WRAP:
if (list.getWidth() != listWidth) {
updateLayoutStateNeeded |= widthChanged;
redrawList();
}
break;
default:
break;
}
maybeUpdateLayoutState();
ListCellRenderer renderer = list.getCellRenderer();
ListModel dataModel = list.getModel();
ListSelectionModel selModel = list.getSelectionModel();
int size;
if ((renderer == null) || (size = dataModel.getSize()) == 0) {
return;
}
// Determine how many columns we need to paint
Rectangle paintBounds = g.getClipBounds();
int startColumn, endColumn;
if (c.getComponentOrientation().isLeftToRight()) {
startColumn = convertLocationToColumn(paintBounds.x,
paintBounds.y);
endColumn = convertLocationToColumn(paintBounds.x +
paintBounds.width,
paintBounds.y);
} else {
startColumn = convertLocationToColumn(paintBounds.x +
paintBounds.width,
paintBounds.y);
endColumn = convertLocationToColumn(paintBounds.x,
paintBounds.y);
}
int maxY = paintBounds.y + paintBounds.height;
int leadIndex = list.getLeadSelectionIndex();
int rowIncrement = (layoutOrientation == JList.HORIZONTAL_WRAP) ?
columnCount : 1;
for (int colCounter = startColumn; colCounter <= endColumn;
colCounter++) {
// And then how many rows in this columnn
int row = convertLocationToRowInColumn(paintBounds.y, colCounter);
int rowCount = getRowCount(colCounter);
int index = getModelIndex(colCounter, row);
Rectangle rowBounds = getCellBounds(list, index, index);
if (rowBounds == null) {
// Not valid, bail!
return;
}
while (row < rowCount && rowBounds.y < maxY &&
index < size) {
rowBounds.height = getHeight(colCounter, row);
g.setClip(rowBounds.x, rowBounds.y, rowBounds.width,
rowBounds.height);
g.clipRect(paintBounds.x, paintBounds.y, paintBounds.width,
paintBounds.height);
paintCell(g, index, rowBounds, renderer, dataModel, selModel,
leadIndex);
rowBounds.y += rowBounds.height;
index += rowIncrement;
row++;
}
}
|
protected void | paintCell(java.awt.Graphics g, int row, java.awt.Rectangle rowBounds, javax.swing.ListCellRenderer cellRenderer, javax.swing.ListModel dataModel, javax.swing.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().
Object value = dataModel.getElementAt(row);
boolean cellHasFocus = list.hasFocus() && (row == leadIndex);
boolean isSelected = selModel.isSelectedIndex(row);
Component rendererComponent =
cellRenderer.getListCellRendererComponent(list, value, row, isSelected, cellHasFocus);
int cx = rowBounds.x;
int cy = rowBounds.y;
int cw = rowBounds.width;
int ch = rowBounds.height;
if (isFileList) {
// Shrink renderer to preferred size. This is mostly used on Windows
// where selection is only shown around the file name, instead of
// across the whole list cell.
int w = Math.min(cw, rendererComponent.getPreferredSize().width + 4);
if (!isLeftToRight) {
cx += (cw - w);
}
cw = w;
}
rendererPane.paintComponent(g, rendererComponent, list, cx, cy, cw, ch, true);
|
private void | redrawList()
list.revalidate();
list.repaint();
|
protected void | selectNextIndex()Selected the previous row and force it to be visible.
int s = list.getSelectedIndex();
if((s + 1) < list.getModel().getSize()) {
s += 1;
list.setSelectedIndex(s);
list.ensureIndexIsVisible(s);
}
|
protected void | selectPreviousIndex()Selected the previous row and force it to be visible.
int s = list.getSelectedIndex();
if(s > 0) {
s -= 1;
list.setSelectedIndex(s);
list.ensureIndexIsVisible(s);
}
|
protected void | uninstallDefaults()Set the JList properties that haven't been explicitly overridden to
null. A property is considered overridden if its current value
is not a UIResource.
LookAndFeel.uninstallBorder(list);
if (list.getFont() instanceof UIResource) {
list.setFont(null);
}
if (list.getForeground() instanceof UIResource) {
list.setForeground(null);
}
if (list.getBackground() instanceof UIResource) {
list.setBackground(null);
}
if (list.getSelectionBackground() instanceof UIResource) {
list.setSelectionBackground(null);
}
if (list.getSelectionForeground() instanceof UIResource) {
list.setSelectionForeground(null);
}
if (list.getCellRenderer() instanceof UIResource) {
list.setCellRenderer(null);
}
if (list.getTransferHandler() instanceof UIResource) {
list.setTransferHandler(null);
}
|
protected void | uninstallKeyboardActions()Unregisters keyboard actions installed from
installKeyboardActions .
This method is called at uninstallUI() time - subclassess should
ensure that all of the keyboard actions registered at installUI
time are removed here.
SwingUtilities.replaceUIActionMap(list, null);
SwingUtilities.replaceUIInputMap(list, JComponent.WHEN_FOCUSED, null);
|
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.
list.removeFocusListener(focusListener);
if (!DRAG_FIX) {
list.removeMouseListener(defaultDragRecognizer);
list.removeMouseMotionListener(defaultDragRecognizer);
}
list.removeMouseListener(mouseInputListener);
list.removeMouseMotionListener(mouseInputListener);
list.removePropertyChangeListener(propertyChangeListener);
list.removeKeyListener(getHandler());
ListModel model = list.getModel();
if (model != null) {
model.removeListDataListener(listDataListener);
}
ListSelectionModel selectionModel = list.getSelectionModel();
if (selectionModel != null) {
selectionModel.removeListSelectionListener(listSelectionListener);
}
focusListener = null;
mouseInputListener = null;
listSelectionListener = null;
listDataListener = null;
propertyChangeListener = null;
handler = null;
|
public void | uninstallUI(javax.swing.JComponent c)Uninitializes this.list by calling uninstallListeners() ,
uninstallKeyboardActions() , and uninstallDefaults()
in order. Sets this.list to null.
uninstallListeners();
uninstallDefaults();
uninstallKeyboardActions();
cellWidth = cellHeight = -1;
cellHeights = null;
listWidth = listHeight = -1;
list.remove(rendererPane);
rendererPane = null;
list = null;
|
private void | updateHorizontalLayoutState(int fixedCellWidth, int fixedCellHeight)Invoked when the list is layed out horizontally to determine how
many columns to create.
This updates the rowsPerColumn, columnCount ,
preferredHeight and potentially cellHeight
instance variables.
int visRows = list.getVisibleRowCount();
int dataModelSize = list.getModel().getSize();
Insets insets = list.getInsets();
listHeight = list.getHeight();
listWidth = list.getWidth();
if (dataModelSize == 0) {
rowsPerColumn = columnCount = 0;
preferredHeight = insets.top + insets.bottom;
return;
}
int height;
if (fixedCellHeight != -1) {
height = fixedCellHeight;
}
else {
// Determine the max of the renderer heights.
int maxHeight = 0;
if (cellHeights.length > 0) {
maxHeight = cellHeights[cellHeights.length - 1];
for (int counter = cellHeights.length - 2;
counter >= 0; counter--) {
maxHeight = Math.max(maxHeight, cellHeights[counter]);
}
}
height = cellHeight = maxHeight;
cellHeights = null;
}
// The number of rows is either determined by the visible row
// count, or by the height of the list.
rowsPerColumn = dataModelSize;
if (visRows > 0) {
rowsPerColumn = visRows;
columnCount = Math.max(1, dataModelSize / rowsPerColumn);
if (dataModelSize > 0 && dataModelSize > rowsPerColumn &&
dataModelSize % rowsPerColumn != 0) {
columnCount++;
}
if (layoutOrientation == JList.HORIZONTAL_WRAP) {
// Because HORIZONTAL_WRAP flows differently, the
// rowsPerColumn needs to be adjusted.
rowsPerColumn = (dataModelSize / columnCount);
if (dataModelSize % columnCount > 0) {
rowsPerColumn++;
}
}
}
else if (layoutOrientation == JList.VERTICAL_WRAP && height != 0) {
rowsPerColumn = Math.max(1, (listHeight - insets.top -
insets.bottom) / height);
columnCount = Math.max(1, dataModelSize / rowsPerColumn);
if (dataModelSize > 0 && dataModelSize > rowsPerColumn &&
dataModelSize % rowsPerColumn != 0) {
columnCount++;
}
}
else if (layoutOrientation == JList.HORIZONTAL_WRAP && cellWidth > 0 &&
listWidth > 0) {
columnCount = Math.max(1, (listWidth - insets.left -
insets.right) / cellWidth);
rowsPerColumn = dataModelSize / columnCount;
if (dataModelSize % columnCount > 0) {
rowsPerColumn++;
}
}
preferredHeight = rowsPerColumn * cellHeight + insets.top +
insets.bottom;
|
private void | updateIsFileList()
boolean b = Boolean.TRUE.equals(list.getClientProperty("List.isFileList"));
if (b != isFileList) {
isFileList = b;
Font oldFont = list.getFont();
if (oldFont == null || oldFont instanceof UIResource) {
Font newFont = UIManager.getFont(b ? "FileChooser.listFont" : "List.font");
if (newFont != null && newFont != oldFont) {
list.setFont(newFont);
}
}
}
|
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.
/* If both JList fixedCellWidth and fixedCellHeight have been
* set, then initialize cellWidth and cellHeight, and set
* cellHeights to null.
*/
int fixedCellHeight = list.getFixedCellHeight();
int fixedCellWidth = list.getFixedCellWidth();
cellWidth = (fixedCellWidth != -1) ? fixedCellWidth : -1;
if (fixedCellHeight != -1) {
cellHeight = fixedCellHeight;
cellHeights = null;
}
else {
cellHeight = -1;
cellHeights = new int[list.getModel().getSize()];
}
/* If either of JList fixedCellWidth and fixedCellHeight haven't
* been set, then initialize cellWidth and cellHeights by
* scanning through the entire model. Note: if the renderer is
* null, we just set cellWidth and cellHeights[*] to zero,
* if they're not set already.
*/
if ((fixedCellWidth == -1) || (fixedCellHeight == -1)) {
ListModel dataModel = list.getModel();
int dataModelSize = dataModel.getSize();
ListCellRenderer renderer = list.getCellRenderer();
if (renderer != null) {
for(int index = 0; index < dataModelSize; index++) {
Object value = dataModel.getElementAt(index);
Component c = renderer.getListCellRendererComponent(list, value, index, false, false);
rendererPane.add(c);
Dimension cellSize = c.getPreferredSize();
if (fixedCellWidth == -1) {
cellWidth = Math.max(cellSize.width, cellWidth);
}
if (fixedCellHeight == -1) {
cellHeights[index] = cellSize.height;
}
}
}
else {
if (cellWidth == -1) {
cellWidth = 0;
}
if (cellHeights == null) {
cellHeights = new int[dataModelSize];
}
for(int index = 0; index < dataModelSize; index++) {
cellHeights[index] = 0;
}
}
}
columnCount = 1;
if (layoutOrientation != JList.VERTICAL) {
updateHorizontalLayoutState(fixedCellWidth, fixedCellHeight);
}
|