Skip to main content



      Home
Home » Eclipse Projects » GEF » [Zest] How to add Listener For GraphNode/GraphConnection?
[Zest] How to add Listener For GraphNode/GraphConnection? [message #249209] Fri, 05 June 2009 01:34 Go to next message
Eclipse UserFriend
Hello,

I try to add listener for GraphNode/GraphConnection but it doens't work.

I.e. I want to print something when user double clicks one of the
GraphNodes and GraphConnections:

public class TestListener {

public static void main(String[] args) {
Display d = new Display();
Shell shell = new Shell(d);
shell.setLayout(new FillLayout());
shell.setSize(400, 400);

Graph g = new Graph(shell, SWT.NONE);

GraphNode n = new GraphNode(g, SWT.NONE, "Paper");
GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock");
GraphNode n3 = new GraphNode(g, SWT.NONE, "Scissors");

GraphConnection c1 = new GraphConnection(g, SWT.NONE, n, n2);
GraphConnection c2 = new GraphConnection(g, SWT.NONE, n2, n3);
GraphConnection c3 = new GraphConnection(g, SWT.NONE, n3, n);

n.addListener(SWT.MouseDoubleClick, new Listener() {
public void handleEvent(Event event) {
System.out.println("hello!");
}
});

c1.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event event) {
System.out.println("hi!");
}
});

g.setLayoutAlgorithm(new SpringLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);

shell.open();
while (!shell.isDisposed()) {
while (!d.readAndDispatch()) {
d.sleep();
}
}
}
}

Why GraphNode.addListener() doesn't work?

Thanks in advance.
Re: [Zest] How to add Listener For GraphNode/GraphConnection? [message #633785 is a reply to message #249209] Tue, 19 October 2010 09:02 Go to previous messageGo to next message
Eclipse UserFriend
*Sigh*
Well, in the face of my continued failure to solve this problem, I'm giving up on the graph-based interaction, and creating a dropdown menu for selecting nodes instead.
Re: [Zest] How to add Listener For GraphNode/GraphConnection? [message #633789 is a reply to message #249209] Tue, 19 October 2010 09:06 Go to previous messageGo to next message
Eclipse UserFriend
Whoops. My apologies, wrong thread (though similar problem). Confused it with my own.
Re: [Zest] How to add Listener For GraphNode/GraphConnection? [message #642316 is a reply to message #249209] Tue, 30 November 2010 14:00 Go to previous message
Eclipse UserFriend
You have to add the listener to the graph and get the selected figure from either graph.getFigureAt(x, y) and the coords of the event or graph.getSelection(), same with all other events.

Johan
Previous Topic:[Zest] All the nodes are in the upper left corner - please help
Next Topic:[Zest] Display SWT controls inside graph nodes
Goto Forum:
  


Current Time: Wed Apr 30 04:35:10 EDT 2025

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

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

Back to the top