// 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
if (backgroundColor != null) {
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);
VisibleNodeIterator visibleNodeIterator = new VisibleNodeIterator(nodeStart, nodeEnd);
while (visibleNodeIterator.hasNext()) {
NodeInfo nodeInfo = visibleNodeIterator.next();
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;
boolean showBranchControl = true;
if (!showEmptyBranchControls) {
branchInfo.loadChildren();
showBranchControl = !branchInfo.children.isEmpty();
}
if (showBranchControl) {
expanded = branchInfo.isExpanded();
Color branchControlColor;
if (selected) {
if (treeView.isFocused()) {
branchControlColor = branchControlSelectionColor;
} else {
branchControlColor = branchControlInactiveSelectionColor;
}
} else {
branchControlColor = this.branchControlColor;
}
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();
Graphics2D branchControlGraphics = (Graphics2D)graphics.create();
branchControlGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if (!treeView.isEnabled()
|| disabled) {
branchControlGraphics.setComposite
(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
}
branchControlGraphics.setPaint(branchControlColor);
branchControlGraphics.fill(shape);
branchControlGraphics.dispose();
}
}
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();
int checkboxX = Math.max(indent - checkboxWidth, 0) / 2;
int checkboxY = (nodeHeight - checkboxHeight) / 2;
Graphics2D checkboxGraphics = (Graphics2D)graphics.create(nodeX + checkboxX,
nodeY + checkboxY, checkboxWidth, checkboxHeight);
Button.State state;
switch (checkState) {
case CHECKED:
state = Button.State.SELECTED;
break;
case MIXED:
state = Button.State.MIXED;
break;
default:
state = Button.State.UNSELECTED;
break;
}
CHECKBOX.setState(state);
CHECKBOX.setEnabled(treeView.isEnabled() && !disabled
&& !nodeInfo.isCheckmarkDisabled());
CHECKBOX.paint(checkboxGraphics);
checkboxGraphics.dispose();
nodeX += Math.max(indent, checkboxWidth) + spacing;