Hi, I have a program where I have a box "a" attached to another "b" and an arrow connecting them. "b" can be resized programatically at different intervals. When this happens, the arrow sometimes is left dangling, not connected to "b". Even calling arrow.route() doesn't fix the problem.
If the box "a" is not attached to "b", it works fine.
Below is a code sample to highlight the problem.
[code]
private FlowChart flowChart;
@Override public void init() { super.init();
initialize(); testArrow2(); }
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); }
Box two;
private void testArrow2() { Box one = new Box(flowChart); one.setBounds(new Rectangle2D.Float(10, 10, 100, 100));
two = new Box(flowChart); two.setBounds(new Rectangle2D.Float(10, 160, 500, 100));
flowChart.add(one); flowChart.add(two);
one.attachTo(two, AttachToNode.TopRight);
flowChart.addFlowChartListener(new FlowChartAdapter() {
@Override public void itemSelected(ItemEvent e) { resizeTwo(); } });
Arrow con = new Arrow(flowChart, one, two); flowChart.add(con); }
public void resizeTwo() { two.setBounds(400, 160, 100, 100); }
[/code]
1. When the applet loads, you will see that there are two boxes, a small and a large.
2. Now click the small box - the code handles the event and resizes the bottom large box.
You will see that the arrow head is now dangling, not connected to the bottom box.
Remove the line: [code] one.attachTo(two, AttachToNode.TopRight); [/code] from the example, and run it again. You will see that the arrow is now connected properly.
Can I get around this problem somehow?
Thanks, Praveen
|