Skip to content

Commit

Permalink
Getting Rid of Swing (#4894)
Browse files Browse the repository at this point in the history
* Add Architecture Test for the usage of Swing and JGoodies

* Delete unused classes

* Fix test for matching sub-packages of Swing and JGoodies

* remove iconset and obsolete key methods

* remove some more keybindings
remove locale setting for swing
remove obsolete special fields drop down

* Remove FileListTableModel and associated class, improve opening file in base Panel

* remove showMessage

* remove swing from file type

* remove whitespace

* fix loading of external file type edit dialog

* remove glazedlists, this time remove all dependencies

* remove emacs keybinding

* remove emacs keybinding rest

* Improve tests to exclude the UndoManager

* Deleted unused FieldSetComponent

* Check for awt usages

* Remove awt font and color methods
Possible todo: Fix font style or posture settings

* enable backwards compatiblitiy with font size

* Fix remaining swing issues
remove swing stuff from groups class
Skip awt test rule, as the remaining classes should be

* fix l10n

* fix mods tests
  • Loading branch information
LinusDietz authored and Siedlerchr committed Aug 23, 2019
1 parent 9aae35f commit 854cd51
Show file tree
Hide file tree
Showing 39 changed files with 135 additions and 2,768 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ dependencies {

compile 'org.postgresql:postgresql:42.2.6'

compile 'net.java.dev.glazedlists:glazedlists_java15:1.9.1'

compile 'com.google.guava:guava:28.0-jre'

// JavaFX stuff
Expand Down
83 changes: 36 additions & 47 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -14,7 +13,6 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.swing.SwingUtilities;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;

Expand Down Expand Up @@ -45,12 +43,8 @@
import org.jabref.gui.exporter.SaveDatabaseAction;
import org.jabref.gui.exporter.WriteXMPAction;
import org.jabref.gui.externalfiles.FindFullTextAction;
import org.jabref.gui.externalfiletype.ExternalFileMenuItem;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.filelist.FileListEntry;
import org.jabref.gui.filelist.FileListTableModel;
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.gui.importer.actions.AppendDatabaseAction;
import org.jabref.gui.journals.AbbreviateAction;
import org.jabref.gui.journals.UnabbreviateAction;
Expand Down Expand Up @@ -92,6 +86,7 @@
import org.jabref.model.database.shared.DatabaseLocation;
import org.jabref.model.database.shared.DatabaseSynchronizer;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.FileFieldParser;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.entry.event.EntryChangedEvent;
import org.jabref.model.entry.event.EntryEventSource;
Expand Down Expand Up @@ -342,25 +337,25 @@ private void setupActions() {
actions.put(Actions.REPLACE_ALL, () -> (new ReplaceStringAction(this)).execute());

actions.put(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getCommand(),
new SpecialFieldViewModel(SpecialField.RELEVANCE, undoManager).getSpecialFieldAction(SpecialField.RELEVANCE.getValues().get(0), frame));
new SpecialFieldViewModel(SpecialField.RELEVANCE, undoManager).getSpecialFieldAction(SpecialField.RELEVANCE.getValues().get(0), frame));

actions.put(new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getCommand(),
new SpecialFieldViewModel(SpecialField.QUALITY, undoManager).getSpecialFieldAction(SpecialField.QUALITY.getValues().get(0), frame));
new SpecialFieldViewModel(SpecialField.QUALITY, undoManager).getSpecialFieldAction(SpecialField.QUALITY.getValues().get(0), frame));

actions.put(new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getCommand(),
new SpecialFieldViewModel(SpecialField.PRINTED, undoManager).getSpecialFieldAction(SpecialField.PRINTED.getValues().get(0), frame));
new SpecialFieldViewModel(SpecialField.PRINTED, undoManager).getSpecialFieldAction(SpecialField.PRINTED.getValues().get(0), frame));

for (SpecialFieldValue prio : SpecialField.PRIORITY.getValues()) {
actions.put(new SpecialFieldValueViewModel(prio).getCommand(),
new SpecialFieldViewModel(SpecialField.PRIORITY, undoManager).getSpecialFieldAction(prio, this.frame));
new SpecialFieldViewModel(SpecialField.PRIORITY, undoManager).getSpecialFieldAction(prio, this.frame));
}
for (SpecialFieldValue rank : SpecialField.RANKING.getValues()) {
actions.put(new SpecialFieldValueViewModel(rank).getCommand(),
new SpecialFieldViewModel(SpecialField.RANKING, undoManager).getSpecialFieldAction(rank, this.frame));
new SpecialFieldViewModel(SpecialField.RANKING, undoManager).getSpecialFieldAction(rank, this.frame));
}
for (SpecialFieldValue status : SpecialField.READ_STATUS.getValues()) {
actions.put(new SpecialFieldValueViewModel(status).getCommand(),
new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame));
new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame));
}

