JGoSubGraph label

Hi,

I have a simple extension of JGoSubGraph and I add nodes to it. My particular problem occurs when I add a node that is ‘small’ in comparison to the size of the label for the JGoSubGraph. What happens is that the label covers part of the small yellow expand/contract widget in the top left of the sub graph.
e.g If my label text is “A Big Subgraph Title” then I add an icon node of, say, 16x16 pixels then the first few characters of the label text appear over the expand widget.

So what is the best way to alter the location of the subgraph’s label? (I still want the label in the top center but x-shifted so as to not obscure the expand widget)
I tried calling getLabel and then modifying the location but this seems not to work.

Thanks

Mike

I assume you don’t have a JGoSubGraph.getCollapsedObject(), and don’t want one.

You'll need to override layoutLabel to position the Label where you want. Perhaps something like:
[code] protected void layoutLabel() {
if (!isExpanded() && getHandle() != null && getLabel() != null) {
getLabel().setSpotLocation(TopLeft, getHandle(), TopRight);
return;
}
super.layoutLabel();
}[/code]

Walter, I have similar question

I would like to arrange the handle at BottomCenter of subgraph and expand/collapse it with regard to its center.
I overridden layoutHandle() and computeReferencePoint();

protected Point computeReferencePoint() {

Point hpos = new Point();

Rectangle r = getBoundingRect();

hpos.x= r.x + r.width/2;

hpos.y= r.y + r.height/2;

if (getCollapsedObject() != null) {

hpos.x-= getCollapsedObject().getWidth()/2;

hpos.y-= getCollapsedObject().getHeight()/2;

}

return hpos; }

protected void layoutHandle() {

JGoSubGraphHandle h = getHandle();

if (h != null) {

if (!isExpanded()) {

Rectangle r = getCollapsedObject().getBoundingRect();

h.setTopLeft(r.x + (r.width - h.getWidth()) / 2, r.y + r.height

- h.getHeight());

} else {

Rectangle r = computeBorder();

h.setTopLeft(r.x + (r.width - h.getWidth()) / 2, r.y + r.height

- h.getHeight());

}

}
}
When collapsedLabelSpot = JGoObject.BottomCenter all works correctly.
But if to call setCollapsedLabelSpot(JGoObject.Right) or .Left in collapsed state, subgraph will jump down.
What's wrong?
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]
Thank you. I tried it.
[QUOTE=walter]
it's off by half the width&height of the CollapsedObject at some step of the process.[/quote]
Yes. If to add child node/s and then collapse/expand many times, subgraph moves to bottom right corner .
it will be fine to repare it.