Skip to main content


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 18:15 Go to next message
michele  is currently offline michele Friend
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 22: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 13:44 Go to previous message
Fabian Steeg is currently offline Fabian SteegFriend
Messages: 76
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/Draw2D] Drag and drop
Goto Forum:
  


Current Time: Tue Mar 19 02:22:58 GMT 2024

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

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

Back to the top