Home » Eclipse Projects » GEF » Graph too small(Can't resize, can't see)
Graph too small [message #544807] |
Mon, 05 July 2010 15:02 |
ouri.maler Messages: 22 Registered: July 2010 |
Junior Member |
|
|
My apologies if this has been asked before, but I couldn't find it...
I'm currently on a project to create a GUI for an application, and have been learning SWT in the process. I need to include a visual representation of an automaton in the GUI, and decided to use ZEST to that effect.
I started by looking into this tutorial, and I've got the program in 3.1 running successfully. When I tried to create a Graph in my GUI, however...the Graph view ends up so small, I can't actually see the graph it contains. I tried to use the setSize() method, but to no avail.
Any suggestions? Trimmed-down version of the code below...
package verimag.dfinder.gui;
import org.junit.Before;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.ui.part.ViewPart;
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;
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
import verimag.dfinder.Config;
import verimag.dfinder.OutputListener;
import verimag.dfinder.bip2.*;
public class GridGUI extends ViewPart implements OutputListener {
String mInFile;
String BIPPartition = null;
Text console;
Display display;
public static void main(String[] args) {
GridGUI gui = new GridGUI();
gui.init();
}
public void setPartition (String Partition){
BIPPartition = Partition;
}
public void init(){
display = new Display();
final Shell shell = new Shell(display); //This is the window of the GUI.
GridLayout layout = new GridLayout(); // Create the layout.
layout.numColumns = 2;
layout.marginLeft = 15;
layout.marginTop = 15;
layout.marginRight = 15;
layout.marginBottom = 15;
shell.setLayout(layout);
final Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(layout);
//create the menu system
Menu menu = new Menu(shell, SWT.BAR);
// create a file menu and add an exit item
final MenuItem file = new MenuItem(menu, SWT.CASCADE);
file.setText("&File");
final Menu filemenu = new Menu(shell, SWT.DROP_DOWN);
file.setMenu(filemenu);
final MenuItem openItem = new MenuItem(filemenu, SWT.PUSH); //This item is for loading a .BIP file
openItem.setText("&Open BIP file\tCTRL+O");
openItem.setAccelerator(SWT.CTRL + 'O');
final MenuItem selectPartition = new MenuItem(filemenu, SWT.PUSH); //This item is for selecting a partition of the .BIP file to use for verification
selectPartition.setText("&Set Partition\tCTRL+S");
selectPartition.setAccelerator(SWT.CTRL + 'S');
final MenuItem undoPartition = new MenuItem(filemenu, SWT.PUSH); //This item is for selecting not not partition .BIP models for verification
undoPartition.setText("&Undo Partition\tCTRL+U");
undoPartition.setAccelerator(SWT.CTRL + 'U');
final MenuItem separator = new MenuItem(filemenu, SWT.SEPARATOR);
final MenuItem exitItem = new MenuItem(filemenu, SWT.PUSH); //This item is for closing the GUI.
exitItem.setText("E&xit");
shell.setMenuBar(menu);
//create buttons for launching deadlock-search
Button button1 = new Button(composite, SWT.PUSH);
Button button2 = new Button(composite, SWT.PUSH);
button1.setText("Global Positive Mapping");
button2.setText("Global Fixed Point");
button1.setLayoutData(new GridData(200, 100));
button2.setLayoutData(new GridData(200, 100));
shell.setText("DFinder");
console = new Text(shell, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
console.setLayoutData(new GridData(400, 500));
/************************************************************/
final Graph graph = new Graph(composite, SWT.NONE);
// Now a few nodes
GraphNode node1 = new GraphNode(graph, SWT.NONE, "Jim");
GraphNode node2 = new GraphNode(graph, SWT.NONE, "Jack");
GraphNode node3 = new GraphNode(graph, SWT.NONE, "Joe");
GraphNode node4 = new GraphNode(graph, SWT.NONE, "Bill");
// Lets have a directed connection
new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node1,
node2);
// Lets have a dotted graph connection
new GraphConnection(graph, ZestStyles.CONNECTIONS_DOT, node2, node3);
// Standard connection
new GraphConnection(graph, SWT.NONE, node3, node1);
// Change line color and line width
GraphConnection graphConnection = new GraphConnection(graph, SWT.NONE,
node1, node4);
graphConnection.changeLineColor(composite.getDisplay().getSystemColor(
SWT.COLOR_GREEN));
// Also set a text
graphConnection.setText("This is a text");
graphConnection.setHighlightColor(composite.getDisplay().getSystemColor(
SWT.COLOR_RED));
graphConnection.setLineWidth(3);
graphConnection.addListener(SWT.SELECTED, new Listener() {
@Override
public void handleEvent(Event event) {
System.out.println("Selected");
}
});
graph.setLayoutAlgorithm(new SpringLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
/************************************************************/
shell.pack(); //reduce size to minimum required for all widgets
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public void output(String message){
console.insert(message);
}
@Override
public void createPartControl(Composite arg0) {
// TODO Auto-generated method stub
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
}
|
|
|
Goto Forum:
Current Time: Thu Mar 28 10:45:43 GMT 2024
Powered by FUDForum. Page generated in 0.02551 seconds
|