public void paintLegendItem(final JGraphPane graphPane, JPowerGraphGraphics g, LegendItem legendItem, Legend theLegend, JPowerGraphPoint thePoint, JPowerGraphRectangle theLegendRectangle) {
if (legendItem instanceof NodeLegendItem){
final NodeLegendItem nodeLegendItem = (NodeLegendItem) legendItem;
JPowerGraphDimension d = nodeLegendItem.getNodePainter().getLegendItemSize(graphPane, nodeLegendItem.getDescription());
nodeLegendItem.getNodePainter().paintLegendItem(g, thePoint, nodeLegendItem.getDescription());
if (graphPane.getGraph().getNodeFilter() != null && theLegend.isInteractive()){
int buttonX = theLegendRectangle.x + (theLegendRectangle.width - (buttonWidth + widthPadding));
int buttonY = thePoint.y - heightpadding;
int buttonHeight = d.getHeight() - 5;
boolean canFilterNode = graphPane.getGraph().getNodeFilter().canChangeFilterState(nodeLegendItem.getNodeClass());
boolean isChecked = graphPane.getGraph().getNodeFilter().getFilterState(nodeLegendItem.getNodeClass());
JPowerGraphRectangle r = new JPowerGraphRectangle(buttonX, buttonY, buttonWidth, buttonHeight);
if (canFilterNode){
g.setForeground(enabledButtonColor);
theLegend.addActionRectangle(r, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
graphPane.getGraph().getNodeFilter().setFilterState(nodeLegendItem.getNodeClass(), !graphPane.getGraph().getNodeFilter().getFilterState(nodeLegendItem.getNodeClass()));
}
});
}
else{
g.setForeground(disabledButtonColor);
}
g.drawRectangle(r.x, r.y, r.width, r.height);
if (isChecked){
g.drawLine(r.x + 3, r.y + 3, r.x + r.width - 3, r.y + r.height - 3);
g.drawLine(r.x + 3, r.y + r.height - 3, r.x + r.width - 3, r.y + 3);
}
}
}
else if (legendItem instanceof GroupLegendItem){
final GroupLegendItem groupLegendItem = (GroupLegendItem) legendItem;
if (groupLegendItem.getLegendItems().size() > 0){
JPowerGraphRectangle r = new JPowerGraphRectangle(thePoint.x + 5, thePoint.y, toggleWidth - 10, toggleHeight);
theLegend.addActionRectangle(r, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
groupLegendItem.setExpanded(!groupLegendItem.isExpanded());
graphPane.redraw();
}
});
g.setForeground(enabledButtonColor);
g.drawLine(r.x, r.y + r.height/2, r.x + r.width, r.y + r.height/2);
g.drawString(groupLegendItem.getDescription(), r.x + r.width + 5, r.y - 2, 1);
if (groupLegendItem.isExpanded()){
JPowerGraphPoint subPoint = new JPowerGraphPoint(thePoint.x + indent, thePoint.y + Math.max(toggleHeight, g.getAscent() + g.getDescent() + 4));
for (LegendItem subLegendItem : groupLegendItem.getLegendItems()) {
JPowerGraphDimension subDimension = new JPowerGraphDimension(0, 0);
getLegendItemSize(graphPane, subLegendItem, theLegend, subDimension);
paintLegendItem(graphPane, g, subLegendItem, theLegend, subPoint, theLegendRectangle);
subPoint.y += subDimension.height;
}
}