actions.put(Actions.TOGGLE_PREVIEW, () -> {
Expand Down Expand Up @@ -532,7 +527,7 @@ private void copyKeyAndTitle() {
Layout layout;
try {
layout = new LayoutHelper(sr, Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader))
.getLayoutFromText();
.getLayoutFromText();
} catch (IOException e) {
LOGGER.info("Could not get layout", e);
return;
Expand Down Expand Up @@ -579,16 +574,21 @@ private void openExternalFile() {
new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen();
return;
}
FileListTableModel fileListTableModel = new FileListTableModel();
entry.getField(StandardField.FILE).ifPresent(fileListTableModel::setContent);
if (fileListTableModel.getRowCount() == 0) {

List<LinkedFile> files = new ArrayList<>();
entry.getField(StandardField.FILE).map(FileFieldParser::parse).ifPresent(files::addAll);

if (files.isEmpty()) {
// content in BibTeX field is not readable
new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen();
return;
}
FileListEntry flEntry = fileListTableModel.getEntry(0);
ExternalFileMenuItem item = new ExternalFileMenuItem(frame(), "", flEntry.getLink(), flEntry.getType().map(ExternalFileType::getIcon).map(JabRefIcon::getSmallIcon).orElse(null), bibDatabaseContext, flEntry.getType());
item.doClick();
LinkedFile flEntry = files.get(0);
try {
JabRefDesktop.openExternalFileAnyFormat(this.getBibDatabaseContext(), flEntry.getLink(), ExternalFileTypes.getInstance().fromLinkedFile(flEntry, true));
} catch (IOException ex) {
dialogService.showErrorDialogAndWait(ex);
}
});
}

Expand Down Expand Up @@ -828,9 +828,8 @@ public EntryEditor getEntryEditor() {
}

/**
* Sets the entry editor as the bottom component in the split pane. If an entry editor already was shown,
* makes sure that the divider doesn't move. Updates the mode to SHOWING_EDITOR.
* Then shows the given entry.
* Sets the entry editor as the bottom component in the split pane. If an entry editor already was shown, makes sure
* that the divider doesn't move. Updates the mode to SHOWING_EDITOR. Then shows the given entry.
*
* @param entry The entry to edit.
*/
Expand Down Expand Up @@ -949,8 +948,7 @@ public void entryEditorClosing(EntryEditor editor) {
* Closes the entry editor or preview panel if it is showing the given entry.
*/
public void ensureNotShowingBottomPanel(BibEntry entry) {
if (((mode == BasePanelMode.SHOWING_EDITOR) && (entryEditor.getEntry() == entry))
|| ((mode == BasePanelMode.SHOWING_PREVIEW))) {
if (((mode == BasePanelMode.SHOWING_EDITOR) && (entryEditor.getEntry() == entry)) || ((mode == BasePanelMode.SHOWING_PREVIEW))) {
closeBottomPane();
}
}
Expand All @@ -964,16 +962,7 @@ public void updateEntryEditorIfShowing() {

public void markBaseChanged() {
baseChanged = true;

if (SwingUtilities.isEventDispatchThread()) {
markBasedChangedInternal();
} else {
try {
SwingUtilities.invokeAndWait(() -> markBasedChangedInternal());
} catch (InvocationTargetException | InterruptedException e) {
LOGGER.info("Problem marking database as changed", e);
}
}
markBasedChangedInternal();
}

private void markBasedChangedInternal() {
Expand Down Expand Up @@ -1021,18 +1010,19 @@ public boolean showDeleteConfirmationDialog(int numberOfEntries) {
}

return dialogService.showConfirmationDialogWithOptOutAndWait(title,
message,
okButton,
cancelButton,
Localization.lang("Disable this confirmation dialog"),
optOut -> Globals.prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, !optOut));
message,
okButton,
cancelButton,
Localization.lang("Disable this confirmation dialog"),
optOut -> Globals.prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, !optOut));
} else {
return true;
}
}

