Skip to main content
Jump to: navigation, search

Difference between revisions of "GEF/GEF4/Cloudio"

< GEF‎ | GEF4
(Cloudio.UI)
Line 4: Line 4:
  
 
== Introduction ==  
 
== Introduction ==  
The [[GEF/GEF4/Cloudio|<span style="color:#8A3572">GEF4 Cloudio</span>]] component provides support for visualizing tag clouds within a dedicated SWT Canvas or JFace viewer. It is internally decomposed into the single '''[[#Cloudio.UI|Cloudio.UI]]''' module.
+
The <span style="color:#8A3572">[[GEF/GEF4/Cloudio|GEF4 Cloudio]]</span> component provides support for visualizing tag clouds within a dedicated SWT Canvas or JFace viewer. It is internally decomposed into the single '''[[#Cloudio.UI|Cloudio.UI]]''' module.
  
 
[[Image:GEF4-Components-Cloudio.png|600px]]
 
[[Image:GEF4-Components-Cloudio.png|600px]]
Line 44: Line 44:
 
A minimal example to create and display a tag cloud.
 
A minimal example to create and display a tag cloud.
  
    public static void main(String [] args) {
+
<source lang="java" style="border-style:solid;border-color:#f2f2f2;border-width:1px;padding:10px;margin-bottom:10px">
        final Display display = new Display();
+
public static void main(String [] args) {
        final Shell shell = new Shell(display);
+
  final Display display = new Display();
        TagCloud cloud = new TagCloud(shell, SWT.NONE);
+
  final Shell shell = new Shell(display);
        // Generate some dummy words - color, weight and fontdata must
+
  TagCloud cloud = new TagCloud(shell, SWT.NONE);
        // always be defined.
+
 
        List<Word> words = new ArrayList<Word>();
+
  // Generate some dummy words - color, weight and fontdata must
        Word w = new Word("Hello");
+
  // always be defined.
        w.setColor(display.getSystemColor(SWT.COLOR_DARK_CYAN));
+
  List<Word> words = new ArrayList<Word>();
        w.weight = 1;
+
  Word w = new Word("Hello");
        w.setFontData(cloud.getFont().getFontData().clone());
+
  w.setColor(display.getSystemColor(SWT.COLOR_DARK_CYAN));
        words.add(w);
+
  w.weight = 1;
        w = new Word("Cloudio");
+
  w.setFontData(cloud.getFont().getFontData().clone());
        w.setColor(display.getSystemColor(SWT.COLOR_DARK_GREEN));
+
  words.add(w);
        w.setFontData(cloud.getFont().getFontData().clone());
+
  w = new Word("Cloudio");
        w.weight = 0.5;
+
  w.setColor(display.getSystemColor(SWT.COLOR_DARK_GREEN));
        w.angle = -45;
+
  w.setFontData(cloud.getFont().getFontData().clone());
        words.add(w);
+
  w.weight = 0.5;
        shell.setBounds(50,50, 300, 300);
+
  w.angle = -45;
        cloud.setBounds(0,0, shell.getBounds().width, shell.getBounds().height);
+
  words.add(w);
        // Assign the list of words to the cloud:
+
 
        cloud.setWords(words, null);
+
  shell.setBounds(50,50, 300, 300);
        shell.open();
+
  cloud.setBounds(0,0, shell.getBounds().width, shell.getBounds().height);
        while (!shell.isDisposed()) {
+
 
            if (!display.readAndDispatch()) display.sleep();
+
  // Assign the list of words to the cloud:
        }
+
  cloud.setWords(words, null);
        display.dispose();
+
  shell.open();
    }
+
  while (!shell.isDisposed()) {
 +
    if (!display.readAndDispatch()) display.sleep();
 +
  }
 +
  display.dispose();
 +
}
 +
</source>
  
 
The result should look similar to this (String positions are assigned by random):
 
The result should look similar to this (String positions are assigned by random):
Line 83: Line 88:
 
display tool tips on words.
 
display tool tips on words.
  
 
+
<source lang="java" style="border-style:solid;border-color:#f2f2f2;border-width:1px;padding:10px;margin-bottom:10px">
 
   import java.util.ArrayList;
 
   import java.util.ArrayList;
 
   import java.util.Arrays;
 
   import java.util.Arrays;
 
   import java.util.List;
 
   import java.util.List;
  <br />
