use of javax.swing.PopupFactory in project gephi by gephi.
the class RichTooltip method showTooltip.
public void showTooltip(JComponent component, Point screenLocation) {
if (component == null || !component.isShowing()) {
return;
}
Dimension size;
Point location = new Point();
GraphicsConfiguration gc;
gc = component.getGraphicsConfiguration();
Rectangle sBounds = gc.getBounds();
Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
// Take into account screen insets, decrease viewport
sBounds.x += screenInsets.left;
sBounds.y += screenInsets.top;
sBounds.width -= (screenInsets.left + screenInsets.right);
sBounds.height -= (screenInsets.top + screenInsets.bottom);
hideTooltip();
JRichTooltipPanel tip = new JRichTooltipPanel(this);
size = tip.getPreferredSize();
// display directly below or above it
location.x = screenLocation.x + 10;
location.y = screenLocation.y - 10;
if ((location.y + size.height) > (sBounds.y + sBounds.height)) {
location.y = screenLocation.y - size.height;
}
// Tweak the X location to not overflow the screen
if (location.x < sBounds.x) {
location.x = sBounds.x;
} else if (location.x - sBounds.x + size.width > sBounds.width) {
location.x = sBounds.x + Math.max(0, sBounds.width - size.width);
}
PopupFactory popupFactory = PopupFactory.getSharedInstance();
tipWindow = popupFactory.getPopup(component, tip, location.x, location.y);
tipWindow.show();
tipShowing = true;
}
Aggregations