Search in sources :

Example 96 with RelativePoint

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

the class InfoAndProgressPanel method notifyByBalloon.

public BalloonHandler notifyByBalloon(MessageType type, String htmlBody, @Nullable Icon icon, @Nullable HyperlinkListener listener) {
    final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(htmlBody.replace("\n", "<br>"), icon != null ? icon : type.getDefaultIcon(), type.getPopupBackground(), listener).createBalloon();
    SwingUtilities.invokeLater(() -> {
        Component comp = this;
        if (comp.isShowing()) {
            int offset = comp.getHeight() / 2;
            Point point = new Point(comp.getWidth() - offset, comp.getHeight() - offset);
            balloon.show(new RelativePoint(comp, point), Balloon.Position.above);
        } else {
            final JRootPane rootPane = SwingUtilities.getRootPane(comp);
            if (rootPane != null && rootPane.isShowing()) {
                final Container contentPane = rootPane.getContentPane();
                final Rectangle bounds = contentPane.getBounds();
                final Point target = UIUtil.getCenterPoint(bounds, JBUI.size(1, 1));
                target.y = bounds.height - 3;
                balloon.show(new RelativePoint(contentPane, target), Balloon.Position.above);
            }
        }
    });
    return new BalloonHandler() {

        @Override
        public void hide() {
            SwingUtilities.invokeLater(() -> balloon.hide());
        }
    };
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 97 with RelativePoint

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

the class DebuggerTreeWithHistoryPopup method updateContainer.

@Override
protected void updateContainer(final Tree tree, String title) {
    if (myPopup != null) {
        myPopup.cancel();
    }
    tree.getModel().addTreeModelListener(createTreeListener(tree));
    myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(createMainPanel(tree), tree).setRequestFocus(true).setTitle(title).setResizable(true).setMovable(true).setDimensionServiceKey(myProject, DIMENSION_SERVICE_KEY, false).setMayBeParent(true).setKeyEventHandler(event -> {
        if (AbstractPopup.isCloseRequest(event)) {
            SpeedSearchSupply supply = SpeedSearchSupply.getSupply(tree);
            return supply != null && StringUtil.isEmpty(supply.getEnteredPrefix());
        }
        return false;
    }).addListener(new JBPopupAdapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            if (myHideRunnable != null) {
                myHideRunnable.run();
            }
        }
    }).setCancelCallback(() -> {
        Window parent = SwingUtilities.getWindowAncestor(tree);
        if (parent != null) {
            for (Window child : parent.getOwnedWindows()) {
                if (child.isShowing()) {
                    return false;
                }
            }
        }
        return true;
    }).createPopup();
    registerTreeDisposable(myPopup, tree);
    //Editor may be disposed before later invokator process this action
    if (myEditor.getComponent().getRootPane() == null) {
        myPopup.cancel();
        return;
    }
    myPopup.show(new RelativePoint(myEditor.getContentComponent(), myPoint));
    updateInitialBounds(tree);
}
Also used : SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter) RelativePoint(com.intellij.ui.awt.RelativePoint) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent)

Example 98 with RelativePoint

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

the class JBComboBoxTableCellEditorComponent method initAndShowPopup.

private void initAndShowPopup() {
    myList.removeAll();
    myList.setModel(JBList.createDefaultListModel(myOptions));
    if (myRenderer != null) {
        myList.setCellRenderer(myRenderer);
    }
    final Rectangle rect = myTable.getCellRect(myRow, myColumn, true);
    Point point = new Point(rect.x, rect.y);
    final boolean surrendersFocusOnKeystrokeOldValue = myTable instanceof JBTable ? ((JBTable) myTable).surrendersFocusOnKeyStroke() : myTable.getSurrendersFocusOnKeystroke();
    final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(myList).setItemChoosenCallback(() -> {
        myValue = myList.getSelectedValue();
        final ActionEvent event = new ActionEvent(myList, ActionEvent.ACTION_PERFORMED, "elementChosen");
        for (ActionListener listener : myListeners) {
            listener.actionPerformed(event);
        }
        TableUtil.stopEditing(myTable);
        // on Mac getCellEditorValue() called before myValue is set.
        myTable.setValueAt(myValue, myRow, myColumn);
        // force repaint
        myTable.tableChanged(new TableModelEvent(myTable.getModel(), myRow));
    }).setCancelCallback(() -> {
        TableUtil.stopEditing(myTable);
        return true;
    }).addListener(new JBPopupAdapter() {

        @Override
        public void beforeShown(LightweightWindowEvent event) {
            super.beforeShown(event);
            myTable.setSurrendersFocusOnKeystroke(false);
        }

        @Override
        public void onClosed(LightweightWindowEvent event) {
            myTable.setSurrendersFocusOnKeystroke(surrendersFocusOnKeystrokeOldValue);
            super.onClosed(event);
        }
    }).setMinSize(myWide ? new Dimension(((int) rect.getSize().getWidth()), -1) : null).createPopup();
    popup.show(new RelativePoint(myTable, point));
}
Also used : ActionEvent(java.awt.event.ActionEvent) TableModelEvent(javax.swing.event.TableModelEvent) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBTable(com.intellij.ui.table.JBTable) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) ActionListener(java.awt.event.ActionListener) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 99 with RelativePoint

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

the class MouseDragHelper method mouseDragged.

@Override
public void mouseDragged(final MouseEvent e) {
    if (myPressPointScreen == null || myCancelled)
        return;
    final boolean deadZone = isWithinDeadZone(e);
    if (!myDraggingNow && !deadZone) {
        myDraggingNow = true;
        myDragJustStarted = true;
    } else if (myDraggingNow) {
        myDragJustStarted = false;
    }
    if (myDraggingNow && myPressPointScreen != null) {
        final Point draggedTo = new RelativePoint(e).getScreenPoint();
        boolean dragOutStarted = false;
        if (!myDetachingMode) {
            if (isDragOut(e, draggedTo, (Point) myPressPointScreen.clone())) {
                myDetachingMode = true;
                processDragFinish(e, true);
                dragOutStarted = true;
            }
        }
        if (myDetachingMode) {
            processDragOut(e, draggedTo, (Point) myPressPointScreen.clone(), dragOutStarted);
        } else {
            processDrag(e, draggedTo, (Point) myPressPointScreen.clone());
        }
    }
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 100 with RelativePoint

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

the class Callout method showText.

public static void showText(JComponent component, int direction, String text) {
    final RelativePoint point = new RelativePoint(component, new Point(component.getWidth() / 2, component.getHeight() / 2));
    showText(point, direction, text);
}
Also used : 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