public static void main(String[] args) { Display d = new Display(); final Shell shell = new Shell(d); shell.setText("Animation Example"); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); Button b = new Button(shell, SWT.PUSH); b.setText("Animate"); final Graph g = new Graph(shell, SWT.NONE); final GraphNode n = new GraphNode(g, SWT.NONE, "Paper"); final GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock"); b.addSelectionListener( new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) {} public void widgetSelected(SelectionEvent e) { Animation.markBegin(); n2.setLocation(0, 0); n.setLocation(g.getSize().x - n2.getSize().width - 5, 0); Animation.run(1000); } }); new GraphConnection(g, SWT.NONE, n, n2); int centerX = shell.getSize().x / 2; int centerY = shell.getSize().y / 4; n.setLocation(centerX, centerY); n2.setLocation(centerX, centerY); shell.open(); while (!shell.isDisposed()) { while (!d.readAndDispatch()) { d.sleep(); } } }
/* * (non-Javadoc) * * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, * java.lang.Object) */ protected void inputChanged(Object input, Object oldInput) { IStylingGraphModelFactory factory = getFactory(); factory.setConnectionStyle(getConnectionStyle()); factory.setNodeStyle(getNodeStyle()); // Save the old map so we can set the size and position of any nodes // that are the same Map oldNodesMap = nodesMap; Graph graph = (Graph) getControl(); graph.setSelection(new GraphNode[0]); Iterator iterator = nodesMap.values().iterator(); while (iterator.hasNext()) { GraphNode node = (GraphNode) iterator.next(); if (!node.isDisposed()) { node.dispose(); } } iterator = connectionsMap.values().iterator(); while (iterator.hasNext()) { GraphConnection connection = (GraphConnection) iterator.next(); if (!connection.isDisposed()) { connection.dispose(); } } nodesMap = new HashMap(); connectionsMap = new HashMap(); graph = factory.createGraphModel(graph); ((Graph) getControl()).setNodeStyle(getNodeStyle()); ((Graph) getControl()).setConnectionStyle(getConnectionStyle()); // check if any of the pre-existing nodes are still present // in this case we want them to keep the same location & size for (Iterator iter = oldNodesMap.keySet().iterator(); iter.hasNext(); ) { Object data = iter.next(); GraphNode newNode = (GraphNode) nodesMap.get(data); if (newNode != null) { GraphNode oldNode = (GraphNode) oldNodesMap.get(data); newNode.setLocation(oldNode.getLocation().x, oldNode.getLocation().y); if (oldNode.isSizeFixed()) { newNode.setSize(oldNode.getSize().width, oldNode.getSize().height); } } } applyLayout(); }
@Override protected Control createDialogArea(Composite parent) { // toolkit = new FormToolkit(parent.getDisplay()); // form = toolkit.createScrolledForm(parent); // form.setText("Dependency Graph UI Legend"); // form.getToolBarManager().add(new Action("Close Dialog", MavenEditorImages.CLEAR) { // public void run() { // close(); // } // }); // form.getToolBarManager().update(true); // form.getBody().setLayout(new TableWrapLayout()); // toolkit.decorateFormHeading(form.getForm()); Graph g = new Graph(parent, SWT.NONE) { public org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint, boolean changed) { return new org.eclipse.swt.graphics.Point(260, 300); } }; g.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); g.setEnabled(false); { GraphNode n1 = new GraphNode(g, SWT.NONE, " compile scope dependency "); n1.setLocation(10, 10); n1.setSize(240, 25); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " non-compile scope dependency "); n1.setLocation(10, 40); n1.setSize(240, 25); n1.setBackgroundColor(colorTestBackground); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " selected dependency "); n1.setLocation(10, 70); n1.setSize(240, 25); n1.setBackgroundColor(colorSelectedBackground); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " selected non-compile "); n1.setLocation(10, 100); n1.setSize(240, 25); n1.setBackgroundColor(colorSelectedTestBackground); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " "); GraphNode n2 = new GraphNode(g, SWT.NONE, " "); DependencyConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2); c1.setText("compile scope"); c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_SOLID); n1.setLocation(10, 140); n2.setLocation(220, 140); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " "); GraphNode n2 = new GraphNode(g, SWT.NONE, " "); n2.setBackgroundColor(colorTestBackground); GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2); c1.setText("non-compile scope"); c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_DOT); c1.setLineColor(colorTestRel); n1.setLocation(10, 170); n2.setLocation(220, 170); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " "); GraphNode n2 = new GraphNode(g, SWT.NONE, " "); GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2); c1.setText("resolved conflict"); c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_SOLID); c1.setLineColor(colorRelResolved); n1.setLocation(10, 200); n2.setLocation(220, 200); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " "); GraphNode n2 = new GraphNode(g, SWT.NONE, " "); n2.setBackgroundColor(colorSelectedBackground); GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2); c1.setText("referenced from selected"); c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_SOLID); c1.setLineColor(highlighted); c1.setLineWidth(3); n1.setLocation(10, 230); n2.setLocation(220, 230); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " "); GraphNode n2 = new GraphNode(g, SWT.NONE, " "); n2.setBackgroundColor(colorSelectedTestBackground); GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2); c1.setText("referenced from non-compile"); c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_DOT); c1.setLineColor(highlighted); c1.setLineWidth(3); n1.setLocation(10, 260); n2.setLocation(220, 260); } g.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { close(); } }); return parent; }