Search in sources :

Example 46 with JPopupMenu

use of javax.swing.JPopupMenu in project jabref by JabRef.

the class MainTableSelectionListener method showIconRightClickMenu.

/**
     * Process popup trigger events occurring on an icon cell in the table. Show a menu where the user can choose which
     * external resource to open for the entry. If no relevant external resources exist, let the normal popup trigger
     * handler do its thing instead.
     *
     * @param e The mouse event defining this popup trigger.
     * @param row The row where the event occurred.
     * @param column the MainTableColumn associated with this table cell.
     */
private void showIconRightClickMenu(MouseEvent e, int row, MainTableColumn column) {
    BibEntry entry = tableRows.get(row);
    JPopupMenu menu = new JPopupMenu();
    boolean showDefaultPopup = true;
    // field that can specify a list of links:
    if (!column.getBibtexFields().isEmpty()) {
        for (String field : column.getBibtexFields()) {
            if (FieldName.FILE.equals(field)) {
                // We use a FileListTableModel to parse the field content:
                FileListTableModel fileList = new FileListTableModel();
                entry.getField(field).ifPresent(fileList::setContent);
                for (int i = 0; i < fileList.getRowCount(); i++) {
                    FileListEntry flEntry = fileList.getEntry(i);
                    if (column.isFileFilter() && (!flEntry.getType().get().getName().equalsIgnoreCase(column.getColumnName()))) {
                        continue;
                    }
                    String description = flEntry.getDescription();
                    if ((description == null) || (description.trim().isEmpty())) {
                        description = flEntry.getLink();
                    }
                    menu.add(new ExternalFileMenuItem(panel.frame(), entry, description, flEntry.getLink(), flEntry.getType().get().getIcon(), panel.getBibDatabaseContext(), flEntry.getType()));
                    showDefaultPopup = false;
                }
            } else {
                if (SpecialField.isSpecialField(column.getColumnName())) {
                    // full pop should be shown as left click already shows short popup
                    showDefaultPopup = true;
                } else {
                    Optional<String> content = entry.getField(field);
                    if (content.isPresent()) {
                        Icon icon;
                        JLabel iconLabel = GUIGlobals.getTableIcon(field);
                        if (iconLabel == null) {
                            icon = IconTheme.JabRefIcon.FILE.getIcon();
                        } else {
                            icon = iconLabel.getIcon();
                        }
                        menu.add(new ExternalFileMenuItem(panel.frame(), entry, content.get(), content.get(), icon, panel.getBibDatabaseContext(), field));
                        if (field.equals(FieldName.DOI)) {
                            menu.add(new CopyDoiUrlAction(content.get()));
                        }
                        showDefaultPopup = false;
                    }
                }
            }
        }
        if (showDefaultPopup) {
            processPopupTrigger(e, row);
        } else {
            menu.show(table, e.getX(), e.getY());
        }
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) ExternalFileMenuItem(org.jabref.gui.externalfiletype.ExternalFileMenuItem) FileListEntry(org.jabref.gui.filelist.FileListEntry) JLabel(javax.swing.JLabel) JPopupMenu(javax.swing.JPopupMenu) CopyDoiUrlAction(org.jabref.gui.actions.CopyDoiUrlAction) Icon(javax.swing.Icon)

Example 47 with JPopupMenu

use of javax.swing.JPopupMenu in project jabref by JabRef.

the class MainTableSelectionListener method handleSpecialFieldLeftClick.

/**
     * Method to handle a single left click on one the special fields (e.g., ranking, quality, ...)
     * Shows either a popup to select/clear a value or simply toggles the functionality to set/unset the special field
     *
     * @param e MouseEvent used to determine the position of the popups
     * @param columnName the name of the specialfield column
     */
private void handleSpecialFieldLeftClick(MouseEvent e, String columnName) {
    if ((e.getClickCount() == 1)) {
        SpecialField.getSpecialFieldInstanceFromFieldName(columnName).ifPresent(field -> {
            if (field.isSingleValueField()) {
                new SpecialFieldViewModel(field).getSpecialFieldAction(field.getValues().get(0), panel.frame()).action();
            } else {
                JPopupMenu menu = new JPopupMenu();
                for (SpecialFieldValue val : field.getValues()) {
                    menu.add(new SpecialFieldMenuAction(new SpecialFieldValueViewModel(val), panel.frame()));
                }
                menu.show(table, e.getX(), e.getY());
            }
        });
    }
}
Also used : SpecialFieldMenuAction(org.jabref.gui.specialfields.SpecialFieldMenuAction) SpecialFieldValueViewModel(org.jabref.gui.specialfields.SpecialFieldValueViewModel) SpecialFieldViewModel(org.jabref.gui.specialfields.SpecialFieldViewModel) JPopupMenu(javax.swing.JPopupMenu) SpecialFieldValue(org.jabref.model.entry.specialfields.SpecialFieldValue)

Example 48 with JPopupMenu

use of javax.swing.JPopupMenu in project JMRI by JMRI.

the class BeanTableDataModel method showPopup.

/*{
     return "Bean";
     }*/
protected void showPopup(MouseEvent e) {
    JTable source = (JTable) e.getSource();
    int row = source.rowAtPoint(e.getPoint());
    int column = source.columnAtPoint(e.getPoint());
    if (!source.isRowSelected(row)) {
        source.changeSelection(row, column, false, false);
    }
    final int rowindex = source.convertRowIndexToModel(row);
    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem(Bundle.getMessage("CopyName"));
    menuItem.addActionListener((ActionEvent e1) -> {
        copyName(rowindex, 0);
    });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("Rename"));
    menuItem.addActionListener((ActionEvent e1) -> {
        renameBean(rowindex, 0);
    });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("Clear"));
    menuItem.addActionListener((ActionEvent e1) -> {
        removeName(rowindex, 0);
    });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("Move"));
    menuItem.addActionListener((ActionEvent e1) -> {
        moveBean(rowindex, 0);
    });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("ButtonDelete"));
    menuItem.addActionListener((ActionEvent e1) -> {
        deleteBean(rowindex, 0);
    });
    popupMenu.add(menuItem);
    popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
