Search in sources :

Example 86 with RelativePoint

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

the class ListPopupImpl method showUnderneathOfLabel.

public void showUnderneathOfLabel(@NotNull JLabel label) {
    int offset = -UIUtil.getListCellHPadding() - UIUtil.getListViewportPadding().left;
    if (label.getIcon() != null) {
        offset += label.getIcon().getIconWidth() + label.getIconTextGap();
    }
    show(new RelativePoint(label, new Point(offset, label.getHeight() + 1)));
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 87 with RelativePoint

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

the class PopupFactoryImpl method guessBestPopupLocation.

@NotNull
@Override
public RelativePoint guessBestPopupLocation(@NotNull DataContext dataContext) {
    Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
    JComponent focusOwner = component instanceof JComponent ? (JComponent) component : null;
    if (focusOwner == null) {
        Project project = CommonDataKeys.PROJECT.getData(dataContext);
        IdeFrameImpl frame = project == null ? null : ((WindowManagerEx) WindowManager.getInstance()).getFrame(project);
        focusOwner = frame == null ? null : frame.getRootPane();
        if (focusOwner == null) {
            throw new IllegalArgumentException("focusOwner cannot be null");
        }
    }
    final Point point = PlatformDataKeys.CONTEXT_MENU_POINT.getData(dataContext);
    if (point != null) {
        return new RelativePoint(focusOwner, point);
    }
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (editor != null && focusOwner == editor.getContentComponent()) {
        return guessBestPopupLocation(editor);
    } else {
        return guessBestPopupLocation(focusOwner);
    }
}
Also used : Project(com.intellij.openapi.project.Project) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) Editor(com.intellij.openapi.editor.Editor) NotNull(org.jetbrains.annotations.NotNull)

Example 88 with RelativePoint

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

the class InplaceChangeSignature method showBalloon.

protected void showBalloon() {
    NonFocusableCheckBox checkBox = new NonFocusableCheckBox(RefactoringBundle.message("delegation.panel.delegate.via.overloading.method"));
    checkBox.addActionListener(e -> {
        myDelegate = checkBox.isSelected();
        updateCurrentInfo();
    });
    JPanel content = new JPanel(new BorderLayout());
    content.add(new JBLabel("Performed signature modifications:"), BorderLayout.NORTH);
    content.add(myPreview.getComponent(), BorderLayout.CENTER);
    updateMethodSignature(myStableChange);
    content.add(checkBox, BorderLayout.SOUTH);
    final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createDialogBalloonBuilder(content, null).setSmallVariant(true);
    myBalloon = balloonBuilder.createBalloon();
    myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    myBalloon.show(new PositionTracker<Balloon>(myEditor.getContentComponent()) {

        @Override
        public RelativePoint recalculateLocation(Balloon object) {
            int offset = myStableChange.getMethod().getTextOffset();
            VisualPosition visualPosition = myEditor.offsetToVisualPosition(offset);
            Point point = myEditor.visualPositionToXY(new VisualPosition(visualPosition.line, visualPosition.column));
            return new RelativePoint(myEditor.getContentComponent(), point);
        }
    }, Balloon.Position.above);
    Disposer.register(myBalloon, () -> {
        EditorFactory.getInstance().releaseEditor(myPreview);
        myPreview = null;
    });
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) NonFocusableCheckBox(com.intellij.ui.NonFocusableCheckBox) Balloon(com.intellij.openapi.ui.popup.Balloon) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder)

Example 89 with RelativePoint

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

the class ShowPopupMenuAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final RelativePoint relPoint = JBPopupFactory.getInstance().guessBestPopupLocation(e.getDataContext());
    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focusOwner = focusManager.getFocusOwner();
    Point popupMenuPoint = relPoint.getPoint(focusOwner);
    final Editor editor = e.getData(CommonDataKeys.EDITOR);
    int coord = editor != null ? //To avoid cursor jump to the line below. http://www.jetbrains.net/jira/browse/IDEADEV-10644
    Math.max(0, popupMenuPoint.y - 1) : popupMenuPoint.y;
    focusOwner.dispatchEvent(new MouseEvent(focusOwner, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, popupMenuPoint.x, coord, 1, true));
}
Also used : MouseEvent(java.awt.event.MouseEvent) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) Editor(com.intellij.openapi.editor.Editor) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 90 with RelativePoint

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

the class EncodingPanel method showPopup.

private void showPopup(@NotNull MouseEvent e) {
    if (!actionEnabled) {
        return;
    }
    DataContext dataContext = getContext();
    ListPopup popup = new ChangeFileEncodingAction().createPopup(dataContext);
    if (popup != null) {
        Dimension dimension = popup.getContent().getPreferredSize();
        Point at = new Point(0, -dimension.height);
        popup.show(new RelativePoint(e.getComponent(), at));
        // destroy popup on unexpected project close
        Disposer.register(this, popup);
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) ListPopup(com.intellij.openapi.ui.popup.ListPopup) ChangeFileEncodingAction(com.intellij.openapi.vfs.encoding.ChangeFileEncodingAction) RelativePoint(com.intellij.ui.awt.RelativePoint) 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