Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [ZEST] Problem with number of node and also color of node
icon9.gif  [ZEST] Problem with number of node and also color of node [message #762218] Wed, 07 December 2011 13:15 Go to next message
michele  is currently offline michele
Messages: 6
Registered: November 2011
Junior Member
Hi guys!
I'm sorry for my English Smile
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.
Sad Sad Sad Sad Sad Sad Sad


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?
Sad Sad Sad Sad Sad Sad

[Updated on: Wed, 07 December 2011 17:17]

Report message to a moderator

Re: [ZEST] Problem with number of node and also color of node [message #767613 is a reply to message #762218] Sun, 18 December 2011 08:44 Go to previous message
Fabian Steeg is currently offline Fabian Steeg
Messages: 72
Registered: July 2009
Member
Some nodes are not connected because you don't connect them in your loop. If I change your conditions from '< 10' to '< 17', all nodes are connected.

To set the color, you get a Color instance from the display, in your case:

prova[i].setBackgroundColor(d.getSystemColor(SWT.COLOR_RED));
Previous Topic:Any suggestion to create flow chart diagram?
Next Topic:[Zest] How to use Drag and Drop (DND) with zest?
Goto Forum:
  


Current Time: Thu Aug 21 06:24:06 EDT 2014

Powered by FUDForum. Page generated in 0.02280 seconds