Alternate Tree Layout sample

A useful tweak to the Tree Layout algorithm... lays out all the children except the top level in an indented tree layout. code below. (note this code doesn't set the colors...)
public class RootOnlyTreeLayout : GoLayoutTree {
public RootOnlyTreeLayout() {
// set RootDefaults:
this.Angle = 90;
// set AlternateDefaults:
this.AlternateDefaults.Angle = 0;
this.AlternateDefaults.PortSpot = GoObject.BottomLeft;
this.AlternateDefaults.ChildPortSpot = GoObject.MiddleLeft;
this.AlternateDefaults.Alignment = GoLayoutTreeAlignment.Start;
}
// In the future, you can get the effect of this override by
// specifying GoLayoutTree.Style = GoLayoutTreeStyle.RootOnly
protected override void InitializeTreeNodeValues(GoLayoutTreeNode n) {
GoLayoutTreeNode mom;
if (n.Parent == null) mom = this.RootDefaults;
else if (n.Parent.Parent == null) mom = this.AlternateDefaults;
else mom = n.Parent;
n.CopyInheritedPropertiesFrom(mom);
n.Initialized = true; // should already be true, but make sure
}
protected override void AssignTreeNodeValues(GoLayoutTreeNode n) {
base.AssignTreeNodeValues(n);
if (n.Parent == null) return;
n.NodeIndent = n.Height + 20;
n.LayerSpacing = -n.Width + 30;
}
}