Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into maintable-beta
Browse files Browse the repository at this point in the history
* upstream/master:
  New translations JabRef_en.properties (French) (#4009)
  Fix Look and Feel related issues (#4002)
  Fix statement in changelog
  [WIP] Add Text File Export for "Find Unlinked Files" (#3979)

# Conflicts:
#	src/main/java/org/jabref/JabRefGUI.java
#	src/main/java/org/jabref/gui/preftabs/AppearancePrefsTab.java
#	src/main/java/org/jabref/migrations/PreferencesMigrations.java
  • Loading branch information
Siedlerchr committed May 4, 2018
2 parents 147ffca + 18011fc commit c019582
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 72 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
We added RFC, a new entry generator ID type. [#3971](https://github.com/JabRef/jabref/issues/3971)
- We added a text file export for 'Find Unlinked Files'. [#3341](https://github.com/JabRef/jabref/issues/3341)
- We added a fetcher based on RFC-IDs. [#3971](https://github.com/JabRef/jabref/issues/3971)

### Fixed
We fixed an issue where the export to clipboard functionality could not be invoked [#3994](https://github.com/JabRef/jabref/issues/3994)

We fixed an issue with the migration of invalid Look and Feels [#3995, comment](https://github.com/JabRef/jabref/issues/3995#issuecomment-385649448)
We fixed an issue where JabRef would no longer start, when the option "Override default font settings" was activated [#3986](https://github.com/JabRef/jabref/issues/3986)
### Removed


We removed the GTK Look and Feel from the Options, as it leads to freezes in JabRef on MacOSX and Linux [#3995](https://github.com/JabRef/jabref/issues/3995)
The GTK Look and Feel is now replaced with the "Nimbus" style as default.



Expand Down
31 changes: 17 additions & 14 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref;

import java.awt.Font;
import java.awt.Frame;
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -42,7 +44,10 @@

public class JabRefGUI {

private static final String NIMBUS_LOOK_AND_FEEL = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
private static final Logger LOGGER = LoggerFactory.getLogger(JabRefGUI.class);
private static final String GTK_LF_CLASSNAME = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";

private static JabRefFrame mainFrame;

private final List<ParserResult> bibDatabases;
Expand All @@ -59,7 +64,10 @@ public JabRefGUI(Stage mainStage, List<ParserResult> argsDatabases, boolean isBl
this.dialogService = new FXDialogService(mainStage);

// passed file (we take the first one) should be focused
focusedFile = argsDatabases.stream().findFirst().flatMap(ParserResult::getFile).map(File::getAbsolutePath)
focusedFile = argsDatabases.stream()
.findFirst()
.flatMap(ParserResult::getFile)
.map(File::getAbsolutePath)
.orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED));

openWindow(mainStage);
Expand Down Expand Up @@ -237,25 +245,20 @@ private void setLookAndFeel() {
String systemLookFeel = UIManager.getSystemLookAndFeelClassName();

if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) {
// FIXME: Problems with OpenJDK and GTK L&F
// See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638
if (System.getProperty("java.runtime.name").contains("OpenJDK")) {
// Metal L&F
lookFeel = UIManager.getCrossPlatformLookAndFeelClassName();
LOGGER.warn(
"There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution.");
// FIXME: Problems with GTK L&F on Linux and Mac. Needs reevaluation for Java9
if (GTK_LF_CLASSNAME.equals(systemLookFeel)) {
lookFeel = NIMBUS_LOOK_AND_FEEL;
LOGGER.warn("There seems to be problems with GTK Look&Feel. Using Nimbus L&F instead. Change to another L&F with caution.");
} else {
lookFeel = systemLookFeel;
}
} else {
lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
}

// FIXME: Open JDK problem
if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel)
&& !System.getProperty("java.runtime.name").contains("OpenJDK")) {
// try to avoid ending up with the ugly Metal L&F
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
//Prevent metal l&f
if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel)) {
UIManager.setLookAndFeel(NIMBUS_LOOK_AND_FEEL);
} else {
try {
UIManager.setLookAndFeel(lookFeel);
Expand Down Expand Up @@ -292,7 +295,7 @@ private void setLookAndFeel() {
Enumeration<Object> keys = defaults.keys();
for (Object key : Collections.list(keys)) {
if ((key instanceof String) && ((String) key).endsWith(".font")) {
FontUIResource font = (FontUIResource) UIManager.get(key);
Font font = (Font) UIManager.get(key);
font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
defaults.put(key, font);
}
Expand Down
89 changes: 87 additions & 2 deletions src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
Expand Down Expand Up @@ -74,6 +77,7 @@
import org.jabref.gui.importer.UnlinkedPDFFileFilter;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.EntryTypes;
import org.jabref.model.database.BibDatabaseContext;
Expand Down Expand Up @@ -114,6 +118,7 @@ public class FindUnlinkedFilesDialog extends JabRefDialog {
private JPanel panelImportArea;
private JButton buttonBrowse;
private JButton buttonScan;
private JButton buttonExport;
private JButton buttonApply;

private JButton buttonClose;
Expand All @@ -132,6 +137,7 @@ public class FindUnlinkedFilesDialog extends JabRefDialog {
private JLabel labelSearchingDirectoryInfo;

private JLabel labelImportingInfo;
private JLabel labelExportingInfo;
private JTree tree;
private JScrollPane scrollpaneTree;
private JComboBox<FileFilter> comboBoxFileTypeSelection;
Expand Down Expand Up @@ -167,6 +173,7 @@ public FindUnlinkedFilesDialog(Frame owner, JabRefFrame frame) {

initialize();
buttonApply.setEnabled(false);
buttonExport.setEnabled(false);
}

/**
Expand Down Expand Up @@ -485,6 +492,7 @@ private void startImport() {

progressBarImporting.setVisible(true);
labelImportingInfo.setVisible(true);
buttonExport.setVisible(false);
buttonApply.setVisible(false);
buttonClose.setVisible(false);
disOrEnableDialog(false);
Expand Down Expand Up @@ -519,6 +527,72 @@ public void stateChanged(ChangeEvent e) {
});
}

/**
* This starts the export of all files of all selected nodes in this
* dialogs tree view. <br>
* <br>
* The export itself will run in a seperate thread, whilst this dialog will
* be showing a progress bar, until the thread has finished its work. <br>
* <br>
* When the export has finished, the {@link #exportFinishedHandler()} is
* invoked.
*/
private void startExport() {
if (treeModel == null) {
return;
}
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

CheckableTreeNode root = (CheckableTreeNode) treeModel.getRoot();

final List<File> fileList = getFileListFromNode(root);
if ((fileList == null) || fileList.isEmpty()) {
return;
}

buttonExport.setVisible(false);
buttonApply.setVisible(false);
buttonClose.setVisible(false);
disOrEnableDialog(false);

FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
DialogService ds = new FXDialogService();

Optional<Path> exportPath = DefaultTaskExecutor
.runInJavaFXThread(() -> ds.showFileSaveDialog(fileDialogConfiguration));

if (!exportPath.isPresent()) {
exportFinishedHandler();
return;
}

threadState.set(true);
JabRefExecutorService.INSTANCE.execute(() -> {
try (BufferedWriter writer =
Files.newBufferedWriter(exportPath.get(), StandardCharsets.UTF_8,
StandardOpenOption.CREATE)) {
for (File file : fileList) {
writer.write(file.toString() + "\n");
}

} catch (IOException e) {
LOGGER.warn("IO Error.", e);
}
});

exportFinishedHandler();
}

private void exportFinishedHandler() {
buttonExport.setVisible(true);
buttonApply.setVisible(true);
buttonClose.setVisible(true);
disOrEnableDialog(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.getCurrentBasePanel().markBaseChanged();
}

/**
*
* @param errors
Expand All @@ -540,6 +614,7 @@ private void importFinishedHandler(List<String> errors) {

progressBarImporting.setVisible(false);
labelImportingInfo.setVisible(false);
buttonExport.setVisible(true);
buttonApply.setVisible(true);
buttonClose.setVisible(true);
disOrEnableDialog(true);
Expand Down Expand Up @@ -570,6 +645,7 @@ private void searchFinishedHandler(CheckableTreeNode rootNode) {

disOrEnableDialog(true);
buttonApply.setEnabled(true);
buttonExport.setEnabled(true);
}

/**
Expand Down Expand Up @@ -600,8 +676,8 @@ private void setupActions() {
* Actions on this button will start the import of all file of all
* selected nodes in this dialogs tree view. <br>
*/
ActionListener actionListenerImportEntrys = e -> startImport();
buttonApply.addActionListener(actionListenerImportEntrys);
buttonExport.addActionListener(e -> startExport());
buttonApply.addActionListener(e -> startImport());
buttonClose.addActionListener(e -> dispose());
}

Expand Down Expand Up @@ -683,6 +759,9 @@ public void windowClosing(WindowEvent e) {
buttonScan = new JButton(Localization.lang("Scan directory"));
buttonScan.setMnemonic('S');
buttonScan.setToolTipText(Localization.lang("Searches the selected directory for unlinked files."));
buttonExport = new JButton(Localization.lang("Export"));
buttonExport.setMnemonic('E');
buttonExport.setToolTipText(Localization.lang("Export to text file."));
buttonApply = new JButton(Localization.lang("Apply"));
buttonApply.setMnemonic('I');
buttonApply.setToolTipText(Localization.lang("Starts the import of BibTeX entries."));
Expand Down Expand Up @@ -725,6 +804,9 @@ public void windowClosing(WindowEvent e) {
labelImportingInfo = new JLabel(Localization.lang("Importing into Library..."));
labelImportingInfo.setHorizontalAlignment(SwingConstants.CENTER);
labelImportingInfo.setVisible(false);
labelExportingInfo = new JLabel(Localization.lang("Exporting into file..."));
labelExportingInfo.setHorizontalAlignment(SwingConstants.CENTER);
labelExportingInfo.setVisible(false);

tree = new JTree();

Expand Down Expand Up @@ -807,6 +889,8 @@ GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, new Insets(18, 3, 18, 6)
GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, basicInsets, 0, 1, 2, 1, 0, 0, 0, 0);
FindUnlinkedFilesDialog.addComponent(gbl, panelImportArea, labelImportingInfo, GridBagConstraints.HORIZONTAL,
GridBagConstraints.CENTER, new Insets(6, 6, 0, 6), 0, 1, 1, 1, 1, 0, 0, 0);
FindUnlinkedFilesDialog.addComponent(gbl, panelImportArea, labelExportingInfo, GridBagConstraints.HORIZONTAL,
GridBagConstraints.CENTER, new Insets(6, 6, 0, 6), 0, 1, 1, 1, 1, 0, 0, 0);
FindUnlinkedFilesDialog.addComponent(gbl, panelImportArea, progressBarImporting, GridBagConstraints.HORIZONTAL,
GridBagConstraints.CENTER, new Insets(0, 6, 6, 6), 0, 2, 1, 1, 1, 0, 0, 0);
FindUnlinkedFilesDialog.addComponent(gbl, panelButtons, panelImportArea, GridBagConstraints.NONE,
Expand All @@ -824,6 +908,7 @@ GridBagConstraints.HORIZONTAL, GridBagConstraints.SOUTHWEST, new Insets(12, 6, 2

ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
bb.addButton(buttonExport);
bb.addButton(buttonApply);
bb.addButton(buttonClose);
bb.addGlue();
Expand Down
Loading

0 comments on commit c019582

Please sign in to comment.