Search in sources :

Example 1 with TooltipEvent

use of com.intellij.ide.TooltipEvent in project intellij-community by JetBrains.

the class AbstractValueHint method showHint.

protected boolean showHint(final JComponent component) {
    myInsideShow = true;
    if (myCurrentHint != null) {
        myCurrentHint.hide();
    }
    myCurrentHint = new LightweightHint(component) {

        @Override
        protected boolean canAutoHideOn(TooltipEvent event) {
            InputEvent inputEvent = event.getInputEvent();
            if (inputEvent instanceof MouseEvent) {
                Component comp = inputEvent.getComponent();
                if (comp instanceof EditorComponentImpl) {
                    EditorImpl editor = ((EditorComponentImpl) comp).getEditor();
                    return !isInsideCurrentRange(editor, ((MouseEvent) inputEvent).getPoint());
                }
            }
            return true;
        }
    };
    myCurrentHint.addHintListener(new HintListener() {

        @Override
        public void hintHidden(EventObject event) {
            if (myHideRunnable != null && !myInsideShow) {
                myHideRunnable.run();
            }
            onHintHidden();
        }
    });
    // editor may be disposed before later invokator process this action
    if (myEditor.isDisposed() || myEditor.getComponent().getRootPane() == null) {
        return false;
    }
    Point p = HintManagerImpl.getHintPosition(myCurrentHint, myEditor, myEditor.xyToLogicalPosition(myPoint), HintManager.UNDER);
    HintHint hint = HintManagerImpl.createHintHint(myEditor, p, myCurrentHint, HintManager.UNDER, true);
    hint.setShowImmediately(true);
    HintManagerImpl.getInstanceImpl().showEditorHint(myCurrentHint, myEditor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false, hint);
    myInsideShow = false;
    return true;
}
Also used : EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) TooltipEvent(com.intellij.ide.TooltipEvent) EditorComponentImpl(com.intellij.openapi.editor.impl.EditorComponentImpl) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) RelativePoint(com.intellij.ui.awt.RelativePoint) EventObject(java.util.EventObject)

Example 2 with TooltipEvent

use of com.intellij.ide.TooltipEvent in project intellij-community by JetBrains.

the class LightweightHint method show.

/**
   * Shows the hint in the layered pane. Coordinates <code>x</code> and <code>y</code>
   * are in <code>parentComponent</code> coordinate system. Note that the component
   * appears on 250 layer.
   */
@Override
public void show(@NotNull final JComponent parentComponent, final int x, final int y, final JComponent focusBackComponent, @NotNull final HintHint hintHint) {
    myParentComponent = parentComponent;
    myHintHint = hintHint;
    myFocusBackComponent = focusBackComponent;
    LOG.assertTrue(myParentComponent.isShowing());
    myEscListener = new MyEscListener();
    myComponent.registerKeyboardAction(myEscListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    myComponent.registerKeyboardAction(myEscListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_FOCUSED);
    final JLayeredPane layeredPane = parentComponent.getRootPane().getLayeredPane();
    myComponent.validate();
    if (!myForceShowAsPopup && (myForceLightweightPopup || fitsLayeredPane(layeredPane, myComponent, new RelativePoint(parentComponent, new Point(x, y)), hintHint))) {
        beforeShow();
        final Dimension preferredSize = myComponent.getPreferredSize();
        if (hintHint.isAwtTooltip()) {
            IdeTooltip tooltip = new IdeTooltip(hintHint.getOriginalComponent(), hintHint.getOriginalPoint(), myComponent, hintHint, myComponent) {

                @Override
                protected boolean canAutohideOn(TooltipEvent event) {
                    if (!LightweightHint.this.canAutoHideOn(event)) {
                        return false;
                    } else if (event.getInputEvent() instanceof MouseEvent) {
                        return !(hintHint.isContentActive() && event.isIsEventInsideBalloon());
                    } else if (event.getAction() != null) {
                        return false;
                    } else {
                        return true;
                    }
                }

                @Override
                protected void onHidden() {
                    fireHintHidden();
                    TooltipController.getInstance().resetCurrent();
                }

                @Override
                public boolean canBeDismissedOnTimeout() {
                    return false;
                }
            }.setToCenterIfSmall(hintHint.isMayCenterTooltip()).setPreferredPosition(hintHint.getPreferredPosition()).setHighlighterType(hintHint.isHighlighterType()).setTextForeground(hintHint.getTextForeground()).setTextBackground(hintHint.getTextBackground()).setBorderColor(hintHint.getBorderColor()).setBorderInsets(hintHint.getBorderInsets()).setFont(hintHint.getTextFont()).setCalloutShift(hintHint.getCalloutShift()).setPositionChangeShift(hintHint.getPositionChangeX(), hintHint.getPositionChangeY()).setExplicitClose(hintHint.isExplicitClose()).setRequestFocus(hintHint.isRequestFocus()).setHint(true);
            myComponent.validate();
            myCurrentIdeTooltip = IdeTooltipManager.getInstance().show(tooltip, hintHint.isShowImmediately(), hintHint.isAnimationEnabled());
        } else {
            final Point layeredPanePoint = SwingUtilities.convertPoint(parentComponent, x, y, layeredPane);
            myComponent.setBounds(layeredPanePoint.x, layeredPanePoint.y, preferredSize.width, preferredSize.height);
            layeredPane.add(myComponent, JLayeredPane.POPUP_LAYER);
            myComponent.validate();
            myComponent.repaint();
        }
    } else {
        myIsRealPopup = true;
        Point actualPoint = new Point(x, y);
        JComponent actualComponent = new OpaquePanel(new BorderLayout());
        actualComponent.add(myComponent, BorderLayout.CENTER);
        if (isAwtTooltip()) {
            int inset = BalloonImpl.getNormalInset();
            actualComponent.setBorder(new LineBorder(hintHint.getTextBackground(), inset));
            actualComponent.setBackground(hintHint.getTextBackground());
            actualComponent.validate();
        }
        myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(actualComponent, myFocusRequestor).setRequestFocus(myFocusRequestor != null).setFocusable(myFocusRequestor != null).setResizable(myResizable).setMovable(myTitle != null).setTitle(myTitle).setModalContext(false).setShowShadow(isRealPopup() && !isForceHideShadow()).setCancelKeyEnabled(false).setCancelOnClickOutside(myCancelOnClickOutside).setCancelCallback(() -> {
            onPopupCancel();
            return true;
        }).setCancelOnOtherWindowOpen(myCancelOnOtherWindowOpen).createPopup();
        beforeShow();
        myPopup.show(new RelativePoint(myParentComponent, new Point(actualPoint.x, actualPoint.y)));
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) LineBorder(javax.swing.border.LineBorder) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) OpaquePanel(com.intellij.ui.components.panels.OpaquePanel) RelativePoint(com.intellij.ui.awt.RelativePoint) TooltipEvent(com.intellij.ide.TooltipEvent) IdeTooltip(com.intellij.ide.IdeTooltip)

Aggregations

TooltipEvent (com.intellij.ide.TooltipEvent)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 IdeTooltip (com.intellij.ide.IdeTooltip)1 EditorMouseEvent (com.intellij.openapi.editor.event.EditorMouseEvent)1 EditorComponentImpl (com.intellij.openapi.editor.impl.EditorComponentImpl)1 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)1 OpaquePanel (com.intellij.ui.components.panels.OpaquePanel)1 MouseEvent (java.awt.event.MouseEvent)1 EventObject (java.util.EventObject)1 LineBorder (javax.swing.border.LineBorder)1