/**
* Depending on whether a preview or an entry editor is showing, save the current divider location in the correct preference setting.
* Depending on whether a preview or an entry editor is showing, save the current divider location in the correct
* preference setting.
*/
private void saveDividerLocation(Number position) {
if (position == null) {
Expand Down Expand Up @@ -1224,7 +1214,7 @@ public void listen(EntryAddedEvent addedEntryEvent) {
if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)) {
final List<BibEntry> entries = Collections.singletonList(addedEntryEvent.getBibEntry());
Globals.stateManager.getSelectedGroup(bibDatabaseContext).forEach(
selectedGroup -> selectedGroup.addEntriesToGroup(entries));
selectedGroup -> selectedGroup.addEntriesToGroup(entries));
}
}
}
Expand All @@ -1239,8 +1229,7 @@ public void listen(EntryRemovedEvent entryRemovedEvent) {

/**
* Ensures that the search auto completer is up to date when entries are changed AKA Let the auto completer, if any,
* harvest words from the entry
* Actual methods for autocomplete indexing must run in javafx thread
* harvest words from the entry Actual methods for autocomplete indexing must run in javafx thread
*/
private class SearchAutoCompleteListener {

Expand All @@ -1256,8 +1245,8 @@ public void listen(EntryChangedEvent entryChangedEvent) {
}

/**
* Ensures that the results of the current search are updated when a new entry is inserted into the database
* Actual methods for performing search must run in javafx thread
* Ensures that the results of the current search are updated when a new entry is inserted into the database Actual
* methods for performing search must run in javafx thread
*/
private class SearchListener {

Expand Down Expand Up @@ -1331,8 +1320,8 @@ public void action() {
try {

JabRefDesktop.openExternalFileAnyFormat(bibDatabaseContext,
linkedFile.get().getLink(),
ExternalFileTypes.getInstance().fromLinkedFile(linkedFile.get(), true));
linkedFile.get().getLink(),
ExternalFileTypes.getInstance().fromLinkedFile(linkedFile.get(), true));

output(Localization.lang("External viewer called") + '.');
} catch (IOException e) {
Expand Down
16 changes: 5 additions & 11 deletions src/main/java/org/jabref/gui/GUIGlobals.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.jabref.gui;

import java.awt.Color;
import java.awt.Font;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

import org.jabref.Globals;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.keyboard.EmacsKeyBindings;
import org.jabref.gui.util.CustomLocalDragboard;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;
Expand Down Expand Up @@ -45,20 +44,15 @@ public static void updateEntryEditorColors() {
* on Un*x is unavailable.
*/
public static void init() {
if (Globals.prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS)) {
EmacsKeyBindings.load();
}

// Set up entry editor colors, first time:
GUIGlobals.updateEntryEditorColors();

IconTheme.loadFonts();
GUIGlobals.currentFont = new Font(Globals.prefs.get(JabRefPreferences.FONT_FAMILY),
Globals.prefs.getInt(JabRefPreferences.FONT_STYLE), Globals.prefs.getInt(JabRefPreferences.FONT_SIZE));
GUIGlobals.currentFont = new Font(Globals.prefs.getFontFamily(), Globals.prefs.getDouble(JabRefPreferences.FONT_SIZE));
}

public static void setFont(int size) {
currentFont = new Font(currentFont.getFamily(), currentFont.getStyle(), size);
public static void setFont(double size) {
currentFont = new Font(currentFont.getFamily(), size);
// update preferences
Globals.prefs.putInt(JabRefPreferences.FONT_SIZE, size);
}
Expand Down
54 changes: 0 additions & 54 deletions src/main/java/org/jabref/gui/JabRefDialog.java

This file was deleted.

24 changes: 4 additions & 20 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
import java.util.TimerTask;
import java.util.stream.Collectors;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
Expand Down Expand Up @@ -294,9 +291,7 @@ private void initShowTrackingNotification() {

@Override
public void run() {
SwingUtilities.invokeLater(() -> {
DefaultTaskExecutor.runInJavaFXThread(JabRefFrame.this::showTrackingNotification);
});
}
}, 60000); // run in one minute
}
Expand Down Expand Up @@ -402,6 +397,8 @@ private void tearDownJabRef(List<String> filenames) {
prefs.flush();

// dispose all windows, even if they are not displayed anymore
// TODO: javafx variant only avaiable in java 9 and updwards
// https://docs.oracle.com/javase/9/docs/api/javafx/stage/Window.html#getWindows--
for (Window window : Window.getWindows()) {
window.dispose();
}
Expand Down Expand Up @@ -1063,18 +1060,9 @@ public void setProgressBarVisible(final boolean visible) {
/**
* Sets the indeterminate status of the progress bar.
* <p>
* If not called on the event dispatch thread, this method uses SwingUtilities.invokeLater() to do the actual
* operation on the EDT.
*/
public void setProgressBarIndeterminate(final boolean value) {
// TODO: Reimplement
/*
if (SwingUtilities.isEventDispatchThread()) {
progressBar.setIndeterminate(value);
} else {
SwingUtilities.invokeLater(() -> progressBar.setIndeterminate(value));
}
*/
progressBar.setProgress(ProgressBar.INDETERMINATE_PROGRESS);
}

/**
Expand Down Expand Up @@ -1107,10 +1095,6 @@ private boolean isExistURLorDOI(List<BibEntry> selectEntryList) {
return false;
}

public void showMessage(String message) {
JOptionPane.showMessageDialog(null, message);
}

/**
* Ask if the user really wants to close the given database
*
Expand Down Expand Up @@ -1297,7 +1281,7 @@ private void increaseTableFontSize() {
}

private void decreaseTableFontSize() {
int currentSize = GUIGlobals.currentFont.getSize();
double currentSize = GUIGlobals.currentFont.getSize();
if (currentSize < 2) {
return;
}
Expand Down
Loading

0 comments on commit 854cd51

Please sign in to comment.