Search in sources :

Example 1 with PopupFactory

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;
}
Also used : PopupFactory(javax.swing.PopupFactory) Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Aggregations

Dimension (java.awt.Dimension)1 GraphicsConfiguration (java.awt.GraphicsConfiguration)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 PopupFactory (javax.swing.PopupFactory)1