Search in sources :

Example 1 with LayoutFormatterPreferences

use of org.jabref.logic.layout.LayoutFormatterPreferences in project jabref by JabRef.

the class ArgumentProcessor method importPreferences.

private void importPreferences() {
    try {
        Globals.prefs.importPreferences(cli.getPreferencesImport());
        EntryTypes.loadCustomEntryTypes(Globals.prefs.loadCustomEntryTypes(BibDatabaseMode.BIBTEX), Globals.prefs.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX));
        Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs, Globals.journalAbbreviationLoader);
        LayoutFormatterPreferences layoutPreferences = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
        SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
        ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
    } catch (JabRefException ex) {
        LOGGER.error("Cannot import preferences", ex);
    }
}
Also used : LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) JabRefException(org.jabref.JabRefException) SavePreferences(org.jabref.logic.exporter.SavePreferences) IExportFormat(org.jabref.logic.exporter.IExportFormat) ExportFormat(org.jabref.logic.exporter.ExportFormat)

Example 2 with LayoutFormatterPreferences

use of org.jabref.logic.layout.LayoutFormatterPreferences in project jabref by JabRef.

the class DroppedFileHandler method showLinkMoveCopyRenameDialog.

//
// @return true if user pushed "OK", false otherwise
//
private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileType fileType, BibEntry entry, BibDatabase database) {
    String dialogTitle = Localization.lang("Link to file %0", linkFileName);
    Optional<Path> dir = panel.getBibDatabaseContext().getFirstExistingFileDir(Globals.prefs.getFileDirectoryPreferences());
    if (!dir.isPresent()) {
        destDirLabel.setText(Localization.lang("File directory is not set or does not exist!"));
        copyRadioButton.setEnabled(false);
        moveRadioButton.setEnabled(false);
        renameToTextBox.setEnabled(false);
        renameCheckBox.setEnabled(false);
        linkInPlace.setSelected(true);
    } else {
        destDirLabel.setText(Localization.lang("File directory is '%0':", dir.get().toString()));
        copyRadioButton.setEnabled(true);
        moveRadioButton.setEnabled(true);
        renameToTextBox.setEnabled(true);
        renameCheckBox.setEnabled(true);
    }
    ChangeListener cl = arg0 -> {
        renameCheckBox.setEnabled(!linkInPlace.isSelected());
        renameToTextBox.setEnabled(!linkInPlace.isSelected());
    };
    linkInPlace.setText(Localization.lang("Leave file in its current directory"));
    copyRadioButton.setText(Localization.lang("Copy file to file directory"));
    moveRadioButton.setText(Localization.lang("Move file to file directory"));
    renameCheckBox.setText(Localization.lang("Rename file to").concat(": "));
    LayoutFormatterPreferences layoutPrefs = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
    // Determine which name to suggest:
    String targetName = FileUtil.createFileNameFromPattern(database, entry, Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN), layoutPrefs);
    String fileDirPattern = Globals.prefs.get(JabRefPreferences.IMPORT_FILEDIRPATTERN);
    String targetDirName = "";
    if (!fileDirPattern.isEmpty()) {
        targetDirName = FileUtil.createFileNameFromPattern(database, entry, fileDirPattern, layoutPrefs);
    }
    if (targetDirName.isEmpty()) {
        renameToTextBox.setText(targetName.concat(".").concat(fileType.getExtension()));
    } else {
        renameToTextBox.setText(targetDirName.concat("/").concat(targetName.concat(".").concat(fileType.getExtension())));
    }
    linkInPlace.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_LEAVE));
    copyRadioButton.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_COPY));
    moveRadioButton.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_MOVE));
    renameCheckBox.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_RENAME));
    linkInPlace.addChangeListener(cl);
    cl.stateChanged(new ChangeEvent(linkInPlace));
    try {
        Object[] messages = { Localization.lang("How would you like to link to '%0'?", linkFileName), optionsPanel };
        int reply = JOptionPane.showConfirmDialog(frame, messages, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (reply == JOptionPane.OK_OPTION) {
            // store user's choice
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_LEAVE, linkInPlace.isSelected());
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_COPY, copyRadioButton.isSelected());
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_MOVE, moveRadioButton.isSelected());
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_RENAME, renameCheckBox.isSelected());
            return true;
        } else {
            return false;
        }
    } finally {
        linkInPlace.removeChangeListener(cl);
    }
}
Also used : Path(java.nio.file.Path) NamedCompound(org.jabref.gui.undo.NamedCompound) JTextField(javax.swing.JTextField) FieldName(org.jabref.model.entry.FieldName) BibDatabase(org.jabref.model.database.BibDatabase) JabRefPreferences(org.jabref.preferences.JabRefPreferences) BasePanel(org.jabref.gui.BasePanel) JabRefFrame(org.jabref.gui.JabRefFrame) Localization(org.jabref.logic.l10n.Localization) ChangeListener(javax.swing.event.ChangeListener) BorderLayout(java.awt.BorderLayout) Path(java.nio.file.Path) BoxLayout(javax.swing.BoxLayout) ExternalFileType(org.jabref.gui.externalfiletype.ExternalFileType) ChangeEvent(javax.swing.event.ChangeEvent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileUtil(org.jabref.logic.util.io.FileUtil) Files(java.nio.file.Files) ButtonGroup(javax.swing.ButtonGroup) BibEntry(org.jabref.model.entry.BibEntry) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) IOException(java.io.IOException) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) JOptionPane(javax.swing.JOptionPane) MainTable(org.jabref.gui.maintable.MainTable) IdGenerator(org.jabref.model.entry.IdGenerator) File(java.io.File) JRadioButton(javax.swing.JRadioButton) Globals(org.jabref.Globals) FileListEntry(org.jabref.gui.filelist.FileListEntry) FileHelper(org.jabref.model.util.FileHelper) List(java.util.List) Paths(java.nio.file.Paths) FormLayout(com.jgoodies.forms.layout.FormLayout) JLabel(javax.swing.JLabel) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) XMPUtil(org.jabref.logic.xmp.XMPUtil) Log(org.apache.commons.logging.Log) JTextArea(javax.swing.JTextArea) ExternalFileTypes(org.jabref.gui.externalfiletype.ExternalFileTypes) LogFactory(org.apache.commons.logging.LogFactory) JPanel(javax.swing.JPanel) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener)

