Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Infinite Loop using ShortestPathConnectionRouter
Infinite Loop using ShortestPathConnectionRouter [message #178903] Sat, 23 April 2005 19:15
Jim Adams is currently offline Jim AdamsFriend
Messages: 160
Registered: July 2009
Senior Member
I too one of the simple GEF examples that shows 2 nodes and a connection
and added another node and a connection. All well and good. I can drag the
nodes around and life is good. When I tried to add a
ShortestPathConnectionRouter the code goes into an infinite loop when
first displaying.

The original code as a stand-alone SWT program. I changed it to a View

Here's my CreatePartControl and Dragger class. Any ideas what I am doing
wrong to cause the infinite loop?

public void createPartControl(Composite parent) {
c = new Canvas(parent, SWT.NONE);
LightweightSystem lws = new LightweightSystem(c);

IFigure panel = new Figure();
lws.setContents(panel);
RectangleFigure node1 = new RectangleFigure();
RectangleFigure node2 = new RectangleFigure();
RectangleFigure node3 = new RectangleFigure();

node1.setBackgroundColor(ColorConstants.red);
node1.setSize(100, 100);
node1.setLocation(new Point(150,10));

node2.setBackgroundColor(ColorConstants.blue);
node2.setSize(100, 100);
node2.setLocation(new Point(300, 300));

node3.setBackgroundColor(ColorConstants.green);
node3.setSize(100, 100);
node3.setLocation(new Point(10, 300));

PolylineConnection conn = new PolylineConnection();
conn.setSourceAnchor(new ChopboxAnchor(node1));
conn.setTargetAnchor(new ChopboxAnchor(node2));
conn.setTargetDecoration(new PolygonDecoration());

ShortestPathConnectionRouter router = new
ShortestPathConnectionRouter(panel);

PolylineConnection conn1 = new PolylineConnection();
conn1.setSourceAnchor(new ChopboxAnchor(node1));
conn1.setTargetAnchor(new ChopboxAnchor(node3));
conn1.setTargetDecoration(new PolygonDecoration());

Label label = new Label("Midpoint");
label.setOpaque(true);
label.setBackgroundColor(ColorConstants.buttonLightest);
label.setBorder(new LineBorder());
conn.add(label, new MidpointLocator(conn, 0));

panel.add(node1);
panel.add(node2);
panel.add(node3);
panel.add(conn);
panel.add(conn1);
new Dragger(node1);
new Dragger(node2);
new Dragger(node3);
panel.addLayoutListener(router.getLayoutListener());
conn.setConnectionRouter(router);
conn1.setConnectionRouter(router);

}

private void showMessage(String message) {
MessageDialog.openInformation(c.getShell(), "Sample View", message);
}

/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
c.setFocus();
}

static class Dragger extends MouseMotionListener.Stub implements
MouseListener {
public Dragger(IFigure figure) {
figure.addMouseMotionListener(this);
figure.addMouseListener(this);
}

Point last;

public void mouseReleased(MouseEvent e) {
}

public void mouseClicked(MouseEvent e) {
}

public void mouseDoubleClicked(MouseEvent e) {
}

public void mousePressed(MouseEvent e) {
last = e.getLocation();
}

public void mouseDragged(MouseEvent e) {
Point p = e.getLocation();
if ((p != null) && (last != null)) {
Dimension delta = p.getDifference(last);
last = p;
Figure f = ((Figure) e.getSource());
f.setBounds(f.getBounds().getTranslated(delta.width,
delta.height));
}
}
};
Previous Topic:Header for a GEF editor
Next Topic:endless loop when moving figure outside of display area
Goto Forum:
  


Current Time: Fri Apr 26 16:19:36 GMT 2024

Powered by FUDForum. Page generated in 0.02886 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top