Adding shapes to JGoIconicNode


#1

I am trying to add shapes (rectangle and polygon) to JGoIconincNode. I have overwritten the paint method to draw the shapes required. However, I have problems positioning the icon and the text on the background shapes. I have been trying to position the image using the setLocationOffset relative to the node’s bounding rectangle, but with no success. Regardless of what I do, it seems the icons is positioned on the top left corner of the bounding rectangle. Any suggestion how I can do this?
Thanks, NE


#2

Don’t do anything relative to the node’s (area’s) bounding rectangle.
The reason is that the area’s bounding rectangle is constantly changing as you move or resize any of the children.
Instead, pick a child and positioning everything else relative to that child. JGoIconicNode.layoutChildren normally does so relative to the Icon.


#3

Thanks. I modified the layoutChildren method and I see the behavior I am looking for :)
I have one more question I was hoping you could help me with. I have overwritten the paint method to draw a background for the JGoIconicNode. The background is slightly bigger than the bounding rectangle. So based on the user guide, I also overwrote the expandRectByPenWidth to account for it. When I select a particular node, the selection rectangle is not as big as the background. It seems to be same as the original bounding rectangle. The following is what I do in the expandRectByPenWidth. I was hoping that by the time the paint method is called, the width of the bounding rectangle has been increased by 10. Is my assumption wrong? Do you have a suggestion?
public void expandRectByPenWidth(Rectangle rect) {
rect.setSize(rect.width+10, rect.height);
super.expandRectByPenWidth(rect);
}


#4

The expandRectByPenWidth method is just supposed to reflect how the paint method might paint beyond the bounding rectangle. Assuming you only drew some stuff just to the right of the bounding rectangle, your override looks OK.
If you really want to change the bounding rectangle, override computeBoundingRect instead. Call the super method and then add 10 to the resulting width.