Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [zest] Set Text For Ellipse
[zest] Set Text For Ellipse [message #249089] Mon, 01 June 2009 13:16
jeffty is currently offline jefftyFriend
Messages: 2
Registered: July 2009
Junior Member
Am a new user of zest and I want to change the shape of GraphNode to
ellipse.

I tried many times but failed to add text for the ellipse. Now the
GraphNode's shape is changed to ellipse but I can't set text for it.

After that I want to pop up window and show the information of GraphNodes
when user double clicks the GraphNodes and GraphConnection. Unfortunately
I find I can't get the selected Node or Connection directly.

Instead of that I get the GraphLabel and PolylineConnection from
'g.getFigureAt()'. So I should list all of the GraphNodes with
'g.getNodes()' and check their text one by one to find the selected Nodes?

My class looks like:

public class MyGraphNode extends GraphNode {

public MyGraphNode(IContainer graphModel, int style, String text) {
super(graphModel, style, text);
}

@Override
protected IFigure createFigureForModel() {
Ellipse ellipse = new Ellipse();
ellipse.setSize(30, 20);
return ellipse;
}

public static void main(String[] args) {

Display d = new Display();
Shell shell = new Shell(d);
shell.setLayout(new FillLayout());
shell.setSize(400, 400);
final Graph g = new Graph(shell, SWT.NONE);

g.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
Object o = g.getFigureAt(e.x, e.y);

if (o instanceof GraphLabel) {
String labelText = ((GraphLabel) o).getText();

GraphNode n;
for (Object node : g.getNodes()) {
if (((GraphNode) node).getText().equalsIgnoreCase(
labelText)) {
n = (GraphNode) node;
}
}

// ....

} else if (o instanceof PolylineConnection) {
// ....
}
}
});

GraphNode n = new MyGraphNode(g, SWT.NONE, "1");
GraphNode n2 = new GraphNode(g, SWT.NONE, "normal");

new GraphConnection(g, SWT.NONE, n, n2);

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

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

}

}

Thanks in advance.
Previous Topic:Selection of composites
Next Topic:Undo Redo retagets never activate for my EditorPart
Goto Forum:
  


Current Time: Fri Nov 21 19:22:51 GMT 2014

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

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