| 1 3 package com.sshtools.ui.awt.tooltips; 4 5 import java.awt.Component ; 6 import java.awt.Dimension ; 7 import java.awt.Frame ; 8 import java.awt.Graphics ; 9 import java.awt.GridLayout ; 10 import java.awt.IllegalComponentStateException ; 11 import java.awt.Insets ; 12 import java.awt.Point ; 13 import java.awt.Window ; 14 15 import com.sshtools.ui.awt.ImageTextLabel; 16 17 18 class TipWindow extends Window { 19 private ImageTextLabel textLabel; 20 private long lastShow; 21 private boolean dismissed; 22 private Component component; 23 private String text; 24 25 TipWindow(Frame owner) { 26 super(owner); 27 textLabel = new ImageTextLabel() { 28 public void paint(Graphics g) { 29 super.paint(g); 30 g.setColor(getForeground()); 31 Dimension s = getSize(); 32 g.drawRect(0, 0, s.width -1 , s.height -1); 33 } 34 }; 35 textLabel.setMargin(new Insets (2, 2, 2, 2)); 36 setLayout(new GridLayout (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 component, String 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 p = component.getLocationOnScreen(); 67 Dimension 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 icse) { 76 77 } 78 } 79 } | Popular Tags |