Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Zest Bug - Small Nodes(No proper redraw of the graph)
Zest Bug - Small Nodes [message #889814] Tue, 19 June 2012 18:18 Go to next message
Ali Beli is currently offline Ali Beli
Messages: 2
Registered: June 2012
Junior Member
Hello,

I'm new to Zest and GUI. For my GUI I'm using JFrames and JButtons and the Graph is shown by Zest. Somehow I'm facing a problem, when trying to redraw my graph.
Here is a simple demo of my problem:

public class shelltest {
	Display d;
		
	public void showGUI(){
		JFrame frame= new JFrame("SWT GUI");
		frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		JPanel buttonPanel = new JPanel(new GridLayout(2,3));		
		
		final JButton createButton = new JButton("Create Graph");
		
		buttonPanel.add(createButton);
				
		frame.getContentPane().add(buttonPanel);
		
		createButton.setEnabled(true);	
				
		ActionListener createListener = new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
		
				showGraph();			
				
			}
		};

		createButton.addActionListener(createListener);
		frame.setVisible(true);
		
	}
	

	public void showGraph(){	
		
		new Thread() {
		
		public void run() {
            	
            		d = new Display();
        		Shell shell = new Shell(d);
        		shell.setText("Test");
        		shell.setLayout(new FillLayout());
        		Graph g = new Graph(shell, SWT.NONE);
        		
        		GraphNode a = new GraphNode(g,ZestStyles.NODES_CACHE_LABEL, "A");
        		
        		new GraphConnection(g,SWT.NONE,a,new GraphNode(g,SWT.NONE, "B"));
        		g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
        		
        	
        		shell.open();
        		
        		while (!shell.isDisposed()) {
        		   if (!d.readAndDispatch()) {
        	           	d.sleep();
        	        	}
        		}
        	    a.dispose();
        		g.clear();
        		g.dispose();
        		d.dispose();
        		
          	  }
      	  }.start();
		
	}

public static void main(String[] args) {
		shelltest myshell = new shelltest();
		myshell.showGUI();
	}
		
}


If I press the "Create Graph"-Button, the Shell opens and shows me the Graph. Somehow, if I close this new opened window and again press the "Create-Graph"-Button, the graph is shown in a inproper way, with tiny nodes and unreadable labels. Can anyone tell me, how to fix this?

Thank you
Re: Zest Bug - Small Nodes [message #889826 is a reply to message #889814] Tue, 19 June 2012 19:38 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Interesting. If you don't recreate the display, but use always the same instance it works fine.
But why is that, I really don't know.
Re: Zest Bug - Small Nodes [message #889832 is a reply to message #889814] Tue, 19 June 2012 20:21 Go to previous messageGo to next message
Ali Beli is currently offline Ali Beli
Messages: 2
Registered: June 2012
Junior Member
Thanks for your reply. How do you use just one instance of the display?
If I instantiate the display d only once, I'm getting an invalid thread access exception.
Re: Zest Bug - Small Nodes [message #889872 is a reply to message #889832] Wed, 20 June 2012 05:55 Go to previous message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
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.algorithms.SpringLayoutAlgorithm;

public class shelltest {
	final Display d;
	volatile boolean closed;

	public shelltest(Display d) {
		this.d = d;
	}

	public void showGUI() {
		JFrame frame= new JFrame("SWT GUI");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.addWindowListener(new WindowAdapter() {

			@Override
			public void windowClosed(WindowEvent e) {
				closed = true;
			}
		
		});
		JPanel buttonPanel = new JPanel(new GridLayout(2,3));		

		final JButton createButton = new JButton("Create Graph");

		buttonPanel.add(createButton);

		frame.getContentPane().add(buttonPanel);

		createButton.setEnabled(true);	

		ActionListener createListener = new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {

				showGraph();			

			}
		};

		createButton.addActionListener(createListener);
		frame.setVisible(true);
	}


	public void showGraph(){	
		d.asyncExec(new Runnable() {

			@Override
			public void run() {
				Shell shell = new Shell(d);
				shell.setText("Test");
				shell.setLayout(new FillLayout());
				Graph g = new Graph(shell, SWT.NONE);

				GraphNode a = new GraphNode(g,ZestStyles.NODES_CACHE_LABEL, "A");

				new GraphConnection(g,SWT.NONE,a,new GraphNode(g,SWT.NONE, "B"));
				g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);

				shell.open();
			}
		});
	}

	public static void main(String[] args) {
		Display d = new Display();
		shelltest myshell = new shelltest(d);
		myshell.showGUI();
		
		while (!myshell.closed) {
			if (!d.readAndDispatch()) {
				d.sleep();
			}
		}
		d.dispose();
	}

}

[Updated on: Wed, 20 June 2012 06:51]

Report message to a moderator

Previous Topic:Best way to add Draw2d to a GraphicalEditorWithFlyoutPalette?
Next Topic:Integrate tree drawing algorithm in GEF editor?
Goto Forum:
  


Current Time: Tue Sep 23 22:34:22 GMT 2014

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

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