Search in sources :

Example 36 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project android by JetBrains.

the class ViewBitmapAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    ClassInstance selectedClassInstance = e.getData(InstancesTreeView.SELECTED_CLASS_INSTANCE);
    if (selectedClassInstance == null) {
        return;
    }
    try {
        BufferedImage img = BitmapDecoder.getBitmap(new HprofBitmapProvider(selectedClassInstance));
        final JComponent comp;
        if (img != null) {
            comp = ImageEditorManagerImpl.createImageEditorUI(img);
        } else {
            String errorMessage = AndroidBundle.message("android.profiler.hprof.actions.view.bitmap.fail");
            comp = new JLabel(errorMessage, Messages.getErrorIcon(), SwingConstants.CENTER);
        }
        Project project = e.getData(CommonDataKeys.PROJECT);
        JBPopup popup = DebuggerUIUtil.createValuePopup(project, comp, null);
        JFrame frame = WindowManager.getInstance().getFrame(project);
        Dimension frameSize = frame.getSize();
        Dimension size = new Dimension(frameSize.width / 2, frameSize.height / 2);
        popup.setSize(size);
        popup.show(new RelativePoint(frame, new Point(size.width / 2, size.height / 2)));
    } catch (Exception ignored) {
    }
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) BufferedImage(java.awt.image.BufferedImage) Project(com.intellij.openapi.project.Project) JBPopup(com.intellij.openapi.ui.popup.JBPopup) ClassInstance(com.android.tools.perflib.heap.ClassInstance) HprofBitmapProvider(com.android.tools.perflib.heap.memoryanalyzer.HprofBitmapProvider)

Example 37 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project android by JetBrains.

the class ModuleDependenciesPanel method createTableWithButtons.

@NotNull
private JComponent createTableWithButtons() {
    myEntryTable.getSelectionModel().addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            return;
        }
        updateButtons();
    });
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myEntryTable);
    decorator.setAddAction(button -> {
        ImmutableList<PopupAction> popupActions = ImmutableList.of(new PopupAction(AndroidIcons.MavenLogo, 1, "Library dependency") {

            @Override
            public void run() {
                addExternalDependency();
            }
        }, new PopupAction(PlatformIcons.LIBRARY_ICON, 2, "Jar dependency") {

            @Override
            public void run() {
                addFileDependency();
            }
        }, new PopupAction(AllIcons.Nodes.Module, 3, "Module dependency") {

            @Override
            public void run() {
                addModuleDependency();
            }
        });
        final JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<PopupAction>(null, popupActions) {

            @Override
            public Icon getIconFor(PopupAction value) {
                return value.myIcon;
            }

            @Override
            public boolean hasSubstep(PopupAction value) {
                return false;
            }

            @Override
            public boolean isMnemonicsNavigationEnabled() {
                return true;
            }

            @Override
            public PopupStep onChosen(final PopupAction value, final boolean finalChoice) {
                return doFinalStep(value);
            }

            @Override
            @NotNull
            public String getTextFor(PopupAction value) {
                return "&" + value.myIndex + "  " + value.myTitle;
            }
        });
        popup.show(button.getPreferredPopupPoint());
    });
    decorator.setRemoveAction(button -> removeSelectedItems());
    decorator.setMoveUpAction(button -> moveSelectedRows(-1));
    decorator.setMoveDownAction(button -> moveSelectedRows(+1));
    final JPanel panel = decorator.createPanel();
    myRemoveButton = ToolbarDecorator.findRemoveButton(panel);
    return panel;
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) NotNull(org.jetbrains.annotations.NotNull)

Example 38 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project android by JetBrains.

the class LintNotificationPanel method setupPopup.

/**
   * Sets-up the panel popup and calls the passed {@link Consumer<JBPopup>} with the new {@link JBPopup} instance.
   * This method will not display the popup.
   */
