}
@Override
@SuppressWarnings("unchecked")
public void paint(Graphics2D graphics) {
ListView listView = (ListView)getComponent();
List<Object> listData = (List<Object>)listView.getListData();
ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
int width = getWidth();
int height = getHeight();
// Paint the background
if (backgroundColor != null) {
graphics.setPaint(backgroundColor);
graphics.fillRect(0, 0, width, height);
}
// Paint the list contents
int itemStart = 0;
int itemEnd = listData.getLength() - 1;
// Ensure that we only paint items that are visible
Rectangle clipBounds = graphics.getClipBounds();
if (clipBounds != null) {
if (variableItemHeight) {
itemStart = getItemAt(clipBounds.y);
itemEnd = getItemAt(clipBounds.y + clipBounds.height - 1);
} else {
itemStart = Math.max(itemStart, (int)Math.floor(clipBounds.y
/ (double)fixedItemHeight));
itemEnd = Math.min(itemEnd, (int)Math.ceil((clipBounds.y
+ clipBounds.height) / (double)fixedItemHeight) - 1);
}
}
int itemY;
if (variableItemHeight) {
itemY = itemHeights.get(itemStart);
} else {
itemY = itemStart * fixedItemHeight;
}
for (int itemIndex = itemStart; itemIndex <= itemEnd; itemIndex++) {
Object item = listData.get(itemIndex);
boolean highlighted = (itemIndex == highlightedIndex
&& listView.getSelectMode() != ListView.SelectMode.NONE);
boolean selected = listView.isItemSelected(itemIndex);
boolean disabled = listView.isItemDisabled(itemIndex);
int itemHeight;
if (variableItemHeight) {
itemHeight = itemHeights.get(itemIndex + 1) - itemHeights.get(itemIndex);
} else {
itemHeight = fixedItemHeight;
}
Color itemBackgroundColor = null;
if (selected) {
itemBackgroundColor = (listView.isFocused())
? this.selectionBackgroundColor : inactiveSelectionBackgroundColor;
} else {
if (highlighted && showHighlight && !disabled) {
itemBackgroundColor = highlightBackgroundColor;
}
}
if (itemBackgroundColor != null) {
graphics.setPaint(itemBackgroundColor);
graphics.fillRect(0, itemY, width, itemHeight);
}
int itemX = 0;
int itemWidth = width;
boolean checked = false;
if (listView.getCheckmarksEnabled()) {
checked = listView.isItemChecked(itemIndex);
int checkboxY = (itemHeight - CHECKBOX.getHeight()) / 2;
Graphics2D checkboxGraphics = (Graphics2D)graphics.create(checkboxPadding.left,
itemY + checkboxY, CHECKBOX.getWidth(), CHECKBOX.getHeight());
CHECKBOX.setSelected(checked);
CHECKBOX.setEnabled(!disabled && !listView.isCheckmarkDisabled(itemIndex));
CHECKBOX.paint(checkboxGraphics);
checkboxGraphics.dispose();
itemX = CHECKBOX.getWidth() + (checkboxPadding.left
+ checkboxPadding.right);