Node with 4 ports and text not in shape


#1

Hi,
I’d like to have a node with four ports (one on every side of the shape) and a text on the outside of the shape. So,GoTextNode is probably the right Node to work with, but I have a couple of questions.
Is LayoutChildren the best place to move the label to the right position ? (Id like to have it bottom left outside of the shape)?
Do I need to change the selectionObject. My initial tests show that the selectionObject is the Label and the background shape and that I get a very large selectionObject. How do I do this. Override ?
Is there a sample to show how the label is moved from a Node ? If not there should be.
Thanks
/Christian


#2

Yes, you need to override LayoutChildren. Perhaps something like:
public override void LayoutChildren(GoObject childchanged) {
if (this.Initializing) return;
GoObject back = this.Background;
if (back != null) {
GoText label = this.Label;
if (label != null)
label.SetSpotLocation(TopRight, back, BottomLeft);
if (this.TopPort != null)
this.TopPort.SetSpotLocation(MiddleTop, back, MiddleTop);
if (this.RightPort != null)
this.RightPort.SetSpotLocation(MiddleRight, back, MiddleRight);
if (this.BottomPort != null)
this.BottomPort.SetSpotLocation(MiddleBottom, back, MiddleBottom);
if (this.LeftPort != null)
this.LeftPort.SetSpotLocation(MiddleLeft, back, MiddleLeft);
}
}
The SelectionObject is the GoObject that gets the selection handle(s) when the object becomes selected. For a GoTextNode, the value of GoObject.SelectionObject is just itself. But you probably want the shape to be appear selected, so you should override SelectionObject:
public override GoObject SelectionObject {
get { return this.Background; }
}


#3

Many thanks,
This was exactly what I wanted to do. Big smile
/Christian