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 java.awt.Canvas;
\r
15 import java.awt.Color;
\r
16 import java.awt.Dimension;
\r
17 import java.awt.Frame;
\r
18 import java.awt.Graphics;
\r
19 import java.awt.Image;
\r
21 import javax.swing.BorderFactory;
\r
22 import javax.swing.BoxLayout;
\r
23 import javax.swing.JLabel;
\r
24 import javax.swing.JPanel;
\r
26 import org.simantics.g2d.element.IElement;
\r
27 import org.simantics.g2d.tooltip.AWTTooltipProvider;
\r
28 import org.simantics.utils.datastructures.hints.IHintContext.Key;
\r
29 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
\r
32 * GalleryViewers tooltip provider
\r
34 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
37 public class GalleryTooltipProvider extends AWTTooltipProvider {
\r
39 public static Key TOOLTIP_TEXT = new KeyOf(String.class, "TOOLTIP_TEXT");
\r
40 public static Key TOOLTIP_IMAGE = new KeyOf(Image.class, "TOOLTIP_IMAGE");
\r
43 public void constructPopup(Frame frame,IElement element) {
\r
44 String text = element.getHint(TOOLTIP_TEXT);
\r
45 final Image image = element.getHint(TOOLTIP_IMAGE);
\r
46 if (text == null && image == null)
\r
49 frame.setLayout(new BoxLayout(frame, BoxLayout.X_AXIS));
\r
50 JPanel panel = new JPanel();
\r
51 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
\r
52 Color c = new Color(255, 255, 220);
\r
53 panel.setBackground(c);
\r
54 panel.setBorder(BorderFactory.createLineBorder(Color.black));
\r
56 if (image != null) {
\r
57 Canvas canvas = new Canvas() {
\r
58 private static final long serialVersionUID = -7357041194563374338L;
\r
61 public void paint(Graphics g) {
\r
63 g.drawImage(image, 0, 0, null);
\r
67 public Dimension getSize() {
\r
68 return new Dimension(image.getWidth(null), image.getHeight(null));
\r
72 public Dimension getSize(Dimension rv) {
\r
74 rv = new Dimension();
\r
75 rv.width = image.getWidth(null);
\r
76 rv.height = image.getHeight(null);
\r
83 JLabel label = new JLabel(text);
\r