1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\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.chassis;
\r
14 import java.awt.BorderLayout;
\r
15 import java.awt.Color;
\r
16 import java.awt.Component;
\r
17 import java.awt.GridLayout;
\r
18 import java.awt.MouseInfo;
\r
19 import java.awt.Point;
\r
20 import java.awt.event.MouseAdapter;
\r
21 import java.awt.event.MouseListener;
\r
23 import javax.swing.BorderFactory;
\r
24 import javax.swing.JFrame;
\r
25 import javax.swing.JLabel;
\r
26 import javax.swing.JPanel;
\r
28 public class Tooltip extends JFrame {
\r
34 panel = new JPanel();
\r
35 panel.setBorder(BorderFactory.createLineBorder(Color.black));
\r
38 addMouseListener( ml );
\r
40 // long eventMask = AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK;
\r
41 // Toolkit.getDefaultToolkit().addAWTEventListener( new AWTEventListener()
\r
43 // public void eventDispatched(AWTEvent e)
\r
45 // System.out.println(e);
\r
49 setFocusableWindowState(false);
\r
50 setUndecorated(true);
\r
52 setAlwaysOnTop(true);
\r
53 Color c = new Color(255, 255, 220);
\r
54 panel.setBackground( c );
\r
55 setFocusable(false);
\r
56 Point mouse = MouseInfo.getPointerInfo().getLocation();
\r
57 setLocation( mouse );
\r
58 setResizable(false);
\r
61 setVisible( true );
\r
64 public Tooltip( String...tips )
\r
67 GridLayout gl = new GridLayout(tips.length, 1, 5, 5);
\r
68 // Insets i = new Insets(3, 3, 3, 3);
\r
69 panel.setLayout( gl );
\r
70 for (String tip : tips) {
\r
71 JLabel label = new JLabel( tip );
\r
78 public Tooltip( Component component )
\r
81 setContent( component );
\r
84 void setContent( Component component ) {
\r
85 panel.add( component, BorderLayout.CENTER );
\r
90 MouseListener ml = new MouseAdapter() {
\r
91 public void mouseExited(java.awt.event.MouseEvent e) {
\r
92 if (e.getSource() == Tooltip.this) {
\r
93 Tooltip.this.dispose();
\r
97 public void mouseClicked(java.awt.event.MouseEvent e) {
\r
98 Tooltip.this.dispose();
\r