Example 3 with LayoutFormatterPreferences

use of org.jabref.logic.layout.LayoutFormatterPreferences in project jabref by JabRef.

the class PreferencesDialog method updateAfterPreferenceChanges.

private void updateAfterPreferenceChanges() {
    setValues();
    Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs, Globals.journalAbbreviationLoader);
    LayoutFormatterPreferences layoutPreferences = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
    SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
    ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
    Globals.prefs.updateEntryEditorTabList();
}
Also used : LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) SavePreferences(org.jabref.logic.exporter.SavePreferences) ExportFormat(org.jabref.logic.exporter.ExportFormat)

Example 4 with LayoutFormatterPreferences

use of org.jabref.logic.layout.LayoutFormatterPreferences in project jabref by JabRef.

the class CustomExportList method readPrefs.

private void readPrefs(JabRefPreferences prefs, JournalAbbreviationLoader loader) {
    Objects.requireNonNull(prefs);
    Objects.requireNonNull(loader);
    formats.clear();
    list.clear();
    int i = 0;
    List<String> s;
    LayoutFormatterPreferences layoutPreferences = prefs.getLayoutFormatterPreferences(loader);
    SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(prefs);
    while (!((s = prefs.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)).isEmpty())) {
        Optional<ExportFormat> format = createFormat(s, layoutPreferences, savePreferences);
        if (format.isPresent()) {
            formats.put(format.get().getConsoleName(), format.get());
            list.add(s);
        } else {
            String customExportFormat = prefs.get(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i);
            LOGGER.error("Error initializing custom export format from string " + customExportFormat);
        }
        i++;
    }
}
Also used : LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) SavePreferences(org.jabref.logic.exporter.SavePreferences) ExportFormat(org.jabref.logic.exporter.ExportFormat)

Example 5 with LayoutFormatterPreferences

use of org.jabref.logic.layout.LayoutFormatterPreferences in project jabref by JabRef.

the class RenamePdfCleanupTest method setUp.

@Before
public void setUp() throws Exception {
    MetaData metaData = new MetaData();
    context = new BibDatabaseContext(new BibDatabase(), metaData, new Defaults());
    context.setDatabaseFile(testFolder.newFile("test.bib"));
    fileDirPrefs = mock(FileDirectoryPreferences.class);
    //Set Biblocation as Primary Directory, otherwise the tmp folders won't be cleaned up correctly
    when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(true);
    entry = new BibEntry();
    entry.setCiteKey("Toot");
    layoutFormatterPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS);
}
Also used : FileDirectoryPreferences(org.jabref.model.metadata.FileDirectoryPreferences) BibEntry(org.jabref.model.entry.BibEntry) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) Defaults(org.jabref.model.Defaults) MetaData(org.jabref.model.metadata.MetaData) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) BibDatabase(org.jabref.model.database.BibDatabase) Before(org.junit.Before)

Aggregations

LayoutFormatterPreferences (org.jabref.logic.layout.LayoutFormatterPreferences)11 ExportFormat (org.jabref.logic.exporter.ExportFormat)5 SavePreferences (org.jabref.logic.exporter.SavePreferences)5 BibEntry (org.jabref.model.entry.BibEntry)5 HashMap (java.util.HashMap)3 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)3 Before (org.junit.Before)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 JabRefFrame (org.jabref.gui.JabRefFrame)2 BibDatabase (org.jabref.model.database.BibDatabase)2 FormBuilder (com.jgoodies.forms.builder.FormBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 BorderLayout (java.awt.BorderLayout)1 ActionEvent (java.awt.event.ActionEvent)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1