]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/chassis/Tooltip.java
Testing SonarQube with Simantics Platform SDK
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / chassis / Tooltip.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * 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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.chassis;\r
13 \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
22 \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
27 \r
28 public class Tooltip extends JFrame {\r
29 \r
30         JPanel panel;\r
31         \r
32         Tooltip() {\r
33                 super();\r
34                 panel = new JPanel();\r
35                 panel.setBorder(BorderFactory.createLineBorder(Color.black));\r
36                 add(panel);\r
37                 \r
38                 addMouseListener( ml );\r
39                 // Mouse Capture\r
40 //              long eventMask = AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK;\r
41 //              Toolkit.getDefaultToolkit().addAWTEventListener( new AWTEventListener()\r
42 //              {\r
43 //                  public void eventDispatched(AWTEvent e)\r
44 //                  {\r
45 //                      System.out.println(e);\r
46 //                  }\r
47 //              }, eventMask);\r
48                 \r
49                 setFocusableWindowState(false);\r
50                 setUndecorated(true);\r
51         \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
59                 \r
60                 pack();\r
61                 setVisible( true );     \r
62         }\r
63         \r
64         public Tooltip( String...tips )\r
65         {\r
66                 this();\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
72                         panel.add( label );\r
73                 }\r
74                 pack();\r
75                 setVisible( true );\r
76         }\r
77         \r
78         public Tooltip( Component component )\r
79         {\r
80                 this();\r
81                 setContent( component );\r
82         }\r
83         \r
84         void setContent( Component component ) {\r
85                 panel.add( component, BorderLayout.CENTER );\r
86                 pack();\r
87                 setVisible( true );\r
88         }\r
89         \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
94                     }\r
95                 };\r
96                 \r
97                 public void mouseClicked(java.awt.event.MouseEvent e) {\r
98                         Tooltip.this.dispose();\r
99                 };\r
100         };\r
101 \r
102 }\r