Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Connected arrow routing (Read 3741 times)
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Connected arrow routing
Jul 13th, 2008 at 6:22am
Print Post  
Hi,

Another problem I noticed:

[code]

@Override
public void init() {
super.init();
flowChart = new Diagram();
flowchartView = new DiagramView(flowChart);
flowChart.setSelectionOnTop(false);
flowChart.setShadowsStyle(ShadowsStyle.None);
this.getContentPane().add(flowchartView);
flowChart.setMeasureUnit(GraphicsUnit.Pixel);

flowChart.setAllowUnconnectedLinks(true);
flowChart.setLinkStyle(LinkStyle.Cascading);
flowChart.setSnapToAnchor(SnapToAnchor.OnCreateOrModify);
flowChart.setRouteLinks(true);
flowChart.getRoutingOptions().setTriggerRerouting(
RerouteLinks.WhileCreating);
flowChart.setLinksSnapToBorders(true);

testArrowSnap();
}

private void testArrowSnap() {
one = new ShapeNode(flowChart);
one.setBounds(100, 100, 200, 200);
flowChart.add(one);

two = new ShapeNode(flowChart);
two.setBounds(500, 100, 200, 200);
flowChart.add(two);

DiagramLink arrow = new DiagramLink(flowChart, one, two);
arrow.setStyle(LinkStyle.Polyline);
arrow.setAutoRoute(false);
arrow.setSegmentCount(1);
arrow.getControlPoints().set(0, new Point2D.Float(300, 110));
arrow.getControlPoints().set(1, new Point2D.Float(500, 110));
arrow.setSnapToNodeBorder(true);
flowChart.add(arrow);
}

[/code]

Above I have two DiagramNodes and one DiagramLink connecting them. I have mentioned only one segment, but you will see that the DiagramLink has two segments.

Also when you move the first DiagramNode, the origin of the DiagramLink jumps to the center of the first box. The destination of the DiagramLink is now positioned at the right place (where it was placed during its creation)

If you move the second box only, the origin is at the right place, but the destination is now at the center of the second box.

Some way I can get around this problem too?

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Connected arrow routing
Reply #1 - Jul 15th, 2008 at 11:47am
Print Post  
A call to DiagramLink.updateFromPoints() should fix that too. This is needed in order to update the relative positions that the link keeps for its ends (in relation to the connected nodes) from the absolute coordinates you assign.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: Connected arrow routing
Reply #2 - Jul 15th, 2008 at 4:47pm
Print Post  
Hi Stoyan,

Thanks, I see that work alright.

I also have this sort of a code, where on modifying a node, I change its arrows to turn orthogonal.

[code]

flowChart.addDiagramListener(new DiagramAdapter() {
@Override
public void nodeModified(NodeEvent e) {
arrow.setStyle(LinkStyle.Cascading);
}
});

[/code]

Again, the arrow moves to the centers of the two symbols.

Something I can do to fix this?

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Connected arrow routing
Reply #3 - Jul 16th, 2008 at 9:52am
Print Post  
Hi,

It didn't move to the center in my test. Is there anything else done in your nodeModified handler?

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: Connected arrow routing
Reply #4 - Jul 17th, 2008 at 2:24am
Print Post  
Hi Stoyan,

Here is the whole code:

[code]

private Diagram flowChart;

DiagramView flowchartView;

@Override
public void init() {
super.init();
flowChart = new Diagram();
flowchartView = new DiagramView(flowChart);
flowChart.setSelectionOnTop(false);
flowChart.setShadowsStyle(ShadowsStyle.None);
this.getContentPane().add(flowchartView);
flowChart.setMeasureUnit(GraphicsUnit.Pixel);

flowChart.setAllowUnconnectedLinks(true);
flowChart.setLinkStyle(LinkStyle.Cascading);
flowChart.setSnapToAnchor(SnapToAnchor.OnCreateOrModify);
flowChart.setRouteLinks(true);
flowChart.getRoutingOptions().setTriggerRerouting(
RerouteLinks.WhileCreating);
flowChart.setLinksSnapToBorders(true);

testArrowSnap();
// testArrowDistortion();
}

private void testArrowSnap() {
one = new ShapeNode(flowChart);
one.setBounds(100, 100, 200, 200);
flowChart.add(one);

two = new ShapeNode(flowChart);
two.setBounds(500, 100, 200, 200);
flowChart.add(two);

arrow = new DiagramLink(flowChart, one, two);
arrow.setStyle(LinkStyle.Polyline);
arrow.setAutoRoute(false);
arrow.setSegmentCount(1);
arrow.getControlPoints().set(0, new Point2D.Float(300, 110));
arrow.getControlPoints().set(1, new Point2D.Float(500, 110));
arrow.setSnapToNodeBorder(true);
arrow.updateFromPoints();
flowChart.add(arrow);

flowChart.addDiagramListener(new DiagramAdapter() {
@Override
public void nodeModified(NodeEvent e) {
arrow.setStyle(LinkStyle.Cascading);
}
});
}

DiagramNode one, two;
DiagramLink arrow;

[/code]

The arrows are initially connected to the right side of the first box and the left side of the second close to the top of the two boxes.

When I move either of the boxes, the arrow orgin shifts to the center of the right side of the first box and to the center of the bottom of the second box.

---             ----
   |            |
   |            |
   |-----      |
   |            |
   |            |
---             -----------------
                         |
                         |


Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Connected arrow routing
Reply #5 - Jul 17th, 2008 at 7:50am
Print Post  
We discussed this some time ago - changing the Style resets all point positions, so you will have to save the original start and end point values before setting Style, and restore them after that.

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: Connected arrow routing
Reply #6 - Jul 17th, 2008 at 8:26am
Print Post  
Hi Stoyan,

Thank you, that worked. I lost track of our last discussion, sorry.

Praveen
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint