From b231bb02ab85a4e1a061257baf948bc497353496 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 5 Mar 2019 19:20:48 +0100 Subject: [PATCH 01/11] remove unused swing stuff convert help buttons --- src/main/java/org/jabref/gui/WrapLayout.java | 175 ------------ .../BibtexKeyPatternPanel.java | 15 +- .../java/org/jabref/gui/help/HelpAction.java | 19 -- .../journals/JournalAbbreviationsUtil.java | 34 --- .../jabref/gui/preferences/AdvancedTab.java | 10 +- .../jabref/gui/preferences/ExternalTab.java | 22 +- .../logic/citationstyle/CSLAdapter.java | 8 +- .../migrations/FileLinksUpgradeWarning.java | 256 ------------------ 8 files changed, 28 insertions(+), 511 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/WrapLayout.java delete mode 100644 src/main/java/org/jabref/gui/journals/JournalAbbreviationsUtil.java delete mode 100644 src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java diff --git a/src/main/java/org/jabref/gui/WrapLayout.java b/src/main/java/org/jabref/gui/WrapLayout.java deleted file mode 100644 index 999c7abd3f0..00000000000 --- a/src/main/java/org/jabref/gui/WrapLayout.java +++ /dev/null @@ -1,175 +0,0 @@ -package org.jabref.gui; - -import java.awt.Component; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Insets; - -import javax.swing.JScrollPane; -import javax.swing.SwingUtilities; - -/** - * FlowLayout subclass that fully supports wrapping of components. - */ -public class WrapLayout extends FlowLayout { - /** - * Constructs a new WrapLayout with a left - * alignment and a default 5-unit horizontal and vertical gap. - */ - public WrapLayout() { - super(); - } - - /** - * Constructs a new FlowLayout with the specified - * alignment and a default 5-unit horizontal and vertical gap. - * The value of the alignment argument must be one of - * WrapLayout, WrapLayout, - * or WrapLayout. - * @param align the alignment value - */ - public WrapLayout(int align) { - super(align); - } - - /** - * Creates a new flow layout manager with the indicated alignment - * and the indicated horizontal and vertical gaps. - *

- * The value of the alignment argument must be one of - * WrapLayout, WrapLayout, - * or WrapLayout. - * @param align the alignment value - * @param hgap the horizontal gap between components - * @param vgap the vertical gap between components - */ - public WrapLayout(int align, int hgap, int vgap) { - super(align, hgap, vgap); - } - - /** - * Returns the preferred dimensions for this layout given the - * visible components in the specified target container. - * @param target the component which needs to be laid out - * @return the preferred dimensions to lay out the - * subcomponents of the specified container - */ - @Override - public Dimension preferredLayoutSize(Container target) { - return layoutSize(target, true); - } - - /** - * Returns the minimum dimensions needed to layout the visible - * components contained in the specified target container. - * @param target the component which needs to be laid out - * @return the minimum dimensions to lay out the - * subcomponents of the specified container - */ - @Override - public Dimension minimumLayoutSize(Container target) { - Dimension minimum = layoutSize(target, false); - minimum.width -= (getHgap() + 1); - return minimum; - } - - /** - * Returns the minimum or preferred dimension needed to layout the target - * container. - * - * @param target target to get layout size for - * @param preferred should preferred size be calculated - * @return the dimension to layout the target container - */ - private Dimension layoutSize(Container target, boolean preferred) { - synchronized (target.getTreeLock()) { - // Each row must fit with the width allocated to the container. - // When the container width = 0, the preferred width of the container - // has not yet been calculated so lets ask for the maximum. - - int targetWidth = target.getSize().width; - - if (targetWidth == 0) { - targetWidth = Integer.MAX_VALUE; - } - - int hgap = getHgap(); - int vgap = getVgap(); - Insets insets = target.getInsets(); - int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); - int maxWidth = targetWidth - horizontalInsetsAndGap; - - // Fit components into the allowed width - - Dimension dim = new Dimension(0, 0); - int rowWidth = 0; - int rowHeight = 0; - - int nmembers = target.getComponentCount(); - - for (int i = 0; i < nmembers; i++) { - Component m = target.getComponent(i); - - if (m.isVisible()) { - Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize(); - - if (d != null) { - // Can't add the component to current row. Start a new row. - - if ((rowWidth + d.width) > maxWidth) { - addRow(dim, rowWidth, rowHeight); - rowWidth = 0; - rowHeight = 0; - } - - // Add a horizontal gap for all components after the first - - if (rowWidth != 0) { - rowWidth += hgap; - } - - rowWidth += d.width; - rowHeight = Math.max(rowHeight, d.height); - } - } - } - - addRow(dim, rowWidth, rowHeight); - - dim.width += horizontalInsetsAndGap; - dim.height += insets.top + insets.bottom + (vgap * 2); - - // When using a scroll pane or the DecoratedLookAndFeel we need to - // make sure the preferred size is less than the size of the - // target container so shrinking the container size works - // correctly. Removing the horizontal gap is an easy way to do this. - - Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); - - if (scrollPane != null) { - dim.width -= (hgap + 1); - } - - return dim; - } - } - - /* - * A new row has been completed. Use the dimensions of this row - * to update the preferred size for the container. - * - * @param dim update the width and height when appropriate - * @param rowWidth the width of the row to add - * @param rowHeight the height of the row to add - */ - private void addRow(Dimension dim, int rowWidth, int rowHeight) { - dim.width = Math.max(dim.width, rowWidth); - - if (dim.height > 0) { - dim.height += getVgap(); - } - - dim.height += rowHeight; - } -} diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java index 994452e5efa..a5a8b27c55b 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java @@ -15,6 +15,8 @@ import org.jabref.Globals; import org.jabref.gui.BasePanel; +import org.jabref.gui.actions.ActionFactory; +import org.jabref.gui.actions.StandardActions; import org.jabref.gui.help.HelpAction; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; @@ -34,7 +36,6 @@ public class BibtexKeyPatternPanel extends Pane { // default pattern protected final TextField defaultPat = new TextField(); - private final HelpAction help; private final int COLUMNS = 2; @@ -45,7 +46,6 @@ public class BibtexKeyPatternPanel extends Pane { public BibtexKeyPatternPanel(BasePanel panel) { this.panel = panel; - help = new HelpAction(Localization.lang("Help on key patterns"), HelpFile.BIBTEX_KEY_PATTERN); gridPane.setHgap(10); gridPane.setVgap(5); buildGUI(); @@ -93,7 +93,7 @@ private void buildGUI() { textFields.put(type.getName().toLowerCase(Locale.ROOT), textField); - if (columnIndex == COLUMNS - 1) { + if (columnIndex == (COLUMNS - 1)) { columnIndex = 0; rowIndex++; } else { @@ -103,9 +103,10 @@ private void buildGUI() { rowIndex++; - Button help1 = new Button("?"); - help1.setOnAction(e -> new HelpAction(Localization.lang("Help on key patterns"), HelpFile.BIBTEX_KEY_PATTERN).getHelpButton().doClick()); - gridPane.add(help1, 1, rowIndex); + + ActionFactory factory = new ActionFactory(Globals.prefs.getKeyBindingRepository()); + Button help = factory.createIconButton(StandardActions.HELP, new HelpAction(Localization.lang("Help on key patterns"), HelpFile.BIBTEX_KEY_PATTERN).getCommand()); + gridPane.add(help, 1, rowIndex); Button btnDefaultAll1 = new Button(Localization.lang("Reset all")); btnDefaultAll1.setOnAction(e -> { @@ -162,7 +163,7 @@ public void setValues(AbstractBibtexKeyPattern keyPattern) { setValue(entry.getValue(), entry.getKey(), keyPattern); } - if (keyPattern.getDefaultValue() == null || keyPattern.getDefaultValue().isEmpty()) { + if ((keyPattern.getDefaultValue() == null) || keyPattern.getDefaultValue().isEmpty()) { defaultPat.setText(""); } else { defaultPat.setText(keyPattern.getDefaultValue().get(0)); diff --git a/src/main/java/org/jabref/gui/help/HelpAction.java b/src/main/java/org/jabref/gui/help/HelpAction.java index ab7ae84e027..e8d410de343 100644 --- a/src/main/java/org/jabref/gui/help/HelpAction.java +++ b/src/main/java/org/jabref/gui/help/HelpAction.java @@ -1,11 +1,7 @@ package org.jabref.gui.help; -import java.awt.Color; -import java.awt.Cursor; import java.awt.Dimension; import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; @@ -14,7 +10,6 @@ import javax.swing.Action; import javax.swing.Icon; import javax.swing.JButton; -import javax.swing.JLabel; import javax.swing.KeyStroke; import org.jabref.Globals; @@ -91,20 +86,6 @@ public void setHelpFile(HelpFile urlPart) { this.helpPage = urlPart; } - public JLabel getHelpLabel(String labelText) { - JLabel helpLabel = new JLabel("" + labelText + ""); - helpLabel.setForeground(Color.BLUE); - helpLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); - helpLabel.addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent e) { - openHelpPage(helpPage); - } - }); - return helpLabel; - } - @Override public void actionPerformed(ActionEvent e) { openHelpPage(helpPage); diff --git a/src/main/java/org/jabref/gui/journals/JournalAbbreviationsUtil.java b/src/main/java/org/jabref/gui/journals/JournalAbbreviationsUtil.java deleted file mode 100644 index 86a284cd78f..00000000000 --- a/src/main/java/org/jabref/gui/journals/JournalAbbreviationsUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.jabref.gui.journals; - -import java.util.Collection; - -import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableModel; - -import org.jabref.logic.journals.Abbreviation; -import org.jabref.logic.l10n.Localization; - -public class JournalAbbreviationsUtil { - - private JournalAbbreviationsUtil() { - } - - public static TableModel getTableModel(Collection abbreviations) { - Object[][] cells = new Object[abbreviations.size()][2]; - int row = 0; - for (Abbreviation abbreviation : abbreviations) { - cells[row][0] = abbreviation.getName(); - cells[row][1] = abbreviation.getIsoAbbreviation(); - row++; - } - - return new DefaultTableModel(cells, new Object[] {Localization.lang("Full name"), - Localization.lang("Abbreviation")}) { - - @Override - public boolean isCellEditable(int row1, int column) { - return false; - } - }; - } -} diff --git a/src/main/java/org/jabref/gui/preferences/AdvancedTab.java b/src/main/java/org/jabref/gui/preferences/AdvancedTab.java index 3fcd0516ce5..4a8dbf0a075 100644 --- a/src/main/java/org/jabref/gui/preferences/AdvancedTab.java +++ b/src/main/java/org/jabref/gui/preferences/AdvancedTab.java @@ -15,6 +15,8 @@ import org.jabref.Globals; import org.jabref.gui.DialogService; +import org.jabref.gui.actions.ActionFactory; +import org.jabref.gui.actions.StandardActions; import org.jabref.gui.help.HelpAction; import org.jabref.gui.remote.JabRefMessageHandler; import org.jabref.gui.util.DefaultTaskExecutor; @@ -76,9 +78,11 @@ public AdvancedTab(DialogService dialogService, JabRefPreferences prefs) { HBox p = new HBox(); p.getChildren().add(useRemoteServer); p.getChildren().add(remoteServerPort); - Button helpButton = new Button("?"); - helpButton.setOnAction(event -> new HelpAction(HelpFile.REMOTE).getHelpButton().doClick()); - p.getChildren().add(helpButton); + + ActionFactory factory = new ActionFactory(preferences.getKeyBindingRepository()); + Button help = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.REMOTE).getCommand()); + help.setMaxWidth(Double.MAX_VALUE); + p.getChildren().add(help); builder.add(p, 2, 9); builder.add(new Label(""), 1, 10); diff --git a/src/main/java/org/jabref/gui/preferences/ExternalTab.java b/src/main/java/org/jabref/gui/preferences/ExternalTab.java index 782a14fa11d..3b819033f9d 100644 --- a/src/main/java/org/jabref/gui/preferences/ExternalTab.java +++ b/src/main/java/org/jabref/gui/preferences/ExternalTab.java @@ -1,13 +1,8 @@ package org.jabref.gui.preferences; -import java.awt.BorderLayout; - import javax.swing.JFileChooser; -import javax.swing.JPanel; -import javafx.embed.swing.JFXPanel; import javafx.scene.Node; -import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.Label; @@ -15,10 +10,10 @@ import javafx.scene.control.TextField; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; import org.jabref.Globals; import org.jabref.gui.JabRefFrame; -import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.externalfiletype.ExternalFileTypeEditor; import org.jabref.gui.push.PushToApplication; import org.jabref.gui.push.PushToApplicationSettings; @@ -28,7 +23,7 @@ import org.jabref.logic.util.OS; import org.jabref.preferences.JabRefPreferences; -class ExternalTab extends JPanel implements PrefsTab { +class ExternalTab extends Pane implements PrefsTab { private final JabRefPreferences prefs; private final TextField emailSubject; @@ -135,11 +130,11 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere builder.add(openPdf, 1, 12); builder.add(pdfOptionPanel, 1, 13); - JFXPanel panel = CustomJFXPanel.wrap(new Scene(builder)); - setLayout(new BorderLayout()); - add(panel, BorderLayout.CENTER); + + FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder(). } + @Override public Node getBuilder() { return builder; } @@ -149,10 +144,10 @@ private void addSettingsButton(final PushToApplication application, GridPane pan Button button = new Button(Localization.lang("Settings for %0", application.getApplicationName())); button.setPrefSize(150, 20); button.setOnAction(e -> PushToApplicationSettingsDialog.showSettingsDialog(null, settings, index)); - if (index % 2 == 0) { - panel.add(button, 1, index / 2 + 1); + if ((index % 2) == 0) { + panel.add(button, 1, (index / 2) + 1); } else { - panel.add(button, 2, index / 2 + 1); + panel.add(button, 2, (index / 2) + 1); } } @@ -213,6 +208,7 @@ private void updateExecuteConsoleButtonAndFieldEnabledState() { } private void showConsoleChooser() { + JFileChooser consoleChooser = new JFileChooser(); int answer = consoleChooser.showOpenDialog(ExternalTab.this); if (answer == JFileChooser.APPROVE_OPTION) { diff --git a/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java b/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java index cda929568d2..0de338a1f0f 100644 --- a/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java +++ b/src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java @@ -31,9 +31,9 @@ * same style. Changing the output format is cheap. * @implNote The main function {@link #makeBibliography} will enforce * synchronized calling. The main CSL engine under the hood is not thread-safe. Since this class is usually called from - * a SwingWorker, the only other option would be to create several CSL instances which is wasting a lot of resources and very slow. + * a BackgroundTakk, the only other option would be to create several CSL instances which is wasting a lot of resources and very slow. * In the current scheme, {@link #makeBibliography} can be called as usual - * SwingWorker task and to the best of my knowledge, concurrent calls will pile up and processed sequentially. + * background task and to the best of my knowledge, concurrent calls will pile up and processed sequentially. */ public class CSLAdapter { @@ -63,7 +63,7 @@ public synchronized List makeBibliography(List bibEntries, Str * @throws IOException An error occurred in the underlying JavaScript framework */ private void initialize(String newStyle, CitationStyleOutputFormat newFormat) throws IOException { - if (cslInstance == null || !Objects.equals(newStyle, style)) { + if ((cslInstance == null) || !Objects.equals(newStyle, style)) { // lang and forceLang are set to the default values of other CSL constructors cslInstance = new CSL(dataProvider, new JabRefLocaleProvider(), newStyle, "en-US", false); style = newStyle; @@ -81,7 +81,7 @@ private void initialize(String newStyle, CitationStyleOutputFormat newFormat) th */ private static class JabRefItemDataProvider implements ItemDataProvider { - private ArrayList data = new ArrayList<>(); + private final ArrayList data = new ArrayList<>(); /** * Converts the {@link BibEntry} into {@link CSLItemData}. diff --git a/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java b/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java deleted file mode 100644 index eed9497457e..00000000000 --- a/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java +++ /dev/null @@ -1,256 +0,0 @@ -package org.jabref.migrations; - -import java.util.List; - -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import org.jabref.Globals; -import org.jabref.gui.BasePanel; -import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.importer.actions.GUIPostOpenAction; -import org.jabref.gui.undo.NamedCompound; -import org.jabref.gui.undo.UndoableFieldChange; -import org.jabref.gui.util.DefaultTaskExecutor; -import org.jabref.gui.util.FileDialogConfiguration; -import org.jabref.logic.cleanup.UpgradePdfPsToFileCleanup; -import org.jabref.logic.importer.ParserResult; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.FieldChange; -import org.jabref.model.database.BibDatabase; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; -import org.jabref.model.metadata.FilePreferences; -import org.jabref.preferences.JabRefPreferences; - -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; - -/** - * This class defines the warning that can be offered when opening a pre-2.3 - * JabRef file into a later version. This warning mentions the new external file - * link system in this version of JabRef, and offers to: - * - * * upgrade old-style PDF/PS links into the "file" field - * * modify General fields to show "file" instead of "pdf" / "ps" - * * modify table column settings to show "file" instead of "pdf" / "ps" - */ -public class FileLinksUpgradeWarning implements GUIPostOpenAction { - - private static final String[] FIELDS_TO_LOOK_FOR = new String[]{FieldName.PDF, FieldName.PS}; - - private boolean offerChangeSettings; - - private boolean offerChangeDatabase; - - private boolean offerSetFileDir; - - /** - * Collect file links from the given set of fields, and add them to the list contained in the field - * GUIGlobals.FILE_FIELD. - * - * @param database The database to modify. - * @return A CompoundEdit specifying the undo operation for the whole operation. - */ - private static NamedCompound upgradePdfPsToFile(BibDatabase database) { - NamedCompound ce = new NamedCompound(Localization.lang("Move external links to 'file' field")); - - UpgradePdfPsToFileCleanup cleanupJob = new UpgradePdfPsToFileCleanup(); - for (BibEntry entry : database.getEntries()) { - List changes = cleanupJob.cleanup(entry); - - for (FieldChange change : changes) { - ce.addEdit(new UndoableFieldChange(change)); - } - } - - ce.end(); - return ce; - } - - /** - * This method should be performed if the major/minor versions recorded in the ParserResult - * are less than or equal to 2.2. - * - * @return true if the file was written by a jabref version <=2.2 - */ - @Override - public boolean isActionNecessary(ParserResult pr) { - // Find out which actions should be offered: - // Only offer to change Preferences if file column is not already visible: - offerChangeSettings = !Globals.prefs.getBoolean(JabRefPreferences.FILE_COLUMN) || !showsFileInGenFields(); - // Only offer to upgrade links if the pdf/ps fields are used: - offerChangeDatabase = linksFound(pr.getDatabase(), FileLinksUpgradeWarning.FIELDS_TO_LOOK_FOR); - // If the "file" directory is not set, offer to migrate pdf/ps dir: - offerSetFileDir = !Globals.prefs.hasKey(FieldName.FILE + FilePreferences.DIR_SUFFIX) - && (Globals.prefs.hasKey(FieldName.PDF + FilePreferences.DIR_SUFFIX) - || Globals.prefs.hasKey(FieldName.PS + FilePreferences.DIR_SUFFIX)); - - // First check if this warning is disabled: - return Globals.prefs.getBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING) - && isThereSomethingToBeDone(); - } - - /* - * This method presents a dialog box explaining and offering to make the - * changes. If the user confirms, the changes are performed. - */ - @Override - public void performAction(BasePanel panel, ParserResult parserResult) { - - if (!isThereSomethingToBeDone()) { - return; // Nothing to do, just return. - } - - JCheckBox changeSettings = new JCheckBox( - Localization.lang("Change table column and General fields settings to use the new feature"), - offerChangeSettings); - JCheckBox changeDatabase = new JCheckBox( - Localization.lang("Upgrade old external file links to use the new feature"), - offerChangeDatabase); - JCheckBox setFileDir = new JCheckBox(Localization.lang("Set main external file directory") + ":", - offerSetFileDir); - JTextField fileDir = new JTextField(30); - JCheckBox doNotShowDialog = new JCheckBox(Localization.lang("Do not show these options in the future"), - false); - - JPanel message = new JPanel(); - FormBuilder formBuilder = FormBuilder.create().layout(new FormLayout("left:pref", "p")); - // Keep the formatting of these lines. Otherwise, strings have to be translated again. - // See updated JabRef_en.properties modifications by python syncLang.py -s -u - int row = 1; - formBuilder.add(new JLabel("" + Localization.lang("This library uses outdated file links.") + "

" - + Localization - .lang("JabRef no longer supports 'ps' or 'pdf' fields.
File links are now stored in the 'file' field and files are stored in an external file directory.
To make use of this feature, JabRef needs to upgrade file links.

") - + "

" - + Localization.lang("Do you want JabRef to do the following operations?") + "")).xy(1, row); - - if (offerChangeSettings) { - formBuilder.appendRows("2dlu, p"); - row += 2; - formBuilder.add(changeSettings).xy(1, row); - } - if (offerChangeDatabase) { - formBuilder.appendRows("2dlu, p"); - row += 2; - formBuilder.add(changeDatabase).xy(1, row); - } - if (offerSetFileDir) { - if (Globals.prefs.hasKey(FieldName.PDF + FilePreferences.DIR_SUFFIX)) { - fileDir.setText(Globals.prefs.get(FieldName.PDF + FilePreferences.DIR_SUFFIX)); - } else { - fileDir.setText(Globals.prefs.get(FieldName.PS + FilePreferences.DIR_SUFFIX)); - } - JPanel builderPanel = new JPanel(); - builderPanel.add(setFileDir); - builderPanel.add(fileDir); - JButton browse = new JButton(Localization.lang("Browse")); - - FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); - DialogService ds = new FXDialogService(); - - browse.addActionListener( - e -> DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration) - .ifPresent(f -> fileDir.setText(f.toAbsolutePath().toString())))); - builderPanel.add(browse); - formBuilder.appendRows("2dlu, p"); - row += 2; - formBuilder.add(builderPanel).xy(1, row); - } - formBuilder.appendRows("6dlu, p"); - formBuilder.add(doNotShowDialog).xy(1, row + 2); - - message.add(formBuilder.build()); - - int answer = JOptionPane.showConfirmDialog(null, - message, Localization.lang("Upgrade file"), JOptionPane.YES_NO_OPTION); - if (doNotShowDialog.isSelected()) { - Globals.prefs.putBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING, false); - } - - if (answer == JOptionPane.YES_OPTION) { - makeChanges(panel, parserResult, changeSettings.isSelected(), changeDatabase.isSelected(), - setFileDir.isSelected() ? fileDir.getText() : null); - } - } - - private boolean isThereSomethingToBeDone() { - return offerChangeSettings || offerChangeDatabase || offerSetFileDir; - } - - /** - * Check the database to find out whether any of a set of fields are used - * for any of the entries. - * - * @param database The BIB database. - * @param fields The set of fields to look for. - * @return true if at least one of the given fields is set in at least one entry, - * false otherwise. - */ - private boolean linksFound(BibDatabase database, String[] fields) { - for (BibEntry entry : database.getEntries()) { - for (String field : fields) { - if (entry.hasField(field)) { - return true; - } - } - } - return false; - } - - /** - * This method performs the actual changes. - * - * @param fileDir The path to the file directory to set, or null if it should not be set. - */ - private void makeChanges(BasePanel panel, ParserResult pr, boolean upgradePrefs, - boolean upgradeDatabase, String fileDir) { - - if (upgradeDatabase) { - // Update file links links in the database: - NamedCompound ce = upgradePdfPsToFile(pr.getDatabase()); - panel.getUndoManager().addEdit(ce); - panel.markBaseChanged(); - } - - if (fileDir != null) { - Globals.prefs.put(FieldName.FILE + FilePreferences.DIR_SUFFIX, fileDir); - } - - if (upgradePrefs) { - // Exchange table columns: - Globals.prefs.putBoolean(JabRefPreferences.FILE_COLUMN, Boolean.TRUE); - - // Modify General fields if necessary: - // If we don't find the file field, insert it at the bottom of the first tab: - if (!showsFileInGenFields()) { - String gfs = Globals.prefs.get(JabRefPreferences.CUSTOM_TAB_FIELDS + "0"); - StringBuilder sb = new StringBuilder(gfs); - if (!gfs.isEmpty()) { - sb.append(';'); - } - sb.append(FieldName.FILE); - Globals.prefs.put(JabRefPreferences.CUSTOM_TAB_FIELDS + "0", sb.toString()); - Globals.prefs.updateEntryEditorTabList(); - } - panel.frame().setupAllTables(); - } - } - - private boolean showsFileInGenFields() { - for (List fields : Globals.prefs.getEntryEditorTabList().values()) { - for (String field : fields) { - if (field.equals(FieldName.FILE)) { - return true; - } - } - } - return false; - } -} From 187cc0fcb47c905f520d59f8e876e4a9ebecb424 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 5 Mar 2019 19:31:16 +0100 Subject: [PATCH 02/11] convert file chooser in preferences --- .../jabref/gui/preferences/ExternalTab.java | 54 ++++++++----------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/ExternalTab.java b/src/main/java/org/jabref/gui/preferences/ExternalTab.java index 3b819033f9d..8d3b1bf17e9 100644 --- a/src/main/java/org/jabref/gui/preferences/ExternalTab.java +++ b/src/main/java/org/jabref/gui/preferences/ExternalTab.java @@ -1,7 +1,5 @@ package org.jabref.gui.preferences; -import javax.swing.JFileChooser; - import javafx.scene.Node; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; @@ -13,12 +11,14 @@ import javafx.scene.layout.Pane; import org.jabref.Globals; +import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; import org.jabref.gui.externalfiletype.ExternalFileTypeEditor; import org.jabref.gui.push.PushToApplication; import org.jabref.gui.push.PushToApplicationSettings; import org.jabref.gui.push.PushToApplicationSettingsDialog; import org.jabref.gui.push.PushToApplications; +import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.OS; import org.jabref.preferences.JabRefPreferences; @@ -40,12 +40,15 @@ class ExternalTab extends Pane implements PrefsTab { private final TextField adobeAcrobatReaderPath; private final TextField sumatraReaderPath; private final GridPane builder = new GridPane(); + private final DialogService dialogService; + private final FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().build(); public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPreferences prefs) { this.prefs = prefs; + dialogService = frame.getDialogService(); Button editFileTypes = new Button(Localization.lang("Manage external file types")); citeCommand = new TextField(); - editFileTypes.setOnAction(e->ExternalFileTypeEditor.getAction()); + editFileTypes.setOnAction(e -> ExternalFileTypeEditor.getAction()); defaultConsole = new RadioButton(Localization.lang("Use default terminal emulator")); executeConsole = new RadioButton(Localization.lang("Execute command") + ":"); consoleCommand = new TextField(); @@ -68,25 +71,25 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere final ToggleGroup consoleGroup = new ToggleGroup(); defaultConsole.setToggleGroup(consoleGroup); executeConsole.setToggleGroup(consoleGroup); - consoleOptionPanel.add(defaultConsole, 1, 1); - consoleOptionPanel.add(executeConsole, 1, 2); - consoleOptionPanel.add(consoleCommand, 2, 2); - consoleOptionPanel.add(browseButton, 3, 2); - consoleOptionPanel.add(commandDescription, 2, 3); + consoleOptionPanel.add(defaultConsole, 1, 1); + consoleOptionPanel.add(executeConsole, 1, 2); + consoleOptionPanel.add(consoleCommand, 2, 2); + consoleOptionPanel.add(browseButton, 3, 2); + consoleOptionPanel.add(commandDescription, 2, 3); GridPane pdfOptionPanel = new GridPane(); final ToggleGroup pdfReaderGroup = new ToggleGroup(); - pdfOptionPanel.add(adobeAcrobatReader, 1, 1); - pdfOptionPanel.add(adobeAcrobatReaderPath, 2, 1); + pdfOptionPanel.add(adobeAcrobatReader, 1, 1); + pdfOptionPanel.add(adobeAcrobatReaderPath, 2, 1); adobeAcrobatReader.setToggleGroup(pdfReaderGroup); - pdfOptionPanel.add(browseAdobeAcrobatReader, 3, 1); + pdfOptionPanel.add(browseAdobeAcrobatReader, 3, 1); if (OS.WINDOWS) { browseSumatraReader.setOnAction(e -> showSumatraChooser()); - pdfOptionPanel.add(sumatraReader, 1, 2); + pdfOptionPanel.add(sumatraReader, 1, 2); sumatraReader.setToggleGroup(pdfReaderGroup); - pdfOptionPanel.add(sumatraReaderPath, 2, 2); - pdfOptionPanel.add(browseSumatraReader, 3, 2); + pdfOptionPanel.add(sumatraReaderPath, 2, 2); + pdfOptionPanel.add(browseSumatraReader, 3, 2); } Label sendingOfEmails = new Label(Localization.lang("Sending of emails")); @@ -127,11 +130,10 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere Label openPdf = new Label(Localization.lang("Open PDF")); openPdf.getStyleClass().add("sectionHeader"); - builder.add(openPdf, 1, 12); + builder.add(openPdf, 1, 12); builder.add(pdfOptionPanel, 1, 13); - FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder(). } @Override @@ -208,28 +210,16 @@ private void updateExecuteConsoleButtonAndFieldEnabledState() { } private void showConsoleChooser() { - - JFileChooser consoleChooser = new JFileChooser(); - int answer = consoleChooser.showOpenDialog(ExternalTab.this); - if (answer == JFileChooser.APPROVE_OPTION) { - consoleCommand.setText(consoleChooser.getSelectedFile().getAbsolutePath()); - } + dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> consoleCommand.setText(file.toAbsolutePath().toString())); } private void showAdobeChooser() { - JFileChooser adobeChooser = new JFileChooser(); - int answer = adobeChooser.showOpenDialog(ExternalTab.this); - if (answer == JFileChooser.APPROVE_OPTION) { - adobeAcrobatReaderPath.setText(adobeChooser.getSelectedFile().getAbsolutePath()); - } + dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> adobeAcrobatReaderPath.setText(file.toAbsolutePath().toString())); + } private void showSumatraChooser() { - JFileChooser adobeChooser = new JFileChooser(); - int answer = adobeChooser.showOpenDialog(ExternalTab.this); - if (answer == JFileChooser.APPROVE_OPTION) { - sumatraReaderPath.setText(adobeChooser.getSelectedFile().getAbsolutePath()); - } + dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> sumatraReaderPath.setText(file.toAbsolutePath().toString())); } private void readerSelected() { From d6f0b5854adbadf695ab50dbfa4dbe832982585e Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 5 Mar 2019 19:35:27 +0100 Subject: [PATCH 03/11] cleanup --- src/main/java/org/jabref/gui/preferences/ExternalTab.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/ExternalTab.java b/src/main/java/org/jabref/gui/preferences/ExternalTab.java index 8d3b1bf17e9..0f96816e55e 100644 --- a/src/main/java/org/jabref/gui/preferences/ExternalTab.java +++ b/src/main/java/org/jabref/gui/preferences/ExternalTab.java @@ -8,7 +8,6 @@ import javafx.scene.control.TextField; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.GridPane; -import javafx.scene.layout.Pane; import org.jabref.Globals; import org.jabref.gui.DialogService; @@ -23,7 +22,7 @@ import org.jabref.logic.util.OS; import org.jabref.preferences.JabRefPreferences; -class ExternalTab extends Pane implements PrefsTab { +class ExternalTab implements PrefsTab { private final JabRefPreferences prefs; private final TextField emailSubject; From 0a155b9364554aad6ea1d7e21f53832c567ed04d Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 5 Mar 2019 19:36:40 +0100 Subject: [PATCH 04/11] fix build --- .../org/jabref/gui/importer/actions/OpenDatabaseAction.java | 4 ---- src/main/java/org/jabref/gui/preferences/ExternalTab.java | 1 - 2 files changed, 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java index 9a87333b386..67bd022cbc0 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -35,7 +35,6 @@ import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; import org.jabref.logic.shared.exception.NotASharedDatabaseException; import org.jabref.logic.util.StandardFileType; -import org.jabref.migrations.FileLinksUpgradeWarning; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.shared.DatabaseNotSupportedException; import org.jabref.preferences.JabRefPreferences; @@ -53,9 +52,6 @@ public class OpenDatabaseAction extends SimpleCommand { // Migrations: // Warning for migrating the Review into the Comment field new MergeReviewIntoCommentAction(), - // External file handling system in version 2.3: - new FileLinksUpgradeWarning(), - // Check for new custom entry types loaded from the BIB file: new CheckForNewEntryTypesAction() ); diff --git a/src/main/java/org/jabref/gui/preferences/ExternalTab.java b/src/main/java/org/jabref/gui/preferences/ExternalTab.java index 0f96816e55e..0328eaf4e1b 100644 --- a/src/main/java/org/jabref/gui/preferences/ExternalTab.java +++ b/src/main/java/org/jabref/gui/preferences/ExternalTab.java @@ -214,7 +214,6 @@ private void showConsoleChooser() { private void showAdobeChooser() { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> adobeAcrobatReaderPath.setText(file.toAbsolutePath().toString())); - } private void showSumatraChooser() { From 731b9d2ea588e9e03c0fac385da8120b523344f4 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 5 Mar 2019 20:49:18 +0100 Subject: [PATCH 05/11] remove obsolete localization strings fix checkstyle --- .../bibtexkeypattern/BibtexKeyPatternPanel.java | 5 +---- src/main/resources/l10n/JabRef_en.properties | 15 --------------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java index a5a8b27c55b..e3796c623ee 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java @@ -103,7 +103,6 @@ private void buildGUI() { rowIndex++; - ActionFactory factory = new ActionFactory(Globals.prefs.getKeyBindingRepository()); Button help = factory.createIconButton(StandardActions.HELP, new HelpAction(Localization.lang("Help on key patterns"), HelpFile.BIBTEX_KEY_PATTERN).getCommand()); gridPane.add(help, 1, rowIndex); @@ -119,7 +118,6 @@ private void buildGUI() { gridPane.add(btnDefaultAll1, 2, rowIndex); } - /** * fill the given LabelPattern by values generated from the text fields */ @@ -141,8 +139,7 @@ private void fillPatternUsingPanelData(AbstractBibtexKeyPattern keypatterns) { protected GlobalBibtexKeyPattern getKeyPatternAsGlobalBibtexKeyPattern() { GlobalBibtexKeyPattern res = GlobalBibtexKeyPattern.fromPattern( - JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN) - ); + JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN)); fillPatternUsingPanelData(res); return res; } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 8c0d5cedea9..b7f8e0dd5ea 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -137,8 +137,6 @@ Change\ of\ Grouping\ Method=Change of Grouping Method change\ preamble=change preamble -Change\ table\ column\ and\ General\ fields\ settings\ to\ use\ the\ new\ feature=Change table column and General fields settings to use the new feature - Changed\ language\ settings=Changed language settings Changed\ preamble=Changed preamble @@ -283,13 +281,10 @@ Do\ not\ import\ entry=Do not import entry Do\ not\ open\ any\ files\ at\ startup=Do not open any files at startup Do\ not\ overwrite\ existing\ keys=Do not overwrite existing keys -Do\ not\ show\ these\ options\ in\ the\ future=Do not show these options in the future Do\ not\ wrap\ the\ following\ fields\ when\ saving=Do not wrap the following fields when saving Do\ not\ write\ the\ following\ fields\ to\ XMP\ Metadata\:=Do not write the following fields to XMP Metadata: -Do\ you\ want\ JabRef\ to\ do\ the\ following\ operations?=Do you want JabRef to do the following operations? - Donate\ to\ JabRef=Donate to JabRef Down=Down @@ -439,8 +434,6 @@ Formatter\ name=Formatter name found\ in\ AUX\ file=found in AUX file -Full\ name=Full name - Further\ information\ about\ Mr\ DLib.\ for\ JabRef\ users.=Further information about Mr DLib. for JabRef users. General=General @@ -619,8 +612,6 @@ Modify=Modify Move\ down=Move down -Move\ external\ links\ to\ 'file'\ field=Move external links to 'file' field - move\ group=move group Move\ up=Move up @@ -918,8 +909,6 @@ Set\ fields=Set fields Set\ General\ Fields=Set General Fields -Set\ main\ external\ file\ directory=Set main external file directory - Settings=Settings Shortcut=Shortcut @@ -1062,8 +1051,6 @@ untitled=untitled Up=Up Upgrade\ external\ PDF/PS\ links\ to\ use\ the\ '%0'\ field.=Upgrade external PDF/PS links to use the '%0' field. -Upgrade\ file=Upgrade file -Upgrade\ old\ external\ file\ links\ to\ use\ the\ new\ feature=Upgrade old external file links to use the new feature usage=usage Use\ autocompletion\ for\ the\ following\ fields=Use autocompletion for the following fields @@ -1553,8 +1540,6 @@ This\ search\ contains\ entries\ in\ which\ any\ field\ contains\ the\ term\ This\ search\ contains\ entries\ in\ which=This search contains entries in which Unable\ to\ autodetect\ OpenOffice/LibreOffice\ installation.\ Please\ choose\ the\ installation\ directory\ manually.=Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually. -JabRef\ no\ longer\ supports\ 'ps'\ or\ 'pdf'\ fields.
File\ links\ are\ now\ stored\ in\ the\ 'file'\ field\ and\ files\ are\ stored\ in\ an\ external\ file\ directory.
To\ make\ use\ of\ this\ feature,\ JabRef\ needs\ to\ upgrade\ file\ links.

=JabRef no longer supports 'ps' or 'pdf' fields.
File links are now stored in the 'file' field and files are stored in an external file directory.
To make use of this feature, JabRef needs to upgrade file links.

-This\ library\ uses\ outdated\ file\ links.=This library uses outdated file links. Close\ library=Close library Decrease\ table\ font\ size=Decrease table font size From ddd12aec466eee9b9eb3434948d4b2459298eae6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Wed, 6 Mar 2019 08:54:34 +0100 Subject: [PATCH 06/11] Bump mockito-core from 2.24.5 to 2.25.0 (#4723) Bumps [mockito-core](https://github.com/mockito/mockito) from 2.24.5 to 2.25.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v2.24.5...v2.25.0) Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ea5d8e813b2..d08efe7b1a2 100644 --- a/build.gradle +++ b/build.gradle @@ -167,7 +167,7 @@ dependencies { testRuntime 'org.apache.logging.log4j:log4j-core:2.11.1' testRuntime 'org.apache.logging.log4j:log4j-jul:2.11.2' - testCompile 'org.mockito:mockito-core:2.24.5' + testCompile 'org.mockito:mockito-core:2.25.0' testCompile 'com.github.tomakehurst:wiremock:2.21.0' testCompile 'org.assertj:assertj-swing-junit:3.9.2' testCompile 'org.reflections:reflections:0.9.11' From a73a676cf778fe5076f9d06b90aa8379e7b52c79 Mon Sep 17 00:00:00 2001 From: Yash Kothari Date: Wed, 6 Mar 2019 18:19:18 +0530 Subject: [PATCH 07/11] Adding "von" part to Author's last name when exporting to MS Office 2007 (#4725) * Adding "von" part from Author's last name when exporting to MS Office 2007 Fixes #4655 * Adding "von" to Author's last name when exporting to MS Office 2007 Fixes #4655 --- src/main/java/org/jabref/logic/msbib/MsBibAuthor.java | 2 +- src/test/java/org/jabref/logic/msbib/MsBibAuthorTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/msbib/MsBibAuthor.java b/src/main/java/org/jabref/logic/msbib/MsBibAuthor.java index caad384ec22..8da1d4e49ca 100644 --- a/src/main/java/org/jabref/logic/msbib/MsBibAuthor.java +++ b/src/main/java/org/jabref/logic/msbib/MsBibAuthor.java @@ -48,7 +48,7 @@ public String getMiddleName() { } public String getLastName() { - return author.getLast().orElse(null); + return author.getLastOnly(); } public String getFirstLast() { diff --git a/src/test/java/org/jabref/logic/msbib/MsBibAuthorTest.java b/src/test/java/org/jabref/logic/msbib/MsBibAuthorTest.java index cbb37c47408..8736b6542e1 100644 --- a/src/test/java/org/jabref/logic/msbib/MsBibAuthorTest.java +++ b/src/test/java/org/jabref/logic/msbib/MsBibAuthorTest.java @@ -44,4 +44,11 @@ public void testGetLastName() { MsBibAuthor msBibAuthor = new MsBibAuthor(author); assertEquals("Bach", msBibAuthor.getLastName()); } + + @Test + public void testGetVonAndLastName() { + Author author = new Author("John", null, "von", "Neumann", null); + MsBibAuthor msBibAuthor = new MsBibAuthor(author); + assertEquals("von Neumann", msBibAuthor.getLastName()); + } } From 8deb0623f02508e3716da35ed6818fff047e802f Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Tue, 5 Mar 2019 20:23:29 +0100 Subject: [PATCH 08/11] Adding additional modifiers to be used in bibtex key generator --- CHANGELOG.md | 2 +- .../jabref/logic/formatter/Formatters.java | 6 +++ .../BibtexKeyGeneratorTest.java | 54 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 646ffbe4bd9..be3982fb06c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,7 +53,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We added the ability change the column widths directly in the main table. [#4546](https://github.com/JabRef/jabref/issues/4546) - We added the ability to execute default action in dialog by using with Ctrl + Enter combination [#4496](https://github.com/JabRef/jabref/issues/4496) - We grouped and reordered the Main Menu (File, Edit, Library, Quality, Tools, and View tabs & icons). [#4666](https://github.com/JabRef/jabref/issues/4666) [#4667](https://github.com/JabRef/jabref/issues/4667) [#4668](https://github.com/JabRef/jabref/issues/4668) [#4669](https://github.com/JabRef/jabref/issues/4669) [#4670](https://github.com/JabRef/jabref/issues/4670) [#4671](https://github.com/JabRef/jabref/issues/4671) [#4672](https://github.com/JabRef/jabref/issues/4672) [#4673](https://github.com/JabRef/jabref/issues/4673) - +- We added additional modifiers (capitalize, titlecase and sentencecase) to the Bibtex key generator. [#1506](https://github.com/JabRef/jabref/issues/1506) diff --git a/src/main/java/org/jabref/logic/formatter/Formatters.java b/src/main/java/org/jabref/logic/formatter/Formatters.java index 4e1d25f968f..9e867ac23ed 100644 --- a/src/main/java/org/jabref/logic/formatter/Formatters.java +++ b/src/main/java/org/jabref/logic/formatter/Formatters.java @@ -87,6 +87,12 @@ public static Optional getFormatterForModifier(String modifier) { return Optional.of(new LowerCaseFormatter()); case "upper": return Optional.of(new UpperCaseFormatter()); + case "capitalize": + return Optional.of(new CapitalizeFormatter()); + case "titlecase": + return Optional.of(new TitleCaseFormatter()); + case "sentencecase": + return Optional.of(new SentenceCaseFormatter()); } if (modifier.startsWith(RegexFormatter.KEY)) { diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java index 4ed5b5bb728..f09b091fb7e 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java @@ -1007,4 +1007,58 @@ public void generateKeyWithTwoModifiers() throws Exception { entry.setField("title", "The Interesting Title"); assertEquals("theinterestingtitle", BibtexKeyGenerator.generateKey(entry, "title:lower:(_)")); } + + @Test + public void generateKeyWithTitleCapitalizeModifier() throws Exception { + BibEntry entry = new BibEntry(); + entry.setField("title", "the InTeresting title longer than THREE words"); + assertEquals("TheInterestingTitleLongerThanThreeWords", BibtexKeyGenerator.generateKey(entry, "title:capitalize")); + } + + @Test + public void generateKeyWithShortTitleCapitalizeModifier() throws Exception { + BibEntry entry = new BibEntry(); + entry.setField("title", "the InTeresting title longer than THREE words"); + assertEquals("InterestingTitleLonger", BibtexKeyGenerator.generateKey(entry, "shorttitle:capitalize")); + } + + @Test + public void generateKeyWithTitleTitleCaseModifier() throws Exception { + BibEntry entry = new BibEntry(); + entry.setField("title", "A title WITH some of The key words"); + assertEquals("ATitlewithSomeoftheKeyWords", BibtexKeyGenerator.generateKey(entry, "title:titlecase")); + } + + @Test + public void generateKeyWithShortTitleTitleCaseModifier() throws Exception { + BibEntry entry = new BibEntry(); + entry.setField("title", "the InTeresting title longer than THREE words"); + assertEquals("InterestingTitleLonger", BibtexKeyGenerator.generateKey(entry, "shorttitle:titlecase")); + } + + @Test + public void generateKeyWithTitleSentenceCaseModifier() throws Exception { + BibEntry entry = new BibEntry(); + entry.setField("title", "A title WITH some of The key words"); + assertEquals("Atitlewithsomeofthekeywords", BibtexKeyGenerator.generateKey(entry, "title:sentencecase")); + } + + @Test + public void generateKeyWithAuthUpperYearShortTitleCapitalizeModifier() throws Exception { + BibEntry entry = new BibEntry(); + entry.setField("author", AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1); + entry.setField("year", "2019"); + entry.setField("title", "the InTeresting title longer than THREE words"); + assertEquals("NEWTON2019InterestingTitleLonger", BibtexKeyGenerator.generateKey(entry, "[auth:upper][year][shorttitle:capitalize]")); + } + + @Test + public void generateKeyWithYearAuthUpperTitleSentenceCaseModifier() throws Exception { + BibEntry entry = new BibEntry(); + entry.setField("author", AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3); + entry.setField("year", "2019"); + entry.setField("title", "the InTeresting title longer than THREE words"); + assertEquals("NewtonMaxwellEtAl_2019_TheInterestingTitleLongerThanThreeWords", BibtexKeyGenerator.generateKey(entry, "[authors2]_[year]_[title:capitalize]")); + } + } From 2f7aa7a6305a1dd760e08d35f8954ffcb1a9faa0 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 7 Mar 2019 09:04:37 +0100 Subject: [PATCH 09/11] Convert "wait for save" dialog to JavaFX (#4697) --- src/main/java/org/jabref/gui/JabRefFrame.java | 13 +-- .../jabref/gui/WaitForSaveFinishedDialog.java | 43 ++++++++++ .../org/jabref/gui/WaitForSaveOperation.java | 82 ------------------- 3 files changed, 45 insertions(+), 93 deletions(-) create mode 100644 src/main/java/org/jabref/gui/WaitForSaveFinishedDialog.java delete mode 100644 src/main/java/org/jabref/gui/WaitForSaveOperation.java diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 2e41bbc7e64..81290cfaab2 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -500,17 +500,8 @@ public boolean quit() { context.getDatabaseFile().map(File::getAbsolutePath).ifPresent(filenames::add); } - // Wait for save operations to finish - for (int i = 0; i < tabbedPane.getTabs().size(); i++) { - if (getBasePanelAt(i).isSaving()) { - // There is a database still being saved, so we need to wait. - WaitForSaveOperation w = new WaitForSaveOperation(this); - w.show(); // This method won't return until canceled or the save operation is done. - if (w.canceled()) { - return false; // The user clicked cancel. - } - } - } + WaitForSaveFinishedDialog waitForSaveFinishedDialog = new WaitForSaveFinishedDialog(dialogService); + waitForSaveFinishedDialog.showAndWait(getBasePanelList()); // Good bye! tearDownJabRef(filenames); diff --git a/src/main/java/org/jabref/gui/WaitForSaveFinishedDialog.java b/src/main/java/org/jabref/gui/WaitForSaveFinishedDialog.java new file mode 100644 index 00000000000..f8758ab8e1e --- /dev/null +++ b/src/main/java/org/jabref/gui/WaitForSaveFinishedDialog.java @@ -0,0 +1,43 @@ +package org.jabref.gui; + +import java.util.List; + +import javafx.concurrent.Task; + +import org.jabref.logic.l10n.Localization; + +/** + * Dialog shown when closing of application needs to wait for a save operation to finish. + */ +public class WaitForSaveFinishedDialog { + + private final DialogService dialogService; + + public WaitForSaveFinishedDialog(DialogService dialogService) { + this.dialogService = dialogService; + } + + public void showAndWait(List basePanels) { + if (basePanels.stream().anyMatch(BasePanel::isSaving)) { + Task waitForSaveFinished = new Task() { + @Override + protected Void call() throws Exception { + while (basePanels.stream().anyMatch(BasePanel::isSaving)) { + if (isCancelled()) { + return null; + } else { + Thread.sleep(100); + } + } + return null; + } + }; + + dialogService.showProgressDialogAndWait( + Localization.lang("Please wait..."), + Localization.lang("Waiting for save operation to finish") + "...", + waitForSaveFinished + ); + } + } +} diff --git a/src/main/java/org/jabref/gui/WaitForSaveOperation.java b/src/main/java/org/jabref/gui/WaitForSaveOperation.java deleted file mode 100644 index 86b2e0a2f8b..00000000000 --- a/src/main/java/org/jabref/gui/WaitForSaveOperation.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.jabref.gui; - -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JProgressBar; -import javax.swing.Timer; - -import org.jabref.logic.l10n.Localization; - -import com.jgoodies.forms.builder.ButtonBarBuilder; - -/** - * Dialog shown when closing of application needs to wait for a save operation to finish. - */ -public class WaitForSaveOperation implements ActionListener { - - private final JabRefFrame frame; - private final JDialog diag; - private final Timer t = new Timer(500, this); - private boolean canceled; - - - public WaitForSaveOperation(JabRefFrame frame) { - this.frame = frame; - - JButton cancel = new JButton(Localization.lang("Cancel")); - JProgressBar prog = new JProgressBar(0); - prog.setIndeterminate(true); - prog.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - diag = new JDialog((JFrame) null, Localization.lang("Please wait..."), true); - - ButtonBarBuilder bb = new ButtonBarBuilder(); - bb.addGlue(); - bb.addButton(cancel); - bb.addGlue(); - cancel.addActionListener(e -> { - canceled = true; - t.stop(); - diag.dispose(); - }); - - JLabel message = new JLabel(Localization.lang("Waiting for save operation to finish") + "..."); - message.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - - diag.getContentPane().add(message, BorderLayout.NORTH); - diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); - diag.getContentPane().add(prog, BorderLayout.CENTER); - diag.pack(); - } - - public void show() { - t.start(); - diag.setVisible(true); - - } - - public boolean canceled() { - return canceled; - } - - @Override - public void actionPerformed(ActionEvent actionEvent) { - boolean anySaving = false; - for (BasePanel basePanel : frame.getBasePanelList()) { - if (basePanel.isSaving()) { - anySaving = true; - break; - } - } - if (!anySaving) { - t.stop(); - diag.dispose(); - } - } -} From f71ed752b2f6822ddc7317b4ff395594841fe4da Mon Sep 17 00:00:00 2001 From: Ronak Lakhotia Date: Fri, 8 Mar 2019 18:07:35 +0800 Subject: [PATCH 10/11] Add key bindings (#4732) --- src/main/java/org/jabref/gui/actions/StandardActions.java | 4 ++-- src/main/java/org/jabref/gui/keyboard/KeyBinding.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/actions/StandardActions.java b/src/main/java/org/jabref/gui/actions/StandardActions.java index b3b10e3aeaa..302bc7359bd 100644 --- a/src/main/java/org/jabref/gui/actions/StandardActions.java +++ b/src/main/java/org/jabref/gui/actions/StandardActions.java @@ -65,7 +65,7 @@ public enum StandardActions implements Action { NEW_LIBRARY_BIBLATEX(Localization.lang("New %0 library", BibDatabaseMode.BIBLATEX.getFormattedName())), OPEN_LIBRARY(Localization.lang("Open library"), IconTheme.JabRefIcons.OPEN, KeyBinding.OPEN_DATABASE), IMPORT(Localization.lang("Import"), IconTheme.JabRefIcons.IMPORT), - EXPORT(Localization.lang("Export"), IconTheme.JabRefIcons.EXPORT), + EXPORT(Localization.lang("Export"), IconTheme.JabRefIcons.EXPORT, KeyBinding.EXPORT), MERGE_DATABASE(Localization.lang("Append library"), Localization.lang("Append contents from a BibTeX library into the currently viewed library")), SAVE_LIBRARY(Localization.lang("Save library"), IconTheme.JabRefIcons.SAVE, KeyBinding.SAVE_DATABASE), SAVE_LIBRARY_AS(Localization.lang("Save library as..."), KeyBinding.SAVE_DATABASE_AS), @@ -74,7 +74,7 @@ public enum StandardActions implements Action { IMPORT_INTO_NEW_LIBRARY(Localization.lang("Import into new library"), KeyBinding.IMPORT_INTO_NEW_DATABASE), IMPORT_INTO_CURRENT_LIBRARY(Localization.lang("Import into current library"), KeyBinding.IMPORT_INTO_CURRENT_DATABASE), EXPORT_ALL(Localization.lang("Export all entries")), - EXPORT_SELECTED(Localization.lang("Export selected entries")), + EXPORT_SELECTED(Localization.lang("Export selected entries"), KeyBinding.EXPORT_SELECTED), CONNECT_TO_SHARED_DB(Localization.lang("Connect to shared database"), IconTheme.JabRefIcons.CONNECT_DB), PULL_CHANGES_FROM_SHARED_DB(Localization.lang("Pull changes from shared database"), KeyBinding.PULL_CHANGES_FROM_SHARED_DATABASE), CLOSE_LIBRARY(Localization.lang("Close library"), Localization.lang("Close the current library"), IconTheme.JabRefIcons.CLOSE, KeyBinding.CLOSE_DATABASE), diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java index b73fbc6b0c3..b1b2cbbb4b5 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java @@ -28,6 +28,8 @@ public enum KeyBinding { DEFAULT_DIALOG_ACTION("Execute default action in dialog", Localization.lang("Execute default action in dialog"), "ctrl+ENTER", KeyBindingCategory.VIEW), DOWNLOAD_FULL_TEXT("Look up full text documents", Localization.lang("Look up full text documents"), "alt+F7", KeyBindingCategory.QUALITY), EDIT_ENTRY("Edit entry", Localization.lang("Edit entry"), "ctrl+E", KeyBindingCategory.BIBTEX), + EXPORT("Export", Localization.lang("Export"), "ctrl+alt+e", KeyBindingCategory.FILE), + EXPORT_SELECTED("Export Selected", Localization.lang("Export selected entries"), "ctrl+shift+e", KeyBindingCategory.FILE), EDIT_STRINGS("Edit strings", Localization.lang("Edit strings"), "ctrl+T", KeyBindingCategory.BIBTEX), ENTRY_EDITOR_NEXT_ENTRY("Entry editor, next entry", Localization.lang("Entry editor, next entry"), "alt+DOWN", KeyBindingCategory.VIEW), ENTRY_EDITOR_NEXT_PANEL("Entry editor, next panel", Localization.lang("Entry editor, next panel"), "ctrl+TAB", KeyBindingCategory.VIEW), From 4d1738d34dba565a7ab14eeb499995afebca9be7 Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 8 Mar 2019 11:09:40 +0100 Subject: [PATCH 11/11] Fix default import format pattern (#4731) Remove Display Array Add migration Fixe #4724 --- .../jabref/gui/preferences/ImportSettingsTab.java | 12 +++++------- .../org/jabref/migrations/PreferencesMigrations.java | 8 +++++++- .../jabref/migrations/PreferencesMigrationsTest.java | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/ImportSettingsTab.java b/src/main/java/org/jabref/gui/preferences/ImportSettingsTab.java index 3067882b2c2..80873eab063 100644 --- a/src/main/java/org/jabref/gui/preferences/ImportSettingsTab.java +++ b/src/main/java/org/jabref/gui/preferences/ImportSettingsTab.java @@ -9,24 +9,20 @@ import javafx.scene.control.Separator; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; -import javafx.scene.layout.Pane; import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; -public class ImportSettingsTab extends Pane implements PrefsTab { +public class ImportSettingsTab implements PrefsTab { public static final String[] DEFAULT_FILENAMEPATTERNS = new String[] {"[bibtexkey]", - "[bibtexkey] - [title]"}; - - private static final String[] DEFAULT_FILENAMEPATTERNS_DISPLAY = new String[] {"bibtexkey", "bibtexkey - title",}; + "[bibtexkey] - [title]"}; private final JabRefPreferences prefs; private final GridPane builder = new GridPane(); private final TextField fileNamePattern; private final ComboBox selectFileNamePattern; - private final TextField fileDirPattern; public ImportSettingsTab(JabRefPreferences prefs) { @@ -35,8 +31,9 @@ public ImportSettingsTab(JabRefPreferences prefs) { fileNamePattern = new TextField(); fileDirPattern = new TextField(); selectFileNamePattern = new ComboBox<>(); - selectFileNamePattern.getItems().addAll(FXCollections.observableArrayList(DEFAULT_FILENAMEPATTERNS_DISPLAY)); + selectFileNamePattern.getItems().addAll(FXCollections.observableArrayList(DEFAULT_FILENAMEPATTERNS)); selectFileNamePattern.setValue(Localization.lang("Choose pattern")); + selectFileNamePattern.setOnAction(e -> { fileNamePattern.setText(selectFileNamePattern.getValue()); }); @@ -60,6 +57,7 @@ public ImportSettingsTab(JabRefPreferences prefs) { builder.add(fileDirPattern, 2, 10); } + @Override public Node getBuilder() { return builder; } diff --git a/src/main/java/org/jabref/migrations/PreferencesMigrations.java b/src/main/java/org/jabref/migrations/PreferencesMigrations.java index f0923915177..70a4357ef3b 100644 --- a/src/main/java/org/jabref/migrations/PreferencesMigrations.java +++ b/src/main/java/org/jabref/migrations/PreferencesMigrations.java @@ -237,10 +237,16 @@ static void upgradeImportFileAndDirePatterns(JabRefPreferences prefs, Preference String[] oldStylePatterns = new String[] {"\\bibtexkey", "\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}"}; String[] newStylePatterns = new String[] {"[bibtexkey]", - "[bibtexkey] - [fulltitle]"}; + "[bibtexkey] - [title]"}; + + String[] oldDisplayStylePattern = new String[] {"bibtexkey", "bibtexkey - title",}; + for (int i = 0; i < oldStylePatterns.length; i++) { migrateFileImportPattern(oldStylePatterns[i], newStylePatterns[i], prefs, mainPrefsNode); } + for (int i = 0; i < oldDisplayStylePattern.length; i++) { + migrateFileImportPattern(oldDisplayStylePattern[i], newStylePatterns[i], prefs, mainPrefsNode); + } } // Directory preferences are not yet migrated, since it is not quote clear how to parse and reinterpret // the user defined old-style patterns, and the default pattern is "". diff --git a/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java b/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java index c646bab55bb..6a2ee9bc5e8 100644 --- a/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java +++ b/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java @@ -20,7 +20,7 @@ class PreferencesMigrationsTest { private final String[] oldStylePatterns = new String[]{"\\bibtexkey", "\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}"}; private final String[] newStylePatterns = new String[]{"[bibtexkey]", - "[bibtexkey] - [fulltitle]"}; + "[bibtexkey] - [title]"}; @BeforeEach void setUp() {