KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > awt > tooltips > TipWindow


1 /*
2  */

3 package com.sshtools.ui.awt.tooltips;
4
5 import java.awt.Component JavaDoc;
6 import java.awt.Dimension JavaDoc;
7 import java.awt.Frame JavaDoc;
8 import java.awt.Graphics JavaDoc;
9 import java.awt.GridLayout JavaDoc;
10 import java.awt.IllegalComponentStateException JavaDoc;
11 import java.awt.Insets JavaDoc;
12 import java.awt.Point JavaDoc;
13 import java.awt.Window JavaDoc;
14
15 import com.sshtools.ui.awt.ImageTextLabel;
16
17
18 class TipWindow extends Window JavaDoc {
19   private ImageTextLabel textLabel;
20   private long lastShow;
21   private boolean dismissed;
22   private Component JavaDoc component;
23   private String JavaDoc text;
24
25   TipWindow(Frame JavaDoc owner) {
26     super(owner);
27     textLabel = new ImageTextLabel() {
28       public void paint(Graphics JavaDoc g) {
29         super.paint(g);
30         g.setColor(getForeground());
31         Dimension JavaDoc s = getSize();
32         g.drawRect(0, 0, s.width -1 , s.height -1);
33       }
34     };
35     textLabel.setMargin(new Insets JavaDoc(2, 2, 2, 2));
36     setLayout(new GridLayout JavaDoc(1, 1));
37     add(textLabel);
38   }
39   
40   boolean isDismissed() {
41     return dismissed;
42   }
43
44   boolean isOutOfDate() {
45     return (System.currentTimeMillis() > (lastShow + 5000));
46   }
47   
48   synchronized void dismiss() {
49     dismissed = true;
50     hide();
51   }
52
53   synchronized void popup(int x, int y, Component JavaDoc component, String JavaDoc text) {
54      
55     invalidate();
56     textLabel.setText(text);
57     textLabel.setForeground(ToolTipManager.getInstance().foreground);
58     textLabel.setBackground(ToolTipManager.getInstance().background);
59     validate();
60     pack();
61     try {
62         if(x != -1 && y != -1) {
63             setLocation(x + 8, y + 8);
64         }
65         else {
66             Point JavaDoc p = component.getLocationOnScreen();
67             Dimension JavaDoc s = component.getSize();
68             setLocation(p.x + 8, p.y + s.height + 8);
69         }
70         setVisible(true);
71         toFront();
72         lastShow = System.currentTimeMillis();
73         dismissed = false;
74     }
75     catch(IllegalComponentStateException JavaDoc icse) {
76       
77     }
78   }
79 }
Popular Tags