Search in sources :

Example 1 with TypedBibEntry

use of org.jabref.logic.TypedBibEntry in project jabref by JabRef.

the class EntryEditor method setupToolBar.

private void setupToolBar() {
    JPanel leftPan = new JPanel();
    leftPan.setLayout(new BorderLayout());
    JToolBar toolBar = new OSXCompatibleToolbar(SwingConstants.VERTICAL);
    toolBar.setBorder(null);
    toolBar.setRollover(true);
    toolBar.setMargin(new Insets(0, 0, 0, 2));
    // The toolbar carries all the key bindings that are valid for the whole window.
    ActionMap actionMap = toolBar.getActionMap();
    InputMap inputMap = toolBar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_ENTRY_EDITOR), "close");
    actionMap.put("close", closeAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store");
    actionMap.put("store", storeFieldAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOGENERATE_BIBTEX_KEYS), "generateKey");
    actionMap.put("generateKey", generateKeyAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOMATICALLY_LINK_FILES), "autoLink");
    actionMap.put("autoLink", autoLinkAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_ENTRY), "prev");
    actionMap.put("prev", prevEntryAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_ENTRY), "next");
    actionMap.put("next", nextEntryAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.UNDO), "undo");
    actionMap.put("undo", undoAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.REDO), "redo");
    actionMap.put("redo", redoAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help");
    actionMap.put("help", helpAction);
    toolBar.setFloatable(false);
    // Add actions (and thus buttons)
    JButton closeBut = new JButton(closeAction);
    closeBut.setText(null);
    closeBut.setBorder(null);
    closeBut.setMargin(new Insets(8, 0, 8, 0));
    leftPan.add(closeBut, BorderLayout.NORTH);
    // Create type-label
    TypedBibEntry typedEntry = new TypedBibEntry(entry, panel.getBibDatabaseContext().getMode());
    leftPan.add(new TypeLabel(typedEntry.getTypeForDisplay()), BorderLayout.CENTER);
    TypeButton typeButton = new TypeButton();
    toolBar.add(typeButton);
    toolBar.add(generateKeyAction);
    toolBar.add(autoLinkAction);
    toolBar.add(writeXmp);
    JPopupMenu fetcherPopup = new JPopupMenu();
    for (EntryBasedFetcher fetcher : WebFetchers.getEntryBasedFetchers(Globals.prefs.getImportFormatPreferences())) {
        fetcherPopup.add(new JMenuItem(new AbstractAction(fetcher.getName()) {

            @Override
            public void actionPerformed(ActionEvent e) {
                new EntryFetchAndMergeWorker(panel, getEntry(), fetcher).execute();
            }
        }));
    }
    JButton fetcherButton = new JButton(IconTheme.JabRefIcon.REFRESH.getIcon());
    fetcherButton.setToolTipText(Localization.lang("Update with bibliographic information from the web"));
    fetcherButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            fetcherPopup.show(e.getComponent(), e.getX(), e.getY());
        }
    });
    toolBar.add(fetcherButton);
    toolBar.addSeparator();
    toolBar.add(deleteAction);
    toolBar.add(prevEntryAction);
    toolBar.add(nextEntryAction);
    toolBar.addSeparator();
    toolBar.add(helpAction);
    Component[] comps = toolBar.getComponents();
    for (Component comp : comps) {
        ((JComponent) comp).setOpaque(false);
    }
    leftPan.add(toolBar, BorderLayout.SOUTH);
    add(leftPan, BorderLayout.WEST);
}
Also used : JPanel(javax.swing.JPanel) Insets(java.awt.Insets) MouseEvent(java.awt.event.MouseEvent) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) MouseAdapter(java.awt.event.MouseAdapter) JComponent(javax.swing.JComponent) EntryFetchAndMergeWorker(org.jabref.gui.mergeentries.EntryFetchAndMergeWorker) JToolBar(javax.swing.JToolBar) TypedBibEntry(org.jabref.logic.TypedBibEntry) JPopupMenu(javax.swing.JPopupMenu) BorderLayout(java.awt.BorderLayout) OSXCompatibleToolbar(org.jabref.gui.OSXCompatibleToolbar) InputMap(javax.swing.InputMap) EntryBasedFetcher(org.jabref.logic.importer.EntryBasedFetcher) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) AbstractAction(javax.swing.AbstractAction)

Example 2 with TypedBibEntry

use of org.jabref.logic.TypedBibEntry in project jabref by JabRef.

the class FirstColumnComparator method compare.

@Override
public int compare(BibEntry e1, BibEntry e2) {
    int score1 = 0;
    int score2 = 0;
    TypedBibEntry typedEntry1 = new TypedBibEntry(e1, database);
    TypedBibEntry typedEntry2 = new TypedBibEntry(e2, database);
    if (typedEntry1.hasAllRequiredFields()) {
        score1++;
    }
    if (typedEntry2.hasAllRequiredFields()) {
        score2++;
    }
    return score1 - score2;
}
Also used : TypedBibEntry(org.jabref.logic.TypedBibEntry)

