Horizontal align in JGoLayeredDigraphLayo

Hi,

Is it possible to influence the horizontal aligment of nodes in a column when using this AutoLayout?

I have an example with basic nodes having a label on the right. Because
the length of the labels varies, the centers of the nodes are not
aligned and the links are not straight. I assume this is because the
center of the complete area is used for positioning the node.

I tried to influence it by setting the JGoObject.Center spot location
of the basic node to that of its port, which sits in the center of the
node, but that failed.

Regards,

Werner.

Actually, the node’s bounding rectangle includes all of its parts. So the center of the node won’t be in the center of your JGoBasicNode’s Drawable shape.
You can make the positioning of the nodes smarter by using a custom JGoNetworkNode that overrides commitPosition:
public class CustomNetwork extends JGoNetwork {
public CustomNetwork(JGoObjectSimpleCollection collection) { super(collection); }
public JGoNetworkNode createNetworkNode() { return new CustomNetworkNode(); }
}
public class CustomNetworkNode extends JGoNetworkNode {
public void commitPosition() {
JGoObject obj = getJGoObject();
if (obj instanceof JGoBasicNode) {
JGoBasicNode bn = (JGoBasicNode)obj;
bn.getDrawable().setSpotLocation(JGoObject.Center, getCenter());
} else {
super.commitPosition();
}
}
}
// usage:
JGoDocument doc = …
JGoLayeredDigraphAutoLayout layout = new JGoLayeredDigraphAutoLayout(doc, new CustomNetwork(doc));
… set any properties
layout.performLayout();

Thank you very much Walter. It works perfectly.

Regards,

Werner.