Search in sources :

Example 46 with JBPopup

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

the class PopupPositionManager method discoverPopup.

private static Component discoverPopup(final DataKey<JBPopup> datakey, Component focusOwner) {
    if (focusOwner == null) {
        focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    }
    if (focusOwner == null)
        return null;
    final DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner);
    if (dataContext == null)
        return null;
    final JBPopup popup = datakey.getData(dataContext);
    if (popup != null && popup.isVisible()) {
        return popup.getContent();
    }
    return null;
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 47 with JBPopup

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

the class ChangeGoToChangePopupAction method createPopup.

@NotNull
@Override
protected JBPopup createPopup(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (project == null)
        project = ProjectManager.getInstance().getDefaultProject();
    Ref<JBPopup> popup = new Ref<>();
    ChangesBrowser cb = new MyChangesBrowser(project, getChanges(), getCurrentSelection(), popup);
    popup.set(JBPopupFactory.getInstance().createComponentPopupBuilder(cb, cb.getPreferredFocusedComponent()).setResizable(true).setModalContext(false).setFocusable(true).setRequestFocus(true).setCancelOnWindowDeactivation(true).setCancelOnOtherWindowOpen(true).setMovable(true).setCancelKeyEnabled(true).setCancelOnClickOutside(true).setDimensionServiceKey(project, "Diff.GoToChangePopup", false).createPopup());
    return popup.get();
}
Also used : Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) ChangesBrowser(com.intellij.openapi.vcs.changes.ui.ChangesBrowser) JBPopup(com.intellij.openapi.ui.popup.JBPopup) NotNull(org.jetbrains.annotations.NotNull)

Example 48 with JBPopup

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

the class InjectLanguageAction method doChooseLanguageToInject.

public static boolean doChooseLanguageToInject(Editor editor, final Processor<Injectable> onChosen) {
    final List<Injectable> injectables = getAllInjectables();
    final JList list = new JBList(injectables);
    list.setCellRenderer(new ColoredListCellRendererWrapper<Injectable>() {

        @Override
        protected void doCustomize(JList list, Injectable language, int index, boolean selected, boolean hasFocus) {
            setIcon(language.getIcon());
            append(language.getDisplayName());
            String description = language.getAdditionalDescription();
            if (description != null) {
                append(description, SimpleTextAttributes.GRAYED_ATTRIBUTES);
            }
        }
    });
    Dimension minSize = new JLabel(PlainTextLanguage.INSTANCE.getDisplayName(), EmptyIcon.ICON_16, SwingConstants.LEFT).getMinimumSize();
    minSize.height *= 4;
    list.setMinimumSize(minSize);
    JBPopup popup = new PopupChooserBuilder(list).setItemChoosenCallback(() -> {
        Injectable value = (Injectable) list.getSelectedValue();
        if (value != null) {
            onChosen.process(value);
            PropertiesComponent.getInstance().setValue(LAST_INJECTED_LANGUAGE, value.getId());
        }
    }).setFilteringEnabled(language -> ((Injectable) language).getDisplayName()).setMinSize(minSize).createPopup();
    final String lastInjected = PropertiesComponent.getInstance().getValue(LAST_INJECTED_LANGUAGE);
    if (lastInjected != null) {
        Injectable injectable = ContainerUtil.find(injectables, injectable1 -> lastInjected.equals(injectable1.getId()));
        list.setSelectedValue(injectable, true);
    }
    popup.showInBestPositionFor(editor);
    return true;
}
Also used : Injectable(com.intellij.psi.injection.Injectable) JBList(com.intellij.ui.components.JBList) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 49 with JBPopup

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

the class ManageRecentProjectsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Disposable disposable = Disposer.newDisposable();
    NewRecentProjectPanel panel = new NewRecentProjectPanel(disposable);
    JList list = UIUtil.findComponentOfType(panel, JList.class);
    JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, list).setTitle("Recent Projects").setFocusable(true).setRequestFocus(true).setMayBeParent(true).setMovable(true).createPopup();
    Disposer.register(popup, disposable);
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    popup.showCenteredInCurrentWindow(project);
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) NewRecentProjectPanel(com.intellij.openapi.wm.impl.welcomeScreen.NewRecentProjectPanel) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 50 with JBPopup

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

the class SliderSelectorAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final JPanel result = new JPanel(new BorderLayout());
    final JLabel label = new JLabel(myConfiguration.getSelectText());
    label.setBorder(BorderFactory.createEmptyBorder(4, 4, 0, 0));
    JPanel wrapper = new JPanel(new BorderLayout());
    wrapper.add(label, BorderLayout.NORTH);
    final Dictionary dictionary = myConfiguration.getDictionary();
    final Enumeration elements = dictionary.elements();
    final JSlider slider = new JSlider(SwingConstants.HORIZONTAL, myConfiguration.getMin(), myConfiguration.getMax(), myConfiguration.getSelected()) {

        Integer myWidth = null;

        @Override
        public Dimension getPreferredSize() {
            final Dimension size = super.getPreferredSize();
            if (myWidth == null) {
                myWidth = 10;
                final FontMetrics fm = getFontMetrics(getFont());
                while (elements.hasMoreElements()) {
                    String text = ((JLabel) elements.nextElement()).getText();
                    myWidth += fm.stringWidth(text + "W");
                }
            }
            return new Dimension(myWidth, size.height);
        }
    };
    slider.setMinorTickSpacing(1);
    slider.setPaintTicks(true);
    slider.setPaintTrack(true);
    slider.setSnapToTicks(true);
    UIUtil.setSliderIsFilled(slider, true);
    slider.setPaintLabels(true);
    slider.setLabelTable(dictionary);
    if (!myConfiguration.isShowOk()) {
        result.add(wrapper, BorderLayout.WEST);
        result.add(slider, BorderLayout.CENTER);
    } else {
        result.add(wrapper, BorderLayout.WEST);
        result.add(slider, BorderLayout.CENTER);
    }
    final Runnable saveSelection = () -> {
        int value = slider.getModel().getValue();
        myConfiguration.getResultConsumer().consume(value);
    };
    final Ref<JBPopup> popupRef = new Ref<>(null);
    final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(result, slider).setMovable(true).setCancelOnWindowDeactivation(true).setCancelKeyEnabled(myConfiguration.isShowOk()).setKeyboardActions(Collections.singletonList(Pair.<ActionListener, KeyStroke>create(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            saveSelection.run();
            popupRef.get().closeOk(null);
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)))).createPopup();
    popupRef.set(popup);
    if (myConfiguration.isShowOk()) {
        final JButton done = new JButton("Done");
        final JBPanel doneWrapper = new JBPanel(new BorderLayout());
        doneWrapper.add(done, BorderLayout.NORTH);
        result.add(doneWrapper, BorderLayout.EAST);
        done.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                saveSelection.run();
                popup.closeOk(null);
            }
        });
    } else {
        popup.setFinalRunnable(saveSelection);
    }
    InputEvent inputEvent = e.getInputEvent();
    show(e, result, popup, inputEvent);
}
Also used : Dictionary(java.util.Dictionary) Enumeration(java.util.Enumeration) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Ref(com.intellij.openapi.util.Ref) 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