Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 141373 Details for
Bug 283244
Adapt snippets to new layout API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch
tests-patch1.diff (text/plain), 204.76 KB, created by
Mateusz Matela
on 2009-07-12 10:23:48 EDT
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Mateusz Matela
Created:
2009-07-12 10:23:48 EDT
Size:
204.76 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.zest.tests >Index: src/org/eclipse/zest/tests/swt/PaintSnippet.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/test/org.eclipse.zest.tests/src/org/eclipse/zest/tests/swt/PaintSnippet.java,v >retrieving revision 1.2 >diff -u -r1.2 PaintSnippet.java >--- src/org/eclipse/zest/tests/swt/PaintSnippet.java 12 Sep 2007 20:44:36 -0000 1.2 >+++ src/org/eclipse/zest/tests/swt/PaintSnippet.java 12 Jul 2009 14:23:45 -0000 >@@ -1,11 +1,13 @@ > /******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, > * Canada. All rights reserved. This program and the accompanying materials are > * made available under the terms of the Eclipse Public License v1.0 which > * accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * >- * Contributors: The Chisel Group, University of Victoria >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 > ******************************************************************************/ > package org.eclipse.zest.tests.swt; > >@@ -13,7 +15,6 @@ > 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.layouts.LayoutStyles; > import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.PaintEvent; >@@ -66,7 +67,7 @@ > new GraphConnection(g, SWT.NONE, n, n2); > new GraphConnection(g, SWT.NONE, n2, n3); > new GraphConnection(g, SWT.NONE, n3, n); >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >+ g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); > > b.addSelectionListener(new SelectionListener() { > >Index: src/org/eclipse/zest/tests/swt/GraphSnippet7.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet7.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet7.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet7.java 12 May 2008 18:14:29 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,71 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-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.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.MouseEvent; >-import org.eclipse.swt.events.MouseMoveListener; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-/** >- * This snippet shows how to use the findFigureAt to get the figure under the mouse >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet7 { >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphSnippet7"); >- shell.setLayout(new FillLayout()); >- shell.setSize(400, 400); >- >- final Graph g = new Graph(shell, SWT.NONE); >- >- GraphNode n = new GraphNode(g, SWT.NONE, "Paper"); >- GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock"); >- GraphNode n3 = new GraphNode(g, SWT.NONE, "Scissors"); >- new GraphConnection(g, SWT.NONE, n, n2); >- new GraphConnection(g, SWT.NONE, n2, n3); >- new GraphConnection(g, SWT.NONE, n3, n); >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- >- g.addMouseMoveListener(new MouseMoveListener() { >- >- public void mouseMove(MouseEvent e) { >- // Get the figure at the current mouse location >- Object o = g.getFigureAt(e.x, e.y); >- if ( o != null ) { >- System.out.println(o + " is at: (" + e.x + "," + e.y + ")"); >- } >- } >- >- }); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- } >-} >Index: src/org/eclipse/zest/tests/swt/GraphSnippet12.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet12.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet12.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet12.java 31 Mar 2009 16:43:00 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,164 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-import java.util.Iterator; >- >-import org.eclipse.draw2d.ColorConstants; >-import org.eclipse.draw2d.Ellipse; >-import org.eclipse.draw2d.Figure; >-import org.eclipse.draw2d.FreeformLayout; >-import org.eclipse.draw2d.IFigure; >-import org.eclipse.draw2d.ImageFigure; >-import org.eclipse.draw2d.PolylineShape; >-import org.eclipse.draw2d.geometry.Point; >-import org.eclipse.draw2d.geometry.Rectangle; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >-import org.eclipse.zest.core.widgets.CGraphNode; >-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.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >- >-/** >- * >- * This snippet shows how to create a curved connection using Zest. >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet12 { >- >- public static IFigure createPersonFigure(Image headImage) { >- Figure person = new Figure(); >- person.setLayoutManager(new FreeformLayout()); >- IFigure head = null; >- if ( headImage != null ) { >- headImage = new Image(headImage.getDevice(), headImage.getImageData().scaledTo(40, 50)); >- head = new ImageFigure(headImage); >- } >- else >- head = new Ellipse(); >- head.setSize(40, 50); >- >- PolylineShape body = new PolylineShape(); >- body.setLineWidth(1); >- body.setStart(new Point(20,40)); >- body.setEnd(new Point(20,100)); >- body.setBounds(new Rectangle(0,0,40,100)); >- >- PolylineShape leftLeg = new PolylineShape(); >- leftLeg.setLineWidth(1); >- leftLeg.setStart(new Point(20,100)); >- leftLeg.setEnd(new Point(0,130)); >- leftLeg.setBounds(new Rectangle(0,0,40,130)); >- >- PolylineShape rightLeg = new PolylineShape(); >- rightLeg.setLineWidth(1); >- rightLeg.setStart(new Point(20,100)); >- rightLeg.setEnd(new Point(40,130)); >- rightLeg.setBounds(new Rectangle(0,0,40,130)); >- >- PolylineShape leftArm = new PolylineShape(); >- leftArm.setLineWidth(1); >- leftArm.setStart(new Point(20,60)); >- leftArm.setEnd(new Point(0,50)); >- leftArm.setBounds(new Rectangle(0,0,40,130)); >- >- PolylineShape rightArm = new PolylineShape(); >- rightArm.setLineWidth(1); >- rightArm.setStart(new Point(20,60)); >- rightArm.setEnd(new Point(40,50)); >- rightArm.setBounds(new Rectangle(0,0,40,130)); >- >- person.add(head); >- person.add(body); >- person.add(leftLeg); >- person.add(rightLeg); >- person.add(leftArm); >- person.add(rightArm); >- person.setSize(40,130); >- return person; >- } >- >- public static void main(String[] args) { >- final Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphSnippet11"); >- shell.setLayout(new FillLayout()); >- shell.setSize(400, 400); >- >- >- final Graph g = new Graph(shell, SWT.NONE); >- g.addSelectionListener(new SelectionListener(){ >- >- public void widgetSelected(SelectionEvent e) { >- Iterator iter = g.getSelection().iterator(); >- while(iter.hasNext()) { >- Object o = iter.next(); >- if ( o instanceof CGraphNode) { >- IFigure figure = ((CGraphNode)o).getFigure(); >- figure.setBackgroundColor(ColorConstants.blue); >- figure.setForegroundColor(ColorConstants.blue); >- } >- } >- iter = g.getNodes().iterator(); >- while ( iter.hasNext()) { >- Object o = iter.next(); >- if ( o instanceof CGraphNode) { >- if ( !g.getSelection().contains(o)) { >- ((CGraphNode)o).getFigure().setBackgroundColor(ColorConstants.black); >- ((CGraphNode)o).getFigure().setForegroundColor(ColorConstants.black); >- } >- } >- } >- } >- >- public void widgetDefaultSelected(SelectionEvent e) { >- // TODO Auto-generated method stub >- >- } >- }); >- >- Image zx = new Image(d, "zx.png"); >- Image ibull = new Image(d, "ibull.jpg"); >- CGraphNode n = new CGraphNode(g, SWT.NONE, createPersonFigure(zx)); >- CGraphNode n2 = new CGraphNode(g, SWT.NONE, createPersonFigure(ibull)); >- GraphNode n3 = new GraphNode(g, SWT.NONE, "PDE"); >- GraphNode n4 = new GraphNode(g, SWT.NONE, "Zest"); >- GraphNode n5 = new GraphNode(g, SWT.NONE, "PDE Viz tool"); >- >- new GraphConnection(g, SWT.NONE, n, n2); >- new GraphConnection(g, SWT.NONE, n, n3); >- new GraphConnection(g, SWT.NONE, n2, n4); >- new GraphConnection(g, SWT.NONE, n, n5); >- new GraphConnection(g, SWT.NONE, n2, n5); >- new GraphConnection(g, SWT.NONE, n3, n5); >- new GraphConnection(g, SWT.NONE, n4, n5); >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- zx.dispose(); >- ibull.dispose(); >- } >- >-} >Index: src/org/eclipse/zest/tests/swt/GraphSnippet10.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet10.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet10.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet10.java 20 Nov 2008 23:51:04 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,78 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.SelectionAdapter; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Button; >-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.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >- >-/** >- * >- * This snippet shows how to create a curved connection using Zest. >- * Each time the Button is clicked, the curve changes. >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet10 { >- >- public static void main(String[] args) { >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphSnippet1"); >- shell.setLayout(new FillLayout()); >- shell.setSize(400, 400); >- >- final Graph g = new Graph(shell, SWT.NONE); >- >- GraphNode n = new GraphNode(g, SWT.NONE, "Paper"); >- n.setBorderColor(org.eclipse.draw2d.ColorConstants.yellow); >- n.setBorderWidth(3); >- GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock"); >- GraphNode n3 = new GraphNode(g, SWT.NONE, "Scissors"); >- final GraphConnection connection = new GraphConnection(g, SWT.NONE, n, n2); >- connection.setLineWidth(3); >- new GraphConnection(g, SWT.NONE, n2, n3); >- new GraphConnection(g, SWT.NONE, n3, n); >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- >- Button button = new Button(shell, SWT.PUSH); >- button.setText("Change Curve"); >- button.addSelectionListener(new SelectionAdapter() { >- int count = 0; >- public void widgetSelected(SelectionEvent e) { >- count = ++count % 16; >- if ( count > 8 ) { >- connection.setCurveDepth((-16 + count) * 10); >- } >- else { >- connection.setCurveDepth(count * 10); >- } >- } >- }); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- } >- >-} >Index: src/org/eclipse/zest/tests/swt/ZoomSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/ZoomSnippet.java >diff -N src/org/eclipse/zest/tests/swt/ZoomSnippet.java >--- src/org/eclipse/zest/tests/swt/ZoomSnippet.java 12 Sep 2007 20:44:36 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,151 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-import org.eclipse.zest.core.widgets.Graph; >-import org.eclipse.zest.core.widgets.GraphConnection; >-import org.eclipse.zest.core.widgets.GraphContainer; >-import org.eclipse.zest.core.widgets.GraphItem; >-import org.eclipse.zest.core.widgets.GraphNode; >-import org.eclipse.zest.core.widgets.ZestStyles; >-import org.eclipse.zest.layouts.LayoutAlgorithm; >-import org.eclipse.zest.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.CompositeLayoutAlgorithm; >-import org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm; >-import org.eclipse.zest.layouts.algorithms.HorizontalShift; >-import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm; >-import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.KeyEvent; >-import org.eclipse.swt.events.KeyListener; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-public class ZoomSnippet { >- >- private static Image image1; >- private static Image classImage; >- >- public static void createContainer(Graph g) { >- GraphContainer a = new GraphContainer(g, SWT.NONE, "SomeClass.java", classImage); >- int r = (int) ((Math.random() * 3) + 1); >- r = 2; >- populateContainer(a, g, r, true); >- for (int i = 0; i < 4; i++) { >- GraphContainer b = new GraphContainer(g, SWT.NONE, "SomeNestedClass.java", classImage); >- r = (int) ((Math.random() * 3) + 1); >- r = 2; >- populateContainer(b, g, r, false); >- new GraphConnection(g, SWT.NONE, a, b); >- for (int j = 0; j < 4; j++) { >- GraphContainer c = new GraphContainer(g, SWT.NONE, "DefaultAction.java", classImage); >- r = (int) ((Math.random() * 3) + 1); >- r = 2; >- populateContainer(c, g, r, true); >- new GraphConnection(g, SWT.NONE, b, c); >- } >- } >- } >- >- public static void populateContainer(GraphContainer c, Graph g, int number, boolean radial) { >- GraphNode a = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "SomeClass.java", classImage); >- for (int i = 0; i < 4; i++) { >- GraphNode b = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "SomeNestedClass.java", classImage); >- new GraphConnection(g, SWT.NONE, a, b); >- for (int j = 0; j < 4; j++) { >- GraphNode d = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "DefaultAction.java", classImage); >- new GraphConnection(g, SWT.NONE, b, d); >- if (number > 2) { >- for (int k = 0; k < 4; k++) { >- GraphNode e = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "LastAction(Hero).java", classImage); >- new GraphConnection(g, SWT.NONE, d, e); >- if (number > 3) { >- for (int l = 0; l < 4; l++) { >- GraphNode f = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "LastAction(Hero).java", classImage); >- new GraphConnection(g, SWT.NONE, e, f); >- } >- } >- } >- } >- } >- } >- if (number == 1) { >- c.setScale(0.75); >- } else if (number == 2) { >- c.setScale(0.50); >- } else { >- c.setScale(0.25); >- } >- if (radial) { >- c.setLayoutAlgorithm(new RadialLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- } else { >- c.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- } >- } >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- // Create the shell >- Display d = new Display(); >- >- image1 = new Image(Display.getDefault(), ZoomSnippet.class.getResourceAsStream("package_obj.gif")); >- classImage = new Image(Display.getDefault(), ZoomSnippet.class.getResourceAsStream("class_obj.gif")); >- >- Shell shell = new Shell(d); >- shell.setText("GraphSnippet1"); >- shell.setLayout(new FillLayout()); >- shell.setSize(500, 800); >- >- final Graph g = new Graph(shell, SWT.NONE); >- createContainer(g); >- >- CompositeLayoutAlgorithm compositeLayoutAlgorithm = new CompositeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING, new LayoutAlgorithm[] { new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), new HorizontalShift(LayoutStyles.NO_LAYOUT_NODE_RESIZING) }); >- //g.setLayoutAlgorithm(new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- g.setLayoutAlgorithm(compositeLayoutAlgorithm, true); >- >- g.addKeyListener(new KeyListener() { >- boolean flip = true; >- >- public void keyPressed(KeyEvent e) { >- >- if (g.getSelection().size() == 1) { >- GraphNode item = (GraphNode) g.getSelection().get(0); >- if (item.getItemType() == GraphItem.CONTAINER) { >- if (flip) { >- (item).setSize(500, 100); >- } else { >- (item).setSize(0, 0); >- } >- flip = !flip; >- } >- } >- >- } >- >- public void keyReleased(KeyEvent e) { >- // TODO Auto-generated method stub >- >- } >- >- }); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- image1.dispose(); >- } >-} >Index: src/org/eclipse/zest/tests/swt/GraphSnippet8.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet8.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet8.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet8.java 12 May 2008 18:22:24 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,120 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-import org.eclipse.draw2d.ColorConstants; >-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.Filter; >-import org.eclipse.zest.layouts.LayoutItem; >-import org.eclipse.zest.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; >- >-/** >- * This snippet shows how to filter elements in the layout. The Data on the tree >- * connections are set to "False", meaning they won't be filtered. >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet8 { >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- Display display = new Display(); >- Shell shell = new Shell(display); >- shell.setText("GraphSnippet8"); >- shell.setLayout(new FillLayout()); >- shell.setSize(400, 400); >- >- final Graph graph = new Graph(shell, SWT.NONE); >- >- GraphNode a = new GraphNode(graph, SWT.NONE, "Root"); >- GraphNode b = new GraphNode(graph, SWT.NONE, "B"); >- GraphNode c = new GraphNode(graph, SWT.NONE, "C"); >- GraphNode d = new GraphNode(graph, SWT.NONE, "D"); >- GraphNode e = new GraphNode(graph, SWT.NONE, "E"); >- GraphNode f = new GraphNode(graph, SWT.NONE, "F"); >- GraphNode g = new GraphNode(graph, SWT.NONE, "G"); >- GraphNode h = new GraphNode(graph, SWT.NONE, "H"); >- GraphConnection connection = new GraphConnection(graph, SWT.NONE, a, b); >- connection.setData(Boolean.FALSE); >- connection = new GraphConnection(graph, SWT.NONE, a, c); >- connection.setData(Boolean.FALSE); >- connection = new GraphConnection(graph, SWT.NONE, a, c); >- connection.setData(Boolean.FALSE); >- connection = new GraphConnection(graph, SWT.NONE, a, d); >- connection.setData(Boolean.FALSE); >- connection = new GraphConnection(graph, SWT.NONE, b, e); >- connection.setData(Boolean.FALSE); >- connection = new GraphConnection(graph, SWT.NONE, b, f); >- connection.setData(Boolean.FALSE); >- connection = new GraphConnection(graph, SWT.NONE, c, g); >- connection.setData(Boolean.FALSE); >- connection = new GraphConnection(graph, SWT.NONE, d, h); >- connection.setData(Boolean.FALSE); >- >- connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, b, c); >- connection.setLineColor(ColorConstants.red); >- connection.setLineWidth(3); >- connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, c, d); >- connection.setLineColor(ColorConstants.red); >- connection.setLineWidth(3); >- connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, e, f); >- connection.setLineColor(ColorConstants.red); >- connection.setLineWidth(3); >- connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, f, g); >- connection.setLineColor(ColorConstants.red); >- connection.setLineWidth(3); >- >- connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, h, e); >- connection.setLineColor(ColorConstants.red); >- connection.setLineWidth(3); >- >- TreeLayoutAlgorithm treeLayoutAlgorithm = new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING); >- Filter filter = new Filter() { >- public boolean isObjectFiltered(LayoutItem item) { >- >- // Get the "Connection" from the Layout Item >- // and use this connection to get the "Graph Data" >- Object object = item.getGraphData(); >- if (object instanceof GraphConnection ) { >- GraphConnection connection = (GraphConnection) object; >- if ( connection.getData() != null && connection.getData() instanceof Boolean ) { >- // If the data is false, don't filter, otherwise, filter. >- return ((Boolean)connection.getData()).booleanValue(); >- } >- return true; >- } >- return false; >- } >- >- }; >- treeLayoutAlgorithm.setFilter(filter); >- graph.setLayoutAlgorithm(treeLayoutAlgorithm, true); >- >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!display.readAndDispatch()) { >- display.sleep(); >- } >- } >- } >- >-} >Index: src/org/eclipse/zest/tests/swt/NestedGraphSnippet2.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/NestedGraphSnippet2.java >diff -N src/org/eclipse/zest/tests/swt/NestedGraphSnippet2.java >--- src/org/eclipse/zest/tests/swt/NestedGraphSnippet2.java 12 Sep 2007 20:44:36 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,87 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-import org.eclipse.zest.core.widgets.Graph; >-import org.eclipse.zest.core.widgets.GraphConnection; >-import org.eclipse.zest.core.widgets.GraphContainer; >-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.GridLayoutAlgorithm; >-import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-public class NestedGraphSnippet2 { >- >- public static void main(String[] args) { >- // Create the shell >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphSnippet1"); >- shell.setLayout(new FillLayout()); >- shell.setSize(400, 400); >- >- Graph g = new Graph(shell, SWT.NONE); >- >- /* Machines */ >- GraphContainer machine1 = new GraphContainer(g, SWT.NONE); >- machine1.setText("Machine 1 (prop:1)"); >- GraphContainer machine2 = new GraphContainer(g, SWT.NONE); >- machine2.setText("Machine 2"); >- GraphContainer machine3 = new GraphContainer(g, SWT.NONE); >- machine3.setText("Machine 3"); >- >- /* Network */ >- GraphConnection networkConnection = new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, machine1, machine2); >- networkConnection.setText("Network (bandwidth:1) "); >- new GraphConnection(g, SWT.NONE, machine2, machine3); >- >- /* Containers */ >- GraphContainer container1 = new GraphContainer(machine1, SWT.NONE); >- container1.setText("Host 1"); >- GraphContainer container2 = new GraphContainer(machine1, SWT.NONE); >- container2.setText("Host 2"); >- >- GraphContainer container3 = new GraphContainer(machine2, SWT.NONE); >- container3.setText("Host 3"); >- GraphContainer container4 = new GraphContainer(machine3, SWT.NONE); >- container4.setText("Host 4"); >- >- /* Objects */ >- GraphNode object1 = new GraphNode(container1, ZestStyles.NODES_FISHEYE, "JSP Object"); >- GraphNode object2 = new GraphNode(container1, ZestStyles.NODES_FISHEYE, "JSP Object 2"); >- GraphNode object3 = new GraphNode(container2, ZestStyles.NODES_FISHEYE, "JSP Object 3"); >- GraphNode object4 = new GraphNode(container3, ZestStyles.NODES_FISHEYE, "JSP Object 4"); >- GraphNode object5 = new GraphNode(container4, ZestStyles.NODES_FISHEYE, "JSP Object 5"); >- >- /* Connections */ >- new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object1, object2); >- new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object2, object3); >- new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object3, object4); >- new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object4, object5); >- >- container1.setLayoutAlgorithm(new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- container2.setLayoutAlgorithm(new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- container3.setLayoutAlgorithm(new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- container3.setLayoutAlgorithm(new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- } >-} >Index: src/org/eclipse/zest/tests/swt/GraphSnippet3.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet3.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet3.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet3.java 9 May 2008 20:42:48 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,73 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, Canada. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * The Chisel Group, University of Victoria >- *******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-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.swt.SWT; >-import org.eclipse.swt.events.SelectionAdapter; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-/** >- * Adds a selection listener to the nodes to tell when a selection event has >- * happened. >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet3 { >- >- 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(400, 400); >- >- 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, "Information", image1); >- GraphNode n2 = new GraphNode(g, SWT.NONE, "Warning", image2); >- GraphNode n3 = new GraphNode(g, SWT.NONE, "Error", image3); >- >- new GraphConnection(g, SWT.NONE, n1, n2); >- new GraphConnection(g, SWT.NONE, n2, n3); >- >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- image1.dispose(); >- image2.dispose(); >- image3.dispose(); >- >- } >-} >Index: src/org/eclipse/zest/tests/swt/CustomLayout.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/test/org.eclipse.zest.tests/src/org/eclipse/zest/tests/swt/CustomLayout.java,v >retrieving revision 1.1 >diff -u -r1.1 CustomLayout.java >--- src/org/eclipse/zest/tests/swt/CustomLayout.java 17 Jun 2008 04:40:03 -0000 1.1 >+++ src/org/eclipse/zest/tests/swt/CustomLayout.java 12 Jul 2009 14:23:45 -0000 >@@ -1,3 +1,14 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ > package org.eclipse.zest.tests.swt; > > import org.eclipse.swt.SWT; >@@ -7,10 +18,9 @@ > 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.layouts.LayoutEntity; >-import org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm; >-import org.eclipse.zest.layouts.dataStructures.InternalNode; >-import org.eclipse.zest.layouts.dataStructures.InternalRelationship; >+import org.eclipse.zest.layouts.EntityLayout; >+import org.eclipse.zest.layouts.LayoutAlgorithm; >+import org.eclipse.zest.layouts.LayoutContext; > > /** > * This snippet shows how to create a custom layout. This layout simply lays the nodes out vertically >@@ -36,59 +46,28 @@ > new GraphConnection(g, SWT.NONE, n, n2); > new GraphConnection(g, SWT.NONE, n2, n3); > new GraphConnection(g, SWT.NONE, n3, n); >- g.setLayoutAlgorithm(new AbstractLayoutAlgorithm(SWT.NONE) { >- >+ >+ LayoutAlgorithm layoutAlgorithm = new LayoutAlgorithm() { >+ private LayoutContext context; >+ public void setLayoutContext(LayoutContext context) { >+ this.context = context; >+ } > >- private int totalSteps; >- private int currentStep; >- >- protected void applyLayoutInternal(InternalNode[] entitiesToLayout, >- InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, >- double boundsHeight) { >- >- totalSteps = entitiesToLayout.length; >- double distance = boundsWidth / totalSteps; >+ public void applyLayout() { >+ EntityLayout[] entitiesToLayout = context.getEntities(); >+ int totalSteps = entitiesToLayout.length; >+ double distance = context.getBounds().width / totalSteps; > int xLocation = 0; >- >- fireProgressStarted(totalSteps); >- >- for (currentStep = 0; currentStep < entitiesToLayout.length; currentStep++) { >- LayoutEntity layoutEntity = entitiesToLayout[currentStep].getLayoutEntity(); >- layoutEntity.setLocationInLayout(xLocation, layoutEntity.getYInLayout()); >+ >+ for (int currentStep = 0; currentStep < entitiesToLayout.length; currentStep++) { >+ EntityLayout layoutEntity = entitiesToLayout[currentStep]; >+ layoutEntity.setLocation(xLocation, layoutEntity.getLocation().y); > xLocation+= distance; >- fireProgressEvent(currentStep, totalSteps); > } >- fireProgressEnded(totalSteps); >- } >- >- protected int getCurrentLayoutStep() { >- return 0; >- } >- >- protected int getTotalNumberOfLayoutSteps() { >- return totalSteps; > } >- >- protected boolean isValidConfiguration(boolean asynchronous, boolean continuous) { >- return true; >- } >- >- protected void postLayoutAlgorithm(InternalNode[] entitiesToLayout, >- InternalRelationship[] relationshipsToConsider) { >- // Do nothing >- } >- >- protected void preLayoutAlgorithm(InternalNode[] entitiesToLayout, >- InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height) { >- // do nothing >- } >- >- public void setLayoutArea(double x, double y, double width, double height) { >- // do nothing >- } >- >- }, true); >- >+ }; >+ g.setLayoutAlgorithm(layoutAlgorithm, true); >+ > shell.open(); > while (!shell.isDisposed()) { > while (!d.readAndDispatch()) { >Index: src/org/eclipse/zest/tests/swt/GraphSnippet13.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet13.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet13.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet13.java 31 Mar 2009 16:43:00 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,182 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-import java.util.Iterator; >- >-import org.eclipse.draw2d.ColorConstants; >-import org.eclipse.draw2d.Ellipse; >-import org.eclipse.draw2d.Figure; >-import org.eclipse.draw2d.FlowLayout; >-import org.eclipse.draw2d.FreeformLayout; >-import org.eclipse.draw2d.IFigure; >-import org.eclipse.draw2d.ImageFigure; >-import org.eclipse.draw2d.Label; >-import org.eclipse.draw2d.MarginBorder; >-import org.eclipse.draw2d.PolylineShape; >-import org.eclipse.draw2d.geometry.Point; >-import org.eclipse.draw2d.geometry.Rectangle; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >-import org.eclipse.zest.core.widgets.CGraphNode; >-import org.eclipse.zest.core.widgets.Graph; >-import org.eclipse.zest.core.widgets.GraphConnection; >-import org.eclipse.zest.core.widgets.GraphContainer; >-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; >- >-/** >- * >- * This snippet shows how to create a curved connection using Zest. >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet13 { >- >- public static IFigure createPersonFigure(Image headImage) { >- Figure person = new Figure(); >- person.setLayoutManager(new FreeformLayout()); >- IFigure head = null; >- if ( headImage != null ) { >- headImage = new Image(headImage.getDevice(), headImage.getImageData().scaledTo(40, 50)); >- head = new ImageFigure(headImage); >- } >- else >- head = new Ellipse(); >- head.setSize(40, 50); >- >- PolylineShape body = new PolylineShape(); >- body.setLineWidth(1); >- body.setStart(new Point(20,40)); >- body.setEnd(new Point(20,100)); >- body.setBounds(new Rectangle(0,0,40,100)); >- >- PolylineShape leftLeg = new PolylineShape(); >- leftLeg.setLineWidth(1); >- leftLeg.setStart(new Point(20,100)); >- leftLeg.setEnd(new Point(0,130)); >- leftLeg.setBounds(new Rectangle(0,0,40,130)); >- >- PolylineShape rightLeg = new PolylineShape(); >- rightLeg.setLineWidth(1); >- rightLeg.setStart(new Point(20,100)); >- rightLeg.setEnd(new Point(40,130)); >- rightLeg.setBounds(new Rectangle(0,0,40,130)); >- >- PolylineShape leftArm = new PolylineShape(); >- leftArm.setLineWidth(1); >- leftArm.setStart(new Point(20,60)); >- leftArm.setEnd(new Point(0,50)); >- leftArm.setBounds(new Rectangle(0,0,40,130)); >- >- PolylineShape rightArm = new PolylineShape(); >- rightArm.setLineWidth(1); >- rightArm.setStart(new Point(20,60)); >- rightArm.setEnd(new Point(40,50)); >- rightArm.setBounds(new Rectangle(0,0,40,130)); >- >- person.add(head); >- person.add(body); >- person.add(leftLeg); >- person.add(rightLeg); >- person.add(leftArm); >- person.add(rightArm); >- person.setSize(40,130); >- return person; >- } >- >- public static void main(String[] args) { >- final Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphSnippet11"); >- shell.setLayout(new FillLayout()); >- shell.setSize(400, 400); >- >- >- final Graph g = new Graph(shell, SWT.NONE); >- g.addSelectionListener(new SelectionListener(){ >- >- public void widgetSelected(SelectionEvent e) { >- Iterator iter = g.getSelection().iterator(); >- while(iter.hasNext()) { >- Object o = iter.next(); >- if ( o instanceof CGraphNode) { >- IFigure figure = ((CGraphNode)o).getFigure(); >- figure.setBackgroundColor(ColorConstants.blue); >- figure.setForegroundColor(ColorConstants.blue); >- } >- } >- iter = g.getNodes().iterator(); >- while ( iter.hasNext()) { >- Object o = iter.next(); >- if ( o instanceof CGraphNode) { >- if ( !g.getSelection().contains(o)) { >- ((CGraphNode)o).getFigure().setBackgroundColor(ColorConstants.black); >- ((CGraphNode)o).getFigure().setForegroundColor(ColorConstants.black); >- } >- } >- } >- } >- >- public void widgetDefaultSelected(SelectionEvent e) { >- // TODO Auto-generated method stub >- >- } >- }); >- >- Image zx = new Image(d, "zxsnow.png"); >- IFigure tooltip = new Figure(); >- tooltip.setBorder(new MarginBorder(5,5,5,5)); >- FlowLayout layout = new FlowLayout(false); >- layout.setMajorSpacing(3); >- layout.setMinorAlignment(3); >- tooltip.setLayoutManager(new FlowLayout(false)); >- tooltip.add(new ImageFigure(zx)); >- tooltip.add(new Label("Name: " + "Chris Aniszczyk")); >- tooltip.add(new Label("Location: " + "Austin, Texas")); >- >- Image ibull = new Image(d, "ibull.jpg"); >- GraphContainer c1 = new GraphContainer(g, SWT.NONE); >- c1.setText("Canada"); >- GraphContainer c2 = new GraphContainer(g, SWT.NONE); >- c2.setText("USA"); >- >- GraphNode n1 = new GraphNode(c1, SWT.NONE, "Ian B."); >- n1.setSize(200, 100); >- GraphNode n2 = new GraphNode(c2, SWT.NONE, "Chris A."); >- n2.setTooltip(tooltip); >- >- GraphConnection connection = new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, n1, n2); >- connection.setCurveDepth(-30); >- GraphConnection connection2 = new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, n2, n1); >- connection2.setCurveDepth(-30); >- >- >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- zx.dispose(); >- ibull.dispose(); >- } >- >-} >Index: src/org/eclipse/zest/tests/swt/GraphSnippet4.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet4.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet4.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet4.java 12 Sep 2007 20:44:36 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,103 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, Canada. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * The Chisel Group, University of Victoria >- *******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-import org.eclipse.draw2d.IFigure; >-import org.eclipse.draw2d.Label; >-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.swt.SWT; >-import org.eclipse.swt.graphics.GC; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-/** >- * This snippet shows how a custom figure can be used as a ToolTip for connections. >- * Let your mouse hover over an edge to see the custom tooltip. >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet4 { >- >- >- /** >- * Merges 2 images so they appear beside each other >- * >- * You must dispose this image! >- * @param image1 >- * @param image2 >- * @param result >- * @return >- */ >- public static Image mergeImages(Image image1, Image image2) { >- Image mergedImage = new Image(Display.getDefault(), image1.getBounds().width + image2.getBounds().width, image1.getBounds().height); >- GC gc = new GC(mergedImage); >- gc.drawImage(image1, 0, 0); >- gc.drawImage(image2, image1.getBounds().width, 0); >- gc.dispose(); >- return mergedImage; >- } >- >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("Graph Snippet 4"); >- 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(400, 400); >- >- Graph g = new Graph(shell, SWT.NONE); >- g.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED ); >- GraphNode n1 = new GraphNode(g, SWT.NONE, "Information", image1); >- GraphNode n2 = new GraphNode(g, SWT.NONE, "Warning", image2); >- GraphNode n3 = new GraphNode(g, SWT.NONE, "Error", image3); >- >- GraphConnection connection1 = new GraphConnection(g, SWT.NONE, n1, n2); >- GraphConnection connection2 = new GraphConnection(g, SWT.NONE, n2, n3); >- >- Image information2warningImage = mergeImages(image1, image2); >- Image warning2error = mergeImages(image2, image3); >- IFigure tooltip1 = new Label("Information to Warning", information2warningImage); >- IFigure tooltip2 = new Label("Warning to Error", warning2error); >- connection1.setTooltip(tooltip1); >- connection2.setTooltip(tooltip2); >- >- n1.setLocation(10, 10); >- n2.setLocation(200, 10); >- n3.setLocation(200, 200); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- >- image1.dispose(); >- image2.dispose(); >- image3.dispose(); >- >- information2warningImage.dispose(); >- warning2error.dispose(); >- >- } >-} >Index: src/org/eclipse/zest/tests/swt/GraphSnippet2.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet2.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet2.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet2.java 9 May 2008 20:42:48 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,66 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, Canada. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * The Chisel Group, University of Victoria >- *******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-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.swt.SWT; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-/** >- * This snippet creates a very simple graph with an Icon and Label. >- * >- * This snippet shows how to use directed edges and self loops. >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet2 { >- >- 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(400, 400); >- >- Graph g = new Graph(shell, SWT.NONE); >- g.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); >- GraphNode n1 = new GraphNode(g, SWT.NONE, "Information", image1); >- GraphNode n2 = new GraphNode(g, SWT.NONE, "Warning", image2); >- GraphNode n3 = new GraphNode(g, SWT.NONE, "Error", image3); >- >- new GraphConnection(g, SWT.NONE, n1, n2); >- new GraphConnection(g, SWT.NONE, n2, n3); >- new GraphConnection(g, SWT.NONE, n3, n3); >- >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- image1.dispose(); >- image2.dispose(); >- image3.dispose(); >- } >-} >Index: src/org/eclipse/zest/tests/swt/GraphSnippet5.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet5.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet5.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet5.java 9 May 2008 20:48:40 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,137 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-import java.util.ArrayList; >-import java.util.HashMap; >-import java.util.Iterator; >-import java.util.List; >-import java.util.Map; >- >-import org.eclipse.draw2d.ColorConstants; >-import org.eclipse.zest.core.widgets.Graph; >-import org.eclipse.zest.core.widgets.GraphConnection; >-import org.eclipse.zest.core.widgets.GraphItem; >-import org.eclipse.zest.core.widgets.GraphNode; >-import org.eclipse.zest.core.widgets.ZestStyles; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.KeyAdapter; >-import org.eclipse.swt.events.KeyEvent; >-import org.eclipse.swt.events.PaintEvent; >-import org.eclipse.swt.events.PaintListener; >-import org.eclipse.swt.graphics.Font; >-import org.eclipse.swt.graphics.FontData; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.graphics.Region; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-/** >- * This snippet shows how you can add a paint listener to a Zest graph to paint on top of >- * the widget. This snippet allows you to type and it selects all the nodes that match >- * what you type. >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet5 { >- public static final int BACKSPACE = 8; >- public static final int ENTER = 13; >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- final Map figureListing = new HashMap(); >- final StringBuffer stringBuffer = new StringBuffer(); >- final Display d = new Display(); >- FontData fontData = d.getSystemFont().getFontData()[0]; >- fontData.height = 42; >- >- final Font font = new Font(d, fontData); >- >- Shell shell = new Shell(d); >- shell.setText("Graph Snippet 5"); >- 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(400, 400); >- >- final Graph g = new Graph(shell, SWT.NONE); >- g.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); >- GraphNode n1 = new GraphNode(g, SWT.NONE, "org.eclipse.Information", image1); >- GraphNode n2 = new GraphNode(g, SWT.NONE, "org.eclipse.Warning", image2); >- GraphNode n3 = new GraphNode(g, SWT.NONE, "org.eclipse.Error", image3); >- figureListing.put(n1.getText().toLowerCase(), n1); >- figureListing.put(n2.getText().toLowerCase(), n2); >- figureListing.put(n3.getText().toLowerCase(), n3); >- >- new GraphConnection(g, SWT.NONE, n1, n2); >- new GraphConnection(g, SWT.NONE, n2, n3); >- n1.setLocation(10, 10); >- n2.setLocation(200, 10); >- n3.setLocation(200, 200); >- >- g.addKeyListener(new KeyAdapter() { >- >- public void keyPressed(KeyEvent e) { >- boolean complete = false; >- if (e.keyCode == BACKSPACE) { >- if (stringBuffer.length() > 0) { >- stringBuffer.deleteCharAt(stringBuffer.length() - 1); >- } >- } else if (e.keyCode == ENTER) { >- complete = true; >- } else if ((e.character >= 'a' && e.character <= 'z') || (e.character >= 'A' && e.character <= 'Z') || (e.character == '.') || (e.character >= '0' && e.character <= '9')) { >- stringBuffer.append(e.character); >- } >- Iterator iterator = figureListing.keySet().iterator(); >- List list = new ArrayList(); >- if (stringBuffer.length() > 0) { >- while (iterator.hasNext()) { >- String string = (String) iterator.next(); >- if (string.indexOf(stringBuffer.toString().toLowerCase()) >= 0) { >- list.add(figureListing.get(string)); >- } >- } >- } >- g.setSelection((GraphItem[]) list.toArray(new GraphItem[list.size()])); >- if (complete && stringBuffer.length() > 0) { >- stringBuffer.delete(0, stringBuffer.length()); >- } >- >- g.redraw(); >- } >- >- }); >- >- g.addPaintListener(new PaintListener() { >- public void paintControl(PaintEvent e) { >- e.gc.setFont(font); >- e.gc.setClipping((Region) null); >- e.gc.setForeground(ColorConstants.black); >- e.gc.drawText(stringBuffer.toString(), 50, 50, true); >- } >- }); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- image1.dispose(); >- image2.dispose(); >- image3.dispose(); >- font.dispose(); >- } >-} >Index: src/org/eclipse/zest/tests/swt/GraphSnippet1.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet1.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet1.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet1.java 9 May 2008 20:42:48 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,60 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-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.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-/** >- * This snippet creates a very simple graph where Rock is connected to Paper >- * which is connected to scissors which is connected to rock. >- * >- * The nodes a positioned using a SpringLayout Algorithm, and they can be moved >- * around. >- * >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet1 { >- >- public static void main(String[] args) { >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphSnippet1"); >- shell.setLayout(new FillLayout()); >- shell.setSize(400, 400); >- >- Graph g = new Graph(shell, SWT.NONE); >- >- GraphNode n = new GraphNode(g, SWT.NONE, "Paper"); >- GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock"); >- GraphNode n3 = new GraphNode(g, SWT.NONE, "Scissors"); >- new GraphConnection(g, SWT.NONE, n, n2); >- new GraphConnection(g, SWT.NONE, n2, n3); >- new GraphConnection(g, SWT.NONE, n3, n); >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- } >- >-} >Index: src/org/eclipse/zest/tests/swt/GraphSnippet9.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet9.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet9.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet9.java 12 May 2008 19:03:15 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,54 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-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; >- >-/** >- * This snippet demonstrates a self loop with a label. >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet9 { >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- Display display = new Display(); >- Shell shell = new Shell(display); >- shell.setText("GraphSnippet9"); >- shell.setLayout(new FillLayout()); >- shell.setSize(400, 400); >- >- final Graph graph = new Graph(shell, SWT.NONE); >- >- GraphNode a = new GraphNode(graph, ZestStyles.CONNECTIONS_DIRECTED, "Root"); >- GraphConnection connection = new GraphConnection(graph, SWT.NONE, a, a); >- connection.setText("A to A"); >- a.setLocation(100, 100); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!display.readAndDispatch()) { >- display.sleep(); >- } >- } >- } >- >-} >Index: src/org/eclipse/zest/tests/swt/LayoutExample.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/LayoutExample.java >diff -N src/org/eclipse/zest/tests/swt/LayoutExample.java >--- src/org/eclipse/zest/tests/swt/LayoutExample.java 12 Sep 2007 20:44:36 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,86 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-import org.eclipse.zest.core.widgets.ConstraintAdapter; >-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.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >-import org.eclipse.zest.layouts.constraints.BasicEdgeConstraints; >-import org.eclipse.zest.layouts.constraints.LayoutConstraint; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-/** >- * This snippet shows how to use the findFigureAt to get the figure under the >- * mouse >- * >- * @author Ian Bull >- * >- */ >-public class LayoutExample { >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- // Create the shell >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphSnippet1"); >- shell.setLayout(new FillLayout()); >- shell.setSize(400, 400); >- >- final Graph g = new Graph(shell, SWT.NONE); >- GraphNode root = new GraphNode(g, SWT.NONE, "Root"); >- for (int i = 0; i < 3; i++) { >- GraphNode n = new GraphNode(g, SWT.NONE, "1 - " + i); >- for (int j = 0; j < 3; j++) { >- GraphNode n2 = new GraphNode(g, SWT.NONE, "2 - " + j); >- new GraphConnection(g, SWT.NONE, n, n2); >- } >- new GraphConnection(g, SWT.NONE, root, n); >- } >- >- SpringLayoutAlgorithm springLayoutAlgorithm = new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING); >- >- ConstraintAdapter constraintAdapters = new ConstraintAdapter() { >- >- public void populateConstraint(Object object, LayoutConstraint constraint) { >- if (constraint instanceof BasicEdgeConstraints) { >- BasicEdgeConstraints basicEdgeConstraints = (BasicEdgeConstraints) constraint; >- GraphConnection connection = (GraphConnection) object; >- if (connection.getSource().getText().equals("Root")) { >- basicEdgeConstraints.weight = 1; >- } >- else { >- basicEdgeConstraints.weight = -1; >- } >- } >- >- } >- }; >- >- g.addConstraintAdapter(constraintAdapters); >- g.setLayoutAlgorithm(springLayoutAlgorithm, true); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- } >- >-} >Index: src/org/eclipse/zest/tests/swt/GraphSnippet6.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet6.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet6.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet6.java 9 May 2008 20:48:40 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,71 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, Canada. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * The Chisel Group, University of Victoria >- *******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-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.GridLayoutAlgorithm; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-/** >- * This snippet creates a graph with 80*3 nodes (240 nodes). Only the icons are shown for the nodes, but if >- * you mouse over the node you get the entire text. >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet6 { >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphSnippet6"); >- 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.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); >- for (int i = 0; i < 80; i++) { >- GraphNode n1 = new GraphNode(g, ZestStyles.NODES_HIDE_TEXT | ZestStyles.NODES_FISHEYE, "Information", image1); >- GraphNode n2 = new GraphNode(g, ZestStyles.NODES_HIDE_TEXT | ZestStyles.NODES_FISHEYE, "Warning", image2); >- GraphNode n3 = new GraphNode(g, ZestStyles.NODES_HIDE_TEXT | ZestStyles.NODES_FISHEYE, "Error", image3); >- new GraphConnection(g, SWT.NONE, n1, n2); >- new GraphConnection(g, SWT.NONE, n2, n3); >- new GraphConnection(g, SWT.NONE, n3, n3); >- } >- g.setLayoutAlgorithm(new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- image1.dispose(); >- image2.dispose(); >- image3.dispose(); >- >- } >- >-} >Index: src/org/eclipse/zest/tests/swt/NestedGraphSnippet.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/test/org.eclipse.zest.tests/src/org/eclipse/zest/tests/swt/NestedGraphSnippet.java,v >retrieving revision 1.3 >diff -u -r1.3 NestedGraphSnippet.java >--- src/org/eclipse/zest/tests/swt/NestedGraphSnippet.java 12 Sep 2007 20:44:36 -0000 1.3 >+++ src/org/eclipse/zest/tests/swt/NestedGraphSnippet.java 12 Jul 2009 14:23:45 -0000 >@@ -5,7 +5,9 @@ > * accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * >- * Contributors: The Chisel Group, University of Victoria >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 > ******************************************************************************/ > package org.eclipse.zest.tests.swt; > >@@ -14,102 +16,67 @@ > import org.eclipse.zest.core.widgets.GraphContainer; > import org.eclipse.zest.core.widgets.GraphNode; > import org.eclipse.zest.core.widgets.ZestStyles; >-import org.eclipse.zest.layouts.LayoutAlgorithm; >-import org.eclipse.zest.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.CompositeLayoutAlgorithm; > import org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm; >-import org.eclipse.zest.layouts.algorithms.HorizontalShift; >-import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm; >-import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; >+import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; > import org.eclipse.swt.SWT; >-import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.layout.FillLayout; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; > > public class NestedGraphSnippet { > >- private static Image image1; >- private static Image classImage; >- >- public static void createContainer(Graph g) { >- GraphContainer a = new GraphContainer(g, SWT.NONE, "SomeClass.java", classImage); >- int r = (int) ((Math.random() * 3) + 1); >- r = 2; >- populateContainer(a, g, r, true); >- for (int i = 0; i < 4; i++) { >- GraphContainer b = new GraphContainer(g, SWT.NONE, "SomeNestedClass.java", classImage); >- r = (int) ((Math.random() * 3) + 1); >- r = 2; >- populateContainer(b, g, r, false); >- new GraphConnection(g, SWT.NONE, a, b); >- for (int j = 0; j < 4; j++) { >- GraphContainer c = new GraphContainer(g, SWT.NONE, "DefaultAction.java", classImage); >- r = (int) ((Math.random() * 3) + 1); >- r = 2; >- populateContainer(c, g, r, true); >- new GraphConnection(g, SWT.NONE, b, c); >- } >- } >- } >- >- public static void populateContainer(GraphContainer c, Graph g, int number, boolean radial) { >- GraphNode a = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "SomeClass.java", classImage); >- for (int i = 0; i < 4; i++) { >- GraphNode b = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "SomeNestedClass.java", classImage); >- new GraphConnection(g, SWT.NONE, a, b); >- for (int j = 0; j < 4; j++) { >- GraphNode d = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "DefaultAction.java", classImage); >- new GraphConnection(g, SWT.NONE, b, d); >- if (number > 2) { >- for (int k = 0; k < 4; k++) { >- GraphNode e = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "LastAction(Hero).java", classImage); >- new GraphConnection(g, SWT.NONE, d, e); >- if (number > 3) { >- for (int l = 0; l < 4; l++) { >- GraphNode f = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "LastAction(Hero).java", classImage); >- new GraphConnection(g, SWT.NONE, e, f); >- } >- } >- } >- } >- } >- } >- if (number == 1) { >- c.setScale(0.75); >- } else if (number == 2) { >- c.setScale(0.50); >- } else { >- c.setScale(0.25); >- } >- if (radial) { >- c.setLayoutAlgorithm(new RadialLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- } else { >- c.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- } >- } >- >- /** >- * @param args >- */ > public static void main(String[] args) { > // Create the shell > Display d = new Display(); >- >- image1 = new Image(Display.getDefault(), NestedGraphSnippet.class.getResourceAsStream("package_obj.gif")); >- classImage = new Image(Display.getDefault(), NestedGraphSnippet.class.getResourceAsStream("class_obj.gif")); >- > Shell shell = new Shell(d); > shell.setText("GraphSnippet1"); > shell.setLayout(new FillLayout()); >- shell.setSize(500, 800); >+ shell.setSize(400, 400); > > Graph g = new Graph(shell, SWT.NONE); >- createContainer(g); > >- CompositeLayoutAlgorithm compositeLayoutAlgorithm = new CompositeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING, new LayoutAlgorithm[] { new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), new HorizontalShift(LayoutStyles.NO_LAYOUT_NODE_RESIZING) }); >- //g.setLayoutAlgorithm(new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- g.setLayoutAlgorithm(compositeLayoutAlgorithm, true); >+ /* Machines */ >+ GraphContainer machine1 = new GraphContainer(g, SWT.NONE); >+ machine1.setText("Machine 1 (prop:1)"); >+ GraphContainer machine2 = new GraphContainer(g, SWT.NONE); >+ machine2.setText("Machine 2"); >+ GraphContainer machine3 = new GraphContainer(g, SWT.NONE); >+ machine3.setText("Machine 3"); >+ >+ /* Network */ >+ GraphConnection networkConnection = new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, machine1, machine2); >+ networkConnection.setText("Network (bandwidth:1) "); >+ new GraphConnection(g, SWT.NONE, machine2, machine3); >+ >+ /* Containers */ >+ GraphContainer container1 = new GraphContainer(machine1, SWT.NONE); >+ container1.setText("Host 1"); >+ GraphContainer container2 = new GraphContainer(machine1, SWT.NONE); >+ container2.setText("Host 2"); >+ >+ GraphContainer container3 = new GraphContainer(machine2, SWT.NONE); >+ container3.setText("Host 3"); >+ GraphContainer container4 = new GraphContainer(machine3, SWT.NONE); >+ container4.setText("Host 4"); >+ >+ /* Objects */ >+ GraphNode object1 = new GraphNode(container1, ZestStyles.NODES_FISHEYE, "JSP Object"); >+ GraphNode object2 = new GraphNode(container1, ZestStyles.NODES_FISHEYE, "JSP Object 2"); >+ GraphNode object3 = new GraphNode(container2, ZestStyles.NODES_FISHEYE, "JSP Object 3"); >+ GraphNode object4 = new GraphNode(container3, ZestStyles.NODES_FISHEYE, "JSP Object 4"); >+ GraphNode object5 = new GraphNode(container4, ZestStyles.NODES_FISHEYE, "JSP Object 5"); >+ >+ /* Connections */ >+ new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object1, object2); >+ new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object2, object3); >+ new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object3, object4); >+ new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object4, object5); >+ >+ container1.setLayoutAlgorithm(new GridLayoutAlgorithm(), true); >+ container2.setLayoutAlgorithm(new GridLayoutAlgorithm(), true); >+ container3.setLayoutAlgorithm(new GridLayoutAlgorithm(), true); >+ container3.setLayoutAlgorithm(new GridLayoutAlgorithm(), true); >+ g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); > > shell.open(); > while (!shell.isDisposed()) { >@@ -117,6 +84,5 @@ > d.sleep(); > } > } >- image1.dispose(); > } > } >Index: src/org/eclipse/zest/tests/swt/GraphSnippet11.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/GraphSnippet11.java >diff -N src/org/eclipse/zest/tests/swt/GraphSnippet11.java >--- src/org/eclipse/zest/tests/swt/GraphSnippet11.java 21 Nov 2008 16:43:44 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,69 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.swt; >- >-import org.eclipse.draw2d.ColorConstants; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.graphics.Color; >-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; >- >-/** >- * >- * This snippet shows how to create a curved connection using Zest. >- * >- * @author Ian Bull >- * >- */ >-public class GraphSnippet11 { >- >- >- public static void createConnection( Graph g, GraphNode n1, GraphNode n2, Color color, int curve) { >- GraphConnection connection = new GraphConnection(g, SWT.NONE, n1, n2); >- connection.setLineColor(color); >- connection.setCurveDepth(curve); >- connection.setLineWidth(1); >- } >- >- public static void main(String[] args) { >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphSnippet11"); >- shell.setLayout(new FillLayout()); >- shell.setSize(400, 400); >- >- final Graph g = new Graph(shell, SWT.NONE); >- GraphNode n = new GraphNode(g, SWT.NONE, "Node 1"); >- GraphNode n2 = new GraphNode(g, SWT.NONE, "Node 2"); >- createConnection(g, n, n2, ColorConstants.darkGreen, 20); >- createConnection(g, n, n2, ColorConstants.darkGreen, -20); >- createConnection(g, n, n2, ColorConstants.darkBlue, 40); >- createConnection(g, n, n2, ColorConstants.darkBlue, -40); >- createConnection(g, n, n2, ColorConstants.darkGray, 60); >- createConnection(g, n, n2, ColorConstants.darkGray, -60); >- createConnection(g, n, n2, ColorConstants.black, 0); >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- } >- >-} >Index: src/org/eclipse/zest/tests/swt/HelloWorld.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/test/org.eclipse.zest.tests/src/org/eclipse/zest/tests/swt/HelloWorld.java,v >retrieving revision 1.3 >diff -u -r1.3 HelloWorld.java >--- src/org/eclipse/zest/tests/swt/HelloWorld.java 12 May 2008 18:47:53 -0000 1.3 >+++ src/org/eclipse/zest/tests/swt/HelloWorld.java 12 Jul 2009 14:23:45 -0000 >@@ -1,18 +1,19 @@ > /******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, > * Canada. All rights reserved. This program and the accompanying materials are > * made available under the terms of the Eclipse Public License v1.0 which > * accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * >- * Contributors: The Chisel Group, University of Victoria >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 > ******************************************************************************/ > package org.eclipse.zest.tests.swt; > > 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.layouts.LayoutStyles; > import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; > import org.eclipse.swt.SWT; > import org.eclipse.swt.layout.FillLayout; >@@ -41,7 +42,7 @@ > GraphNode hello = new GraphNode(g, SWT.NONE, "Hello"); > GraphNode world = new GraphNode(g, SWT.NONE, "World"); > new GraphConnection(g, SWT.NONE, hello, world); >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >+ g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); > > shell.open(); > while (!shell.isDisposed()) { >Index: src/org/eclipse/zest/tests/uml/UMLExample.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/test/org.eclipse.zest.tests/src/org/eclipse/zest/tests/uml/UMLExample.java,v >retrieving revision 1.4 >diff -u -r1.4 UMLExample.java >--- src/org/eclipse/zest/tests/uml/UMLExample.java 12 Sep 2007 20:44:36 -0000 1.4 >+++ src/org/eclipse/zest/tests/uml/UMLExample.java 12 Jul 2009 14:23:45 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, Canada. >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, Canada. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,19 +7,20 @@ > * > * Contributors: > * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 > *******************************************************************************/ > package org.eclipse.zest.tests.uml; > > import org.eclipse.draw2d.IFigure; > import org.eclipse.draw2d.Label; >+import org.eclipse.draw2d.geometry.Dimension; > import org.eclipse.zest.core.widgets.Graph; > import org.eclipse.zest.core.widgets.GraphConnection; > import org.eclipse.zest.core.widgets.GraphContainer; > import org.eclipse.zest.core.widgets.GraphNode; >-import org.eclipse.zest.core.widgets.IContainer; > 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 org.eclipse.swt.SWT; > import org.eclipse.swt.graphics.Color; > import org.eclipse.swt.graphics.Font; >@@ -82,13 +83,21 @@ > > IFigure customFigure = null; > >- public UMLNode(IContainer graphModel, int style, IFigure figure) { >+ public UMLNode(Graph graphModel, int style, IFigure figure) { >+ super(graphModel, style, figure); >+ } >+ >+ public UMLNode(GraphContainer graphModel, int style, IFigure figure) { > super(graphModel, style, figure); > } > > protected IFigure createFigureForModel() { > return (IFigure) this.getData(); > } >+ >+ public Dimension getSize() { >+ return ((IFigure) this.getData()).getPreferredSize(); >+ } > > } > >@@ -119,8 +128,8 @@ > new GraphConnection(g, SWT.NONE, n1, n2); > new GraphConnection(g, SWT.NONE, n, n1); > >- c.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >- g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >+ c.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); >+ g.setLayoutAlgorithm(new TreeLayoutAlgorithm(), true); > > shell.open(); > while (!shell.isDisposed()) { >Index: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet3.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet3.java >diff -N src/org/eclipse/zest/tests/jface/GraphJFaceSnippet3.java >--- src/org/eclipse/zest/tests/jface/GraphJFaceSnippet3.java 12 Sep 2007 20:44:36 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,135 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.jface; >- >-import java.io.BufferedReader; >-import java.io.File; >-import java.io.FileReader; >-import java.io.IOException; >-import java.util.ArrayList; >-import java.util.StringTokenizer; >- >-import org.eclipse.jface.viewers.LabelProvider; >-import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.zest.core.viewers.GraphViewer; >-import org.eclipse.zest.core.viewers.IGraphContentProvider; >-import org.eclipse.zest.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.FileDialog; >-import org.eclipse.swt.widgets.Shell; >- >-/** >- * This snippet uses a very simple file format to read a graph. Edges are listed >- * on a new line in a file as such: >- * a calls b >- * b calls c >- * c calld d >- * >- * The content provider creates an edge for each line in the file and names the >- * sources and destination from the line. >- * >- * >- * @author Ian Bull >- * >- */ >-public class GraphJFaceSnippet3 { >- >- public static final String graph = "a calls b\n" + "a calls c\n" + "b calld d\n" + "b calls e\n" + "c calls f\n" + "c calls g\n" + "d calls h\n" + "d calls i\n" + "e calls j\n" + "e calls k\n" + "f calls l\n" + "f calls m\n"; >- >- static class SimpleGraphContentProvider implements IGraphContentProvider { >- >- private StringTokenizer graph; >- >- public Object getDestination(Object rel) { >- String string = (String) rel; >- String[] parts = string.split(" "); >- return parts[2]; >- } >- >- public Object[] getElements(Object input) { >- ArrayList listOfEdges = new ArrayList(); >- while (graph.hasMoreTokens()) { >- listOfEdges.add(graph.nextToken()); >- } >- return listOfEdges.toArray(); >- } >- >- public Object getSource(Object rel) { >- String string = (String) rel; >- String[] parts = string.split(" "); >- return parts[0]; >- } >- >- public double getWeight(Object connection) { >- return 0; >- } >- >- public void dispose() { >- >- } >- >- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >- if (newInput != null) { >- graph = new StringTokenizer((String) newInput, "\n"); >- } >- } >- >- } >- >- public static void main(String[] args) throws IOException { >- Display display = new Display(); >- Shell shell = new Shell(display); >- shell.setText("Simple Graph File Format"); >- >- FileDialog dialog = new FileDialog(shell, SWT.OPEN); >- dialog.setFilterNames(new String[] { "Simple Graph Files (*.sgf)", "All Files (*.*)" }); >- dialog.setFilterExtensions(new String[] { "*.sgf", "*.*" }); //Windows wild cards >- >- String directory = System.getProperty("user.dir") + "/src/org/eclipse/zest/tests/jface/SimpleGraph.sgf"; //eclipse/zest/examples/jface/"; >- System.out.println(directory); >- dialog.setFilterPath(directory); >- //dialog.setFilterPath(System.getProperty("user.dir") + "src/org/eclipse/zest/examples/jface/"); //Windows path >- >- shell.setLayout(new FillLayout(SWT.VERTICAL)); >- shell.setSize(400, 400); >- GraphViewer viewer = null; >- >- viewer = new GraphViewer(shell, SWT.NONE); >- viewer.setContentProvider(new SimpleGraphContentProvider()); >- viewer.setLabelProvider(new LabelProvider()); >- viewer.setLayoutAlgorithm(new RadialLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)); >- >- shell.open(); >- String fileName = dialog.open(); >- >- if (fileName == null) { >- // use the sample graph >- viewer.setInput(graph); >- } else { >- FileReader fileReader = new FileReader(new File(fileName)); >- BufferedReader bufferedReader = new BufferedReader(fileReader); >- StringBuffer stringBuffer = new StringBuffer(); >- while (bufferedReader.ready()) { >- stringBuffer.append(bufferedReader.readLine() + "\n"); >- } >- viewer.setInput(stringBuffer.toString()); >- } >- >- while (!shell.isDisposed()) { >- if (!display.readAndDispatch()) { >- display.sleep(); >- } >- } >- display.dispose(); >- } >-} >Index: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet1.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/test/org.eclipse.zest.tests/src/org/eclipse/zest/tests/jface/GraphJFaceSnippet1.java,v >retrieving revision 1.2 >diff -u -r1.2 GraphJFaceSnippet1.java >--- src/org/eclipse/zest/tests/jface/GraphJFaceSnippet1.java 12 Sep 2007 20:44:36 -0000 1.2 >+++ src/org/eclipse/zest/tests/jface/GraphJFaceSnippet1.java 12 Jul 2009 14:23:44 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, Canada. >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, Canada. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 > *******************************************************************************/ > package org.eclipse.zest.tests.jface; > >@@ -14,7 +15,6 @@ > import org.eclipse.jface.viewers.LabelProvider; > import org.eclipse.jface.viewers.SelectionChangedEvent; > import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.zest.layouts.LayoutStyles; > import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; > import org.eclipse.zest.core.viewers.GraphViewer; > import org.eclipse.zest.core.viewers.IGraphEntityContentProvider; >@@ -113,7 +113,7 @@ > > viewer.setContentProvider(new MyContentProvider()); > viewer.setLabelProvider(new MyLabelProvider()); >- viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)); >+ viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm()); > viewer.addSelectionChangedListener(new ISelectionChangedListener() { > public void selectionChanged(SelectionChangedEvent event) { > System.out.println("Selection changed: " + (event.getSelection())); >Index: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet7.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet7.java >diff -N src/org/eclipse/zest/tests/jface/GraphJFaceSnippet7.java >--- src/org/eclipse/zest/tests/jface/GraphJFaceSnippet7.java 31 Mar 2009 16:43:00 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,182 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.jface; >- >- >-import org.eclipse.draw2d.IFigure; >-import org.eclipse.draw2d.Label; >-import org.eclipse.jface.viewers.LabelProvider; >-import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; >-import org.eclipse.swt.graphics.Font; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Button; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >-import org.eclipse.zest.core.viewers.EntityConnectionData; >-import org.eclipse.zest.core.viewers.GraphViewer; >-import org.eclipse.zest.core.viewers.IFigureProvider; >-import org.eclipse.zest.core.viewers.IGraphEntityContentProvider; >-import org.eclipse.zest.core.viewers.INestedContentProvider; >-import org.eclipse.zest.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >-import org.eclipse.zest.tests.uml.UMLClassFigure; >- >-/** >- * This snippet shows how to use the INestedGraphContentProvider to create a graph >- * with Zest. In this example, getElements returns 3 edges: * Rock2Paper * >- * Paper2Scissors * Scissors2Rock >- * >- * And for each of these, the source and destination are returned in getSource >- * and getDestination. >- * >- * A label provider is also used to create the text and icons for the graph. >- * >- * @author Ian Bull >- * >- */ >-public class GraphJFaceSnippet7 { >- >- public static IFigure createClassFigure1(Font classFont, Image classImage, Image publicField, Image privateField) { >- Label classLabel1 = new Label("Table", classImage); >- classLabel1.setFont(classFont); >- >- UMLClassFigure classFigure = new UMLClassFigure(classLabel1); >- Label attribute1 = new Label("columns: Column[]", privateField); >- >- Label attribute2 = new Label("rows: Row[]", privateField); >- >- Label method1 = new Label("getColumns(): Column[]", publicField); >- Label method2 = new Label("getRows(): Row[]", publicField); >- classFigure.getAttributesCompartment().add(attribute1); >- classFigure.getAttributesCompartment().add(attribute2); >- classFigure.getMethodsCompartment().add(method1); >- classFigure.getMethodsCompartment().add(method2); >- classFigure.setSize(-1, -1); >- >- return classFigure; >- } >- >- static class MyContentProvider implements IGraphEntityContentProvider, INestedContentProvider { >- >- public Object[] getConnectedTo(Object entity) { >- if (entity.equals("First")) { >- return new Object[] { "Second" }; >- } >- if (entity.equals("Second")) { >- return new Object[] { "Third", "rock" }; >- } >- if (entity.equals("Third")) { >- return new Object[] { "First" }; >- } >- if ( entity.equals("rock")) { >- return new Object[] { "paper" }; >- } >- return null; >- } >- >- public Object[] getElements(Object inputElement) { >- return new String[] { "First", "Second", "Third" }; >- } >- >- public double getWeight(Object entity1, Object entity2) { >- return 0; >- } >- >- public void dispose() { >- >- } >- >- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >- >- } >- >- public Object[] getChildren(Object element) { >- // TODO Auto-generated method stub >- return new Object[] {"rock", "paper", "scissors"}; >- } >- >- public boolean hasChildren(Object element) { >- // TODO Auto-generated method stub >- if ( element.equals("First")) return true; >- return false; >- } >- >- } >- >- >- >- static class MyLabelProvider extends LabelProvider implements IFigureProvider { >- final Image image = Display.getDefault().getSystemImage(SWT.ICON_WARNING); >- >- public Image getImage(Object element) { >- if (element.equals("Rock") || element.equals("Paper") || element.equals("Scissors")) { >- return image; >- } >- return null; >- } >- >- public String getText(Object element) { >- if ( element instanceof EntityConnectionData ) return ""; >- return element.toString(); >- } >- >- public IFigure getFigure(Object element) { >- Font classFont = new Font(null, "Arial", 12, SWT.BOLD); >- Image classImage = new Image(Display.getDefault(), UMLClassFigure.class.getResourceAsStream("class_obj.gif")); >- Image privateField = new Image(Display.getDefault(), UMLClassFigure.class.getResourceAsStream("field_private_obj.gif")); >- Image publicField= new Image(Display.getDefault(), UMLClassFigure.class.getResourceAsStream("methpub_obj.gif")); >- return createClassFigure1(classFont, classImage, publicField, privateField); >- } >- >- } >- >- static GraphViewer viewer = null; >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphJFaceSnippet2"); >- shell.setLayout(new FillLayout(SWT.VERTICAL)); >- shell.setSize(400, 400); >- viewer = new GraphViewer(shell, SWT.NONE); >- viewer.setContentProvider(new MyContentProvider()); >- viewer.setLabelProvider(new MyLabelProvider()); >- viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)); >- viewer.setInput(new Object()); >- >- Button button = new Button(shell, SWT.PUSH); >- button.setText("push"); >- button.addSelectionListener(new SelectionListener() { >- >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >- public void widgetSelected(SelectionEvent e) { >- viewer.setInput(new Object()); >- } >- >- }); >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- >- } >- >-} >Index: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet5.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet5.java >diff -N src/org/eclipse/zest/tests/jface/GraphJFaceSnippet5.java >--- src/org/eclipse/zest/tests/jface/GraphJFaceSnippet5.java 12 Sep 2007 20:44:36 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,141 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.jface; >- >-import org.eclipse.jface.viewers.LabelProvider; >-import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >-import org.eclipse.zest.core.viewers.GraphViewer; >-import org.eclipse.zest.core.viewers.IGraphContentProvider; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.SelectionAdapter; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.layout.GridData; >-import org.eclipse.swt.layout.GridLayout; >-import org.eclipse.swt.widgets.Button; >-import org.eclipse.swt.widgets.Composite; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-/** >- * This snippet shows how the refresh works on a Zest viewer. >- */ >-public class GraphJFaceSnippet5 { >- >- static class MyContentProvider implements IGraphContentProvider { >- >- Object[] elements = new Object[] { "Rock2Paper", "Paper2Scissors", "Scissors2Rock" }; >- >- public Object getDestination(Object rel) { >- if ("Rock2Paper".equals(rel)) { >- return "Rock"; >- } else if ("Paper2Scissors".equals(rel) || "Scissors2Paper".equals(rel)) { >- return "Paper"; >- } else if ("Scissors2Rock".equals(rel)) { >- return "Scissors"; >- } >- return null; >- } >- >- public Object[] getElements(Object input) { >- return elements; >- } >- >- public Object getSource(Object rel) { >- if ("Rock2Paper".equals(rel)) { >- return "Paper"; >- } else if ("Paper2Scissors".equals(rel) || "Scissors2Paper".equals(rel)) { >- return "Scissors"; >- } else if ("Scissors2Rock".equals(rel)) { >- return "Rock"; >- } >- return null; >- } >- >- public void setElements(Object[] elements) { >- this.elements = elements; >- } >- >- public double getWeight(Object connection) { >- return 0; >- } >- >- public void dispose() { >- } >- >- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >- } >- >- } >- >- static class MyLabelProvider extends LabelProvider { >- final Image image = Display.getDefault().getSystemImage(SWT.ICON_WARNING); >- >- public MyLabelProvider() { >- >- } >- >- public String getText(Object element) { >- return element.toString(); >- } >- >- public Image getImage(Object element) { >- return image; >- } >- } >- >- static GraphViewer viewer = null; >- private static MyContentProvider contentProvider; >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphJFaceSnippet2"); >- shell.setLayout(new FillLayout(SWT.VERTICAL)); >- shell.setSize(400, 400); >- Composite parent = new Composite(shell, SWT.NONE); >- parent.setLayout(new GridLayout(2, false)); >- buildViewer(parent); >- buildButton(parent); >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- >- } >- >- private static void buildButton(Composite parent) { >- Button button = new Button(parent, SWT.PUSH); >- button.setText("Refresh"); >- button.addSelectionListener(new SelectionAdapter() { >- public void widgetSelected(SelectionEvent e) { >- contentProvider.setElements(new Object[] { "Rock2Paper", "Scissors2Paper", "Scissors2Rock" }); >- viewer.refresh(); >- } >- }); >- } >- >- private static void buildViewer(Composite parent) { >- viewer = new GraphViewer(parent, SWT.NONE); >- viewer.getGraphControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); >- contentProvider = new MyContentProvider(); >- viewer.setContentProvider(contentProvider); >- viewer.setLabelProvider(new MyLabelProvider()); >- viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm()); >- viewer.setInput(new Object()); >- } >-} >Index: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet2.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/test/org.eclipse.zest.tests/src/org/eclipse/zest/tests/jface/GraphJFaceSnippet2.java,v >retrieving revision 1.2 >diff -u -r1.2 GraphJFaceSnippet2.java >--- src/org/eclipse/zest/tests/jface/GraphJFaceSnippet2.java 12 Sep 2007 20:44:36 -0000 1.2 >+++ src/org/eclipse/zest/tests/jface/GraphJFaceSnippet2.java 12 Jul 2009 14:23:44 -0000 >@@ -1,17 +1,18 @@ > /******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, > * Canada. All rights reserved. This program and the accompanying materials are > * made available under the terms of the Eclipse Public License v1.0 which > * accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * >- * Contributors: The Chisel Group, University of Victoria >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 > ******************************************************************************/ > package org.eclipse.zest.tests.jface; > > import org.eclipse.jface.viewers.LabelProvider; > import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.zest.layouts.LayoutStyles; > import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; > import org.eclipse.zest.core.viewers.GraphViewer; > import org.eclipse.zest.core.viewers.IGraphContentProvider; >@@ -107,7 +108,7 @@ > viewer = new GraphViewer(shell, SWT.NONE); > viewer.setContentProvider(new MyContentProvider()); > viewer.setLabelProvider(new MyLabelProvider()); >- viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)); >+ viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm()); > viewer.setInput(new Object()); > shell.open(); > while (!shell.isDisposed()) { >Index: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet4.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet4.java >diff -N src/org/eclipse/zest/tests/jface/GraphJFaceSnippet4.java >--- src/org/eclipse/zest/tests/jface/GraphJFaceSnippet4.java 12 Sep 2007 20:44:36 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,133 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.jface; >- >-import java.util.Iterator; >- >-import org.eclipse.jface.viewers.ISelectionChangedListener; >-import org.eclipse.jface.viewers.LabelProvider; >-import org.eclipse.jface.viewers.SelectionChangedEvent; >-import org.eclipse.jface.viewers.StructuredSelection; >-import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.zest.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >-import org.eclipse.zest.core.viewers.GraphViewer; >-import org.eclipse.zest.core.viewers.IGraphContentProvider; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >- >-public class GraphJFaceSnippet4 { >- static class MyContentProvider implements IGraphContentProvider { >- >- public Object getDestination(Object rel) { >- if ("Rock2Paper".equals(rel)) { >- return "Rock"; >- } else if ("Paper2Scissors".equals(rel)) { >- return "Paper"; >- } else if ("Scissors2Rock".equals(rel)) { >- return "Scissors"; >- } >- return null; >- } >- >- public Object[] getElements(Object input) { >- return new Object[] { "Rock2Paper", "Paper2Scissors", "Scissors2Rock" }; >- } >- >- public Object getSource(Object rel) { >- if ("Rock2Paper".equals(rel)) { >- return "Paper"; >- } else if ("Paper2Scissors".equals(rel)) { >- return "Scissors"; >- } else if ("Scissors2Rock".equals(rel)) { >- return "Rock"; >- } >- return null; >- } >- >- public double getWeight(Object connection) { >- return 0; >- } >- >- public void dispose() { >- } >- >- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >- } >- >- } >- >- static class MyLabelProvider extends LabelProvider { >- final Image image = Display.getDefault().getSystemImage(SWT.ICON_WARNING); >- >- public Image getImage(Object element) { >- if (element.equals("Rock") || element.equals("Paper") || element.equals("Scissors")) { >- return image; >- } >- return null; >- } >- >- public String getText(Object element) { >- return element.toString(); >- } >- >- } >- >- static GraphViewer viewer = null; >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphJFaceSnippet2"); >- shell.setLayout(new FillLayout(SWT.VERTICAL)); >- shell.setSize(400, 400); >- viewer = new GraphViewer(shell, SWT.NONE); >- viewer.setContentProvider(new MyContentProvider()); >- viewer.setLabelProvider(new MyLabelProvider()); >- viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)); >- viewer.setInput(new Object()); >- viewer.addSelectionChangedListener(new ISelectionChangedListener() { >- >- public void selectionChanged(SelectionChangedEvent event) { >- System.out.println("Selection Changed: " + selectionToString((StructuredSelection) event.getSelection())); >- } >- >- private String selectionToString(StructuredSelection selection) { >- StringBuffer stringBuffer = new StringBuffer(); >- Iterator iterator = selection.iterator(); >- boolean first = true; >- while (iterator.hasNext()) { >- if (first) { >- first = false; >- } else { >- stringBuffer.append(" : "); >- } >- stringBuffer.append(iterator.next()); >- } >- return stringBuffer.toString(); >- } >- >- }); >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- >- } >- >-} >Index: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet6.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/jface/GraphJFaceSnippet6.java >diff -N src/org/eclipse/zest/tests/jface/GraphJFaceSnippet6.java >--- src/org/eclipse/zest/tests/jface/GraphJFaceSnippet6.java 20 Nov 2008 00:13:06 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,147 +0,0 @@ >-/******************************************************************************* >- * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >- * Canada. All rights reserved. This program and the accompanying materials are >- * made available under the terms of the Eclipse Public License v1.0 which >- * accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: The Chisel Group, University of Victoria >- ******************************************************************************/ >-package org.eclipse.zest.tests.jface; >- >- >-import org.eclipse.jface.viewers.LabelProvider; >-import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.widgets.Button; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; >-import org.eclipse.zest.core.viewers.EntityConnectionData; >-import org.eclipse.zest.core.viewers.GraphViewer; >-import org.eclipse.zest.core.viewers.IGraphEntityContentProvider; >-import org.eclipse.zest.core.viewers.INestedContentProvider; >-import org.eclipse.zest.layouts.LayoutStyles; >-import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >- >-/** >- * This snippet shows how to use the INestedGraphContentProvider to create a graph >- * with Zest. In this example, getElements returns 3 edges: * Rock2Paper * >- * Paper2Scissors * Scissors2Rock >- * >- * And for each of these, the source and destination are returned in getSource >- * and getDestination. >- * >- * A label provider is also used to create the text and icons for the graph. >- * >- * @author Ian Bull >- * >- */ >-public class GraphJFaceSnippet6 { >- >- static class MyContentProvider implements IGraphEntityContentProvider, INestedContentProvider { >- >- public Object[] getConnectedTo(Object entity) { >- if (entity.equals("First")) { >- return new Object[] { "Second" }; >- } >- if (entity.equals("Second")) { >- return new Object[] { "Third", "rock" }; >- } >- if (entity.equals("Third")) { >- return new Object[] { "First" }; >- } >- if ( entity.equals("rock")) { >- return new Object[] { "paper" }; >- } >- return null; >- } >- >- public Object[] getElements(Object inputElement) { >- return new String[] { "First", "Second", "Third" }; >- } >- >- public double getWeight(Object entity1, Object entity2) { >- return 0; >- } >- >- public void dispose() { >- >- } >- >- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >- >- } >- >- public Object[] getChildren(Object element) { >- // TODO Auto-generated method stub >- return new Object[] {"rock", "paper", "scissors"}; >- } >- >- public boolean hasChildren(Object element) { >- // TODO Auto-generated method stub >- if ( element.equals("First")) return true; >- return false; >- } >- >- } >- >- static class MyLabelProvider extends LabelProvider { >- final Image image = Display.getDefault().getSystemImage(SWT.ICON_WARNING); >- >- public Image getImage(Object element) { >- if (element.equals("Rock") || element.equals("Paper") || element.equals("Scissors")) { >- return image; >- } >- return null; >- } >- >- public String getText(Object element) { >- if ( element instanceof EntityConnectionData ) return ""; >- return element.toString(); >- } >- >- } >- >- static GraphViewer viewer = null; >- >- /** >- * @param args >- */ >- public static void main(String[] args) { >- Display d = new Display(); >- Shell shell = new Shell(d); >- shell.setText("GraphJFaceSnippet2"); >- shell.setLayout(new FillLayout(SWT.VERTICAL)); >- shell.setSize(400, 400); >- viewer = new GraphViewer(shell, SWT.NONE); >- viewer.setContentProvider(new MyContentProvider()); >- viewer.setLabelProvider(new MyLabelProvider()); >- viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)); >- viewer.setInput(new Object()); >- >- Button button = new Button(shell, SWT.PUSH); >- button.setText("push"); >- button.addSelectionListener(new SelectionListener() { >- >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >- public void widgetSelected(SelectionEvent e) { >- viewer.setInput(new Object()); >- } >- >- }); >- shell.open(); >- while (!shell.isDisposed()) { >- while (!d.readAndDispatch()) { >- d.sleep(); >- } >- } >- >- } >- >-} >Index: src/org/eclipse/zest/tests/swt/TreeLayoutExample.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/TreeLayoutExample.java >diff -N src/org/eclipse/zest/tests/swt/TreeLayoutExample.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/TreeLayoutExample.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,106 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Mateusz Matela and others. All rights reserved. This >+ * program and the accompanying materials are made available under the terms of >+ * the Eclipse Public License v1.0 which accompanies this distribution, and is >+ * available at http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ *******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+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.layouts.algorithms.TreeLayoutAlgorithm; >+ >+/** >+ * This example shows the effects of TreeLayoutAlgorithm with different >+ * directions. >+ */ >+public class TreeLayoutExample { >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ // Create the shell >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet1"); >+ GridLayout gridLayout = new GridLayout(); >+ gridLayout.numColumns = 10; >+ shell.setLayout(gridLayout); >+ shell.setSize(500, 500); >+ >+ final Graph g = new Graph(shell, SWT.NONE); >+ g.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 10, 10)); >+ g.setSize(500, 500); >+ GraphNode root = new GraphNode(g, SWT.NONE, "Root"); >+ for (int i = 0; i < 3; i++) { >+ GraphNode n = new GraphNode(g, SWT.NONE, "1 - " + i); >+ for (int j = 0; j < 3; j++) { >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "2 - " + j); >+ new GraphConnection(g, SWT.NONE, n, n2).setWeight(-1); >+ } >+ new GraphConnection(g, SWT.NONE, root, n); >+ } >+ >+ final TreeLayoutAlgorithm algorithm = new TreeLayoutAlgorithm(); >+ g.setLayoutAlgorithm(algorithm, false); >+ >+ final Button buttonTopDown = new Button(shell, SWT.FLAT); >+ buttonTopDown.setText("TOP_DOWN"); >+ >+ final Button buttonBottomUp = new Button(shell, SWT.FLAT); >+ buttonBottomUp.setText("BOTTOM_UP"); >+ buttonBottomUp.setLayoutData(new GridData()); >+ >+ final Button buttonLeftRight = new Button(shell, SWT.FLAT); >+ buttonLeftRight.setText("LEFT_RIGHT"); >+ >+ final Button buttonRightLeft = new Button(shell, SWT.FLAT); >+ buttonRightLeft.setText("RIGHT_LEFT"); >+ >+ SelectionAdapter buttonListener = new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ if (e.widget == buttonTopDown) >+ algorithm.setDirection(TreeLayoutAlgorithm.TOP_DOWN); >+ if (e.widget == buttonBottomUp) >+ algorithm.setDirection(TreeLayoutAlgorithm.BOTTOM_UP); >+ if (e.widget == buttonLeftRight) >+ algorithm.setDirection(TreeLayoutAlgorithm.LEFT_RIGHT); >+ if (e.widget == buttonRightLeft) >+ algorithm.setDirection(TreeLayoutAlgorithm.RIGHT_LEFT); >+ >+ g.applyLayout(); >+ } >+ }; >+ buttonTopDown.addSelectionListener(buttonListener); >+ buttonBottomUp.addSelectionListener(buttonListener); >+ buttonLeftRight.addSelectionListener(buttonListener); >+ buttonRightLeft.addSelectionListener(buttonListener); >+ >+ final Button resizeButton = new Button(shell, SWT.CHECK); >+ resizeButton.setText("Resize"); >+ resizeButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ algorithm.setResizing(resizeButton.getSelection()); >+ } >+ }); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ } >+} >Index: src/org/eclipse/zest/tests/swt/IconsGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/IconsGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/IconsGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/IconsGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,66 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, Canada. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ *******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+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.algorithms.SpringLayoutAlgorithm; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * This snippet creates a very simple graph with an Icon and Label. >+ * >+ * This snippet shows how to use directed edges and self loops. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class IconsGraphSnippet { >+ >+ 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(400, 400); >+ >+ Graph g = new Graph(shell, SWT.NONE); >+ g.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); >+ GraphNode n1 = new GraphNode(g, SWT.NONE, "Information", image1); >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "Warning", image2); >+ GraphNode n3 = new GraphNode(g, SWT.NONE, "Error", image3); >+ >+ new GraphConnection(g, SWT.NONE, n1, n2); >+ new GraphConnection(g, SWT.NONE, n2, n3); >+ new GraphConnection(g, SWT.NONE, n3, n3); >+ >+ g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ image1.dispose(); >+ image2.dispose(); >+ image3.dispose(); >+ } >+} >Index: src/org/eclipse/zest/tests/swt/SimpleGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/SimpleGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/SimpleGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/SimpleGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,61 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+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.layouts.algorithms.SpringLayoutAlgorithm; >+ >+/** >+ * This snippet creates a very simple graph where Rock is connected to Paper >+ * which is connected to scissors which is connected to rock. >+ * >+ * The nodes a positioned using a SpringLayout Algorithm, and they can be moved >+ * around. >+ * >+ * >+ * @author Ian Bull >+ * >+ */ >+public class SimpleGraphSnippet { >+ >+ public static void main(String[] args) { >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet1"); >+ shell.setLayout(new FillLayout()); >+ shell.setSize(400, 400); >+ >+ Graph g = new Graph(shell, SWT.NONE); >+ >+ GraphNode n = new GraphNode(g, SWT.NONE, "Paper"); >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock"); >+ GraphNode n3 = new GraphNode(g, SWT.NONE, "Scissors"); >+ new GraphConnection(g, SWT.NONE, n, n2); >+ new GraphConnection(g, SWT.NONE, n2, n3); >+ //new GraphConnection(g, SWT.NONE, n3, n); >+ g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ } >+ >+} >Index: src/org/eclipse/zest/tests/swt/FindFigureGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/FindFigureGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/FindFigureGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/FindFigureGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,72 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+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.layouts.algorithms.SpringLayoutAlgorithm; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.MouseEvent; >+import org.eclipse.swt.events.MouseMoveListener; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * This snippet shows how to use the findFigureAt to get the figure under the mouse >+ * >+ * @author Ian Bull >+ * >+ */ >+public class FindFigureGraphSnippet { >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet7"); >+ shell.setLayout(new FillLayout()); >+ shell.setSize(400, 400); >+ >+ final Graph g = new Graph(shell, SWT.NONE); >+ >+ GraphNode n = new GraphNode(g, SWT.NONE, "Paper"); >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock"); >+ GraphNode n3 = new GraphNode(g, SWT.NONE, "Scissors"); >+ new GraphConnection(g, SWT.NONE, n, n2); >+ new GraphConnection(g, SWT.NONE, n2, n3); >+ new GraphConnection(g, SWT.NONE, n3, n); >+ g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); >+ >+ g.addMouseMoveListener(new MouseMoveListener() { >+ >+ public void mouseMove(MouseEvent e) { >+ // Get the figure at the current mouse location >+ Object o = g.getFigureAt(e.x, e.y); >+ if ( o != null ) { >+ System.out.println(o + " is at: (" + e.x + "," + e.y + ")"); >+ } >+ } >+ >+ }); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ } >+} >Index: src/org/eclipse/zest/tests/swt/FisheyeGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/FisheyeGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/FisheyeGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/FisheyeGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,71 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, Canada. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ *******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Image; >+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.algorithms.GridLayoutAlgorithm; >+ >+/** >+ * This snippet creates a graph with 80*3 nodes (240 nodes). Only the icons are shown for the nodes, but if >+ * you mouse over the node you get the entire text. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class FisheyeGraphSnippet { >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet6"); >+ 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.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); >+ for (int i = 0; i < 80; i++) { >+ GraphNode n1 = new GraphNode(g, ZestStyles.NODES_HIDE_TEXT | ZestStyles.NODES_FISHEYE, "Information", image1); >+ GraphNode n2 = new GraphNode(g, ZestStyles.NODES_HIDE_TEXT | ZestStyles.NODES_FISHEYE, "Warning", image2); >+ GraphNode n3 = new GraphNode(g, ZestStyles.NODES_HIDE_TEXT | ZestStyles.NODES_FISHEYE, "Error", image3); >+ new GraphConnection(g, SWT.NONE, n1, n2); >+ new GraphConnection(g, SWT.NONE, n2, n3); >+ new GraphConnection(g, SWT.NONE, n3, n3); >+ } >+ g.setLayoutAlgorithm(new GridLayoutAlgorithm(), true); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ image1.dispose(); >+ image2.dispose(); >+ image3.dispose(); >+ >+ } >+ >+} >Index: src/org/eclipse/zest/tests/swt/CustomFigureGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/CustomFigureGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/CustomFigureGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/CustomFigureGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,165 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+import java.util.Iterator; >+ >+import org.eclipse.draw2d.ColorConstants; >+import org.eclipse.draw2d.Ellipse; >+import org.eclipse.draw2d.Figure; >+import org.eclipse.draw2d.FreeformLayout; >+import org.eclipse.draw2d.IFigure; >+import org.eclipse.draw2d.ImageFigure; >+import org.eclipse.draw2d.PolylineShape; >+import org.eclipse.draw2d.geometry.Point; >+import org.eclipse.draw2d.geometry.Rectangle; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.zest.core.widgets.CGraphNode; >+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.layouts.algorithms.SpringLayoutAlgorithm; >+ >+/** >+ * >+ * This snippet shows how to create a graph with custom figures as nodes. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class CustomFigureGraphSnippet { >+ >+ public static IFigure createPersonFigure(Image headImage) { >+ Figure person = new Figure(); >+ person.setLayoutManager(new FreeformLayout()); >+ IFigure head = null; >+ if ( headImage != null ) { >+ headImage = new Image(headImage.getDevice(), headImage.getImageData().scaledTo(40, 50)); >+ head = new ImageFigure(headImage); >+ } >+ else >+ head = new Ellipse(); >+ head.setSize(40, 50); >+ >+ PolylineShape body = new PolylineShape(); >+ body.setLineWidth(1); >+ body.setStart(new Point(20,40)); >+ body.setEnd(new Point(20,100)); >+ body.setBounds(new Rectangle(0,0,40,100)); >+ >+ PolylineShape leftLeg = new PolylineShape(); >+ leftLeg.setLineWidth(1); >+ leftLeg.setStart(new Point(20,100)); >+ leftLeg.setEnd(new Point(0,130)); >+ leftLeg.setBounds(new Rectangle(0,0,40,130)); >+ >+ PolylineShape rightLeg = new PolylineShape(); >+ rightLeg.setLineWidth(1); >+ rightLeg.setStart(new Point(20,100)); >+ rightLeg.setEnd(new Point(40,130)); >+ rightLeg.setBounds(new Rectangle(0,0,40,130)); >+ >+ PolylineShape leftArm = new PolylineShape(); >+ leftArm.setLineWidth(1); >+ leftArm.setStart(new Point(20,60)); >+ leftArm.setEnd(new Point(0,50)); >+ leftArm.setBounds(new Rectangle(0,0,40,130)); >+ >+ PolylineShape rightArm = new PolylineShape(); >+ rightArm.setLineWidth(1); >+ rightArm.setStart(new Point(20,60)); >+ rightArm.setEnd(new Point(40,50)); >+ rightArm.setBounds(new Rectangle(0,0,40,130)); >+ >+ person.add(head); >+ person.add(body); >+ person.add(leftLeg); >+ person.add(rightLeg); >+ person.add(leftArm); >+ person.add(rightArm); >+ person.setSize(40,130); >+ return person; >+ } >+ >+ public static void main(String[] args) { >+ final Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet11"); >+ shell.setLayout(new FillLayout()); >+ shell.setSize(400, 400); >+ >+ >+ final Graph g = new Graph(shell, SWT.NONE); >+ g.addSelectionListener(new SelectionListener(){ >+ >+ public void widgetSelected(SelectionEvent e) { >+ Iterator iter = g.getSelection().iterator(); >+ while(iter.hasNext()) { >+ Object o = iter.next(); >+ if ( o instanceof CGraphNode) { >+ IFigure figure = ((CGraphNode)o).getFigure(); >+ figure.setBackgroundColor(ColorConstants.blue); >+ figure.setForegroundColor(ColorConstants.blue); >+ } >+ } >+ iter = g.getNodes().iterator(); >+ while ( iter.hasNext()) { >+ Object o = iter.next(); >+ if ( o instanceof CGraphNode) { >+ if ( !g.getSelection().contains(o)) { >+ ((CGraphNode)o).getFigure().setBackgroundColor(ColorConstants.black); >+ ((CGraphNode)o).getFigure().setForegroundColor(ColorConstants.black); >+ } >+ } >+ } >+ } >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ // TODO Auto-generated method stub >+ >+ } >+ }); >+ >+ Image zx = new Image(d, "zx.png"); >+ Image ibull = new Image(d, "ibull.jpg"); >+ CGraphNode n = new CGraphNode(g, SWT.NONE, createPersonFigure(zx)); >+ CGraphNode n2 = new CGraphNode(g, SWT.NONE, createPersonFigure(ibull)); >+ GraphNode n3 = new GraphNode(g, SWT.NONE, "PDE"); >+ GraphNode n4 = new GraphNode(g, SWT.NONE, "Zest"); >+ GraphNode n5 = new GraphNode(g, SWT.NONE, "PDE Viz tool"); >+ >+ new GraphConnection(g, SWT.NONE, n, n2); >+ new GraphConnection(g, SWT.NONE, n, n3); >+ new GraphConnection(g, SWT.NONE, n2, n4); >+ new GraphConnection(g, SWT.NONE, n, n5); >+ new GraphConnection(g, SWT.NONE, n2, n5); >+ new GraphConnection(g, SWT.NONE, n3, n5); >+ new GraphConnection(g, SWT.NONE, n4, n5); >+ g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ zx.dispose(); >+ ibull.dispose(); >+ } >+ >+} >Index: src/org/eclipse/zest/tests/swt/CurvedEdgeGraphSnippet2.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/CurvedEdgeGraphSnippet2.java >diff -N src/org/eclipse/zest/tests/swt/CurvedEdgeGraphSnippet2.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/CurvedEdgeGraphSnippet2.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,69 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+import org.eclipse.draw2d.ColorConstants; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Color; >+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.layouts.algorithms.SpringLayoutAlgorithm; >+ >+/** >+ * >+ * This snippet shows how to create a curved connection using Zest. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class CurvedEdgeGraphSnippet2 { >+ >+ >+ public static void createConnection( Graph g, GraphNode n1, GraphNode n2, Color color, int curve) { >+ GraphConnection connection = new GraphConnection(g, SWT.NONE, n1, n2); >+ connection.setLineColor(color); >+ connection.setCurveDepth(curve); >+ connection.setLineWidth(1); >+ } >+ >+ public static void main(String[] args) { >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet11"); >+ shell.setLayout(new FillLayout()); >+ shell.setSize(400, 400); >+ >+ final Graph g = new Graph(shell, SWT.NONE); >+ GraphNode n = new GraphNode(g, SWT.NONE, "Node 1"); >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "Node 2"); >+ createConnection(g, n, n2, ColorConstants.darkGreen, 20); >+ createConnection(g, n, n2, ColorConstants.darkGreen, -20); >+ createConnection(g, n, n2, ColorConstants.darkBlue, 40); >+ createConnection(g, n, n2, ColorConstants.darkBlue, -40); >+ createConnection(g, n, n2, ColorConstants.darkGray, 60); >+ createConnection(g, n, n2, ColorConstants.darkGray, -60); >+ createConnection(g, n, n2, ColorConstants.black, 0); >+ g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ } >+ >+} >Index: src/org/eclipse/zest/tests/swt/CustomPaintingGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/CustomPaintingGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/CustomPaintingGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/CustomPaintingGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,139 @@ >+/******************************************************************************* >+ * Copyright 2005-2007, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+import java.util.ArrayList; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.List; >+import java.util.Map; >+ >+import org.eclipse.draw2d.ColorConstants; >+import org.eclipse.zest.core.widgets.Graph; >+import org.eclipse.zest.core.widgets.GraphConnection; >+import org.eclipse.zest.core.widgets.GraphItem; >+import org.eclipse.zest.core.widgets.GraphNode; >+import org.eclipse.zest.core.widgets.ZestStyles; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.KeyAdapter; >+import org.eclipse.swt.events.KeyEvent; >+import org.eclipse.swt.events.PaintEvent; >+import org.eclipse.swt.events.PaintListener; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.FontData; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Region; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * This snippet shows how you can add a paint listener to a Zest graph to paint on top of >+ * the widget. This snippet allows you to type and it selects all the nodes that match >+ * what you type. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class CustomPaintingGraphSnippet { >+ public static final int BACKSPACE = 8; >+ public static final int ENTER = 13; >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ final Map figureListing = new HashMap(); >+ final StringBuffer stringBuffer = new StringBuffer(); >+ final Display d = new Display(); >+ FontData fontData = d.getSystemFont().getFontData()[0]; >+ fontData.height = 42; >+ >+ final Font font = new Font(d, fontData); >+ >+ Shell shell = new Shell(d); >+ shell.setText("Graph Snippet 5"); >+ 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(400, 400); >+ >+ final Graph g = new Graph(shell, SWT.NONE); >+ g.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); >+ GraphNode n1 = new GraphNode(g, SWT.NONE, "org.eclipse.Information", image1); >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "org.eclipse.Warning", image2); >+ GraphNode n3 = new GraphNode(g, SWT.NONE, "org.eclipse.Error", image3); >+ figureListing.put(n1.getText().toLowerCase(), n1); >+ figureListing.put(n2.getText().toLowerCase(), n2); >+ figureListing.put(n3.getText().toLowerCase(), n3); >+ >+ new GraphConnection(g, SWT.NONE, n1, n2); >+ new GraphConnection(g, SWT.NONE, n2, n3); >+ n1.setLocation(10, 10); >+ n2.setLocation(200, 10); >+ n3.setLocation(200, 200); >+ >+ g.addKeyListener(new KeyAdapter() { >+ >+ public void keyPressed(KeyEvent e) { >+ boolean complete = false; >+ if (e.keyCode == BACKSPACE) { >+ if (stringBuffer.length() > 0) { >+ stringBuffer.deleteCharAt(stringBuffer.length() - 1); >+ } >+ } else if (e.keyCode == ENTER) { >+ complete = true; >+ } else if ((e.character >= 'a' && e.character <= 'z') || (e.character >= 'A' && e.character <= 'Z') || (e.character == '.') || (e.character >= '0' && e.character <= '9')) { >+ stringBuffer.append(e.character); >+ } >+ Iterator iterator = figureListing.keySet().iterator(); >+ List list = new ArrayList(); >+ if (stringBuffer.length() > 0) { >+ while (iterator.hasNext()) { >+ String string = (String) iterator.next(); >+ if (string.indexOf(stringBuffer.toString().toLowerCase()) >= 0) { >+ list.add(figureListing.get(string)); >+ } >+ } >+ } >+ g.setSelection((GraphItem[]) list.toArray(new GraphItem[list.size()])); >+ if (complete && stringBuffer.length() > 0) { >+ stringBuffer.delete(0, stringBuffer.length()); >+ } >+ >+ g.redraw(); >+ } >+ >+ }); >+ >+ g.addPaintListener(new PaintListener() { >+ public void paintControl(PaintEvent e) { >+ e.gc.setFont(font); >+ e.gc.setClipping((Region) null); >+ e.gc.setForeground(ColorConstants.black); >+ e.gc.drawText(stringBuffer.toString(), 50, 50, true); >+ } >+ }); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ image1.dispose(); >+ image2.dispose(); >+ image3.dispose(); >+ font.dispose(); >+ } >+} >Index: src/org/eclipse/zest/tests/swt/ContainerResizeGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/ContainerResizeGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/ContainerResizeGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/ContainerResizeGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,152 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.KeyEvent; >+import org.eclipse.swt.events.KeyListener; >+import org.eclipse.swt.graphics.Image; >+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.GraphContainer; >+import org.eclipse.zest.core.widgets.GraphItem; >+import org.eclipse.zest.core.widgets.GraphNode; >+import org.eclipse.zest.core.widgets.ZestStyles; >+import org.eclipse.zest.layouts.LayoutAlgorithm; >+import org.eclipse.zest.layouts.algorithms.CompositeLayoutAlgorithm; >+import org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm; >+import org.eclipse.zest.layouts.algorithms.HorizontalShiftAlgorithm; >+import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm; >+import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; >+ >+public class ContainerResizeGraphSnippet { >+ >+ private static Image image1; >+ private static Image classImage; >+ >+ public static void createContainer(Graph g) { >+ GraphContainer a = new GraphContainer(g, SWT.NONE, "SomeClass.java", classImage); >+ int r = (int) ((Math.random() * 3) + 1); >+ r = 2; >+ populateContainer(a, g, r, true); >+ for (int i = 0; i < 4; i++) { >+ GraphContainer b = new GraphContainer(g, SWT.NONE, "SomeNestedClass.java", classImage); >+ r = (int) ((Math.random() * 3) + 1); >+ r = 2; >+ populateContainer(b, g, r, false); >+ new GraphConnection(g, SWT.NONE, a, b); >+ for (int j = 0; j < 4; j++) { >+ GraphContainer c = new GraphContainer(g, SWT.NONE, "DefaultAction.java", classImage); >+ r = (int) ((Math.random() * 3) + 1); >+ r = 2; >+ populateContainer(c, g, r, true); >+ new GraphConnection(g, SWT.NONE, b, c); >+ } >+ } >+ } >+ >+ public static void populateContainer(GraphContainer c, Graph g, int number, boolean radial) { >+ GraphNode a = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "SomeClass.java", classImage); >+ for (int i = 0; i < 4; i++) { >+ GraphNode b = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "SomeNestedClass.java", classImage); >+ new GraphConnection(g, SWT.NONE, a, b); >+ for (int j = 0; j < 4; j++) { >+ GraphNode d = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "DefaultAction.java", classImage); >+ new GraphConnection(g, SWT.NONE, b, d); >+ if (number > 2) { >+ for (int k = 0; k < 4; k++) { >+ GraphNode e = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "LastAction(Hero).java", classImage); >+ new GraphConnection(g, SWT.NONE, d, e); >+ if (number > 3) { >+ for (int l = 0; l < 4; l++) { >+ GraphNode f = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "LastAction(Hero).java", classImage); >+ new GraphConnection(g, SWT.NONE, e, f); >+ } >+ } >+ } >+ } >+ } >+ } >+ if (number == 1) { >+ c.setScale(0.75); >+ } else if (number == 2) { >+ c.setScale(0.50); >+ } else { >+ c.setScale(0.25); >+ } >+ if (radial) { >+ c.setLayoutAlgorithm(new RadialLayoutAlgorithm(), true); >+ } else { >+ c.setLayoutAlgorithm(new TreeLayoutAlgorithm(), true); >+ } >+ } >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ // Create the shell >+ Display d = new Display(); >+ >+ image1 = new Image(Display.getDefault(), ContainerResizeGraphSnippet.class.getResourceAsStream("package_obj.gif")); >+ classImage = new Image(Display.getDefault(), ContainerResizeGraphSnippet.class.getResourceAsStream("class_obj.gif")); >+ >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet1"); >+ shell.setLayout(new FillLayout()); >+ shell.setSize(500, 800); >+ >+ final Graph g = new Graph(shell, SWT.NONE); >+ createContainer(g); >+ >+ CompositeLayoutAlgorithm compositeLayoutAlgorithm = new CompositeLayoutAlgorithm(new LayoutAlgorithm[] { new GridLayoutAlgorithm(), new HorizontalShiftAlgorithm() }); >+ //g.setLayoutAlgorithm(new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); >+ g.setLayoutAlgorithm(compositeLayoutAlgorithm, true); >+ >+ g.addKeyListener(new KeyListener() { >+ boolean flip = true; >+ >+ public void keyPressed(KeyEvent e) { >+ >+ if (g.getSelection().size() == 1) { >+ GraphNode item = (GraphNode) g.getSelection().get(0); >+ if (item.getItemType() == GraphItem.CONTAINER) { >+ if (flip) { >+ (item).setSize(500, 100); >+ } else { >+ (item).setSize(0, 0); >+ } >+ flip = !flip; >+ } >+ } >+ >+ } >+ >+ public void keyReleased(KeyEvent e) { >+ // TODO Auto-generated method stub >+ >+ } >+ >+ }); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ image1.dispose(); >+ } >+} >Index: src/org/eclipse/zest/tests/swt/ToolTipGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/ToolTipGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/ToolTipGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/ToolTipGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,104 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, Canada. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ *******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+import org.eclipse.draw2d.IFigure; >+import org.eclipse.draw2d.Label; >+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.swt.SWT; >+import org.eclipse.swt.graphics.GC; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * This snippet shows how a custom figure can be used as a ToolTip for connections. >+ * Let your mouse hover over an edge to see the custom tooltip. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class ToolTipGraphSnippet { >+ >+ >+ /** >+ * Merges 2 images so they appear beside each other >+ * >+ * You must dispose this image! >+ * @param image1 >+ * @param image2 >+ * @param result >+ * @return >+ */ >+ public static Image mergeImages(Image image1, Image image2) { >+ Image mergedImage = new Image(Display.getDefault(), image1.getBounds().width + image2.getBounds().width, image1.getBounds().height); >+ GC gc = new GC(mergedImage); >+ gc.drawImage(image1, 0, 0); >+ gc.drawImage(image2, image1.getBounds().width, 0); >+ gc.dispose(); >+ return mergedImage; >+ } >+ >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("Graph Snippet 4"); >+ 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(400, 400); >+ >+ Graph g = new Graph(shell, SWT.NONE); >+ g.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED ); >+ GraphNode n1 = new GraphNode(g, SWT.NONE, "Information", image1); >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "Warning", image2); >+ GraphNode n3 = new GraphNode(g, SWT.NONE, "Error", image3); >+ >+ GraphConnection connection1 = new GraphConnection(g, SWT.NONE, n1, n2); >+ GraphConnection connection2 = new GraphConnection(g, SWT.NONE, n2, n3); >+ >+ Image information2warningImage = mergeImages(image1, image2); >+ Image warning2error = mergeImages(image2, image3); >+ IFigure tooltip1 = new Label("Information to Warning", information2warningImage); >+ IFigure tooltip2 = new Label("Warning to Error", warning2error); >+ connection1.setTooltip(tooltip1); >+ connection2.setTooltip(tooltip2); >+ >+ n1.setLocation(10, 10); >+ n2.setLocation(200, 10); >+ n3.setLocation(200, 200); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ >+ image1.dispose(); >+ image2.dispose(); >+ image3.dispose(); >+ >+ information2warningImage.dispose(); >+ warning2error.dispose(); >+ >+ } >+} >Index: src/org/eclipse/zest/tests/jface/NestedGraphJFaceSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/jface/NestedGraphJFaceSnippet.java >diff -N src/org/eclipse/zest/tests/jface/NestedGraphJFaceSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/jface/NestedGraphJFaceSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,148 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.jface; >+ >+ >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.zest.core.viewers.EntityConnectionData; >+import org.eclipse.zest.core.viewers.GraphViewer; >+import org.eclipse.zest.core.viewers.IGraphEntityContentProvider; >+import org.eclipse.zest.core.viewers.INestedContentProvider; >+import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >+ >+/** >+ * This snippet shows how to use the INestedGraphContentProvider to create a graph >+ * with Zest. In this example, getElements returns 3 edges: * Rock2Paper * >+ * Paper2Scissors * Scissors2Rock >+ * >+ * And for each of these, the source and destination are returned in getSource >+ * and getDestination. >+ * >+ * A label provider is also used to create the text and icons for the graph. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class NestedGraphJFaceSnippet { >+ >+ static class MyContentProvider implements IGraphEntityContentProvider, INestedContentProvider { >+ >+ public Object[] getConnectedTo(Object entity) { >+ if (entity.equals("First")) { >+ return new Object[] { "Second" }; >+ } >+ if (entity.equals("Second")) { >+ return new Object[] { "Third", "rock" }; >+ } >+ if (entity.equals("Third")) { >+ return new Object[] { "First" }; >+ } >+ if ( entity.equals("rock")) { >+ return new Object[] { "paper" }; >+ } >+ return null; >+ } >+ >+ public Object[] getElements(Object inputElement) { >+ return new String[] { "First", "Second", "Third" }; >+ } >+ >+ public double getWeight(Object entity1, Object entity2) { >+ return 0; >+ } >+ >+ public void dispose() { >+ >+ } >+ >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ >+ } >+ >+ public Object[] getChildren(Object element) { >+ // TODO Auto-generated method stub >+ return new Object[] {"rock", "paper", "scissors"}; >+ } >+ >+ public boolean hasChildren(Object element) { >+ // TODO Auto-generated method stub >+ if ( element.equals("First")) return true; >+ return false; >+ } >+ >+ } >+ >+ static class MyLabelProvider extends LabelProvider { >+ final Image image = Display.getDefault().getSystemImage(SWT.ICON_WARNING); >+ >+ public Image getImage(Object element) { >+ if (element.equals("Rock") || element.equals("Paper") || element.equals("Scissors")) { >+ return image; >+ } >+ return null; >+ } >+ >+ public String getText(Object element) { >+ if ( element instanceof EntityConnectionData ) return ""; >+ return element.toString(); >+ } >+ >+ } >+ >+ static GraphViewer viewer = null; >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphJFaceSnippet2"); >+ shell.setLayout(new FillLayout(SWT.VERTICAL)); >+ shell.setSize(400, 400); >+ viewer = new GraphViewer(shell, SWT.NONE); >+ viewer.setContentProvider(new MyContentProvider()); >+ viewer.setLabelProvider(new MyLabelProvider()); >+ viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm()); >+ viewer.setInput(new Object()); >+ >+ Button button = new Button(shell, SWT.PUSH); >+ button.setText("push"); >+ button.addSelectionListener(new SelectionListener() { >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ } >+ >+ public void widgetSelected(SelectionEvent e) { >+ viewer.setInput(new Object()); >+ } >+ >+ }); >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ >+ } >+ >+} >Index: src/org/eclipse/zest/tests/swt/FilterGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/FilterGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/FilterGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/FilterGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,117 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+import org.eclipse.draw2d.ColorConstants; >+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.GraphItem; >+import org.eclipse.zest.core.widgets.GraphNode; >+import org.eclipse.zest.core.widgets.LayoutFilter; >+import org.eclipse.zest.core.widgets.ZestStyles; >+import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; >+ >+/** >+ * This snippet shows how to filter elements in the layout. The Data on the tree >+ * connections are set to "False", meaning they won't be filtered. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class FilterGraphSnippet { >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ Display display = new Display(); >+ Shell shell = new Shell(display); >+ shell.setText("GraphSnippet8"); >+ shell.setLayout(new FillLayout()); >+ shell.setSize(400, 400); >+ >+ final Graph graph = new Graph(shell, SWT.NONE); >+ >+ GraphNode a = new GraphNode(graph, SWT.NONE, "Root"); >+ GraphNode b = new GraphNode(graph, SWT.NONE, "B"); >+ GraphNode c = new GraphNode(graph, SWT.NONE, "C"); >+ GraphNode d = new GraphNode(graph, SWT.NONE, "D"); >+ GraphNode e = new GraphNode(graph, SWT.NONE, "E"); >+ GraphNode f = new GraphNode(graph, SWT.NONE, "F"); >+ GraphNode g = new GraphNode(graph, SWT.NONE, "G"); >+ GraphNode h = new GraphNode(graph, SWT.NONE, "H"); >+ GraphConnection connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, a, b); >+ connection.setData(Boolean.TRUE); >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, a, c); >+ connection.setData(Boolean.TRUE); >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, a, c); >+ connection.setData(Boolean.TRUE); >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, a, d); >+ connection.setData(Boolean.TRUE); >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, b, e); >+ connection.setData(Boolean.FALSE); >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, b, f); >+ connection.setData(Boolean.FALSE); >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, c, g); >+ connection.setData(Boolean.FALSE); >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, d, h); >+ connection.setData(Boolean.FALSE); >+ >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, b, c); >+ connection.setLineColor(ColorConstants.red); >+ connection.setLineWidth(3); >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, c, d); >+ connection.setLineColor(ColorConstants.red); >+ connection.setLineWidth(3); >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, e, f); >+ connection.setLineColor(ColorConstants.red); >+ connection.setLineWidth(3); >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, f, g); >+ connection.setLineColor(ColorConstants.red); >+ connection.setLineWidth(3); >+ >+ connection = new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, h, e); >+ connection.setLineColor(ColorConstants.red); >+ connection.setLineWidth(3); >+ >+ TreeLayoutAlgorithm treeLayoutAlgorithm = new TreeLayoutAlgorithm(); >+ LayoutFilter filter = new LayoutFilter() { >+ public boolean isObjectFiltered(GraphItem item) { >+ if (item instanceof GraphConnection ) { >+ GraphConnection connection = (GraphConnection) item; >+ Object data = connection.getData(); >+ if ( data != null && data instanceof Boolean ) { >+ // If the data is false, don't filter, otherwise, filter. >+ return ((Boolean)data).booleanValue(); >+ } >+ return true; >+ } >+ return false; >+ } >+ }; >+ graph.addLayoutFilter(filter); >+ graph.setLayoutAlgorithm(treeLayoutAlgorithm, true); >+ >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!display.readAndDispatch()) { >+ display.sleep(); >+ } >+ } >+ } >+ >+} >Index: src/org/eclipse/zest/tests/jface/CustomFigureGraphJFaceSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/jface/CustomFigureGraphJFaceSnippet.java >diff -N src/org/eclipse/zest/tests/jface/CustomFigureGraphJFaceSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/jface/CustomFigureGraphJFaceSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,177 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.jface; >+ >+ >+import org.eclipse.draw2d.IFigure; >+import org.eclipse.draw2d.Label; >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.zest.core.viewers.EntityConnectionData; >+import org.eclipse.zest.core.viewers.GraphViewer; >+import org.eclipse.zest.core.viewers.IFigureProvider; >+import org.eclipse.zest.core.viewers.IGraphEntityContentProvider; >+import org.eclipse.zest.core.viewers.INestedContentProvider; >+import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >+import org.eclipse.zest.tests.uml.UMLClassFigure; >+ >+/** >+ * This snippet shows how to use Zest viewers with custom figures. >+ * It creates a figure containing UML representation of Table class. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class CustomFigureGraphJFaceSnippet { >+ >+ public static IFigure createClassFigure1(Font classFont, Image classImage, Image publicField, Image privateField) { >+ Label classLabel1 = new Label("Table", classImage); >+ classLabel1.setFont(classFont); >+ >+ UMLClassFigure classFigure = new UMLClassFigure(classLabel1); >+ Label attribute1 = new Label("columns: Column[]", privateField); >+ >+ Label attribute2 = new Label("rows: Row[]", privateField); >+ >+ Label method1 = new Label("getColumns(): Column[]", publicField); >+ Label method2 = new Label("getRows(): Row[]", publicField); >+ classFigure.getAttributesCompartment().add(attribute1); >+ classFigure.getAttributesCompartment().add(attribute2); >+ classFigure.getMethodsCompartment().add(method1); >+ classFigure.getMethodsCompartment().add(method2); >+ classFigure.setSize(-1, -1); >+ >+ return classFigure; >+ } >+ >+ static class MyContentProvider implements IGraphEntityContentProvider, INestedContentProvider { >+ >+ public Object[] getConnectedTo(Object entity) { >+ if (entity.equals("First")) { >+ return new Object[] { "Second" }; >+ } >+ if (entity.equals("Second")) { >+ return new Object[] { "Third", "rock" }; >+ } >+ if (entity.equals("Third")) { >+ return new Object[] { "First" }; >+ } >+ if ( entity.equals("rock")) { >+ return new Object[] { "paper" }; >+ } >+ return null; >+ } >+ >+ public Object[] getElements(Object inputElement) { >+ return new String[] { "First", "Second", "Third" }; >+ } >+ >+ public double getWeight(Object entity1, Object entity2) { >+ return 0; >+ } >+ >+ public void dispose() { >+ >+ } >+ >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ >+ } >+ >+ public Object[] getChildren(Object element) { >+ // TODO Auto-generated method stub >+ return new Object[] {"rock", "paper", "scissors"}; >+ } >+ >+ public boolean hasChildren(Object element) { >+ // TODO Auto-generated method stub >+ if ( element.equals("First")) return true; >+ return false; >+ } >+ >+ } >+ >+ >+ >+ static class MyLabelProvider extends LabelProvider implements IFigureProvider { >+ final Image image = Display.getDefault().getSystemImage(SWT.ICON_WARNING); >+ >+ public Image getImage(Object element) { >+ if (element.equals("Rock") || element.equals("Paper") || element.equals("Scissors")) { >+ return image; >+ } >+ return null; >+ } >+ >+ public String getText(Object element) { >+ if ( element instanceof EntityConnectionData ) return ""; >+ return element.toString(); >+ } >+ >+ public IFigure getFigure(Object element) { >+ Font classFont = new Font(null, "Arial", 12, SWT.BOLD); >+ Image classImage = new Image(Display.getDefault(), UMLClassFigure.class.getResourceAsStream("class_obj.gif")); >+ Image privateField = new Image(Display.getDefault(), UMLClassFigure.class.getResourceAsStream("field_private_obj.gif")); >+ Image publicField= new Image(Display.getDefault(), UMLClassFigure.class.getResourceAsStream("methpub_obj.gif")); >+ return createClassFigure1(classFont, classImage, publicField, privateField); >+ } >+ >+ } >+ >+ static GraphViewer viewer = null; >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphJFaceSnippet2"); >+ shell.setLayout(new FillLayout(SWT.VERTICAL)); >+ shell.setSize(400, 400); >+ viewer = new GraphViewer(shell, SWT.NONE); >+ viewer.setContentProvider(new MyContentProvider()); >+ viewer.setLabelProvider(new MyLabelProvider()); >+ viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm()); >+ viewer.setInput(new Object()); >+ >+ Button button = new Button(shell, SWT.PUSH); >+ button.setText("push"); >+ button.addSelectionListener(new SelectionListener() { >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ } >+ >+ public void widgetSelected(SelectionEvent e) { >+ viewer.setInput(new Object()); >+ } >+ >+ }); >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ >+ } >+ >+} >Index: src/org/eclipse/zest/tests/swt/RadialLayoutSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/RadialLayoutSnippet.java >diff -N src/org/eclipse/zest/tests/swt/RadialLayoutSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/RadialLayoutSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,58 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, Canada. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ *******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+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.layouts.LayoutAlgorithm; >+import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm; >+ >+/** >+ * This example shows how {@link RadialLayoutAlgorithm} lays out a simple tree. >+ */ >+public class RadialLayoutSnippet { >+ public static void main(String[] args) { >+ // Create the shell >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet1"); >+ shell.setLayout(new FillLayout()); >+ shell.setSize(500, 500); >+ >+ final Graph g = new Graph(shell, SWT.NONE); >+ g.setSize(500, 500); >+ GraphNode root = new GraphNode(g, SWT.NONE, "Root"); >+ for (int i = 0; i < 3; i++) { >+ GraphNode n = new GraphNode(g, SWT.NONE, "1 - " + i); >+ for (int j = 0; j < 3; j++) { >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "2 - " + j); >+ new GraphConnection(g, SWT.NONE, n, n2).setWeight(-1); >+ } >+ new GraphConnection(g, SWT.NONE, root, n); >+ } >+ >+ final LayoutAlgorithm layoutAlgorithm = new RadialLayoutAlgorithm(); >+ >+ g.setLayoutAlgorithm(layoutAlgorithm, true); >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ } >+} >Index: src/org/eclipse/zest/tests/swt/CurvedEdgeGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/CurvedEdgeGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/CurvedEdgeGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/CurvedEdgeGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,79 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Button; >+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.layouts.algorithms.SpringLayoutAlgorithm; >+ >+/** >+ * >+ * This snippet shows how to create a curved connection using Zest. >+ * Each time the Button is clicked, the curve changes. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class CurvedEdgeGraphSnippet { >+ >+ public static void main(String[] args) { >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet1"); >+ shell.setLayout(new FillLayout()); >+ shell.setSize(400, 400); >+ >+ final Graph g = new Graph(shell, SWT.NONE); >+ >+ GraphNode n = new GraphNode(g, SWT.NONE, "Paper"); >+ n.setBorderColor(org.eclipse.draw2d.ColorConstants.yellow); >+ n.setBorderWidth(3); >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock"); >+ GraphNode n3 = new GraphNode(g, SWT.NONE, "Scissors"); >+ final GraphConnection connection = new GraphConnection(g, SWT.NONE, n, n2); >+ connection.setLineWidth(3); >+ new GraphConnection(g, SWT.NONE, n2, n3); >+ new GraphConnection(g, SWT.NONE, n3, n); >+ g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); >+ >+ Button button = new Button(shell, SWT.PUSH); >+ button.setText("Change Curve"); >+ button.addSelectionListener(new SelectionAdapter() { >+ int count = 0; >+ public void widgetSelected(SelectionEvent e) { >+ count = ++count % 16; >+ if ( count > 8 ) { >+ connection.setCurveDepth((-16 + count) * 10); >+ } >+ else { >+ connection.setCurveDepth(count * 10); >+ } >+ } >+ }); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ } >+ >+} >Index: src/org/eclipse/zest/tests/swt/SpringLayoutProgressSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/SpringLayoutProgressSnippet.java >diff -N src/org/eclipse/zest/tests/swt/SpringLayoutProgressSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/SpringLayoutProgressSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,87 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Mateusz Matela and others. All rights reserved. This >+ * program and the accompanying materials are made available under the terms of >+ * the Eclipse Public License v1.0 which accompanies this distribution, and is >+ * available at http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ *******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Label; >+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.layouts.algorithms.SpringLayoutAlgorithm; >+ >+/** >+ * This example allows to see how SpringLayoutAlgorithm changes the position >+ * of entities in each step. >+ */ >+public class SpringLayoutProgressSnippet { >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ // Create the shell >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet1"); >+ GridLayout gridLayout = new GridLayout(); >+ gridLayout.numColumns = 5; >+ shell.setLayout(gridLayout); >+ shell.setSize(500, 500); >+ >+ final Graph g = new Graph(shell, SWT.NONE); >+ g.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 5)); >+ g.setSize(500, 500); >+ GraphNode root = new GraphNode(g, SWT.NONE, "Root"); >+ for (int i = 0; i < 3; i++) { >+ GraphNode n = new GraphNode(g, SWT.NONE, "1 - " + i); >+ for (int j = 0; j < 3; j++) { >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "2 - " + j); >+ new GraphConnection(g, SWT.NONE, n, n2).setWeight(-1); >+ } >+ new GraphConnection(g, SWT.NONE, root, n); >+ } >+ >+ >+ final SpringLayoutAlgorithm springLayoutAlgorithm = new SpringLayoutAlgorithm(); >+ >+ g.setLayoutAlgorithm(springLayoutAlgorithm, false); >+ >+ Button b = new Button(shell, SWT.FLAT); >+ b.setText("step"); >+ >+ final Label label = new Label(shell, SWT.LEFT); >+ label.setText("<--click"); >+ label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); >+ >+ b.addSelectionListener(new SelectionAdapter() { >+ int steps = 0; >+ public void widgetSelected(SelectionEvent e) { >+ springLayoutAlgorithm.performOneIteration(); >+ g.redraw(); >+ label.setText("steps: " + ++steps); >+ } >+ }); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ } >+ >+} >Index: src/org/eclipse/zest/tests/jface/RefreshGraphJFaceSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/jface/RefreshGraphJFaceSnippet.java >diff -N src/org/eclipse/zest/tests/jface/RefreshGraphJFaceSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/jface/RefreshGraphJFaceSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,143 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.jface; >+ >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >+import org.eclipse.zest.core.viewers.GraphViewer; >+import org.eclipse.zest.core.viewers.IGraphContentProvider; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * This snippet shows how the refresh works on a Zest viewer. >+ */ >+public class RefreshGraphJFaceSnippet { >+ >+ static class MyContentProvider implements IGraphContentProvider { >+ >+ Object[] elements = new Object[] { "Rock2Paper", "Paper2Scissors", "Scissors2Rock" }; >+ >+ public Object getDestination(Object rel) { >+ if ("Rock2Paper".equals(rel)) { >+ return "Rock"; >+ } else if ("Paper2Scissors".equals(rel) || "Scissors2Paper".equals(rel)) { >+ return "Paper"; >+ } else if ("Scissors2Rock".equals(rel)) { >+ return "Scissors"; >+ } >+ return null; >+ } >+ >+ public Object[] getElements(Object input) { >+ return elements; >+ } >+ >+ public Object getSource(Object rel) { >+ if ("Rock2Paper".equals(rel)) { >+ return "Paper"; >+ } else if ("Paper2Scissors".equals(rel) || "Scissors2Paper".equals(rel)) { >+ return "Scissors"; >+ } else if ("Scissors2Rock".equals(rel)) { >+ return "Rock"; >+ } >+ return null; >+ } >+ >+ public void setElements(Object[] elements) { >+ this.elements = elements; >+ } >+ >+ public double getWeight(Object connection) { >+ return 0; >+ } >+ >+ public void dispose() { >+ } >+ >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ } >+ >+ } >+ >+ static class MyLabelProvider extends LabelProvider { >+ final Image image = Display.getDefault().getSystemImage(SWT.ICON_WARNING); >+ >+ public MyLabelProvider() { >+ >+ } >+ >+ public String getText(Object element) { >+ return element.toString(); >+ } >+ >+ public Image getImage(Object element) { >+ return image; >+ } >+ } >+ >+ static GraphViewer viewer = null; >+ private static MyContentProvider contentProvider; >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphJFaceSnippet2"); >+ shell.setLayout(new FillLayout(SWT.VERTICAL)); >+ shell.setSize(400, 400); >+ Composite parent = new Composite(shell, SWT.NONE); >+ parent.setLayout(new GridLayout(2, false)); >+ buildViewer(parent); >+ buildButton(parent); >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ >+ } >+ >+ private static void buildButton(Composite parent) { >+ Button button = new Button(parent, SWT.PUSH); >+ button.setText("Refresh"); >+ button.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ contentProvider.setElements(new Object[] { "Rock2Paper", "Scissors2Paper", "Scissors2Rock" }); >+ viewer.refresh(); >+ } >+ }); >+ } >+ >+ private static void buildViewer(Composite parent) { >+ viewer = new GraphViewer(parent, SWT.NONE); >+ viewer.getGraphControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); >+ contentProvider = new MyContentProvider(); >+ viewer.setContentProvider(contentProvider); >+ viewer.setLabelProvider(new MyLabelProvider()); >+ viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm()); >+ viewer.setInput(new Object()); >+ } >+} >Index: src/org/eclipse/zest/tests/swt/SelfLoopGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/SelfLoopGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/SelfLoopGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/SelfLoopGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,56 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+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; >+ >+/** >+ * This snippet demonstrates a self loop with a label. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class SelfLoopGraphSnippet { >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ Display display = new Display(); >+ Shell shell = new Shell(display); >+ shell.setText("GraphSnippet9"); >+ shell.setLayout(new FillLayout()); >+ shell.setSize(400, 400); >+ >+ final Graph graph = new Graph(shell, SWT.NONE); >+ >+ GraphNode a = new GraphNode(graph, ZestStyles.CONNECTIONS_DIRECTED, "Root"); >+ GraphConnection connection = new GraphConnection(graph, SWT.NONE, a, a); >+ connection.setText("A to A"); >+ a.setLocation(100, 100); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!display.readAndDispatch()) { >+ display.sleep(); >+ } >+ } >+ } >+ >+} >Index: src/org/eclipse/zest/tests/swt/SelectionGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/SelectionGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/SelectionGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/SelectionGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,73 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, Canada. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ *******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+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.algorithms.SpringLayoutAlgorithm; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * Adds a selection listener to the nodes to tell when a selection event has >+ * happened. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class SelectionGraphSnippet { >+ >+ 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(400, 400); >+ >+ 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, "Information", image1); >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "Warning", image2); >+ GraphNode n3 = new GraphNode(g, SWT.NONE, "Error", image3); >+ >+ new GraphConnection(g, SWT.NONE, n1, n2); >+ new GraphConnection(g, SWT.NONE, n2, n3); >+ >+ g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ image1.dispose(); >+ image2.dispose(); >+ image3.dispose(); >+ >+ } >+} >Index: src/org/eclipse/zest/tests/swt/SpringLayoutSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/SpringLayoutSnippet.java >diff -N src/org/eclipse/zest/tests/swt/SpringLayoutSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/SpringLayoutSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,64 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+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.layouts.LayoutAlgorithm; >+import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >+ >+/** >+ * This example shows how SpringLayoutSnippet layouts a simple graph >+ * and how it reacts to different weights of edges. >+ */ >+public class SpringLayoutSnippet { >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ // Create the shell >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet1"); >+ shell.setLayout(new FillLayout()); >+ shell.setSize(500, 500); >+ >+ final Graph g = new Graph(shell, SWT.NONE); >+ g.setSize(500, 500); >+ GraphNode root = new GraphNode(g, SWT.NONE, "Root"); >+ for (int i = 0; i < 3; i++) { >+ GraphNode n = new GraphNode(g, SWT.NONE, "1 - " + i); >+ for (int j = 0; j < 3; j++) { >+ GraphNode n2 = new GraphNode(g, SWT.NONE, "2 - " + j); >+ new GraphConnection(g, SWT.NONE, n, n2).setWeight(-1); >+ } >+ new GraphConnection(g, SWT.NONE, root, n); >+ } >+ >+ final LayoutAlgorithm layoutAlgorithm = new SpringLayoutAlgorithm(); >+ >+ g.setLayoutAlgorithm(layoutAlgorithm, true); >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ } >+ >+} >Index: src/org/eclipse/zest/tests/swt/ContainersGraphSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/swt/ContainersGraphSnippet.java >diff -N src/org/eclipse/zest/tests/swt/ContainersGraphSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/swt/ContainersGraphSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,88 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.swt; >+ >+import org.eclipse.draw2d.Figure; >+import org.eclipse.draw2d.FlowLayout; >+import org.eclipse.draw2d.IFigure; >+import org.eclipse.draw2d.ImageFigure; >+import org.eclipse.draw2d.Label; >+import org.eclipse.draw2d.MarginBorder; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Image; >+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.GraphContainer; >+import org.eclipse.zest.core.widgets.GraphNode; >+import org.eclipse.zest.core.widgets.ZestStyles; >+import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >+ >+/** >+ * >+ * This snippet shows how to use graph containers. >+ * >+ * @author Ian Bull >+ * >+ */ >+public class ContainersGraphSnippet { >+ >+ public static void main(String[] args) { >+ final Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphSnippet11"); >+ shell.setLayout(new FillLayout()); >+ shell.setSize(400, 400); >+ >+ final Graph g = new Graph(shell, SWT.NONE); >+ >+ Image zx = new Image(d, "zxsnow.png"); >+ IFigure tooltip = new Figure(); >+ tooltip.setBorder(new MarginBorder(5,5,5,5)); >+ FlowLayout layout = new FlowLayout(false); >+ layout.setMajorSpacing(3); >+ layout.setMinorAlignment(3); >+ tooltip.setLayoutManager(new FlowLayout(false)); >+ tooltip.add(new ImageFigure(zx)); >+ tooltip.add(new Label("Name: Chris Aniszczyk")); >+ tooltip.add(new Label("Location: Austin, Texas")); >+ >+ GraphContainer c1 = new GraphContainer(g, SWT.NONE); >+ c1.setText("Canada"); >+ GraphContainer c2 = new GraphContainer(g, SWT.NONE); >+ c2.setText("USA"); >+ >+ GraphNode n1 = new GraphNode(c1, SWT.NONE, "Ian B."); >+ n1.setSize(200, 100); >+ GraphNode n2 = new GraphNode(c2, SWT.NONE, "Chris A."); >+ n2.setTooltip(tooltip); >+ >+ GraphConnection connection = new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, n1, n2); >+ connection.setCurveDepth(-30); >+ GraphConnection connection2 = new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, n2, n1); >+ connection2.setCurveDepth(-30); >+ >+ >+ g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); >+ >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ zx.dispose(); >+ } >+ >+} >Index: src/org/eclipse/zest/tests/jface/SelectionListenerGraphJFaceSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/jface/SelectionListenerGraphJFaceSnippet.java >diff -N src/org/eclipse/zest/tests/jface/SelectionListenerGraphJFaceSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/jface/SelectionListenerGraphJFaceSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,134 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.jface; >+ >+import java.util.Iterator; >+ >+import org.eclipse.jface.viewers.ISelectionChangedListener; >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.SelectionChangedEvent; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; >+import org.eclipse.zest.core.viewers.GraphViewer; >+import org.eclipse.zest.core.viewers.IGraphContentProvider; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+public class SelectionListenerGraphJFaceSnippet { >+ static class MyContentProvider implements IGraphContentProvider { >+ >+ public Object getDestination(Object rel) { >+ if ("Rock2Paper".equals(rel)) { >+ return "Rock"; >+ } else if ("Paper2Scissors".equals(rel)) { >+ return "Paper"; >+ } else if ("Scissors2Rock".equals(rel)) { >+ return "Scissors"; >+ } >+ return null; >+ } >+ >+ public Object[] getElements(Object input) { >+ return new Object[] { "Rock2Paper", "Paper2Scissors", "Scissors2Rock" }; >+ } >+ >+ public Object getSource(Object rel) { >+ if ("Rock2Paper".equals(rel)) { >+ return "Paper"; >+ } else if ("Paper2Scissors".equals(rel)) { >+ return "Scissors"; >+ } else if ("Scissors2Rock".equals(rel)) { >+ return "Rock"; >+ } >+ return null; >+ } >+ >+ public double getWeight(Object connection) { >+ return 0; >+ } >+ >+ public void dispose() { >+ } >+ >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ } >+ >+ } >+ >+ static class MyLabelProvider extends LabelProvider { >+ final Image image = Display.getDefault().getSystemImage(SWT.ICON_WARNING); >+ >+ public Image getImage(Object element) { >+ if (element.equals("Rock") || element.equals("Paper") || element.equals("Scissors")) { >+ return image; >+ } >+ return null; >+ } >+ >+ public String getText(Object element) { >+ return element.toString(); >+ } >+ >+ } >+ >+ static GraphViewer viewer = null; >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ Display d = new Display(); >+ Shell shell = new Shell(d); >+ shell.setText("GraphJFaceSnippet2"); >+ shell.setLayout(new FillLayout(SWT.VERTICAL)); >+ shell.setSize(400, 400); >+ viewer = new GraphViewer(shell, SWT.NONE); >+ viewer.setContentProvider(new MyContentProvider()); >+ viewer.setLabelProvider(new MyLabelProvider()); >+ viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm()); >+ viewer.setInput(new Object()); >+ viewer.addSelectionChangedListener(new ISelectionChangedListener() { >+ >+ public void selectionChanged(SelectionChangedEvent event) { >+ System.out.println("Selection Changed: " + selectionToString((StructuredSelection) event.getSelection())); >+ } >+ >+ private String selectionToString(StructuredSelection selection) { >+ StringBuffer stringBuffer = new StringBuffer(); >+ Iterator iterator = selection.iterator(); >+ boolean first = true; >+ while (iterator.hasNext()) { >+ if (first) { >+ first = false; >+ } else { >+ stringBuffer.append(" : "); >+ } >+ stringBuffer.append(iterator.next()); >+ } >+ return stringBuffer.toString(); >+ } >+ >+ }); >+ shell.open(); >+ while (!shell.isDisposed()) { >+ while (!d.readAndDispatch()) { >+ d.sleep(); >+ } >+ } >+ >+ } >+ >+} >Index: src/org/eclipse/zest/tests/jface/FileProviderJFaceSnippet.java >=================================================================== >RCS file: src/org/eclipse/zest/tests/jface/FileProviderJFaceSnippet.java >diff -N src/org/eclipse/zest/tests/jface/FileProviderJFaceSnippet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/zest/tests/jface/FileProviderJFaceSnippet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,136 @@ >+/******************************************************************************* >+ * Copyright 2005-2009, CHISEL Group, University of Victoria, Victoria, BC, >+ * Canada. All rights reserved. This program and the accompanying materials are >+ * made available under the terms of the Eclipse Public License v1.0 which >+ * accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * The Chisel Group, University of Victoria >+ * Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 >+ ******************************************************************************/ >+package org.eclipse.zest.tests.jface; >+ >+import java.io.BufferedReader; >+import java.io.File; >+import java.io.FileReader; >+import java.io.IOException; >+import java.util.ArrayList; >+import java.util.StringTokenizer; >+ >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.zest.core.viewers.GraphViewer; >+import org.eclipse.zest.core.viewers.IGraphContentProvider; >+import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.FileDialog; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * This snippet uses a very simple file format to read a graph. Edges are listed >+ * on a new line in a file as such: >+ * a calls b >+ * b calls c >+ * c calld d >+ * >+ * The content provider creates an edge for each line in the file and names the >+ * sources and destination from the line. >+ * >+ * >+ * @author Ian Bull >+ * >+ */ >+public class FileProviderJFaceSnippet { >+ >+ public static final String graph = "a calls b\n" + "a calls c\n" + "b calld d\n" + "b calls e\n" + "c calls f\n" + "c calls g\n" + "d calls h\n" + "d calls i\n" + "e calls j\n" + "e calls k\n" + "f calls l\n" + "f calls m\n"; >+ >+ static class SimpleGraphContentProvider implements IGraphContentProvider { >+ >+ private StringTokenizer graph; >+ >+ public Object getDestination(Object rel) { >+ String string = (String) rel; >+ String[] parts = string.split(" "); >+ return parts[2]; >+ } >+ >+ public Object[] getElements(Object input) { >+ ArrayList listOfEdges = new ArrayList(); >+ while (graph.hasMoreTokens()) { >+ listOfEdges.add(graph.nextToken()); >+ } >+ return listOfEdges.toArray(); >+ } >+ >+ public Object getSource(Object rel) { >+ String string = (String) rel; >+ String[] parts = string.split(" "); >+ return parts[0]; >+ } >+ >+ public double getWeight(Object connection) { >+ return 0; >+ } >+ >+ public void dispose() { >+ >+ } >+ >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ if (newInput != null) { >+ graph = new StringTokenizer((String) newInput, "\n"); >+ } >+ } >+ >+ } >+ >+ public static void main(String[] args) throws IOException { >+ Display display = new Display(); >+ Shell shell = new Shell(display); >+ shell.setText("Simple Graph File Format"); >+ >+ FileDialog dialog = new FileDialog(shell, SWT.OPEN); >+ dialog.setFilterNames(new String[] { "Simple Graph Files (*.sgf)", "All Files (*.*)" }); >+ dialog.setFilterExtensions(new String[] { "*.sgf", "*.*" }); //Windows wild cards >+ >+ String directory = System.getProperty("user.dir") + "/src/org/eclipse/zest/tests/jface/SimpleGraph.sgf"; //eclipse/zest/examples/jface/"; >+ System.out.println(directory); >+ dialog.setFilterPath(directory); >+ //dialog.setFilterPath(System.getProperty("user.dir") + "src/org/eclipse/zest/examples/jface/"); //Windows path >+ >+ shell.setLayout(new FillLayout(SWT.VERTICAL)); >+ shell.setSize(400, 400); >+ GraphViewer viewer = null; >+ >+ viewer = new GraphViewer(shell, SWT.NONE); >+ viewer.setContentProvider(new SimpleGraphContentProvider()); >+ viewer.setLabelProvider(new LabelProvider()); >+ viewer.setLayoutAlgorithm(new RadialLayoutAlgorithm()); >+ >+ shell.open(); >+ String fileName = dialog.open(); >+ >+ if (fileName == null) { >+ // use the sample graph >+ viewer.setInput(graph); >+ } else { >+ FileReader fileReader = new FileReader(new File(fileName)); >+ BufferedReader bufferedReader = new BufferedReader(fileReader); >+ StringBuffer stringBuffer = new StringBuffer(); >+ while (bufferedReader.ready()) { >+ stringBuffer.append(bufferedReader.readLine() + "\n"); >+ } >+ viewer.setInput(stringBuffer.toString()); >+ } >+ >+ while (!shell.isDisposed()) { >+ if (!display.readAndDispatch()) { >+ display.sleep(); >+ } >+ } >+ display.dispose(); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 283244
: 141373