1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g2d.gallery;
\r
14 import org.eclipse.jface.viewers.ArrayContentProvider;
\r
15 import org.eclipse.jface.viewers.BaseLabelProvider;
\r
16 import org.eclipse.swt.graphics.Color;
\r
17 import org.eclipse.swt.layout.FillLayout;
\r
18 import org.eclipse.swt.widgets.Display;
\r
19 import org.eclipse.swt.widgets.Shell;
\r
20 import org.simantics.g2d.diagram.handler.layout.FlowLayout;
\r
21 import org.simantics.g2d.image.DefaultImages;
\r
22 import org.simantics.g2d.image.Image;
\r
23 import org.simantics.utils.datastructures.cache.IProvider;
\r
25 public class GalleryExample {
\r
27 @SuppressWarnings("unchecked")
\r
28 static IProvider<Image>[] content = new IProvider[] {
\r
30 DefaultImages.GRAB32,
\r
32 DefaultImages.HAND32,
\r
33 DefaultImages.ERROR_DECORATOR,
\r
34 DefaultImages.HOURGLASS,
\r
38 static class LabelProvider extends BaseLabelProvider implements ILabelProvider {
\r
40 public Image getImage(Object element) {
\r
41 @SuppressWarnings("unchecked")
\r
42 IProvider<Image> img = (IProvider<Image>) element;
\r
46 public String getText(Object element) {
\r
47 return element.toString();
\r
51 public java.awt.Image getToolTipImage(Object object) {
\r
56 public String getToolTipText(Object element) {
\r
57 return element.toString();
\r
61 public Color getToolTipForegroundColor(Object object) {
\r
66 public Color getToolTipBackgroundColor(Object object) {
\r
71 public static void main (String [] args) {
\r
72 Display display = new Display ();
\r
73 Shell shell = new Shell (display);
\r
74 shell.setLayout(new FillLayout());
\r
75 shell.setText("Gallery Example");
\r
78 GalleryViewer viewer = new GalleryViewer(shell);
\r
79 viewer.getControl();
\r
80 viewer.setContentProvider(new ArrayContentProvider());
\r
81 viewer.setLabelProvider(new LabelProvider());
\r
82 viewer.setAlign(FlowLayout.Align.Left);
\r
83 viewer.setInput(content);
\r
86 shell.setSize (300, 300);
\r
88 while (!shell.isDisposed()) {
\r
89 if (!display.readAndDispatch ()) display.sleep ();
\r