/** * Return a button which sets the owner if the field for fields with EXTRA_SET_OWNER * * @param fieldEditor * @param storeFieldAction * @return */ public static Optional<JComponent> getSetOwnerExtraComponent( FieldEditor fieldEditor, StoreFieldAction storeFieldAction) { JButton button = new JButton(Localization.lang("Auto")); button.addActionListener( actionEvent -> { fieldEditor.setText(Globals.prefs.get(JabRefPreferences.DEFAULT_OWNER)); storeFieldAction.actionPerformed(new ActionEvent(fieldEditor, 0, "")); }); return Optional.of(button); }
/** * Add controls for switching between abbreviated and full journal names. If this field also has a * FieldContentSelector, we need to combine these. * * @param panel * @param editor * @param entry * @param storeFieldAction * @return */ public static Optional<JComponent> getJournalExtraComponent( JabRefFrame frame, BasePanel panel, FieldEditor editor, BibEntry entry, Set<FieldContentSelector> contentSelectors, StoreFieldAction storeFieldAction) { JPanel controls = new JPanel(); controls.setLayout(new BorderLayout()); if (!panel .getBibDatabaseContext() .getMetaData() .getContentSelectorValuesForField(editor.getFieldName()) .isEmpty()) { FieldContentSelector ws = new FieldContentSelector(frame, panel, frame, editor, storeFieldAction, false, ", "); contentSelectors.add(ws); controls.add(ws, BorderLayout.NORTH); } // Button to toggle abbreviated/full journal names JButton button = new JButton(Localization.lang("Toggle abbreviation")); button.setToolTipText(ABBREVIATION_TOOLTIP_TEXT); button.addActionListener( actionEvent -> { String text = editor.getText(); JournalAbbreviationRepository abbreviationRepository = Globals.journalAbbreviationLoader.getRepository( Globals.prefs.getJournalAbbreviationPreferences()); if (abbreviationRepository.isKnownName(text)) { String s = abbreviationRepository.getNextAbbreviation(text).orElse(text); if (s != null) { editor.setText(s); storeFieldAction.actionPerformed(new ActionEvent(editor, 0, "")); panel .getUndoManager() .addEdit(new UndoableFieldChange(entry, editor.getFieldName(), text, s)); } } }); controls.add(button, BorderLayout.SOUTH); return Optional.of(controls); }