Example 3 with TypedBibEntry

use of org.jabref.logic.TypedBibEntry in project jabref by JabRef.

the class BibEntryWriter method writeRequiredFieldsFirstRemainingFieldsSecond.

/**
     * Write fields in the order of requiredFields, optionalFields and other fields, but does not sort the fields.
     *
     * @param entry
     * @param out
     * @throws IOException
     */
private void writeRequiredFieldsFirstRemainingFieldsSecond(BibEntry entry, Writer out, BibDatabaseMode bibDatabaseMode) throws IOException {
    // Write header with type and bibtex-key.
    TypedBibEntry typedEntry = new TypedBibEntry(entry, bibDatabaseMode);
    out.write('@' + typedEntry.getTypeForDisplay() + '{');
    writeKeyField(entry, out);
    Set<String> written = new HashSet<>();
    written.add(BibEntry.KEY_FIELD);
    int indentation = getLengthOfLongestFieldName(entry);
    EntryType type = EntryTypes.getTypeOrDefault(entry.getType(), bibDatabaseMode);
    // Write required fields first.
    List<String> fields = type.getRequiredFieldsFlat();
    if (fields != null) {
        for (String value : fields) {
            writeField(entry, out, value, indentation);
            written.add(value);
        }
    }
    // Then optional fields.
    fields = type.getOptionalFields();
    if (fields != null) {
        for (String value : fields) {
            if (!written.contains(value)) {
                // If field appears both in req. and opt. don't repeat.
                writeField(entry, out, value, indentation);
                written.add(value);
            }
        }
    }
    // Then write remaining fields in alphabetic order.
    Set<String> remainingFields = new TreeSet<>();
    for (String key : entry.getFieldNames()) {
        boolean writeIt = write ? InternalBibtexFields.isWriteableField(key) : InternalBibtexFields.isDisplayableField(key);
        if (!written.contains(key) && writeIt) {
            remainingFields.add(key);
        }
    }
    for (String field : remainingFields) {
        writeField(entry, out, field, indentation);
    }
    // Finally, end the entry.
    out.write('}');
}
Also used : EntryType(org.jabref.model.entry.EntryType) TreeSet(java.util.TreeSet) TypedBibEntry(org.jabref.logic.TypedBibEntry) HashSet(java.util.HashSet)

Example 4 with TypedBibEntry

use of org.jabref.logic.TypedBibEntry in project jabref by JabRef.

the class EntryTypeFormatter method format.

/**
     * Input: entry type as a string
     */
@Override
public String format(String entryType) {
    BibEntry entry = new BibEntry();
    entry.setType(entryType);
    TypedBibEntry typedEntry = new TypedBibEntry(entry, BibDatabaseMode.BIBLATEX);
    return typedEntry.getTypeForDisplay();
}
Also used : TypedBibEntry(org.jabref.logic.TypedBibEntry) BibEntry(org.jabref.model.entry.BibEntry) TypedBibEntry(org.jabref.logic.TypedBibEntry)

Example 5 with TypedBibEntry

use of org.jabref.logic.TypedBibEntry in project jabref by JabRef.

the class XMPUtil method writeToDCSchema.

