Search in sources :

Example 1 with JBPopupMenu

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

the class ActionMenu method getPopupMenu.

@Override
public JPopupMenu getPopupMenu() {
    if (mySpecialMenu == null) {
        mySpecialMenu = new JBPopupMenu();
        mySpecialMenu.setInvoker(this);
        popupListener = createWinListener(mySpecialMenu);
        ReflectionUtil.setField(JMenu.class, this, JPopupMenu.class, "popupMenu", mySpecialMenu);
    }
    return super.getPopupMenu();
}
Also used : JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu)

Example 2 with JBPopupMenu

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

the class ThemeEditorTable method getPopupMenuAtCell.

private JPopupMenu getPopupMenuAtCell(final int row, final int column) {
    if (row < 0 || column < 0) {
        return null;
    }
    TableModel rawModel = getModel();
    if (!(rawModel instanceof AttributesTableModel)) {
        return null;
    }
    final AttributesTableModel model = (AttributesTableModel) rawModel;
    AttributesTableModel.RowContents contents = model.getRowContents(this.convertRowIndexToModel(row));
    if (contents instanceof AttributesTableModel.AttributeContents) {
        final AttributesTableModel.AttributeContents attribute = (AttributesTableModel.AttributeContents) contents;
        final EditedStyleItem item = attribute.getValue();
        if (item == null) {
            return null;
        }
        final JBPopupMenu popupMenu = new JBPopupMenu();
        if (attribute.getCellClass(1) == ConfiguredThemeEditorStyle.class) {
            popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    myGoToListener.goTo(item);
                }
            });
        } else {
            final ResourceResolver resolver = myContext.getResourceResolver();
            assert resolver != null;
            final Project project = myContext.getProject();
            final ResourceValue resourceValue = resolver.resolveResValue(item.getSelectedValue());
            final File file = new File(resourceValue.getValue());
            final VirtualFileManager manager = VirtualFileManager.getInstance();
            final VirtualFile virtualFile = file.exists() ? manager.findFileByUrl("file://" + file.getAbsolutePath()) : null;
            if (virtualFile != null) {
                popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
                        FileEditorManager.getInstance(project).openEditor(descriptor, true);
                    }
                });
            }
        }
        myJavadocAction.setCurrentItem(item);
        popupMenu.add(myJavadocAction);
        final ConfiguredThemeEditorStyle selectedStyle = model.getSelectedStyle();
        if (!selectedStyle.isReadOnly() && selectedStyle.hasItem(item)) {
            popupMenu.add(new AbstractAction("Reset value") {

                @Override
                public void actionPerformed(ActionEvent e) {
                    selectedStyle.removeAttribute(item.getQualifiedName());
                    model.fireTableCellUpdated(attribute.getRowIndex(), 0);
                }
            });
        }
        return popupMenu;
    } else if (contents instanceof AttributesTableModel.ParentAttribute) {
        final ConfiguredThemeEditorStyle parentStyle = model.getSelectedStyle().getParent();
        if (parentStyle == null) {
            return null;
        }
        final JBPopupMenu menu = new JBPopupMenu();
        menu.add(new AbstractAction(GO_TO_DECLARATION) {

            @Override
            public void actionPerformed(ActionEvent e) {
                myGoToListener.goToParent();
            }
        });
        return menu;
    }
    return null;
}
Also used : AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) ActionEvent(java.awt.event.ActionEvent) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) Project(com.intellij.openapi.project.Project) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) TableModel(javax.swing.table.TableModel) AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel)

Example 3 with JBPopupMenu

use of com.intellij.openapi.ui.JBPopupMenu 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 JBPopupMenu

use of com.intellij.openapi.ui.JBPopupMenu 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 5 with JBPopupMenu

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

the class DeviceDefinitionList method possiblyShowPopup.

private void possiblyShowPopup(MouseEvent e) {
    if (!e.isPopupTrigger()) {
        return;
    }
    Point p = e.getPoint();
    int row = myTable.rowAtPoint(p);
    int col = myTable.columnAtPoint(p);
    if (row != -1 && col != -1) {
        JBPopupMenu menu = new JBPopupMenu();
        menu.add(createMenuItem(new CloneDeviceAction(this)));
        menu.add(createMenuItem(new EditDeviceAction(this)));
        menu.add(createMenuItem(new ExportDeviceAction(this)));
        menu.add(createMenuItem(new DeleteDeviceAction(this)));
        menu.show(myTable, p.x, p.y);
    }
}
Also used : JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu)

Aggregations

JBPopupMenu (com.intellij.openapi.ui.JBPopupMenu)14 ActionEvent (java.awt.event.ActionEvent)4 JBMenuItem (com.intellij.openapi.ui.JBMenuItem)3 NotNull (org.jetbrains.annotations.NotNull)3 ActionListener (java.awt.event.ActionListener)2 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 ResourceResolver (com.android.ide.common.resources.ResourceResolver)1 XmlNode (com.android.manifmerger.XmlNode)1 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)1 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)1 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)1 DnDManagerImpl (com.intellij.ide.dnd.DnDManagerImpl)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 Project (com.intellij.openapi.project.Project)1 JBCheckboxMenuItem (com.intellij.openapi.ui.JBCheckboxMenuItem)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1 PsiFile (com.intellij.psi.PsiFile)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1