Your layoutHandle method looks fine. But I think one problem with your computeReferencePoint is that the CollapsedObject is moved around, particularly by layoutCollapsedObject. One way around this problem is to always position the CollapsedObject at the center of the desired area, even when the subgraph is expanded and the CollapsedObject is not visible. That way the center of the CollapsedObject can be reliably used when expanded and when collapsed.
Also I think you need to override computeCollapsedRectangle, to center all of the invisible collapsed children.
The following code almost works right -- it's off by half the width&height of the CollapsedObject at some step of the process. Sorry, I don't have time right now to investigate further.
[code] protected Point computeReferencePoint() {
JGoObject co = getCollapsedObject();
if (co == null) co = this;
return co.getSpotLocation(Center);
}
protected Rectangle computeCollapsedRectangle(Dimension s) {
Point hpos = computeReferencePoint();
return new Rectangle(hpos.x - s.width/2, hpos.y - s.height/2, s.width, s.height);
}
protected void layoutCollapsedObject() {
JGoObject co = getCollapsedObject();
if (co != null) {
Rectangle r;
if (isExpanded()) {
// find bounds of meaningful children, excluding CollapsedObject and ignoring Margin
r = computeInsideMargins(co);
} else {
Dimension maxsize = computeCollapsedSize(true);
r = computeCollapsedRectangle(maxsize);
}
boolean oldInit = isInitializing();
setInitializing(true);
co.setSpotLocation(Center, r.x+r.width/2, r.y+r.height/2);
setInitializing(oldInit);
}
}
protected void layoutHandle() {
JGoSubGraphHandle h = getHandle();
if (h != null) {
Rectangle r;
if (isExpanded()) {
r = computeBorder();
} else {
r = getCollapsedObject().getBoundingRect();
}
h.setTopLeft(r.x + (r.width - h.getWidth()) / 2, r.y + r.height - h.getHeight());
}
}[/code]