summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Schwiebert2011-09-05 14:53:11 (EDT)
committerFabian Steeg2011-09-06 09:40:35 (EDT)
commit2c409bc4663819622c0ef92ec5ac125698c11f00 (patch)
tree49e14013bf0d0c2cff7dda455e4be66b72636fb7
parent0e530e4289b712dfa38b5fe89ae34ea44bb77d21 (diff)
downloadorg.eclipse.gef4-2c409bc4663819622c0ef92ec5ac125698c11f00.zip
org.eclipse.gef4-2c409bc4663819622c0ef92ec5ac125698c11f00.tar.gz
org.eclipse.gef4-2c409bc4663819622c0ef92ec5ac125698c11f00.tar.bz2
added snippets to demonstrate how to use TagCloud and TagCloudViewer.
-rw-r--r--org.eclipse.zest.examples.cloudio/src/main/java/org/eclipse/zest/examples/cloudio/snippets/TagCloudSnippet.java54
-rw-r--r--org.eclipse.zest.examples.cloudio/src/main/java/org/eclipse/zest/examples/cloudio/snippets/TagCloudViewerSnippet.java134
2 files changed, 188 insertions, 0 deletions
diff --git a/org.eclipse.zest.examples.cloudio/src/main/java/org/eclipse/zest/examples/cloudio/snippets/TagCloudSnippet.java b/org.eclipse.zest.examples.cloudio/src/main/java/org/eclipse/zest/examples/cloudio/snippets/TagCloudSnippet.java
new file mode 100644
index 0000000..80610c8
--- /dev/null
+++ b/org.eclipse.zest.examples.cloudio/src/main/java/org/eclipse/zest/examples/cloudio/snippets/TagCloudSnippet.java
@@ -0,0 +1,54 @@
+package org.eclipse.zest.examples.cloudio.snippets;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.zest.cloudio.TagCloud;
+import org.eclipse.zest.cloudio.Word;
+
+/**
+ * This snippet demonstrates how to create a simple tag cloud,
+ * which will display the words "Hello" and "Cloudio".
+ *
+ * @author sschwieb
+ *
+ */
+public class TagCloudSnippet {
+
+ public static void main(String [] args) {
+ final Display display = new Display();
+ final Shell shell = new Shell(display);
+ TagCloud cloud = new TagCloud(shell, SWT.NONE);
+
+ // Generate some dummy words - color, weight and fontdata must
+ // always be defined.
+ List<Word> words = new ArrayList<Word>();
+ Word w = new Word("Hello");
+ w.setColor(display.getSystemColor(SWT.COLOR_DARK_CYAN));
+ w.weight = 1;
+ w.setFontData(cloud.getFont().getFontData().clone());
+ words.add(w);
+ w = new Word("Cloudio");
+ w.setColor(display.getSystemColor(SWT.COLOR_DARK_GREEN));
+ w.setFontData(cloud.getFont().getFontData().clone());
+ w.weight = 0.5;
+ w.angle = -45;
+ words.add(w);
+
+ shell.setBounds(50,50, 300, 300);
+ cloud.setBounds(0,0, shell.getBounds().width, shell.getBounds().height);
+
+ // Assign the list of words to the cloud:
+ cloud.setWords(words, null);
+
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) display.sleep();
+ }
+ display.dispose();
+ }
+
+}
diff --git a/org.eclipse.zest.examples.cloudio/src/main/java/org/eclipse/zest/examples/cloudio/snippets/TagCloudViewerSnippet.java b/org.eclipse.zest.examples.cloudio/src/main/java/org/eclipse/zest/examples/cloudio/snippets/TagCloudViewerSnippet.java
new file mode 100644
index 0000000..206a2f6
--- /dev/null
+++ b/org.eclipse.zest.examples.cloudio/src/main/java/org/eclipse/zest/examples/cloudio/snippets/TagCloudViewerSnippet.java
@@ -0,0 +1,134 @@
+package org.eclipse.zest.examples.cloudio.snippets;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.jface.viewers.BaseLabelProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.zest.cloudio.ICloudLabelProvider;
+import org.eclipse.zest.cloudio.TagCloud;
+import org.eclipse.zest.cloudio.TagCloudViewer;
+
+/**
+ * This snippet demonstrates how to create a {@link TagCloudViewer},
+ * how to use label- and content-providers and how to add an
+ * {@link ISelectionChangedListener}.
+ *
+ * @author sschwieb
+ *
+ */
+public class TagCloudViewerSnippet {
+
+ static class CustomLabelProvider extends BaseLabelProvider implements ICloudLabelProvider {
+
+ private Font font;
+
+ public CustomLabelProvider(Font font) {
+ this.font = font;
+ }
+
+ @Override
+ public String getLabel(Object element) {
+ return element.toString();
+ }
+
+ @Override
+ public double getWeight(Object element) {
+ return Math.random();
+ }
+
+ @Override
+ public Color getColor(Object element) {
+ return Display.getDefault().getSystemColor(SWT.COLOR_GREEN);
+ }
+
+ @Override
+ public FontData[] getFontData(Object element) {
+ return font.getFontData();
+ }
+
+ @Override
+ public float getAngle(Object element) {
+ return (float) (-90 + Math.random() * 180);
+ }
+
+ @Override
+ public String getToolTip(Object element) {
+ return element.toString();
+ }
+
+ }
+
+
+
+ public static void main(String [] args) {
+ final Display display = new Display();
+ final Shell shell = new Shell(display);
+ TagCloud cloud = new TagCloud(shell, SWT.NONE);
+
+ final TagCloudViewer viewer = new TagCloudViewer(cloud);
+
+ // A simple content provider for a list of elements
+ viewer.setContentProvider(new IStructuredContentProvider() {
+
+ @Override
+ public void dispose() { }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {}
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return ((List<?>)inputElement).toArray();
+ }
+
+ });
+
+ // A simple label provider (see above)
+ viewer.setLabelProvider(new CustomLabelProvider(cloud.getFont()));
+
+ // Demo of an selection listener
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
+ System.out.println("Selection: " + selection);
+ }
+ });
+
+ // Demo data
+ List<String> data = new ArrayList<String>();
+ data.add("Hello");
+ data.add("World");
+ data.add("Hello Cloudio");
+
+ shell.setBounds(50,50, 300, 300);
+ cloud.setBounds(0,0, shell.getBounds().width, shell.getBounds().height);
+
+ // Set the input of the viewer
+ viewer.setInput(data);
+
+ // Set initial selection:
+ viewer.setSelection(new StructuredSelection(Arrays.asList("Hello Cloudio")));
+
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) display.sleep();
+ }
+ display.dispose();
+ }
+} \ No newline at end of file