Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Arrow head disappears sometimes (Read 3091 times)
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Arrow head disappears sometimes
Jan 1st, 2008 at 8:49am
Print Post  
Hi,

There are some instances when the head of an arrow disappears.

[code]


public class Goop extends JApplet {
private static final long serialVersionUID = 1L;

@Override
public void init() {
super.init();

flowChart = new FlowChart();
initialize();
testArrow();
//resizeTest();
}

private void initialize() {
flowChart = new FlowChart();
JScrollPane pane = new JScrollPane(flowChart);
this.getContentPane().add(pane);

flowChart.setSelectionOnTop(false);

flowChart.setArrowStyle(ArrowStyle.Cascading);
flowChart.setRouteArrows(true);
flowChart.getRoutingOptions().setTriggerRerouting(
RerouteArrows.WhileCreating | RerouteArrows.WhenModified);

flowChart.setMeasureUnit(GraphicsUnit.Pixel);

TextFormat textFormat = new TextFormat(Align.Center, Align.Near);
textFormat.setWrapAtCharacter(true);
flowChart.setTextFormat(textFormat);
}

private void testArrow() {
Box one = new Box(flowChart);
one.setBounds(new Rectangle2D.Float(10, 10, 100, 100));

Box two = new Box(flowChart);
two.setBounds(new Rectangle2D.Float(10, 160, 100, 100));

flowChart.add(one);
flowChart.add(two);

Arrow con = new Arrow(flowChart, one, two);
con.setArrowHead(ArrowHead.Triangle);
con.setArrowHeadSize(15);
con.setSnapToNodeBorder(true);
flowChart.add(con);
}
}
[/code]

If you just run the above code, you will see that the arrow head is missing (which I have specified as a triangle).

If you drag the lower box to the right, the head shows up.

In this scenario, when the two boxes are connected by a straight line, the box disappeared.

But sometimes, there are other scenarios as well when this happened.

Is there a way this can be stopped?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Arrow head disappears sometimes
Reply #1 - Jan 1st, 2008 at 9:32am
Print Post  
Hi,

Ok, this happens when the last two control points of an arrow coincide. In such case the control cannot choose direction for the arrowhead, so the arrowhead shape is not drawn. We have changed this to use the direction of the next-to-last segment in that case. You can fix it in your version of the source code by adding this method:

Code
Select All
void updateArrowHead()
{
	if (!points.get(points.size() - 2).equals(points.get(points.size() - 1)))
	{
		headTemplates[arrowHead].recalcArrowHead(
			ahHead, points.get(points.size()-2), points.get(points.size()-1));
	}
	else if (points.size() > 2)
	{
		headTemplates[arrowHead].recalcArrowHead(
			ahHead, points.get(points.size() - 3), points.get(points.size() - 1));
	}
	else
	{
		ahHead.defined = false;
	}
}
 



Then find the updateArrowHeads, setArrowHead and setArrowHeadSize methods, and there replace the following line with a call to updateArrowHead():

headTemplates[arrowHead].recalcArrowHead(ahHead, points.get(points.size()-2), points.get(points.size()-1));

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


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: Arrow head disappears sometimes
Reply #2 - Jan 3rd, 2008 at 12:58am
Print Post  
Hi Stoyan,

This works, thank you.

I would also like to know if this would be required for the arrowBase calculation in updateArrowHeads method.

I appreciate your prompt replies to my posts.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Arrow head disappears sometimes
Reply #3 - Jan 3rd, 2008 at 5:51am
Print Post  
I guess this will be needed for the base arrowhead shape too. Instead of calculating the direction from point 1 to point 0 when they coincide, the control should calculate the direction defined by point 2 and point 0. We will fix this for the 1.0.3 release.

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