[zest] Set Text For Ellipse [message #249089] |
Mon, 01 June 2009 09:16 |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.04270 seconds