Search in sources :

Example 71 with RelativePoint

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

the class AbstractDependenciesPanel method createActionsPanel.

@NotNull
protected final JPanel createActionsPanel() {
    JPanel actionsPanel = new JPanel(new BorderLayout());
    DefaultActionGroup actions = new DefaultActionGroup();
    AnAction addDependencyAction = new DumbAwareAction("Add Dependency", "", IconUtil.getAddIcon()) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<AbstractPopupAction>(null, getPopupActions()) {

                @Override
                public Icon getIconFor(AbstractPopupAction action) {
                    return action.icon;
                }

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

                @Override
                public PopupStep onChosen(AbstractPopupAction action, boolean finalChoice) {
                    return doFinalStep(action::execute);
                }

                @Override
                @NotNull
                public String getTextFor(AbstractPopupAction action) {
                    return "&" + action.index + "  " + action.text;
                }
            });
            popup.show(new RelativePoint(actionsPanel, new Point(0, actionsPanel.getHeight() - 1)));
        }
    };
    actions.add(addDependencyAction);
    List<AnAction> extraToolbarActions = getExtraToolbarActions();
    if (!extraToolbarActions.isEmpty()) {
        actions.addSeparator();
        actions.addAll(extraToolbarActions);
    }
    ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("TOP", actions, true);
    JComponent toolbarComponent = toolbar.getComponent();
    toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
    actionsPanel.add(toolbarComponent, BorderLayout.CENTER);
    return actionsPanel;
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) JBPopup(com.intellij.openapi.ui.popup.JBPopup) NotNull(org.jetbrains.annotations.NotNull)

Example 72 with RelativePoint

use of com.intellij.ui.awt.RelativePoint 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 73 with RelativePoint

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

the class LintNotificationPanel method showInBestPositionFor.

@NotNull
public JBPopup showInBestPositionFor(@Nullable Project project, @NotNull JComponent component) {
    return setupPopup(project, popup -> {
        Dimension preferredSize = DimensionService.getInstance().getSize(DIMENSION_KEY, project);
        if (preferredSize == null) {
            preferredSize = myPanel.getPreferredSize();
        }
        showInScreenPosition(project, new RelativePoint(component, new Point(component.getWidth() - preferredSize.width, component.getHeight())));
    });
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull)

Example 74 with RelativePoint

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

the class JstdAssertionFrameworkLineMarkerProvider method showPopup.

private static void showPopup(@NotNull MouseEvent e, @NotNull final PsiElement psiElement, final String displayName) {
    final JBList list = new JBList(getAvailableTypes());
    list.setCellRenderer(new ListCellRendererWrapper<Type>() {

        @Override
        public void customize(JList list, Type value, int index, boolean selected, boolean hasFocus) {
            setIcon(value.getIcon());
            setText(value.getTitle(displayName));
        }
    });
    PopupChooserBuilder builder = new PopupChooserBuilder(list);
    JBPopup popup = builder.setMovable(true).setItemChoosenCallback(() -> {
        int[] ids = list.getSelectedIndices();
        if (ids.length == 0)
            return;
        Type type = ObjectUtils.tryCast(list.getSelectedValue(), Type.class);
        if (type != null) {
            if (psiElement.isValid()) {
                execute(type.getExecutor(), psiElement);
            }
        }
    }).createPopup();
    popup.show(new RelativePoint(e));
}
Also used : JBList(com.intellij.ui.components.JBList) RelativePoint(com.intellij.ui.awt.RelativePoint) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 75 with RelativePoint

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

the class LiveTemplateSettingsEditor method createShortContextPanel.

private JPanel createShortContextPanel(final boolean allowNoContexts) {
    JPanel panel = new JPanel(new BorderLayout());
    final JLabel ctxLabel = new JLabel();
    final JLabel change = new JLabel();
    change.setForeground(PlatformColors.BLUE);
    change.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    panel.add(ctxLabel, BorderLayout.CENTER);
    panel.add(change, BorderLayout.EAST);
    final Runnable updateLabel = () -> {
        myExpandByCombo.setEnabled(isExpandableFromEditor());
        updateHighlighter();
        StringBuilder sb = new StringBuilder();
        String oldPrefix = "";
        for (TemplateContextType type : getApplicableContexts()) {
            final TemplateContextType base = type.getBaseContextType();
            String ownName = UIUtil.removeMnemonic(type.getPresentableName());
            String prefix = "";
            if (base != null && !(base instanceof EverywhereContextType)) {
                prefix = UIUtil.removeMnemonic(base.getPresentableName()) + ": ";
                ownName = StringUtil.decapitalize(ownName);
            }
            if (type instanceof EverywhereContextType) {
                ownName = "Other";
            }
            if (sb.length() > 0) {
                sb.append(oldPrefix.equals(prefix) ? ", " : "; ");
            }
            if (!oldPrefix.equals(prefix)) {
                sb.append(prefix);
                oldPrefix = prefix;
            }
            sb.append(ownName);
        }
        String contexts = "Applicable in " + sb.toString();
        change.setText("Change");
        final boolean noContexts = sb.length() == 0;
        if (noContexts) {
            if (!allowNoContexts) {
                ctxLabel.setForeground(JBColor.RED);
            }
            contexts = "No applicable contexts" + (allowNoContexts ? "" : " yet");
            ctxLabel.setIcon(AllIcons.General.BalloonWarning);
            change.setText("Define");
        } else {
            ctxLabel.setForeground(UIUtil.getLabelForeground());
            ctxLabel.setIcon(null);
        }
        ctxLabel.setText(StringUtil.first(contexts + ". ", 100, true));
        myTemplateOptionsPanel.removeAll();
        myTemplateOptionsPanel.add(createTemplateOptionsPanel());
    };
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            if (disposeContextPopup())
                return false;
            final JPanel content = createPopupContextPanel(updateLabel, myContext);
            Dimension prefSize = content.getPreferredSize();
            if (myLastSize != null && (myLastSize.width > prefSize.width || myLastSize.height > prefSize.height)) {
                content.setPreferredSize(new Dimension(Math.max(prefSize.width, myLastSize.width), Math.max(prefSize.height, myLastSize.height)));
            }
            myContextPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(content, null).setResizable(true).createPopup();
            myContextPopup.show(new RelativePoint(change, new Point(change.getWidth(), -content.getPreferredSize().height - 10)));
            myContextPopup.addListener(new JBPopupAdapter() {

                @Override
                public void onClosed(LightweightWindowEvent event) {
                    myLastSize = content.getSize();
                }
            });
            return true;
        }
    }.installOn(change);
    updateLabel.run();
    return panel;
}
Also used : EverywhereContextType(com.intellij.codeInsight.template.EverywhereContextType) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter) TemplateContextType(com.intellij.codeInsight.template.TemplateContextType)

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