public RightClickMenu(JabRefFrame frame, BasePanel panel) { this.panel = panel; JMenu typeMenu = new ChangeEntryTypeMenu().getChangeEntryTypeMenu(panel); // Are multiple entries selected? boolean multiple = areMultipleEntriesSelected(); // If only one entry is selected, get a reference to it for adapting the menu. BibEntry be = null; if (panel.getMainTable().getSelectedRowCount() == 1) { be = panel.getMainTable().getSelected().get(0); } addPopupMenuListener(this); JMenu copySpecialMenu = new JMenu(Localization.lang("Copy") + "..."); copySpecialMenu.add(new GeneralAction(Actions.COPY_KEY, Localization.lang("Copy BibTeX key"))); copySpecialMenu.add( new GeneralAction(Actions.COPY_CITE_KEY, Localization.lang("Copy \\cite{BibTeX key}"))); copySpecialMenu.add( new GeneralAction( Actions.COPY_KEY_AND_TITLE, Localization.lang("Copy BibTeX key and title"))); copySpecialMenu.add( new GeneralAction( Actions.EXPORT_TO_CLIPBOARD, Localization.lang("Export to clipboard"), IconTheme.JabRefIcon.EXPORT_TO_CLIPBOARD.getSmallIcon())); add( new GeneralAction( Actions.COPY, Localization.lang("Copy"), IconTheme.JabRefIcon.COPY.getSmallIcon())); add(copySpecialMenu); add( new GeneralAction( Actions.PASTE, Localization.lang("Paste"), IconTheme.JabRefIcon.PASTE.getSmallIcon())); add( new GeneralAction( Actions.CUT, Localization.lang("Cut"), IconTheme.JabRefIcon.CUT.getSmallIcon())); add( new GeneralAction( Actions.DELETE, Localization.lang("Delete"), IconTheme.JabRefIcon.DELETE_ENTRY.getSmallIcon())); add( new GeneralAction( Actions.PRINT_PREVIEW, Localization.lang("Print entry preview"), IconTheme.JabRefIcon.PRINTED.getSmallIcon())); addSeparator(); add( new GeneralAction( Actions.SEND_AS_EMAIL, Localization.lang("Send as email"), IconTheme.JabRefIcon.EMAIL.getSmallIcon())); addSeparator(); JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color")); for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) { markSpecific.add(new MarkEntriesAction(frame, i).getMenuItem()); } if (multiple) { add( new GeneralAction( Actions.MARK_ENTRIES, Localization.lang("Mark entries"), IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon())); add(markSpecific); add( new GeneralAction( Actions.UNMARK_ENTRIES, Localization.lang("Unmark entries"), IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon())); } else if (be != null) { Optional<String> marked = be.getFieldOptional(FieldName.MARKED_INTERNAL); // We have to check for "" too as the marked field may be empty if ((!marked.isPresent()) || marked.get().isEmpty()) { add( new GeneralAction( Actions.MARK_ENTRIES, Localization.lang("Mark entry"), IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon())); add(markSpecific); } else { add(markSpecific); add( new GeneralAction( Actions.UNMARK_ENTRIES, Localization.lang("Unmark entry"), IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon())); } } if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SPECIALFIELDSENABLED)) { if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_RANKING)) { JMenu rankingMenu = new JMenu(); RightClickMenu.populateSpecialFieldMenu(rankingMenu, Rank.getInstance(), frame); add(rankingMenu); } // TODO: multiple handling for relevance and quality-assurance // if multiple values are selected ("if (multiple)"), two options (set / clear) should be // offered // if one value is selected either set or clear should be offered if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_RELEVANCE)) { add(Relevance.getInstance().getValues().get(0).getMenuAction(frame)); } if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_QUALITY)) { add(Quality.getInstance().getValues().get(0).getMenuAction(frame)); } if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_PRINTED)) { add(Printed.getInstance().getValues().get(0).getMenuAction(frame)); } if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_PRIORITY)) { JMenu priorityMenu = new JMenu(); RightClickMenu.populateSpecialFieldMenu(priorityMenu, Priority.getInstance(), frame); add(priorityMenu); } if (Globals.prefs.getBoolean(JabRefPreferences.PREF_SHOWCOLUMN_READ)) { JMenu readStatusMenu = new JMenu(); RightClickMenu.populateSpecialFieldMenu(readStatusMenu, ReadStatus.getInstance(), frame); add(readStatusMenu); } } addSeparator(); add( new GeneralAction(Actions.OPEN_FOLDER, Localization.lang("Open folder")) { { if (!isFieldSetForSelectedEntry(FieldName.FILE)) { this.setEnabled(false); } } }); add( new GeneralAction( Actions.OPEN_EXTERNAL_FILE, Localization.lang("Open file"), getFileIconForSelectedEntry()) { { if (!isFieldSetForSelectedEntry(FieldName.FILE)) { this.setEnabled(false); } } }); add( new GeneralAction( Actions.OPEN_URL, Localization.lang("Open URL or DOI"), IconTheme.JabRefIcon.WWW.getSmallIcon()) { { if (!(isFieldSetForSelectedEntry(FieldName.URL) || isFieldSetForSelectedEntry(FieldName.DOI))) { this.setEnabled(false); } } }); addSeparator(); add(typeMenu); add( new GeneralAction( Actions.MERGE_WITH_FETCHED_ENTRY, Localization.lang( "Get BibTeX data from %0", FetchAndMergeEntry.getDisplayNameOfSupportedFields())) { { if (!(isAnyFieldSetForSelectedEntry(FetchAndMergeEntry.SUPPORTED_FIELDS))) { this.setEnabled(false); } } }); add(frame.getMassSetField()); add( new GeneralAction( Actions.ADD_FILE_LINK, Localization.lang("Attach file"), IconTheme.JabRefIcon.ATTACH_FILE.getSmallIcon())); add(frame.getManageKeywords()); add( new GeneralAction( Actions.MERGE_ENTRIES, Localization.lang("Merge entries") + "...", IconTheme.JabRefIcon.MERGE_ENTRIES.getSmallIcon()) { { if (!(areExactlyTwoEntriesSelected())) { this.setEnabled(false); } } }); addSeparator(); // for "add/move/remove to/from group" entries (appended here) groupAdd = new JMenuItem(new GeneralAction(Actions.ADD_TO_GROUP, Localization.lang("Add to group"))); add(groupAdd); groupRemove = new JMenuItem( new GeneralAction(Actions.REMOVE_FROM_GROUP, Localization.lang("Remove from group"))); add(groupRemove); groupMoveTo = add(new GeneralAction(Actions.MOVE_TO_GROUP, Localization.lang("Move to group"))); add(groupMoveTo); // create disabledIcons for all menu entries frame.createDisabledIconsForMenuEntries(this); }
class ExternalFileEntry { private JPanel pan; private final JTextField tf; private final JButton browse = new JButton(Localization.lang("Browse")); private final JButton view = new JButton(Localization.lang("Preview")); private final JButton clear = new JButton(IconTheme.JabRefIcon.DELETE_ENTRY.getIcon()); private final JButton download = new JButton(Localization.lang("Download")); public ExternalFileEntry() { tf = new JTextField(); setupPanel(); } public ExternalFileEntry(String filename) { tf = new JTextField(filename); setupPanel(); } private void setupPanel() { tf.setEditable(false); BrowseAction browseA = new BrowseAction(tf, false); browse.addActionListener(browseA); DownloadAction da = new DownloadAction(tf); download.addActionListener(da); FormBuilder builder = FormBuilder.create() .layout( new FormLayout( "fill:pref:grow, 4dlu, fill:pref, 4dlu, fill:pref, 4dlu, fill:pref, 4dlu, fill:pref", "p")); builder.add(tf).xy(1, 1); builder.add(browse).xy(3, 1); builder.add(download).xy(5, 1); builder.add(view).xy(7, 1); builder.add(clear).xy(9, 1); pan = builder.getPanel(); view.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { JournalAbbreviationRepository abbr = new JournalAbbreviationRepository(); abbr.readJournalListFromFile(new File(tf.getText())); JTable table = new JTable(JournalAbbreviationsUtil.getTableModel(abbr)); JScrollPane pane = new JScrollPane(table); JOptionPane.showMessageDialog( null, pane, Localization.lang("Journal list preview"), JOptionPane.INFORMATION_MESSAGE); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog( null, Localization.lang("File '%0' not found", tf.getText()), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); } } }); clear.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { externals.remove(ExternalFileEntry.this); buildExternalsPanel(); } }); clear.setToolTipText(Localization.lang("Remove")); } public JPanel getPanel() { return pan; } public String getValue() { return tf.getText(); } }