KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  */

3 package com.sshtools.ui.awt.tooltips;
4
5 import java.awt.Component JavaDoc;
6 import java.awt.Frame JavaDoc;
7
8 import com.sshtools.ui.awt.UIUtil;
9
10 class WaitThread extends Thread JavaDoc {
11     TipWindow tipWindow;
12     Component JavaDoc component;
13     int tx = -1;
14     int ty = -1;
15     String JavaDoc text;
16     Frame JavaDoc lastSharedFrame;
17
18     WaitThread() {
19         super("ToolTip"); //$NON-NLS-1$
20

21     }
22
23     synchronized void requestToolTip(Component JavaDoc component, String JavaDoc text) {
24         requestToolTip(component, -1, -1, text);
25     }
26
27     synchronized void requestToolTip(Component JavaDoc component, int x, int y, String JavaDoc text) {
28         // if(!isAlive()) {
29
// start();
30
// }
31
this.component = component;
32         this.tx = x;
33         this.ty = y;
34         this.text = text;
35         if (component == null || text == null) {
36             dismissToolTip();
37         }
38     }
39
40     public void run() {
41         while (true) {
42             try {
43                 Thread.sleep(500);
44                 synchronized (this) {
45                     if (component != null) {
46                         if (tipWindow == null || lastSharedFrame == null
47                                         || lastSharedFrame != ToolTipManager.getInstance().getSharedFrame()) {
48                             lastSharedFrame = ToolTipManager.getInstance().getSharedFrame();
49                             Frame JavaDoc f = UIUtil.getFrameAncestor(component);
50                             if (tipWindow != null) {
51                                 tipWindow.dispose();
52                             }
53                             f = f == null ? ToolTipManager.getInstance().getSharedFrame() : f;
54                             tipWindow = new TipWindow(f);
55                         }
56                         tipWindow.popup(tx, ty, component, text);
57                         component = null;
58                         text = null;
59                     } else {
60                         if (tipWindow != null && tipWindow.isOutOfDate()) {
61                             dismissToolTip();
62                         }
63                     }
64                 }
65             } catch (InterruptedException JavaDoc ie) {
66
67             }
68         }
69     }
70
71     /**
72      *
73      */

74     public void dismissToolTip() {
75         if (tipWindow != null) {
76             tipWindow.dismiss();
77         }
78     }
79 }
Popular Tags