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