[ZEST] Problem with number of node and also color of node [message #762218] |
Wed, 07 December 2011 18:15 |
michele Messages: 6 Registered: November 2011 |
Junior Member |
|
|
Hi guys!
I'm sorry for my English
I have a problem to create a tree... this code it works but It has a serious problem: It draws only 10 nodes....and put the others on the right abd without connections, like this:
5 1 2 3 4
6 7
8 9 10 11
The other problem is about the color of the node...
I'd like to change the color but I don't know how... I try to use the method setBackgroundColor(color c) but I don't understand what parameter It wants.
The code of my program is:
import java.awt.Color;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.LayoutStyles.*;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
import org.eclipse.swt.*;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
public class Prova {
public static void main(String[] args) {
Display d = new Display();
Shell shell = new Shell(d);
shell.setText("GraphSnippet1");
shell.setLayout(new FillLayout());
shell.setSize(800, 800);
Graph g = new Graph(shell, SWT.NONE);
int [] heap = { 1, 2 , 3 , 4 , 5, 6, 7 , 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
GraphNode[] prova = new GraphNode[heap.length];
for(int i=0; i<heap.length; i++){
prova[i] = new GraphNode(g, SWT.COLOR_RED, Integer.toString(heap[i]));
prova[i].setSize(20.00, 20.00);
}
for(int l=0 ; l<heap.length -1; l++){
if(((l*2)+1)<10){
int posFiglioSx = (l*2)+1;
new GraphConnection(g, ZestStyles.CONNECTIONS_DOT, prova[l], prova[posFiglioSx]).setConnectionStyle(1);
}
if(((l*2)+2)<10){
int posFiglioDx = (l*2)+2; //non esiste il figlio destro
new GraphConnection(g, SWT.NONE, prova[l], prova[posFiglioDx]);
}
}
g.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
shell.open();
while (!shell.isDisposed()) {
while (!d.readAndDispatch()) {
d.sleep();
}
}
}
}
Can anyone help me?
[Updated on: Wed, 07 December 2011 22:17] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02307 seconds