private static void writeToDCSchema(XMPSchemaDublinCore dcSchema, BibEntry entry, BibDatabase database, XMPPreferences xmpPreferences) {
    BibEntry resolvedEntry;
    if (database == null) {
        resolvedEntry = entry;
    } else {
        resolvedEntry = database.resolveForStrings(entry, false);
    }
    // Query privacy filter settings
    boolean useXmpPrivacyFilter = xmpPreferences.isUseXMPPrivacyFilter();
    // Fields for which not to write XMP data later on:
    Set<String> filters = new TreeSet<>(xmpPreferences.getXmpPrivacyFilter());
    for (Entry<String, String> field : resolvedEntry.getFieldMap().entrySet()) {
        if (useXmpPrivacyFilter && filters.contains(field.getKey())) {
            continue;
        }
        if (FieldName.EDITOR.equals(field.getKey())) {
            String authors = field.getValue();
            /*
                 * Editor -> Contributor
                 *
                 * Field: dc:contributor
                 *
                 * Type: bag ProperName
                 *
                 * Category: External
                 *
                 * Description: Contributors to the resource (other than the
                 * authors).
                 *
                 * Bibtex-Fields used: editor
                 */
            AuthorList list = AuthorList.parse(authors);
            for (Author author : list.getAuthors()) {
                dcSchema.addContributor(author.getFirstLast(false));
            }
            continue;
        }
        /*
             * ? -> Coverage
             *
             * Unmapped
             *
             * dc:coverage Text External The extent or scope of the resource.
             *
             * Author -> Creator
             *
             * Field: dc:creator
             *
             * Type: seq ProperName
             *
             * Category: External
             *
             * Description: The authors of the resource (listed in order of
             * precedence, if significant).
             *
             * Bibtex-Fields used: author
             */
        if (FieldName.AUTHOR.equals(field.getKey())) {
            String authors = field.getValue();
            AuthorList list = AuthorList.parse(authors);
            for (Author author : list.getAuthors()) {
                dcSchema.addCreator(author.getFirstLast(false));
            }
            continue;
        }
        if (FieldName.MONTH.equals(field.getKey())) {
            // Dealt with in year
            continue;
        }
        if (FieldName.YEAR.equals(field.getKey())) {
            /*
                 * Year + Month -> Date
                 *
                 * Field: dc:date
                 *
                 * Type: seq Date
                 *
                 * Category: External
                 *
                 * Description: Date(s) that something interesting happened to
                 * the resource.
                 *
                 * Bibtex-Fields used: year, month
                 */
            entry.getPublicationDate().ifPresent(publicationDate -> dcSchema.addSequenceValue("dc:date", publicationDate));
            continue;
        }
        /*
             * Abstract -> Description
             *
             * Field: dc:description
             *
             * Type: Lang Alt
             *
             * Category: External
             *
             * Description: A textual description of the content of the
             * resource. Multiple values may be present for different languages.
             *
             * Bibtex-Fields used: abstract
             */
        if (FieldName.ABSTRACT.equals(field.getKey())) {
            dcSchema.setDescription(field.getValue());
            continue;
        }
        /*
             * DOI -> identifier
             *
             * Field: dc:identifier
             *
             * Type: Text
             *
             * Category: External
             *
             * Description: Unique identifier of the resource.
             *
             * Bibtex-Fields used: doi
             */
        if (FieldName.DOI.equals(field.getKey())) {
            dcSchema.setIdentifier(field.getValue());
            continue;
        }
        /*
             * Publisher -> Publisher
             *
             * Field: dc:publisher
             *
             * Type: bag ProperName
             *
             * Category: External
             *
             * Description: Publishers.
             *
             * Bibtex-Fields used: doi
             */
        if (FieldName.PUBLISHER.equals(field.getKey())) {
            dcSchema.addPublisher(field.getValue());
            continue;
        }
        /*
             * Keywords -> Subject
             *
             * Field: dc:subject
             *
             * Type: bag Text
             *
             * Category: External
             *
             * Description: An unordered array of descriptive phrases or
             * keywords that specify the topic of the content of the resource.
             *
             * Bibtex-Fields used: doi
             */
        if (FieldName.KEYWORDS.equals(field.getKey())) {
            String o = field.getValue();
            String[] keywords = o.split(",");
            for (String keyword : keywords) {
                dcSchema.addSubject(keyword.trim());
            }
            continue;
        }
        /*
             * Title -> Title
             *
             * Field: dc:title
             *
             * Type: Lang Alt
             *
             * Category: External
             *
             * Description: The title of the document, or the name given to the
             * resource. Typically, it will be a name by which the resource is
             * formally known.
             *
             * Bibtex-Fields used: title
             */
        if (FieldName.TITLE.equals(field.getKey())) {
            dcSchema.setTitle(field.getValue());
            continue;
        }
        /*
             * All others (including the bibtex key) get packaged in the
             * relation attribute
             */
        String o = field.getValue();
        dcSchema.addRelation("bibtex/" + field.getKey() + '/' + o);
    }
    /*
         * ? -> Format
         *
         * Unmapped
         *
         * dc:format MIMEType Internal The file format used when saving the
         * resource. Tools and applications should set this property to the save
         * format of the data. It may include appropriate qualifiers.
         */
    dcSchema.setFormat("application/pdf");
    /*
         * entrytype -> Type
         *
         * Field: dc:type
         *
         * Type: bag open Choice
         *
         * Category: External
         *
         * Description: A document type; for example, novel, poem, or working
         * paper.
         *
         * Bibtex-Fields used: entrytype
         */
    TypedBibEntry typedEntry = new TypedBibEntry(entry, BibDatabaseMode.BIBTEX);
    String o = typedEntry.getTypeForDisplay();
    if (!o.isEmpty()) {
        dcSchema.addType(o);
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) TypedBibEntry(org.jabref.logic.TypedBibEntry) TreeSet(java.util.TreeSet) AuthorList(org.jabref.model.entry.AuthorList) Author(org.jabref.model.entry.Author) TypedBibEntry(org.jabref.logic.TypedBibEntry)

Aggregations

TypedBibEntry (org.jabref.logic.TypedBibEntry)5 TreeSet (java.util.TreeSet)2 BibEntry (org.jabref.model.entry.BibEntry)2 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 HashSet (java.util.HashSet)1 AbstractAction (javax.swing.AbstractAction)1 ActionMap (javax.swing.ActionMap)1 InputMap (javax.swing.InputMap)1 JButton (javax.swing.JButton)1 JComponent (javax.swing.JComponent)1 JMenuItem (javax.swing.JMenuItem)1 JPanel (javax.swing.JPanel)1 JPopupMenu (javax.swing.JPopupMenu)1 JToolBar (javax.swing.JToolBar)1 JTextComponent (javax.swing.text.JTextComponent)1