Also used : ActionEvent(java.awt.event.ActionEvent) JTable(javax.swing.JTable) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 49 with JPopupMenu

use of javax.swing.JPopupMenu in project JMRI by JMRI.

the class CatalogPanel method showPopUp.

/**
     * Return the icon selected in the preview panel Save this code in case
     * there is a need to use an alternative icon changing method rather than
     * DnD.
     *
     * public NamedIcon getSelectedIcon() { if (_selectedImage != null) { JLabel
     * l = (JLabel)_selectedImage.getComponent(0); // deselect
     * //setSelectionBackground(_currentBackground); Save for use as alternative
     * to DnD. _selectedImage = null; return (NamedIcon)l.getIcon(); } return
     * null; }
     */
private void showPopUp(MouseEvent e, NamedIcon icon) {
    if (log.isDebugEnabled()) {
        log.debug("showPopUp {}", icon.toString());
    }
    JPopupMenu popup = new JPopupMenu();
    popup.add(new JMenuItem(icon.getName()));
    popup.add(new JMenuItem(icon.getURL()));
    popup.add(new javax.swing.JPopupMenu.Separator());
    popup.add(new AbstractAction(Bundle.getMessage("RenameIcon")) {

        NamedIcon icon;

        @Override
        public void actionPerformed(ActionEvent e) {
            rename(icon);
        }

        AbstractAction init(NamedIcon i) {
            icon = i;
            return this;
        }
    }.init(icon));
    popup.add(new javax.swing.JPopupMenu.Separator());
    popup.add(new AbstractAction(Bundle.getMessage("DeleteIcon")) {

        NamedIcon icon;

        @Override
        public void actionPerformed(ActionEvent e) {
            delete(icon);
        }

        AbstractAction init(NamedIcon i) {
            icon = i;
            return this;
        }
    }.init(icon));
    popup.show(e.getComponent(), e.getX(), e.getY());
}
Also used : ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JPopupMenu(javax.swing.JPopupMenu)

Example 50 with JPopupMenu

use of javax.swing.JPopupMenu in project JMRI by JMRI.

the class RosterGroupsPanel method defaultMenu.

private JPopupMenu defaultMenu(int menu) {
    JPopupMenu pm = new JPopupMenu();
    MenuActionListener ml = new MenuActionListener();
    JMenuItem mi = new JMenuItem(Bundle.getMessage("Exportddd"));
    mi.addActionListener(ml);
    mi.setActionCommand("export");
    pm.add(mi);
    mi = new JMenuItem(Bundle.getMessage("Importddd"));
    mi.addActionListener(ml);
    mi.setActionCommand("import");
    pm.add(mi);
    if (menu == GROUPS_MENU) {
        pm.addSeparator();
        // key is in jmri.NamedBeanBundle
        mi = new JMenuItem(Bundle.getMessage("Renameddd"));
        mi.addActionListener(ml);
        mi.setActionCommand("rename");
        pm.add(mi);
        mi = new JMenuItem(Bundle.getMessage("Duplicateddd"));
        mi.addActionListener(ml);
        mi.setActionCommand("duplicate");
        pm.add(mi);
        mi = new JMenuItem(Bundle.getMessage("ButtonDelete"));
        mi.addActionListener(ml);
        mi.setActionCommand("delete");
        pm.add(mi);
    }
    return pm;
}
Also used : JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Aggregations

JPopupMenu (javax.swing.JPopupMenu)203 JMenuItem (javax.swing.JMenuItem)105 ActionEvent (java.awt.event.ActionEvent)61 ActionListener (java.awt.event.ActionListener)46 JMenu (javax.swing.JMenu)28 Point (java.awt.Point)24 Component (java.awt.Component)20 JLabel (javax.swing.JLabel)20 JSeparator (javax.swing.JSeparator)19 JScrollPane (javax.swing.JScrollPane)18 MouseEvent (java.awt.event.MouseEvent)17 JButton (javax.swing.JButton)16 AbstractAction (javax.swing.AbstractAction)15 BorderLayout (java.awt.BorderLayout)13 JPanel (javax.swing.JPanel)13 JTable (javax.swing.JTable)13 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)12 MouseAdapter (java.awt.event.MouseAdapter)11 ArrayList (java.util.ArrayList)11 Icon (javax.swing.Icon)11