I'm glad to have become a csdn expert today, so I have to take the time to write a blog. Recently, the company has a need to display hierarchical relationships in a tree structure in RCP applications. After searching for a half-day open-source framework, I finally found that eclipse rest best fits the current needs. Rest is specifically used to display the graph effect. It does not need to talk about the effect or code.
public class DeviceTreeViewSWT { public static void main(String[] args) { Display d = new Display(); Shell shell = new Shell(d); Image image1 = Display.getDefault().getSystemImage(SWT.ICON_INFORMATION); Image image2 = Display.getDefault().getSystemImage(SWT.ICON_WARNING); Image image3 = Display.getDefault().getSystemImage(SWT.ICON_ERROR); shell.setLayout(new FillLayout()); shell.setSize(800, 800); Graph g = new Graph(shell, SWT.NONE); g.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { System.out.println(((Graph) e.widget).getSelection()); } }); g.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); GraphNode n1 = new GraphNode(g, SWT.NONE, "Virtual"); n1.setBackgroundColor(new Color(d,255,0,0)); GraphNode n2 = new GraphNode(g, SWT.NONE, "Shanghai"); GraphNode n3 = new GraphNode(g, SWT.NONE, "Beijing"); GraphNode n4 = new GraphNode(g, SWT.NONE, "AGM001"); GraphNode n5 = new GraphNode(g, SWT.NONE, "AGM002"); GraphNode n6 = new GraphNode(g, SWT.NONE, "AGM003"); GraphNode n7 = new GraphNode(g, SWT.NONE, "AGM004"); GraphNode n8 = new GraphNode(g, SWT.NONE, "AGM005"); GraphNode n9 = new GraphNode(g, SWT.NONE, "AGM006"); GraphNode n10 = new GraphNode(g, SWT.NONE, "AGM007"); GraphNode n11 = new GraphNode(g, SWT.NONE, "AGM008");// class PathFigure extends PolylineConnection {// public PathFigure() {// setTargetDecoration(new PolylineDecoration());// setConnectionRouter(new ManhattanConnectionRouter());// }// } new GraphConnection(g, SWT.NONE, n1, n2); new GraphConnection(g, SWT.NONE, n1, n3); new GraphConnection(g, SWT.NONE, n2, n4); new GraphConnection(g, SWT.NONE, n2, n5); new GraphConnection(g, SWT.NONE, n2, n6); new GraphConnection(g, SWT.NONE, n3, n7); new GraphConnection(g, SWT.NONE, n3, n8); new GraphConnection(g, SWT.NONE, n5, n9); new GraphConnection(g, SWT.NONE, n5, n10); new GraphConnection(g, SWT.NONE, n4, n11); //g.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.ENFORCE_BOUNDS), true); //g.setLayoutAlgorithm(new HorizontalTreeLayoutAlgorithm(LayoutStyles.ENFORCE_BOUNDS),true); g.setLayoutAlgorithm(new RadialLayoutAlgorithm(LayoutStyles.ENFORCE_BOUNDS),true); //g.setLayoutAlgorithm(new GridLayoutAlgorithm(LayoutStyles.ENFORCE_BOUNDS), true); shell.open(); while (!shell.isDisposed()) { while (!d.readAndDispatch()) { d.sleep(); } } image1.dispose(); image2.dispose(); image3.dispose(); }}
Change layoutalgorithm to see a brighter radiation map.
Good results. It is very convenient to display graphs and trees.
If you use graphviewer encapsulated by jface, it is more convenient to use MVC.