JGoLayers and Links

Hi,

I need to create a JGoDocument that has a 3 layers. The first layer contains a number of objects with ports. In the Second layer I want to create the links between the ports and in the Third layer present an alternate set of links to the first layer objects.
When running the UI I want to be able to swap between layer 2 and layer 3 and only see the base object layer and One links layer at anytime.
My current implementation works ok for drawing and dragging with one set of links however when I switch to the alternate view or back again I am losing the intergity of the drawing and links are losing their connection to the layer One objects.
Additionally Using AutoLayout with multiple layering results in the first layer being aligned and all of the links in layers two and three being left on the drawing canvas in their old positions.
Can anyone suggect a way forward to resolve the two issues?
Mark

It sounds like your additional JGoLayers may not have been properly added to the JGoDocument.

I've created a test app that looks like this:
The initial diagram is created by the following code:
JGoLayer defaultLayer = this.goView.getDocument().getFirstLayer();
layer1 = this.goView.getDocument().addLayerAfter(defaultLayer);
layer1.setVisible(false);
layer2 = this.goView.getDocument().addLayerAfter(layer1);
layer2.setVisible(false);
JGoBasicNode n1 = new JGoBasicNode("AAA");
n1.setLocation(20, 100);
this.goView.getDocument().add(n1);
JGoBasicNode n2 = new JGoBasicNode("BBB");
n2.setLocation(220, 30);
this.goView.getDocument().add(n2);
JGoBasicNode n3 = new JGoBasicNode("CCC");
n3.setLocation(220, 170);
this.goView.getDocument().add(n3);
JGoLink l1 = new JGoLink(n1.getPort(), n2.getPort());
layer1.addObjectAtTail(l1);
JGoLink l2 = new JGoLink(n1.getPort(), n3.getPort());
layer2.addObjectAtTail(l2);
The button click code is as follows:
protected void showLinksLayerButton_actionPerformed(ActionEvent e) {
// Links Layer 1 Button Clicked
layer1.setVisible(true);
layer2.setVisible(false);
}
protected void showLinksLayerButton_1_actionPerformed(ActionEvent e) {
// Links Layer 2 Button Clicked
layer1.setVisible(false);
layer2.setVisible(true);
}

Hi,

Thanks this has helped to address the first of my issues. The second part was getting AutoLayout to correctly function when Nodes are in Layer 1 and Links in Layer 2.
Performing Layout results in Layer 1 being sorted as if there are no children, the links in Layer 2 are ignored.
Mark

Hmmmm, that’s odd. I would have expected that both problems were related.

I've modified the above sample code to perform an autolayout on each button press. It works correctly for me. The modified button press code is as follows:

protected void showLinksLayerButton_actionPerformed(ActionEvent e) {
// Links Layer 1 Button Clicked
layer1.setVisible(true);
layer2.setVisible(false);
layout();
}
protected void showLinksLayerButton_1_actionPerformed(ActionEvent e) {
// Links Layer 2 Button Clicked
layer1.setVisible(false);
layer2.setVisible(true);
layout();
}

private void layout() {
JGoLayeredDigraphAutoLayout layout = new JGoLayeredDigraphAutoLayout(this.goView.getDocument());
layout.setDirectionOption(JGoLayeredDigraphAutoLayout.LD_DIRECTION_RIGHT);
layout.setLayerSpacing(10);
layout.setColumnSpacing(10);
layout.performLayout();
}

Hi,

All working and thanks for the accurate replies.
Mark

One final question,

In the implementation I am looking at, the developer has done an explicit 'deleteContents' between each button push. This has the effect of clearing out the underlying JGoDocument.
In rebuilding the UI as part of the button push event the Object and Links are created and the link lines drawn, but when dragging an object the link lines are not reponding in anyway and become detached from the moved Object. Any ideas?
Mark

Is it necessary to delete the contents of the JGoDocument on each button push? That sounds like it could be inefficient and more complicated than necessary in your code.

If it really is necessary, just make sure you recreate the nodes and links and add them back to the document just as you did originally did. If the links aren't moving when you move the node, it sounds like JGo ports may not have been recreated properly or haven't been correctly added to the new node.