+
 
 
   import org.eclipse.jface.viewers.BaseLabelProvider;
 
   import org.eclipse.jface.viewers.BaseLabelProvider;
 
   import org.eclipse.jface.viewers.ISelectionChangedListener;
 
   import org.eclipse.jface.viewers.ISelectionChangedListener;
Line 104: Line 109:
 
   import org.eclipse.zest.cloudio.TagCloud;
 
   import org.eclipse.zest.cloudio.TagCloud;
 
   import org.eclipse.zest.cloudio.TagCloudViewer;
 
   import org.eclipse.zest.cloudio.TagCloudViewer;
  <br />
+
 
 
   public class TagCloudViewerSnippet {
 
   public class TagCloudViewerSnippet {
  <br />
+
 
 
     static class CustomLabelProvider extends BaseLabelProvider implements ICloudLabelProvider {
 
     static class CustomLabelProvider extends BaseLabelProvider implements ICloudLabelProvider {
  <br />
+
 
 
         private Font font;
 
         private Font font;
  <br />
+
 
 
         public CustomLabelProvider(Font font) {
 
         public CustomLabelProvider(Font font) {
 
             this.font = font;
 
             this.font = font;
 
         }
 
         }
  <br />
+
 
 
         @Override
 
         @Override
 
         public String getLabel(Object element) {
 
         public String getLabel(Object element) {
 
             return element.toString();
 
             return element.toString();
 
         }
 
         }
  <br />
+
 
 
         @Override
 
         @Override
 
         public double getWeight(Object element) {
 
         public double getWeight(Object element) {
 
             return Math.random();
 
             return Math.random();
 
         }
 
         }
  <br />
+
 
 
         @Override
 
         @Override
 
         public Color getColor(Object element) {
 
         public Color getColor(Object element) {
 
             return Display.getDefault().getSystemColor(SWT.COLOR_GREEN);
 
             return Display.getDefault().getSystemColor(SWT.COLOR_GREEN);
 
         }
 
         }
  <br />
+
 
 
         @Override
 
         @Override
 
         public FontData[] getFontData(Object element) {
 
         public FontData[] getFontData(Object element) {
 
             return font.getFontData();
 
             return font.getFontData();
 
         }
 
         }
  <br />
+
 
 
         @Override
 
         @Override
 
         public float getAngle(Object element) {
 
         public float getAngle(Object element) {
 
             return (float) (-90 + Math.random() * 180);
 
             return (float) (-90 + Math.random() * 180);
 
         }
 
         }
  <br />
+
 
 
         @Override
 
         @Override
 
         public String getToolTip(Object element) {
 
         public String getToolTip(Object element) {
Line 145: Line 150:
 
         }
 
         }
 
     }
 
     }
  <br />
+
 
  <br />
+
 
     public static void main(String [] args) {
 
     public static void main(String [] args) {
 
         final Display display = new Display();
 
         final Display display = new Display();
 
         final Shell shell = new Shell(display);
 
         final Shell shell = new Shell(display);
 
         TagCloud cloud = new TagCloud(shell, SWT.NONE);
 
         TagCloud cloud = new TagCloud(shell, SWT.NONE);
  <br />
+
 
 
         final TagCloudViewer viewer = new TagCloudViewer(cloud);
 
         final TagCloudViewer viewer = new TagCloudViewer(cloud);
  <br />
+
 
 
         // A simple content provider for a list of elements  
 
         // A simple content provider for a list of elements  
 
         viewer.setContentProvider(new IStructuredContentProvider() {
 
         viewer.setContentProvider(new IStructuredContentProvider() {
  <br />
+
 
 
             @Override
 
             @Override
 
             public void dispose() { }
 
             public void dispose() { }
  <br />
+
 
 
             @Override
 
             @Override
 
             public void inputChanged(Viewer viewer, Object oldInput,
 
             public void inputChanged(Viewer viewer, Object oldInput,
 
                     Object newInput) {}
 
                     Object newInput) {}
  <br />
+
 
 
             @Override
 
             @Override
 
             public Object[] getElements(Object inputElement) {
 
             public Object[] getElements(Object inputElement) {
 
                 return ((List<?>)inputElement).toArray();
 
                 return ((List<?>)inputElement).toArray();
 
             }
 
             }
  <br />
+
 
 
         });
 
         });
  <br />
+
 
 
         // A simple label provider (see above)
 
         // A simple label provider (see above)
 
         viewer.setLabelProvider(new CustomLabelProvider(cloud.getFont()));
 
         viewer.setLabelProvider(new CustomLabelProvider(cloud.getFont()));
  <br />
+
 
 
         // Demo of an selection listener
 
         // Demo of an selection listener
 
         viewer.addSelectionChangedListener(new ISelectionChangedListener() {
 
         viewer.addSelectionChangedListener(new ISelectionChangedListener() {
  <br />
+
 
 
             @Override
 
             @Override
 
             public void selectionChanged(SelectionChangedEvent event) {
 
             public void selectionChanged(SelectionChangedEvent event) {
Line 183: Line 187:
 
             }
 
             }
 
         });
 
         });
  <br />
+
 
 
         // Demo data
 
         // Demo data
 
         List<String> data = new ArrayList<String>();
 
         List<String> data = new ArrayList<String>();
Line 189: Line 193:
 
         data.add("World");
 
         data.add("World");
 
         data.add("Hello Cloudio");
 
         data.add("Hello Cloudio");
  <br />
+
 
 
         shell.setBounds(50,50, 300, 300);
 
         shell.setBounds(50,50, 300, 300);
 
         cloud.setBounds(0,0, shell.getBounds().width, shell.getBounds().height);
 
         cloud.setBounds(0,0, shell.getBounds().width, shell.getBounds().height);
  <br />
+
 
 
         // Set the input of the viewer
 
         // Set the input of the viewer
 
         viewer.setInput(data);
 
         viewer.setInput(data);
  <br />
+
 
 
         // Set initial selection:
 
         // Set initial selection:
 
         viewer.setSelection(new StructuredSelection(Arrays.asList("Hello Cloudio")));
 
         viewer.setSelection(new StructuredSelection(Arrays.asList("Hello Cloudio")));
  <br />
+
 
         shell.open();
 
         shell.open();
 
         while (!shell.isDisposed()) {
 
         while (!shell.isDisposed()) {
Line 206: Line 210:
 
     }
 
     }
 
   }
 
   }
 
+
</source>
 
The result will look similar to this:
 
The result will look similar to this:
  

Revision as of 06:57, 28 May 2015

Note to non-wiki readers: This documentation is generated from the Eclipse wiki - if you have corrections or additions it would be awesome if you added them in the original wiki page.


Introduction

The GEF4 Cloudio component provides support for visualizing tag clouds within a dedicated SWT Canvas or JFace viewer. It is internally decomposed into the single Cloudio.UI module.

GEF4-Components-Cloudio.png

User Documentation

The GEF4 Cloudio component provides a Tag Cloud view that can be used to create word clouds.

GEF4-Cloudio-TagCloud.png

Below are some examples of tag clouds generated with Cloudio. The images were created with the help of the TagCloud view, modifying different parameters (such as colors, fonts or rotation angles).

Woyzeck

Zest cloudio woyzeck.png

Created from Georg Büchner's Woyzeck. The most frequent word was boosted.

Winnetou

Zest cloudio winnetou.png

Karl May's Winnetou III, using two different fonts, 45-degree rotation and a relatively large x-axis variation when placing the words.

Nietzsche

Zest cloudio nietzsche.png

'Also sprach Zarathustra', by Nietzsche. 90 degree rotation and a large x-axis variation.

Woyzeck Cluster

Zest cloudio woyzeck cluster.png

Same text as in the first example, but with a modified layout algorithm and label provider: Both labels and initial position are assigned based on the first character of the word (for instance, words starting with a to l are at the bottom left). Doesn't really look good, but shows how to extend the functionality to realize a cluster visualization or else...

Cloudio.UI

  • feature: org.eclipse.gef4.cloudio.ui
  • bundle: org.eclipse.gef4.cloudio.ui

TagCloud

A minimal example to create and display a tag cloud.

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();
}

The result should look similar to this (String positions are assigned by random):

Zest cloudio snippet1.png

Tag Cloud Viewer

The following example creates a tag cloud viewer. In addition to the example above, the viewer will enhance the functionality of the tag cloud: It is possible to select and deselect elements by mouse click, to zoom in or out using the mouse wheel and to display tool tips on words.

  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;
 
  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();
    }
  }

The result will look similar to this:

Zest cloudio snippet2.png

Back to the top