1 19 20 package org.netbeans.modules.retouche.navigation.base; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.awt.event.MouseEvent ; 25 import javax.swing.JComponent ; 26 import javax.swing.Timer ; 27 import javax.swing.ToolTipManager ; 28 29 44 public final class TooltipHack implements ActionListener { 45 46 private static TooltipHack instance; 47 48 49 private static int prevDismiss = -1; 50 51 private TooltipHack() { 52 } 53 54 60 public static void invokeTip (JComponent comp, int x, int y, int dismissDelay) { 61 final ToolTipManager ttm = ToolTipManager.sharedInstance(); 62 final int prevInit = ttm.getInitialDelay(); 63 prevDismiss = ttm.getDismissDelay(); 64 ttm.setInitialDelay(0); 65 ttm.setDismissDelay(dismissDelay); 66 67 MouseEvent fakeEvt = new MouseEvent ( 68 comp, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 69 0, x, y, 0, false); 70 ttm.mouseMoved(fakeEvt); 71 72 ttm.setInitialDelay(prevInit); 73 Timer timer = new Timer (20, instance()); 74 timer.setRepeats(false); 75 timer.start(); 76 } 77 78 81 public void actionPerformed(ActionEvent e) { 82 if (prevDismiss > 0) { 83 ToolTipManager.sharedInstance().setDismissDelay(prevDismiss); 84 prevDismiss = -1; 85 } 86 } 87 88 private static TooltipHack instance () { 89 if (instance == null) { 90 instance = new TooltipHack(); 91 } 92 return instance; 93 } 94 95 } 96 | Popular Tags |