Search in sources :

Example 1 with JBMenuItem

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

the class TabbedLanguageCodeStylePanel method fillPredefined.

private void fillPredefined(JMenuItem parentMenu) {
    for (final PredefinedCodeStyle predefinedCodeStyle : myPredefinedCodeStyles) {
        JMenuItem predefinedItem = new JBMenuItem(predefinedCodeStyle.getName());
        parentMenu.add(predefinedItem);
        predefinedItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                applyPredefinedStyle(predefinedCodeStyle.getName());
            }
        });
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JBMenuItem(com.intellij.openapi.ui.JBMenuItem)

Example 2 with JBMenuItem

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

the class DaemonEditorPopup method invokePopup.

@Override
public void invokePopup(final Component comp, final int x, final int y) {
    if (ApplicationManager.getApplication() == null)
        return;
    final JRadioButtonMenuItem errorsFirst = createRadioButtonMenuItem(EditorBundle.message("errors.panel.go.to.errors.first.radio"));
    errorsFirst.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DaemonCodeAnalyzerSettings.getInstance().NEXT_ERROR_ACTION_GOES_TO_ERRORS_FIRST = errorsFirst.isSelected();
        }
    });
    final JPopupMenu popupMenu = new JBPopupMenu();
    popupMenu.add(errorsFirst);
    final JRadioButtonMenuItem next = createRadioButtonMenuItem(EditorBundle.message("errors.panel.go.to.next.error.warning.radio"));
    next.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DaemonCodeAnalyzerSettings.getInstance().NEXT_ERROR_ACTION_GOES_TO_ERRORS_FIRST = !next.isSelected();
        }
    });
    popupMenu.add(next);
    ButtonGroup group = new ButtonGroup();
    group.add(errorsFirst);
    group.add(next);
    popupMenu.addSeparator();
    final JMenuItem hLevel = new JBMenuItem(EditorBundle.message("customize.highlighting.level.menu.item"));
    popupMenu.add(hLevel);
    final boolean isErrorsFirst = DaemonCodeAnalyzerSettings.getInstance().NEXT_ERROR_ACTION_GOES_TO_ERRORS_FIRST;
    errorsFirst.setSelected(isErrorsFirst);
    next.setSelected(!isErrorsFirst);
    hLevel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final PsiFile psiFile = myPsiFile;
            if (psiFile == null)
                return;
            final HectorComponent component = new HectorComponent(psiFile);
            final Dimension dimension = component.getPreferredSize();
            Point point = new Point(x, y);
            component.showComponent(new RelativePoint(comp, new Point(point.x - dimension.width, point.y)));
        }
    });
    final JBCheckboxMenuItem previewCheckbox = new JBCheckboxMenuItem(IdeBundle.message("checkbox.show.editor.preview.popup"), UISettings.getInstance().getShowEditorToolTip());
    popupMenu.addSeparator();
    popupMenu.add(previewCheckbox);
    previewCheckbox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            UISettings.getInstance().setShowToolWindowsNumbers(previewCheckbox.isSelected());
            UISettings.getInstance().fireUISettingsChanged();
        }
    });
    PsiFile file = myPsiFile;
    if (file != null && DaemonCodeAnalyzer.getInstance(myPsiFile.getProject()).isHighlightingAvailable(file)) {
        popupMenu.show(comp, x, y);
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) JBCheckboxMenuItem(com.intellij.openapi.ui.JBCheckboxMenuItem) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) ActionListener(java.awt.event.ActionListener) PsiFile(com.intellij.psi.PsiFile) JBMenuItem(com.intellij.openapi.ui.JBMenuItem)

Example 3 with JBMenuItem

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

the class VariantsComboBox method createPopupMenu.

@NotNull
protected JPopupMenu createPopupMenu() {
    JPopupMenu menu = new JBPopupMenu();
    Border existingBorder = menu.getBorder();
    if (existingBorder != null) {
        menu.setBorder(BorderFactory.createCompoundBorder(existingBorder, VARIANT_MENU_BORDER));
    } else {
        menu.setBorder(VARIANT_MENU_BORDER);
    }
    menu.setBackground(VARIANT_MENU_BACKGROUND_COLOR);
    int nElements = myModel.getSize();
    for (int i = 0; i < nElements; i++) {
        final Object element = myModel.getElementAt(i);
        JMenuItem item = new JBMenuItem(element.toString());
        item.setFont(ThemeEditorUtils.scaleFontForAttribute(item.getFont()));
        item.setBorder(VARIANT_ITEM_BORDER);
        if (i == 0) {
            // Pre-select the first element
            item.setArmed(true);
        }
        item.setBackground(VARIANT_MENU_BACKGROUND_COLOR);
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                Object selectedItem = myModel.getSelectedItem();
                if (selectedItem != null) {
                    fireItemSelectionChanged(new ItemEvent(VariantsComboBox.this, ItemEvent.ITEM_STATE_CHANGED, selectedItem, ItemEvent.DESELECTED));
                }
                myModel.setSelectedItem(element);
                fireModelUpdated();
                fireItemSelectionChanged(new ItemEvent(VariantsComboBox.this, ItemEvent.ITEM_STATE_CHANGED, element, ItemEvent.SELECTED));
            }
        });
        menu.add(item);
    }
    if (!myActions.isEmpty()) {
        if (nElements > 0) {
            menu.addSeparator();
        }
        for (Action action : myActions) {
            JMenuItem newMenuItem = new JBMenuItem(action);
            newMenuItem.setFont(ThemeEditorUtils.scaleFontForAttribute(newMenuItem.getFont()));
            newMenuItem.setBackground(VARIANT_MENU_BACKGROUND_COLOR);
            newMenuItem.setBorder(VARIANT_ITEM_BORDER);
            menu.add(newMenuItem);
        }
    }
    return menu;
}
Also used : JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) Border(javax.swing.border.Border) JBEmptyBorder(com.intellij.util.ui.JBEmptyBorder) JBMenuItem(com.intellij.openapi.ui.JBMenuItem) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JBMenuItem

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

