]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/chassis/Tooltip.java
G2DParentNode handles "undefined" child bounds separately
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / chassis / Tooltip.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * 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.chassis;
13
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;
22
23 import javax.swing.BorderFactory;
24 import javax.swing.JFrame;
25 import javax.swing.JLabel;
26 import javax.swing.JPanel;
27
28 public class Tooltip extends JFrame {
29
30         JPanel panel;
31         
32         Tooltip() {
33                 super();
34                 panel = new JPanel();
35                 panel.setBorder(BorderFactory.createLineBorder(Color.black));
36                 add(panel);
37                 
38                 addMouseListener( ml );
39                 // Mouse Capture
40 //              long eventMask = AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK;
41 //              Toolkit.getDefaultToolkit().addAWTEventListener( new AWTEventListener()
42 //              {
43 //                  public void eventDispatched(AWTEvent e)
44 //                  {
45 //                      System.out.println(e);
46 //                  }
47 //              }, eventMask);
48                 
49                 setFocusableWindowState(false);
50                 setUndecorated(true);
51         
52                 setAlwaysOnTop(true);
53                 Color c = new Color(255, 255, 220);
54                 panel.setBackground( c );
55                 setFocusable(false);
56                 Point mouse = MouseInfo.getPointerInfo().getLocation();
57                 setLocation( mouse );
58                 setResizable(false);
59                 
60                 pack();
61                 setVisible( true );     
62         }
63         
64         public Tooltip( String...tips )
65         {
66                 this();
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 );
72                         panel.add( label );
73                 }
74                 pack();
75                 setVisible( true );
76         }
77         
78         public Tooltip( Component component )
79         {
80                 this();
81                 setContent( component );
82         }
83         
84         void setContent( Component component ) {
85                 panel.add( component, BorderLayout.CENTER );
86                 pack();
87                 setVisible( true );
88         }
89         
90         MouseListener ml = new MouseAdapter() {
91                 public void mouseExited(java.awt.event.MouseEvent e) {
92                     if (e.getSource() == Tooltip.this) {
93                                 Tooltip.this.dispose();
94                     }
95                 };
96                 
97                 public void mouseClicked(java.awt.event.MouseEvent e) {
98                         Tooltip.this.dispose();
99                 };
100         };
101
102 }