// No-op
}
@Override
public void paint(Graphics2D graphics) {
TreeView treeView = (TreeView)getComponent();
TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer();
int width = getWidth();
int height = getHeight();
int nodeHeight = getNodeHeight();
// Paint the background
graphics.setPaint(backgroundColor);
graphics.fillRect(0, 0, width, height);
// nodeStart and nodeEnd are both inclusive
int nodeStart = 0;
int nodeEnd = visibleNodes.getLength() - 1;
// Ensure that we only paint items that are visible
Rectangle clipBounds = graphics.getClipBounds();
if (clipBounds != null) {
nodeStart = Math.max(nodeStart, (int)(clipBounds.y
/ (double)(nodeHeight + VERTICAL_SPACING)));
nodeEnd = Math.min(nodeEnd, (int)((clipBounds.y +
clipBounds.height) / (double)(nodeHeight + VERTICAL_SPACING)));
}
int nodeY = nodeStart * (nodeHeight + VERTICAL_SPACING);
for (int i = nodeStart; i <= nodeEnd; i++) {
NodeInfo nodeInfo = visibleNodes.get(i);
boolean expanded = false;
boolean highlighted = nodeInfo.isHighlighted();
boolean selected = nodeInfo.isSelected();
boolean disabled = nodeInfo.isDisabled();
int nodeX = (nodeInfo.depth - 1) * (indent + spacing);
if (treeView.isEnabled()) {
if (selected) {
// Paint the selection state
Color selectionBackgroundColor = treeView.isFocused() ?
this.selectionBackgroundColor : inactiveSelectionBackgroundColor;
graphics.setPaint(selectionBackgroundColor);
graphics.fillRect(0, nodeY, width, nodeHeight);
} else if (highlighted && !disabled) {
// Paint the highlight state
graphics.setPaint(highlightBackgroundColor);
graphics.fillRect(0, nodeY, width, nodeHeight);
}
}
// Paint the expand/collapse control
if (showBranchControls) {
if (nodeInfo instanceof BranchInfo) {
BranchInfo branchInfo = (BranchInfo)nodeInfo;
expanded = branchInfo.isExpanded();
Color branchControlColor;
if (treeView.isEnabled()
&& !disabled) {
if (selected) {
if (treeView.isFocused()) {
branchControlColor = branchControlSelectionColor;
} else {
branchControlColor = branchControlInactiveSelectionColor;
}
} else {
branchControlColor = this.branchControlColor;
}
} else {
branchControlColor = branchControlDisabledColor;
}
GeneralPath shape = new GeneralPath();
int imageX = nodeX + (indent - BRANCH_CONTROL_IMAGE_WIDTH) / 2;
int imageY = nodeY + (nodeHeight - BRANCH_CONTROL_IMAGE_HEIGHT) / 2;
if (expanded) {
shape.moveTo(imageX, imageY + 1);
shape.lineTo(imageX + 8, imageY + 1);
shape.lineTo(imageX + 4, imageY + 7);
} else {
shape.moveTo(imageX + 1, imageY);
shape.lineTo(imageX + 7, imageY + 4);
shape.lineTo(imageX + 1, imageY + 8);
}
shape.closePath();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setPaint(branchControlColor);
graphics.fill(shape);
}
nodeX += indent + spacing;
}
// Paint the checkbox
TreeView.NodeCheckState checkState = TreeView.NodeCheckState.UNCHECKED;
if (treeView.getCheckmarksEnabled()) {
checkState = nodeInfo.getCheckState();
int checkboxWidth = CHECKBOX.getWidth();
int checkboxHeight = CHECKBOX.getHeight();