Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Arrow Routing (Read 2013 times)
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Arrow Routing
Jul 30th, 2007 at 4:50am
Print Post  
Hi,

I have the following code:


private void TestArrows() {

flowChart = new FlowChart();
this.getContentPane().add(flowChart);
flowChart.setMeasureUnit(GraphicsUnit.Pixel);
flowChart.setRouteArrows(false);

Box top = new Box(flowChart);
Box below1 = new Box(flowChart);
Box below2 = new Box(flowChart);
top.setObstacle(false);
below1.setObstacle(false);
below2.setObstacle(false);

below1.attachTo(top, AttachToNode.TopLeft);
below2.attachTo(top, AttachToNode.TopLeft);

top.setBounds(new Rectangle2D.Float(100, 100, 100, 100));
below1.setBounds(new Rectangle2D.Float(150, 250, 100, 100));
below2.setBounds(new Rectangle2D.Float(350, 250, 100, 100));
flowChart.add(top);
flowChart.add(below1);
flowChart.add(below2);

Arrow top1 = new Arrow(flowChart, top, below1);
Arrow top2 = new Arrow(flowChart, top, below2);
flowChart.add(top1);
flowChart.add(top2);

UpdateConnector(top, below1);
UpdateConnector(top, below2);
}

private void UpdateConnector(Box group, Box subordinate) {

// There will be only one connector
Arrow connector = subordinate.getIncomingArrows().get(0);
connector.getControlPoints().clear();

float midY = (subordinate.getBounds().y + group.getBounds().y + group.getBounds().height) / 2;

connector.getControlPoints().add(new Point2D.Float(group.getBounds().x + group.getBounds().width / 2, group.getBounds().y + group.getBounds().height));
connector.getControlPoints().add(new Point2D.Float(group.getBounds().x + group.getBounds().width / 2, midY));
connector.getControlPoints().add(new Point2D.Float(subordinate.getBounds().x + subordinate.getBounds().width / 2, midY));
connector.getControlPoints().add(new Point2D.Float(subordinate.getBounds().x + subordinate.getBounds().width / 2, subordinate.getBounds().y));

connector.setStyle(ArrowStyle.Cascading);

connector.updateFromPoints();
}

1. I have given the arrow a cascading feel and assigned 4 control points per arrow.

So, both arrows should appear with two bends, but when rendered, they come up with only 3 control points.

2. I can add the line flowChart.setArrowStyle(ArrowStyle.Cascading);
This will make the arrows come up with two bends. But on moving the top box, the second arrow loses its shape. How do I prevent this?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Arrow Routing
Reply #1 - Jul 30th, 2007 at 6:03am
Print Post  
Hi,

1. Instead of clearing the control points collection and adding new points,  call setSegments(3) and then use the PointCollection.set() method to set the point coordinates.

2. If an arrow's segment does not keep strictly horizontal or vertical direction, probably you should call the Arrow.setCascadeOrientation() method to specify what direction you will be using, before calling setStyle().

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