471 |
&& currentComponent instanceof JComponent) |
&& currentComponent instanceof JComponent) |
472 |
currentTip = ((JComponent) currentComponent).createToolTip(); |
currentTip = ((JComponent) currentComponent).createToolTip(); |
473 |
|
|
474 |
|
Container parent = currentComponent.getParent(); |
475 |
|
if (parent instanceof JPopupMenu) |
476 |
|
setLightWeightPopupEnabled(((JPopupMenu) parent).isLightWeightPopupEnabled()); |
477 |
|
|
478 |
Point p = currentPoint; |
Point p = currentPoint; |
479 |
Dimension dims = currentTip.getPreferredSize(); |
Dimension dims = currentTip.getPreferredSize(); |
|
if (canToolTipFit(currentTip)) |
|
|
{ |
|
|
JLayeredPane pane = ((JRootPane) SwingUtilities. |
|
|
getAncestorOfClass(JRootPane.class, currentComponent)).getLayeredPane(); |
|
|
|
|
|
// This should never happen, but just in case. |
|
|
if (pane == null) |
|
|
return; |
|
|
|
|
|
if (containerPanel != null) |
|
|
hideTip(); |
|
|
containerPanel = new Panel(); |
|
480 |
if (isLightWeightPopupEnabled()) |
if (isLightWeightPopupEnabled()) |
481 |
{ |
{ |
482 |
|
JLayeredPane pane = ((JRootPane) SwingUtilities. |
483 |
|
getAncestorOfClass(JRootPane.class, currentComponent)). |
484 |
|
getLayeredPane(); |
485 |
|
|
486 |
|
// This should never happen, but just in case. |
487 |
|
if (pane == null) |
488 |
|
return; |
489 |
|
|
490 |
|
if (containerPanel != null) |
491 |
|
hideTip(); |
492 |
|
containerPanel = new Panel(); |
493 |
JRootPane root = new JRootPane(); |
JRootPane root = new JRootPane(); |
494 |
root.getContentPane().add(currentTip); |
root.getContentPane().add(currentTip); |
495 |
containerPanel.add(root); |
containerPanel.add(root); |
|
} |
|
|
else |
|
|
containerPanel.add(currentTip); |
|
|
|
|
|
LayoutManager lm = containerPanel.getLayout(); |
|
|
if (lm instanceof FlowLayout) |
|
|
{ |
|
|
FlowLayout fm = (FlowLayout) lm; |
|
|
fm.setVgap(0); |
|
|
fm.setHgap(0); |
|
|
} |
|
|
p = getGoodPoint(p, pane, currentTip, dims); |
|
|
pane.add(containerPanel); |
|
|
containerPanel.setBounds(p.x, p.y, dims.width, dims.height); |
|
|
currentTip.setBounds(0, 0, dims.width, dims.height); |
|
496 |
|
|
497 |
pane.revalidate(); |
LayoutManager lm = containerPanel.getLayout(); |
498 |
pane.repaint(); |
if (lm instanceof FlowLayout) |
499 |
|
{ |
500 |
|
FlowLayout fm = (FlowLayout) lm; |
501 |
|
fm.setVgap(0); |
502 |
|
fm.setHgap(0); |
503 |
|
} |
504 |
|
|
505 |
|
p = getGoodPoint(currentPoint, pane, currentTip, dims); |
506 |
|
pane.add(containerPanel); |
507 |
|
containerPanel.setBounds(p.x, p.y, dims.width, dims.height); |
508 |
|
currentTip.setBounds(0, 0, dims.width, dims.height); |
509 |
|
pane.revalidate(); |
510 |
|
pane.repaint(); |
511 |
} |
} |
512 |
else if (currentComponent.isShowing()) |
else if (currentComponent.isShowing()) |
513 |
{ |
{ |
515 |
tooltipWindow = new JDialog(); |
tooltipWindow = new JDialog(); |
516 |
tooltipWindow.setContentPane(currentTip); |
tooltipWindow.setContentPane(currentTip); |
517 |
tooltipWindow.setUndecorated(true); |
tooltipWindow.setUndecorated(true); |
518 |
tooltipWindow.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); |
tooltipWindow.getRootPane(). |
519 |
tooltipWindow.setFocusable(false); |
setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); |
520 |
tooltipWindow.pack(); |
tooltipWindow.pack(); |
521 |
tooltipWindow.setBounds(p.x, p.y, dims.width, dims.height); |
tooltipWindow.setBounds(p.x, p.y, dims.width, dims.height); |
522 |
tooltipWindow.show(); |
tooltipWindow.show(); |
523 |
} |
} |
524 |
currentTip.setVisible(true); |
currentTip.setVisible(true); |
525 |
|
currentTip.revalidate(); |
526 |
|
currentTip.repaint(); |
527 |
} |
} |
528 |
|
|
529 |
/** |
/** |
611 |
Component target = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y); |
Component target = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y); |
612 |
return target; |
return target; |
613 |
} |
} |
|
|
|
|
/** |
|
|
* This method returns whether the ToolTip can fit in the first |
|
|
* RootPaneContainer up from the currentComponent. |
|
|
* |
|
|
* @param tip The ToolTip. |
|
|
* |
|
|
* @return Whether the ToolTip can fit. |
|
|
*/ |
|
|
private boolean canToolTipFit(JToolTip tip) |
|
|
{ |
|
|
JRootPane root = (JRootPane) SwingUtilities.getAncestorOfClass(JRootPane.class, |
|
|
currentComponent); |
|
|
if (root == null) |
|
|
return false; |
|
|
Dimension pref = tip.getPreferredSize(); |
|
|
Dimension rootSize = root.getSize(); |
|
|
if (rootSize.width > pref.width && rootSize.height > pref.height) |
|
|
return true; |
|
|
return false; |
|
|
} |
|
614 |
} |
} |