]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/gallery/GalleryExample.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / gallery / GalleryExample.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/gallery/GalleryExample.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/gallery/GalleryExample.java
new file mode 100644 (file)
index 0000000..b947ce3
--- /dev/null
@@ -0,0 +1,95 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.gallery;\r
+\r
+import org.eclipse.jface.viewers.ArrayContentProvider;\r
+import org.eclipse.jface.viewers.BaseLabelProvider;\r
+import org.eclipse.swt.graphics.Color;\r
+import org.eclipse.swt.layout.FillLayout;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.simantics.g2d.diagram.handler.layout.FlowLayout;\r
+import org.simantics.g2d.image.DefaultImages;\r
+import org.simantics.g2d.image.Image;\r
+import org.simantics.utils.datastructures.cache.IProvider;\r
+\r
+public class GalleryExample {\r
+\r
+    @SuppressWarnings("unchecked")\r
+    static IProvider<Image>[] content = new IProvider[] {\r
+        DefaultImages.GRAB,\r
+        DefaultImages.GRAB32,\r
+        DefaultImages.HAND,\r
+        DefaultImages.HAND32,\r
+        DefaultImages.ERROR_DECORATOR,\r
+        DefaultImages.HOURGLASS,\r
+        DefaultImages.WHEEL\r
+    };\r
+\r
+    static class LabelProvider extends BaseLabelProvider implements ILabelProvider {\r
+        @Override\r
+        public Image getImage(Object element) {\r
+            @SuppressWarnings("unchecked")\r
+            IProvider<Image> img = (IProvider<Image>) element;\r
+            return img.get();\r
+        }\r
+        @Override\r
+        public String getText(Object element) {\r
+            return element.toString();\r
+        }\r
+        \r
+        @Override\r
+        public java.awt.Image getToolTipImage(Object object) {\r
+               return null;\r
+        }\r
+        \r
+        @Override\r
+        public String getToolTipText(Object element) {\r
+                return element.toString();\r
+        }\r
+        \r
+        @Override\r
+        public Color getToolTipForegroundColor(Object object) {\r
+               return null;\r
+        }\r
+        \r
+        @Override\r
+        public Color getToolTipBackgroundColor(Object object) {\r
+               return null;\r
+        }\r
+    }\r
+\r
+    public static void main (String [] args) {\r
+        Display display = new Display ();\r
+        Shell shell = new Shell (display);\r
+        shell.setLayout(new FillLayout());\r
+        shell.setText("Gallery Example");\r
+\r
+\r
+        GalleryViewer viewer = new GalleryViewer(shell);\r
+        viewer.getControl();\r
+        viewer.setContentProvider(new ArrayContentProvider());\r
+        viewer.setLabelProvider(new LabelProvider());\r
+        viewer.setAlign(FlowLayout.Align.Left);\r
+        viewer.setInput(content);\r
+        viewer.refresh();\r
+\r
+        shell.setSize (300, 300);\r
+        shell.open ();\r
+        while (!shell.isDisposed()) {\r
+            if (!display.readAndDispatch ()) display.sleep ();\r
+        }\r
+        display.dispose ();\r
+    }\r
+\r
+\r
+}\r