Search in sources :

Example 6 with RelativePoint

use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.

the class StudyUtils method computeLocation.

public static RelativePoint computeLocation(Editor editor) {
    final Rectangle visibleRect = editor.getComponent().getVisibleRect();
    Point point = new Point(visibleRect.x + visibleRect.width + 10, visibleRect.y + 10);
    return new RelativePoint(editor.getComponent(), point);
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 7 with RelativePoint

use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.

the class ActionToolbarImpl method showAutoPopup.

private void showAutoPopup() {
    if (isPopupShowing())
        return;
    final ActionGroup group;
    if (myOrientation == SwingConstants.HORIZONTAL) {
        group = myActionGroup;
    } else {
        final DefaultActionGroup outside = new DefaultActionGroup();
        for (int i = myFirstOutsideIndex; i < myVisibleActions.size(); i++) {
            outside.add(myVisibleActions.get(i));
        }
        group = outside;
    }
    PopupToolbar popupToolbar = new PopupToolbar(myPlace, group, true, myDataManager, myActionManager, myUpdater.getKeymapManager(), this) {

        @Override
        protected void onOtherActionPerformed() {
            hidePopup();
        }

        @Override
        protected DataContext getDataContext() {
            return ActionToolbarImpl.this.getDataContext();
        }
    };
    popupToolbar.setLayoutPolicy(NOWRAP_LAYOUT_POLICY);
    popupToolbar.updateActionsImmediately();
    Point location;
    if (myOrientation == SwingConstants.HORIZONTAL) {
        location = getLocationOnScreen();
    } else {
        location = getLocationOnScreen();
        location.y = location.y + getHeight() - popupToolbar.getPreferredSize().height;
    }
    final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(popupToolbar, null);
    builder.setResizable(false).setMovable(// fit the screen automatically
    true).setRequestFocus(false).setTitle(null).setCancelOnClickOutside(true).setCancelOnOtherWindowOpen(true).setCancelCallback(() -> {
        final boolean toClose = myActionManager.isActionPopupStackEmpty();
        if (toClose) {
            myUpdater.updateActions(false, true);
        }
        return toClose;
    }).setCancelOnMouseOutCallback(new MouseChecker() {

        @Override
        public boolean check(final MouseEvent event) {
            return myAutoPopupRec != null && myActionManager.isActionPopupStackEmpty() && !new RelativeRectangle(ActionToolbarImpl.this, myAutoPopupRec).contains(new RelativePoint(event));
        }
    });
    builder.addListener(new JBPopupAdapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            processClosed();
        }
    });
    myPopup = builder.createPopup();
    final AnActionListener.Adapter listener = new AnActionListener.Adapter() {

        @Override
        public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
            final JBPopup popup = myPopup;
            if (popup != null && !popup.isDisposed() && popup.isVisible()) {
                popup.cancel();
            }
        }
    };
    ActionManager.getInstance().addAnActionListener(listener);
    Disposer.register(myPopup, popupToolbar);
    Disposer.register(popupToolbar, new Disposable() {

        @Override
        public void dispose() {
            ActionManager.getInstance().removeAnActionListener(listener);
        }
    });
    myPopup.showInScreenCoordinates(this, location);
    final Window window = SwingUtilities.getWindowAncestor(this);
    if (window != null) {
        final ComponentAdapter componentAdapter = new ComponentAdapter() {

            @Override
            public void componentResized(final ComponentEvent e) {
                hidePopup();
            }

            @Override
            public void componentMoved(final ComponentEvent e) {
                hidePopup();
            }

            @Override
            public void componentShown(final ComponentEvent e) {
                hidePopup();
            }

            @Override
            public void componentHidden(final ComponentEvent e) {
                hidePopup();
            }
        };
        window.addComponentListener(componentAdapter);
        Disposer.register(popupToolbar, new Disposable() {

            @Override
            public void dispose() {
                window.removeComponentListener(componentAdapter);
            }
        });
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) ComponentAdapter(java.awt.event.ComponentAdapter) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 8 with RelativePoint

use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.

the class JBTabsImpl method processDropOver.

@Override
public void processDropOver(TabInfo over, RelativePoint point) {
    int index = myLayout.getDropIndexFor(point.getPoint(this));
    if (index != getDropInfoIndex()) {
        setDropInfoIndex(index);
        relayout(true, false);
    }
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 9 with RelativePoint

use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.

the class JBTabsImpl method startDropOver.

@Override
public Image startDropOver(TabInfo tabInfo, RelativePoint point) {
    myDropInfo = tabInfo;
    int index = myLayout.getDropIndexFor(point.getPoint(this));
    setDropInfoIndex(index);
    addTab(myDropInfo, index, true, true);
    TabLabel label = myInfo2Label.get(myDropInfo);
    Dimension size = label.getPreferredSize();
    label.setBounds(0, 0, size.width, size.height);
    BufferedImage img = UIUtil.createImage(this, size.width, size.height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = img.createGraphics();
    label.paintOffscreen(g);
    g.dispose();
    relayout(true, false);
    return img;
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) BufferedImage(java.awt.image.BufferedImage)

Example 10 with RelativePoint

use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.

the class Callout method showTextBelow.

public static void showTextBelow(JComponent component, String text) {
    final RelativePoint calloutPoint = RelativePoint.getSouthWestOf(component);
    calloutPoint.getPoint().x += 5;
    Callout.showText(calloutPoint, Callout.SOUTH_EAST, text);
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint)

Aggregations

RelativePoint (com.intellij.ui.awt.RelativePoint)127 Project (com.intellij.openapi.project.Project)16 Balloon (com.intellij.openapi.ui.popup.Balloon)15 JBPopup (com.intellij.openapi.ui.popup.JBPopup)15 NotNull (org.jetbrains.annotations.NotNull)15 MouseEvent (java.awt.event.MouseEvent)12 Nullable (org.jetbrains.annotations.Nullable)10 Editor (com.intellij.openapi.editor.Editor)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 PsiElement (com.intellij.psi.PsiElement)8 JBList (com.intellij.ui.components.JBList)8 Disposable (com.intellij.openapi.Disposable)7 BalloonBuilder (com.intellij.openapi.ui.popup.BalloonBuilder)7 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)7 ArrayList (java.util.ArrayList)7 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)6 ListPopup (com.intellij.openapi.ui.popup.ListPopup)6 PsiFile (com.intellij.psi.PsiFile)5 HintHint (com.intellij.ui.HintHint)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)4