Zest Snippet Page
//-- Main.java --
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
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 Main {
private Shell sShell = null;
private static Image image = Display.getDefault().getSystemImage(SWT.ICON_INFORMATION);
public static void main(String[] args) {
Display display = Display.getDefault();
Main thisClass = new Main();
thisClass.createSShell();
thisClass.sShell.open();
while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
image.dispose();
}
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setSize(new Point(492, 345));
sShell.setLayout(new FillLayout());
Graph g = new Graph(sShell, SWT.NONE);
List<GraphNode> items = new ArrayList<GraphNode>();
for (int i = 1; i <= 5; i++) {
items.add(new GraphNode(g, SWT.NONE, "item" + i, image));
}
List<GraphConnection> connections = new ArrayList<GraphConnection>();
List<GraphNode> items2 = new ArrayList<GraphNode>(items);
for (GraphNode node1 : items) {
items2.remove(node1);
for (GraphNode node2 : items2) {
connections.add(new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, node1, node2));
}
}
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
}
}
沒有留言:
張貼留言