the class TabbedLanguageCodeStylePanel method fillLanguages.

private void fillLanguages(JComponent parentMenu) {
    Language[] languages = LanguageCodeStyleSettingsProvider.getLanguagesWithCodeStyleSettings();
    @SuppressWarnings("UnnecessaryFullyQualifiedName") java.util.List<JMenuItem> langItems = new ArrayList<>();
    for (final Language lang : languages) {
        if (!lang.equals(getDefaultLanguage())) {
            final String langName = LanguageCodeStyleSettingsProvider.getLanguageName(lang);
            JMenuItem langItem = new JBMenuItem(langName);
            langItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    applyLanguageSettings(lang);
                }
            });
            langItems.add(langItem);
        }
    }
    Collections.sort(langItems, (item1, item2) -> item1.getText().compareToIgnoreCase(item2.getText()));
    for (JMenuItem langItem : langItems) {
        parentMenu.add(langItem);
    }
}
Also used : Language(com.intellij.lang.Language) java.util(java.util) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JBMenuItem(com.intellij.openapi.ui.JBMenuItem)

Example 5 with JBMenuItem

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

the class ManifestPanel method createPopupMenu.

private void createPopupMenu() {
    myPopup = new JBPopupMenu();
    JMenuItem gotoItem = new JBMenuItem("Go to Declaration");
    gotoItem.addActionListener(e -> {
        TreePath treePath = myTree.getSelectionPath();
        final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
        if (node != null) {
            goToDeclaration(node.getUserObject());
        }
    });
    myPopup.add(gotoItem);
    myRemoveItem = new JBMenuItem("Remove");
    myRemoveItem.addActionListener(e -> {
        TreePath treePath = myTree.getSelectionPath();
        final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
        new WriteCommandAction.Simple(myFacet.getModule().getProject(), "Removing manifest tag", ManifestUtils.getMainManifest(myFacet)) {

            @Override
            protected void run() throws Throwable {
                ManifestUtils.toolsRemove(ManifestUtils.getMainManifest(myFacet), node.getUserObject());
            }
        }.execute();
    });
    myPopup.add(myRemoveItem);
    MouseListener ml = new MouseAdapter() {

        @Override
        public void mousePressed(@NotNull MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopup(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopup(e);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
                if (treePath != null) {
                    ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
                    Node attribute = node.getUserObject();
                    if (attribute instanceof Attr) {
                        goToDeclaration(attribute);
                    }
                }
            }
        }

        private void handlePopup(@NotNull MouseEvent e) {
            TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
            if (treePath == null || e.getSource() == myDetails) {
                // Use selection instead
                treePath = myTree.getSelectionPath();
            }
            if (treePath != null) {
                ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
                myRemoveItem.setEnabled(canRemove(node.getUserObject()));
                myPopup.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    };
    myTree.addMouseListener(ml);
    myDetails.addMouseListener(ml);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) MouseEvent(java.awt.event.MouseEvent) XmlNode(com.android.manifmerger.XmlNode) MouseAdapter(java.awt.event.MouseAdapter) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) NotNull(org.jetbrains.annotations.NotNull) MouseListener(java.awt.event.MouseListener) JBMenuItem(com.intellij.openapi.ui.JBMenuItem)

Aggregations

JBMenuItem (com.intellij.openapi.ui.JBMenuItem)6 JBPopupMenu (com.intellij.openapi.ui.JBPopupMenu)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 NotNull (org.jetbrains.annotations.NotNull)3 XmlNode (com.android.manifmerger.XmlNode)1 Language (com.intellij.lang.Language)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 JBCheckboxMenuItem (com.intellij.openapi.ui.JBCheckboxMenuItem)1 PsiFile (com.intellij.psi.PsiFile)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 JBEmptyBorder (com.intellij.util.ui.JBEmptyBorder)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1 java.util (java.util)1 Border (javax.swing.border.Border)1