Skip to content

Commit 3aaae4d

Browse files
committed
Merge remote-tracking branch 'upstream/maintable-beta' into jdk9
* upstream/maintable-beta: set look and feel to windows, aqua or nimbus for swing in case fix import remove look and feel 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)
2 parents dc7411d + 477771d commit 3aaae4d

File tree

7 files changed

+177
-149
lines changed

7 files changed

+177
-149
lines changed

CHANGELOG.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
1111
## [Unreleased]
1212

1313
### Changed
14-
We added RFC, a new entry generator ID type. [#3971](https://github.com/JabRef/jabref/issues/3971)
14+
- We added a text file export for 'Find Unlinked Files'. [#3341](https://github.com/JabRef/jabref/issues/3341)
15+
- We added a fetcher based on RFC-IDs. [#3971](https://github.com/JabRef/jabref/issues/3971)
16+
1517
### Fixed
1618
We fixed an issue where the export to clipboard functionality could not be invoked [#3994](https://github.com/JabRef/jabref/issues/3994)
17-
19+
We fixed an issue with the migration of invalid Look and Feels [#3995, comment](https://github.com/JabRef/jabref/issues/3995#issuecomment-385649448)
20+
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)
1821
### Removed
19-
20-
22+
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)
23+
The GTK Look and Feel is now replaced with the "Nimbus" style as default.
2124

2225

2326

src/main/java/org/jabref/JabRefGUI.java

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jabref;
22

3+
import java.awt.Font;
34
import java.io.File;
45
import java.sql.SQLException;
56
import java.util.ArrayList;
@@ -33,6 +34,7 @@
3334
import org.jabref.logic.l10n.Localization;
3435
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
3536
import org.jabref.logic.shared.exception.NotASharedDatabaseException;
37+
import org.jabref.logic.util.OS;
3638
import org.jabref.logic.util.Version;
3739
import org.jabref.model.database.shared.DatabaseNotSupportedException;
3840
import org.jabref.preferences.JabRefPreferences;
@@ -42,7 +44,12 @@
4244

4345
public class JabRefGUI {
4446

47+
private static final String NIMBUS_LOOK_AND_FEEL = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
48+
private static final String WINDOWS_LOOK_AND_FEEL = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
49+
private static final String OSX_AQUA_LOOk_AND_FEEL = "apple.laf.AquaLookAndFeel";
50+
4551
private static final Logger LOGGER = LoggerFactory.getLogger(JabRefGUI.class);
52+
4653
private static JabRefFrame mainFrame;
4754

4855
private final List<ParserResult> bibDatabases;
@@ -59,8 +66,11 @@ public JabRefGUI(Stage mainStage, List<ParserResult> argsDatabases, boolean isBl
5966
this.dialogService = new FXDialogService(mainStage);
6067

6168
// passed file (we take the first one) should be focused
62-
focusedFile = argsDatabases.stream().findFirst().flatMap(ParserResult::getFile).map(File::getAbsolutePath)
63-
.orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED));
69+
focusedFile = argsDatabases.stream()
70+
.findFirst()
71+
.flatMap(ParserResult::getFile)
72+
.map(File::getAbsolutePath)
73+
.orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED));
6474

6575
openWindow(mainStage);
6676
JabRefGUI.checkForNewVersion(false);
@@ -112,15 +122,15 @@ private void openWindow(Stage mainStage) {
112122
try {
113123
new SharedDatabaseUIManager(mainFrame).openSharedDatabaseFromParserResult(pr);
114124
} catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException |
115-
NotASharedDatabaseException e) {
125+
NotASharedDatabaseException e) {
116126
pr.getDatabaseContext().clearDatabaseFile(); // do not open the original file
117127
pr.getDatabase().clearSharedDatabaseID();
118128

119129
LOGGER.error("Connection error", e);
120130
dialogService.showErrorDialogAndWait(
121-
Localization.lang("Connection error"),
122-
Localization.lang("A local copy will be opened."),
123-
e);
131+
Localization.lang("Connection error"),
132+
Localization.lang("A local copy will be opened."),
133+
e);
124134
}
125135
toOpenTab.add(pr);
126136
} else if (pr.toOpenTab()) {
@@ -163,7 +173,7 @@ private void openWindow(Stage mainStage) {
163173

164174
for (ParserResult pr : failed) {
165175
String message = Localization.lang("Error opening file '%0'.", pr.getFile().get().getName()) + "\n"
166-
+ pr.getErrorMessage();
176+
+ pr.getErrorMessage();
167177

168178
dialogService.showErrorDialogAndWait(Localization.lang("Error opening file"), message);
169179

@@ -212,7 +222,7 @@ private void openLastEditedDatabases() {
212222
}
213223

214224
ParserResult parsedDatabase = OpenDatabase.loadDatabase(fileName,
215-
Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
225+
Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
216226

217227
if (parsedDatabase.isEmpty()) {
218228
LOGGER.error(Localization.lang("Error opening file") + " '" + dbFile.getPath() + "'");
@@ -233,55 +243,30 @@ private boolean isLoaded(File fileToOpen) {
233243

234244
private void setLookAndFeel() {
235245
try {
236-
String lookFeel;
237-
String systemLookFeel = UIManager.getSystemLookAndFeelClassName();
238-
239-
if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) {
240-
// FIXME: Problems with OpenJDK and GTK L&F
241-
// See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638
242-
if (System.getProperty("java.runtime.name").contains("OpenJDK")) {
243-
// Metal L&F
244-
lookFeel = UIManager.getCrossPlatformLookAndFeelClassName();
245-
LOGGER.warn(
246-
"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.");
247-
} else {
248-
lookFeel = systemLookFeel;
249-
}
250-
} else {
251-
lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
252-
}
253246

254-
// FIXME: Open JDK problem
255-
if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel)
256-
&& !System.getProperty("java.runtime.name").contains("OpenJDK")) {
257-
// try to avoid ending up with the ugly Metal L&F
258-
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
247+
if (OS.WINDOWS) {
248+
UIManager.setLookAndFeel(WINDOWS_LOOK_AND_FEEL);
249+
}
250+
if (OS.OS_X) {
251+
UIManager.setLookAndFeel(OSX_AQUA_LOOk_AND_FEEL);
259252
} else {
260-
try {
261-
UIManager.setLookAndFeel(lookFeel);
262-
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
263-
UnsupportedLookAndFeelException e) {
264-
// specified look and feel does not exist on the classpath, so use system l&f
265-
UIManager.setLookAndFeel(systemLookFeel);
266-
// also set system l&f as default
267-
Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLookFeel);
268-
// notify the user
269-
270-
LOGGER.warn("Unable to find requested look and feel", e);
271-
dialogService.showWarningDialogAndWait(Localization.lang("Warning"),
272-
Localization.lang("Unable to find the requested look and feel and thus the default one is used."));
273-
274-
}
253+
UIManager.setLookAndFeel(NIMBUS_LOOK_AND_FEEL);
275254
}
276-
277255
// On Linux, Java FX fonts look blurry per default. This can be improved by using a non-default rendering
278256
// setting. See https://github.com/woky/javafx-hates-linux
279257
if (Globals.prefs.getBoolean(JabRefPreferences.FX_FONT_RENDERING_TWEAK)) {
280258
System.setProperty("prism.text", "t2k");
281259
System.setProperty("prism.lcdtext", "true");
282260
}
283-
} catch (Exception e) {
284-
LOGGER.warn("Look and feel could not be set", e);
261+
} catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
262+
try {
263+
LOGGER.warn("Setting Look and Feel to Nimbus", e);
264+
265+
UIManager.setLookAndFeel(NIMBUS_LOOK_AND_FEEL);
266+
} catch (Exception ex) {
267+
LOGGER.warn("Look and feel could not be set", e);
268+
}
269+
285270
}
286271

287272
// In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms
@@ -292,7 +277,7 @@ private void setLookAndFeel() {
292277
Enumeration<Object> keys = defaults.keys();
293278
for (Object key : Collections.list(keys)) {
294279
if ((key instanceof String) && ((String) key).endsWith(".font")) {
295-
FontUIResource font = (FontUIResource) UIManager.get(key);
280+
Font font = (Font) UIManager.get(key);
296281
font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
297282
defaults.put(key, font);
298283
}

src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
import java.awt.event.MouseListener;
1919
import java.awt.event.WindowAdapter;
2020
import java.awt.event.WindowEvent;
21+
import java.io.BufferedWriter;
2122
import java.io.File;
2223
import java.io.FileFilter;
2324
import java.io.IOException;
25+
import java.nio.charset.StandardCharsets;
2426
import java.nio.file.Files;
2527
import java.nio.file.Path;
2628
import java.nio.file.Paths;
29+
import java.nio.file.StandardOpenOption;
2730
import java.util.ArrayList;
2831
import java.util.Collections;
2932
import java.util.Enumeration;
@@ -74,6 +77,7 @@
7477
import org.jabref.gui.importer.UnlinkedPDFFileFilter;
7578
import org.jabref.gui.util.DefaultTaskExecutor;
7679
import org.jabref.gui.util.DirectoryDialogConfiguration;
80+
import org.jabref.gui.util.FileDialogConfiguration;
7781
import org.jabref.logic.l10n.Localization;
7882
import org.jabref.model.EntryTypes;
7983
import org.jabref.model.database.BibDatabaseContext;
@@ -114,6 +118,7 @@ public class FindUnlinkedFilesDialog extends JabRefDialog {
114118
private JPanel panelImportArea;
115119
private JButton buttonBrowse;
116120
private JButton buttonScan;
121+
private JButton buttonExport;
117122
private JButton buttonApply;
118123

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

134139
private JLabel labelImportingInfo;
140+
private JLabel labelExportingInfo;
135141
private JTree tree;
136142
private JScrollPane scrollpaneTree;
137143
private JComboBox<FileFilter> comboBoxFileTypeSelection;
@@ -167,6 +173,7 @@ public FindUnlinkedFilesDialog(Frame owner, JabRefFrame frame) {
167173

168174
initialize();
169175
buttonApply.setEnabled(false);
176+
buttonExport.setEnabled(false);
170177
}
171178

172179
/**
@@ -485,6 +492,7 @@ private void startImport() {
485492

486493
progressBarImporting.setVisible(true);
487494
labelImportingInfo.setVisible(true);
495+
buttonExport.setVisible(false);
488496
buttonApply.setVisible(false);
489497
buttonClose.setVisible(false);
490498
disOrEnableDialog(false);
@@ -519,6 +527,72 @@ public void stateChanged(ChangeEvent e) {
519527
});
520528
}
521529

530+
/**
531+
* This starts the export of all files of all selected nodes in this
532+
* dialogs tree view. <br>
533+
* <br>
534+
* The export itself will run in a seperate thread, whilst this dialog will
535+
* be showing a progress bar, until the thread has finished its work. <br>
536+
* <br>
537+
* When the export has finished, the {@link #exportFinishedHandler()} is
538+
* invoked.
539+
*/
540+
private void startExport() {
541+
if (treeModel == null) {
542+
return;
543+
}
544+
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
545+
546+
CheckableTreeNode root = (CheckableTreeNode) treeModel.getRoot();
547+
548+
final List<File> fileList = getFileListFromNode(root);
549+
if ((fileList == null) || fileList.isEmpty()) {
550+
return;
551+
}
552+
553+
buttonExport.setVisible(false);
554+
buttonApply.setVisible(false);
555+
buttonClose.setVisible(false);
556+
disOrEnableDialog(false);
557+
558+
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
559+
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
560+
DialogService ds = new FXDialogService();
561+
562+
Optional<Path> exportPath = DefaultTaskExecutor
563+
.runInJavaFXThread(() -> ds.showFileSaveDialog(fileDialogConfiguration));
564+
565+
if (!exportPath.isPresent()) {
566+
exportFinishedHandler();
567+
return;
568+
}
569+
570+
threadState.set(true);
571+
JabRefExecutorService.INSTANCE.execute(() -> {
572+
try (BufferedWriter writer =
573+
Files.newBufferedWriter(exportPath.get(), StandardCharsets.UTF_8,
574+
StandardOpenOption.CREATE)) {
575+
for (File file : fileList) {
576+
writer.write(file.toString() + "\n");
577+
}
578+
579+
} catch (IOException e) {
580+
LOGGER.warn("IO Error.", e);
581+
}
582+
});
583+
584+
exportFinishedHandler();
585+
}
586+
587+
private void exportFinishedHandler() {
588+
buttonExport.setVisible(true);
589+
buttonApply.setVisible(true);
590+
buttonClose.setVisible(true);
591+
disOrEnableDialog(true);
592+
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
593+
frame.getCurrentBasePanel().markBaseChanged();
594+
}
595+
522596
/**
523597
*
524598
* @param errors
@@ -540,6 +614,7 @@ private void importFinishedHandler(List<String> errors) {
540614

541615
progressBarImporting.setVisible(false);
542616
labelImportingInfo.setVisible(false);
617+
buttonExport.setVisible(true);
543618
buttonApply.setVisible(true);
544619
buttonClose.setVisible(true);
545620
disOrEnableDialog(true);
@@ -570,6 +645,7 @@ private void searchFinishedHandler(CheckableTreeNode rootNode) {
570645

571646
disOrEnableDialog(true);
572647
buttonApply.setEnabled(true);
648+
buttonExport.setEnabled(true);
573649
}
574650

575651
/**
@@ -600,8 +676,8 @@ private void setupActions() {
600676
* Actions on this button will start the import of all file of all
601677
* selected nodes in this dialogs tree view. <br>
602678
*/
603-
ActionListener actionListenerImportEntrys = e -> startImport();
604-
buttonApply.addActionListener(actionListenerImportEntrys);
679+
buttonExport.addActionListener(e -> startExport());
680+
buttonApply.addActionListener(e -> startImport());
605681
buttonClose.addActionListener(e -> dispose());
606682
}
607683

@@ -688,6 +764,9 @@ public void windowClosing(WindowEvent e) {
688764
buttonScan = new JButton(Localization.lang("Scan directory"));
689765
buttonScan.setMnemonic('S');
690766
buttonScan.setToolTipText(Localization.lang("Searches the selected directory for unlinked files."));
767+
buttonExport = new JButton(Localization.lang("Export"));
768+
buttonExport.setMnemonic('E');
769+
buttonExport.setToolTipText(Localization.lang("Export to text file."));
691770
buttonApply = new JButton(Localization.lang("Apply"));
692771
buttonApply.setMnemonic('I');
693772
buttonApply.setToolTipText(Localization.lang("Starts the import of BibTeX entries."));
@@ -730,6 +809,9 @@ public void windowClosing(WindowEvent e) {
730809
labelImportingInfo = new JLabel(Localization.lang("Importing into Library..."));
731810
labelImportingInfo.setHorizontalAlignment(SwingConstants.CENTER);
732811
labelImportingInfo.setVisible(false);
812+
labelExportingInfo = new JLabel(Localization.lang("Exporting into file..."));
813+
labelExportingInfo.setHorizontalAlignment(SwingConstants.CENTER);
814+
labelExportingInfo.setVisible(false);
733815

734816
tree = new JTree();
735817

@@ -812,6 +894,8 @@ GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, new Insets(18, 3, 18, 6)
812894
GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, basicInsets, 0, 1, 2, 1, 0, 0, 0, 0);
813895
FindUnlinkedFilesDialog.addComponent(gbl, panelImportArea, labelImportingInfo, GridBagConstraints.HORIZONTAL,
814896
GridBagConstraints.CENTER, new Insets(6, 6, 0, 6), 0, 1, 1, 1, 1, 0, 0, 0);
897+
FindUnlinkedFilesDialog.addComponent(gbl, panelImportArea, labelExportingInfo, GridBagConstraints.HORIZONTAL,
898+
GridBagConstraints.CENTER, new Insets(6, 6, 0, 6), 0, 1, 1, 1, 1, 0, 0, 0);
815899
FindUnlinkedFilesDialog.addComponent(gbl, panelImportArea, progressBarImporting, GridBagConstraints.HORIZONTAL,
816900
GridBagConstraints.CENTER, new Insets(0, 6, 6, 6), 0, 2, 1, 1, 1, 0, 0, 0);
817901
FindUnlinkedFilesDialog.addComponent(gbl, panelButtons, panelImportArea, GridBagConstraints.NONE,
@@ -829,6 +913,7 @@ GridBagConstraints.HORIZONTAL, GridBagConstraints.SOUTHWEST, new Insets(12, 6, 2
829913

830914
ButtonBarBuilder bb = new ButtonBarBuilder();
831915
bb.addGlue();
916+
bb.addButton(buttonExport);
832917
bb.addButton(buttonApply);
833918
bb.addButton(buttonClose);
834919
bb.addGlue();

0 commit comments

Comments
 (0)