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