]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/gallery/GalleryExample.java
Fixed invalid comparisons which were identified by Eclipse IDE 2018-09
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / gallery / GalleryExample.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.gallery;
13
14 import org.eclipse.jface.viewers.ArrayContentProvider;
15 import org.eclipse.jface.viewers.BaseLabelProvider;
16 import org.eclipse.swt.graphics.Color;
17 import org.eclipse.swt.layout.FillLayout;
18 import org.eclipse.swt.widgets.Display;
19 import org.eclipse.swt.widgets.Shell;
20 import org.simantics.g2d.diagram.handler.layout.FlowLayout;
21 import org.simantics.g2d.image.DefaultImages;
22 import org.simantics.g2d.image.Image;
23 import org.simantics.utils.datastructures.cache.IProvider;
24
25 public class GalleryExample {
26
27     @SuppressWarnings("unchecked")
28     static IProvider<Image>[] content = new IProvider[] {
29         DefaultImages.GRAB,
30         DefaultImages.GRAB32,
31         DefaultImages.HAND,
32         DefaultImages.HAND32,
33         DefaultImages.ERROR_DECORATOR,
34         DefaultImages.HOURGLASS,
35         DefaultImages.WHEEL
36     };
37
38     static class LabelProvider extends BaseLabelProvider implements ILabelProvider {
39         @Override
40         public Image getImage(Object element) {
41             @SuppressWarnings("unchecked")
42             IProvider<Image> img = (IProvider<Image>) element;
43             return img.get();
44         }
45         @Override
46         public String getText(Object element) {
47             return element.toString();
48         }
49         
50         @Override
51         public java.awt.Image getToolTipImage(Object object) {
52                 return null;
53         }
54         
55         @Override
56         public String getToolTipText(Object element) {
57                  return element.toString();
58         }
59         
60         @Override
61         public Color getToolTipForegroundColor(Object object) {
62                 return null;
63         }
64         
65         @Override
66         public Color getToolTipBackgroundColor(Object object) {
67                 return null;
68         }
69     }
70
71     public static void main (String [] args) {
72         Display display = new Display ();
73         Shell shell = new Shell (display);
74         shell.setLayout(new FillLayout());
75         shell.setText("Gallery Example");
76
77
78         GalleryViewer viewer = new GalleryViewer(shell);
79         viewer.getControl();
80         viewer.setContentProvider(new ArrayContentProvider());
81         viewer.setLabelProvider(new LabelProvider());
82         viewer.setAlign(FlowLayout.Align.Left);
83         viewer.setInput(content);
84         viewer.refresh();
85
86         shell.setSize (300, 300);
87         shell.open ();
88         while (!shell.isDisposed()) {
89             if (!display.readAndDispatch ()) display.sleep ();
90         }
91         display.dispose ();
92     }
93
94
95 }