Search in sources :

Example 91 with RelativePoint

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

the class InfoAndProgressPanel method buildInInlineIndicator.

private void buildInInlineIndicator(@NotNull final InlineProgressIndicator inline) {
    removeAll();
    setLayout(new InlineLayout());
    final JRootPane pane = getRootPane();
    // e.g. project frame is closed
    if (pane == null)
        return;
    add(myRefreshAndInfoPanel);
    final JPanel inlinePanel = new JPanel(new BorderLayout());
    inline.getComponent().setBorder(JBUI.Borders.empty(1, 0, 0, 2));
    final JComponent inlineComponent = inline.getComponent();
    inlineComponent.setOpaque(false);
    inlinePanel.add(inlineComponent, BorderLayout.CENTER);
    //myProgressIcon.setBorder(new IdeStatusBarImpl.MacStatusBarWidgetBorder());
    inlinePanel.add(myProgressIcon, BorderLayout.WEST);
    inline.updateProgressNow();
    inlinePanel.setOpaque(false);
    add(inlinePanel);
    myRefreshAndInfoPanel.revalidate();
    myRefreshAndInfoPanel.repaint();
    final PresentationModeProgressPanel panel = new PresentationModeProgressPanel(inline);
    MyInlineProgressIndicator delegate = new MyInlineProgressIndicator(true, inline.getInfo(), inline) {

        @Override
        protected void updateProgress() {
            super.updateProgress();
            panel.update();
        }
    };
    Disposer.register(inline, delegate);
    Component anchor = getAnchor(pane);
    final BalloonLayoutImpl balloonLayout = getBalloonLayout(pane);
    final Balloon balloon = JBPopupFactory.getInstance().createBalloonBuilder(panel.getProgressPanel()).setFadeoutTime(0).setFillColor(Gray.TRANSPARENT).setShowCallout(false).setBorderColor(Gray.TRANSPARENT).setBorderInsets(JBUI.emptyInsets()).setAnimationCycle(0).setCloseButtonEnabled(false).setHideOnClickOutside(false).setDisposable(inline).setHideOnFrameResize(false).setHideOnKeyOutside(false).setBlockClicksThroughBalloon(true).setHideOnAction(false).createBalloon();
    if (balloonLayout != null) {
        class MyListener implements JBPopupListener, Runnable {

            @Override
            public void beforeShown(LightweightWindowEvent event) {
                balloonLayout.addListener(this);
            }

            @Override
            public void onClosed(LightweightWindowEvent event) {
                balloonLayout.removeListener(this);
            }

            @Override
            public void run() {
                if (!balloon.isDisposed()) {
                    balloon.revalidate();
                }
            }
        }
        balloon.addListener(new MyListener());
    }
    balloon.show(new PositionTracker<Balloon>(anchor) {

        @Override
        public RelativePoint recalculateLocation(Balloon object) {
            Component c = getAnchor(pane);
            int y = c.getHeight() - 45;
            if (balloonLayout != null && !isBottomSideToolWindowsVisible(pane)) {
                Component component = balloonLayout.getTopBalloonComponent();
                if (component != null) {
                    y = SwingUtilities.convertPoint(component, 0, -45, c).y;
                }
            }
            return new RelativePoint(c, new Point(c.getWidth() - 150, y));
        }
    }, Balloon.Position.above);
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) BalloonLayoutImpl(com.intellij.ui.BalloonLayoutImpl)

Example 92 with RelativePoint

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

the class ToolWindowsWidget method mouseEntered.

public void mouseEntered() {
    final boolean active = ApplicationManager.getApplication().isActive();
    if (!active) {
        return;
    }
    if (myAlarm.getActiveRequestCount() == 0) {
        myAlarm.addRequest(() -> {
            final IdeFrameImpl frame = UIUtil.getParentOfType(IdeFrameImpl.class, this);
            if (frame == null)
                return;
            List<ToolWindow> toolWindows = new ArrayList<>();
            final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(frame.getProject());
            for (String id : toolWindowManager.getToolWindowIds()) {
                final ToolWindow tw = toolWindowManager.getToolWindow(id);
                if (tw.isAvailable() && tw.isShowStripeButton()) {
                    toolWindows.add(tw);
                }
            }
            Collections.sort(toolWindows, (o1, o2) -> StringUtil.naturalCompare(o1.getStripeTitle(), o2.getStripeTitle()));
            final JBList list = new JBList(toolWindows);
            list.setCellRenderer(new ListCellRenderer() {

                final JBLabel label = new JBLabel();

                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    final ToolWindow toolWindow = (ToolWindow) value;
                    label.setText(toolWindow.getStripeTitle());
                    label.setIcon(toolWindow.getIcon());
                    label.setBorder(JBUI.Borders.empty(4, 10));
                    label.setForeground(UIUtil.getListForeground(isSelected));
                    label.setBackground(UIUtil.getListBackground(isSelected));
                    final JPanel panel = new JPanel(new BorderLayout());
                    panel.add(label, BorderLayout.CENTER);
                    panel.setBackground(UIUtil.getListBackground(isSelected));
                    return panel;
                }
            });
            final Dimension size = list.getPreferredSize();
            final JComponent c = this;
            final Insets padding = UIUtil.getListViewportPadding();
            final RelativePoint point = new RelativePoint(c, new Point(-4, -padding.top - padding.bottom - 4 - size.height + (SystemInfo.isMac ? 2 : 0)));
            if (popup != null && popup.isVisible()) {
                return;
            }
            list.setSelectedIndex(list.getItemsCount() - 1);
            PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
            popup = builder.setAutoselectOnMouseMove(true).setRequestFocus(false).setItemChoosenCallback(() -> {
                if (popup != null)
                    popup.closeOk(null);
                final Object value = list.getSelectedValue();
                if (value instanceof ToolWindow) {
                    ((ToolWindow) value).activate(null, true, true);
                }
            }).createPopup();
            // override default of 15 set when createPopup() is called
            list.setVisibleRowCount(30);
            popup.show(point);
        }, 300);
    }
}
Also used : IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) ArrayList(java.util.ArrayList) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBLabel(com.intellij.ui.components.JBLabel) JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 93 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 94 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 95 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)

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