1 19 20 package org.netbeans.modules.java.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 39 public final class TooltipHack implements ActionListener { 40 41 private static TooltipHack instance; 42 43 44 private static int prevDismiss = -1; 45 46 private TooltipHack() { 47 } 48 49 55 public static void invokeTip (JComponent comp, int x, int y, int dismissDelay) { 56 final ToolTipManager ttm = ToolTipManager.sharedInstance(); 57 final int prevInit = ttm.getInitialDelay(); 58 prevDismiss = ttm.getDismissDelay(); 59 ttm.setInitialDelay(0); 60 ttm.setDismissDelay(dismissDelay); 61 62 MouseEvent fakeEvt = new MouseEvent ( 63 comp, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 64 0, x, y, 0, false); 65 ttm.mouseMoved(fakeEvt); 66 67 ttm.setInitialDelay(prevInit); 68 Timer timer = new Timer (20, instance()); 69 timer.setRepeats(false); 70 timer.start(); 71 } 72 73 76 public void actionPerformed(ActionEvent e) { 77 if (prevDismiss > 0) { 78 ToolTipManager.sharedInstance().setDismissDelay(prevDismiss); 79 prevDismiss = -1; 80 } 81 } 82 83 private static TooltipHack instance () { 84 if (instance == null) { 85 instance = new TooltipHack(); 86 } 87 return instance; 88 } 89 90 } 91 | Popular Tags |