173 |
|
|
174 |
/** The last known position of the mouse cursor. */ |
/** The last known position of the mouse cursor. */ |
175 |
private static Point currentPoint; |
private static Point currentPoint; |
176 |
|
|
177 |
/** |
/** */ |
178 |
* The panel that holds the tooltip when the tooltip is displayed fully |
private static Popup popup; |
|
* inside the current container. |
|
|
*/ |
|
|
private static Container containerPanel; |
|
|
|
|
|
/** |
|
|
* The window used when the tooltip doesn't fit inside the current |
|
|
* container. |
|
|
*/ |
|
|
private static JDialog tooltipWindow; |
|
179 |
|
|
180 |
/** |
/** |
181 |
* Creates a new ToolTipManager and sets up the timers. |
* Creates a new ToolTipManager and sets up the timers. |
360 |
&& getContentPaneDeepestComponent(event) == currentComponent) |
&& getContentPaneDeepestComponent(event) == currentComponent) |
361 |
return; |
return; |
362 |
currentPoint = event.getPoint(); |
currentPoint = event.getPoint(); |
363 |
|
|
364 |
currentComponent = (Component) event.getSource(); |
currentComponent = (Component) event.getSource(); |
365 |
|
|
366 |
if (exitTimer.isRunning()) |
if (exitTimer.isRunning()) |
367 |
{ |
{ |
368 |
exitTimer.stop(); |
exitTimer.stop(); |
369 |
insideTimer.start(); |
showTip(); |
370 |
return; |
return; |
371 |
} |
} |
|
|
|
372 |
// This should always be stopped unless we have just fake-exited. |
// This should always be stopped unless we have just fake-exited. |
373 |
if (! enterTimer.isRunning()) |
if (!enterTimer.isRunning()) |
374 |
enterTimer.start(); |
enterTimer.start(); |
375 |
} |
} |
376 |
|
|
377 |
/** |
/** |
378 |
* This method is called when the mouse exits a JComponent registered with |
* This method is called when the mouse exits a JComponent registered with the |
379 |
* the ToolTipManager. When the mouse exits, the tooltip should be hidden |
* ToolTipManager. When the mouse exits, the tooltip should be hidden |
380 |
* immediately. |
* immediately. |
381 |
* |
* |
382 |
* @param event The MouseEvent. |
* @param event |
383 |
|
* The MouseEvent. |
384 |
*/ |
*/ |
385 |
public void mouseExited(MouseEvent event) |
public void mouseExited(MouseEvent event) |
386 |
{ |
{ |
391 |
currentComponent = null; |
currentComponent = null; |
392 |
hideTip(); |
hideTip(); |
393 |
|
|
394 |
if (! enterTimer.isRunning() && insideTimer.isRunning()) |
if (! enterTimer.isRunning()) |
395 |
exitTimer.start(); |
exitTimer.start(); |
396 |
if (enterTimer.isRunning()) |
if (enterTimer.isRunning()) |
397 |
enterTimer.stop(); |
enterTimer.stop(); |
452 |
void showTip() |
void showTip() |
453 |
{ |
{ |
454 |
if (!enabled || currentComponent == null || !currentComponent.isEnabled() |
if (!enabled || currentComponent == null || !currentComponent.isEnabled() |
455 |
|| (currentTip != null && currentTip.isVisible())) |
|| !currentComponent.isShowing()) |
456 |
return; |
{ |
457 |
|
popup = null; |
458 |
|
return; |
459 |
|
} |
460 |
|
|
461 |
if (currentTip == null || currentTip.getComponent() != currentComponent |
if (currentTip == null || currentTip.getComponent() != currentComponent |
462 |
&& currentComponent instanceof JComponent) |
&& currentComponent instanceof JComponent) |
463 |
currentTip = ((JComponent) currentComponent).createToolTip(); |
currentTip = ((JComponent) currentComponent).createToolTip(); |
464 |
|
|
|
currentTip.setVisible(true); |
|
|
Container parent = currentComponent.getParent(); |
|
465 |
Point p = currentPoint; |
Point p = currentPoint; |
466 |
|
Point cP = currentComponent.getLocationOnScreen(); |
467 |
Dimension dims = currentTip.getPreferredSize(); |
Dimension dims = currentTip.getPreferredSize(); |
468 |
|
|
469 |
if (parent instanceof JPopupMenu) |
JLayeredPane pane = null; |
470 |
setLightWeightPopupEnabled(((JPopupMenu) parent).isLightWeightPopupEnabled()); |
JRootPane r = ((JRootPane) SwingUtilities.getAncestorOfClass(JRootPane.class, |
471 |
else |
currentComponent)); |
472 |
setLightWeightPopupEnabled(true); |
if (r != null) |
473 |
|
pane = r.getLayeredPane(); |
474 |
if (isLightWeightPopupEnabled()) |
if (pane == null) |
475 |
{ |
return; |
476 |
JLayeredPane pane = null; |
|
477 |
JRootPane r = ((JRootPane) SwingUtilities. |
p.translate(cP.x, cP.y); |
478 |
getAncestorOfClass(JRootPane.class, currentComponent)); |
adjustLocation(p, pane, dims); |
479 |
if (r != null) |
|
480 |
pane = r.getLayeredPane(); |
currentTip.setBounds(0, 0, dims.width, dims.height); |
481 |
if (pane == null) |
|
482 |
return; |
PopupFactory factory = PopupFactory.getSharedInstance(); |
483 |
|
popup = factory.getPopup(currentComponent, currentTip, p.x, p.y); |
484 |
if (containerPanel != null) |
popup.show(); |
|
hideTip(); |
|
|
|
|
|
containerPanel = new Panel(); |
|
|
JRootPane root = new JRootPane(); |
|
|
root.getContentPane().add(currentTip); |
|
|
containerPanel.add(root); |
|
|
|
|
|
LayoutManager lm = containerPanel.getLayout(); |
|
|
if (lm instanceof FlowLayout) |
|
|
{ |
|
|
FlowLayout fm = (FlowLayout) lm; |
|
|
fm.setVgap(0); |
|
|
fm.setHgap(0); |
|
|
} |
|
|
|
|
|
p = SwingUtilities.convertPoint(currentComponent, p, pane); |
|
|
p = adjustLocation(p, pane, dims); |
|
|
|
|
|
pane.add(containerPanel); |
|
|
containerPanel.setBounds(p.x, p.y, dims.width, dims.height); |
|
|
currentTip.setBounds(0, 0, dims.width, dims.height); |
|
|
containerPanel.validate(); |
|
|
containerPanel.repaint(); |
|
|
} |
|
|
else if (currentComponent.isShowing()) |
|
|
{ |
|
|
SwingUtilities.convertPointToScreen(p, currentComponent); |
|
|
p = adjustLocation(p, SwingUtilities.getWindowAncestor(currentComponent), |
|
|
dims); |
|
|
|
|
|
tooltipWindow = new JDialog(); |
|
|
tooltipWindow.setContentPane(currentTip); |
|
|
tooltipWindow.setUndecorated(true); |
|
|
tooltipWindow.getRootPane(). |
|
|
setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); |
|
|
tooltipWindow.pack(); |
|
|
tooltipWindow.setBounds(p.x, p.y, dims.width, dims.height); |
|
|
tooltipWindow.show(); |
|
|
tooltipWindow.validate(); |
|
|
tooltipWindow.repaint(); |
|
|
currentTip.revalidate(); |
|
|
currentTip.repaint(); |
|
|
} |
|
485 |
} |
} |
486 |
|
|
487 |
/** |
/** |
501 |
if (p.y + d.height < c.getHeight()) |
if (p.y + d.height < c.getHeight()) |
502 |
p.y += d.height; |
p.y += d.height; |
503 |
if (p.y + d.height > c.getHeight()) |
if (p.y + d.height > c.getHeight()) |
504 |
p.y -= d.height*2; |
p.y -= d.height; |
505 |
|
|
506 |
return p; |
return p; |
507 |
} |
} |
512 |
*/ |
*/ |
513 |
void hideTip() |
void hideTip() |
514 |
{ |
{ |
515 |
if (currentTip == null || ! currentTip.isVisible() || ! enabled) |
if (popup != null) |
516 |
return; |
popup.hide(); |
|
currentTip.setVisible(false); |
|
|
if (containerPanel != null) |
|
|
{ |
|
|
Container parent = containerPanel.getParent(); |
|
|
if (parent == null) |
|
|
return; |
|
|
parent.remove(containerPanel); |
|
|
|
|
|
parent = currentTip.getParent(); |
|
|
if (parent == null) |
|
|
return; |
|
|
parent.remove(currentTip); |
|
|
containerPanel = null; |
|
|
} |
|
|
if (tooltipWindow != null) |
|
|
{ |
|
|
tooltipWindow.hide(); |
|
|
tooltipWindow.dispose(); |
|
|
tooltipWindow = null; |
|
|
} |
|
|
currentTip = null; |
|
517 |
} |
} |
518 |
|
|
519 |
/** |
/** |