1 3 package com.sshtools.ui.awt.tooltips; 4 5 import java.awt.Component ; 6 import java.awt.Frame ; 7 8 import com.sshtools.ui.awt.UIUtil; 9 10 class WaitThread extends Thread { 11 TipWindow tipWindow; 12 Component component; 13 int tx = -1; 14 int ty = -1; 15 String text; 16 Frame lastSharedFrame; 17 18 WaitThread() { 19 super("ToolTip"); 21 } 22 23 synchronized void requestToolTip(Component component, String text) { 24 requestToolTip(component, -1, -1, text); 25 } 26 27 synchronized void requestToolTip(Component component, int x, int y, String text) { 28 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 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 ie) { 66 67 } 68 } 69 } 70 71 74 public void dismissToolTip() { 75 if (tipWindow != null) { 76 tipWindow.dismiss(); 77 } 78 } 79 } | Popular Tags |