Search in sources :

Example 91 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent 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)

Example 92 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.

the class CloudAccountSelectionEditor method onNewButton.

private void onNewButton() {
    if (myCloudTypes.size() == 1) {
        createAccount(ContainerUtil.getFirstItem(myCloudTypes));
        return;
    }
    DefaultActionGroup group = new DefaultActionGroup();
    for (final ServerType<?> cloudType : myCloudTypes) {
        group.add(new AnAction(cloudType.getPresentableName(), cloudType.getPresentableName(), cloudType.getIcon()) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                createAccount(cloudType);
            }
        });
    }
    JBPopupFactory.getInstance().createActionGroupPopup("New Account", group, DataManager.getInstance().getDataContext(myMainPanel), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false).showUnderneathOf(myNewButton);
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 93 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.

the class TaskDefaultFavoriteListProvider method showNotePopup.

private void showNotePopup(Project project, final DnDAwareTree tree, final Consumer<String> after, final String initText) {
    final JTextArea textArea = new JTextArea(3, 50);
    textArea.setFont(UIUtil.getTreeFont());
    textArea.setText(initText);
    final JBScrollPane pane = new JBScrollPane(textArea);
    final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(pane, textArea).setCancelOnClickOutside(true).setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish").setTitle("Comment").setMovable(true).setRequestFocus(true).setResizable(true).setMayBeParent(true);
    final JBPopup popup = builder.createPopup();
    final JComponent content = popup.getContent();
    final AnAction action = new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            popup.closeOk(e.getInputEvent());
            unregisterCustomShortcutSet(content);
            after.consume(textArea.getText());
        }
    };
    action.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, content);
    ApplicationManager.getApplication().invokeLater(() -> popup.showInCenterOf(tree), ModalityState.NON_MODAL, project.getDisposed());
}
Also used : ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 94 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.

the class FrameDiffTool method show.

public void show(DiffRequest request) {
    Collection hints = request.getHints();
    boolean shouldOpenDialog = shouldOpenDialog(hints);
    if (shouldOpenDialog) {
        final DialogBuilder builder = new DialogBuilder(request.getProject());
        DiffPanelImpl diffPanel = createDiffPanelIfShouldShow(request, builder.getWindow(), builder, true);
        if (diffPanel == null) {
            Disposer.dispose(builder);
            return;
        }
        final Runnable onOkRunnable = request.getOnOkRunnable();
        if (onOkRunnable != null) {
            builder.setOkOperation(() -> {
                builder.getDialogWrapper().close(0);
                onOkRunnable.run();
            });
        } else {
            builder.removeAllActions();
        }
        builder.setCenterPanel(diffPanel.getComponent());
        builder.setPreferredFocusComponent(diffPanel.getPreferredFocusedComponent());
        builder.setTitle(request.getWindowTitle());
        builder.setDimensionServiceKey(request.getGroupKey());
        new AnAction() {

            public void actionPerformed(final AnActionEvent e) {
                builder.getDialogWrapper().close(0);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
        showDiffDialog(builder, hints);
    } else {
        final FrameWrapper frameWrapper = new FrameWrapper(request.getProject(), request.getGroupKey());
        DiffPanelImpl diffPanel = createDiffPanelIfShouldShow(request, frameWrapper.getFrame(), frameWrapper, true);
        if (diffPanel == null) {
            Disposer.dispose(frameWrapper);
            return;
        }
        frameWrapper.setTitle(request.getWindowTitle());
        DiffUtil.initDiffFrame(diffPanel.getProject(), frameWrapper, diffPanel, diffPanel.getComponent());
        new AnAction() {

            public void actionPerformed(final AnActionEvent e) {
                frameWrapper.getFrame().dispose();
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
        frameWrapper.show();
    }
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) DiffPanelImpl(com.intellij.openapi.diff.impl.DiffPanelImpl) Collection(java.util.Collection) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) FrameWrapper(com.intellij.openapi.ui.FrameWrapper) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 95 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.

the class MultiLevelDiffTool method show.

@Override
public void show(DiffRequest request) {
    Collection hints = request.getHints();
    boolean shouldOpenDialog = FrameDiffTool.shouldOpenDialog(hints);
    if (shouldOpenDialog) {
        final DialogBuilder builder = new DialogBuilder(request.getProject());
        final CompositeDiffPanel diffPanel = createPanel(request, builder.getWindow(), builder);
        if (diffPanel == null) {
            Disposer.dispose(builder);
            return;
        }
        final Runnable onOkRunnable = request.getOnOkRunnable();
        if (onOkRunnable != null) {
            builder.setOkOperation(() -> {
                builder.getDialogWrapper().close(0);
                onOkRunnable.run();
            });
        } else {
            builder.removeAllActions();
        }
        builder.setCenterPanel(diffPanel.getComponent());
        builder.setPreferredFocusComponent(diffPanel.getPreferredFocusedComponent());
        builder.setTitle(request.getWindowTitle());
        builder.setDimensionServiceKey(request.getGroupKey());
        new AnAction() {

            public void actionPerformed(final AnActionEvent e) {
                builder.getDialogWrapper().close(0);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
        diffPanel.setDiffRequest(request);
        FrameDiffTool.showDiffDialog(builder, hints);
    } else {
        final FrameWrapper frameWrapper = new FrameWrapper(request.getProject(), request.getGroupKey());
        final CompositeDiffPanel diffPanel = createPanel(request, frameWrapper.getFrame(), frameWrapper);
        if (diffPanel == null) {
            Disposer.dispose(frameWrapper);
            return;
        }
        frameWrapper.setTitle(request.getWindowTitle());
        diffPanel.setDiffRequest(request);
        DiffUtil.initDiffFrame(request.getProject(), frameWrapper, diffPanel, diffPanel.getComponent());
        new AnAction() {

            public void actionPerformed(final AnActionEvent e) {
                Disposer.dispose(frameWrapper);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
        frameWrapper.show();
    }
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) FrameWrapper(com.intellij.openapi.ui.FrameWrapper) CompositeDiffPanel(com.intellij.openapi.diff.impl.CompositeDiffPanel) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)130 AnAction (com.intellij.openapi.actionSystem.AnAction)67 Project (com.intellij.openapi.project.Project)27 NotNull (org.jetbrains.annotations.NotNull)25 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 Nullable (org.jetbrains.annotations.Nullable)20 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)15 List (java.util.List)14 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)11 Presentation (com.intellij.openapi.actionSystem.Presentation)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)8 JBTable (com.intellij.ui.table.JBTable)8 DataContext (com.intellij.openapi.actionSystem.DataContext)7 Pair (com.intellij.openapi.util.Pair)7 Logger (com.intellij.openapi.diagnostic.Logger)6 Ref (com.intellij.openapi.util.Ref)6 AnActionButton (com.intellij.ui.AnActionButton)6