public JBPopup setupPopup(@Nullable Project project, @NotNull Consumer<JBPopup> onPopupBuilt) {
    JBPopup builder = JBPopupFactory.getInstance().createComponentPopupBuilder(myPanel, myPanel).setProject(project).setDimensionServiceKey(project, DIMENSION_KEY, false).setResizable(true).setMovable(true).setMinSize(MIN_POPUP_SIZE).setRequestFocus(true).setTitle("Lint Warnings in Layout").setCancelOnClickOutside(true).setLocateWithinScreenBounds(true).setShowShadow(true).setCancelOnWindowDeactivation(true).setCancelOnMouseOutCallback(new MouseChecker() {

        Rectangle myDismissRectangle;

        double myPreviousDistance = 0;

        @Override
        public boolean check(MouseEvent event) {
            if (myPopup == null) {
                return false;
            }
            Point mousePosition = event.getPoint();
            SwingUtilities.convertPointToScreen(mousePosition, event.getComponent());
            Point popupPosition = myPopup.getLocationOnScreen();
            Dimension popupDimension = myPopup.getSize();
            int centerX = popupPosition.x + popupDimension.width / 2;
            int centerY = popupPosition.y + popupDimension.height / 2;
            // Is it the mouse getting closer to the center of the popup or moving away? We only close the dialog if the mouse is
            // moving away.
            double currentDistance = mousePosition.distance(centerX, centerY);
            double previousDistance = myPreviousDistance;
            myPreviousDistance = currentDistance;
            boolean mouseMovingAway = previousDistance != 0 && currentDistance > previousDistance;
            if (!mouseMovingAway) {
                // We only dismiss the dialog if the mouse is moving away from the center
                return false;
            }
            int dismissRectX = popupPosition.x - DISMISS_MARGIN_PX;
            int dismissRectY = popupPosition.y - DISMISS_MARGIN_PX;
            int dismissRectW = popupDimension.width + 2 * DISMISS_MARGIN_PX;
            int dismissRectH = popupDimension.height + 2 * DISMISS_MARGIN_PX;
            if (myDismissRectangle == null) {
                myDismissRectangle = new Rectangle(dismissRectX, dismissRectY, dismissRectW, dismissRectH);
            } else {
                myDismissRectangle.setBounds(dismissRectX, dismissRectY, dismissRectW, dismissRectH);
            }
            return !myDismissRectangle.contains(mousePosition);
        }
    }).createPopup();
    myPopup = builder;
    Disposer.register(myScreenView.getSurface(), myPopup);
    onPopupBuilt.accept(builder);
    return builder;
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseChecker(com.intellij.openapi.ui.popup.MouseChecker) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 39 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project android by JetBrains.

the class DesignSurface method hover.

public void hover(@SwingCoordinate int x, @SwingCoordinate int y) {
    ScreenView current = getHoverScreenView(x, y);
    for (Layer layer : myLayers) {
        if (layer instanceof ConstraintsLayer) {
            // For constraint layer, set show on hover if they are above their screen view
            ConstraintsLayer constraintsLayer = (ConstraintsLayer) layer;
            boolean show = false;
            if (constraintsLayer.getScreenView() == current) {
                show = true;
            }
            if (constraintsLayer.isShowOnHover() != show) {
                constraintsLayer.setShowOnHover(show);
                repaint();
            }
        } else if (layer instanceof SceneLayer) {
            // For constraint layer, set show on hover if they are above their screen view
            SceneLayer sceneLayer = (SceneLayer) layer;
            boolean show = false;
            if (sceneLayer.getScreenView() == current) {
                show = true;
            }
            if (sceneLayer.isShowOnHover() != show) {
                sceneLayer.setShowOnHover(show);
                repaint();
            }
        } else if (layer instanceof CanvasResizeLayer) {
            if (((CanvasResizeLayer) layer).changeHovering(x, y)) {
                repaint();
            }
        }
    }
    if (myErrorPanel.isVisible() && myRenderHasProblems) {
        // TODO: we should really move this logic into the error panel itself
        return;
    }
    // Currently, we use the hover action only to check whether we need to show a warning.
    if (AndroidEditorSettings.getInstance().getGlobalState().isShowLint()) {
        ScreenView currentScreenView = getCurrentScreenView();
        LintAnnotationsModel lintModel = currentScreenView != null ? currentScreenView.getModel().getLintAnnotationsModel() : null;
        if (lintModel != null) {
            for (Layer layer : myLayers) {
                String tooltip = layer.getTooltip(x, y);
                if (tooltip != null) {
                    JBPopup lintPopup = myLintTooltipPopup.get();
                    if (lintPopup == null || !lintPopup.isVisible()) {
                        NlUsageTrackerManager.getInstance(this).logAction(LayoutEditorEvent.LayoutEditorEventType.LINT_TOOLTIP);
                        LintNotificationPanel lintPanel = new LintNotificationPanel(getCurrentScreenView(), lintModel);
                        lintPanel.selectIssueAtPoint(Coordinates.getAndroidX(getCurrentScreenView(), x), Coordinates.getAndroidY(getCurrentScreenView(), y));
                        Point point = new Point(x, y);
                        SwingUtilities.convertPointToScreen(point, this);
                        myLintTooltipPopup = new WeakReference<>(lintPanel.showInScreenPosition(myProject, this, point));
                    }
                    break;
                }
            }
        }
    }
}
Also used : LintNotificationPanel(com.android.tools.idea.uibuilder.lint.LintNotificationPanel) LintAnnotationsModel(com.android.tools.idea.uibuilder.lint.LintAnnotationsModel) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 40 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoImportPackageQuickFix method perform.

private void perform(@NotNull List<String> packagesToImport, @NotNull PsiFile file, @Nullable Editor editor) {
    LOG.assertTrue(editor != null || packagesToImport.size() == 1, "Cannot invoke fix with ambiguous imports on null editor");
    if (packagesToImport.size() > 1 && editor != null) {
        JBList list = new JBList(packagesToImport);
        list.installCellRenderer(o -> {
            JBLabel label = new JBLabel(o.toString(), GoIcons.PACKAGE, SwingConstants.LEFT);
            label.setBorder(IdeBorderFactory.createEmptyBorder(2, 4, 2, 4));
            return label;
        });
        PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list).setRequestFocus(true).setTitle("Package to import").setItemChoosenCallback(() -> {
            int i = list.getSelectedIndex();
            if (i < 0)
                return;
            perform(file, packagesToImport.get(i));
        }).setFilteringEnabled(o -> o instanceof String ? (String) o : o.toString());
        JBPopup popup = builder.createPopup();
        builder.getScrollPane().setBorder(null);
        builder.getScrollPane().setViewportBorder(null);
        popup.showInBestPositionFor(editor);
    } else if (packagesToImport.size() == 1) {
        perform(file, getFirstItem(packagesToImport));
    } else {
        String packages = StringUtil.join(packagesToImport, ",");
        throw new IncorrectOperationException("Cannot invoke fix with ambiguous imports on editor ()" + editor + ". Packages: " + packages);
    }
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) JBList(com.intellij.ui.components.JBList) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Aggregations

JBPopup (com.intellij.openapi.ui.popup.JBPopup)76 Project (com.intellij.openapi.project.Project)21 NotNull (org.jetbrains.annotations.NotNull)20 RelativePoint (com.intellij.ui.awt.RelativePoint)19 JBList (com.intellij.ui.components.JBList)18 PopupChooserBuilder (com.intellij.openapi.ui.popup.PopupChooserBuilder)15 Editor (com.intellij.openapi.editor.Editor)13 PsiElement (com.intellij.psi.PsiElement)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Nullable (org.jetbrains.annotations.Nullable)8 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)7 Ref (com.intellij.openapi.util.Ref)7 DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)6 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)6 AbstractPopup (com.intellij.ui.popup.AbstractPopup)6 ActionEvent (java.awt.event.ActionEvent)6 List (java.util.List)6 javax.swing (javax.swing)6 Disposable (com.intellij.openapi.Disposable)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)5