Zest Bug - Small Nodes [message #889814] |
Tue, 19 June 2012 18:18 |
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 #889872 is a reply to message #889832] |
Wed, 20 June 2012 05:55 |
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
|
|
|
Powered by
FUDForum. Page generated in 0.02322 seconds