From a0488d3b385b847b4f026a318f45f60170e01e67 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sun, 3 Dec 2017 22:35:09 +0100 Subject: [PATCH 001/827] Convert main view to JavaFX --- src/main/java/org/jabref/JabRefGUI.java | 97 +++++--- src/main/java/org/jabref/JabRefMain.java | 35 +-- src/main/java/org/jabref/gui/BasePanel.java | 113 ++++------ .../jabref/gui/DuplicateResolverDialog.java | 15 +- .../java/org/jabref/gui/EntryTypeDialog.java | 57 ++--- src/main/java/org/jabref/gui/FXDialog.java | 12 +- .../org/jabref/gui/GenFieldsCustomizer.java | 30 +-- src/main/java/org/jabref/gui/JabRefFrame.java | 208 ++++++------------ src/main/java/org/jabref/gui/MergeDialog.java | 21 +- .../java/org/jabref/gui/PreambleEditor.java | 25 +-- .../org/jabref/gui/ReplaceStringDialog.java | 31 +-- .../java/org/jabref/gui/SidePaneManager.java | 20 +- .../java/org/jabref/gui/StringDialog.java | 45 ++-- .../org/jabref/gui/WaitForSaveOperation.java | 20 +- .../gui/actions/AutoLinkFilesAction.java | 13 +- .../org/jabref/gui/actions/CleanupAction.java | 17 +- .../gui/actions/IntegrityCheckAction.java | 48 ++-- .../gui/actions/ManageKeywordsAction.java | 46 ++-- .../gui/actions/MassSetFieldAction.java | 39 +--- .../jabref/gui/actions/NewEntryAction.java | 16 +- .../gui/actions/NewSubDatabaseAction.java | 8 +- .../autosaveandbackup/BackupUIManager.java | 10 +- .../jabref/gui/auximport/FromAuxDialog.java | 39 +--- .../BibtexKeyPatternDialog.java | 21 +- .../ResolveDuplicateLabelDialog.java | 30 +-- .../org/jabref/gui/collab/ChangeScanner.java | 35 ++- .../ContentSelectorDialog.java | 46 ++-- .../EntryCustomizationDialog.java | 52 ++--- .../org/jabref/gui/desktop/JabRefDesktop.java | 40 ++-- .../jabref/gui/entryeditor/EntryEditor.java | 67 ++---- .../gui/exporter/CustomExportDialog.java | 34 +-- .../org/jabref/gui/exporter/ExportAction.java | 31 ++- .../exporter/ExportCustomizationDialog.java | 37 +--- .../gui/exporter/ExportToClipboardAction.java | 33 ++- .../gui/exporter/SaveDatabaseAction.java | 42 ++-- .../externalfiles/DownloadExternalFile.java | 33 ++- .../gui/externalfiles/DroppedFileHandler.java | 50 ++--- .../gui/externalfiles/FindFullTextAction.java | 32 ++- .../externalfiles/SynchronizeFileField.java | 49 ++--- .../gui/externalfiles/WriteXMPAction.java | 39 +--- .../ExternalFileMenuItem.java | 20 +- .../ExternalFileTypeEditor.java | 47 ++-- .../gui/groups/GroupAddRemoveDialog.java | 36 +-- .../org/jabref/gui/groups/GroupDialog.java | 57 ++--- .../gui/importer/FetcherPreviewDialog.java | 45 ++-- .../importer/ImportCustomizationDialog.java | 60 ++--- .../jabref/gui/importer/ImportFormats.java | 31 ++- .../gui/importer/ImportInspectionDialog.java | 110 +++------ .../jabref/gui/importer/ImportMenuItem.java | 35 ++- .../importer/ParserResultWarningDialog.java | 15 +- .../actions/CheckForNewEntryTypesAction.java | 22 +- .../importer/actions/OpenDatabaseAction.java | 41 ++-- .../gui/importer/fetcher/GeneralFetcher.java | 30 +-- .../org/jabref/gui/menus/FileHistoryMenu.java | 19 +- .../gui/mergeentries/MergeEntriesDialog.java | 22 +- .../mergeentries/MergeFetchedEntryDialog.java | 27 +-- .../MergeWithFetchedEntryAction.java | 6 +- .../gui/openoffice/AdvancedCiteDialog.java | 25 +-- .../gui/openoffice/CitationManager.java | 42 ++-- .../gui/openoffice/OpenOfficePanel.java | 108 ++++----- .../gui/openoffice/StyleSelectDialog.java | 80 +++---- .../gui/plaintextimport/TextInputDialog.java | 97 ++------ .../org/jabref/gui/preftabs/ExternalTab.java | 24 +- .../java/org/jabref/gui/preftabs/FileTab.java | 30 +-- .../gui/preftabs/PreferencesDialog.java | 46 ++-- .../NewProtectedTermsFileDialog.java | 30 +-- .../protectedterms/ProtectedTermsDialog.java | 66 ++---- .../gui/push/PushToApplicationAction.java | 18 +- .../gui/push/PushToApplicationButton.java | 39 +--- .../java/org/jabref/gui/push/PushToEmacs.java | 21 +- .../java/org/jabref/gui/push/PushToVim.java | 21 +- .../shared/ConnectToSharedDatabaseDialog.java | 57 ++--- .../gui/shared/MergeSharedEntryDialog.java | 22 +- .../gui/shared/SharedDatabaseUIManager.java | 17 +- .../org/jabref/gui/worker/VersionWorker.java | 25 +-- .../migrations/FileLinksUpgradeWarning.java | 17 +- .../org/jabref/pdfimport/PdfImporter.java | 22 +- .../jabref/preferences/JabRefPreferences.java | 55 ++--- src/main/java/osx/macadapter/MacAdapter.java | 20 +- .../java/org/jabref/gui/AbstractUITest.java | 22 +- .../java/org/jabref/testutils/TestUtils.java | 1 - 81 files changed, 1078 insertions(+), 2086 deletions(-) diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index 3e17bf108b6..98a824c2776 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -1,21 +1,19 @@ package org.jabref; -import java.awt.Frame; -import java.io.File; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; - -import javax.swing.JOptionPane; -import javax.swing.UIDefaults; -import javax.swing.UIManager; -import javax.swing.UnsupportedLookAndFeelException; -import javax.swing.plaf.FontUIResource; -import javax.swing.plaf.metal.MetalLookAndFeel; - +import com.jgoodies.looks.plastic.Plastic3DLookAndFeel; +import com.jgoodies.looks.plastic.theme.SkyBluer; +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import com.sun.jna.platform.win32.User32; +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinUser; +import javafx.application.Platform; +import javafx.scene.Scene; +import javafx.scene.control.TextArea; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.gui.BasePanel; import org.jabref.gui.GUIGlobals; import org.jabref.gui.JabRefFrame; @@ -35,10 +33,14 @@ import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; import org.jabref.shared.exception.NotASharedDatabaseException; -import com.jgoodies.looks.plastic.Plastic3DLookAndFeel; -import com.jgoodies.looks.plastic.theme.SkyBluer; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.plaf.FontUIResource; +import javax.swing.plaf.metal.MetalLookAndFeel; +import java.io.File; +import java.sql.SQLException; +import java.util.*; + +import static com.sun.jna.platform.win32.WinUser.GWL_STYLE; public class JabRefGUI { private static final Log LOGGER = LogFactory.getLog(JabRefGUI.class); @@ -52,7 +54,7 @@ public class JabRefGUI { private String focusedFile; - public JabRefGUI(List argsDatabases, boolean isBlank) { + public JabRefGUI(Stage mainStage, List argsDatabases, boolean isBlank) { this.bibDatabases = argsDatabases; this.isBlank = isBlank; @@ -60,7 +62,7 @@ public JabRefGUI(List argsDatabases, boolean isBlank) { focusedFile = argsDatabases.stream().findFirst().flatMap(ParserResult::getFile).map(File::getAbsolutePath) .orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED)); - openWindow(); + openWindow(mainStage); JabRefGUI.checkForNewVersion(false); } @@ -70,7 +72,7 @@ public static void checkForNewVersion(boolean manualExecution) { new VersionWorker(JabRefGUI.getMainFrame(), manualExecution, currentVersion, toBeIgnored).execute(); } - private void openWindow() { + private void openWindow(Stage mainStage) { // This property is set to make the Mac OSX Java VM move the menu bar to the top of the screen if (OS.OS_X) { @@ -121,7 +123,7 @@ private void openWindow() { pr.getDatabase().clearSharedDatabaseID(); LOGGER.error("Connection error", e); - JOptionPane.showMessageDialog(mainFrame, + JOptionPane.showMessageDialog(null, e.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."), Localization.lang("Connection error"), JOptionPane.WARNING_MESSAGE); } @@ -147,17 +149,54 @@ private void openWindow() { // state. This needs to be set after the window has been made visible, so we // do it here: if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) { - JabRefGUI.getMainFrame().setExtendedState(Frame.MAXIMIZED_BOTH); + //JabRefGUI.getMainFrame().setExtendedState(Frame.MAXIMIZED_BOTH); + } + + mainStage.setTitle(JabRefFrame.FRAME_TITLE); + + TextArea ta = new TextArea("output\n"); + VBox root = new VBox(5, ta); + Scene scene = new Scene(root, 800, 200); + mainStage.setTitle("Find this window"); + mainStage.setScene(scene); + mainStage.show(); + + //gets this window (stage) + long lhwnd = com.sun.glass.ui.Window.getWindows().get(0).getNativeWindow(); + Pointer lpVoid = new Pointer(lhwnd); + //gets the foreground (focused) window + final User32 user32 = User32.INSTANCE; + char[] windowText = new char[512]; + WinDef.HWND hwnd = user32.GetForegroundWindow(); + //see what the title is + user32.GetWindowText(hwnd, windowText, 512); + //user32.GetWindowText(new HWND(lpVoid), windowText, 512);//to use the hwnd from stage + String text = (Native.toString(windowText)); + //see if it's the same pointer + ta.appendText("HWND java:" + lpVoid + " HWND user32:" + hwnd + " text:" + text + "\n"); + //change the window style if it's the right title + if (text.equals(mainStage.getTitle())) { + //the style to change + int WS_DLGFRAME = 0x00400000;//s/b long I think + //not the same constant here?? + ta.appendText("windows api:" + WS_DLGFRAME + " JNA: " + WinUser.SM_CXDLGFRAME); + int oldStyle = user32.GetWindowLong(hwnd, GWL_STYLE); + int newStyle = oldStyle & ~0x00400000; //bitwise not WS_DLGFRAME means remove the style + newStyle = newStyle & ~0x00040000;//WS_THICKFRAME + user32.SetWindowLong(hwnd, GWL_STYLE, newStyle); } - JabRefGUI.getMainFrame().setVisible(true); + mainStage.setOnCloseRequest(event -> { + mainFrame.quit(); + Platform.exit(); + }); for (ParserResult pr : failed) { String message = "" + Localization.lang("Error opening file '%0'.", pr.getFile().get().getName()) + "

" + pr.getErrorMessage() + ""; - JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), message, Localization.lang("Error opening file"), + JOptionPane.showMessageDialog(null, message, Localization.lang("Error opening file"), JOptionPane.ERROR_MESSAGE); } @@ -204,7 +243,7 @@ private void openLastEditedDatabases() { } if (BackupManager.checkForBackupFile(dbFile.toPath())) { - BackupUIManager.showRestoreBackupDialog(mainFrame, dbFile.toPath()); + BackupUIManager.showRestoreBackupDialog(null, dbFile.toPath()); } ParserResult parsedDatabase = OpenDatabase.loadDatabase(fileName, @@ -265,7 +304,7 @@ private void setLookAndFeel() { // also set system l&f as default Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLookFeel); // notify the user - JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), + JOptionPane.showMessageDialog(null, Localization .lang("Unable to find the requested look and feel and thus the default one is used."), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE); diff --git a/src/main/java/org/jabref/JabRefMain.java b/src/main/java/org/jabref/JabRefMain.java index 428fdd5cdd6..08a7ae1b55a 100644 --- a/src/main/java/org/jabref/JabRefMain.java +++ b/src/main/java/org/jabref/JabRefMain.java @@ -1,16 +1,10 @@ package org.jabref; -import java.net.Authenticator; -import java.util.Map; - -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - import javafx.application.Application; import javafx.application.Platform; import javafx.stage.Stage; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.cli.ArgumentProcessor; import org.jabref.gui.remote.JabRefMessageHandler; import org.jabref.logic.exporter.ExportFormat; @@ -35,8 +29,9 @@ import org.jabref.model.entry.InternalBibtexFields; import org.jabref.preferences.JabRefPreferences; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.net.Authenticator; +import java.util.Map; /** * JabRef MainClass @@ -51,12 +46,6 @@ public static void main(String[] args) { launch(arguments); } - @Override - public void start(Stage mainStage) throws Exception { - Platform.setImplicitExit(false); - SwingUtilities.invokeLater(() -> start(arguments)); - } - /** * Tests if we are running an acceptable Java and terminates JabRef when we are sure the version is not supported. * This test uses the requirements for the Java version as specified in gradle.build. It is possible to @@ -89,7 +78,7 @@ private static void ensureCorrectJavaVersion() { versionError.append(Localization.lang("Note that currently, JabRef does not run with Java 9.")); } final JFrame frame = new JFrame(); - JOptionPane.showMessageDialog(frame, versionError, Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, versionError, Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); frame.dispose(); // We exit on Java 9 error since this will definitely not work @@ -99,7 +88,8 @@ private static void ensureCorrectJavaVersion() { } } - private static void start(String[] args) { + @Override + public void start(Stage mainStage) throws Exception { FallbackExceptionHandler.installExceptionHandler(); JabRefPreferences preferences = JabRefPreferences.getInstance(); @@ -164,7 +154,7 @@ private static void start(String[] args) { if (!Globals.REMOTE_LISTENER.isOpen()) { // we are not alone, there is already a server out there, try to contact already running JabRef: - if (RemoteListenerClient.sendToActiveJabRefInstance(args, remotePreferences.getPort())) { + if (RemoteListenerClient.sendToActiveJabRefInstance(arguments, remotePreferences.getPort())) { // We have successfully sent our command line options through the socket to another JabRef instance. // So we assume it's all taken care of, and quit. LOGGER.info(Localization.lang("Arguments passed on to running JabRef instance. Shutting down.")); @@ -183,7 +173,7 @@ private static void start(String[] args) { OS.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE); // Process arguments - ArgumentProcessor argumentProcessor = new ArgumentProcessor(args, ArgumentProcessor.Mode.INITIAL_START); + ArgumentProcessor argumentProcessor = new ArgumentProcessor(arguments, ArgumentProcessor.Mode.INITIAL_START); // See if we should shut down now if (argumentProcessor.shouldShutDown()) { @@ -193,8 +183,7 @@ private static void start(String[] args) { } // If not, start GUI - SwingUtilities - .invokeLater(() -> new JabRefGUI(argumentProcessor.getParserResults(), - argumentProcessor.isBlank())); + new JabRefGUI(mainStage, argumentProcessor.getParserResults(), argumentProcessor.isBlank()); } + } diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 63ab1798c0d..f6aa04b26c6 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1,46 +1,11 @@ package org.jabref.gui; -import java.awt.BorderLayout; -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.ClipboardOwner; -import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.awt.event.ActionEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.io.File; -import java.io.IOException; -import java.io.StringReader; -import java.lang.reflect.InvocationTargetException; -import java.nio.charset.Charset; -import java.nio.charset.UnsupportedCharsetException; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import javax.swing.AbstractAction; -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JSplitPane; -import javax.swing.JTextArea; -import javax.swing.SwingUtilities; -import javax.swing.undo.CannotRedoException; -import javax.swing.undo.CannotUndoException; - +import com.google.common.eventbus.Subscribe; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; import javafx.application.Platform; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.actions.Actions; @@ -84,29 +49,15 @@ import org.jabref.gui.specialfields.SpecialFieldDatabaseChangeListener; import org.jabref.gui.specialfields.SpecialFieldValueViewModel; import org.jabref.gui.specialfields.SpecialFieldViewModel; -import org.jabref.gui.undo.CountingUndoManager; -import org.jabref.gui.undo.NamedCompound; -import org.jabref.gui.undo.UndoableChangeType; -import org.jabref.gui.undo.UndoableFieldChange; -import org.jabref.gui.undo.UndoableInsertEntry; -import org.jabref.gui.undo.UndoableKeyChange; -import org.jabref.gui.undo.UndoableRemoveEntry; +import org.jabref.gui.undo.*; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.component.CheckBoxMessage; -import org.jabref.gui.worker.AbstractWorker; -import org.jabref.gui.worker.CallBack; -import org.jabref.gui.worker.CitationStyleToClipboardWorker; -import org.jabref.gui.worker.MarkEntriesAction; -import org.jabref.gui.worker.SendAsEMailAction; +import org.jabref.gui.worker.*; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import org.jabref.logic.citationstyle.CitationStyleCache; import org.jabref.logic.citationstyle.CitationStyleOutputFormat; -import org.jabref.logic.exporter.BibtexDatabaseWriter; -import org.jabref.logic.exporter.FileSaveSession; -import org.jabref.logic.exporter.SaveException; -import org.jabref.logic.exporter.SavePreferences; -import org.jabref.logic.exporter.SaveSession; +import org.jabref.logic.exporter.*; import org.jabref.logic.l10n.Encodings; import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.Layout; @@ -140,11 +91,27 @@ import org.jabref.preferences.PreviewPreferences; import org.jabref.shared.DBMSSynchronizer; -import com.google.common.eventbus.Subscribe; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.undo.CannotRedoException; +import javax.swing.undo.CannotUndoException; +import java.awt.*; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.ClipboardOwner; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import java.awt.event.ActionEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.lang.reflect.InvocationTargetException; +import java.nio.charset.Charset; +import java.nio.charset.UnsupportedCharsetException; +import java.nio.file.Path; +import java.util.*; +import java.util.List; +import java.util.stream.Collectors; public class BasePanel extends JPanel implements ClipboardOwner { @@ -373,7 +340,6 @@ private void setupActions() { actions.put(Actions.EDIT_PREAMBLE, (BaseAction) () -> { if (preambleEditor == null) { PreambleEditor form = new PreambleEditor(frame, BasePanel.this, bibDatabaseContext.getDatabase()); - form.setLocationRelativeTo(frame); form.setVisible(true); preambleEditor = form; } else { @@ -393,8 +359,7 @@ private void setupActions() { }); actions.put(FindUnlinkedFilesDialog.ACTION_COMMAND, (BaseAction) () -> { - final FindUnlinkedFilesDialog dialog = new FindUnlinkedFilesDialog(frame, frame, BasePanel.this); - dialog.setLocationRelativeTo(frame); + final FindUnlinkedFilesDialog dialog = new FindUnlinkedFilesDialog(null, frame, BasePanel.this); dialog.setVisible(true); }); @@ -412,7 +377,7 @@ public void init() { numSelected = entries.size(); if (entries.isEmpty()) { // None selected. Inform the user to select entries first. - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("First select the entries you want keys to be generated for."), Localization.lang("Autogenerate BibTeX keys"), JOptionPane.INFORMATION_MESSAGE); return; @@ -434,7 +399,7 @@ public void run() { CheckBoxMessage cbm = new CheckBoxMessage( Localization.lang("One or more keys will be overwritten. Continue?"), Localization.lang("Disable this confirmation dialog"), false); - final int answer = JOptionPane.showConfirmDialog(frame, cbm, + final int answer = JOptionPane.showConfirmDialog(null, cbm, Localization.lang("Overwrite keys"), JOptionPane.YES_NO_OPTION); Globals.prefs.putBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY, !cbm.isSelected()); @@ -691,8 +656,7 @@ public void update() { actions.put(Actions.PREVIOUS_PREVIEW_STYLE, (BaseAction) selectionListener::previousPreviewStyle); actions.put(Actions.MANAGE_SELECTORS, (BaseAction) () -> { - ContentSelectorDialog csd = new ContentSelectorDialog(frame, frame, BasePanel.this, false, null); - csd.setLocationRelativeTo(frame); + ContentSelectorDialog csd = new ContentSelectorDialog(null, frame, BasePanel.this, false, null); csd.setVisible(true); }); @@ -1058,7 +1022,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc, } // FIXME: not sure if this is really thrown anywhere catch (UnsupportedCharsetException ex) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("Could not save file.") + ' ' + Localization.lang("Character encoding '%0' is not supported.", enc.displayName()), SAVE_DATABASE, JOptionPane.ERROR_MESSAGE); @@ -1072,7 +1036,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc, LOGGER.warn("Could not save", ex); } - JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + "\n" + ex.getMessage(), + JOptionPane.showMessageDialog(null, Localization.lang("Could not save file.") + "\n" + ex.getMessage(), SAVE_DATABASE, JOptionPane.ERROR_MESSAGE); throw new SaveException("rt"); } finally { @@ -1090,13 +1054,13 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc, builder.add(ta).xy(3, 1); builder.add(Localization.lang("What do you want to do?")).xy(1, 3); String tryDiff = Localization.lang("Try different encoding"); - int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), SAVE_DATABASE, + int answer = JOptionPane.showOptionDialog(null, builder.getPanel(), SAVE_DATABASE, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[]{Localization.lang("Save"), tryDiff, Localization.lang("Cancel")}, tryDiff); if (answer == JOptionPane.NO_OPTION) { // The user wants to use another encoding. - Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"), SAVE_DATABASE, + Object choice = JOptionPane.showInputDialog(null, Localization.lang("Select encoding"), SAVE_DATABASE, JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, enc); if (choice == null) { commit = false; @@ -1143,7 +1107,6 @@ public BibEntry newEntry(EntryType type) { // Find out what type is wanted. final EntryTypeDialog etd = new EntryTypeDialog(frame); // We want to center the dialog, to make it look nicer. - etd.setLocationRelativeTo(frame); etd.setVisible(true); actualType = etd.getChoice(); } @@ -1715,7 +1678,7 @@ public boolean showDeleteConfirmationDialog(int numberOfEntries) { CheckBoxMessage cb = new CheckBoxMessage(msg, Localization.lang("Disable this confirmation dialog"), false); - int answer = JOptionPane.showConfirmDialog(frame, cb, title, JOptionPane.YES_NO_OPTION, + int answer = JOptionPane.showConfirmDialog(null, cb, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (cb.isSelected()) { Globals.prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, false); diff --git a/src/main/java/org/jabref/gui/DuplicateResolverDialog.java b/src/main/java/org/jabref/gui/DuplicateResolverDialog.java index baae8dac19a..ff0a2976d54 100644 --- a/src/main/java/org/jabref/gui/DuplicateResolverDialog.java +++ b/src/main/java/org/jabref/gui/DuplicateResolverDialog.java @@ -1,13 +1,5 @@ package org.jabref.gui; -import java.awt.BorderLayout; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -import javax.swing.Box; -import javax.swing.JButton; -import javax.swing.JPanel; - import org.jabref.gui.help.HelpAction; import org.jabref.gui.importer.ImportInspectionDialog; import org.jabref.gui.mergeentries.MergeEntries; @@ -17,6 +9,11 @@ import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; +import javax.swing.*; +import java.awt.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + public class DuplicateResolverDialog extends JabRefDialog { public enum DuplicateResolverType { @@ -45,7 +42,7 @@ public enum DuplicateResolverResult { private MergeEntries me; public DuplicateResolverDialog(JabRefFrame frame, BibEntry one, BibEntry two, DuplicateResolverType type) { - super(frame, Localization.lang("Possible duplicate entries"), true, DuplicateResolverDialog.class); + super((JFrame) null, Localization.lang("Possible duplicate entries"), true, DuplicateResolverDialog.class); this.frame = frame; init(one, two, type); } diff --git a/src/main/java/org/jabref/gui/EntryTypeDialog.java b/src/main/java/org/jabref/gui/EntryTypeDialog.java index 84a736773c4..0ce7b157e2f 100644 --- a/src/main/java/org/jabref/gui/EntryTypeDialog.java +++ b/src/main/java/org/jabref/gui/EntryTypeDialog.java @@ -1,31 +1,8 @@ package org.jabref.gui; -import java.awt.BorderLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.ExecutionException; - -import javax.swing.AbstractAction; -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.SwingUtilities; -import javax.swing.SwingWorker; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.importer.ImportInspectionDialog; import org.jabref.gui.keyboard.KeyBinding; @@ -38,15 +15,18 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.EntryTypes; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BiblatexEntryTypes; -import org.jabref.model.entry.BibtexEntryTypes; -import org.jabref.model.entry.EntryType; -import org.jabref.model.entry.IEEETranEntryTypes; +import org.jabref.model.entry.*; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; /** * Dialog that prompts the user to choose a type for an entry. @@ -66,7 +46,7 @@ public class EntryTypeDialog extends JabRefDialog implements ActionListener { public EntryTypeDialog(JabRefFrame frame) { // modal dialog - super(frame, true, EntryTypeDialog.class); + super(null, true, EntryTypeDialog.class); this.frame = frame; @@ -314,7 +294,6 @@ protected void done() { ImportInspectionDialog diag = new ImportInspectionDialog(frame, panel, Localization.lang("Import"), false); diag.addEntry(bibEntry); diag.entryListComplete(); - diag.setLocationRelativeTo(frame); diag.setVisible(true); diag.toFront(); } else { @@ -329,11 +308,11 @@ protected void done() { dispose(); } else if (searchID.trim().isEmpty()) { - JOptionPane.showMessageDialog(frame, Localization.lang("The given search ID was empty."), Localization.lang("Empty search ID"), JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(null, Localization.lang("The given search ID was empty."), Localization.lang("Empty search ID"), JOptionPane.WARNING_MESSAGE); } else if (!fetcherException) { - JOptionPane.showMessageDialog(frame, Localization.lang("Fetcher '%0' did not find an entry for id '%1'.", fetcher.getName(), searchID) + "\n" + fetcherExceptionMessage, Localization.lang("No files found."), JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(null, Localization.lang("Fetcher '%0' did not find an entry for id '%1'.", fetcher.getName(), searchID) + "\n" + fetcherExceptionMessage, Localization.lang("No files found."), JOptionPane.WARNING_MESSAGE); } else { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("Error while fetching from %0", fetcher.getName()) + "." + "\n" + fetcherExceptionMessage, Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); } diff --git a/src/main/java/org/jabref/gui/FXDialog.java b/src/main/java/org/jabref/gui/FXDialog.java index d59ccaecda4..1affaba5f0d 100644 --- a/src/main/java/org/jabref/gui/FXDialog.java +++ b/src/main/java/org/jabref/gui/FXDialog.java @@ -1,9 +1,5 @@ package org.jabref.gui; -import java.awt.Window; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - import javafx.application.Platform; import javafx.fxml.FXMLLoader; import javafx.scene.control.Alert; @@ -12,12 +8,14 @@ import javafx.scene.image.Image; import javafx.stage.Modality; import javafx.stage.Stage; - import org.jabref.Globals; -import org.jabref.JabRefGUI; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.keyboard.KeyBindingRepository; +import java.awt.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + /** * This class provides a super class for all dialogs implemented in JavaFX. * It mimics the behavior of a Swing JDialog which means once a object of this class @@ -134,6 +132,7 @@ private void setSwingWindowsEnabledAndFocusable(boolean enabled) { } private void setLocationRelativeToMainWindow() { + /* double mainWindowX = JabRefGUI.getMainFrame().getLocationOnScreen().getX(); double mainWindowY = JabRefGUI.getMainFrame().getLocationOnScreen().getY(); double mainWindowWidth = JabRefGUI.getMainFrame().getSize().getWidth(); @@ -141,6 +140,7 @@ private void setLocationRelativeToMainWindow() { setX((mainWindowX + (mainWindowWidth / 2)) - (getWidth() / 2)); setY((mainWindowY + (mainWindowHeight / 2)) - (getHeight() / 2)); + */ } } diff --git a/src/main/java/org/jabref/gui/GenFieldsCustomizer.java b/src/main/java/org/jabref/gui/GenFieldsCustomizer.java index d7b93d7b349..11e0a36aced 100644 --- a/src/main/java/org/jabref/gui/GenFieldsCustomizer.java +++ b/src/main/java/org/jabref/gui/GenFieldsCustomizer.java @@ -1,25 +1,7 @@ package org.jabref.gui; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.util.Locale; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.layout.Sizes; import org.jabref.Globals; import org.jabref.gui.entryeditor.EntryEditorTabList; import org.jabref.gui.help.HelpAction; @@ -29,8 +11,10 @@ import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.layout.Sizes; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.util.Locale; public class GenFieldsCustomizer extends JabRefDialog { @@ -49,7 +33,7 @@ public class GenFieldsCustomizer extends JabRefDialog { private final JButton revert = new JButton(); public GenFieldsCustomizer(JabRefFrame frame) { - super(frame, Localization.lang("Set general fields"), false, GenFieldsCustomizer.class); + super((JFrame) null, Localization.lang("Set general fields"), false, GenFieldsCustomizer.class); helpBut = new HelpAction(HelpFile.GENERAL_FIELDS).getHelpButton(); jbInit(); setSize(new Dimension(650, 300)); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 3e30b97409c..630a4548626 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -1,83 +1,19 @@ package org.jabref.gui; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.FlowLayout; -import java.awt.Frame; -import java.awt.GraphicsEnvironment; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.Window; -import java.awt.event.ActionEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.MouseAdapter; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.TimerTask; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JProgressBar; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.JToggleButton; -import javax.swing.KeyStroke; -import javax.swing.MenuElement; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.TransferHandler; -import javax.swing.UIManager; -import javax.swing.WindowConstants; - +import com.google.common.eventbus.Subscribe; +import com.jgoodies.looks.HeaderStyle; +import com.jgoodies.looks.Options; import javafx.application.Platform; - +import javafx.embed.swing.SwingNode; +import javafx.scene.control.Button; +import javafx.scene.control.SplitPane; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.StackPane; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; -import org.jabref.gui.actions.Actions; -import org.jabref.gui.actions.AutoLinkFilesAction; -import org.jabref.gui.actions.ConnectToSharedDatabaseAction; -import org.jabref.gui.actions.ErrorConsoleAction; -import org.jabref.gui.actions.IntegrityCheckAction; -import org.jabref.gui.actions.LookupIdentifierAction; -import org.jabref.gui.actions.ManageKeywordsAction; -import org.jabref.gui.actions.MassSetFieldAction; -import org.jabref.gui.actions.MnemonicAwareAction; -import org.jabref.gui.actions.NewDatabaseAction; -import org.jabref.gui.actions.NewEntryAction; -import org.jabref.gui.actions.NewSubDatabaseAction; -import org.jabref.gui.actions.OpenBrowserAction; -import org.jabref.gui.actions.SearchForUpdateAction; -import org.jabref.gui.actions.SortTabsAction; +import org.jabref.gui.actions.*; import org.jabref.gui.autosaveandbackup.AutosaveUIManager; import org.jabref.gui.bibtexkeypattern.BibtexKeyPatternDialog; import org.jabref.gui.copyfiles.CopyFilesAction; @@ -114,7 +50,6 @@ import org.jabref.gui.specialfields.SpecialFieldDropDown; import org.jabref.gui.specialfields.SpecialFieldValueViewModel; import org.jabref.gui.util.DefaultTaskExecutor; -import org.jabref.gui.util.WindowLocation; import org.jabref.gui.worker.MarkEntriesAction; import org.jabref.logic.autosaveandbackup.AutosaveManager; import org.jabref.logic.autosaveandbackup.BackupManager; @@ -141,26 +76,32 @@ import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.LastFocusedTabPreferences; import org.jabref.preferences.SearchPreferences; - -import com.google.common.eventbus.Subscribe; -import com.jgoodies.looks.HeaderStyle; -import com.jgoodies.looks.Options; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import osx.macadapter.MacAdapter; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.MouseAdapter; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; +import java.util.List; + /** * The main window of the application. */ -public class JabRefFrame extends JFrame implements OutputPrinter { +public class JabRefFrame extends BorderPane implements OutputPrinter { private static final Log LOGGER = LogFactory.getLog(JabRefFrame.class); // Frame titles. - private static final String FRAME_TITLE = "JabRef"; + public static final String FRAME_TITLE = "JabRef"; private static final String ELLIPSES = "..."; public final AbstractAction nextTab = new ChangeTabAction(true); public final AbstractAction prevTab = new ChangeTabAction(false); - private final JSplitPane splitPane = new JSplitPane(); + private final SplitPane splitPane = new SplitPane(); private final JabRefPreferences prefs = Globals.prefs; private final Insets marg = new Insets(1, 0, 2, 0); private final IntegrityCheckAction checkIntegrity = new IntegrityCheckAction(this); @@ -562,25 +503,6 @@ private void init() { tabbedPane = new DragDropPopupPane(tabPopupMenu()); - MyGlassPane glassPane = new MyGlassPane(); - setGlassPane(glassPane); - - setTitle(FRAME_TITLE); - setIconImages(IconTheme.getLogoSet()); - setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - - @Override - public void windowClosing(WindowEvent e) { - - if (OS.OS_X) { - JabRefFrame.this.setVisible(false); - } else { - new CloseAction().actionPerformed(null); - } - } - }); - initSidePane(); initLayout(); @@ -590,10 +512,10 @@ public void windowClosing(WindowEvent e) { // Show the toolbar if it was visible at last shutdown: tlb.setVisible(Globals.prefs.getBoolean(JabRefPreferences.TOOLBAR_VISIBLE)); - setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); - WindowLocation pw = new WindowLocation(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X, - JabRefPreferences.SIZE_Y); - pw.displayWindowAtStoredLocation(); + //setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); + //WindowLocation pw = new WindowLocation(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X, + // JabRefPreferences.SIZE_Y); + //pw.displayWindowAtStoredLocation(); tabbedPane.setBorder(null); tabbedPane.setForeground(GUIGlobals.INACTIVE_TABBED_COLOR); @@ -703,7 +625,7 @@ public void setWindowTitle() { // no database open if (panel == null) { - setTitle(FRAME_TITLE); + //setTitle(FRAME_TITLE); return; } @@ -715,10 +637,10 @@ public void setWindowTitle() { String changeFlag = panel.isModified() && !isAutosaveEnabled ? "*" : ""; String databaseFile = panel.getBibDatabaseContext().getDatabaseFile().map(File::getPath) .orElse(GUIGlobals.UNTITLED_TITLE); - setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo); + //setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo); } else if (panel.getBibDatabaseContext().getLocation() == DatabaseLocation.SHARED) { - setTitle(FRAME_TITLE + " - " + panel.getBibDatabaseContext().getDBMSSynchronizer().getDBName() + " [" - + Localization.lang("shared") + "]" + modeInfo); + //setTitle(FRAME_TITLE + " - " + panel.getBibDatabaseContext().getDBMSSynchronizer().getDBName() + " [" + // + Localization.lang("shared") + "]" + modeInfo); } } @@ -755,7 +677,7 @@ public void showPreferencesDialog() { output(Localization.lang("Opening preferences...")); if (prefsDialog == null) { prefsDialog = new PreferencesDialog(JabRefFrame.this); - prefsDialog.setLocationRelativeTo(JabRefFrame.this); + //prefsDialog.setLocationRelativeTo(JabRefFrame.this); } else { prefsDialog.setValues(); } @@ -779,15 +701,15 @@ private void tearDownJabRef(List filenames) { Globals.stopBackgroundTasks(); Globals.shutdownThreadPools(); - dispose(); + //dispose(); - prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, getExtendedState() == Frame.MAXIMIZED_BOTH); + //prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, getExtendedState() == Frame.MAXIMIZED_BOTH); prefs.putBoolean(JabRefPreferences.TOOLBAR_VISIBLE, tlb.isVisible()); // Store divider location for side pane: - int width = splitPane.getDividerLocation(); + double width = splitPane.getDividerPositions()[0]; if (width > 0) { - prefs.putInt(JabRefPreferences.SIDE_PANE_WIDTH, width); + prefs.putDouble(JabRefPreferences.SIDE_PANE_WIDTH, width); } if (prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) { // Here we store the names of all current files. If @@ -903,19 +825,33 @@ private void initLayout() { pushExternalButton = new PushToApplicationButton(this, pushApplications.getApplications()); fillMenu(); createToolBar(); - setJMenuBar(mb); - getContentPane().setLayout(new BorderLayout()); + //setJMenuBar(mb); + //getContentPane().setLayout(new BorderLayout()); JPanel toolbarPanel = new JPanel(new WrapLayout(FlowLayout.LEFT)); toolbarPanel.add(tlb); toolbarPanel.add(globalSearchBar); - getContentPane().add(toolbarPanel, BorderLayout.PAGE_START); + //getContentPane().add(toolbarPanel, BorderLayout.PAGE_START); - splitPane.setDividerSize(2); - splitPane.setBorder(null); - splitPane.setRightComponent(tabbedPane); - splitPane.setLeftComponent(sidePaneManager.getPanel()); - getContentPane().add(splitPane, BorderLayout.CENTER); + //splitPane.setDividerSize(2); + //splitPane.setBorder(null); + setCenter(splitPane); + + StackPane header = new StackPane(); + header.setId("header"); + header.setPrefHeight(50); + header.setStyle("-fx-background-color: #4d4674; -fx-text-fill: white;"); + setTop(header); + + SwingNode swingTabbedPane = new SwingNode(); + SwingNode swingSidePane = new SwingNode(); + SwingUtilities.invokeLater(() -> { + swingTabbedPane.setContent(tabbedPane); + swingSidePane.setContent(sidePaneManager.getPanel()); + }); + StackPane centerPane = new StackPane(); + centerPane.getChildren().addAll(swingTabbedPane, new Button("test")); + splitPane.getItems().addAll(swingSidePane, swingTabbedPane); UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0)); sidePaneManager.updateView(); @@ -943,7 +879,7 @@ private void initLayout() { gbl.setConstraints(progressBar, con); status.add(progressBar); statusLabel.setForeground(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR.darker()); - getContentPane().add(status, BorderLayout.PAGE_END); + //getContentPane().add(status, BorderLayout.PAGE_END); // Drag and drop for tabbedPane: TransferHandler xfer = new EntryTableTransferHandler(null, this, null); @@ -1657,7 +1593,7 @@ private void addImportedEntries(final BasePanel panel, final List entr Localization.lang("Import"), openInNew); diag.addEntries(entries); diag.entryListComplete(); - diag.setLocationRelativeTo(JabRefFrame.this); + //diag.setLocationRelativeTo(JabRefFrame.this); diag.setVisible(true); diag.toFront(); }); @@ -1688,6 +1624,7 @@ public void unblock() { * @param blocked true if input should be blocked */ private void changeBlocking(boolean blocked) { + /* if (SwingUtilities.isEventDispatchThread()) { getGlassPane().setVisible(blocked); } else { @@ -1697,6 +1634,7 @@ private void changeBlocking(boolean blocked) { LOGGER.error("Problem " + (blocked ? "" : "un") + "blocking UI", e); } } + */ } /** @@ -1791,7 +1729,7 @@ private boolean isExistURLorDOI(List selectEntryList) { @Override public void showMessage(String message, String title, int msgType) { - JOptionPane.showMessageDialog(this, message, title, msgType); + JOptionPane.showMessageDialog(null, message, title, msgType); } @Override @@ -1801,7 +1739,7 @@ public void setStatus(String s) { @Override public void showMessage(String message) { - JOptionPane.showMessageDialog(this, message); + JOptionPane.showMessageDialog(null, message); } private int showSaveDialog(String filename) { @@ -1809,7 +1747,7 @@ private int showSaveDialog(String filename) { Localization.lang("Discard changes"), Localization.lang("Return to JabRef")}; - return JOptionPane.showOptionDialog(JabRefFrame.this, + return JOptionPane.showOptionDialog(null, Localization.lang("Library '%0' has changed.", filename), Localization.lang("Save before closing"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[2]); @@ -1915,7 +1853,7 @@ public AbstractAction getPreviousPreviewStyleAction() { return previousPreviewStyle; } - public JSplitPane getSplitPane() { + public SplitPane getSplitPane() { return splitPane; } @@ -2180,7 +2118,6 @@ public CustomizeEntryTypeAction() { @Override public void actionPerformed(ActionEvent e) { JDialog dl = new EntryCustomizationDialog(JabRefFrame.this); - dl.setLocationRelativeTo(JabRefFrame.this); dl.setVisible(true); } } @@ -2194,7 +2131,6 @@ public GenFieldsCustomizationAction() { @Override public void actionPerformed(ActionEvent e) { GenFieldsCustomizer gf = new GenFieldsCustomizer(JabRefFrame.this); - gf.setLocationRelativeTo(JabRefFrame.this); gf.setVisible(true); } @@ -2225,11 +2161,11 @@ public DatabasePropertiesAction() { @Override public void actionPerformed(ActionEvent e) { if (propertiesDialog == null) { - propertiesDialog = new DatabasePropertiesDialog(JabRefFrame.this); + propertiesDialog = new DatabasePropertiesDialog(null); } propertiesDialog.setPanel(getCurrentBasePanel()); propertiesDialog.updateEnableStatus(); - propertiesDialog.setLocationRelativeTo(JabRefFrame.this); + propertiesDialog.setLocationRelativeTo(null); propertiesDialog.setVisible(true); } @@ -2253,7 +2189,7 @@ public void actionPerformed(ActionEvent e) { // BibtexKeyPatternDialog allows for updating content based on currently selected panel bibtexKeyPatternDialog.setPanel(getCurrentBasePanel()); } - bibtexKeyPatternDialog.setLocationRelativeTo(JabRefFrame.this); + bibtexKeyPatternDialog.setLocationRelativeTo(null); bibtexKeyPatternDialog.setVisible(true); } diff --git a/src/main/java/org/jabref/gui/MergeDialog.java b/src/main/java/org/jabref/gui/MergeDialog.java index 805e19010a2..eb7ef41919e 100644 --- a/src/main/java/org/jabref/gui/MergeDialog.java +++ b/src/main/java/org/jabref/gui/MergeDialog.java @@ -1,24 +1,13 @@ package org.jabref.gui; -import java.awt.BorderLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.JPanel; - import org.jabref.Globals; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.l10n.Localization; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; + /** *

Title: MergeDialog

*

Description: Asks for details about merge database operation.

@@ -44,7 +33,7 @@ public class MergeDialog extends JabRefDialog { private boolean okPressed; public MergeDialog(JabRefFrame frame, String title, boolean modal) { - super(frame, title, modal, MergeDialog.class); + super((JFrame) null, title, modal, MergeDialog.class); jbInit(); pack(); } diff --git a/src/main/java/org/jabref/gui/PreambleEditor.java b/src/main/java/org/jabref/gui/PreambleEditor.java index ffcfb095c7a..80cba93c28a 100644 --- a/src/main/java/org/jabref/gui/PreambleEditor.java +++ b/src/main/java/org/jabref/gui/PreambleEditor.java @@ -1,23 +1,5 @@ package org.jabref.gui; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Container; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JPanel; -import javax.swing.LayoutFocusTraversalPolicy; -import javax.swing.text.JTextComponent; - import org.jabref.Globals; import org.jabref.gui.actions.Actions; import org.jabref.gui.fieldeditors.FieldEditor; @@ -29,6 +11,11 @@ import org.jabref.model.database.BibDatabase; import org.jabref.preferences.JabRefPreferences; +import javax.swing.*; +import javax.swing.text.JTextComponent; +import java.awt.*; +import java.awt.event.*; + class PreambleEditor extends JabRefDialog { // A reference to the entry this object works on. private final BibDatabase database; @@ -43,7 +30,7 @@ class PreambleEditor extends JabRefDialog { private final CloseAction closeAction = new CloseAction(); public PreambleEditor(JabRefFrame baseFrame, BasePanel panel, BibDatabase database) { - super(baseFrame, PreambleEditor.class); + super(null, PreambleEditor.class); this.panel = panel; this.database = database; diff --git a/src/main/java/org/jabref/gui/ReplaceStringDialog.java b/src/main/java/org/jabref/gui/ReplaceStringDialog.java index 6d5175bd9be..e9cc37fcb0b 100644 --- a/src/main/java/org/jabref/gui/ReplaceStringDialog.java +++ b/src/main/java/org/jabref/gui/ReplaceStringDialog.java @@ -1,26 +1,5 @@ package org.jabref.gui; -import java.awt.BorderLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Locale; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JTextField; - import org.jabref.Globals; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.undo.NamedCompound; @@ -28,6 +7,12 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Locale; + /** * Dialog for replacing strings. */ @@ -47,7 +32,7 @@ class ReplaceStringDialog extends JabRefDialog { public ReplaceStringDialog(JabRefFrame parent) { - super(parent, Localization.lang("Replace string"), true, ReplaceStringDialog.class); + super((JFrame) null, Localization.lang("Replace string"), true, ReplaceStringDialog.class); ButtonGroup bg = new ButtonGroup(); bg.add(allFi); @@ -162,8 +147,6 @@ public void actionPerformed(ActionEvent e) { getContentPane().add(opt, BorderLayout.SOUTH); pack(); - - this.setLocationRelativeTo(parent); } public boolean okPressed() { diff --git a/src/main/java/org/jabref/gui/SidePaneManager.java b/src/main/java/org/jabref/gui/SidePaneManager.java index 500c78af892..ace4d96bf2b 100644 --- a/src/main/java/org/jabref/gui/SidePaneManager.java +++ b/src/main/java/org/jabref/gui/SidePaneManager.java @@ -1,22 +1,14 @@ package org.jabref.gui; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import javax.swing.SwingUtilities; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.maintable.MainTable; import org.jabref.preferences.JabRefPreferences; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.util.*; +import java.util.stream.Collectors; /** * Manages visibility of SideShowComponents in a given newly constructed @@ -267,6 +259,7 @@ private synchronized void setActiveBasePanel(BasePanel panel) { public synchronized void updateView() { sidep.setComponents(visible); + /* if (visible.isEmpty()) { if (sidep.isVisible()) { Globals.prefs.putInt(JabRefPreferences.SIDE_PANE_WIDTH, frame.getSplitPane().getDividerLocation()); @@ -284,5 +277,6 @@ public synchronized void updateView() { } } } + */ } } diff --git a/src/main/java/org/jabref/gui/StringDialog.java b/src/main/java/org/jabref/gui/StringDialog.java index d79dbb67383..12fa871f2ec 100644 --- a/src/main/java/org/jabref/gui/StringDialog.java +++ b/src/main/java/org/jabref/gui/StringDialog.java @@ -1,35 +1,5 @@ package org.jabref.gui; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Container; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.DefaultCellEditor; -import javax.swing.InputMap; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.JToolBar; -import javax.swing.LayoutFocusTraversalPolicy; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableColumnModel; -import javax.swing.undo.CompoundEdit; - import org.jabref.Globals; import org.jabref.gui.actions.Actions; import org.jabref.gui.help.HelpAction; @@ -48,6 +18,19 @@ import org.jabref.model.entry.BibtexString; import org.jabref.preferences.JabRefPreferences; +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumnModel; +import javax.swing.undo.CompoundEdit; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + class StringDialog extends JabRefDialog { private static final String STRINGS_TITLE = Localization.lang("Strings for library"); @@ -65,7 +48,7 @@ class StringDialog extends JabRefDialog { public StringDialog(JabRefFrame frame, BasePanel panel, BibDatabase base) { - super(frame, StringDialog.class); + super(null, StringDialog.class); this.panel = panel; this.base = base; diff --git a/src/main/java/org/jabref/gui/WaitForSaveOperation.java b/src/main/java/org/jabref/gui/WaitForSaveOperation.java index 8d10d066884..47a7bfdd969 100644 --- a/src/main/java/org/jabref/gui/WaitForSaveOperation.java +++ b/src/main/java/org/jabref/gui/WaitForSaveOperation.java @@ -1,19 +1,12 @@ 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.JLabel; -import javax.swing.JProgressBar; -import javax.swing.Timer; - +import com.jgoodies.forms.builder.ButtonBarBuilder; import org.jabref.logic.l10n.Localization; -import com.jgoodies.forms.builder.ButtonBarBuilder; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** * Dialog shown when closing of application needs to wait for a save operation to finish. @@ -33,7 +26,7 @@ public WaitForSaveOperation(JabRefFrame frame) { JProgressBar prog = new JProgressBar(0); prog.setIndeterminate(true); prog.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - diag = new JDialog(frame, Localization.lang("Please wait..."), true); + diag = new JDialog((JFrame) null, Localization.lang("Please wait..."), true); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); @@ -55,7 +48,6 @@ public WaitForSaveOperation(JabRefFrame frame) { } public void show() { - diag.setLocationRelativeTo(frame); t.start(); diag.setVisible(true); diff --git a/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java b/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java index db9931a8f00..f92786113b5 100644 --- a/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java +++ b/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java @@ -1,12 +1,5 @@ package org.jabref.gui.actions; -import java.awt.event.ActionEvent; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JDialog; - import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.JabRefGUI; @@ -17,6 +10,10 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.util.List; + /** * This Action may only be used in a menu or button. * Never in the entry editor. FileListEditor and EntryEditor have other ways to update the file links @@ -38,7 +35,7 @@ public void actionPerformed(ActionEvent event) { .output(Localization.lang("This operation requires one or more entries to be selected.")); return; } - JDialog diag = new JDialog(JabRefGUI.getMainFrame(), true); + JDialog diag = new JDialog((JFrame) null, true); final NamedCompound nc = new NamedCompound(Localization.lang("Automatically set file links")); Runnable runnable = AutoSetLinks.autoSetLinks(entries, nc, null, JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext(), e -> { diff --git a/src/main/java/org/jabref/gui/actions/CleanupAction.java b/src/main/java/org/jabref/gui/actions/CleanupAction.java index 89e8d94ab90..5c26944f288 100644 --- a/src/main/java/org/jabref/gui/actions/CleanupAction.java +++ b/src/main/java/org/jabref/gui/actions/CleanupAction.java @@ -1,10 +1,5 @@ package org.jabref.gui.actions; -import java.util.List; -import java.util.Objects; - -import javax.swing.JOptionPane; - import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; @@ -21,6 +16,10 @@ import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; +import javax.swing.*; +import java.util.List; +import java.util.Objects; + public class CleanupAction extends AbstractWorker { private final BasePanel panel; @@ -46,7 +45,7 @@ public void init() { canceled = false; modifiedEntriesCount = 0; if (panel.getSelectedEntries().isEmpty()) { // None selected. Inform the user to select entries first. - JOptionPane.showMessageDialog(frame, Localization.lang("First select entries to clean up."), + JOptionPane.showMessageDialog(null, Localization.lang("First select entries to clean up."), Localization.lang("Cleanup entry"), JOptionPane.INFORMATION_MESSAGE); canceled = true; return; @@ -75,7 +74,7 @@ public void run() { CheckBoxMessage cbm = new CheckBoxMessage( Localization.lang("Auto-generating PDF-Names does not support undo. Continue?"), Localization.lang("Disable this confirmation dialog"), false); - int answer = JOptionPane.showConfirmDialog(frame, cbm, Localization.lang("Autogenerate PDF Names"), + int answer = JOptionPane.showConfirmDialog(null, cbm, Localization.lang("Autogenerate PDF Names"), JOptionPane.YES_NO_OPTION); if (cbm.isSelected()) { Globals.prefs.putBoolean(JabRefPreferences.ASK_AUTO_NAMING_PDFS_AGAIN, false); @@ -107,7 +106,7 @@ public void update() { return; } if (unsuccessfulRenames > 0) { //Rename failed for at least one entry - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("File rename failed for %0 entries.", Integer.toString(unsuccessfulRenames)), Localization.lang("Autogenerate PDF Names"), JOptionPane.INFORMATION_MESSAGE); } @@ -134,7 +133,7 @@ public void update() { private int showDialog(CleanupPresetPanel presetPanel) { String dialogTitle = Localization.lang("Cleanup entries"); Object[] messages = {Localization.lang("What would you like to clean up?"), presetPanel.getScrollPane()}; - return JOptionPane.showConfirmDialog(frame, messages, dialogTitle, JOptionPane.OK_CANCEL_OPTION, + return JOptionPane.showConfirmDialog(null, messages, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); } diff --git a/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java b/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java index be865ab02a7..37fff199723 100644 --- a/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java +++ b/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java @@ -1,28 +1,9 @@ package org.jabref.gui.actions; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.swing.Action; -import javax.swing.JButton; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JDialog; -import javax.swing.JOptionPane; -import javax.swing.JPopupMenu; -import javax.swing.JProgressBar; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.RowFilter; -import javax.swing.SwingWorker; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableColumnModel; -import javax.swing.table.TableModel; -import javax.swing.table.TableRowSorter; - +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.JabRefFrame; import org.jabref.gui.keyboard.KeyBinding; @@ -30,10 +11,16 @@ import org.jabref.logic.integrity.IntegrityMessage; import org.jabref.logic.l10n.Localization; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumnModel; +import javax.swing.table.TableModel; +import javax.swing.table.TableRowSorter; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class IntegrityCheckAction extends MnemonicAwareAction { @@ -56,9 +43,8 @@ public void actionPerformed(ActionEvent e) { Globals.journalAbbreviationLoader .getRepository(Globals.prefs.getJournalAbbreviationPreferences())); - final JDialog integrityDialog = new JDialog(frame, true); + final JDialog integrityDialog = new JDialog((JFrame) null, true); integrityDialog.setUndecorated(true); - integrityDialog.setLocationRelativeTo(frame); JProgressBar integrityProgressBar = new JProgressBar(); integrityProgressBar.setIndeterminate(true); integrityProgressBar.setStringPainted(true); @@ -87,7 +73,7 @@ protected void done() { } if (messages.isEmpty()) { - JOptionPane.showMessageDialog(frame.getCurrentBasePanel(), Localization.lang("No problems found.")); + JOptionPane.showMessageDialog(null, Localization.lang("No problems found.")); } else { Map showMessage = new HashMap<>(); // prepare data model @@ -147,7 +133,7 @@ public boolean include(Entry entry) { table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); JScrollPane scrollPane = new JScrollPane(table); String title = Localization.lang("%0 problem(s) found", String.valueOf(messages.size())); - JDialog dialog = new JDialog(frame, title, false); + JDialog dialog = new JDialog((JFrame) null, title, false); JPopupMenu menu = new JPopupMenu(); for (String messageString : showMessage.keySet()) { diff --git a/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java b/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java index 1e3304323c1..9f8c678d8e7 100644 --- a/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java +++ b/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java @@ -1,31 +1,8 @@ package org.jabref.gui.actions; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.util.Enumeration; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.DefaultListModel; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JList; -import javax.swing.JRadioButton; -import javax.swing.JScrollPane; -import javax.swing.JTextField; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; @@ -40,9 +17,17 @@ import org.jabref.model.entry.KeywordList; import org.jabref.model.strings.StringUtil; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.Enumeration; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; /** * An Action for launching keyword managing dialog @@ -76,7 +61,7 @@ private void createDialog() { keywordList.setVisibleRowCount(8); JScrollPane kPane = new JScrollPane(keywordList); - diag = new JDialog(frame, Localization.lang("Manage keywords"), true); + diag = new JDialog((JFrame) null, Localization.lang("Manage keywords"), true); JButton ok = new JButton(Localization.lang("OK")); JButton cancel = new JButton(Localization.lang("Cancel")); @@ -258,7 +243,6 @@ public void actionPerformed(ActionEvent e) { fillKeyWordList(); diag.pack(); - diag.setLocationRelativeTo(frame); diag.setVisible(true); if (canceled) { return; diff --git a/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java b/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java index 6743657960a..64dc0af9219 100644 --- a/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java +++ b/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java @@ -1,29 +1,8 @@ package org.jabref.gui.actions; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.util.Collection; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.Set; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JOptionPane; -import javax.swing.JRadioButton; -import javax.swing.JTextField; -import javax.swing.undo.UndoableEdit; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; @@ -33,9 +12,12 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import javax.swing.*; +import javax.swing.undo.UndoableEdit; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.util.*; +import java.util.List; /** * An Action for launching mass field. @@ -69,7 +51,7 @@ public MassSetFieldAction(JabRefFrame frame) { } private void createDialog() { - diag = new JDialog(frame, Localization.lang("Set/clear/append/rename fields"), true); + diag = new JDialog((JFrame) null, Localization.lang("Set/clear/append/rename fields"), true); field = new JComboBox<>(); field.setEditable(true); @@ -220,7 +202,6 @@ public void actionPerformed(ActionEvent e) { canceled = true; prepareDialog(!entries.isEmpty()); if (diag != null) { - diag.setLocationRelativeTo(frame); diag.setVisible(true); } if (canceled) { diff --git a/src/main/java/org/jabref/gui/actions/NewEntryAction.java b/src/main/java/org/jabref/gui/actions/NewEntryAction.java index b404dfea3af..d7a483178ad 100644 --- a/src/main/java/org/jabref/gui/actions/NewEntryAction.java +++ b/src/main/java/org/jabref/gui/actions/NewEntryAction.java @@ -1,12 +1,7 @@ package org.jabref.gui.actions; -import java.awt.event.ActionEvent; -import java.util.HashMap; -import java.util.Map; - -import javax.swing.Action; -import javax.swing.KeyStroke; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.EntryTypeDialog; import org.jabref.gui.IconTheme; @@ -16,8 +11,10 @@ import org.jabref.model.entry.EntryType; import org.jabref.model.strings.StringUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.util.HashMap; +import java.util.Map; public class NewEntryAction extends MnemonicAwareAction { private static final Log LOGGER = LogFactory.getLog(NewEntryAction.class); @@ -54,7 +51,6 @@ public void actionPerformed(ActionEvent e) { String thisType = type; if (thisType == null) { EntryTypeDialog etd = new EntryTypeDialog(jabRefFrame); - etd.setLocationRelativeTo(jabRefFrame); etd.setVisible(true); EntryType tp = etd.getChoice(); if (tp == null) { diff --git a/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java b/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java index 199f0400e4d..b04ac7f7fa1 100644 --- a/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java +++ b/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java @@ -1,9 +1,5 @@ package org.jabref.gui.actions; -import java.awt.event.ActionEvent; - -import javax.swing.Action; - import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.IconTheme; @@ -13,6 +9,9 @@ import org.jabref.model.Defaults; import org.jabref.model.database.BibDatabaseContext; +import javax.swing.*; +import java.awt.event.ActionEvent; + /** * The action concerned with generate a new (sub-)database from latex AUX file. */ @@ -33,7 +32,6 @@ public void actionPerformed(ActionEvent e) { FromAuxDialog dialog = new FromAuxDialog(jabRefFrame, "", true, jabRefFrame.getTabbedPane()); - dialog.setLocationRelativeTo(jabRefFrame); dialog.setVisible(true); if (dialog.generatePressed()) { diff --git a/src/main/java/org/jabref/gui/autosaveandbackup/BackupUIManager.java b/src/main/java/org/jabref/gui/autosaveandbackup/BackupUIManager.java index 3e0e3be4571..66d6a2be189 100644 --- a/src/main/java/org/jabref/gui/autosaveandbackup/BackupUIManager.java +++ b/src/main/java/org/jabref/gui/autosaveandbackup/BackupUIManager.java @@ -1,13 +1,11 @@ package org.jabref.gui.autosaveandbackup; -import java.nio.file.Path; - -import javax.swing.JFrame; -import javax.swing.JOptionPane; - import org.jabref.logic.autosaveandbackup.BackupManager; import org.jabref.logic.l10n.Localization; +import javax.swing.*; +import java.nio.file.Path; + /** * Stores all user dialogs related to {@link BackupManager}. */ @@ -17,7 +15,7 @@ private BackupUIManager() { } public static void showRestoreBackupDialog(JFrame frame, Path originalPath) { - int answer = JOptionPane.showConfirmDialog(frame, + int answer = JOptionPane.showConfirmDialog(null, new StringBuilder() .append(Localization.lang("A backup file for '%0' was found.", originalPath.getFileName().toString())) .append("\n") diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index 2de98920b40..cd5fe4849ca 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -1,31 +1,10 @@ package org.jabref.gui.auximport; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.nio.file.Path; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.DefaultFormBuilder; +import com.jgoodies.forms.layout.FormLayout; import org.jabref.Globals; -import org.jabref.gui.BasePanel; -import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.*; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.FileDialogConfiguration; @@ -36,9 +15,11 @@ import org.jabref.model.database.BibDatabase; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.DefaultFormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.nio.file.Path; +import java.util.Optional; /** * A wizard dialog for generating a new sub database from existing TeX AUX file @@ -67,7 +48,7 @@ public class FromAuxDialog extends JabRefDialog { private final JabRefFrame parentFrame; public FromAuxDialog(JabRefFrame frame, String title, boolean modal, JTabbedPane viewedDBs) { - super(frame, title, modal, FromAuxDialog.class); + super((JFrame) null, title, modal, FromAuxDialog.class); parentTabbedPane = viewedDBs; parentFrame = frame; diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java index 503f2368107..3aa00ec1e1c 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java @@ -1,18 +1,6 @@ package org.jabref.gui.bibtexkeypattern; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.WindowEvent; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JPanel; -import javax.swing.WindowConstants; - +import com.jgoodies.forms.builder.ButtonBarBuilder; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; @@ -22,7 +10,10 @@ import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import org.jabref.model.metadata.MetaData; -import com.jgoodies.forms.builder.ButtonBarBuilder; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.WindowEvent; public class BibtexKeyPatternDialog extends JabRefDialog { @@ -32,7 +23,7 @@ public class BibtexKeyPatternDialog extends JabRefDialog { public BibtexKeyPatternDialog(JabRefFrame parent, BasePanel panel) { - super(parent, Localization.lang("BibTeX key patterns"), true, BibtexKeyPatternDialog.class); + super((JFrame) null, Localization.lang("BibTeX key patterns"), true, BibtexKeyPatternDialog.class); this.bibtexKeyPatternPanel = new BibtexKeyPatternPanel(panel); setPanel(panel); init(); diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java b/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java index 4a7fa49fb79..d17471827e9 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java @@ -1,22 +1,8 @@ package org.jabref.gui.bibtexkeypattern; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JScrollPane; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.PreviewPanel; @@ -24,9 +10,11 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.List; /** * Dialog box for resolving duplicate bibte keys @@ -40,7 +28,7 @@ class ResolveDuplicateLabelDialog { public ResolveDuplicateLabelDialog(BasePanel panel, String key, List entries) { - diag = new JDialog(panel.frame(), Localization.lang("Duplicate BibTeX key"), true); + diag = new JDialog((JFrame) null, Localization.lang("Duplicate BibTeX key"), true); FormBuilder b = FormBuilder.create().layout(new FormLayout( "left:pref, 4dlu, fill:pref", "p")); diff --git a/src/main/java/org/jabref/gui/collab/ChangeScanner.java b/src/main/java/org/jabref/gui/collab/ChangeScanner.java index a35ca71bad0..b07f18607ba 100644 --- a/src/main/java/org/jabref/gui/collab/ChangeScanner.java +++ b/src/main/java/org/jabref/gui/collab/ChangeScanner.java @@ -1,16 +1,7 @@ package org.jabref.gui.collab; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; - -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; -import javax.swing.tree.DefaultMutableTreeNode; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; @@ -19,12 +10,7 @@ import org.jabref.logic.bibtex.comparator.BibDatabaseDiff; import org.jabref.logic.bibtex.comparator.BibEntryDiff; import org.jabref.logic.bibtex.comparator.BibStringDiff; -import org.jabref.logic.exporter.BibDatabaseWriter; -import org.jabref.logic.exporter.BibtexDatabaseWriter; -import org.jabref.logic.exporter.FileSaveSession; -import org.jabref.logic.exporter.SaveException; -import org.jabref.logic.exporter.SavePreferences; -import org.jabref.logic.exporter.SaveSession; +import org.jabref.logic.exporter.*; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.OpenDatabase; import org.jabref.logic.importer.ParserResult; @@ -34,8 +20,14 @@ import org.jabref.model.entry.BibtexString; import org.jabref.model.metadata.MetaData; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.tree.DefaultMutableTreeNode; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; public class ChangeScanner implements Runnable { private static final Log LOGGER = LogFactory.getLog(ChangeScanner.class); @@ -84,8 +76,7 @@ private static BibEntry bestFit(BibEntry targetEntry, List entries) { public void displayResult(final DisplayResultCallback fup) { if (changes.getChildCount() > 0) { SwingUtilities.invokeLater(() -> { - ChangeDisplayDialog changeDialog = new ChangeDisplayDialog(frame, panel, databaseInTemp.getDatabase(), changes); - changeDialog.setLocationRelativeTo(frame); + ChangeDisplayDialog changeDialog = new ChangeDisplayDialog(null, panel, databaseInTemp.getDatabase(), changes); changeDialog.setVisible(true); fup.scanResultsResolved(changeDialog.isOkPressed()); if (changeDialog.isOkPressed()) { @@ -95,7 +86,7 @@ public void displayResult(final DisplayResultCallback fup) { }); } else { - JOptionPane.showMessageDialog(frame, Localization.lang("No actual changes found."), + JOptionPane.showMessageDialog(null, Localization.lang("No actual changes found."), Localization.lang("External changes"), JOptionPane.INFORMATION_MESSAGE); fup.scanResultsResolved(true); } diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java index 2fb061ee6e9..f9bcbd3cdc8 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java @@ -1,33 +1,8 @@ package org.jabref.gui.contentselector; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.Window; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.DefaultListModel; -import javax.swing.JButton; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextField; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; import org.jabref.gui.JabRefFrame; @@ -40,9 +15,14 @@ import org.jabref.model.metadata.ContentSelectors; import org.jabref.model.metadata.MetaData; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.util.*; +import java.util.List; public class ContentSelectorDialog extends JabRefDialog { @@ -197,7 +177,7 @@ private void setupActions() { dispose(); } catch (Exception ex) { LOGGER.info("Could not apply changes in \"Manage content selectors\"", ex); - JOptionPane.showMessageDialog(frame, Localization.lang("Could not apply changes.")); + JOptionPane.showMessageDialog(null, Localization.lang("Could not apply changes.")); } }); @@ -210,7 +190,7 @@ private void setupActions() { applyChanges(); } catch (Exception ex) { LOGGER.info("Could not apply changes in \"Manage content selectors\"", ex); - JOptionPane.showMessageDialog(frame, Localization.lang("Could not apply changes.")); + JOptionPane.showMessageDialog(null, Localization.lang("Could not apply changes.")); } }); diff --git a/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java b/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java index ef63583e117..0418fef435d 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java +++ b/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java @@ -1,39 +1,6 @@ package org.jabref.gui.customentrytypes; -import java.awt.BorderLayout; -import java.awt.Container; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.ListSelectionModel; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.table.AbstractTableModel; - +import com.jgoodies.forms.builder.ButtonBarBuilder; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; @@ -48,7 +15,18 @@ import org.jabref.model.entry.InternalBibtexFields; import org.jabref.model.strings.StringUtil; -import com.jgoodies.forms.builder.ButtonBarBuilder; +import javax.swing.*; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.AbstractTableModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.*; +import java.util.List; +import java.util.stream.Collectors; public class EntryCustomizationDialog extends JabRefDialog implements ListSelectionListener { @@ -75,7 +53,7 @@ public class EntryCustomizationDialog extends JabRefDialog implements ListSelect * Creates a new instance of EntryCustomizationDialog */ public EntryCustomizationDialog(JabRefFrame frame) { - super(frame, Localization.lang("Customize entry types"), false, EntryCustomizationDialog.class); + super((JFrame) null, Localization.lang("Customize entry types"), false, EntryCustomizationDialog.class); this.frame = frame; initGui(); @@ -325,7 +303,7 @@ private void deleteType(String name) { if (type.isPresent() && (type.get() instanceof CustomEntryType)) { if (!EntryTypes.getStandardType(name, bibDatabaseMode).isPresent()) { int reply = JOptionPane.showConfirmDialog - (frame, Localization.lang("All entries of this " + (null, Localization.lang("All entries of this " + "type will be declared " + "typeless. Continue?"), Localization.lang("Delete custom format") + diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index 0d93ede3330..d905e867e57 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -1,29 +1,13 @@ package org.jabref.gui.desktop; -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.regex.Pattern; - -import javax.swing.JOptionPane; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefGUI; import org.jabref.gui.ClipBoardManager; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; -import org.jabref.gui.desktop.os.DefaultDesktop; -import org.jabref.gui.desktop.os.Linux; -import org.jabref.gui.desktop.os.NativeDesktop; -import org.jabref.gui.desktop.os.OSX; -import org.jabref.gui.desktop.os.Windows; +import org.jabref.gui.desktop.os.*; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypeEntryEditor; import org.jabref.gui.externalfiletype.ExternalFileTypes; @@ -42,8 +26,14 @@ import org.jabref.model.util.FileHelper; import org.jabref.preferences.JabRefPreferences; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; +import java.util.regex.Pattern; /** * TODO: Replace by http://docs.oracle.com/javase/7/docs/api/java/awt/Desktop.html @@ -184,7 +174,7 @@ public static boolean openExternalFileUnknown(JabRefFrame frame, BibEntry entry, String[] options = new String[] {Localization.lang("Define '%0'", fileType.getName()), Localization.lang("Change file type"), Localization.lang("Cancel")}; String defOption = options[0]; - int answer = JOptionPane.showOptionDialog(frame, + int answer = JOptionPane.showOptionDialog(null, Localization.lang("This external link is of the type '%0', which is undefined. What do you want to do?", fileType.getName()), Localization.lang("Undefined file type"), JOptionPane.YES_NO_CANCEL_OPTION, @@ -196,7 +186,7 @@ public static boolean openExternalFileUnknown(JabRefFrame frame, BibEntry entry, // User wants to define the new file type. Show the dialog: ExternalFileType newType = new ExternalFileType(fileType.getName(), "", "", "", "new", IconTheme.JabRefIcon.FILE.getSmallIcon()); - ExternalFileTypeEntryEditor editor = new ExternalFileTypeEntryEditor(frame, newType); + ExternalFileTypeEntryEditor editor = new ExternalFileTypeEntryEditor((JFrame) null, newType); editor.setVisible(true); if (editor.okPressed()) { // Get the old list of types, add this one, and update the list in prefs: @@ -292,7 +282,7 @@ public static void openBrowserShowPopup(String url) { String openManually = Localization.lang("Please open %0 manually.", url); String copiedToClipboard = Localization.lang("The link has been copied to the clipboard."); JabRefGUI.getMainFrame().output(couldNotOpenBrowser); - JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), couldNotOpenBrowser + "\n" + openManually + "\n" + + JOptionPane.showMessageDialog(null, couldNotOpenBrowser + "\n" + openManually + "\n" + copiedToClipboard, couldNotOpenBrowser, JOptionPane.ERROR_MESSAGE); } } @@ -334,7 +324,7 @@ public static void openConsole(File file) throws IOException { } catch (IOException exception) { LOGGER.error("Open console", exception); - JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), + JOptionPane.showMessageDialog(null, Localization.lang("Error_occured_while_executing_the_command_\"%0\".", commandLoggingText), Localization.lang("Open console") + " - " + Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index f9663dfec8d..a4c7a2ac87a 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -1,40 +1,6 @@ package org.jabref.gui.entryeditor; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Insets; -import java.awt.RenderingHints; -import java.awt.event.ActionEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JToolBar; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.undo.UndoableEdit; - +import com.google.common.eventbus.Subscribe; import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.embed.swing.JFXPanel; @@ -42,14 +8,11 @@ import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.input.KeyEvent; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.fxmisc.easybind.EasyBind; import org.jabref.Globals; -import org.jabref.gui.BasePanel; -import org.jabref.gui.EntryContainer; -import org.jabref.gui.GUIGlobals; -import org.jabref.gui.IconTheme; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.OSXCompatibleToolbar; +import org.jabref.gui.*; import org.jabref.gui.actions.Actions; import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.entryeditor.fileannotationtab.FileAnnotationTab; @@ -86,10 +49,16 @@ import org.jabref.model.entry.event.FieldAddedOrRemovedEvent; import org.jabref.preferences.JabRefPreferences; -import com.google.common.eventbus.Subscribe; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.fxmisc.easybind.EasyBind; +import javax.swing.*; +import javax.swing.undo.UndoableEdit; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.*; +import java.util.List; +import java.util.stream.Collectors; /** @@ -660,7 +629,7 @@ public void actionPerformed(ActionEvent event) { } else { textField.setInvalidBackgroundColor(); if (!SwingUtilities.isEventDispatchThread()) { - JOptionPane.showMessageDialog(frame, Localization.lang("Invalid BibTeX key"), + JOptionPane.showMessageDialog(null, Localization.lang("Invalid BibTeX key"), Localization.lang("Error setting field"), JOptionPane.ERROR_MESSAGE); requestFocus(); } @@ -750,7 +719,7 @@ public void actionPerformed(ActionEvent event) { } catch (InvalidFieldValueException ex) { fieldEditor.setInvalidBackgroundColor(); if (!SwingUtilities.isEventDispatchThread()) { - JOptionPane.showMessageDialog(frame, Localization.lang("Error") + ": " + ex.getMessage(), + JOptionPane.showMessageDialog(null, Localization.lang("Error") + ": " + ex.getMessage(), Localization.lang("Error setting field"), JOptionPane.ERROR_MESSAGE); LOGGER.debug("Error setting field", ex); requestFocus(); @@ -838,7 +807,7 @@ public void actionPerformed(ActionEvent e) { CheckBoxMessage cbm = new CheckBoxMessage( Localization.lang("The current BibTeX key will be overwritten. Continue?"), Localization.lang("Disable this confirmation dialog"), false); - int answer = JOptionPane.showConfirmDialog(frame, cbm, Localization.lang("Overwrite key"), + int answer = JOptionPane.showConfirmDialog(null, cbm, Localization.lang("Overwrite key"), JOptionPane.YES_NO_OPTION); if (cbm.isSelected()) { Globals.prefs.putBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY, false); diff --git a/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java b/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java index e0b367f4606..611dc14a148 100644 --- a/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java +++ b/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java @@ -1,24 +1,8 @@ package org.jabref.gui.exporter; -import java.awt.BorderLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.nio.file.Path; -import java.nio.file.Paths; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; @@ -31,9 +15,12 @@ import org.jabref.logic.util.FileExtensions; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.nio.file.Path; +import java.nio.file.Paths; /** * Dialog for creating or modifying custom exports. @@ -58,7 +45,7 @@ public CustomExportDialog(final JabRefFrame parent, final String exporterName, f } public CustomExportDialog(final JabRefFrame parent) { - super(parent, Localization.lang("Edit custom export"), true, CustomExportDialog.class); + super((JFrame) null, Localization.lang("Edit custom export"), true, CustomExportDialog.class); frame = parent; ActionListener okListener = e -> { Path layoutFileDir = Paths.get(layoutFile.getText()).getParent(); @@ -180,7 +167,6 @@ public void actionPerformed(ActionEvent e) { setSize(700, 200); - setLocationRelativeTo(parent); } public boolean okPressed() { diff --git a/src/main/java/org/jabref/gui/exporter/ExportAction.java b/src/main/java/org/jabref/gui/exporter/ExportAction.java index 306aff7d677..11bfc2e5961 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportAction.java +++ b/src/main/java/org/jabref/gui/exporter/ExportAction.java @@ -1,18 +1,7 @@ package org.jabref.gui.exporter; -import java.awt.event.ActionEvent; -import java.io.File; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JFileChooser; -import javax.swing.JOptionPane; -import javax.swing.filechooser.FileFilter; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.JabRefFrame; import org.jabref.gui.actions.MnemonicAwareAction; @@ -26,8 +15,14 @@ import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.filechooser.FileFilter; +import java.awt.event.ActionEvent; +import java.io.File; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; public class ExportAction { @@ -72,7 +67,7 @@ public void actionPerformed(ActionEvent e) { ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences); JFileChooser fc = ExportAction .createExportFileChooser(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY)); - fc.showSaveDialog(frame); + fc.showSaveDialog(null); File file = fc.getSelectedFile(); if (file == null) { return; @@ -88,7 +83,7 @@ public void actionPerformed(ActionEvent e) { file = new File(path); if (file.exists()) { // Warn that the file exists: - if (JOptionPane.showConfirmDialog(frame, + if (JOptionPane.showConfirmDialog(null, Localization.lang("'%0' exists. Overwrite file?", file.getName()), Localization.lang("Export"), JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) { return; @@ -149,7 +144,7 @@ public void update() { else { frame.output(Localization.lang("Could not save file.") + " - " + errorMessage); // Need to warn the user that saving failed! - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("Could not save file.") + "\n" + errorMessage, Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE); } diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java index 98f331f4bd6..fd58ba4b9be 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java @@ -1,26 +1,8 @@ package org.jabref.gui.exporter; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.ScrollPaneConstants; -import javax.swing.table.TableColumnModel; - +import ca.odell.glazedlists.gui.TableFormat; +import ca.odell.glazedlists.swing.DefaultEventTableModel; +import com.jgoodies.forms.builder.ButtonBarBuilder; import org.jabref.Globals; import org.jabref.gui.JabRefDialog; import org.jabref.gui.JabRefFrame; @@ -31,9 +13,13 @@ import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.LayoutFormatterPreferences; -import ca.odell.glazedlists.gui.TableFormat; -import ca.odell.glazedlists.swing.DefaultEventTableModel; -import com.jgoodies.forms.builder.ButtonBarBuilder; +import javax.swing.*; +import javax.swing.table.TableColumnModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** *

Title:

@@ -53,7 +39,7 @@ public class ExportCustomizationDialog extends JabRefDialog { public ExportCustomizationDialog(final JabRefFrame frame) { - super(frame, Localization.lang("Manage custom exports"), false, ExportCustomizationDialog.class); + super((JFrame) null, Localization.lang("Manage custom exports"), false, ExportCustomizationDialog.class); DefaultEventTableModel> tableModel = new DefaultEventTableModel<>( Globals.prefs.customExports.getSortedList(), new ExportTableFormat()); JTable table = new JTable(tableModel); @@ -156,7 +142,6 @@ public void actionPerformed(ActionEvent e) { getContentPane().add(main, BorderLayout.CENTER); getContentPane().add(buttons, BorderLayout.SOUTH); pack(); - setLocationRelativeTo(frame); table.requestFocus(); } diff --git a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java index aecdddb5e0f..43111194458 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java +++ b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java @@ -1,21 +1,7 @@ package org.jabref.gui.exporter; -import java.awt.Toolkit; -import java.awt.datatransfer.ClipboardOwner; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; - -import javax.swing.BorderFactory; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.ListSelectionModel; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; @@ -25,8 +11,17 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.awt.*; +import java.awt.datatransfer.ClipboardOwner; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; public class ExportToClipboardAction extends AbstractWorker { @@ -68,7 +63,7 @@ public void run() { list.setBorder(BorderFactory.createEtchedBorder()); list.setSelectionInterval(0, 0); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - int answer = JOptionPane.showOptionDialog(frame, list, Localization.lang("Select export format"), + int answer = JOptionPane.showOptionDialog(null, list, Localization.lang("Select export format"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] {Localization.lang("Export"), Localization.lang("Cancel")}, diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index 25007ea94a2..d7f0f211246 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -1,15 +1,9 @@ package org.jabref.gui.exporter; -import java.io.File; -import java.nio.charset.Charset; -import java.nio.charset.UnsupportedCharsetException; -import java.nio.file.Path; -import java.util.Optional; - -import javax.swing.JOptionPane; -import javax.swing.JTextArea; -import javax.swing.SwingUtilities; - +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; @@ -24,11 +18,7 @@ import org.jabref.gui.worker.AbstractWorker; import org.jabref.logic.autosaveandbackup.AutosaveManager; import org.jabref.logic.autosaveandbackup.BackupManager; -import org.jabref.logic.exporter.BibtexDatabaseWriter; -import org.jabref.logic.exporter.FileSaveSession; -import org.jabref.logic.exporter.SaveException; -import org.jabref.logic.exporter.SavePreferences; -import org.jabref.logic.exporter.SaveSession; +import org.jabref.logic.exporter.*; import org.jabref.logic.l10n.Encodings; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.FileExtensions; @@ -41,10 +31,12 @@ import org.jabref.shared.DBMSConnectionProperties; import org.jabref.shared.prefs.SharedDatabasePreferences; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.io.File; +import java.nio.charset.Charset; +import java.nio.charset.UnsupportedCharsetException; +import java.nio.file.Path; +import java.util.Optional; /** * Action for the "Save" and "Save as" operations called from BasePanel. This class is also used for @@ -192,7 +184,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) panel.registerUndoableChanges(session); } catch (UnsupportedCharsetException ex) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("Could not save file.") + Localization.lang("Character encoding '%0' is not supported.", encoding.displayName()), Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE); @@ -210,7 +202,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) LOGGER.error("A problem occured when trying to save the file", ex); } - JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + ".\n" + ex.getMessage(), + JOptionPane.showMessageDialog(null, Localization.lang("Could not save file.") + ".\n" + ex.getMessage(), Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE); // FIXME: rethrow anti-pattern throw new SaveException("rt"); @@ -231,13 +223,13 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) builder.add(ta).xy(3, 1); builder.add(Localization.lang("What do you want to do?")).xy(1, 3); String tryDiff = Localization.lang("Try different encoding"); - int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save library"), + int answer = JOptionPane.showOptionDialog(null, builder.getPanel(), Localization.lang("Save library"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] {Localization.lang("Save"), tryDiff, Localization.lang("Cancel")}, tryDiff); if (answer == JOptionPane.NO_OPTION) { // The user wants to use another encoding. - Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"), + Object choice = JOptionPane.showInputDialog(null, Localization.lang("Select encoding"), Localization.lang("Save library"), JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, encoding); if (choice == null) { @@ -403,7 +395,7 @@ private boolean checkExternalModification() { if (panel.isUpdatedExternally()) { String[] opts = new String[] {Localization.lang("Review changes"), Localization.lang("Save"), Localization.lang("Cancel")}; - int answer = JOptionPane.showOptionDialog(panel.frame(), + int answer = JOptionPane.showOptionDialog(null, Localization.lang("File has been updated externally. " + "What do you want to do?"), Localization.lang("File updated externally"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opts, opts[0]); @@ -441,7 +433,7 @@ private boolean checkExternalModification() { return true; } else { // User indicated to store anyway. if (panel.getBibDatabaseContext().getMetaData().isProtected()) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization .lang("Library is protected. Cannot save until external changes have been reviewed."), Localization.lang("Protected library"), JOptionPane.ERROR_MESSAGE); diff --git a/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java b/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java index 1fddc5f5820..c1385d590f5 100644 --- a/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java +++ b/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java @@ -1,16 +1,7 @@ package org.jabref.gui.externalfiles; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.nio.file.Paths; -import java.util.List; -import java.util.Optional; - -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.JabRefFrame; @@ -26,8 +17,14 @@ import org.jabref.model.entry.LinkedFile; import org.jabref.preferences.JabRefPreferences; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.Paths; +import java.util.List; +import java.util.Optional; /** * This class handles the download of an external file. Typically called when the user clicks @@ -131,7 +128,7 @@ public void download(final DownloadCallback callback) throws IOException { try { url = new URL(res); } catch (MalformedURLException ex1) { - JOptionPane.showMessageDialog(frame, Localization.lang("Invalid URL"), Localization.lang("Download file"), + JOptionPane.showMessageDialog(null, Localization.lang("Invalid URL"), Localization.lang("Download file"), JOptionPane.ERROR_MESSAGE); return; } @@ -160,7 +157,7 @@ public void download(URL url, final DownloadCallback callback) throws IOExceptio // TODO: stop editor dialog if this results in an error: mimeType = udl.getMimeType(); // Read MIME type } catch (IOException ex) { - JOptionPane.showMessageDialog(frame, Localization.lang("Invalid URL") + ": " + ex.getMessage(), + JOptionPane.showMessageDialog(null, Localization.lang("Invalid URL") + ": " + ex.getMessage(), Localization.lang("Download file"), JOptionPane.ERROR_MESSAGE); LOGGER.info("Error while downloading " + "'" + res + "'", ex); return; @@ -176,7 +173,7 @@ public void download(URL url, final DownloadCallback callback) throws IOExceptio if ((editor != null) && editor.isVisible()) { editor.setVisible(false, false); } - JOptionPane.showMessageDialog(frame, Localization.lang("Invalid URL") + ": " + e2.getMessage(), + JOptionPane.showMessageDialog(null, Localization.lang("Invalid URL") + ": " + e2.getMessage(), Localization.lang("Download file"), JOptionPane.ERROR_MESSAGE); LOGGER.info("Error while downloading " + "'" + urlF + "'", e2); return; @@ -220,12 +217,12 @@ public void download(URL url, final DownloadCallback callback) throws IOExceptio editor.setExternalConfirm(closeEntry -> { File f = directory == null ? new File(closeEntry.getLink()) : expandFilename(directory, closeEntry.getLink()); if (f.isDirectory()) { - JOptionPane.showMessageDialog(frame, Localization.lang("Target file cannot be a directory."), + JOptionPane.showMessageDialog(null, Localization.lang("Target file cannot be a directory."), Localization.lang("Download file"), JOptionPane.ERROR_MESSAGE); return false; } if (f.exists()) { - return JOptionPane.showConfirmDialog(frame, + return JOptionPane.showConfirmDialog(null, Localization.lang("'%0' exists. Overwrite file?", f.getName()), Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION; } else { diff --git a/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java b/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java index a68849e194b..9a1de21d4b5 100644 --- a/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java @@ -1,26 +1,9 @@ package org.jabref.gui.externalfiles; -import java.awt.BorderLayout; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.Optional; - -import javax.swing.BoxLayout; -import javax.swing.ButtonGroup; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; @@ -42,10 +25,17 @@ import org.jabref.model.util.FileHelper; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Optional; /** * This class holds the functionality of autolinking to a file that's dropped @@ -251,7 +241,7 @@ private boolean tryXmpImport(String fileName, ExternalFileType fileType, NamedCo contentPanel.add(confirmationMessage, BorderLayout.NORTH); contentPanel.add(entriesPanel, BorderLayout.CENTER); - int reply = JOptionPane.showConfirmDialog(frame, contentPanel, + int reply = JOptionPane.showConfirmDialog(null, contentPanel, Localization.lang("XMP-metadata found in PDF: %0", fileName), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); @@ -377,7 +367,7 @@ private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileTy try { Object[] messages = {Localization.lang("How would you like to link to '%0'?", linkFileName), optionsPanel}; - int reply = JOptionPane.showConfirmDialog(frame, messages, dialogTitle, JOptionPane.OK_CANCEL_OPTION, + int reply = JOptionPane.showConfirmDialog(null, messages, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (reply == JOptionPane.OK_OPTION) { // store user's choice @@ -475,7 +465,7 @@ private boolean doMove(String fileName, String destFilename, NamedCompound edits Path destFile = dir.get().resolve(destFilename); if (Files.exists(destFile)) { - int answer = JOptionPane.showConfirmDialog(frame, + int answer = JOptionPane.showConfirmDialog(null, Localization.lang("'%0' exists. Overwrite file?", destFile.toString()), Localization.lang("Overwrite file?"), JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.NO_OPTION) { @@ -494,7 +484,7 @@ private boolean doMove(String fileName, String destFilename, NamedCompound edits if (FileUtil.renameFile(fromFile, destFile, true)) { return true; } else { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("Could not move file '%0'.", destFile.toString()) + Localization.lang("Please move the file manually and link in place."), Localization.lang("Move file failed"), JOptionPane.ERROR_MESSAGE); @@ -539,7 +529,7 @@ private boolean doCopy(String fileName, String toFile, NamedCompound edits) { } if (Files.exists(destFile)) { - int answer = JOptionPane.showConfirmDialog(frame, + int answer = JOptionPane.showConfirmDialog(null, Localization.lang("'%0' exists. Overwrite file?", destFile.toString()), Localization.lang("File exists"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.NO_OPTION) { diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index aaf44053987..b19ee85d685 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -1,17 +1,7 @@ package org.jabref.gui.externalfiles; -import java.io.IOException; -import java.net.URL; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; - -import javax.swing.JOptionPane; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.undo.UndoableFieldChange; @@ -23,8 +13,16 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; /** * Try to download fulltext PDF for selected entry(ies) by following URL or DOI link. @@ -56,7 +54,7 @@ public void run() { if (basePanel.getSelectedEntries().size() >= WARNING_LIMIT) { String[] options = new String[] {Localization.lang("Look up full text documents"), Localization.lang("Cancel")}; - int answer = JOptionPane.showOptionDialog(basePanel.frame(), + int answer = JOptionPane.showOptionDialog(null, Localization.lang( "You are about to look up full text documents for %0 entries.", String.valueOf(basePanel.getSelectedEntries().size())) + "\n" @@ -86,7 +84,7 @@ public void update() { Optional dir = basePanel.getBibDatabaseContext().getFirstExistingFileDir(Globals.prefs.getFileDirectoryPreferences()); if (!dir.isPresent()) { - JOptionPane.showMessageDialog(basePanel.frame(), + JOptionPane.showMessageDialog(null, Localization.lang("Main file directory not set!") + " " + Localization.lang("Preferences") + " -> " + Localization.lang("File"), Localization.lang("Directory not found"), JOptionPane.ERROR_MESSAGE); @@ -118,7 +116,7 @@ public void update() { entry.getCiteKeyOptional().orElse(Localization.lang("undefined"))); basePanel.output(message); - JOptionPane.showMessageDialog(basePanel.frame(), message, title, JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE); } remove.add(result); } diff --git a/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java b/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java index 7f8a5011fa7..0ab07abbaf2 100644 --- a/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java +++ b/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java @@ -1,32 +1,8 @@ package org.jabref.gui.externalfiles; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JRadioButton; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; @@ -49,9 +25,13 @@ import org.jabref.model.entry.FieldName; import org.jabref.model.entry.LinkedFile; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; +import java.util.List; /** * This action goes through all selected entries in the BasePanel, and attempts to autoset the @@ -84,9 +64,8 @@ public void init() { // Ask about rules for the operation: if (optDiag == null) { - optDiag = new SynchronizeFileField.OptionsDialog(panel.frame(), panel.getBibDatabaseContext()); + optDiag = new SynchronizeFileField.OptionsDialog(null, panel.getBibDatabaseContext()); } - optDiag.setLocationRelativeTo(panel.frame()); optDiag.setVisible(true); if (optDiag.canceled()) { goOn = false; @@ -156,7 +135,7 @@ public void run() { if (removeAllBroken) { answer = 2; // We should delete this link. } else { - answer = JOptionPane.showOptionDialog(panel.frame(), + answer = JOptionPane.showOptionDialog(null, Localization.lang("Could not find file '%0'
linked from entry '%1'", flEntry.getLink(), aSel.getCiteKeyOptional().orElse(Localization.lang("undefined"))), @@ -198,7 +177,7 @@ public void run() { Localization.lang("Change file type"), Localization.lang("Cancel")}; String defOption = options[0]; - int answer = JOptionPane.showOptionDialog(panel.frame(), Localization.lang("One or more file links are of the type '%0', which is undefined. What do you want to do?", + int answer = JOptionPane.showOptionDialog(null, Localization.lang("One or more file links are of the type '%0', which is undefined. What do you want to do?", flEntry.getType().get().getName()), Localization.lang("Undefined file type"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, defOption @@ -209,7 +188,7 @@ public void run() { // User wants to define the new file type. Show the dialog: ExternalFileType newType = new ExternalFileType(flEntry.getType().get().getName(), "", "", "", "new", IconTheme.JabRefIcon.FILE.getSmallIcon()); - ExternalFileTypeEntryEditor editor = new ExternalFileTypeEntryEditor(panel.frame(), newType); + ExternalFileTypeEntryEditor editor = new ExternalFileTypeEntryEditor((JFrame) null, newType); editor.setVisible(true); if (editor.okPressed()) { // Get the old list of types, add this one, and update the list in prefs: diff --git a/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java b/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java index 9eb50acadbf..b0b5097a68b 100644 --- a/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java @@ -1,30 +1,6 @@ package org.jabref.gui.externalfiles; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingUtilities; - +import com.jgoodies.forms.builder.ButtonBarBuilder; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; @@ -35,7 +11,15 @@ import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; -import com.jgoodies.forms.builder.ButtonBarBuilder; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; /** * @@ -98,7 +82,7 @@ public void init() { errors = entriesChanged = skipped = 0; if (optDiag == null) { - optDiag = new OptionsDialog(panel.frame()); + optDiag = new OptionsDialog(null); } optDiag.open(); @@ -256,7 +240,6 @@ public void done() { public void open() { progressArea.setText(""); canceled = false; - optDiag.setLocationRelativeTo(panel.frame()); okButton.setEnabled(false); cancelButton.setEnabled(true); diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java index 0d5338391a6..43d0f357e5d 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java @@ -1,14 +1,7 @@ package org.jabref.gui.externalfiletype; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -import java.util.Optional; - -import javax.swing.Icon; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.gui.JabRefFrame; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.logic.l10n.Localization; @@ -16,8 +9,11 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.util.FileHelper; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.util.Optional; /** * The menu item used in the popup menu for opening external resources associated @@ -92,7 +88,7 @@ private boolean openLink() { if ((fileType.isPresent()) && (!fileType.get().getOpenWithApplication().isEmpty()) && ex.getMessage().contains(fileType.get().getOpenWithApplication())) { - JOptionPane.showMessageDialog(frame, Localization.lang("Unable to open link. " + JOptionPane.showMessageDialog(null, Localization.lang("Unable to open link. " + "The application '%0' associated with the file type '%1' could not be called.", fileType.get().getOpenWithApplication(), fileType.get().getName()), Localization.lang("Could not open link"), JOptionPane.ERROR_MESSAGE); diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java index ebfaa5c707d..d3dba2e9d28 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java @@ -1,34 +1,7 @@ package org.jabref.gui.externalfiletype; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableCellRenderer; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.ButtonStackBuilder; import org.jabref.Globals; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefDialog; @@ -37,8 +10,18 @@ import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.l10n.Localization; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.ButtonStackBuilder; +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableCellRenderer; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; /** * Editor for external file types. @@ -367,7 +350,7 @@ public void actionPerformed(ActionEvent e) { if (frame == null) { editor = new ExternalFileTypeEditor(dialog); } else { - editor = new ExternalFileTypeEditor(frame); + editor = new ExternalFileTypeEditor((JFrame) null); } } editor.setValues(); diff --git a/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java b/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java index 37beed94ae4..d3340caca84 100644 --- a/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java @@ -1,27 +1,6 @@ package org.jabref.gui.groups; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.util.List; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JScrollPane; -import javax.swing.JTree; -import javax.swing.SwingUtilities; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeSelectionModel; - +import com.jgoodies.forms.builder.ButtonBarBuilder; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.actions.BaseAction; @@ -30,7 +9,15 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.groups.GroupTreeNode; -import com.jgoodies.forms.builder.ButtonBarBuilder; +import javax.swing.*; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.util.List; +import java.util.Optional; public class GroupAddRemoveDialog implements BaseAction { @@ -55,7 +42,7 @@ public void action() throws Exception { selection = panel.getSelectedEntries(); - final JDialog diag = new JDialog(panel.frame(), + final JDialog diag = new JDialog((JFrame) null, (add ? (move ? Localization.lang("Move to group") : Localization.lang("Add to group")) : Localization .lang("Remove from group")), true); @@ -121,7 +108,6 @@ public void actionPerformed(ActionEvent e) { diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); diag.pack(); - diag.setLocationRelativeTo(panel.frame()); diag.setVisible(true); } diff --git a/src/main/java/org/jabref/gui/groups/GroupDialog.java b/src/main/java/org/jabref/gui/groups/GroupDialog.java index 369170a5375..fa160525a80 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialog.java @@ -1,37 +1,13 @@ package org.jabref.gui.groups; -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ItemListener; -import java.util.Optional; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JScrollPane; -import javax.swing.JTextField; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingConstants; -import javax.swing.event.CaretListener; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.DefaultFormBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; import javafx.scene.Node; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.text.TextFlow; - import org.jabref.Globals; import org.jabref.JabRefGUI; import org.jabref.gui.Dialog; @@ -45,22 +21,18 @@ import org.jabref.logic.search.SearchQuery; import org.jabref.model.entry.FieldName; import org.jabref.model.entry.Keyword; -import org.jabref.model.groups.AbstractGroup; -import org.jabref.model.groups.AutomaticKeywordGroup; -import org.jabref.model.groups.AutomaticPersonsGroup; -import org.jabref.model.groups.ExplicitGroup; -import org.jabref.model.groups.GroupHierarchyType; -import org.jabref.model.groups.GroupTreeNode; -import org.jabref.model.groups.RegexKeywordGroup; -import org.jabref.model.groups.SearchGroup; -import org.jabref.model.groups.WordKeywordGroup; +import org.jabref.model.groups.*; import org.jabref.model.strings.StringUtil; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.DefaultFormBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import javax.swing.*; +import javax.swing.event.CaretListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ItemListener; +import java.util.Optional; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; /** * Dialog for creating or modifying groups. Operates directly on the Vector @@ -138,7 +110,7 @@ public Dimension getPreferredSize() { * created. */ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) { - super(jabrefFrame, Localization.lang("Edit group"), true, GroupDialog.class); + super((JFrame) null, Localization.lang("Edit group"), true, GroupDialog.class); // set default values (overwritten if editedGroup != null) keywordGroupSearchField.setText(jabrefFrame.prefs().get(JabRefPreferences.GROUPS_DEFAULT_FIELD)); @@ -305,7 +277,6 @@ public Dimension getPreferredSize() { setResizable(false); updateComponents(); setLayoutForSelectedGroup(); - setLocationRelativeTo(jabrefFrame); // add listeners ItemListener radioButtonItemListener = e -> { diff --git a/src/main/java/org/jabref/gui/importer/FetcherPreviewDialog.java b/src/main/java/org/jabref/gui/importer/FetcherPreviewDialog.java index af21bfecb2d..aa85d58a02f 100644 --- a/src/main/java/org/jabref/gui/importer/FetcherPreviewDialog.java +++ b/src/main/java/org/jabref/gui/importer/FetcherPreviewDialog.java @@ -1,34 +1,5 @@ package org.jabref.gui.importer; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.util.LinkedHashMap; -import java.util.Map; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableModel; - -import org.jabref.Globals; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.logic.importer.OutputPrinter; -import org.jabref.logic.l10n.Localization; - import ca.odell.glazedlists.BasicEventList; import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.gui.TableFormat; @@ -37,6 +8,20 @@ import ca.odell.glazedlists.swing.GlazedListsSwing; import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.ButtonStackBuilder; +import org.jabref.Globals; +import org.jabref.gui.JabRefDialog; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.logic.importer.OutputPrinter; +import org.jabref.logic.l10n.Localization; + +import javax.swing.*; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.util.LinkedHashMap; +import java.util.Map; /** * @@ -51,7 +36,7 @@ public class FetcherPreviewDialog extends JabRefDialog implements OutputPrinter public FetcherPreviewDialog(JabRefFrame frame, int warningLimit, int tableRowHeight) { - super(frame, Localization.lang("Title"), true, FetcherPreviewDialog.class); + super((JFrame) null, Localization.lang("Title"), true, FetcherPreviewDialog.class); this.frame = frame; this.warningLimit = warningLimit; diff --git a/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java b/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java index 8d6658a85f5..352f86de081 100644 --- a/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java @@ -1,31 +1,8 @@ package org.jabref.gui.importer; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.EnumSet; -import java.util.Optional; -import java.util.zip.ZipFile; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.ScrollPaneConstants; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableColumnModel; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; @@ -41,9 +18,17 @@ import org.jabref.logic.util.FileExtensions; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumnModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.EnumSet; +import java.util.Optional; +import java.util.zip.ZipFile; /** * Dialog to manage custom importers. @@ -62,7 +47,7 @@ public class ImportCustomizationDialog extends JabRefDialog { private final JTable customImporterTable; public ImportCustomizationDialog(final JabRefFrame frame) { - super(frame, Localization.lang("Manage custom imports"), false, ImportCustomizationDialog.class); + super((JFrame) null, Localization.lang("Manage custom imports"), false, ImportCustomizationDialog.class); ImportTableModel tableModel = new ImportTableModel(); customImporterTable = new JTable(tableModel); @@ -103,9 +88,9 @@ public ImportCustomizationDialog(final JabRefFrame frame) { customImporterTable.revalidate(); customImporterTable.repaint(); } catch (Exception exc) { - JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0", chosenFileStr)); + JOptionPane.showMessageDialog(null, Localization.lang("Could not instantiate %0", chosenFileStr)); } catch (NoClassDefFoundError exc) { - JOptionPane.showMessageDialog(frame, Localization.lang( + JOptionPane.showMessageDialog(null, Localization.lang( "Could not instantiate %0. Have you chosen the correct package path?", chosenFileStr)); } @@ -134,12 +119,12 @@ public ImportCustomizationDialog(final JabRefFrame frame) { customImporterTable.repaint(10); } catch (IOException exc) { LOGGER.info("Could not open ZIP-archive.", exc); - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("Could not open %0", jarZipFile.get().toString()) + "\n" + Localization.lang("Have you chosen the correct package path?")); } catch (NoClassDefFoundError exc) { LOGGER.info("Could not instantiate ZIP-archive reader.", exc); - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("Could not instantiate %0", jarZipFile.get().toString()) + "\n" + Localization.lang("Have you chosen the correct package path?")); } @@ -153,10 +138,10 @@ public ImportCustomizationDialog(final JabRefFrame frame) { showDescButton.addActionListener(e -> { int row = customImporterTable.getSelectedRow(); if (row == -1) { - JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer.")); + JOptionPane.showMessageDialog(null, Localization.lang("Please select an importer.")); } else { CustomImporter importer = ((ImportTableModel) customImporterTable.getModel()).getImporter(row); - JOptionPane.showMessageDialog(frame, importer.getDescription()); + JOptionPane.showMessageDialog(null, importer.getDescription()); } }); @@ -164,7 +149,7 @@ public ImportCustomizationDialog(final JabRefFrame frame) { removeButton.addActionListener(e -> { int row = customImporterTable.getSelectedRow(); if (row == -1) { - JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer.")); + JOptionPane.showMessageDialog(null, Localization.lang("Please select an importer.")); } else { customImporterTable.removeRowSelectionInterval(row, row); Globals.prefs.customImports @@ -214,7 +199,6 @@ public void actionPerformed(ActionEvent e) { getContentPane().add(buttons, BorderLayout.SOUTH); this.setSize(getSize()); pack(); - this.setLocationRelativeTo(frame); customImporterTable.requestFocus(); } diff --git a/src/main/java/org/jabref/gui/importer/ImportFormats.java b/src/main/java/org/jabref/gui/importer/ImportFormats.java index d291fac7323..dce8f5aacc2 100644 --- a/src/main/java/org/jabref/gui/importer/ImportFormats.java +++ b/src/main/java/org/jabref/gui/importer/ImportFormats.java @@ -1,21 +1,8 @@ package org.jabref.gui.importer; -import java.awt.event.ActionEvent; -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.SortedSet; -import java.util.stream.Collectors; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JOptionPane; - import javafx.stage.FileChooser; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; @@ -29,8 +16,16 @@ import org.jabref.logic.util.FileExtensions; import org.jabref.preferences.JabRefPreferences; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.SortedSet; +import java.util.stream.Collectors; public class ImportFormats { @@ -92,7 +87,7 @@ public void actionPerformed(ActionEvent e) { selectedFile.ifPresent(file -> { try { if (!Files.exists(file)) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("File not found") + ": '" + file.getFileName() + "'.", Localization.lang("Import"), JOptionPane.ERROR_MESSAGE); return; diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index cdf00d5d921..e54cb46e33a 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -1,64 +1,24 @@ package org.jabref.gui.importer; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JProgressBar; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTable; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumnModel; -import javax.swing.table.TableModel; - +import ca.odell.glazedlists.BasicEventList; +import ca.odell.glazedlists.EventList; +import ca.odell.glazedlists.SortedList; +import ca.odell.glazedlists.event.ListEvent; +import ca.odell.glazedlists.event.ListEventListener; +import ca.odell.glazedlists.gui.AbstractTableComparatorChooser; +import ca.odell.glazedlists.gui.TableFormat; +import ca.odell.glazedlists.swing.DefaultEventSelectionModel; +import ca.odell.glazedlists.swing.DefaultEventTableModel; +import ca.odell.glazedlists.swing.GlazedListsSwing; +import ca.odell.glazedlists.swing.TableComparatorChooser; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.ButtonStackBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; -import org.jabref.gui.BasePanel; -import org.jabref.gui.DuplicateResolverDialog; +import org.jabref.gui.*; import org.jabref.gui.DuplicateResolverDialog.DuplicateResolverResult; -import org.jabref.gui.EntryMarker; -import org.jabref.gui.GUIGlobals; -import org.jabref.gui.IconTheme; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.PreviewPanel; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.externalfiles.AutoSetLinks; import org.jabref.gui.externalfiles.DownloadExternalFile; @@ -88,13 +48,7 @@ import org.jabref.model.FieldChange; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.entry.AuthorList; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.FieldProperty; -import org.jabref.model.entry.IdGenerator; -import org.jabref.model.entry.InternalBibtexFields; -import org.jabref.model.entry.LinkedFile; +import org.jabref.model.entry.*; import org.jabref.model.groups.AllEntriesGroup; import org.jabref.model.groups.GroupEntryChanger; import org.jabref.model.groups.GroupTreeNode; @@ -102,21 +56,15 @@ import org.jabref.model.strings.StringUtil; import org.jabref.preferences.JabRefPreferences; -import ca.odell.glazedlists.BasicEventList; -import ca.odell.glazedlists.EventList; -import ca.odell.glazedlists.SortedList; -import ca.odell.glazedlists.event.ListEvent; -import ca.odell.glazedlists.event.ListEventListener; -import ca.odell.glazedlists.gui.AbstractTableComparatorChooser; -import ca.odell.glazedlists.gui.TableFormat; -import ca.odell.glazedlists.swing.DefaultEventSelectionModel; -import ca.odell.glazedlists.swing.DefaultEventTableModel; -import ca.odell.glazedlists.swing.GlazedListsSwing; -import ca.odell.glazedlists.swing.TableComparatorChooser; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.ButtonStackBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumnModel; +import javax.swing.table.TableModel; +import java.awt.*; +import java.awt.event.*; +import java.io.IOException; +import java.util.*; +import java.util.List; /** * Dialog to allow the selection of entries as part of an Import. @@ -191,7 +139,7 @@ public class ImportInspectionDialog extends JabRefDialog implements ImportInspec * @param panel */ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoName, boolean newDatabase) { - super(frame, ImportInspectionDialog.class); + super(null, ImportInspectionDialog.class); this.frame = frame; this.panel = panel; this.bibDatabaseContext = (panel == null) ? null : panel.getBibDatabaseContext(); @@ -1237,7 +1185,7 @@ public void actionPerformed(ActionEvent actionEvent) { } entry = selectionModel.getSelected().get(0); if (!entry.getCiteKeyOptional().isPresent()) { - int answer = JOptionPane.showConfirmDialog(frame, + int answer = JOptionPane.showConfirmDialog(null, Localization.lang("This entry has no BibTeX key. Generate key now?"), Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.OK_OPTION) { @@ -1279,7 +1227,7 @@ public void actionPerformed(ActionEvent actionEvent) { } final BibEntry entry = selectionModel.getSelected().get(0); if (!entry.hasCiteKey()) { - int answer = JOptionPane.showConfirmDialog(frame, + int answer = JOptionPane.showConfirmDialog(null, Localization.lang("This entry has no BibTeX key. Generate key now?"), Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.OK_OPTION) { diff --git a/src/main/java/org/jabref/gui/importer/ImportMenuItem.java b/src/main/java/org/jabref/gui/importer/ImportMenuItem.java index d85d1cb5136..8fb69e3eac2 100644 --- a/src/main/java/org/jabref/gui/importer/ImportMenuItem.java +++ b/src/main/java/org/jabref/gui/importer/ImportMenuItem.java @@ -1,24 +1,7 @@ package org.jabref.gui.importer; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; - import org.jabref.Globals; -import org.jabref.gui.BasePanel; -import org.jabref.gui.DialogService; -import org.jabref.gui.EntryMarker; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.*; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.FileDialogConfiguration; @@ -35,6 +18,17 @@ import org.jabref.model.entry.BibtexString; import org.jabref.preferences.JabRefPreferences; +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + /* * TODO: could separate the "menu item" functionality from the importing functionality */ @@ -163,12 +157,12 @@ public void update() { } else { // Import in a specific format was specified. Check if we have stored error information: if (importError == null) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization .lang("No entries found. Please make sure you are using the correct import filter."), Localization.lang("Import failed"), JOptionPane.ERROR_MESSAGE); } else { - JOptionPane.showMessageDialog(frame, importError.getMessage(), + JOptionPane.showMessageDialog(null, importError.getMessage(), Localization.lang("Import failed"), JOptionPane.ERROR_MESSAGE); } } @@ -184,7 +178,6 @@ public void update() { openInNew); diag.addEntries(bibtexResult.getDatabase().getEntries()); diag.entryListComplete(); - diag.setLocationRelativeTo(frame); diag.setVisible(true); diag.toFront(); } diff --git a/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java b/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java index 90f489d7550..a952cd7678f 100644 --- a/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java +++ b/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java @@ -1,17 +1,14 @@ package org.jabref.gui.importer; -import java.awt.Dimension; -import java.util.List; -import java.util.Objects; - -import javax.swing.JOptionPane; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; - import org.jabref.gui.JabRefFrame; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.l10n.Localization; +import javax.swing.*; +import java.awt.*; +import java.util.List; +import java.util.Objects; + /** * Class for generating a dialog showing warnings from ParserResult * @@ -82,6 +79,6 @@ public Dimension getPreferredSize() { }; // Show dialog - JOptionPane.showMessageDialog(jabRefFrame, scrollPane, dialogTitle, JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(null, scrollPane, dialogTitle, JOptionPane.WARNING_MESSAGE); } } diff --git a/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java b/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java index a2506ac13a7..274952bc106 100644 --- a/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java @@ -1,19 +1,5 @@ package org.jabref.gui.importer.actions; -import java.awt.Font; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import javax.swing.BoxLayout; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; - import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.customentrytypes.CustomEntryTypesManager; @@ -24,6 +10,12 @@ import org.jabref.model.entry.CustomEntryType; import org.jabref.model.entry.EntryType; +import javax.swing.*; +import java.awt.*; +import java.util.*; +import java.util.List; +import java.util.stream.Collectors; + /** * This action checks whether any new custom entry types were loaded from this * BIB file. If so, an offer to remember these entry types is given. @@ -77,7 +69,7 @@ private List determineEntryTypesToSave(BasePanel panel, List { pFetcher.getEntries(dialog.getSelection(), d2); @@ -209,7 +196,6 @@ public void actionPerformed(ActionEvent e) { final ImportInspectionDialog dialog = new ImportInspectionDialog(frame, frame.getCurrentBasePanel(), activeFetcher.getTitle(), false); dialog.addCallBack(activeFetcher); - dialog.setLocationRelativeTo(frame); dialog.setVisible(true); JabRefExecutorService.INSTANCE.execute(() -> { diff --git a/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java b/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java index 92ef7416eff..7d661002a2c 100644 --- a/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java +++ b/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java @@ -1,21 +1,18 @@ package org.jabref.gui.menus; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; - import org.jabref.JabRefExecutorService; import org.jabref.gui.JabRefFrame; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.io.FileHistory; import org.jabref.preferences.JabRefPreferences; +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + public class FileHistoryMenu extends JMenu implements ActionListener { private final FileHistory history; @@ -87,7 +84,7 @@ public void actionPerformed(ActionEvent e) { // the existence check has to be done here (and not in open.openIt) as we have to call "removeItem" if the file does not exist if (!Files.exists(fileToOpen)) { - JOptionPane.showMessageDialog(frame, Localization.lang("File not found") + ": " + fileToOpen.getFileName(), + JOptionPane.showMessageDialog(null, Localization.lang("File not found") + ": " + fileToOpen.getFileName(), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); history.removeItem(name); setItems(); diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java index 3ecc385a7dd..a49c2858ebe 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java @@ -1,11 +1,10 @@ package org.jabref.gui.mergeentries; -import java.util.List; - -import javax.swing.JButton; -import javax.swing.JOptionPane; -import javax.swing.JSeparator; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.layout.CellConstraints; +import com.jgoodies.forms.layout.ColumnSpec; +import com.jgoodies.forms.layout.FormLayout; +import com.jgoodies.forms.layout.RowSpec; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; import org.jabref.gui.undo.NamedCompound; @@ -16,11 +15,8 @@ import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.layout.CellConstraints; -import com.jgoodies.forms.layout.ColumnSpec; -import com.jgoodies.forms.layout.FormLayout; -import com.jgoodies.forms.layout.RowSpec; +import javax.swing.*; +import java.util.List; /** * @author Oscar @@ -36,7 +32,7 @@ public class MergeEntriesDialog extends JabRefDialog { private final CellConstraints cc = new CellConstraints(); public MergeEntriesDialog(BasePanel panel) { - super(panel.frame(), MERGE_ENTRIES, true, MergeEntriesDialog.class); + super((JFrame) null, MERGE_ENTRIES, true, MergeEntriesDialog.class); this.panel = panel; @@ -53,7 +49,7 @@ private void init(List selected) { // Check if there are two entries selected if (selected.size() != 2) { // None selected. Inform the user to select entries first. - JOptionPane.showMessageDialog(panel.frame(), + JOptionPane.showMessageDialog(null, Localization.lang("You have to choose exactly two entries to merge."), MERGE_ENTRIES, JOptionPane.INFORMATION_MESSAGE); this.dispose(); diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeFetchedEntryDialog.java b/src/main/java/org/jabref/gui/mergeentries/MergeFetchedEntryDialog.java index abf8ff23ac9..ac4cbc478fc 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeFetchedEntryDialog.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeFetchedEntryDialog.java @@ -1,15 +1,10 @@ package org.jabref.gui.mergeentries; -import java.awt.event.ActionEvent; -import java.util.Optional; -import java.util.Set; -import java.util.TreeSet; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JButton; -import javax.swing.JSeparator; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.layout.CellConstraints; +import com.jgoodies.forms.layout.ColumnSpec; +import com.jgoodies.forms.layout.FormLayout; +import com.jgoodies.forms.layout.RowSpec; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; import org.jabref.gui.undo.NamedCompound; @@ -21,11 +16,11 @@ import org.jabref.model.entry.InternalBibtexFields; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.layout.CellConstraints; -import com.jgoodies.forms.layout.ColumnSpec; -import com.jgoodies.forms.layout.FormLayout; -import com.jgoodies.forms.layout.RowSpec; +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.util.Optional; +import java.util.Set; +import java.util.TreeSet; /** * Dialog for merging Bibtex entry with fetched data @@ -43,7 +38,7 @@ public class MergeFetchedEntryDialog extends JabRefDialog { public MergeFetchedEntryDialog(BasePanel panel, BibEntry originalEntry, BibEntry fetchedEntry, String type) { - super(panel.frame(), Localization.lang("Merge entry with %0 information", type), true, MergeFetchedEntryDialog.class); + super((JFrame) null, Localization.lang("Merge entry with %0 information", type), true, MergeFetchedEntryDialog.class); this.panel = panel; this.originalEntry = originalEntry; diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java b/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java index 20aabd93421..d5c9e531951 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java @@ -1,13 +1,13 @@ package org.jabref.gui.mergeentries; -import javax.swing.JOptionPane; - import org.jabref.gui.BasePanel; import org.jabref.gui.actions.BaseAction; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; +import javax.swing.*; + public class MergeWithFetchedEntryAction implements BaseAction { private final BasePanel basePanel; @@ -22,7 +22,7 @@ public void action() { BibEntry originalEntry = basePanel.getMainTable().getSelectedEntries().get(0); new FetchAndMergeEntry(originalEntry, basePanel, FetchAndMergeEntry.SUPPORTED_FIELDS); } else { - JOptionPane.showMessageDialog(basePanel.frame(), + JOptionPane.showMessageDialog(null, Localization.lang("This operation requires exactly one item to be selected."), Localization.lang("Merge entry with %0 information", FieldName.orFields(FieldName.getDisplayName(FieldName.DOI), diff --git a/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java b/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java index de51d511030..228cc82f861 100644 --- a/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java +++ b/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java @@ -1,26 +1,17 @@ package org.jabref.gui.openoffice; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JRadioButton; -import javax.swing.JTextField; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; import org.jabref.Globals; import org.jabref.gui.JabRefFrame; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.l10n.Localization; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** * Dialog for adding citation with page number info. @@ -34,7 +25,7 @@ class AdvancedCiteDialog { public AdvancedCiteDialog(JabRefFrame parent) { - diag = new JDialog(parent, Localization.lang("Cite special"), true); + diag = new JDialog((JFrame) null, Localization.lang("Cite special"), true); ButtonGroup bg = new ButtonGroup(); JRadioButton inPar = new JRadioButton(Localization.lang("Cite selected entries between parenthesis")); JRadioButton inText = new JRadioButton(Localization.lang("Cite selected entries with in-text citation")); diff --git a/src/main/java/org/jabref/gui/openoffice/CitationManager.java b/src/main/java/org/jabref/gui/openoffice/CitationManager.java index 47a90885688..7de7abb83bb 100644 --- a/src/main/java/org/jabref/gui/openoffice/CitationManager.java +++ b/src/main/java/org/jabref/gui/openoffice/CitationManager.java @@ -1,30 +1,5 @@ package org.jabref.gui.openoffice; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.List; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JOptionPane; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextField; - -import org.jabref.Globals; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.openoffice.CitationEntry; - import ca.odell.glazedlists.BasicEventList; import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.gui.TableFormat; @@ -42,6 +17,19 @@ import com.sun.star.lang.WrappedTargetException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jabref.Globals; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.openoffice.CitationEntry; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.List; +import java.util.Optional; /** * Dialog for modifying existing citations. @@ -59,7 +47,7 @@ class CitationManager { public CitationManager(final JabRefFrame frame, OOBibBase ooBase) throws NoSuchElementException, WrappedTargetException, UnknownPropertyException { - diag = new JDialog(frame, Localization.lang("Manage citations"), true); + diag = new JDialog((JFrame) null, Localization.lang("Manage citations"), true); this.ooBase = ooBase; list = new BasicEventList<>(); @@ -94,7 +82,7 @@ public CitationManager(final JabRefFrame frame, OOBibBase ooBase) } catch (UnknownPropertyException | NotRemoveableException | PropertyExistException | IllegalTypeException | IllegalArgumentException ex) { LOGGER.warn("Problem modifying citation", ex); - JOptionPane.showMessageDialog(frame, Localization.lang("Problem modifying citation")); + JOptionPane.showMessageDialog(null, Localization.lang("Problem modifying citation")); } diag.dispose(); }); diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index 81e76f6f6f4..5a1f24f531d 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -1,45 +1,16 @@ package org.jabref.gui.openoffice; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ButtonGroup; -import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JTextField; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; +import com.sun.star.beans.*; +import com.sun.star.comp.helper.BootstrapException; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.lang.WrappedTargetException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; -import org.jabref.gui.BasePanel; -import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.IconTheme; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.SidePaneComponent; -import org.jabref.gui.SidePaneManager; +import org.jabref.gui.*; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.desktop.os.NativeDesktop; import org.jabref.gui.help.HelpAction; @@ -65,19 +36,21 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import com.sun.star.beans.IllegalTypeException; -import com.sun.star.beans.NotRemoveableException; -import com.sun.star.beans.PropertyExistException; -import com.sun.star.beans.PropertyVetoException; -import com.sun.star.beans.UnknownPropertyException; -import com.sun.star.comp.helper.BootstrapException; -import com.sun.star.container.NoSuchElementException; -import com.sun.star.lang.WrappedTargetException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; /** * This test panel can be opened by reflection from JabRef, passing the JabRefFrame as an @@ -154,7 +127,7 @@ private void initPanel() { + ooBase.getCurrentDocumentTitle().orElse("")); } catch (UnknownPropertyException | WrappedTargetException | IndexOutOfBoundsException | NoSuchElementException | NoDocumentException ex) { - JOptionPane.showMessageDialog(frame, ex.getMessage(), Localization.lang("Error"), + JOptionPane.showMessageDialog(null, ex.getMessage(), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); LOGGER.warn("Problem connecting", ex); } @@ -207,7 +180,7 @@ public void actionPerformed(ActionEvent e) { List unresolvedKeys = ooBase.refreshCiteMarkers(databases, style); ooBase.rebuildBibTextSection(databases, style); if (!unresolvedKeys.isEmpty()) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang( "Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", unresolvedKeys.get(0)), @@ -220,13 +193,13 @@ public void actionPerformed(ActionEvent e) { } catch (ConnectionLostException ex) { showConnectionLostErrorMessage(); } catch (IOException ex) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization .lang("You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE); LOGGER.warn("Problem with style file", ex); } catch (BibEntryNotFoundException ex) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang( "Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", ex.getBibtexKey()), @@ -324,7 +297,7 @@ private void exportEntries() { List unresolvedKeys = ooBase.refreshCiteMarkers(databases, style); BibDatabase newDatabase = ooBase.generateDatabase(databases); if (!unresolvedKeys.isEmpty()) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang( "Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", unresolvedKeys.get(0)), @@ -337,7 +310,7 @@ private void exportEntries() { this.frame.addTab(databaseContext, true); } catch (BibEntryNotFoundException ex) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang( "Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", ex.getBibtexKey()), @@ -414,12 +387,12 @@ private void connect(boolean autoDetect) { } catch (UnsatisfiedLinkError e) { LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", e); - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("Unable to connect. One possible reason is that JabRef " + "and OpenOffice/LibreOffice are not both running in either 32 bit mode or 64 bit mode.")); } catch (IOException e) { LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", e); - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("Could not connect to running OpenOffice/LibreOffice.") + "\n" + Localization.lang("Make sure you have installed OpenOffice/LibreOffice with Java support.") + "\n" + Localization.lang("If connecting manually, please verify program and library paths.") @@ -477,7 +450,7 @@ private static void addURL(List jarList) throws IOException { private void showManualConnectionDialog() { dialogOkPressed = false; - final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true); + final JDialog cDiag = new JDialog((JFrame) null, Localization.lang("Set connection parameters"), true); final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop(); final DialogService dirDialog = new FXDialogService(); @@ -560,13 +533,12 @@ private void showManualConnectionDialog() { // Finish and show dirDialog cDiag.pack(); - cDiag.setLocationRelativeTo(frame); cDiag.setVisible(true); } private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addPageInfo) { if (!ooBase.isConnectedToDocument()) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("Not connected to any Writer document. Please" + " make sure a document is open, and use the 'Select Writer document' button to connect to it."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); @@ -601,7 +573,7 @@ private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addP ooBase.insertEntry(entries, database, getBaseList(), style, inParenthesis, withText, pageInfo, preferences.syncWhenCiting()); } catch (FileNotFoundException ex) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization .lang("You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE); @@ -648,7 +620,7 @@ private boolean checkThatEntriesHaveKeys(List entries) { // Ask if keys should be generated String[] options = {Localization.lang("Generate keys"), Localization.lang("Cancel")}; - int answer = JOptionPane.showOptionDialog(this.frame, + int answer = JOptionPane.showOptionDialog(null, Localization.lang("Cannot cite entries without BibTeX keys. Generate keys now?"), Localization.lang("Cite"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null); @@ -682,7 +654,7 @@ private boolean checkThatEntriesHaveKeys(List entries) { } private void showConnectionLostErrorMessage() { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("Connection to OpenOffice/LibreOffice has been lost. " + "Please make sure OpenOffice/LibreOffice is running, and try to reconnect."), Localization.lang("Connection lost"), JOptionPane.ERROR_MESSAGE); @@ -691,7 +663,7 @@ private void showConnectionLostErrorMessage() { private void reportUndefinedParagraphFormat(UndefinedParagraphFormatException ex) { JOptionPane .showMessageDialog( - frame, "" + null, "" + Localization.lang( "Your style file specifies the paragraph format '%0', " + "which is undefined in your current OpenOffice/LibreOffice document.", @@ -706,7 +678,7 @@ private void reportUndefinedParagraphFormat(UndefinedParagraphFormatException ex private void reportUndefinedCharacterFormat(UndefinedCharacterFormatException ex) { JOptionPane .showMessageDialog( - frame, "" + null, "" + Localization.lang( "Your style file specifies the character format '%0', " + "which is undefined in your current OpenOffice/LibreOffice document.", diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java index 1114df09da3..da5badc28f4 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java @@ -1,44 +1,21 @@ package org.jabref.gui.openoffice; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Objects; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPopupMenu; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.KeyStroke; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.table.TableColumnModel; - +import ca.odell.glazedlists.BasicEventList; +import ca.odell.glazedlists.EventList; +import ca.odell.glazedlists.SortedList; +import ca.odell.glazedlists.event.ListEvent; +import ca.odell.glazedlists.event.ListEventListener; +import ca.odell.glazedlists.gui.TableFormat; +import ca.odell.glazedlists.swing.DefaultEventSelectionModel; +import ca.odell.glazedlists.swing.DefaultEventTableModel; +import ca.odell.glazedlists.swing.GlazedListsSwing; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; -import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.IconTheme; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.PreviewPanel; +import org.jabref.gui.*; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; @@ -57,20 +34,17 @@ import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; -import ca.odell.glazedlists.BasicEventList; -import ca.odell.glazedlists.EventList; -import ca.odell.glazedlists.SortedList; -import ca.odell.glazedlists.event.ListEvent; -import ca.odell.glazedlists.event.ListEventListener; -import ca.odell.glazedlists.gui.TableFormat; -import ca.odell.glazedlists.swing.DefaultEventSelectionModel; -import ca.odell.glazedlists.swing.DefaultEventTableModel; -import ca.odell.glazedlists.swing.GlazedListsSwing; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.table.TableColumnModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Objects; +import java.util.Optional; /** * This class produces a dialog box for choosing a style file. @@ -144,7 +118,7 @@ private void init() { updateStyles(); // Build dialog - diag = new JDialog(frame, Localization.lang("Select style"), true); + diag = new JDialog((JFrame) null, Localization.lang("Select style"), true); FormBuilder builder = FormBuilder.create(); builder.layout(new FormLayout("fill:pref:grow, 4dlu, left:pref, 4dlu, left:pref", diff --git a/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java b/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java index 6ce4035ede6..ff4650cd29a 100644 --- a/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java +++ b/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java @@ -1,72 +1,10 @@ package org.jabref.gui.plaintextimport; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.GridLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.DefaultListCellRenderer; -import javax.swing.Icon; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JRadioButton; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.JTextPane; -import javax.swing.JToolBar; -import javax.swing.ListSelectionModel; -import javax.swing.ScrollPaneConstants; -import javax.swing.border.TitledBorder; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.text.BadLocationException; -import javax.swing.text.EditorKit; -import javax.swing.text.Style; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyleContext; -import javax.swing.text.StyledDocument; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; -import org.jabref.gui.ClipBoardManager; -import org.jabref.gui.DialogService; -import org.jabref.gui.EntryMarker; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.IconTheme; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.OSXCompatibleToolbar; +import org.jabref.gui.*; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.util.DefaultTaskExecutor; @@ -81,16 +19,25 @@ import org.jabref.logic.util.OS; import org.jabref.logic.util.UpdateField; import org.jabref.model.EntryTypes; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.EntryType; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.FieldProperty; -import org.jabref.model.entry.InternalBibtexFields; +import org.jabref.model.entry.*; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.border.TitledBorder; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.text.*; +import java.awt.*; +import java.awt.event.*; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; /** * import from plain text => simple mark/copy/paste into bibtex entry @@ -138,7 +85,7 @@ public class TextInputDialog extends JabRefDialog { public TextInputDialog(JabRefFrame frame, BibEntry bibEntry) { - super(frame, true, TextInputDialog.class); + super(null, true, TextInputDialog.class); this.frame = Objects.requireNonNull(frame); diff --git a/src/main/java/org/jabref/gui/preftabs/ExternalTab.java b/src/main/java/org/jabref/gui/preftabs/ExternalTab.java index 0f32dba10af..c66bb714b28 100644 --- a/src/main/java/org/jabref/gui/preftabs/ExternalTab.java +++ b/src/main/java/org/jabref/gui/preftabs/ExternalTab.java @@ -1,21 +1,7 @@ package org.jabref.gui.preftabs; -import java.awt.BorderLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.GridLayout; -import java.awt.Insets; - -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JFileChooser; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JTextField; - +import com.jgoodies.forms.builder.DefaultFormBuilder; +import com.jgoodies.forms.layout.FormLayout; import org.jabref.Globals; import org.jabref.gui.JabRefFrame; import org.jabref.gui.externalfiletype.ExternalFileTypeEditor; @@ -25,8 +11,8 @@ import org.jabref.logic.util.OS; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.DefaultFormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import javax.swing.*; +import java.awt.*; class ExternalTab extends JPanel implements PrefsTab { private final JabRefPreferences prefs; @@ -203,7 +189,7 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere private void addSettingsButton(final PushToApplication pt, JPanel p) { JButton button = new JButton(Localization.lang("Settings for %0", pt.getApplicationName()), pt.getIcon()); - button.addActionListener(e -> PushToApplicationButton.showSettingsDialog(frame, pt, pt.getSettingsPanel())); + button.addActionListener(e -> PushToApplicationButton.showSettingsDialog(null, pt, pt.getSettingsPanel())); p.add(button); } diff --git a/src/main/java/org/jabref/gui/preftabs/FileTab.java b/src/main/java/org/jabref/gui/preftabs/FileTab.java index e54e3d0a837..0322b86158a 100644 --- a/src/main/java/org/jabref/gui/preftabs/FileTab.java +++ b/src/main/java/org/jabref/gui/preftabs/FileTab.java @@ -1,23 +1,7 @@ package org.jabref.gui.preftabs; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ItemListener; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JTextField; - +import com.jgoodies.forms.builder.DefaultFormBuilder; +import com.jgoodies.forms.layout.FormLayout; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; import org.jabref.gui.JabRefFrame; @@ -31,8 +15,12 @@ import org.jabref.model.metadata.FileDirectoryPreferences; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.DefaultFormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ItemListener; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; /** * Preferences tab for file options. These options were moved out from GeneralTab to @@ -271,7 +259,7 @@ public boolean validateSettings() { if (!valid) { String content = String.format("%s -> %s %n %n %s: %n %s", Localization.lang("File"), Localization.lang("Main file directory"), Localization.lang("Directory not found"), path); - JOptionPane.showMessageDialog(this.frame, content, Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, content, Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); } return valid; } diff --git a/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java b/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java index 156bbe872b1..dac9aa54ca3 100644 --- a/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java +++ b/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java @@ -1,33 +1,11 @@ package org.jabref.gui.preftabs; -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.prefs.BackingStoreException; - -import javax.swing.AbstractAction; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.ListSelectionModel; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefException; -import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.GUIGlobals; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.*; import org.jabref.gui.keyboard.KeyBinder; import org.jabref.gui.maintable.MainTable; import org.jabref.gui.util.DefaultTaskExecutor; @@ -42,9 +20,15 @@ import org.jabref.preferences.JabRefPreferencesFilter; import org.jabref.shared.prefs.SharedDatabasePreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.prefs.BackingStoreException; /** * Preferences dialog. Contains a TabbedPane, and tabs will be defined in @@ -69,7 +53,7 @@ public class PreferencesDialog extends JabRefDialog { private final JButton resetPreferences = new JButton(Localization.lang("Reset preferences")); public PreferencesDialog(JabRefFrame parent) { - super(parent, Localization.lang("JabRef preferences"), false, PreferencesDialog.class); + super((JFrame) null, Localization.lang("JabRef preferences"), false, PreferencesDialog.class); JabRefPreferences prefs = JabRefPreferences.getInstance(); frame = parent; @@ -188,7 +172,7 @@ public PreferencesDialog(JabRefFrame parent) { }); showPreferences.addActionListener( - e -> new PreferencesFilterDialog(new JabRefPreferencesFilter(prefs), frame).setVisible(true)); + e -> new PreferencesFilterDialog(new JabRefPreferencesFilter(prefs), null).setVisible(true)); resetPreferences.addActionListener(e -> { if (JOptionPane.showConfirmDialog(PreferencesDialog.this, Localization.lang("Are you sure you want to reset all settings to default values?"), diff --git a/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java b/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java index e0e59c9c609..66a6f11d80e 100644 --- a/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java +++ b/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java @@ -1,20 +1,8 @@ package org.jabref.gui.protectedterms; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.nio.file.Path; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JTextField; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; @@ -28,9 +16,11 @@ import org.jabref.logic.util.FileExtensions; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.nio.file.Path; +import java.util.Optional; public class NewProtectedTermsFileDialog extends JabRefDialog { @@ -49,11 +39,9 @@ public NewProtectedTermsFileDialog(JDialog parent, ProtectedTermsLoader loader) } public NewProtectedTermsFileDialog(JabRefFrame mainFrame, ProtectedTermsLoader loader) { - super(mainFrame, Localization.lang("New protected terms file"), true, NewProtectedTermsFileDialog.class); - parent = mainFrame; + super((JFrame) null, Localization.lang("New protected terms file"), true, NewProtectedTermsFileDialog.class); this.loader = loader; setupDialog(); - setLocationRelativeTo(mainFrame); } private void setupDialog() { diff --git a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java b/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java index 7ff7856fa6b..7e4d302eb72 100644 --- a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java +++ b/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java @@ -1,45 +1,12 @@ package org.jabref.gui.protectedterms; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Objects; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPopupMenu; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.KeyStroke; -import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableColumnModel; - +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; -import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.IconTheme; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.*; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; @@ -56,11 +23,20 @@ import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumnModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Objects; +import java.util.Optional; /** * This class produces a dialog box for managing term list files. @@ -122,7 +98,7 @@ private void init() { setupTable(); // Build dialog - diag = new JDialog(frame, Localization.lang("Manage protected terms files"), true); + diag = new JDialog((JFrame) null, Localization.lang("Manage protected terms files"), true); FormBuilder builder = FormBuilder.create(); builder.layout(new FormLayout("fill:pref:grow, 4dlu, left:pref, 4dlu, left:pref, 4dlu, left:pref", diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationAction.java b/src/main/java/org/jabref/gui/push/PushToApplicationAction.java index 1de5f759119..835061a3eb1 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplicationAction.java +++ b/src/main/java/org/jabref/gui/push/PushToApplicationAction.java @@ -1,20 +1,16 @@ package org.jabref.gui.push; -import java.awt.event.ActionEvent; -import java.util.List; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.util.List; +import java.util.Optional; + /** * An Action class representing the process of invoking a PushToApplication operation. */ @@ -45,7 +41,7 @@ public void actionPerformed(ActionEvent e) { // Check if any entries are selected: entries = panel.getSelectedEntries(); if (entries.isEmpty()) { - JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires one or more entries to be selected."), (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, Localization.lang("This operation requires one or more entries to be selected."), (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE); return; } @@ -53,7 +49,7 @@ public void actionPerformed(ActionEvent e) { if (operation.requiresBibtexKeys()) { for (BibEntry entry : entries) { if (!(entry.getCiteKeyOptional().isPresent()) || entry.getCiteKeyOptional().get().trim().isEmpty()) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization .lang("This operation requires all selected entries to have BibTeX keys defined."), (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE); diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationButton.java b/src/main/java/org/jabref/gui/push/PushToApplicationButton.java index 4bf755a0c68..2556d24b031 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplicationButton.java +++ b/src/main/java/org/jabref/gui/push/PushToApplicationButton.java @@ -1,31 +1,6 @@ package org.jabref.gui.push; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.Icon; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; - +import com.jgoodies.forms.builder.ButtonBarBuilder; import org.jabref.Globals; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; @@ -35,7 +10,15 @@ import org.jabref.logic.util.OS; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.ButtonBarBuilder; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Customized UI component for pushing to external applications. Has a selection popup menu to change the selected @@ -115,7 +98,7 @@ private void init() { settings.addActionListener(event -> { JPanel options = toApp.getSettingsPanel(); if (options != null) { - PushToApplicationButton.showSettingsDialog(frame, toApp, options); + PushToApplicationButton.showSettingsDialog(null, toApp, options); } }); diff --git a/src/main/java/org/jabref/gui/push/PushToEmacs.java b/src/main/java/org/jabref/gui/push/PushToEmacs.java index 7dacedf2a97..4339de0da51 100644 --- a/src/main/java/org/jabref/gui/push/PushToEmacs.java +++ b/src/main/java/org/jabref/gui/push/PushToEmacs.java @@ -1,14 +1,7 @@ package org.jabref.gui.push; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import javax.swing.Icon; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; @@ -20,8 +13,10 @@ import org.jabref.model.metadata.MetaData; import org.jabref.preferences.JabRefPreferences; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; public class PushToEmacs extends AbstractPushToApplication implements PushToApplication { @@ -129,13 +124,13 @@ public void pushEntries(BibDatabase database, List entries, String key @Override public void operationCompleted(BasePanel panel) { if (couldNotConnect) { - JOptionPane.showMessageDialog(panel.frame(), "" + + JOptionPane.showMessageDialog(null, "" + Localization.lang("Could not connect to a running gnuserv process. Make sure that " + "Emacs or XEmacs is running,
and that the server has been started " + "(by running the command 'server-start'/'gnuserv-start').") + "", Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); } else if (couldNotCall) { - JOptionPane.showMessageDialog(panel.frame(), + JOptionPane.showMessageDialog(null, Localization.lang("Could not run the gnuclient/emacsclient program. Make sure you have " + "the emacsclient/gnuclient program installed and available in the PATH."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); diff --git a/src/main/java/org/jabref/gui/push/PushToVim.java b/src/main/java/org/jabref/gui/push/PushToVim.java index 1077ec6dfa7..c261b2c0a82 100644 --- a/src/main/java/org/jabref/gui/push/PushToVim.java +++ b/src/main/java/org/jabref/gui/push/PushToVim.java @@ -1,14 +1,7 @@ package org.jabref.gui.push; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import javax.swing.Icon; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; @@ -19,8 +12,10 @@ import org.jabref.model.metadata.MetaData; import org.jabref.preferences.JabRefPreferences; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; public class PushToVim extends AbstractPushToApplication implements PushToApplication { @@ -113,7 +108,7 @@ public void pushEntries(BibDatabase database, List entries, String key public void operationCompleted(BasePanel panel) { if (couldNotConnect) { JOptionPane.showMessageDialog( - panel.frame(), + null, "" + Localization.lang("Could not connect to Vim server. Make sure that " + "Vim is running
with correct server name.") @@ -121,7 +116,7 @@ public void operationCompleted(BasePanel panel) { Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); } else if (couldNotCall) { JOptionPane.showMessageDialog( - panel.frame(), + null, Localization.lang("Could not run the 'vim' program."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); } else { diff --git a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java index 5d181cafd5a..13e9d258c1c 100644 --- a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java +++ b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java @@ -1,44 +1,11 @@ package org.jabref.gui.shared; -import java.awt.FlowLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.io.UnsupportedEncodingException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.security.GeneralSecurityException; -import java.sql.SQLException; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPasswordField; -import javax.swing.JTextField; -import javax.swing.KeyStroke; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefException; import org.jabref.JabRefGUI; -import org.jabref.gui.BasePanel; -import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.*; import org.jabref.gui.exporter.SaveDatabaseAction; import org.jabref.gui.help.HelpAction; import org.jabref.gui.util.DefaultTaskExecutor; @@ -57,8 +24,19 @@ import org.jabref.shared.prefs.SharedDatabasePreferences; import org.jabref.shared.security.Password; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.io.UnsupportedEncodingException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.GeneralSecurityException; +import java.sql.SQLException; +import java.util.List; +import java.util.Optional; +import java.util.Set; public class ConnectToSharedDatabaseDialog extends JabRefDialog { @@ -103,14 +81,13 @@ public class ConnectToSharedDatabaseDialog extends JabRefDialog { * @param frame the JabRef Frame */ public ConnectToSharedDatabaseDialog(JabRefFrame frame) { - super(frame, Localization.lang("Connect to shared database"), ConnectToSharedDatabaseDialog.class); + super((JFrame) null, Localization.lang("Connect to shared database"), ConnectToSharedDatabaseDialog.class); this.frame = frame; initLayout(); updateEnableState(); applyPreferences(); setupActions(); pack(); - setLocationRelativeTo(frame); } public void openSharedDatabase() { diff --git a/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java b/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java index 1080bc7559f..0f1c54422c7 100644 --- a/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java +++ b/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java @@ -1,18 +1,5 @@ package org.jabref.gui.shared; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.WindowConstants; -import javax.swing.border.EmptyBorder; - import org.jabref.gui.JabRefFrame; import org.jabref.gui.mergeentries.MergeEntries; import org.jabref.logic.l10n.Localization; @@ -20,6 +7,12 @@ import org.jabref.model.entry.BibEntry; import org.jabref.shared.DBMSSynchronizer; +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + public class MergeSharedEntryDialog { private final JabRefFrame jabRefFrame; @@ -36,7 +29,7 @@ public MergeSharedEntryDialog(JabRefFrame jabRefFrame, DBMSSynchronizer dbmsSync this.dbmsSynchronizer = dbmsSynchronizer; this.localBibEntry = localBibEntry; this.sharedBibEntry = sharedBibEntry; - this.mergeDialog = new JDialog(jabRefFrame, Localization.lang("Update refused"), true); + this.mergeDialog = new JDialog((JFrame) null, Localization.lang("Update refused"), true); this.mergeEntries = new MergeEntries(sharedBibEntry, localBibEntry, Localization.lang("Shared entry"), Localization.lang("Local entry"), bibDatabaseMode); } @@ -85,7 +78,6 @@ public void windowClosing(WindowEvent e) { } }); - mergeDialog.setLocationRelativeTo(jabRefFrame); mergeDialog.pack(); mergeDialog.setVisible(true); } diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java index 9851104cb7c..c96a77a33d3 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java @@ -1,12 +1,6 @@ package org.jabref.gui.shared; -import java.sql.SQLException; -import java.util.Objects; -import java.util.Optional; - -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - +import com.google.common.eventbus.Subscribe; import org.jabref.Globals; import org.jabref.JabRefGUI; import org.jabref.gui.BasePanel; @@ -29,7 +23,10 @@ import org.jabref.shared.exception.NotASharedDatabaseException; import org.jabref.shared.prefs.SharedDatabasePreferences; -import com.google.common.eventbus.Subscribe; +import javax.swing.*; +import java.sql.SQLException; +import java.util.Objects; +import java.util.Optional; public class SharedDatabaseUIManager { @@ -48,7 +45,7 @@ public void listen(ConnectionLostEvent connectionLostEvent) { String[] options = {Localization.lang("Reconnect"), Localization.lang("Work offline"), Localization.lang("Close library")}; - int answer = JOptionPane.showOptionDialog(jabRefFrame, + int answer = JOptionPane.showOptionDialog(null, Localization.lang("The connection to the server has been terminated.") + "\n\n", Localization.lang("Connection lost"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); @@ -85,7 +82,7 @@ public void listen(SharedEntryNotPresentEvent event) { panel.getUndoManager().addEdit(new UndoableRemoveEntry(panel.getDatabase(), event.getBibEntry(), panel)); if (Objects.nonNull(entryEditor) && (entryEditor.getEntry() == event.getBibEntry())) { - JOptionPane.showMessageDialog(jabRefFrame, + JOptionPane.showMessageDialog(null, Localization.lang("The BibEntry you currently work on has been deleted on the shared side.") + "\n" + Localization.lang("You can restore the entry using the \"Undo\" operation."), Localization.lang("Shared entry is no longer present"), JOptionPane.INFORMATION_MESSAGE); diff --git a/src/main/java/org/jabref/gui/worker/VersionWorker.java b/src/main/java/org/jabref/gui/worker/VersionWorker.java index c6b853215ff..7ad50559ad8 100644 --- a/src/main/java/org/jabref/gui/worker/VersionWorker.java +++ b/src/main/java/org/jabref/gui/worker/VersionWorker.java @@ -1,5 +1,13 @@ package org.jabref.gui.worker; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.help.NewVersionDialog; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.Version; + +import javax.swing.*; import java.io.IOException; import java.util.Collections; import java.util.List; @@ -7,17 +15,6 @@ import java.util.Optional; import java.util.concurrent.ExecutionException; -import javax.swing.JOptionPane; -import javax.swing.SwingWorker; - -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.help.NewVersionDialog; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.util.Version; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - /** * This worker checks if there is a new version of JabRef available. @@ -87,7 +84,7 @@ private void showConnectionError() { String couldNotConnect = Localization.lang("Could not connect to the update server."); String tryLater = Localization.lang("Please try again later and/or check your network connection."); if (manualExecution) { - JOptionPane.showMessageDialog(this.mainFrame, couldNotConnect + "\n" + tryLater, + JOptionPane.showMessageDialog(null, couldNotConnect + "\n" + tryLater, couldNotConnect, JOptionPane.ERROR_MESSAGE); } this.mainFrame.output(couldNotConnect + " " + tryLater); @@ -105,13 +102,13 @@ private void showUpdateInfo(List availableVersions) { if (!newerVersion.isPresent() || (newerVersion.get().equals(toBeIgnored) && !manualExecution)) { String upToDate = Localization.lang("JabRef is up-to-date."); if (manualExecution) { - JOptionPane.showMessageDialog(this.mainFrame, upToDate, upToDate, JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog(null, upToDate, upToDate, JOptionPane.INFORMATION_MESSAGE); } this.mainFrame.output(upToDate); } else { // notify the user about a newer version - new NewVersionDialog(this.mainFrame, installedVersion, newerVersion.get()); + new NewVersionDialog(null, installedVersion, newerVersion.get()); } } diff --git a/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java b/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java index 410deea49fe..ef9ab3ebb9a 100644 --- a/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java +++ b/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java @@ -1,14 +1,7 @@ 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 com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; @@ -29,8 +22,8 @@ import org.jabref.model.metadata.FileDirectoryPreferences; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import javax.swing.*; +import java.util.List; /** * This class defines the warning that can be offered when opening a pre-2.3 @@ -172,7 +165,7 @@ public void performAction(BasePanel panel, ParserResult parserResult) { message.add(formBuilder.build()); - int answer = JOptionPane.showConfirmDialog(panel.frame(), + 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); diff --git a/src/main/java/org/jabref/pdfimport/PdfImporter.java b/src/main/java/org/jabref/pdfimport/PdfImporter.java index 8995ea13b07..f70d27baa01 100644 --- a/src/main/java/org/jabref/pdfimport/PdfImporter.java +++ b/src/main/java/org/jabref/pdfimport/PdfImporter.java @@ -1,16 +1,7 @@ package org.jabref.pdfimport; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.Optional; - -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.BasePanelMode; @@ -37,8 +28,10 @@ import org.jabref.model.entry.FieldName; import org.jabref.preferences.JabRefPreferences; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; public class PdfImporter { @@ -112,7 +105,6 @@ private List importPdfFilesInternal(List fileNames) { if (!XMPUtil.hasMetadata(Paths.get(fileName), Globals.prefs.getXMPPreferences())) { importDialog.disableXMPChoice(); } - importDialog.setLocationRelativeTo(frame); importDialog.showDialog(); doNotShowAgain = importDialog.isDoNotShowAgain(); } @@ -233,8 +225,6 @@ private void doContentImport(String fileName, List res) { private Optional createNewEntry() { // Find out what type is desired EntryTypeDialog etd = new EntryTypeDialog(frame); - // We want to center the dialog, to make it look nicer. - etd.setLocationRelativeTo(frame); etd.setVisible(true); EntryType type = etd.getChoice(); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 6bbd42f0710..7311f6696ac 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -1,39 +1,7 @@ package org.jabref.preferences; -import java.awt.Color; -import java.awt.Font; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.StringReader; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.prefs.BackingStoreException; -import java.util.prefs.InvalidPreferencesFormatException; -import java.util.prefs.Preferences; -import java.util.stream.Collectors; - -import javax.swing.JTable; -import javax.swing.UIManager; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jabref.JabRefException; import org.jabref.JabRefMain; import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; @@ -80,8 +48,19 @@ import org.jabref.model.metadata.SaveOrderConfig; import org.jabref.model.strings.StringUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.awt.*; +import java.io.*; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.List; +import java.util.prefs.BackingStoreException; +import java.util.prefs.InvalidPreferencesFormatException; +import java.util.prefs.Preferences; +import java.util.stream.Collectors; public class JabRefPreferences implements PreferencesService { @@ -1040,6 +1019,10 @@ public void putInt(String key, int value) { prefs.putInt(key, value); } + public void putDouble(String key, double value) { + prefs.putDouble(key, value); + } + public void remove(String key) { prefs.remove(key); } diff --git a/src/main/java/osx/macadapter/MacAdapter.java b/src/main/java/osx/macadapter/MacAdapter.java index c99c782a310..9ab97bec96d 100644 --- a/src/main/java/osx/macadapter/MacAdapter.java +++ b/src/main/java/osx/macadapter/MacAdapter.java @@ -1,23 +1,14 @@ package osx.macadapter; -import java.io.File; -import java.util.List; - -import org.jabref.gui.JabRefFrame; - -import com.apple.eawt.AboutHandler; -import com.apple.eawt.AppEvent; +import com.apple.eawt.*; import com.apple.eawt.AppEvent.AboutEvent; import com.apple.eawt.AppEvent.OpenFilesEvent; import com.apple.eawt.AppEvent.PreferencesEvent; import com.apple.eawt.AppEvent.QuitEvent; -import com.apple.eawt.AppReOpenedListener; -import com.apple.eawt.Application; -import com.apple.eawt.FullScreenUtilities; -import com.apple.eawt.OpenFilesHandler; -import com.apple.eawt.PreferencesHandler; -import com.apple.eawt.QuitHandler; -import com.apple.eawt.QuitResponse; +import org.jabref.gui.JabRefFrame; + +import java.io.File; +import java.util.List; public class MacAdapter implements PreferencesHandler, AboutHandler, QuitHandler, OpenFilesHandler, AppReOpenedListener { @@ -30,7 +21,6 @@ public void registerMacEvents(JabRefFrame inputFrame) { Application.getApplication().setPreferencesHandler(this); Application.getApplication().setQuitHandler(this); Application.getApplication().addAppEventListener(this); - FullScreenUtilities.setWindowCanFullScreen(parentFrame, true); } @Override diff --git a/src/test/java/org/jabref/gui/AbstractUITest.java b/src/test/java/org/jabref/gui/AbstractUITest.java index 57574ff4095..790e170f178 100644 --- a/src/test/java/org/jabref/gui/AbstractUITest.java +++ b/src/test/java/org/jabref/gui/AbstractUITest.java @@ -1,15 +1,5 @@ package org.jabref.gui; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.jabref.JabRefMain; -import org.jabref.testutils.category.GUITest; - import org.assertj.swing.fixture.AbstractWindowFixture; import org.assertj.swing.fixture.FrameFixture; import org.assertj.swing.fixture.JFileChooserFixture; @@ -17,10 +7,18 @@ import org.assertj.swing.image.ScreenshotTaker; import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase; import org.assertj.swing.timing.Pause; +import org.jabref.JabRefMain; +import org.jabref.testutils.category.GUITest; import org.junit.Assert; import org.junit.experimental.categories.Category; -import static org.assertj.swing.finder.WindowFinder.findFrame; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + import static org.assertj.swing.launcher.ApplicationLauncher.application; @Category(GUITest.class) @@ -42,7 +40,7 @@ protected void onSetUp() { robot().settings().timeoutToFindSubMenu(1_000); robot().settings().delayBetweenEvents(SPEED_NORMAL); - mainFrame = findFrame(JabRefFrame.class).withTimeout(10_000).using(robot()); + //mainFrame = findFrame(null).withTimeout(10_000).using(robot()); robot().waitForIdle(); } diff --git a/src/test/java/org/jabref/testutils/TestUtils.java b/src/test/java/org/jabref/testutils/TestUtils.java index e0bf7b650b9..633f5d5e1c3 100644 --- a/src/test/java/org/jabref/testutils/TestUtils.java +++ b/src/test/java/org/jabref/testutils/TestUtils.java @@ -29,7 +29,6 @@ public static void initJabRef() { */ public static void closeJabRef() { if (JabRefGUI.getMainFrame() != null) { - JabRefGUI.getMainFrame().dispose(); } } From 2ebc4395559a69a7400a66e3a8e046b3a1666d7f Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 28 Dec 2017 16:14:12 +0100 Subject: [PATCH 002/827] Start converting --- src/main/java/org/jabref/gui/BasePanel.java | 65 ++++++------------- .../jabref/gui/entryeditor/EntryEditor.java | 3 +- .../jabref/preferences/JabRefPreferences.java | 14 +++- .../preferences/PreviewPreferences.java | 22 +++---- 4 files changed, 46 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 8cf926b0a4f..c77ce3c089b 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1,6 +1,5 @@ package org.jabref.gui; -import java.awt.BorderLayout; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.ClipboardOwner; @@ -29,11 +28,8 @@ import java.util.stream.Collectors; import javax.swing.AbstractAction; -import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JSplitPane; import javax.swing.JTextArea; import javax.swing.SwingUtilities; import javax.swing.undo.CannotRedoException; @@ -41,7 +37,10 @@ import javafx.application.Platform; import javafx.embed.swing.JFXPanel; +import javafx.geometry.Orientation; import javafx.scene.Scene; +import javafx.scene.control.SplitPane; +import javafx.scene.layout.StackPane; import org.jabref.Globals; import org.jabref.JabRefExecutorService; @@ -148,14 +147,12 @@ import com.jgoodies.forms.layout.FormLayout; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.fxmisc.easybind.EasyBind; -public class BasePanel extends JPanel implements ClipboardOwner { +public class BasePanel extends StackPane implements ClipboardOwner { private static final Log LOGGER = LogFactory.getLog(BasePanel.class); - // Divider size for BaseFrame split pane. 0 means non-resizable. - private static final int SPLIT_PANE_DIVIDER_SIZE = 4; - private final BibDatabaseContext bibDatabaseContext; private final MainTableDataModel tableModel; @@ -180,7 +177,7 @@ public class BasePanel extends JPanel implements ClipboardOwner { private BasePanelMode mode = BasePanelMode.SHOWING_NOTHING; private EntryEditor currentEditor; private MainTableSelectionListener selectionListener; - private JSplitPane splitPane; + private SplitPane splitPane; private boolean saving; // AutoCompleter used in the search bar @@ -1348,8 +1345,8 @@ public void keyPressed(KeyEvent e) { } public void setupMainPanel() { - splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); - splitPane.setDividerSize(SPLIT_PANE_DIVIDER_SIZE); + splitPane = new SplitPane(); + splitPane.setOrientation(Orientation.HORIZONTAL); adjustSplitter(); // restore last splitting state (before mainTable is created as creation affects the stored size of the entryEditors) // check whether a mainTable already existed and a floatSearch was active @@ -1357,26 +1354,17 @@ public void setupMainPanel() { createMainTable(); - splitPane.setTopComponent(mainTable.getPane()); - - // Remove borders - splitPane.setBorder(BorderFactory.createEmptyBorder()); - setBorder(BorderFactory.createEmptyBorder()); + splitPane.getItems().add(mainTable.getPane()); - // If an entry is currently being shown, make sure it stays shown, - // otherwise set the bottom component to null. + // If an entry is currently being shown, make sure it stays shown. if (mode == BasePanelMode.SHOWING_PREVIEW) { mode = BasePanelMode.SHOWING_NOTHING; highlightEntry(selectionListener.getPreview().getEntry()); } else if (mode == BasePanelMode.SHOWING_EDITOR) { mode = BasePanelMode.SHOWING_NOTHING; - } else { - splitPane.setBottomComponent(null); } - setLayout(new BorderLayout()); - removeAll(); - add(splitPane, BorderLayout.CENTER); + this.getChildren().setAll(splitPane); // Set up name autocompleter for search: instantiateSearchAutoCompleter(); @@ -1390,12 +1378,8 @@ public void setupMainPanel() { mainTable.showFloatSearch(); } - splitPane.revalidate(); - revalidate(); - repaint(); - // saves the divider position as soon as it changes - splitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, event -> saveDividerLocation()); + EasyBind.subscribe(splitPane.getDividers().get(0).positionProperty(), position -> saveDividerLocation(position)); } /** @@ -1446,16 +1430,14 @@ public void updateStringDialog() { public void adjustSplitter() { if (mode == BasePanelMode.SHOWING_PREVIEW) { - splitPane.setDividerLocation( - splitPane.getHeight() - Globals.prefs.getPreviewPreferences().getPreviewPanelHeight()); + splitPane.setDividerPositions(Globals.prefs.getPreviewPreferences().getPreviewPanelDividerPosition().doubleValue()); } else { - splitPane.setDividerLocation( - splitPane.getHeight() - Globals.prefs.getInt(JabRefPreferences.ENTRY_EDITOR_HEIGHT)); + splitPane.setDividerPositions(Globals.prefs.getDouble(JabRefPreferences.ENTRY_EDITOR_HEIGHT)); } } private boolean isShowingEditor() { - return (splitPane.getBottomComponent() != null) && (splitPane.getBottomComponent() instanceof EntryEditor); + return mode == BasePanelMode.SHOWING_EDITOR; } public void showEntry(final BibEntry bibEntry) { @@ -1516,16 +1498,12 @@ public EntryEditor getCurrentEditor() { * @param editor The entry editor to add. */ public void showEntryEditor(EntryEditor editor) { - if (mode == BasePanelMode.SHOWING_EDITOR) { - Globals.prefs.putInt(JabRefPreferences.ENTRY_EDITOR_HEIGHT, - splitPane.getHeight() - splitPane.getDividerLocation()); - } mode = BasePanelMode.SHOWING_EDITOR; if (currentEditor != null) { currentEditor.setMovingToDifferentEntry(); } currentEditor = editor; - splitPane.setBottomComponent(editor); + splitPane.getItems().set(1, editor); if (editor.getEntry() != getShowing()) { newEntryShowing(editor.getEntry()); } @@ -1790,20 +1768,17 @@ public void autoGenerateKeysBeforeSaving() { } /** - * 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. */ - public void saveDividerLocation() { + private void saveDividerLocation(Number position) { if (mode == BasePanelMode.SHOWING_PREVIEW) { - int previewPanelHeight = splitPane.getHeight() - splitPane.getDividerLocation(); PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences() .getBuilder() - .withPreviewPanelHeight(previewPanelHeight) + .withPreviewPanelDividerPosition(position) .build(); Globals.prefs.storePreviewPreferences(previewPreferences); } else if (mode == BasePanelMode.SHOWING_EDITOR) { - Globals.prefs.putInt(JabRefPreferences.ENTRY_EDITOR_HEIGHT, - splitPane.getHeight() - splitPane.getDividerLocation()); + Globals.prefs.putDouble(JabRefPreferences.ENTRY_EDITOR_HEIGHT, position.doubleValue()); } } diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 140abc77233..3d2215d3fcf 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -6,6 +6,7 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; +import java.awt.Panel; import java.awt.RenderingHints; import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; @@ -100,7 +101,7 @@ * events whenever a field of the entry changes, enabling the text fields to * update themselves if the change is made from somewhere else. */ -public class EntryEditor extends JPanel implements EntryContainer { +public class EntryEditor extends Panel implements EntryContainer { private static final Log LOGGER = LogFactory.getLog(EntryEditor.class); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 155f53cd4ee..6e31892613a 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -1015,6 +1015,10 @@ public int getInt(String key) { return prefs.getInt(key, getIntDefault(key)); } + public double getDouble(String key) { + return prefs.getDouble(key, getDoubleDefault(key)); + } + public int getIntDefault(String key) { if (key.equals(JabRefPreferences.MENU_FONT_SIZE)) { Integer menuFontSize = (Integer) defaults.get(key); @@ -1028,6 +1032,10 @@ public int getIntDefault(String key) { } } + private double getDoubleDefault(String key) { + return (double) defaults.get(key); + } + public void put(String key, String value) { prefs.put(key, value); } @@ -1040,6 +1048,10 @@ public void putInt(String key, int value) { prefs.putInt(key, value); } + public void putDouble(String key, double value) { + prefs.putDouble(key, value); + } + public void remove(String key) { prefs.remove(key); } @@ -1454,7 +1466,7 @@ public VersionPreferences getVersionPreferences() { public JabRefPreferences storePreviewPreferences(PreviewPreferences previewPreferences) { putInt(CYCLE_PREVIEW_POS, previewPreferences.getPreviewCyclePosition()); putStringList(CYCLE_PREVIEW, previewPreferences.getPreviewCycle()); - putInt(PREVIEW_PANEL_HEIGHT, previewPreferences.getPreviewPanelHeight()); + putDouble(PREVIEW_PANEL_HEIGHT, previewPreferences.getPreviewPanelDividerPosition().doubleValue()); put(PREVIEW_STYLE, previewPreferences.getPreviewStyle()); putBoolean(PREVIEW_ENABLED, previewPreferences.isPreviewPanelEnabled()); return this; diff --git a/src/main/java/org/jabref/preferences/PreviewPreferences.java b/src/main/java/org/jabref/preferences/PreviewPreferences.java index 2a03b5d4fea..a4099ca8e54 100644 --- a/src/main/java/org/jabref/preferences/PreviewPreferences.java +++ b/src/main/java/org/jabref/preferences/PreviewPreferences.java @@ -2,20 +2,20 @@ import java.util.List; + public class PreviewPreferences { private final List previewCycle; private final int previewCyclePosition; - private final int previewPanelHeight; + private final Number previewPanelDividerPosition; private final boolean previewPanelEnabled; private final String previewStyle; private final String previewStyleDefault; - - public PreviewPreferences(List previewCycle, int previeCyclePosition, int previewPanelHeight, boolean previewPanelEnabled, String previewStyle, String previewStyleDefault) { + public PreviewPreferences(List previewCycle, int previeCyclePosition, Number previewPanelDividerPosition, boolean previewPanelEnabled, String previewStyle, String previewStyleDefault) { this.previewCycle = previewCycle; this.previewCyclePosition = previeCyclePosition; - this.previewPanelHeight = previewPanelHeight; + this.previewPanelDividerPosition = previewPanelDividerPosition; this.previewPanelEnabled = previewPanelEnabled; this.previewStyle = previewStyle; this.previewStyleDefault = previewStyleDefault; @@ -29,8 +29,8 @@ public int getPreviewCyclePosition() { return previewCyclePosition; } - public int getPreviewPanelHeight() { - return previewPanelHeight; + public Number getPreviewPanelDividerPosition() { + return previewPanelDividerPosition; } public boolean isPreviewPanelEnabled() { @@ -52,7 +52,7 @@ public Builder getBuilder() { public static class Builder { private List previewCycle; private int previeCyclePosition; - private int previewPanelHeight; + private Number previewPanelDividerPosition; private boolean previewPanelEnabled; private String previewStyle; private final String previewStyleDefault; @@ -61,7 +61,7 @@ public static class Builder { public Builder(PreviewPreferences previewPreferences) { this.previewCycle = previewPreferences.getPreviewCycle(); this.previeCyclePosition = previewPreferences.getPreviewCyclePosition(); - this.previewPanelHeight = previewPreferences.getPreviewPanelHeight(); + this.previewPanelDividerPosition = previewPreferences.getPreviewPanelDividerPosition(); this.previewPanelEnabled = previewPreferences.isPreviewPanelEnabled(); this.previewStyle = previewPreferences.getPreviewStyle(); this.previewStyleDefault = previewPreferences.getPreviewStyleDefault(); @@ -81,8 +81,8 @@ public Builder withPreviewCyclePosition(int position) { return this; } - public Builder withPreviewPanelHeight(int previewPanelHeight) { - this.previewPanelHeight = previewPanelHeight; + public Builder withPreviewPanelDividerPosition(Number previewPanelDividerPosition) { + this.previewPanelDividerPosition = previewPanelDividerPosition; return this; } @@ -97,7 +97,7 @@ public Builder withPreviewStyle(String previewStyle) { } public PreviewPreferences build() { - return new PreviewPreferences(previewCycle, previeCyclePosition, previewPanelHeight, previewPanelEnabled, previewStyle, previewStyleDefault); + return new PreviewPreferences(previewCycle, previeCyclePosition, previewPanelDividerPosition, previewPanelEnabled, previewStyle, previewStyleDefault); } } From f70ea5df7281127f0d62bd7336a9e6151b1ae12c Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 29 Dec 2017 22:24:58 +0100 Subject: [PATCH 003/827] Refactor icons (less awt) --- .../java/org/jabref/gui/DragDropPane.java | 6 +- .../jabref/gui/FindUnlinkedFilesDialog.java | 2 +- src/main/java/org/jabref/gui/GUIGlobals.java | 18 ++--- src/main/java/org/jabref/gui/IconTheme.java | 75 ++++++++++++------ .../gui/InternalMaterialDesignIcon.java | 75 ++++++++++++++++++ src/main/java/org/jabref/gui/JabRefIcon.java | 15 ++++ .../java/org/jabref/gui/PreambleEditor.java | 4 +- .../java/org/jabref/gui/PreviewPanel.java | 4 +- .../org/jabref/gui/SidePaneComponent.java | 8 +- .../java/org/jabref/gui/StringDialog.java | 10 +-- .../gui/actions/AutoLinkFilesAction.java | 4 +- .../jabref/gui/actions/NewDatabaseAction.java | 2 +- .../jabref/gui/actions/NewEntryAction.java | 2 +- .../gui/actions/NewSubDatabaseAction.java | 2 +- .../BibtexKeyPatternPanel.java | 2 +- .../jabref/gui/collab/FileUpdatePanel.java | 2 +- .../customentrytypes/FieldSetComponent.java | 4 +- .../org/jabref/gui/desktop/JabRefDesktop.java | 3 +- .../ShowDocumentViewerAction.java | 2 +- .../gui/entryeditor/DeprecatedFieldsTab.java | 2 +- .../gui/entryeditor/OptionalFields2Tab.java | 2 +- .../gui/entryeditor/OptionalFieldsTab.java | 2 +- .../gui/entryeditor/OtherFieldsTab.java | 2 +- .../gui/entryeditor/RequiredFieldsTab.java | 2 +- .../org/jabref/gui/entryeditor/SourceTab.java | 2 +- .../gui/entryeditor/UserDefinedFieldsTab.java | 2 +- .../errorconsole/ErrorConsoleController.java | 2 +- .../gui/errorconsole/LogEventViewModel.java | 9 ++- .../jabref/gui/exporter/SaveAllAction.java | 2 +- .../externalfiletype/ExternalFileType.java | 15 ++-- .../ExternalFileTypeEntryEditor.java | 4 +- .../externalfiletype/ExternalFileTypes.java | 77 ++++++------------- .../UnknownExternalFileType.java | 2 +- .../jabref/gui/groups/GroupNodeViewModel.java | 17 ++-- .../org/jabref/gui/groups/GroupSidePane.java | 4 +- .../gui/groups/GroupTreeController.java | 2 +- .../gui/groups/GroupTreeNodeViewModel.java | 4 +- .../java/org/jabref/gui/help/HelpAction.java | 6 +- .../gui/importer/EntryFromPDFCreator.java | 2 +- .../gui/importer/ImportInspectionDialog.java | 12 +-- .../gui/importer/fetcher/GeneralFetcher.java | 4 +- .../ManageJournalAbbreviationsController.java | 12 +-- .../jabref/gui/keyboard/KeyBindingAction.java | 2 +- .../gui/keyboard/KeyBindingViewModel.java | 7 +- .../keyboard/KeyBindingsDialogController.java | 4 +- .../gui/openoffice/StyleSelectDialog.java | 4 +- .../gui/plaintextimport/TextInputDialog.java | 10 +-- .../jabref/gui/preftabs/NameFormatterTab.java | 4 +- .../org/jabref/gui/preftabs/XmpPrefsTab.java | 4 +- .../protectedterms/ProtectedTermsDialog.java | 6 +- .../gui/push/PushToApplicationButton.java | 2 +- .../jabref/gui/search/SearchResultFrame.java | 10 +-- .../jabref/gui/search/SearchTextField.java | 2 +- .../SpecialFieldValueViewModel.java | 35 +++++---- .../specialfields/SpecialFieldViewModel.java | 32 ++++++-- .../util/ViewModelTreeTableCellFactory.java | 14 +--- 56 files changed, 336 insertions(+), 228 deletions(-) create mode 100644 src/main/java/org/jabref/gui/InternalMaterialDesignIcon.java create mode 100644 src/main/java/org/jabref/gui/JabRefIcon.java diff --git a/src/main/java/org/jabref/gui/DragDropPane.java b/src/main/java/org/jabref/gui/DragDropPane.java index 4382b1cfea5..8b8a139015a 100644 --- a/src/main/java/org/jabref/gui/DragDropPane.java +++ b/src/main/java/org/jabref/gui/DragDropPane.java @@ -124,14 +124,14 @@ public void mouseReleased(MouseEvent e) { static class MarkerPane extends JPanel { private Point locationP; - private final IconTheme.JabRefIcon moveTabArrow; + private final JabRefIcon moveTabArrow; public MarkerPane() { setOpaque(false); // Sets the marker fontIcon - moveTabArrow = IconTheme.JabRefIcon.MOVE_TAB_ARROW; + moveTabArrow = IconTheme.JabRefIcons.MOVE_TAB_ARROW; } @Override @@ -141,7 +141,7 @@ public void paintComponent(Graphics g) { g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.9f)); // Set transparency g.setFont(IconTheme.FONT.deriveFont(Font.BOLD, 24f)); - g.drawString(moveTabArrow.getCode(), locationP.x - (moveTabArrow.getIcon().getIconWidth() / 2), + moveTabArrow.getSmallIcon().paintIcon(this, g, locationP.x - (moveTabArrow.getIcon().getIconWidth() / 2), locationP.y + (moveTabArrow.getIcon().getIconHeight() / 2)); } diff --git a/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java b/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java index fbf049a942d..3bc4e339797 100644 --- a/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java +++ b/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java @@ -987,7 +987,7 @@ public Component getListCellRendererComponent(JList list, Object value, int i if (value instanceof EntryFromFileCreator) { EntryFromFileCreator creator = (EntryFromFileCreator) value; if (creator.getExternalFileType() != null) { - label.setIcon(creator.getExternalFileType().getIcon()); + label.setIcon(creator.getExternalFileType().getIcon().getSmallIcon()); } } return label; diff --git a/src/main/java/org/jabref/gui/GUIGlobals.java b/src/main/java/org/jabref/gui/GUIGlobals.java index 61e3d4364ec..5d5c5dabfeb 100644 --- a/src/main/java/org/jabref/gui/GUIGlobals.java +++ b/src/main/java/org/jabref/gui/GUIGlobals.java @@ -76,40 +76,40 @@ public static void updateEntryEditorColors() { */ public static void init() { JLabel label; - label = new JLabel(IconTheme.JabRefIcon.PDF_FILE.getSmallIcon()); + label = new JLabel(IconTheme.JabRefIcons.PDF_FILE.getSmallIcon()); label.setToolTipText(Localization.lang("Open") + " PDF"); GUIGlobals.TABLE_ICONS.put(FieldName.PDF, label); - label = new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon()); + label = new JLabel(IconTheme.JabRefIcons.WWW.getSmallIcon()); label.setToolTipText(Localization.lang("Open") + " URL"); GUIGlobals.TABLE_ICONS.put(FieldName.URL, label); - label = new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon()); + label = new JLabel(IconTheme.JabRefIcons.WWW.getSmallIcon()); label.setToolTipText(Localization.lang("Open") + " CiteSeer URL"); GUIGlobals.TABLE_ICONS.put("citeseerurl", label); - label = new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon()); + label = new JLabel(IconTheme.JabRefIcons.WWW.getSmallIcon()); label.setToolTipText(Localization.lang("Open") + " ArXiv URL"); GUIGlobals.TABLE_ICONS.put(FieldName.EPRINT, label); - label = new JLabel(IconTheme.JabRefIcon.DOI.getSmallIcon()); + label = new JLabel(IconTheme.JabRefIcons.DOI.getSmallIcon()); label.setToolTipText(Localization.lang("Open") + " DOI " + Localization.lang("web link")); GUIGlobals.TABLE_ICONS.put(FieldName.DOI, label); - label = new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon()); + label = new JLabel(IconTheme.JabRefIcons.FILE.getSmallIcon()); label.setToolTipText(Localization.lang("Open") + " PS"); GUIGlobals.TABLE_ICONS.put(FieldName.PS, label); - label = new JLabel(IconTheme.JabRefIcon.FOLDER.getSmallIcon()); + label = new JLabel(IconTheme.JabRefIcons.FOLDER.getSmallIcon()); label.setToolTipText(Localization.lang("Open folder")); GUIGlobals.TABLE_ICONS.put(FieldName.FOLDER, label); - label = new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon()); + label = new JLabel(IconTheme.JabRefIcons.FILE.getSmallIcon()); label.setToolTipText(Localization.lang("Open file")); GUIGlobals.TABLE_ICONS.put(FieldName.FILE, label); for (ExternalFileType fileType : ExternalFileTypes.getInstance().getExternalFileTypeSelection()) { - label = new JLabel(fileType.getIcon()); + label = new JLabel(fileType.getIcon().getSmallIcon()); label.setToolTipText(Localization.lang("Open %0 file", fileType.getName())); GUIGlobals.TABLE_ICONS.put(fileType.getName(), label); } diff --git a/src/main/java/org/jabref/gui/IconTheme.java b/src/main/java/org/jabref/gui/IconTheme.java index 09488c333f6..da228780bd5 100644 --- a/src/main/java/org/jabref/gui/IconTheme.java +++ b/src/main/java/org/jabref/gui/IconTheme.java @@ -15,24 +15,23 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; import javax.swing.Icon; import javax.swing.ImageIcon; import javafx.scene.Node; import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import org.jabref.logic.groups.DefaultGroupsFactory; import org.jabref.preferences.JabRefPreferences; import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; -import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView; +import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -166,8 +165,8 @@ public static List getLogoSet() { return jabrefLogos; } - - public enum JabRefIcon { + + public enum JabRefIcons implements JabRefIcon { ADD(MaterialDesignIcon.PLUS_BOX), ADD_NOBOX(MaterialDesignIcon.PLUS), @@ -257,6 +256,7 @@ public enum JabRefIcon { FILE_POWERPOINT(MaterialDesignIcon.FILE_POWERPOINT), /*css: file-powerpoint */ FILE_TEXT(MaterialDesignIcon.FILE_DOCUMENT), /*css: file-document */ FILE_MULTIPLE(MaterialDesignIcon.FILE_MULTIPLE), /*css: file-multiple */ + FILE_OPENOFFICE(IconTheme.getImage("openoffice")), KEY_BINDINGS(MaterialDesignIcon.KEYBOARD), /*css: keyboard */ FIND_DUPLICATES(MaterialDesignIcon.CODE_EQUAL), /*css: code-equal */ PULL(MaterialDesignIcon.SOURCE_PULL), /*source-pull*/ @@ -274,42 +274,67 @@ public enum JabRefIcon { // STILL MISSING: GROUP_REGULAR(Color.RED, MaterialDesignIcon.SYNC); - private final List icons; - private final Color color; - private final String unicode; + private final JabRefIcon icon; - JabRefIcon(MaterialDesignIcon... icons) { + JabRefIcons(MaterialDesignIcon... icons) { this(IconTheme.DEFAULT_COLOR, icons); } - JabRefIcon(Color color, MaterialDesignIcon... icons) { - this.icons = Arrays.asList(icons); - this.color = color; - this.unicode = Arrays.stream(icons).map(MaterialDesignIcon::unicode).collect(Collectors.joining()); + JabRefIcons(Color color, MaterialDesignIcon... icons) { + icon = new InternalMaterialDesignIcon(color, icons); } - public FontBasedIcon getIcon() { - return new FontBasedIcon(this.unicode, this.color); + JabRefIcons(ImageIcon imageIcon) { + icon = new InternalFileIcon(imageIcon); } - public List getUnderlyingIcons() { - return icons; + @Override + public Icon getIcon() { + return icon.getIcon(); } - public MaterialDesignIcon getUnderlyingIcon() { - return icons.get(0); + @Override + public Icon getSmallIcon() { + return icon.getSmallIcon(); } - public FontBasedIcon getSmallIcon() { - return new FontBasedIcon(this.unicode, this.color, JabRefPreferences.getInstance().getInt(JabRefPreferences.ICON_SIZE_SMALL)); + @Override + public Node getGraphicNode() { + return icon.getGraphicNode(); } - public Node getGraphicNode() { - return new MaterialDesignIconView(this.icons.get(0)); + @Override + public JabRefIcon disabled() { + return icon.disabled(); } - public String getCode() { - return this.unicode; + private class InternalFileIcon implements JabRefIcon { + + private final ImageIcon imageIcon; + + InternalFileIcon(ImageIcon imageIcon) { + this.imageIcon = imageIcon; + } + + @Override + public Icon getIcon() { + return imageIcon; + } + + @Override + public Icon getSmallIcon() { + return imageIcon; + } + + @Override + public Node getGraphicNode() { + return new ImageView(new Image(imageIcon.getDescription())); + } + + @Override + public JabRefIcon disabled() { + throw new NotImplementedException("Cannot create disabled version of a file-based icon"); + } } } diff --git a/src/main/java/org/jabref/gui/InternalMaterialDesignIcon.java b/src/main/java/org/jabref/gui/InternalMaterialDesignIcon.java new file mode 100644 index 00000000000..d8d9f44e338 --- /dev/null +++ b/src/main/java/org/jabref/gui/InternalMaterialDesignIcon.java @@ -0,0 +1,75 @@ +package org.jabref.gui; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import javax.swing.Icon; + +import javafx.scene.Node; +import javafx.scene.paint.Color; + +import org.jabref.preferences.JabRefPreferences; + +import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; +import de.jensd.fx.glyphs.materialdesignicons.utils.MaterialDesignIconFactory; + +public class InternalMaterialDesignIcon implements JabRefIcon { + private final List icons; + private final Color color; + private final String unicode; + + public InternalMaterialDesignIcon(java.awt.Color color, MaterialDesignIcon... icons) { + this(toFX(color), Arrays.asList(icons)); + } + + public InternalMaterialDesignIcon(Color color, MaterialDesignIcon... icons) { + this(color, Arrays.asList(icons)); + } + + InternalMaterialDesignIcon(Color color, List icons) { + this.icons = icons; + this.color = color; + this.unicode = icons.stream().map(MaterialDesignIcon::unicode).collect(Collectors.joining()); + } + + public static java.awt.Color toAWT(Color color) { + return new java.awt.Color((float) color.getRed(), + (float) color.getGreen(), + (float) color.getBlue(), + (float) color.getOpacity()); + } + + public static Color toFX(java.awt.Color awtColor) { + int r = awtColor.getRed(); + int g = awtColor.getGreen(); + int b = awtColor.getBlue(); + int a = awtColor.getAlpha(); + double opacity = a / 255.0; + return javafx.scene.paint.Color.rgb(r, g, b, opacity); + } + + @Override + public Icon getIcon() { + return new IconTheme.FontBasedIcon(this.unicode, toAWT(this.color)); + } + + @Override + public Icon getSmallIcon() { + return new IconTheme.FontBasedIcon(this.unicode, toAWT(this.color), JabRefPreferences.getInstance().getInt(JabRefPreferences.ICON_SIZE_SMALL)); + } + + @Override + public Node getGraphicNode() { + return MaterialDesignIconFactory.get().createIcon(this.icons.get(0)); + } + + @Override + public JabRefIcon disabled() { + return new InternalMaterialDesignIcon(toFX(IconTheme.DEFAULT_DISABLED_COLOR), icons); + } + + public String getCode() { + return this.unicode; + } +} diff --git a/src/main/java/org/jabref/gui/JabRefIcon.java b/src/main/java/org/jabref/gui/JabRefIcon.java new file mode 100644 index 00000000000..08d4fc56e48 --- /dev/null +++ b/src/main/java/org/jabref/gui/JabRefIcon.java @@ -0,0 +1,15 @@ +package org.jabref.gui; + +import javax.swing.Icon; + +import javafx.scene.Node; + +public interface JabRefIcon { + Icon getIcon(); + + Icon getSmallIcon(); + + Node getGraphicNode(); + + JabRefIcon disabled(); +} diff --git a/src/main/java/org/jabref/gui/PreambleEditor.java b/src/main/java/org/jabref/gui/PreambleEditor.java index ffcfb095c7a..7f956290631 100644 --- a/src/main/java/org/jabref/gui/PreambleEditor.java +++ b/src/main/java/org/jabref/gui/PreambleEditor.java @@ -174,7 +174,7 @@ public void actionPerformed(ActionEvent e) { class UndoAction extends AbstractAction { public UndoAction() { - super("Undo", IconTheme.JabRefIcon.UNDO.getIcon()); + super("Undo", IconTheme.JabRefIcons.UNDO.getIcon()); putValue(Action.SHORT_DESCRIPTION, "Undo"); } @@ -187,7 +187,7 @@ public void actionPerformed(ActionEvent e) { class RedoAction extends AbstractAction { public RedoAction() { - super("Redo", IconTheme.JabRefIcon.REDO.getIcon()); + super("Redo", IconTheme.JabRefIcons.REDO.getIcon()); putValue(Action.SHORT_DESCRIPTION, "Redo"); } diff --git a/src/main/java/org/jabref/gui/PreviewPanel.java b/src/main/java/org/jabref/gui/PreviewPanel.java index d453aa0fff2..49958ceb3cf 100644 --- a/src/main/java/org/jabref/gui/PreviewPanel.java +++ b/src/main/java/org/jabref/gui/PreviewPanel.java @@ -123,10 +123,10 @@ private void createKeyBindings() { } private ContextMenu createPopupMenu() { - MenuItem copyPreview = new MenuItem(Localization.lang("Copy preview"), IconTheme.JabRefIcon.COPY.getGraphicNode()); + MenuItem copyPreview = new MenuItem(Localization.lang("Copy preview"), IconTheme.JabRefIcons.COPY.getGraphicNode()); copyPreview.setAccelerator(keyBindingRepository.getKeyCombination(KeyBinding.COPY_PREVIEW)); copyPreview.setOnAction(event -> copyPreviewToClipBoard()); - MenuItem printEntryPreview = new MenuItem(Localization.lang("Print entry preview"), IconTheme.JabRefIcon.PRINTED.getGraphicNode()); + MenuItem printEntryPreview = new MenuItem(Localization.lang("Print entry preview"), IconTheme.JabRefIcons.PRINTED.getGraphicNode()); printEntryPreview.setOnAction(event -> print()); MenuItem previousPreviewLayout = new MenuItem(Localization.menuTitleFX("Previous preview layout")); previousPreviewLayout.setAccelerator(keyBindingRepository.getKeyCombination(KeyBinding.PREVIOUS_PREVIEW_LAYOUT)); diff --git a/src/main/java/org/jabref/gui/SidePaneComponent.java b/src/main/java/org/jabref/gui/SidePaneComponent.java index d6d54678b57..911ed8b59c4 100644 --- a/src/main/java/org/jabref/gui/SidePaneComponent.java +++ b/src/main/java/org/jabref/gui/SidePaneComponent.java @@ -20,7 +20,7 @@ public abstract class SidePaneComponent extends JPanel { - protected final JButton close = new JButton(IconTheme.JabRefIcon.CLOSE.getSmallIcon()); + protected final JButton close = new JButton(IconTheme.JabRefIcons.CLOSE.getSmallIcon()); protected final SidePaneManager manager; @@ -37,12 +37,12 @@ public SidePaneComponent(SidePaneManager manager, Icon icon, String title) { close.setBorder(null); close.addActionListener(e -> hideAway()); - JButton up = new JButton(IconTheme.JabRefIcon.UP.getSmallIcon()); + JButton up = new JButton(IconTheme.JabRefIcons.UP.getSmallIcon()); up.setMargin(new Insets(0, 0, 0, 0)); up.setBorder(null); up.addActionListener(e -> moveUp()); - JButton down = new JButton(IconTheme.JabRefIcon.DOWN.getSmallIcon()); + JButton down = new JButton(IconTheme.JabRefIcons.DOWN.getSmallIcon()); down.setMargin(new Insets(0, 0, 0, 0)); down.setBorder(null); down.addActionListener(e -> moveDown()); @@ -123,7 +123,7 @@ public Dimension getMinimumSize() { public class ToggleAction extends MnemonicAwareAction { - public ToggleAction(String text, String description, KeyStroke key, IconTheme.JabRefIcon icon) { + public ToggleAction(String text, String description, KeyStroke key, JabRefIcon icon) { super(icon.getIcon()); putValue(Action.NAME, text); putValue(Action.ACCELERATOR_KEY, key); diff --git a/src/main/java/org/jabref/gui/StringDialog.java b/src/main/java/org/jabref/gui/StringDialog.java index d79dbb67383..445a9ab3bba 100644 --- a/src/main/java/org/jabref/gui/StringDialog.java +++ b/src/main/java/org/jabref/gui/StringDialog.java @@ -190,7 +190,7 @@ static class SaveDatabaseAction extends AbstractAction { public SaveDatabaseAction(StringDialog parent) { - super("Save library", IconTheme.JabRefIcon.SAVE.getIcon()); + super("Save library", IconTheme.JabRefIcons.SAVE.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Save library")); this.parent = parent; } @@ -336,7 +336,7 @@ class NewStringAction extends AbstractAction { public NewStringAction(StringDialog parent) { - super("New string", IconTheme.JabRefIcon.ADD.getIcon()); + super("New string", IconTheme.JabRefIcons.ADD.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("New string")); this.parent = parent; } @@ -385,7 +385,7 @@ class RemoveStringAction extends AbstractAction { public RemoveStringAction(StringDialog parent) { - super("Remove selected strings", IconTheme.JabRefIcon.REMOVE.getIcon()); + super("Remove selected strings", IconTheme.JabRefIcons.REMOVE.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Remove selected strings")); this.parent = parent; } @@ -430,7 +430,7 @@ public void actionPerformed(ActionEvent e) { class UndoAction extends AbstractAction { public UndoAction() { - super("Undo", IconTheme.JabRefIcon.UNDO.getIcon()); + super("Undo", IconTheme.JabRefIcons.UNDO.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Undo")); } @@ -443,7 +443,7 @@ public void actionPerformed(ActionEvent e) { class RedoAction extends AbstractAction { public RedoAction() { - super("Redo", IconTheme.JabRefIcon.REDO.getIcon()); + super("Redo", IconTheme.JabRefIcons.REDO.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Redo")); } diff --git a/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java b/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java index db9931a8f00..3e623f5179d 100644 --- a/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java +++ b/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java @@ -24,8 +24,8 @@ public class AutoLinkFilesAction extends AbstractAction { public AutoLinkFilesAction() { - putValue(Action.SMALL_ICON, IconTheme.JabRefIcon.AUTO_FILE_LINK.getSmallIcon()); - putValue(Action.LARGE_ICON_KEY, IconTheme.JabRefIcon.AUTO_FILE_LINK.getIcon()); + putValue(Action.SMALL_ICON, IconTheme.JabRefIcons.AUTO_FILE_LINK.getSmallIcon()); + putValue(Action.LARGE_ICON_KEY, IconTheme.JabRefIcons.AUTO_FILE_LINK.getIcon()); putValue(Action.NAME, Localization.lang("Automatically set file links")); putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.AUTOMATICALLY_LINK_FILES)); } diff --git a/src/main/java/org/jabref/gui/actions/NewDatabaseAction.java b/src/main/java/org/jabref/gui/actions/NewDatabaseAction.java index 5aa52aa62b0..f546b9ef6e8 100644 --- a/src/main/java/org/jabref/gui/actions/NewDatabaseAction.java +++ b/src/main/java/org/jabref/gui/actions/NewDatabaseAction.java @@ -20,7 +20,7 @@ public class NewDatabaseAction extends MnemonicAwareAction { private final BibDatabaseMode mode; public NewDatabaseAction(JabRefFrame jabRefFrame, BibDatabaseMode mode) { - super(IconTheme.JabRefIcon.NEW.getIcon()); + super(IconTheme.JabRefIcons.NEW.getIcon()); this.jabRefFrame = jabRefFrame; this.mode = mode; putValue(Action.NAME, Localization.menuTitle("New %0 library", mode.getFormattedName())); diff --git a/src/main/java/org/jabref/gui/actions/NewEntryAction.java b/src/main/java/org/jabref/gui/actions/NewEntryAction.java index b404dfea3af..8245889ff4b 100644 --- a/src/main/java/org/jabref/gui/actions/NewEntryAction.java +++ b/src/main/java/org/jabref/gui/actions/NewEntryAction.java @@ -27,7 +27,7 @@ public class NewEntryAction extends MnemonicAwareAction { public NewEntryAction(JabRefFrame jabRefFrame, KeyStroke key) { // This action leads to a dialog asking for entry type. - super(IconTheme.JabRefIcon.ADD_ENTRY.getIcon()); + super(IconTheme.JabRefIcons.ADD_ENTRY.getIcon()); this.jabRefFrame = jabRefFrame; putValue(Action.NAME, Localization.menuTitle("New entry") + "..."); putValue(Action.ACCELERATOR_KEY, key); diff --git a/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java b/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java index 199f0400e4d..e5fc7c6bc4e 100644 --- a/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java +++ b/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java @@ -21,7 +21,7 @@ public class NewSubDatabaseAction extends MnemonicAwareAction { private final JabRefFrame jabRefFrame; public NewSubDatabaseAction(JabRefFrame jabRefFrame) { - super(IconTheme.JabRefIcon.NEW.getIcon()); + super(IconTheme.JabRefIcons.NEW.getIcon()); this.jabRefFrame = jabRefFrame; putValue(Action.NAME, Localization.menuTitle("New sublibrary based on AUX file") + "..."); putValue(Action.SHORT_DESCRIPTION, Localization.lang("New BibTeX sublibrary")); diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java index f14b7ab073f..cabdd4b00bc 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java @@ -135,7 +135,7 @@ private void buildGUI() { con.weighty = 0; con.anchor = GridBagConstraints.SOUTHEAST; con.insets = new Insets(0, 5, 0, 5); - JButton hlb = new JButton(IconTheme.JabRefIcon.HELP.getSmallIcon()); + JButton hlb = new JButton(IconTheme.JabRefIcons.HELP.getSmallIcon()); hlb.setToolTipText(Localization.lang("Help on key patterns")); gbl.setConstraints(hlb, con); add(hlb); diff --git a/src/main/java/org/jabref/gui/collab/FileUpdatePanel.java b/src/main/java/org/jabref/gui/collab/FileUpdatePanel.java index b2e72606dec..912c203aec6 100644 --- a/src/main/java/org/jabref/gui/collab/FileUpdatePanel.java +++ b/src/main/java/org/jabref/gui/collab/FileUpdatePanel.java @@ -25,7 +25,7 @@ public class FileUpdatePanel extends SidePaneComponent implements ActionListener public FileUpdatePanel(BasePanel panel, SidePaneManager manager, File file, ChangeScanner scanner) { - super(manager, IconTheme.JabRefIcon.SAVE.getIcon(), Localization.lang("File changed")); + super(manager, IconTheme.JabRefIcons.SAVE.getIcon(), Localization.lang("File changed")); close.setEnabled(false); this.panel = panel; this.manager = manager; diff --git a/src/main/java/org/jabref/gui/customentrytypes/FieldSetComponent.java b/src/main/java/org/jabref/gui/customentrytypes/FieldSetComponent.java index f7d17f4a95b..3ccec8f86ec 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/FieldSetComponent.java +++ b/src/main/java/org/jabref/gui/customentrytypes/FieldSetComponent.java @@ -125,8 +125,8 @@ private FieldSetComponent(String title, List fields, List preset con.gridwidth = 1; if (arrows) { con.weightx = 0; - up = new JButton(IconTheme.JabRefIcon.UP.getSmallIcon()); - down = new JButton(IconTheme.JabRefIcon.DOWN.getSmallIcon()); + up = new JButton(IconTheme.JabRefIcons.UP.getSmallIcon()); + down = new JButton(IconTheme.JabRefIcons.DOWN.getSmallIcon()); up.addActionListener(e -> move(-1)); down.addActionListener(e -> move(1)); up.setToolTipText(Localization.lang("Move up")); diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index c5ab1b21184..a362446b26f 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -194,8 +194,7 @@ public static boolean openExternalFileUnknown(JabRefFrame frame, BibEntry entry, return false; } else if (answer == JOptionPane.YES_OPTION) { // User wants to define the new file type. Show the dialog: - ExternalFileType newType = new ExternalFileType(fileType.getName(), "", "", "", "new", - IconTheme.JabRefIcon.FILE.getSmallIcon()); + ExternalFileType newType = new ExternalFileType(fileType.getName(), "", "", "", "new", IconTheme.JabRefIcons.FILE); ExternalFileTypeEntryEditor editor = new ExternalFileTypeEntryEditor(frame, newType); editor.setVisible(true); if (editor.okPressed()) { diff --git a/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java b/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java index e31e844f9c9..6735edaf1cc 100644 --- a/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java +++ b/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java @@ -21,7 +21,7 @@ public ShowDocumentViewerAction(String title, String tooltip, Icon iconFile) { public ShowDocumentViewerAction() { this(Localization.menuTitle("Show document viewer"), Localization.lang("Show document viewer"), - IconTheme.JabRefIcon.PDF_FILE.getIcon()); + IconTheme.JabRefIcons.PDF_FILE.getIcon()); } @Override diff --git a/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java b/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java index d56cec1b4d9..f52edafa728 100644 --- a/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java @@ -19,7 +19,7 @@ public DeprecatedFieldsTab(BibDatabaseContext databaseContext, SuggestionProvide setText(Localization.lang("Deprecated fields")); setTooltip(new Tooltip(Localization.lang("Show deprecated BibTeX fields"))); - setGraphic(IconTheme.JabRefIcon.OPTIONAL.getGraphicNode()); + setGraphic(IconTheme.JabRefIcons.OPTIONAL.getGraphicNode()); } @Override diff --git a/src/main/java/org/jabref/gui/entryeditor/OptionalFields2Tab.java b/src/main/java/org/jabref/gui/entryeditor/OptionalFields2Tab.java index 7057cc97c84..46f3dbd43d2 100644 --- a/src/main/java/org/jabref/gui/entryeditor/OptionalFields2Tab.java +++ b/src/main/java/org/jabref/gui/entryeditor/OptionalFields2Tab.java @@ -19,7 +19,7 @@ public OptionalFields2Tab(BibDatabaseContext databaseContext, SuggestionProvider setText(Localization.lang("Optional fields 2")); setTooltip(new Tooltip(Localization.lang("Show optional fields"))); - setGraphic(IconTheme.JabRefIcon.OPTIONAL.getGraphicNode()); + setGraphic(IconTheme.JabRefIcons.OPTIONAL.getGraphicNode()); } @Override diff --git a/src/main/java/org/jabref/gui/entryeditor/OptionalFieldsTab.java b/src/main/java/org/jabref/gui/entryeditor/OptionalFieldsTab.java index fe863c95a2c..d5aad5ee108 100644 --- a/src/main/java/org/jabref/gui/entryeditor/OptionalFieldsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/OptionalFieldsTab.java @@ -19,7 +19,7 @@ public OptionalFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders setText(Localization.lang("Optional fields")); setTooltip(new Tooltip(Localization.lang("Show optional fields"))); - setGraphic(IconTheme.JabRefIcon.OPTIONAL.getGraphicNode()); + setGraphic(IconTheme.JabRefIcons.OPTIONAL.getGraphicNode()); } @Override diff --git a/src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java b/src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java index 812a0be7ed9..4896d0a9236 100644 --- a/src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java @@ -23,7 +23,7 @@ public OtherFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders su setText(Localization.lang("Other fields")); setTooltip(new Tooltip(Localization.lang("Show remaining fields"))); - setGraphic(IconTheme.JabRefIcon.OPTIONAL.getGraphicNode()); + setGraphic(IconTheme.JabRefIcons.OPTIONAL.getGraphicNode()); } @Override diff --git a/src/main/java/org/jabref/gui/entryeditor/RequiredFieldsTab.java b/src/main/java/org/jabref/gui/entryeditor/RequiredFieldsTab.java index 77a61fe39f4..4f985b83def 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RequiredFieldsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RequiredFieldsTab.java @@ -21,7 +21,7 @@ public RequiredFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders setText(Localization.lang("Required fields")); setTooltip(new Tooltip(Localization.lang("Show required fields"))); - setGraphic(IconTheme.JabRefIcon.REQUIRED.getGraphicNode()); + setGraphic(IconTheme.JabRefIcons.REQUIRED.getGraphicNode()); } @Override diff --git a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java index 6b61f9ccead..e53866a718a 100644 --- a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java @@ -55,7 +55,7 @@ public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undo this.mode = bibDatabaseContext.getMode(); this.setText(Localization.lang("%0 source", mode.getFormattedName())); this.setTooltip(new Tooltip(Localization.lang("Show/edit %0 source", mode.getFormattedName()))); - this.setGraphic(IconTheme.JabRefIcon.SOURCE.getGraphicNode()); + this.setGraphic(IconTheme.JabRefIcons.SOURCE.getGraphicNode()); this.undoManager = undoManager; this.fieldFormatterPreferences = fieldFormatterPreferences; } diff --git a/src/main/java/org/jabref/gui/entryeditor/UserDefinedFieldsTab.java b/src/main/java/org/jabref/gui/entryeditor/UserDefinedFieldsTab.java index 34a0dc5c29d..13cc45f9bfa 100644 --- a/src/main/java/org/jabref/gui/entryeditor/UserDefinedFieldsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/UserDefinedFieldsTab.java @@ -19,7 +19,7 @@ public UserDefinedFieldsTab(String name, List fields, BibDatabaseContext this.fields = fields; setText(name); - setGraphic(IconTheme.JabRefIcon.OPTIONAL.getGraphicNode()); + setGraphic(IconTheme.JabRefIcons.OPTIONAL.getGraphicNode()); } @Override diff --git a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleController.java b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleController.java index 641cec00f88..b4a33616966 100644 --- a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleController.java +++ b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleController.java @@ -52,7 +52,7 @@ private void initialize() { messagesListView.scrollTo(size - 1); } })); - descriptionLabel.setGraphic(IconTheme.JabRefIcon.CONSOLE.getGraphicNode()); + descriptionLabel.setGraphic(IconTheme.JabRefIcons.CONSOLE.getGraphicNode()); } private Callback, ListCell> createCellFactory() { diff --git a/src/main/java/org/jabref/gui/errorconsole/LogEventViewModel.java b/src/main/java/org/jabref/gui/errorconsole/LogEventViewModel.java index dd906d3c30b..096aedb2f87 100644 --- a/src/main/java/org/jabref/gui/errorconsole/LogEventViewModel.java +++ b/src/main/java/org/jabref/gui/errorconsole/LogEventViewModel.java @@ -4,6 +4,7 @@ import java.util.Optional; import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefIcon; import org.jabref.logic.util.OS; import com.google.common.base.Throwables; @@ -33,15 +34,15 @@ public String getStyleClass() { } } - public IconTheme.JabRefIcon getIcon() { + public JabRefIcon getIcon() { switch (logEvent.getLevel().getStandardLevel()) { case ERROR: - return (IconTheme.JabRefIcon.INTEGRITY_FAIL); + return (IconTheme.JabRefIcons.INTEGRITY_FAIL); case WARN: - return (IconTheme.JabRefIcon.INTEGRITY_WARN); + return (IconTheme.JabRefIcons.INTEGRITY_WARN); case INFO: default: - return (IconTheme.JabRefIcon.INTEGRITY_INFO); + return (IconTheme.JabRefIcons.INTEGRITY_INFO); } } diff --git a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java index fee0a435a08..16c8f1ad454 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java @@ -27,7 +27,7 @@ public class SaveAllAction extends MnemonicAwareAction implements Runnable { /** Creates a new instance of SaveAllAction */ public SaveAllAction(JabRefFrame frame) { - super(IconTheme.JabRefIcon.SAVE_ALL.getIcon()); + super(IconTheme.JabRefIcons.SAVE_ALL.getIcon()); this.frame = frame; putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.SAVE_ALL)); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Save all open libraries")); diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java index 335b78ffcfc..3a35e2f2b78 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java @@ -2,10 +2,10 @@ import java.util.Objects; -import javax.swing.Icon; import javax.swing.JLabel; import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefIcon; /** * This class defines a type of external files that can be linked to from JabRef. @@ -19,11 +19,11 @@ public class ExternalFileType implements Comparable { private String openWith; private String iconName; private String mimeType; - private Icon icon; + private JabRefIcon icon; private final JLabel label = new JLabel(); public ExternalFileType(String name, String extension, String mimeType, - String openWith, String iconName, Icon icon) { + String openWith, String iconName, JabRefIcon icon) { label.setText(null); this.name = name; label.setToolTipText(this.name); @@ -52,7 +52,6 @@ public static ExternalFileType buildFromArgs(String[] val) { String openWith; String mimeType; String iconName; - Icon icon; if (val.length == 4) { // Up to version 2.4b the mime type is not included: @@ -67,7 +66,7 @@ public static ExternalFileType buildFromArgs(String[] val) { } // set icon to default first - icon = IconTheme.JabRefIcon.FILE.getSmallIcon(); + JabRefIcon icon = IconTheme.JabRefIcons.FILE; // check whether there is another icon defined for this file type for (ExternalFileType fileType : ExternalFileTypes.getDefaultExternalFileTypes()) { @@ -171,13 +170,13 @@ public String getIconName() { return iconName; } - public Icon getIcon() { + public JabRefIcon getIcon() { return icon; } - public void setIcon(Icon icon) { + public void setIcon(JabRefIcon icon) { this.icon = icon; - label.setIcon(this.icon); + label.setIcon(this.icon.getSmallIcon()); } @Override diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java index 5a327c96c0b..c8d20d41182 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java @@ -45,7 +45,7 @@ public class ExternalFileTypeEntryEditor { private final JTextField name = new JTextField(); private final JTextField mimeType = new JTextField(); private final JTextField application = new JTextField(); - private final JLabel icon = new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon()); + private final JLabel icon = new JLabel(IconTheme.JabRefIcons.FILE.getSmallIcon()); private final JButton ok = new JButton(Localization.lang("OK")); private final JButton cancel = new JButton(Localization.lang("Cancel")); private final JRadioButton useDefault = new JRadioButton(Localization.lang("Default")); @@ -218,7 +218,7 @@ private void setValues(ExternalFileType entry) { extension.setText(entry.getExtension()); mimeType.setText(entry.getMimeType()); application.setText(entry.getOpenWithApplication()); - icon.setIcon(entry.getIcon()); + icon.setIcon(entry.getIcon().getSmallIcon()); if (application.getText().isEmpty()) { useDefault.setSelected(true); } else { diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java index 702b47048bd..0879f8b3ade 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java @@ -28,8 +28,7 @@ public class ExternalFileTypes { // Map containing all registered external file types: private final Set externalFileTypes = new TreeSet<>(); - private final ExternalFileType HTML_FALLBACK_TYPE = new ExternalFileType("URL", "html", "text/html", "", "www", - IconTheme.JabRefIcon.WWW.getSmallIcon()); + private final ExternalFileType HTML_FALLBACK_TYPE = new ExternalFileType("URL", "html", "text/html", "", "www", IconTheme.JabRefIcons.WWW); private ExternalFileTypes() { updateExternalFileTypes(); @@ -44,57 +43,29 @@ public static ExternalFileTypes getInstance() { public static List getDefaultExternalFileTypes() { List list = new ArrayList<>(); - list.add(new ExternalFileType("PDF", "pdf", "application/pdf", "evince", "pdfSmall", - IconTheme.JabRefIcon.PDF_FILE.getSmallIcon())); - list.add(new ExternalFileType("PostScript", "ps", "application/postscript", "evince", "psSmall", - IconTheme.JabRefIcon.FILE.getSmallIcon())); - list.add(new ExternalFileType("Word", "doc", "application/msword", "oowriter", "openoffice", - IconTheme.JabRefIcon.FILE_WORD.getSmallIcon())); - list.add(new ExternalFileType("Word 2007+", "docx", - "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "oowriter", "openoffice", - IconTheme.JabRefIcon.FILE_WORD.getSmallIcon())); - list.add(new ExternalFileType(Localization.lang("OpenDocument text"), "odt", - "application/vnd.oasis.opendocument.text", "oowriter", "openoffice", IconTheme.getImage("openoffice"))); - list.add(new ExternalFileType("Excel", "xls", "application/excel", "oocalc", "openoffice", - IconTheme.JabRefIcon.FILE_EXCEL.getSmallIcon())); - list.add(new ExternalFileType("Excel 2007+", "xlsx", - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "oocalc", "openoffice", - IconTheme.JabRefIcon.FILE_EXCEL.getSmallIcon())); - list.add(new ExternalFileType(Localization.lang("OpenDocument spreadsheet"), "ods", - "application/vnd.oasis.opendocument.spreadsheet", "oocalc", "openoffice", - IconTheme.getImage("openoffice"))); - list.add(new ExternalFileType("PowerPoint", "ppt", "application/vnd.ms-powerpoint", "ooimpress", "openoffice", - IconTheme.JabRefIcon.FILE_POWERPOINT.getSmallIcon())); - list.add(new ExternalFileType("PowerPoint 2007+", "pptx", - "application/vnd.openxmlformats-officedocument.presentationml.presentation", "ooimpress", "openoffice", - IconTheme.JabRefIcon.FILE_POWERPOINT.getSmallIcon())); - list.add(new ExternalFileType(Localization.lang("OpenDocument presentation"), "odp", - "application/vnd.oasis.opendocument.presentation", "ooimpress", "openoffice", - IconTheme.getImage("openoffice"))); - list.add(new ExternalFileType("Rich Text Format", "rtf", "application/rtf", "oowriter", "openoffice", - IconTheme.JabRefIcon.FILE_TEXT.getSmallIcon())); - list.add(new ExternalFileType(Localization.lang("%0 image", "PNG"), "png", "image/png", "gimp", "picture", - IconTheme.JabRefIcon.PICTURE.getSmallIcon())); - list.add(new ExternalFileType(Localization.lang("%0 image", "GIF"), "gif", "image/gif", "gimp", "picture", - IconTheme.JabRefIcon.PICTURE.getSmallIcon())); - list.add(new ExternalFileType(Localization.lang("%0 image", "JPG"), "jpg", "image/jpeg", "gimp", "picture", - IconTheme.JabRefIcon.PICTURE.getSmallIcon())); - list.add(new ExternalFileType("Djvu", "djvu", "image/vnd.djvu", "evince", "psSmall", - IconTheme.JabRefIcon.FILE.getSmallIcon())); - list.add(new ExternalFileType("Text", "txt", "text/plain", "emacs", "emacs", - IconTheme.JabRefIcon.FILE_TEXT.getSmallIcon())); - list.add(new ExternalFileType("LaTeX", "tex", "application/x-latex", "emacs", "emacs", - IconTheme.JabRefIcon.FILE_TEXT.getSmallIcon())); - list.add(new ExternalFileType("CHM", "chm", "application/mshelp", "gnochm", "www", - IconTheme.JabRefIcon.WWW.getSmallIcon())); - list.add(new ExternalFileType(Localization.lang("%0 image", "TIFF"), "tiff", "image/tiff", "gimp", "picture", - IconTheme.JabRefIcon.PICTURE.getSmallIcon())); - list.add(new ExternalFileType("URL", "html", "text/html", "firefox", "www", - IconTheme.JabRefIcon.WWW.getSmallIcon())); - list.add(new ExternalFileType("MHT", "mht", "multipart/related", "firefox", "www", - IconTheme.JabRefIcon.WWW.getSmallIcon())); - list.add(new ExternalFileType("ePUB", "epub", "application/epub+zip", "firefox", "www", - IconTheme.JabRefIcon.WWW.getSmallIcon())); + list.add(new ExternalFileType("PDF", "pdf", "application/pdf", "evince", "pdfSmall", IconTheme.JabRefIcons.PDF_FILE)); + list.add(new ExternalFileType("PostScript", "ps", "application/postscript", "evince", "psSmall", IconTheme.JabRefIcons.FILE)); + list.add(new ExternalFileType("Word", "doc", "application/msword", "oowriter", "openoffice", IconTheme.JabRefIcons.FILE_WORD)); + list.add(new ExternalFileType("Word 2007+", "docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "oowriter", "openoffice", IconTheme.JabRefIcons.FILE_WORD)); + list.add(new ExternalFileType(Localization.lang("OpenDocument text"), "odt", "application/vnd.oasis.opendocument.text", "oowriter", "openoffice", IconTheme.JabRefIcons.FILE_OPENOFFICE)); + list.add(new ExternalFileType("Excel", "xls", "application/excel", "oocalc", "openoffice", IconTheme.JabRefIcons.FILE_EXCEL)); + list.add(new ExternalFileType("Excel 2007+", "xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "oocalc", "openoffice", IconTheme.JabRefIcons.FILE_EXCEL)); + list.add(new ExternalFileType(Localization.lang("OpenDocument spreadsheet"), "ods", "application/vnd.oasis.opendocument.spreadsheet", "oocalc", "openoffice", IconTheme.JabRefIcons.FILE_OPENOFFICE)); + list.add(new ExternalFileType("PowerPoint", "ppt", "application/vnd.ms-powerpoint", "ooimpress", "openoffice", IconTheme.JabRefIcons.FILE_POWERPOINT)); + list.add(new ExternalFileType("PowerPoint 2007+", "pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "ooimpress", "openoffice", IconTheme.JabRefIcons.FILE_POWERPOINT)); + list.add(new ExternalFileType(Localization.lang("OpenDocument presentation"), "odp", "application/vnd.oasis.opendocument.presentation", "ooimpress", "openoffice", IconTheme.JabRefIcons.FILE_OPENOFFICE)); + list.add(new ExternalFileType("Rich Text Format", "rtf", "application/rtf", "oowriter", "openoffice", IconTheme.JabRefIcons.FILE_TEXT)); + list.add(new ExternalFileType(Localization.lang("%0 image", "PNG"), "png", "image/png", "gimp", "picture", IconTheme.JabRefIcons.PICTURE)); + list.add(new ExternalFileType(Localization.lang("%0 image", "GIF"), "gif", "image/gif", "gimp", "picture", IconTheme.JabRefIcons.PICTURE)); + list.add(new ExternalFileType(Localization.lang("%0 image", "JPG"), "jpg", "image/jpeg", "gimp", "picture", IconTheme.JabRefIcons.PICTURE)); + list.add(new ExternalFileType("Djvu", "djvu", "image/vnd.djvu", "evince", "psSmall", IconTheme.JabRefIcons.FILE)); + list.add(new ExternalFileType("Text", "txt", "text/plain", "emacs", "emacs", IconTheme.JabRefIcons.FILE_TEXT)); + list.add(new ExternalFileType("LaTeX", "tex", "application/x-latex", "emacs", "emacs", IconTheme.JabRefIcons.FILE_TEXT)); + list.add(new ExternalFileType("CHM", "chm", "application/mshelp", "gnochm", "www", IconTheme.JabRefIcons.WWW)); + list.add(new ExternalFileType(Localization.lang("%0 image", "TIFF"), "tiff", "image/tiff", "gimp", "picture", IconTheme.JabRefIcons.PICTURE)); + list.add(new ExternalFileType("URL", "html", "text/html", "firefox", "www", IconTheme.JabRefIcons.WWW)); + list.add(new ExternalFileType("MHT", "mht", "multipart/related", "firefox", "www", IconTheme.JabRefIcons.WWW)); + list.add(new ExternalFileType("ePUB", "epub", "application/epub+zip", "firefox", "www", IconTheme.JabRefIcons.WWW)); // On all OSes there is a generic application available to handle file opening, // so we don't need the default application settings anymore: diff --git a/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java b/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java index 59e9198887a..bb9f4873253 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java +++ b/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java @@ -10,7 +10,7 @@ public class UnknownExternalFileType extends ExternalFileType { public UnknownExternalFileType(String name) { - super(name, "", "", "", "unknown", IconTheme.JabRefIcon.FILE.getSmallIcon()); + super(name, "", "", "", "unknown", IconTheme.JabRefIcons.FILE); } } diff --git a/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java index e53a54f5099..5afa8400a9e 100644 --- a/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java @@ -17,6 +17,8 @@ import org.jabref.gui.DragAndDropDataFormats; import org.jabref.gui.IconTheme; +import org.jabref.gui.InternalMaterialDesignIcon; +import org.jabref.gui.JabRefIcon; import org.jabref.gui.StateManager; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.BindingsHelper; @@ -156,10 +158,7 @@ public boolean equals(Object o) { GroupNodeViewModel that = (GroupNodeViewModel) o; - if (!groupNode.equals(that.groupNode)) { - return false; - } - return true; + return groupNode.equals(that.groupNode); } @Override @@ -180,14 +179,16 @@ public int hashCode() { return groupNode.hashCode(); } - public MaterialDesignIcon getIcon() { + public JabRefIcon getIcon() { Optional iconName = groupNode.getGroup().getIconName(); return iconName.flatMap(this::parseIcon) - .orElse(IconTheme.JabRefIcon.DEFAULT_GROUP_ICON.getUnderlyingIcon()); + .orElse(IconTheme.JabRefIcons.DEFAULT_GROUP_ICON); } - private Optional parseIcon(String iconCode) { - return Enums.getIfPresent(MaterialDesignIcon.class, iconCode.toUpperCase(Locale.ENGLISH)).toJavaUtil(); + private Optional parseIcon(String iconCode) { + return Enums.getIfPresent(MaterialDesignIcon.class, iconCode.toUpperCase(Locale.ENGLISH)) + .toJavaUtil() + .map(icon -> new InternalMaterialDesignIcon(getColor(), icon)); } public ObservableList getChildren() { diff --git a/src/main/java/org/jabref/gui/groups/GroupSidePane.java b/src/main/java/org/jabref/gui/groups/GroupSidePane.java index fb6eed02fd6..cbbb38852af 100644 --- a/src/main/java/org/jabref/gui/groups/GroupSidePane.java +++ b/src/main/java/org/jabref/gui/groups/GroupSidePane.java @@ -40,7 +40,7 @@ public class GroupSidePane extends SidePaneComponent { * regexp for the group. */ public GroupSidePane(JabRefFrame frame, SidePaneManager manager) { - super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups")); + super(manager, IconTheme.JabRefIcons.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups")); Globals.stateManager.activeGroupProperty() .addListener((observable, oldValue, newValue) -> updateShownEntriesAccordingToSelectedGroups(newValue)); @@ -57,7 +57,7 @@ public GroupSidePane(JabRefFrame frame, SidePaneManager manager) { toggleAction = new ToggleAction(Localization.menuTitle("Toggle groups interface"), Localization.lang("Toggle groups interface"), Globals.getKeyPrefs().getKey(KeyBinding.TOGGLE_GROUPS_INTERFACE), - IconTheme.JabRefIcon.TOGGLE_GROUPS); + IconTheme.JabRefIcons.TOGGLE_GROUPS); this.frame = frame; diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeController.java b/src/main/java/org/jabref/gui/groups/GroupTreeController.java index 357331789c3..e91f0e58e54 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeController.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeController.java @@ -101,7 +101,7 @@ public void initialize() { mainColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty()); mainColumn.setCellFactory(new ViewModelTreeTableCellFactory() .withText(GroupNodeViewModel::getDisplayName) - .withIcon(GroupNodeViewModel::getIcon, GroupNodeViewModel::getColor) + .withIcon(GroupNodeViewModel::getIcon) .withTooltip(GroupNodeViewModel::getDescription)); // Number of hits diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeNodeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeNodeViewModel.java index 9ba40973a42..f7f10458674 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeNodeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeNodeViewModel.java @@ -35,8 +35,8 @@ public class GroupTreeNodeViewModel implements Transferable, TreeNode { public static final DataFlavor FLAVOR; private static final Log LOGGER = LogFactory.getLog(GroupTreeNodeViewModel.class); - private static final Icon GROUP_REFINING_ICON = IconTheme.JabRefIcon.GROUP_REFINING.getSmallIcon(); - private static final Icon GROUP_INCLUDING_ICON = IconTheme.JabRefIcon.GROUP_INCLUDING.getSmallIcon(); + private static final Icon GROUP_REFINING_ICON = IconTheme.JabRefIcons.GROUP_REFINING.getSmallIcon(); + private static final Icon GROUP_INCLUDING_ICON = IconTheme.JabRefIcons.GROUP_INCLUDING.getSmallIcon(); private static final Icon GROUP_REGULAR_ICON = null; private static final DataFlavor[] FLAVORS; diff --git a/src/main/java/org/jabref/gui/help/HelpAction.java b/src/main/java/org/jabref/gui/help/HelpAction.java index dfe4cc631fa..384899e9788 100644 --- a/src/main/java/org/jabref/gui/help/HelpAction.java +++ b/src/main/java/org/jabref/gui/help/HelpAction.java @@ -41,7 +41,7 @@ public class HelpAction extends MnemonicAwareAction { public HelpAction(String title, String tooltip, HelpFile helpPage, KeyStroke key) { - this(title, tooltip, helpPage, IconTheme.JabRefIcon.HELP.getSmallIcon()); + this(title, tooltip, helpPage, IconTheme.JabRefIcons.HELP.getSmallIcon()); putValue(Action.ACCELERATOR_KEY, key); } @@ -53,7 +53,7 @@ private HelpAction(String title, String tooltip, HelpFile helpPage, Icon icon) { } public HelpAction(String tooltip, HelpFile helpPage) { - this(Localization.lang("Help"), tooltip, helpPage, IconTheme.JabRefIcon.HELP.getSmallIcon()); + this(Localization.lang("Help"), tooltip, helpPage, IconTheme.JabRefIcons.HELP.getSmallIcon()); } public HelpAction(HelpFile helpPage, Icon icon) { @@ -61,7 +61,7 @@ public HelpAction(HelpFile helpPage, Icon icon) { } public HelpAction(HelpFile helpPage) { - this(Localization.lang("Help"), Localization.lang("Help"), helpPage, IconTheme.JabRefIcon.HELP.getSmallIcon()); + this(Localization.lang("Help"), Localization.lang("Help"), helpPage, IconTheme.JabRefIcons.HELP.getSmallIcon()); } public JButton getHelpButton() { diff --git a/src/main/java/org/jabref/gui/importer/EntryFromPDFCreator.java b/src/main/java/org/jabref/gui/importer/EntryFromPDFCreator.java index 11538571332..de76e260708 100644 --- a/src/main/java/org/jabref/gui/importer/EntryFromPDFCreator.java +++ b/src/main/java/org/jabref/gui/importer/EntryFromPDFCreator.java @@ -40,7 +40,7 @@ public EntryFromPDFCreator() { private static ExternalFileType getPDFExternalFileType() { Optional pdfFileType = ExternalFileTypes.getInstance().getExternalFileTypeByExt("pdf"); if (!pdfFileType.isPresent()) { - return new ExternalFileType("PDF", "pdf", "application/pdf", "evince", "pdfSmall", IconTheme.JabRefIcon.PDF_FILE.getSmallIcon()); + return new ExternalFileType("PDF", "pdf", "application/pdf", "evince", "pdfSmall", IconTheme.JabRefIcons.PDF_FILE); } return pdfFileType.get(); } diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index 2accc567431..85564a70dc8 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -176,9 +176,9 @@ public class ImportInspectionDialog extends JabRefDialog implements ImportInspec private final Map> groupAdditions = new HashMap<>(); private final JCheckBox autoGenerate = new JCheckBox(Localization.lang("Generate keys"), Globals.prefs.getBoolean(JabRefPreferences.GENERATE_KEYS_AFTER_INSPECTION)); - private final JLabel duplLabel = new JLabel(IconTheme.JabRefIcon.DUPLICATE.getSmallIcon()); - private final JLabel fileLabel = new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon()); - private final JLabel urlLabel = new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon()); + private final JLabel duplLabel = new JLabel(IconTheme.JabRefIcons.DUPLICATE.getSmallIcon()); + private final JLabel fileLabel = new JLabel(IconTheme.JabRefIcons.FILE.getSmallIcon()); + private final JLabel urlLabel = new JLabel(IconTheme.JabRefIcons.WWW.getSmallIcon()); private BasePanel panel; private boolean generatedKeys; // Set to true after keys have been generated. private boolean defaultSelected = true; @@ -900,7 +900,7 @@ private List getSelectedEntries() { private class DeleteListener extends AbstractAction { public DeleteListener() { - super(Localization.lang("Delete"), IconTheme.JabRefIcon.DELETE_ENTRY.getSmallIcon()); + super(Localization.lang("Delete"), IconTheme.JabRefIcons.DELETE_ENTRY.getSmallIcon()); } @Override @@ -1046,7 +1046,7 @@ private void showFileFieldMenu(MouseEvent e) { description = flEntry.getLink(); } menu.add(new ExternalFileMenuItem(panel.frame(), entry, description, flEntry.getLink(), - flEntry.getType().get().getIcon(), panel.getBibDatabaseContext(), flEntry.getType())); + flEntry.getType().get().getIcon().getSmallIcon(), panel.getBibDatabaseContext(), flEntry.getType())); count++; } if (count == 0) { @@ -1431,7 +1431,7 @@ public Object getColumnValue(BibEntry entry, int i) { entry.getField(FieldName.FILE).ifPresent(model::setContent); fileLabel.setToolTipText(model.getToolTipHTMLRepresentation()); if ((model.getRowCount() > 0) && model.getEntry(0).getType().isPresent()) { - fileLabel.setIcon(model.getEntry(0).getType().get().getIcon()); + fileLabel.setIcon(model.getEntry(0).getType().get().getIcon().getSmallIcon()); } return fileLabel; } else { diff --git a/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java b/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java index 5bd10e6d06b..b1246e9fd97 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java @@ -47,7 +47,7 @@ public class GeneralFetcher extends SidePaneComponent implements ActionListener public GeneralFetcher(JabRefFrame frame, SidePaneManager sidePaneManager) { - super(sidePaneManager, IconTheme.JabRefIcon.WWW.getSmallIcon(), Localization.lang("Web search")); + super(sidePaneManager, IconTheme.JabRefIcons.WWW.getSmallIcon(), Localization.lang("Web search")); this.frame = frame; List fetchers = new EntryFetchers(Globals.journalAbbreviationLoader).getEntryFetchers(); EntryFetcher[] fetcherArray = fetchers.toArray(new EntryFetcher[fetchers.size()]); @@ -91,7 +91,7 @@ public GeneralFetcher(JabRefFrame frame, SidePaneManager sidePaneManager) { action = new ToggleAction(Localization.lang("Web search"), Localization.lang("Toggle web search interface"), Globals.getKeyPrefs().getKey(KeyBinding.WEB_SEARCH), - IconTheme.JabRefIcon.WWW); + IconTheme.JabRefIcons.WWW); helpBut.setMargin(new Insets(0, 0, 0, 0)); tf.setPreferredSize(new Dimension(1, tf.getPreferredSize().height)); diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsController.java b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsController.java index 7bc81684347..5e6bc92591d 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsController.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsController.java @@ -53,9 +53,9 @@ private void initialize() { } private void setButtonStyles() { - addJournalFileButton.setGraphic(IconTheme.JabRefIcon.OPEN.getGraphicNode()); - addNewJournalFileButton.setGraphic(IconTheme.JabRefIcon.NEW.getGraphicNode()); - removeJournalAbbreviationsButton.setGraphic(IconTheme.JabRefIcon.CLOSE.getGraphicNode()); + addJournalFileButton.setGraphic(IconTheme.JabRefIcons.OPEN.getGraphicNode()); + addNewJournalFileButton.setGraphic(IconTheme.JabRefIcons.NEW.getGraphicNode()); + removeJournalAbbreviationsButton.setGraphic(IconTheme.JabRefIcons.CLOSE.getGraphicNode()); } private void setUpTable() { @@ -73,10 +73,10 @@ private void setUpTable() { journalTableEditColumn.setCellFactory(new ValueTableCellFactory(). withGraphic(isPseudoAbbreviation -> { if (isPseudoAbbreviation) { - return IconTheme.JabRefIcon.ADD.getGraphicNode(); + return IconTheme.JabRefIcons.ADD.getGraphicNode(); } else { return viewModel.isAbbreviationEditableAndRemovable() ? - IconTheme.JabRefIcon.EDIT.getGraphicNode() : null; + IconTheme.JabRefIcons.EDIT.getGraphicNode() : null; } }). withOnMouseClickedEvent(isPseudoAbbreviation -> { @@ -93,7 +93,7 @@ private void setUpTable() { journalTableDeleteColumn.setCellFactory(new ValueTableCellFactory(). withGraphic(isPseudoAbbreviation -> { if (!isPseudoAbbreviation && viewModel.isAbbreviationEditableAndRemovable()) { - return IconTheme.JabRefIcon.DELETE_ENTRY.getGraphicNode(); + return IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode(); } else { return null; } diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBindingAction.java b/src/main/java/org/jabref/gui/keyboard/KeyBindingAction.java index 6086057dde6..47c94c20d90 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBindingAction.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBindingAction.java @@ -15,7 +15,7 @@ public class KeyBindingAction extends AbstractAction { public KeyBindingAction() { super(Localization.lang("Customize key bindings")); - this.putValue(Action.SMALL_ICON, IconTheme.JabRefIcon.KEY_BINDINGS.getSmallIcon()); + this.putValue(Action.SMALL_ICON, IconTheme.JabRefIcons.KEY_BINDINGS.getSmallIcon()); } @Override diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBindingViewModel.java b/src/main/java/org/jabref/gui/keyboard/KeyBindingViewModel.java index aa7e86b26bd..ad99b8b3887 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBindingViewModel.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBindingViewModel.java @@ -10,6 +10,7 @@ import javafx.scene.input.KeyEvent; import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefIcon; import com.google.common.base.CaseFormat; @@ -79,7 +80,7 @@ public StringProperty nameProperty() { } public boolean isCategory() { - return (keyBinding == null) ? true : false; + return keyBinding == null; } /** @@ -134,7 +135,7 @@ public void resetToDefault() { } } - public Optional getIcon() { - return isCategory() ? Optional.empty() : Optional.of(IconTheme.JabRefIcon.CLEANUP_ENTRIES); + public Optional getIcon() { + return isCategory() ? Optional.empty() : Optional.of(IconTheme.JabRefIcons.CLEANUP_ENTRIES); } } diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBindingsDialogController.java b/src/main/java/org/jabref/gui/keyboard/KeyBindingsDialogController.java index 21767bb255d..4b37931ebea 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBindingsDialogController.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBindingsDialogController.java @@ -11,7 +11,7 @@ import org.jabref.gui.AbstractController; import org.jabref.gui.DialogService; -import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefIcon; import org.jabref.gui.util.RecursiveTreeItem; import org.jabref.gui.util.ViewModelTreeTableCellFactory; import org.jabref.preferences.PreferencesService; @@ -47,7 +47,7 @@ private void initialize() { actionColumn.setCellValueFactory(cellData -> cellData.getValue().getValue().nameProperty()); shortcutColumn.setCellValueFactory(cellData -> cellData.getValue().getValue().shownBindingProperty()); resetColumn.setCellFactory(new ViewModelTreeTableCellFactory() - .withGraphic(keyBinding -> keyBinding.getIcon().map(IconTheme.JabRefIcon::getGraphicNode).orElse(null)) + .withGraphic(keyBinding -> keyBinding.getIcon().map(JabRefIcon::getGraphicNode).orElse(null)) .withOnMouseClickedEvent(keyBinding -> evt -> keyBinding.resetToDefault()) ); } diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java index b26740ce10f..1c0caa80c2d 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java @@ -93,8 +93,8 @@ class StyleSelectDialog { private final JMenuItem show = new JMenuItem(Localization.lang("View")); private final JMenuItem remove = new JMenuItem(Localization.lang("Remove")); private final JMenuItem reload = new JMenuItem(Localization.lang("Reload")); - private final JButton addButton = new JButton(IconTheme.JabRefIcon.ADD_NOBOX.getIcon()); - private final JButton removeButton = new JButton(IconTheme.JabRefIcon.REMOVE_NOBOX.getIcon()); + private final JButton addButton = new JButton(IconTheme.JabRefIcons.ADD_NOBOX.getIcon()); + private final JButton removeButton = new JButton(IconTheme.JabRefIcons.REMOVE_NOBOX.getIcon()); private PreviewPanel preview; private ActionListener removeAction; diff --git a/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java b/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java index 6ce4035ede6..669deca3e54 100644 --- a/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java +++ b/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java @@ -526,7 +526,7 @@ private class PasteAction extends BasicAction { public PasteAction() { super(Localization.lang("Paste"), Localization.lang("Paste from clipboard"), - IconTheme.JabRefIcon.PASTE.getIcon()); + IconTheme.JabRefIcons.PASTE.getIcon()); } @Override @@ -549,7 +549,7 @@ public void actionPerformed(ActionEvent e) { private class LoadAction extends BasicAction { public LoadAction() { - super(Localization.lang("Open"), Localization.lang("Open file"), IconTheme.JabRefIcon.OPEN.getIcon()); + super(Localization.lang("Open"), Localization.lang("Open file"), IconTheme.JabRefIcons.OPEN.getIcon()); } @Override @@ -584,7 +584,7 @@ public void actionPerformed(ActionEvent e) { private class ClearAction extends BasicAction { public ClearAction() { - super(Localization.lang("Clear"), Localization.lang("Clear inputarea"), IconTheme.JabRefIcon.NEW.getIcon()); + super(Localization.lang("Clear"), Localization.lang("Clear inputarea"), IconTheme.JabRefIcons.NEW.getIcon()); } @Override @@ -626,8 +626,8 @@ private class SimpleCellRenderer extends DefaultListCellRenderer { private final Font baseFont; private final Font usedFont; - private final Icon okIcon = IconTheme.JabRefIcon.PLAIN_TEXT_IMPORT_DONE.getSmallIcon(); - private final Icon needIcon = IconTheme.JabRefIcon.PLAIN_TEXT_IMPORT_TODO.getSmallIcon(); + private final Icon okIcon = IconTheme.JabRefIcons.PLAIN_TEXT_IMPORT_DONE.getSmallIcon(); + private final Icon needIcon = IconTheme.JabRefIcons.PLAIN_TEXT_IMPORT_TODO.getSmallIcon(); private final Color requiredColor = Globals.prefs.getColor(JabRefPreferences.TABLE_REQ_FIELD_BACKGROUND); private final Color optionalColor = Globals.prefs.getColor(JabRefPreferences.TABLE_OPT_FIELD_BACKGROUND); diff --git a/src/main/java/org/jabref/gui/preftabs/NameFormatterTab.java b/src/main/java/org/jabref/gui/preftabs/NameFormatterTab.java index 13729c60779..6c726a2d997 100644 --- a/src/main/java/org/jabref/gui/preftabs/NameFormatterTab.java +++ b/src/main/java/org/jabref/gui/preftabs/NameFormatterTab.java @@ -213,7 +213,7 @@ public void setValues() { class DeleteRowAction extends AbstractAction { public DeleteRowAction() { - super("Delete row", IconTheme.JabRefIcon.REMOVE_NOBOX.getIcon()); + super("Delete row", IconTheme.JabRefIcons.REMOVE_NOBOX.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Delete rows")); } @@ -246,7 +246,7 @@ public void actionPerformed(ActionEvent e) { class AddRowAction extends AbstractAction { public AddRowAction() { - super("Add row", IconTheme.JabRefIcon.ADD_NOBOX.getIcon()); + super("Add row", IconTheme.JabRefIcons.ADD_NOBOX.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Insert rows")); } diff --git a/src/main/java/org/jabref/gui/preftabs/XmpPrefsTab.java b/src/main/java/org/jabref/gui/preftabs/XmpPrefsTab.java index 81e5fb10fde..d288f23d3a7 100644 --- a/src/main/java/org/jabref/gui/preftabs/XmpPrefsTab.java +++ b/src/main/java/org/jabref/gui/preftabs/XmpPrefsTab.java @@ -154,7 +154,7 @@ public void setValueAt(Object value, int row, int col) { class DeleteRowAction extends AbstractAction { public DeleteRowAction() { - super("Delete row", IconTheme.JabRefIcon.REMOVE_NOBOX.getIcon()); + super("Delete row", IconTheme.JabRefIcons.REMOVE_NOBOX.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Delete rows")); } @@ -183,7 +183,7 @@ public void actionPerformed(ActionEvent e) { class AddRowAction extends AbstractAction { public AddRowAction() { - super("Add row", IconTheme.JabRefIcon.ADD_NOBOX.getIcon()); + super("Add row", IconTheme.JabRefIcons.ADD_NOBOX.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Insert rows")); } diff --git a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java b/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java index 7ff7856fa6b..ade27f62e5d 100644 --- a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java +++ b/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java @@ -79,9 +79,9 @@ public class ProtectedTermsDialog { private final JMenuItem remove = new JMenuItem(Localization.lang("Remove")); private final JMenuItem reload = new JMenuItem(Localization.lang("Reload")); private final JMenuItem enabled = new JCheckBoxMenuItem(Localization.lang("Enabled")); - private final JButton loadButton = new JButton(IconTheme.JabRefIcon.OPEN.getIcon()); - private final JButton removeButton = new JButton(IconTheme.JabRefIcon.DELETE_ENTRY.getIcon()); - private final JButton newButton = new JButton(IconTheme.JabRefIcon.NEW.getIcon()); + private final JButton loadButton = new JButton(IconTheme.JabRefIcons.OPEN.getIcon()); + private final JButton removeButton = new JButton(IconTheme.JabRefIcons.DELETE_ENTRY.getIcon()); + private final JButton newButton = new JButton(IconTheme.JabRefIcons.NEW.getIcon()); private ActionListener removeAction; private final JButton ok = new JButton(Localization.lang("OK")); diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationButton.java b/src/main/java/org/jabref/gui/push/PushToApplicationButton.java index 4bf755a0c68..ee9e3d9b4aa 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplicationButton.java +++ b/src/main/java/org/jabref/gui/push/PushToApplicationButton.java @@ -44,7 +44,7 @@ */ public class PushToApplicationButton implements ActionListener { - private static final Icon ARROW_ICON = IconTheme.JabRefIcon.DOWN.getSmallIcon(); + private static final Icon ARROW_ICON = IconTheme.JabRefIcons.DOWN.getSmallIcon(); private final JabRefFrame frame; private final List pushActions; private JPanel comp; diff --git a/src/main/java/org/jabref/gui/search/SearchResultFrame.java b/src/main/java/org/jabref/gui/search/SearchResultFrame.java index 0a57087f8c0..94b82a245d0 100644 --- a/src/main/java/org/jabref/gui/search/SearchResultFrame.java +++ b/src/main/java/org/jabref/gui/search/SearchResultFrame.java @@ -96,8 +96,8 @@ public class SearchResultFrame { private final JabRefFrame frame; private JFrame searchResultFrame; - private final JLabel fileLabel = new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon()); - private final JLabel urlLabel = new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon()); + private final JLabel fileLabel = new JLabel(IconTheme.JabRefIcons.FILE.getSmallIcon()); + private final JLabel urlLabel = new JLabel(IconTheme.JabRefIcons.WWW.getSmallIcon()); private final JSplitPane contentPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); @@ -521,7 +521,7 @@ public void processPopupTrigger(MouseEvent e) { description = flEntry.getLink(); } menu.add(new ExternalFileMenuItem(p.frame(), entry, description, flEntry.getLink(), - flEntry.getType().get().getIcon(), p.getBibDatabaseContext(), flEntry.getType())); + flEntry.getType().get().getIcon().getSmallIcon(), p.getBibDatabaseContext(), flEntry.getType())); count++; } @@ -591,9 +591,9 @@ public Object getColumnValue(BibEntry entry, int column) { fileLabel.setToolTipText(tmpModel.getToolTipHTMLRepresentation()); if (tmpModel.getRowCount() > 0) { if (tmpModel.getEntry(0).getType().isPresent()) { - fileLabel.setIcon(tmpModel.getEntry(0).getType().get().getIcon()); + fileLabel.setIcon(tmpModel.getEntry(0).getType().get().getIcon().getSmallIcon()); } else { - fileLabel.setIcon(IconTheme.JabRefIcon.FILE.getSmallIcon()); + fileLabel.setIcon(IconTheme.JabRefIcons.FILE.getSmallIcon()); } } return fileLabel; diff --git a/src/main/java/org/jabref/gui/search/SearchTextField.java b/src/main/java/org/jabref/gui/search/SearchTextField.java index e018ac2efd9..b96409b296a 100644 --- a/src/main/java/org/jabref/gui/search/SearchTextField.java +++ b/src/main/java/org/jabref/gui/search/SearchTextField.java @@ -13,7 +13,7 @@ public class SearchTextField { public static TextField create() { CustomTextField textField = (CustomTextField) TextFields.createClearableTextField(); textField.setPromptText(Localization.lang("Search") + "..."); - textField.setLeft(IconTheme.JabRefIcon.SEARCH.getGraphicNode()); + textField.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode()); return textField; } } diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java index df4fc097198..54b6166d949 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java @@ -6,6 +6,7 @@ import javax.swing.JLabel; import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefIcon; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.specialfields.SpecialFieldValue; @@ -20,40 +21,48 @@ public SpecialFieldValueViewModel(SpecialFieldValue value) { } public Icon getSpecialFieldValueIcon() { + JabRefIcon icon = getIcon(); + if (icon == null) { + return null; + } else { + return icon.getSmallIcon(); + } + } + public JabRefIcon getIcon() { switch (value) { case PRINTED: - return IconTheme.JabRefIcon.PRINTED.getSmallIcon(); + return IconTheme.JabRefIcons.PRINTED; case CLEAR_PRIORITY: return null; case PRIORITY_HIGH: - return IconTheme.JabRefIcon.PRIORITY_HIGH.getSmallIcon(); + return IconTheme.JabRefIcons.PRIORITY_HIGH; case PRIORITY_MEDIUM: - return IconTheme.JabRefIcon.PRIORITY_MEDIUM.getSmallIcon(); + return IconTheme.JabRefIcons.PRIORITY_MEDIUM; case PRIORITY_LOW: - return IconTheme.JabRefIcon.PRIORITY_LOW.getSmallIcon(); + return IconTheme.JabRefIcons.PRIORITY_LOW; case QUALITY_ASSURED: - return IconTheme.JabRefIcon.QUALITY_ASSURED.getSmallIcon(); + return IconTheme.JabRefIcons.QUALITY_ASSURED; case CLEAR_RANK: return null; case RANK_1: - return IconTheme.JabRefIcon.RANK1.getSmallIcon(); + return IconTheme.JabRefIcons.RANK1; case RANK_2: - return IconTheme.JabRefIcon.RANK2.getSmallIcon(); + return IconTheme.JabRefIcons.RANK2; case RANK_3: - return IconTheme.JabRefIcon.RANK3.getSmallIcon(); + return IconTheme.JabRefIcons.RANK3; case RANK_4: - return IconTheme.JabRefIcon.RANK4.getSmallIcon(); + return IconTheme.JabRefIcons.RANK4; case RANK_5: - return IconTheme.JabRefIcon.RANK5.getSmallIcon(); + return IconTheme.JabRefIcons.RANK5; case CLEAR_READ_STATUS: return null; case READ: - return IconTheme.JabRefIcon.READ_STATUS_READ.getSmallIcon(); + return IconTheme.JabRefIcons.READ_STATUS_READ; case SKIMMED: - return IconTheme.JabRefIcon.READ_STATUS_SKIMMED.getSmallIcon(); + return IconTheme.JabRefIcons.READ_STATUS_SKIMMED; case RELEVANT: - return IconTheme.JabRefIcon.RELEVANCE.getSmallIcon(); + return IconTheme.JabRefIcons.RELEVANCE; default: throw new IllegalArgumentException("There is no icon mapping for special field value " + value); } diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java index dcace6e65bd..a372ba71417 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java @@ -6,6 +6,7 @@ import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.JabRefIcon; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.specialfields.SpecialField; import org.jabref.model.entry.specialfields.SpecialFieldValue; @@ -30,17 +31,36 @@ public SpecialFieldAction getSpecialFieldAction(SpecialFieldValue value, JabRefF public Icon getRepresentingIcon() { switch (field) { case PRINTED: - return IconTheme.JabRefIcon.PRINTED.getSmallIcon(); + return IconTheme.JabRefIcons.PRINTED.getSmallIcon(); case PRIORITY: - return IconTheme.JabRefIcon.PRIORITY.getSmallIcon(); + return IconTheme.JabRefIcons.PRIORITY.getSmallIcon(); case QUALITY: - return IconTheme.JabRefIcon.QUALITY.getSmallIcon(); + return IconTheme.JabRefIcons.QUALITY.getSmallIcon(); case RANKING: - return IconTheme.JabRefIcon.RANKING.getIcon(); + return IconTheme.JabRefIcons.RANKING.getIcon(); case READ_STATUS: - return IconTheme.JabRefIcon.READ_STATUS.getSmallIcon(); + return IconTheme.JabRefIcons.READ_STATUS.getSmallIcon(); case RELEVANCE: - return IconTheme.JabRefIcon.RELEVANCE.getSmallIcon(); + return IconTheme.JabRefIcons.RELEVANCE.getSmallIcon(); + default: + throw new IllegalArgumentException("There is no icon mapping for special field " + field); + } + } + + public JabRefIcon getIcon() { + switch (field) { + case PRINTED: + return IconTheme.JabRefIcons.PRINTED; + case PRIORITY: + return IconTheme.JabRefIcons.PRIORITY; + case QUALITY: + return IconTheme.JabRefIcons.QUALITY; + case RANKING: + return IconTheme.JabRefIcons.RANKING; + case READ_STATUS: + return IconTheme.JabRefIcons.READ_STATUS; + case RELEVANCE: + return IconTheme.JabRefIcons.RELEVANCE; default: throw new IllegalArgumentException("There is no icon mapping for special field " + field); } diff --git a/src/main/java/org/jabref/gui/util/ViewModelTreeTableCellFactory.java b/src/main/java/org/jabref/gui/util/ViewModelTreeTableCellFactory.java index 98ade037f0a..d6e906e92ac 100644 --- a/src/main/java/org/jabref/gui/util/ViewModelTreeTableCellFactory.java +++ b/src/main/java/org/jabref/gui/util/ViewModelTreeTableCellFactory.java @@ -6,15 +6,11 @@ import javafx.scene.control.TreeTableCell; import javafx.scene.control.TreeTableColumn; import javafx.scene.input.MouseEvent; -import javafx.scene.paint.Paint; -import javafx.scene.text.Text; import javafx.util.Callback; +import org.jabref.gui.JabRefIcon; import org.jabref.model.strings.StringUtil; -import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; -import de.jensd.fx.glyphs.materialdesignicons.utils.MaterialDesignIconFactory; - /** * Constructs a {@link TreeTableCell} based on the view model of the row and a bunch of specified converter methods. * @@ -38,12 +34,8 @@ public ViewModelTreeTableCellFactory withGraphic(Callback toGraph return this; } - public ViewModelTreeTableCellFactory withIcon(Callback toIcon, Callback toColor) { - this.toGraphic = viewModel -> { - Text graphic = MaterialDesignIconFactory.get().createIcon(toIcon.call(viewModel)); - graphic.setFill(toColor.call(viewModel)); - return graphic; - }; + public ViewModelTreeTableCellFactory withIcon(Callback toIcon) { + this.toGraphic = viewModel -> toIcon.call(viewModel).getGraphicNode(); return this; } From 952c03257a791d6bd33b21195d3557bef9a6ee9a Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 29 Dec 2017 22:29:01 +0100 Subject: [PATCH 004/827] More icon related changes --- src/main/java/org/jabref/gui/JabRefFrame.java | 66 +++++++++---------- .../externalfiles/SynchronizeFileField.java | 3 +- .../ExternalFileTypeEditor.java | 8 +-- .../importer/actions/OpenDatabaseAction.java | 2 +- .../org/jabref/gui/menus/RightClickMenu.java | 32 ++++----- .../gui/openoffice/OpenOfficePanel.java | 6 +- .../jabref/gui/preftabs/TableColumnsTab.java | 8 +-- .../jabref/gui/search/GlobalSearchBar.java | 10 +-- 8 files changed, 67 insertions(+), 68 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 3e30b97409c..c759ce7083e 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -194,10 +194,10 @@ public class JabRefFrame extends JFrame implements OutputPrinter { IconTheme.getImage("about"), IconTheme.getImage("about")); private final AbstractAction jabrefFacebookAction = new OpenBrowserAction("https://www.facebook.com/JabRef/", "Facebook", Localization.lang("Opens JabRef's Facebook page"), - IconTheme.JabRefIcon.FACEBOOK.getSmallIcon(), IconTheme.JabRefIcon.FACEBOOK.getIcon()); + IconTheme.JabRefIcons.FACEBOOK.getSmallIcon(), IconTheme.JabRefIcons.FACEBOOK.getIcon()); private final AbstractAction jabrefBlogAction = new OpenBrowserAction("https://blog.jabref.org/", Localization.menuTitle("Blog"), Localization.lang("Opens JabRef's blog"), - IconTheme.JabRefIcon.BLOG.getSmallIcon(), IconTheme.JabRefIcon.BLOG.getIcon()); + IconTheme.JabRefIcons.BLOG.getSmallIcon(), IconTheme.JabRefIcons.BLOG.getIcon()); private final AbstractAction developmentVersionAction = new OpenBrowserAction("https://builds.jabref.org/master/", Localization.menuTitle("Development version"), Localization.lang("Opens a link where the current development version can be downloaded")); @@ -205,22 +205,22 @@ public class JabRefFrame extends JFrame implements OutputPrinter { "https://github.com/JabRef/jabref/blob/master/CHANGELOG.md", Localization.menuTitle("View change log"), Localization.lang("See what has been changed in the JabRef versions")); private final AbstractAction forkMeOnGitHubAction = new OpenBrowserAction("https://github.com/JabRef/jabref", - Localization.menuTitle("Fork me on GitHub"), Localization.lang("Opens JabRef's GitHub page"), IconTheme.JabRefIcon.GITHUB.getSmallIcon(), IconTheme.JabRefIcon.GITHUB.getIcon()); + Localization.menuTitle("Fork me on GitHub"), Localization.lang("Opens JabRef's GitHub page"), IconTheme.JabRefIcons.GITHUB.getSmallIcon(), IconTheme.JabRefIcons.GITHUB.getIcon()); private final AbstractAction donationAction = new OpenBrowserAction("https://github.com/JabRef/jabref/wiki/Donations", - Localization.menuTitle("Donate to JabRef"), Localization.lang("Donate to JabRef"), IconTheme.JabRefIcon.DONATE.getSmallIcon(), IconTheme.JabRefIcon.DONATE.getIcon()); + Localization.menuTitle("Donate to JabRef"), Localization.lang("Donate to JabRef"), IconTheme.JabRefIcons.DONATE.getSmallIcon(), IconTheme.JabRefIcons.DONATE.getIcon()); private final AbstractAction openForumAction = new OpenBrowserAction("http://discourse.jabref.org/", - Localization.menuTitle("Online help forum"), Localization.lang("Online help forum"), IconTheme.JabRefIcon.FORUM.getSmallIcon(), IconTheme.JabRefIcon.FORUM.getIcon()); + Localization.menuTitle("Online help forum"), Localization.lang("Online help forum"), IconTheme.JabRefIcons.FORUM.getSmallIcon(), IconTheme.JabRefIcons.FORUM.getIcon()); private final AbstractAction help = new HelpAction(Localization.menuTitle("Online help"), Localization.lang("Online help"), HelpFile.CONTENTS, Globals.getKeyPrefs().getKey(KeyBinding.HELP)); private final AbstractAction about = new AboutAction(Localization.menuTitle("About JabRef"), Localization.lang("About JabRef"), IconTheme.getImage("about")); private final AbstractAction editEntry = new GeneralAction(Actions.EDIT, Localization.menuTitle("Edit entry"), - Localization.lang("Edit entry"), Globals.getKeyPrefs().getKey(KeyBinding.EDIT_ENTRY), IconTheme.JabRefIcon.EDIT_ENTRY.getIcon()); + Localization.lang("Edit entry"), Globals.getKeyPrefs().getKey(KeyBinding.EDIT_ENTRY), IconTheme.JabRefIcons.EDIT_ENTRY.getIcon()); private final AbstractAction focusTable = new GeneralAction(Actions.FOCUS_TABLE, Localization.menuTitle("Focus entry table"), Localization.lang("Move the keyboard focus to the entry table"), Globals.getKeyPrefs().getKey(KeyBinding.FOCUS_ENTRY_TABLE)); private final AbstractAction save = new GeneralAction(Actions.SAVE, Localization.menuTitle("Save library"), - Localization.lang("Save library"), Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE), IconTheme.JabRefIcon.SAVE.getIcon()); + Localization.lang("Save library"), Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE), IconTheme.JabRefIcons.SAVE.getIcon()); private final AbstractAction saveAs = new GeneralAction(Actions.SAVE_AS, Localization.menuTitle("Save library as..."), Localization.lang("Save library as..."), Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE_AS)); @@ -234,55 +234,55 @@ public class JabRefFrame extends JFrame implements OutputPrinter { private final AbstractAction importNew = ImportFormats.getImportAction(this, true); private final AbstractAction sortTabs = new SortTabsAction(this); private final AbstractAction undo = new GeneralAction(Actions.UNDO, Localization.menuTitle("Undo"), - Localization.lang("Undo"), Globals.getKeyPrefs().getKey(KeyBinding.UNDO), IconTheme.JabRefIcon.UNDO.getIcon()); + Localization.lang("Undo"), Globals.getKeyPrefs().getKey(KeyBinding.UNDO), IconTheme.JabRefIcons.UNDO.getIcon()); private final AbstractAction redo = new GeneralAction(Actions.REDO, Localization.menuTitle("Redo"), - Localization.lang("Redo"), Globals.getKeyPrefs().getKey(KeyBinding.REDO), IconTheme.JabRefIcon.REDO.getIcon()); + Localization.lang("Redo"), Globals.getKeyPrefs().getKey(KeyBinding.REDO), IconTheme.JabRefIcons.REDO.getIcon()); private final AbstractAction forward = new GeneralAction(Actions.FORWARD, Localization.menuTitle("Forward"), - Localization.lang("Forward"), Globals.getKeyPrefs().getKey(KeyBinding.FORWARD), IconTheme.JabRefIcon.RIGHT.getIcon()); + Localization.lang("Forward"), Globals.getKeyPrefs().getKey(KeyBinding.FORWARD), IconTheme.JabRefIcons.RIGHT.getIcon()); private final AbstractAction back = new GeneralAction(Actions.BACK, Localization.menuTitle("Back"), - Localization.lang("Back"), Globals.getKeyPrefs().getKey(KeyBinding.BACK), IconTheme.JabRefIcon.LEFT.getIcon()); + Localization.lang("Back"), Globals.getKeyPrefs().getKey(KeyBinding.BACK), IconTheme.JabRefIcons.LEFT.getIcon()); private final AbstractAction deleteEntry = new GeneralAction(Actions.DELETE, Localization.menuTitle("Delete entry"), - Localization.lang("Delete entry"), Globals.getKeyPrefs().getKey(KeyBinding.DELETE_ENTRY), IconTheme.JabRefIcon.DELETE_ENTRY.getIcon()); + Localization.lang("Delete entry"), Globals.getKeyPrefs().getKey(KeyBinding.DELETE_ENTRY), IconTheme.JabRefIcons.DELETE_ENTRY.getIcon()); private final AbstractAction copy = new EditAction(Actions.COPY, Localization.menuTitle("Copy"), - Localization.lang("Copy"), Globals.getKeyPrefs().getKey(KeyBinding.COPY), IconTheme.JabRefIcon.COPY.getIcon()); + Localization.lang("Copy"), Globals.getKeyPrefs().getKey(KeyBinding.COPY), IconTheme.JabRefIcons.COPY.getIcon()); private final AbstractAction paste = new EditAction(Actions.PASTE, Localization.menuTitle("Paste"), - Localization.lang("Paste"), Globals.getKeyPrefs().getKey(KeyBinding.PASTE), IconTheme.JabRefIcon.PASTE.getIcon()); + Localization.lang("Paste"), Globals.getKeyPrefs().getKey(KeyBinding.PASTE), IconTheme.JabRefIcons.PASTE.getIcon()); private final AbstractAction cut = new EditAction(Actions.CUT, Localization.menuTitle("Cut"), - Localization.lang("Cut"), Globals.getKeyPrefs().getKey(KeyBinding.CUT), IconTheme.JabRefIcon.CUT.getIcon()); + Localization.lang("Cut"), Globals.getKeyPrefs().getKey(KeyBinding.CUT), IconTheme.JabRefIcons.CUT.getIcon()); private final AbstractAction openConsole = new GeneralAction(Actions.OPEN_CONSOLE, Localization.menuTitle("Open terminal here"), Localization.lang("Open terminal here"), Globals.getKeyPrefs().getKey(KeyBinding.OPEN_CONSOLE), - IconTheme.JabRefIcon.CONSOLE.getIcon()); + IconTheme.JabRefIcons.CONSOLE.getIcon()); private final AbstractAction pullChangesFromSharedDatabase = new GeneralAction(Actions.PULL_CHANGES_FROM_SHARED_DATABASE, Localization.menuTitle("Pull changes from shared database"), Localization.lang("Pull changes from shared database"), Globals.getKeyPrefs().getKey(KeyBinding.PULL_CHANGES_FROM_SHARED_DATABASE), - IconTheme.JabRefIcon.PULL.getIcon()); + IconTheme.JabRefIcons.PULL.getIcon()); private final AbstractAction mark = new GeneralAction(Actions.MARK_ENTRIES, Localization.menuTitle("Mark entries"), - Localization.lang("Mark entries"), Globals.getKeyPrefs().getKey(KeyBinding.MARK_ENTRIES), IconTheme.JabRefIcon.MARK_ENTRIES.getIcon()); + Localization.lang("Mark entries"), Globals.getKeyPrefs().getKey(KeyBinding.MARK_ENTRIES), IconTheme.JabRefIcons.MARK_ENTRIES.getIcon()); private final JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color")); private final AbstractAction unmark = new GeneralAction(Actions.UNMARK_ENTRIES, Localization.menuTitle("Unmark entries"), Localization.lang("Unmark entries"), - Globals.getKeyPrefs().getKey(KeyBinding.UNMARK_ENTRIES), IconTheme.JabRefIcon.UNMARK_ENTRIES.getIcon()); + Globals.getKeyPrefs().getKey(KeyBinding.UNMARK_ENTRIES), IconTheme.JabRefIcons.UNMARK_ENTRIES.getIcon()); private final AbstractAction unmarkAll = new GeneralAction(Actions.UNMARK_ALL, Localization.menuTitle("Unmark all")); private final AbstractAction toggleRelevance = new GeneralAction( new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getActionName(), new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getMenuString(), new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getToolTipText(), - IconTheme.JabRefIcon.RELEVANCE.getIcon()); + IconTheme.JabRefIcons.RELEVANCE.getIcon()); private final AbstractAction toggleQualityAssured = new GeneralAction( new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getActionName(), new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getMenuString(), new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getToolTipText(), - IconTheme.JabRefIcon.QUALITY_ASSURED.getIcon()); + IconTheme.JabRefIcons.QUALITY_ASSURED.getIcon()); private final AbstractAction togglePrinted = new GeneralAction( new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getActionName(), new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getMenuString(), new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getToolTipText(), - IconTheme.JabRefIcon.PRINTED.getIcon()); + IconTheme.JabRefIcons.PRINTED.getIcon()); private final AbstractAction normalSearch = new GeneralAction(Actions.SEARCH, Localization.menuTitle("Search"), - Localization.lang("Search"), Globals.getKeyPrefs().getKey(KeyBinding.SEARCH), IconTheme.JabRefIcon.SEARCH.getIcon()); + Localization.lang("Search"), Globals.getKeyPrefs().getKey(KeyBinding.SEARCH), IconTheme.JabRefIcons.SEARCH.getIcon()); private final AbstractAction manageSelectors = new GeneralAction(Actions.MANAGE_SELECTORS, Localization.menuTitle("Manage content selectors")); private final AbstractAction copyPreview = new GeneralAction(Actions.COPY_CITATION_HTML, Localization.lang("Copy preview"), @@ -314,7 +314,7 @@ public class JabRefFrame extends JFrame implements OutputPrinter { Localization.menuTitle("Edit strings"), Localization.lang("Edit strings"), Globals.getKeyPrefs().getKey(KeyBinding.EDIT_STRINGS), - IconTheme.JabRefIcon.EDIT_STRINGS.getIcon()); + IconTheme.JabRefIcons.EDIT_STRINGS.getIcon()); private final AbstractAction customizeAction = new CustomizeEntryTypeAction(); private final Action toggleToolbar = enableToggle(new AbstractAction(Localization.menuTitle("Hide/show toolbar")) { @@ -336,7 +336,7 @@ public void actionPerformed(ActionEvent e) { Localization.menuTitle("Toggle entry preview"), Localization.lang("Toggle entry preview"), Globals.getKeyPrefs().getKey(KeyBinding.TOGGLE_ENTRY_PREVIEW), - IconTheme.JabRefIcon.TOGGLE_ENTRY_PREVIEW.getIcon())); + IconTheme.JabRefIcons.TOGGLE_ENTRY_PREVIEW.getIcon())); private final AbstractAction nextPreviewStyle = new GeneralAction(Actions.NEXT_PREVIEW_STYLE, Localization.menuTitle("Next preview layout"), Globals.getKeyPrefs().getKey(KeyBinding.NEXT_PREVIEW_LAYOUT)); @@ -347,7 +347,7 @@ public void actionPerformed(ActionEvent e) { Localization.menuTitle("Autogenerate BibTeX keys"), Localization.lang("Autogenerate BibTeX keys"), Globals.getKeyPrefs().getKey(KeyBinding.AUTOGENERATE_BIBTEX_KEYS), - IconTheme.JabRefIcon.MAKE_KEY.getIcon()); + IconTheme.JabRefIcons.MAKE_KEY.getIcon()); private final AbstractAction writeXmpAction = new GeneralAction(Actions.WRITE_XMP, Localization.menuTitle("Write XMP-metadata to PDFs"), Localization.lang("Will write XMP-metadata to the PDFs linked from selected entries."), @@ -359,14 +359,14 @@ public void actionPerformed(ActionEvent e) { Localization.menuTitle("Open file"), Localization.lang("Open file"), Globals.getKeyPrefs().getKey(KeyBinding.OPEN_FILE), - IconTheme.JabRefIcon.FILE.getIcon()); + IconTheme.JabRefIcons.FILE.getIcon()); private final AbstractAction openUrl = new GeneralAction(Actions.OPEN_URL, Localization.menuTitle("Open URL or DOI"), Localization.lang("Open URL or DOI"), Globals.getKeyPrefs().getKey(KeyBinding.OPEN_URL_OR_DOI), - IconTheme.JabRefIcon.WWW.getIcon()); + IconTheme.JabRefIcons.WWW.getIcon()); private final AbstractAction dupliCheck = new GeneralAction(Actions.DUPLI_CHECK, - Localization.menuTitle("Find duplicates"), IconTheme.JabRefIcon.FIND_DUPLICATES.getIcon()); + Localization.menuTitle("Find duplicates"), IconTheme.JabRefIcons.FIND_DUPLICATES.getIcon()); private final AbstractAction plainTextImport = new GeneralAction(Actions.PLAIN_TEXT_IMPORT, Localization.menuTitle("New entry from plain text") + ELLIPSES, Globals.getKeyPrefs().getKey(KeyBinding.NEW_FROM_PLAIN_TEXT)); @@ -375,7 +375,7 @@ public void actionPerformed(ActionEvent e) { private final AbstractAction customFileTypesAction = ExternalFileTypeEditor.getAction(this); private final AbstractAction exportToClipboard = new GeneralAction(Actions.EXPORT_TO_CLIPBOARD, Localization.menuTitle("Export selected entries to clipboard"), - IconTheme.JabRefIcon.EXPORT_TO_CLIPBOARD.getIcon()); + IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD.getIcon()); private final AbstractAction autoSetFile = new GeneralAction(Actions.AUTO_SET_FILE, Localization.lang("Synchronize file links") + ELLIPSES, Globals.getKeyPrefs().getKey(KeyBinding.SYNCHRONIZE_FILES)); @@ -399,11 +399,11 @@ public void actionPerformed(ActionEvent e) { Localization.menuTitle("Cleanup entries") + ELLIPSES, Localization.lang("Cleanup entries"), Globals.getKeyPrefs().getKey(KeyBinding.CLEANUP), - IconTheme.JabRefIcon.CLEANUP_ENTRIES.getIcon()); + IconTheme.JabRefIcons.CLEANUP_ENTRIES.getIcon()); private final AbstractAction mergeEntries = new GeneralAction(Actions.MERGE_ENTRIES, Localization.menuTitle("Merge entries") + ELLIPSES, Localization.lang("Merge entries"), - IconTheme.JabRefIcon.MERGE_ENTRIES.getIcon()); + IconTheme.JabRefIcons.MERGE_ENTRIES.getIcon()); private final AbstractAction downloadFullText = new GeneralAction(Actions.DOWNLOAD_FULL_TEXT, Localization.menuTitle("Look up full text documents"), Globals.getKeyPrefs().getKey(KeyBinding.DOWNLOAD_FULL_TEXT)); @@ -415,7 +415,7 @@ public void actionPerformed(ActionEvent e) { Localization.lang("Find and remove duplicate BibTeX keys"), Globals.getKeyPrefs().getKey(KeyBinding.RESOLVE_DUPLICATE_BIBTEX_KEYS)); private final AbstractAction sendAsEmail = new GeneralAction(Actions.SEND_AS_EMAIL, - Localization.lang("Send as email"), IconTheme.JabRefIcon.EMAIL.getIcon()); + Localization.lang("Send as email"), IconTheme.JabRefIcons.EMAIL.getIcon()); private final MassSetFieldAction massSetField = new MassSetFieldAction(this); private final ManageKeywordsAction manageKeywords = new ManageKeywordsAction(this); private final JMenu lookupIdentifiers = JabRefFrame.subMenu(Localization.menuTitle("Look up document identifier...")); diff --git a/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java b/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java index 7f8a5011fa7..c822f61458f 100644 --- a/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java +++ b/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java @@ -207,8 +207,7 @@ public void run() { // User doesn't want to handle this unknown link type. } else if (answer == JOptionPane.YES_OPTION) { // User wants to define the new file type. Show the dialog: - ExternalFileType newType = new ExternalFileType(flEntry.getType().get().getName(), "", "", - "", "new", IconTheme.JabRefIcon.FILE.getSmallIcon()); + ExternalFileType newType = new ExternalFileType(flEntry.getType().get().getName(), "", "", "", "new", IconTheme.JabRefIcons.FILE); ExternalFileTypeEntryEditor editor = new ExternalFileTypeEntryEditor(panel.frame(), newType); editor.setVisible(true); if (editor.okPressed()) { diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java index ebfaa5c707d..bf286e86ed3 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java @@ -53,9 +53,9 @@ public class ExternalFileTypeEditor extends JabRefDialog { private FileTypeTableModel tableModel; private final JButton ok = new JButton(Localization.lang("OK")); private final JButton cancel = new JButton(Localization.lang("Cancel")); - private final JButton add = new JButton(IconTheme.JabRefIcon.ADD_NOBOX.getIcon()); - private final JButton remove = new JButton(IconTheme.JabRefIcon.REMOVE_NOBOX.getIcon()); - private final JButton edit = new JButton(IconTheme.JabRefIcon.EDIT.getIcon()); + private final JButton add = new JButton(IconTheme.JabRefIcons.ADD_NOBOX.getIcon()); + private final JButton remove = new JButton(IconTheme.JabRefIcons.REMOVE_NOBOX.getIcon()); + private final JButton edit = new JButton(IconTheme.JabRefIcons.EDIT.getIcon()); private final JButton toDefaults = new JButton(Localization.lang("Default")); private final EditListener editListener = new EditListener(); @@ -125,7 +125,7 @@ public void actionPerformed(ActionEvent e) { add.addActionListener(e -> { // Generate a new file type: ExternalFileType type = new ExternalFileType("", "", "", "", "new", - IconTheme.JabRefIcon.FILE.getSmallIcon()); + IconTheme.JabRefIcons.FILE); // Show the file type editor: getEditor(type).setVisible(true); if (entryEditor.okPressed()) { 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 a31abf7db04..814daa83dd8 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -71,7 +71,7 @@ public class OpenDatabaseAction extends MnemonicAwareAction { private final JabRefFrame frame; public OpenDatabaseAction(JabRefFrame frame, boolean showDialog) { - super(IconTheme.JabRefIcon.OPEN.getIcon()); + super(IconTheme.JabRefIcons.OPEN.getIcon()); this.frame = frame; this.showDialog = showDialog; putValue(Action.NAME, Localization.menuTitle("Open library")); diff --git a/src/main/java/org/jabref/gui/menus/RightClickMenu.java b/src/main/java/org/jabref/gui/menus/RightClickMenu.java index 9de2ba35609..f77f2ed3101 100644 --- a/src/main/java/org/jabref/gui/menus/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/menus/RightClickMenu.java @@ -88,42 +88,42 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { } copySpecialMenu.add(new GeneralAction(Actions.EXPORT_TO_CLIPBOARD, Localization.lang("Export to clipboard"), - IconTheme.JabRefIcon.EXPORT_TO_CLIPBOARD.getSmallIcon())); + IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD.getSmallIcon())); - add(new GeneralAction(Actions.COPY, Localization.lang("Copy"), IconTheme.JabRefIcon.COPY.getSmallIcon(), KeyBinding.COPY)); + add(new GeneralAction(Actions.COPY, Localization.lang("Copy"), IconTheme.JabRefIcons.COPY.getSmallIcon(), KeyBinding.COPY)); add(copySpecialMenu); - add(new GeneralAction(Actions.PASTE, Localization.lang("Paste"), IconTheme.JabRefIcon.PASTE.getSmallIcon(), KeyBinding.PASTE)); - add(new GeneralAction(Actions.CUT, Localization.lang("Cut"), IconTheme.JabRefIcon.CUT.getSmallIcon(), KeyBinding.CUT)); - add(new GeneralAction(Actions.DELETE, Localization.lang("Delete"), IconTheme.JabRefIcon.DELETE_ENTRY.getSmallIcon(), KeyBinding.DELETE_ENTRY)); - GeneralAction printPreviewAction = new GeneralAction(Actions.PRINT_PREVIEW, Localization.lang("Print entry preview"), IconTheme.JabRefIcon.PRINTED.getSmallIcon()); + add(new GeneralAction(Actions.PASTE, Localization.lang("Paste"), IconTheme.JabRefIcons.PASTE.getSmallIcon(), KeyBinding.PASTE)); + add(new GeneralAction(Actions.CUT, Localization.lang("Cut"), IconTheme.JabRefIcons.CUT.getSmallIcon(), KeyBinding.CUT)); + add(new GeneralAction(Actions.DELETE, Localization.lang("Delete"), IconTheme.JabRefIcons.DELETE_ENTRY.getSmallIcon(), KeyBinding.DELETE_ENTRY)); + GeneralAction printPreviewAction = new GeneralAction(Actions.PRINT_PREVIEW, Localization.lang("Print entry preview"), IconTheme.JabRefIcons.PRINTED.getSmallIcon()); printPreviewAction.setEnabled(!multiple); add(printPreviewAction); addSeparator(); - add(new GeneralAction(Actions.SEND_AS_EMAIL, Localization.lang("Send as email"), IconTheme.JabRefIcon.EMAIL.getSmallIcon())); + add(new GeneralAction(Actions.SEND_AS_EMAIL, Localization.lang("Send as email"), IconTheme.JabRefIcons.EMAIL.getSmallIcon())); addSeparator(); add(new CopyFilesAction()); JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color")); - markSpecific.setIcon(IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon()); + markSpecific.setIcon(IconTheme.JabRefIcons.MARK_ENTRIES.getSmallIcon()); for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) { markSpecific.add(new MarkEntriesAction(frame, i).getMenuItem()); } if (multiple) { - add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entries"), IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon(), KeyBinding.MARK_ENTRIES)); + add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entries"), IconTheme.JabRefIcons.MARK_ENTRIES.getSmallIcon(), KeyBinding.MARK_ENTRIES)); add(markSpecific); - add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entries"), IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon(), KeyBinding.UNMARK_ENTRIES)); + add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entries"), IconTheme.JabRefIcons.UNMARK_ENTRIES.getSmallIcon(), KeyBinding.UNMARK_ENTRIES)); } else if (be != null) { Optional marked = be.getField(FieldName.MARKED_INTERNAL); // We have to check for "" too as the marked field may be empty if ((!marked.isPresent()) || marked.get().isEmpty()) { - add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entry"), IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon(), KeyBinding.MARK_ENTRIES)); + add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entry"), IconTheme.JabRefIcons.MARK_ENTRIES.getSmallIcon(), KeyBinding.MARK_ENTRIES)); add(markSpecific); } else { add(markSpecific); - add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entry"), IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon(), KeyBinding.UNMARK_ENTRIES)); + add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entry"), IconTheme.JabRefIcons.UNMARK_ENTRIES.getSmallIcon(), KeyBinding.UNMARK_ENTRIES)); } } @@ -174,7 +174,7 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { add(openFileAction); GeneralAction openUrlAction = new GeneralAction(Actions.OPEN_URL, Localization.lang("Open URL or DOI"), - IconTheme.JabRefIcon.WWW.getSmallIcon(), KeyBinding.OPEN_URL_OR_DOI); + IconTheme.JabRefIcons.WWW.getSmallIcon(), KeyBinding.OPEN_URL_OR_DOI); openUrlAction.setEnabled(isFieldSetForSelectedEntry(FieldName.URL) || isFieldSetForSelectedEntry(FieldName.DOI)); add(openUrlAction); @@ -190,14 +190,14 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { add(frame.getMassSetField()); GeneralAction attachFileAction = new GeneralAction(Actions.ADD_FILE_LINK, Localization.lang("Attach file"), - IconTheme.JabRefIcon.ATTACH_FILE.getSmallIcon()); + IconTheme.JabRefIcons.ATTACH_FILE.getSmallIcon()); attachFileAction.setEnabled(!multiple); add(attachFileAction); add(frame.getManageKeywords()); GeneralAction mergeEntriesAction = new GeneralAction(Actions.MERGE_ENTRIES, - Localization.lang("Merge entries") + "...", IconTheme.JabRefIcon.MERGE_ENTRIES.getSmallIcon()); + Localization.lang("Merge entries") + "...", IconTheme.JabRefIcons.MERGE_ENTRIES.getSmallIcon()); mergeEntriesAction.setEnabled(areExactlyTwoEntriesSelected()); add(mergeEntriesAction); @@ -279,7 +279,7 @@ private Icon getFileIconForSelectedEntry() { } } } - return IconTheme.JabRefIcon.FILE.getSmallIcon(); + return IconTheme.JabRefIcons.FILE.getSmallIcon(); } class GeneralAction extends AbstractAction { diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index 81e76f6f6f4..0ea66468474 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -114,7 +114,7 @@ public class OpenOfficePanel extends AbstractWorker { private final StyleLoader loader; public OpenOfficePanel(JabRefFrame jabRefFrame, SidePaneManager spManager) { - Icon connectImage = IconTheme.JabRefIcon.CONNECT_OPEN_OFFICE.getSmallIcon(); + Icon connectImage = IconTheme.JabRefIcons.CONNECT_OPEN_OFFICE.getSmallIcon(); connect = new JButton(connectImage); manualConnect = new JButton(connectImage); @@ -123,10 +123,10 @@ public OpenOfficePanel(JabRefFrame jabRefFrame, SidePaneManager spManager) { connect.setPreferredSize(new Dimension(24, 24)); manualConnect.setPreferredSize(new Dimension(24, 24)); - selectDocument = new JButton(IconTheme.JabRefIcon.OPEN.getSmallIcon()); + selectDocument = new JButton(IconTheme.JabRefIcons.OPEN.getSmallIcon()); selectDocument.setToolTipText(Localization.lang("Select Writer document")); selectDocument.setPreferredSize(new Dimension(24, 24)); - update = new JButton(IconTheme.JabRefIcon.REFRESH.getSmallIcon()); + update = new JButton(IconTheme.JabRefIcons.REFRESH.getSmallIcon()); update.setToolTipText(Localization.lang("Sync OpenOffice/LibreOffice bibliography")); update.setPreferredSize(new Dimension(24, 24)); preferences = new OpenOfficePreferences(Globals.prefs); diff --git a/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java b/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java index 5176a32b1a3..6e600ed7e13 100644 --- a/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java +++ b/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java @@ -453,7 +453,7 @@ public void setValues() { class DeleteRowAction extends AbstractAction { public DeleteRowAction() { - super("Delete row", IconTheme.JabRefIcon.REMOVE_NOBOX.getIcon()); + super("Delete row", IconTheme.JabRefIcons.REMOVE_NOBOX.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Delete rows")); } @@ -483,7 +483,7 @@ public void actionPerformed(ActionEvent e) { class AddRowAction extends AbstractAction { public AddRowAction() { - super("Add row", IconTheme.JabRefIcon.ADD_NOBOX.getIcon()); + super("Add row", IconTheme.JabRefIcons.ADD_NOBOX.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Insert rows")); } @@ -534,7 +534,7 @@ public void swap(int i, int j) { class MoveRowUpAction extends AbstractMoveRowAction { public MoveRowUpAction() { - super("Up", IconTheme.JabRefIcon.UP.getIcon()); + super("Up", IconTheme.JabRefIcons.UP.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Move up")); } @@ -567,7 +567,7 @@ public void actionPerformed(ActionEvent e) { class MoveRowDownAction extends AbstractMoveRowAction { public MoveRowDownAction() { - super("Down", IconTheme.JabRefIcon.DOWN.getIcon()); + super("Down", IconTheme.JabRefIcons.DOWN.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Down")); } diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 0ae87009cae..5ded0d496b0 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -69,7 +69,7 @@ public class GlobalSearchBar extends JPanel { private final JButton searchModeButton = new JButton(); private final JLabel currentResults = new JLabel(""); private final SearchQueryHighlightObservable searchQueryHighlightObservable = new SearchQueryHighlightObservable(); - private final JButton openCurrentResultsInDialog = new JButton(IconTheme.JabRefIcon.OPEN_IN_NEW_WINDOW.getSmallIcon()); + private final JButton openCurrentResultsInDialog = new JButton(IconTheme.JabRefIcons.OPEN_IN_NEW_WINDOW.getSmallIcon()); private final JFXPanel container; private SearchWorker searchWorker; private GlobalSearchWorker globalSearchWorker; @@ -93,7 +93,7 @@ public GlobalSearchBar(JabRefFrame frame) { currentResults.setPreferredSize(new Dimension(150, 5)); currentResults.setFont(currentResults.getFont().deriveFont(Font.BOLD)); - JToggleButton globalSearch = new JToggleButton(IconTheme.JabRefIcon.GLOBAL_SEARCH.getSmallIcon(), searchPreferences.isGlobalSearch()); + JToggleButton globalSearch = new JToggleButton(IconTheme.JabRefIcons.GLOBAL_SEARCH.getSmallIcon(), searchPreferences.isGlobalSearch()); globalSearch.setToolTipText(Localization.lang("Search in all open libraries")); // default action to be performed for toggling globalSearch @@ -152,7 +152,7 @@ public void actionPerformed(ActionEvent e) { globalSearch.addActionListener(globalSearchStandardAction); - openCurrentResultsInDialog.setDisabledIcon(IconTheme.JabRefIcon.OPEN_IN_NEW_WINDOW.getSmallIcon().createDisabledIcon()); + openCurrentResultsInDialog.setDisabledIcon(IconTheme.JabRefIcons.OPEN_IN_NEW_WINDOW.disabled().getSmallIcon()); openCurrentResultsInDialog.addActionListener(event -> { if (globalSearch.isSelected()) { performGlobalSearch(); @@ -163,7 +163,7 @@ public void actionPerformed(ActionEvent e) { openCurrentResultsInDialog.setEnabled(false); updateOpenCurrentResultsTooltip(globalSearch.isSelected()); - regularExp = new JToggleButton(IconTheme.JabRefIcon.REG_EX.getSmallIcon(), + regularExp = new JToggleButton(IconTheme.JabRefIcons.REG_EX.getSmallIcon(), searchPreferences.isRegularExpression()); regularExp.setToolTipText(Localization.lang("regular expression")); regularExp.addActionListener(event -> { @@ -171,7 +171,7 @@ public void actionPerformed(ActionEvent e) { performSearch(); }); - caseSensitive = new JToggleButton(IconTheme.JabRefIcon.CASE_SENSITIVE.getSmallIcon(), + caseSensitive = new JToggleButton(IconTheme.JabRefIcons.CASE_SENSITIVE.getSmallIcon(), searchPreferences.isCaseSensitive()); caseSensitive.setToolTipText(Localization.lang("Case sensitive")); caseSensitive.addActionListener(event -> { From 41eeb3c97c7ce7b06ac8a40213ae025c215737cd Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sun, 31 Dec 2017 12:48:55 +0100 Subject: [PATCH 005/827] First working prototype --- src/main/java/org/jabref/gui/BasePanel.java | 262 +++++-------- .../java/org/jabref/gui/EntryTypeDialog.java | 2 +- src/main/java/org/jabref/gui/GUIGlobals.java | 95 ----- src/main/java/org/jabref/gui/JabRefFrame.java | 220 +++++------ src/main/java/org/jabref/gui/Main.css | 5 + .../java/org/jabref/gui/PreviewPanel.java | 2 +- .../java/org/jabref/gui/SidePaneManager.java | 8 +- .../gui/actions/IntegrityCheckAction.java | 2 +- .../jabref/gui/actions/SortTabsAction.java | 15 +- .../jabref/gui/auximport/FromAuxDialog.java | 13 +- .../EntryCustomizationDialog.java | 9 - .../jabref/gui/customjfx/CustomJFXPanel.java | 2 + .../gui/exporter/SaveDatabaseAction.java | 4 +- .../externalfiles/SynchronizeFileField.java | 1 - .../gui/externalfiles/WriteXMPAction.java | 9 +- .../ExternalFileTypeEditor.java | 3 - .../gui/groups/EntryTableTransferHandler.java | 3 + .../jabref/gui/importer/ImportMenuItem.java | 2 +- .../actions/AppendDatabaseAction.java | 4 +- .../importer/actions/OpenDatabaseAction.java | 6 +- .../org/jabref/gui/maintable/CellFactory.java | 103 +++++ .../org/jabref/gui/maintable/MainTable.css | 48 +++ .../org/jabref/gui/maintable/MainTable.java | 355 +++++------------- .../jabref/gui/maintable/MainTableColumn.java | 159 +------- .../gui/maintable/MainTableDataModel.java | 17 +- .../jabref/gui/maintable/MainTableFormat.java | 153 -------- .../maintable/MainTableHeaderRenderer.java | 41 -- .../maintable/MainTableSelectionListener.java | 71 ++-- .../PersistenceTableColumnListener.java | 10 +- .../PreventDraggingJTableHeader.java | 97 ----- .../SpecialMainTableColumnsBuilder.java | 203 ---------- .../org/jabref/gui/menus/RightClickMenu.java | 16 +- .../gui/openoffice/OpenOfficePanel.java | 4 +- .../jabref/gui/preftabs/TableColumnsTab.java | 8 +- .../jabref/gui/preftabs/TablePrefsTab.java | 7 +- .../jabref/gui/search/GlobalSearchBar.java | 15 +- .../jabref/gui/search/SearchResultFrame.java | 2 +- .../org/jabref/gui/search/SearchWorker.java | 3 +- .../gui/shared/SharedDatabaseUIManager.java | 3 +- .../org/jabref/gui/util/BindingsHelper.java | 15 + .../gui/util/ValueTableCellFactory.java | 2 +- .../gui/util/ViewModelTableRowFactory.java | 39 ++ .../org/jabref/pdfimport/PdfImporter.java | 4 +- .../jabref/preferences/JabRefPreferences.java | 9 +- .../jabref/gui/search/SearchResultsTest.java | 10 +- 45 files changed, 624 insertions(+), 1437 deletions(-) create mode 100644 src/main/java/org/jabref/gui/maintable/CellFactory.java create mode 100644 src/main/java/org/jabref/gui/maintable/MainTable.css delete mode 100644 src/main/java/org/jabref/gui/maintable/MainTableFormat.java delete mode 100644 src/main/java/org/jabref/gui/maintable/MainTableHeaderRenderer.java delete mode 100644 src/main/java/org/jabref/gui/maintable/PreventDraggingJTableHeader.java delete mode 100644 src/main/java/org/jabref/gui/maintable/SpecialMainTableColumnsBuilder.java create mode 100644 src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 1303101ed58..4eced8b9227 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -5,9 +5,6 @@ import java.awt.datatransfer.ClipboardOwner; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; -import java.awt.event.ActionEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; import java.io.StringReader; @@ -27,7 +24,6 @@ import java.util.Set; import java.util.stream.Collectors; -import javax.swing.AbstractAction; import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.JTextArea; @@ -35,11 +31,12 @@ import javax.swing.undo.CannotRedoException; import javax.swing.undo.CannotUndoException; -import javafx.application.Platform; -import javafx.embed.swing.JFXPanel; +import javafx.beans.binding.Bindings; import javafx.geometry.Orientation; -import javafx.scene.Scene; +import javafx.scene.Node; +import javafx.scene.control.ScrollPane; import javafx.scene.control.SplitPane; +import javafx.scene.layout.AnchorPane; import javafx.scene.layout.StackPane; import org.jabref.Globals; @@ -56,7 +53,6 @@ import org.jabref.gui.collab.DatabaseChangeMonitor; import org.jabref.gui.collab.FileUpdatePanel; import org.jabref.gui.contentselector.ContentSelectorDialog; -import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.entryeditor.EntryEditor; import org.jabref.gui.exporter.ExportToClipboardAction; @@ -75,11 +71,8 @@ import org.jabref.gui.importer.actions.AppendDatabaseAction; import org.jabref.gui.journals.AbbreviateAction; import org.jabref.gui.journals.UnabbreviateAction; -import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.maintable.MainTable; import org.jabref.gui.maintable.MainTableDataModel; -import org.jabref.gui.maintable.MainTableFormat; -import org.jabref.gui.maintable.MainTableSelectionListener; import org.jabref.gui.mergeentries.MergeEntriesDialog; import org.jabref.gui.mergeentries.MergeWithFetchedEntryAction; import org.jabref.gui.plaintextimport.TextInputDialog; @@ -170,14 +163,11 @@ public class BasePanel extends StackPane implements ClipboardOwner { private final Map actions = new HashMap<>(); private final SidePaneManager sidePaneManager; private final PreviewPanel preview; - private final JFXPanel previewContainer; // To contain instantiated entry editors. This is to save time // As most enums, this must not be null private BasePanelMode mode = BasePanelMode.SHOWING_NOTHING; private final EntryEditor entryEditor; - private final JFXPanel entryEditorContainer; - private MainTableSelectionListener selectionListener; private SplitPane splitPane; private boolean saving; @@ -187,7 +177,6 @@ public class BasePanel extends StackPane implements ClipboardOwner { private boolean nonUndoableChange; // Used to track whether the base has changed since last save. private MainTable mainTable; - private MainTableFormat tableFormat; private BibEntry showing; // Variable to prevent erroneous update of back/forward histories at the time // when a Back or Forward operation is being processed: @@ -244,38 +233,9 @@ public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) { this.getDatabase().registerListener(new UpdateTimestampListener(Globals.prefs)); entryEditor = new EntryEditor(this); - entryEditorContainer = setupEntryEditor(entryEditor); this.preview = new PreviewPanel(this, getBibDatabaseContext()); DefaultTaskExecutor.runInJavaFXThread(() -> frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview)); - this.previewContainer = CustomJFXPanel.wrap(new Scene(preview)); - } - - private static JFXPanel setupEntryEditor(EntryEditor entryEditor) { - JFXPanel container = CustomJFXPanel.wrap(new Scene(entryEditor)); - container.addKeyListener(new KeyAdapter() { - - @Override - public void keyPressed(KeyEvent e) { - - //We need to consume this event here to prevent the propgation of keybinding events back to the JFrame - Optional keyBinding = Globals.getKeyPrefs().mapToKeyBinding(e); - if (keyBinding.isPresent()) { - switch (keyBinding.get()) { - case CUT: - case COPY: - case PASTE: - case DELETE_ENTRY: - case SELECT_ALL: - e.consume(); - break; - default: - //do nothing - } - } - } - }); - return container; } public static void runWorker(AbstractWorker worker) throws Exception { @@ -373,7 +333,7 @@ private void setupActions() { }); // The action for opening an entry editor. - actions.put(Actions.EDIT, (BaseAction) selectionListener::editSignalled); + actions.put(Actions.EDIT, (BaseAction) this::showAndEdit); // The action for saving a database. actions.put(Actions.SAVE, saveAction); @@ -404,7 +364,7 @@ private void setupActions() { // only the text representation seems to get as far as the X clipboard, at least on my system) actions.put(Actions.PASTE, (BaseAction) () -> paste()); - actions.put(Actions.SELECT_ALL, (BaseAction) mainTable::selectAll); + actions.put(Actions.SELECT_ALL, (BaseAction) mainTable.getSelectionModel()::selectAll); // The action for opening the preamble editor actions.put(Actions.EDIT_PREAMBLE, (BaseAction) () -> { @@ -513,19 +473,6 @@ public void update() { } markBaseChanged(); numSelected = entries.size(); - - //////////////////////////////////////////////////////////////////////////////// - // Prevent selection loss for autogenerated BibTeX-Keys - //////////////////////////////////////////////////////////////////////////////// - for (final BibEntry bibEntry : entries) { - SwingUtilities.invokeLater(() -> { - final int row = mainTable.findEntry(bibEntry); - if ((row >= 0) && (mainTable.getSelectedRowCount() < entries.size())) { - mainTable.addRowSelectionInterval(row, row); - } - }); - } - //////////////////////////////////////////////////////////////////////////////// output(formatOutputMessage(Localization.lang("Generated BibTeX key for"), numSelected)); frame.unblock(); } @@ -629,7 +576,7 @@ public void update() { actions.put(Actions.PLAIN_TEXT_IMPORT, (BaseAction) () -> { // get Type of new entry EntryTypeDialog etd = new EntryTypeDialog(frame); - etd.setLocationRelativeTo(BasePanel.this); + etd.setLocationRelativeTo(frame); etd.setVisible(true); EntryType tp = etd.getChoice(); if (tp == null) { @@ -638,7 +585,7 @@ public void update() { BibEntry bibEntry = new BibEntry(tp.getName()); TextInputDialog tidialog = new TextInputDialog(frame, bibEntry); - tidialog.setLocationRelativeTo(BasePanel.this); + tidialog.setLocationRelativeTo(frame); tidialog.setVisible(true); if (tidialog.okPressed()) { @@ -720,7 +667,7 @@ public void update() { .withPreviewPanelEnabled(enabled) .build(); Globals.prefs.storePreviewPreferences(newPreviewPreferences); - setPreviewActiveBasePanels(enabled); + DefaultTaskExecutor.runInJavaFXThread(() -> setPreviewActiveBasePanels(enabled)); frame.setPreviewToggle(enabled); }); @@ -767,22 +714,7 @@ private void copyCitationToClipboard(CitationStyleOutputFormat outputFormat) { private void copy() { List bes = mainTable.getSelectedEntries(); - if (bes.isEmpty()) { - // The user maybe selected a single cell. - // TODO: Check if this can actually happen - int[] rows = mainTable.getSelectedRows(); - int[] cols = mainTable.getSelectedColumns(); - if ((cols.length == 1) && (rows.length == 1)) { - // Copy single value. - Object o = mainTable.getValueAt(rows[0], cols[0]); - if (o != null) { - StringSelection ss = new StringSelection(o.toString()); - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this); - - output(Localization.lang("Copied cell contents") + '.'); - } - } - } else { + if (!bes.isEmpty()) { TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes); // ! look at ClipBoardManager Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, BasePanel.this); @@ -820,12 +752,13 @@ private void delete(boolean cut, List entries) { return; } + // TODO: check if needed // select the next entry to stay at the same place as before (or the previous if we're already at the end) - if (mainTable.getSelectedRow() != (mainTable.getRowCount() - 1)) { - selectNextEntry(); - } else { - selectPreviousEntry(); - } + //if (mainTable.getSelectedRow() != (mainTable.getRowCount() - 1)) { + // selectNextEntry(); + //} else { + // selectPreviousEntry(); + //} NamedCompound compound; if (cut) { @@ -894,11 +827,11 @@ private void paste() { output(formatOutputMessage(Localization.lang("Pasted"), bes.size())); markBaseChanged(); - highlightEntry(firstBE); + clearAndSelect(firstBE); mainTable.requestFocus(); if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) { - selectionListener.editSignalled(firstBE); + showAndEdit(firstBE); } } } @@ -1055,7 +988,7 @@ private void openExternalFile() { } FileListEntry flEntry = fileListTableModel.getEntry(0); ExternalFileMenuItem item = new ExternalFileMenuItem(frame(), entry, "", flEntry.getLink(), - flEntry.getType().get().getIcon(), bibDatabaseContext, flEntry.getType()); + flEntry.getType().get().getIcon().getSmallIcon(), bibDatabaseContext, flEntry.getType()); item.doClick(); }); } @@ -1116,7 +1049,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc, } catch (SaveException ex) { if (ex.specificEntry()) { // Error occurred during processing of the entry. Highlight it: - highlightEntry(ex.getEntry()); + clearAndSelect(ex.getEntry()); showAndEdit(ex.getEntry()); } else { LOGGER.warn("Could not save", ex); @@ -1218,7 +1151,7 @@ public BibEntry newEntry(EntryType type) { mode = BasePanelMode.WILL_SHOW_EDITOR; } - highlightEntry(be); + clearAndSelect(be); // The database just changed. markBaseChanged(); @@ -1252,9 +1185,9 @@ public void insertEntry(final BibEntry bibEntry) { markBaseChanged(); // The database just changed. if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) { - selectionListener.editSignalled(bibEntry); + showAndEdit(bibEntry); } - highlightEntry(bibEntry); + clearAndSelect(bibEntry); } catch (KeyCollisionException ex) { LOGGER.info("Collision for bibtex key" + bibEntry.getId(), ex); } @@ -1263,8 +1196,8 @@ public void insertEntry(final BibEntry bibEntry) { public void editEntryByIdAndFocusField(final String entryId, final String fieldName) { bibDatabaseContext.getDatabase().getEntryById(entryId).ifPresent(entry -> { - mainTable.setSelected(mainTable.findEntry(entry)); - selectionListener.editSignalled(); + clearAndSelect(entry); + //selectionListener.editSignalled(); showAndEdit(entry); entryEditor.setFocusToField(fieldName); }); @@ -1278,21 +1211,15 @@ private void createMainTable() { bibDatabaseContext.getDatabase().registerListener(tableModel.getListSynchronizer()); bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.getInstance()); - tableFormat = new MainTableFormat(bibDatabaseContext.getDatabase()); - tableFormat.updateTableFormat(); - mainTable = new MainTable(tableFormat, tableModel, frame, this); + mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext.getDatabase()); - selectionListener = new MainTableSelectionListener(this, mainTable); mainTable.updateFont(); - mainTable.addSelectionListener(selectionListener); - mainTable.addMouseListener(selectionListener); - mainTable.addKeyListener(selectionListener); - mainTable.addFocusListener(selectionListener); // Add the listener that binds selection to state manager (TODO: should be replaced by proper JavaFX binding as soon as table is implemented in JavaFX) - mainTable.addSelectionListener(listEvent -> Platform - .runLater(() -> Globals.stateManager.setSelectedEntries(mainTable.getSelectedEntries()))); + mainTable.addSelectionListener(listEvent -> Globals.stateManager.setSelectedEntries(mainTable.getSelectedEntries())); + // TODO: Register these actions globally + /* String clearSearch = "clearSearch"; mainTable.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.CLEAR_SEARCH), clearSearch); mainTable.getActionMap().put(clearSearch, new AbstractAction() { @@ -1381,11 +1308,12 @@ public void keyPressed(KeyEvent e) { } } }); + */ } public void setupMainPanel() { splitPane = new SplitPane(); - splitPane.setOrientation(Orientation.HORIZONTAL); + splitPane.setOrientation(Orientation.VERTICAL); adjustSplitter(); // restore last splitting state (before mainTable is created as creation affects the stored size of the entryEditors) // check whether a mainTable already existed and a floatSearch was active @@ -1393,16 +1321,13 @@ public void setupMainPanel() { createMainTable(); - splitPane.getItems().add(mainTable.getPane()); - - // If an entry is currently being shown, make sure it stays shown. - if (mode == BasePanelMode.SHOWING_PREVIEW) { - mode = BasePanelMode.SHOWING_NOTHING; - highlightEntry(selectionListener.getPreview().getEntry()); - } else if (mode == BasePanelMode.SHOWING_EDITOR) { - mode = BasePanelMode.SHOWING_NOTHING; - } - + ScrollPane pane = mainTable.getPane(); + AnchorPane anchorPane = new AnchorPane(pane); + AnchorPane.setBottomAnchor(pane, 0.0); + AnchorPane.setTopAnchor(pane, 0.0); + AnchorPane.setLeftAnchor(pane, 0.0); + AnchorPane.setRightAnchor(pane, 0.0); + splitPane.getItems().add(anchorPane); this.getChildren().setAll(splitPane); // Set up name autocompleter for search: @@ -1416,9 +1341,10 @@ public void setupMainPanel() { if (floatSearchActive) { mainTable.showFloatSearch(); } - - // saves the divider position as soon as it changes - EasyBind.subscribe(splitPane.getDividers().get(0).positionProperty(), position -> saveDividerLocation(position)); + // Saves the divider position as soon as it changes + EasyBind.monadic(Bindings.valueAt(splitPane.getDividers(), 0)) + .flatMap(SplitPane.Divider::positionProperty) + .subscribe((observable, oldValue, newValue) -> saveDividerLocation(newValue)); } /** @@ -1487,35 +1413,46 @@ public EntryEditor getEntryEditor() { * @param entry The entry to edit. */ public void showAndEdit(BibEntry entry) { - if (mode == BasePanelMode.SHOWING_EDITOR) { - Globals.prefs.putInt(JabRefPreferences.ENTRY_EDITOR_HEIGHT, splitPane.getHeight() - splitPane.getDividerLocation()); - } mode = BasePanelMode.SHOWING_EDITOR; - splitPane.setBottomComponent(entryEditorContainer); + showBottomPane(entryEditor); if (entry != getShowing()) { entryEditor.setEntry(entry); newEntryShowing(entry); } entryEditor.requestFocus(); + } + + private void showBottomPane(Node pane) { + if (splitPane.getItems().size() == 2) { + splitPane.getItems().set(1, pane); + } else { + splitPane.getItems().add(1, pane); + } adjustSplitter(); } + private void showAndEdit() { + if (!mainTable.getSelectedEntries().isEmpty()) { + showAndEdit(mainTable.getSelectedEntries().get(0)); + } + } + /** * Sets the given preview panel as the bottom component in the split panel. Updates the mode to SHOWING_PREVIEW. * * @param entry The entry to show in the preview. */ - public void showPreview(BibEntry entry) { - preview.setEntry(entry); + private void showPreview(BibEntry entry) { mode = BasePanelMode.SHOWING_PREVIEW; - splitPane.setBottomComponent(previewContainer); - adjustSplitter(); + showBottomPane(preview); + + preview.setEntry(entry); } private void showPreview() { - if (!mainTable.getSelected().isEmpty()) { - showPreview(mainTable.getSelected().get(0)); + if (!mainTable.getSelectedEntries().isEmpty()) { + showPreview(mainTable.getSelectedEntries().get(0)); } } @@ -1540,44 +1477,53 @@ private void cyclePreview(int newPosition) { /** * Removes the bottom component. */ - public void hideBottomComponent() { + public void closeBottomPane() { mode = BasePanelMode.SHOWING_NOTHING; - splitPane.setBottomComponent(null); + splitPane.getItems().removeAll(entryEditor, preview); } /** * This method selects the given entry, and scrolls it into view in the table. If an entryEditor is shown, it is * given focus afterwards. */ - public void highlightEntry(final BibEntry bibEntry) { - highlightEntry(mainTable.findEntry(bibEntry)); + public void clearAndSelect(final BibEntry bibEntry) { + mainTable.findEntry(bibEntry) + .ifPresent(entry -> { + mainTable.getSelectionModel().clearSelection(); + mainTable.getSelectionModel().select(entry); + }); } /** * This method selects the entry on the given position, and scrolls it into view in the table. * If an entryEditor is shown, it is given focus afterwards. + * + * @deprecated use select by entry not by row */ - public void highlightEntry(int pos) { - if ((pos >= 0) && (pos < mainTable.getRowCount())) { - mainTable.setRowSelectionInterval(pos, pos); - mainTable.ensureVisible(pos); + @Deprecated + private void clearAndSelect(int pos) { + if ((pos >= 0) && (pos < mainTable.getItems().size())) { + mainTable.getSelectionModel().clearAndSelect(pos); } } public void selectPreviousEntry() { - highlightEntry(((mainTable.getSelectedRow() - 1) + mainTable.getRowCount()) % mainTable.getRowCount()); + mainTable.getSelectionModel().clearSelection(); + mainTable.getSelectionModel().selectPrevious(); } public void selectNextEntry() { - highlightEntry((mainTable.getSelectedRow() + 1) % mainTable.getRowCount()); + mainTable.getSelectionModel().clearSelection(); + mainTable.getSelectionModel().selectNext(); } public void selectFirstEntry() { - highlightEntry(0); + clearAndSelect(0); } public void selectLastEntry() { - highlightEntry(mainTable.getRowCount() - 1); + mainTable.getSelectionModel().clearSelection(); + mainTable.getSelectionModel().selectLast(); } /** @@ -1587,10 +1533,12 @@ public void selectLastEntry() { * @param editor The entry editor to close. */ public void entryEditorClosing(EntryEditor editor) { - // Store divider location for next time: - Globals.prefs.putInt(JabRefPreferences.ENTRY_EDITOR_HEIGHT, - splitPane.getHeight() - splitPane.getDividerLocation()); - selectionListener.entryEditorClosing(editor); + if (Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()) { + showPreview(editor.getEntry()); + } else { + closeBottomPane(); + } + mainTable.requestFocus(); } /** @@ -1598,15 +1546,14 @@ public void entryEditorClosing(EntryEditor editor) { */ public void ensureNotShowingBottomPanel(BibEntry entry) { if (((mode == BasePanelMode.SHOWING_EDITOR) && (entryEditor.getEntry() == entry)) - || ((mode == BasePanelMode.SHOWING_PREVIEW) && (selectionListener.getPreview().getEntry() == entry))) { - hideBottomComponent(); + || ((mode == BasePanelMode.SHOWING_PREVIEW) && (preview.getEntry() == entry))) { + closeBottomPane(); } } public void updateEntryEditorIfShowing() { if (mode == BasePanelMode.SHOWING_EDITOR) { BibEntry currentEntry = entryEditor.getEntry(); - showAndEdit(null); showAndEdit(currentEntry); } } @@ -1628,7 +1575,7 @@ public void markBaseChanged() { private void markBasedChangedInternal() { // Put an asterisk behind the filename to indicate the database has changed. frame.setWindowTitle(); - frame.updateAllTabTitles(); + DefaultTaskExecutor.runInJavaFXThread(frame::updateAllTabTitles); // If the status line states that the base has been saved, we // remove this message, since it is no longer relevant. If a // different message is shown, we leave it. @@ -1682,10 +1629,9 @@ private void changeType(List entries, String newType) { } if (entries.size() > 1) { - int choice = JOptionPane.showConfirmDialog(this, - Localization.lang("Multiple entries selected. Do you want to change the type of all these to '%0'?", newType), - Localization.lang("Change entry type"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); - if (choice == JOptionPane.NO_OPTION) { + DialogService dialogService = new FXDialogService(); + boolean proceed = dialogService.showConfirmationDialogAndWait(Localization.lang("Change entry type"), Localization.lang("Multiple entries selected. Do you want to change the type of all these to '%0'?")); + if (!proceed) { return; } } @@ -1881,7 +1827,7 @@ private void back() { nextEntries.add(showing); } backOrForwardInProgress = true; // to avoid the history getting updated erroneously - highlightEntry(toShow); + clearAndSelect(toShow); } } @@ -1894,7 +1840,7 @@ private void forward() { previousEntries.add(showing); } backOrForwardInProgress = true; // to avoid the history getting updated erroneously - highlightEntry(toShow); + clearAndSelect(toShow); } } @@ -1912,7 +1858,7 @@ private String formatOutputMessage(String start, int count) { * Set the preview active state for all BasePanel instances. */ private void setPreviewActiveBasePanels(boolean enabled) { - for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) { + for (int i = 0; i < frame.getTabbedPane().getTabs().size(); i++) { frame.getBasePanelAt(i).setPreviewActive(enabled); } } @@ -2038,15 +1984,7 @@ private class EntryRemovedListener { @Subscribe public void listen(EntryRemovedEvent entryRemovedEvent) { - // if the entry that is displayed in the current entry editor is removed, close the entry editor - if (mode == BasePanelMode.SHOWING_EDITOR && entryEditor.getEntry().equals(entryRemovedEvent.getBibEntry())) { - entryEditor.close(); - } - - BibEntry previewEntry = selectionListener.getPreview().getEntry(); - if ((previewEntry != null) && previewEntry.equals(entryRemovedEvent.getBibEntry())) { - preview.close(); - } + ensureNotShowingBottomPanel(entryRemovedEvent.getBibEntry()); } } diff --git a/src/main/java/org/jabref/gui/EntryTypeDialog.java b/src/main/java/org/jabref/gui/EntryTypeDialog.java index 84a736773c4..b95a1aef051 100644 --- a/src/main/java/org/jabref/gui/EntryTypeDialog.java +++ b/src/main/java/org/jabref/gui/EntryTypeDialog.java @@ -309,7 +309,7 @@ protected void done() { final BibEntry bibEntry = result.get(); if ((DuplicateCheck.containsDuplicate(frame.getCurrentBasePanel().getDatabase(), bibEntry, frame.getCurrentBasePanel().getBibDatabaseContext().getMode()).isPresent())) { //If there are duplicates starts ImportInspectionDialog - final BasePanel panel = (BasePanel) frame.getTabbedPane().getSelectedComponent(); + final BasePanel panel = frame.getCurrentBasePanel(); ImportInspectionDialog diag = new ImportInspectionDialog(frame, panel, Localization.lang("Import"), false); diag.addEntry(bibEntry); diff --git a/src/main/java/org/jabref/gui/GUIGlobals.java b/src/main/java/org/jabref/gui/GUIGlobals.java index 5d5c5dabfeb..4824b0504f0 100644 --- a/src/main/java/org/jabref/gui/GUIGlobals.java +++ b/src/main/java/org/jabref/gui/GUIGlobals.java @@ -3,20 +3,11 @@ import java.awt.Color; import java.awt.Font; import java.awt.Toolkit; -import java.util.HashMap; -import java.util.Map; - -import javax.swing.JLabel; import org.jabref.Globals; -import org.jabref.gui.externalfiletype.ExternalFileType; -import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.keyboard.EmacsKeyBindings; -import org.jabref.gui.specialfields.SpecialFieldViewModel; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.OS; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.specialfields.SpecialField; import org.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; @@ -44,24 +35,11 @@ public class GUIGlobals { // Colors. public static final Color ENTRY_EDITOR_LABEL_COLOR = new Color(100, 100, 150); // Empty field, blue. - static final Color INACTIVE_TABBED_COLOR = Color.black; // inactive Database private static final Log LOGGER = LogFactory.getLog(GUIGlobals.class); - private static final Map TABLE_ICONS = new HashMap<>(); // Contains table icon mappings. Set up - static final Color ACTIVE_TABBED_COLOR = ENTRY_EDITOR_LABEL_COLOR.darker(); // active Database (JTabbedPane) private GUIGlobals() { } - public static JLabel getTableIcon(String fieldType) { - JLabel label = GUIGlobals.TABLE_ICONS.get(fieldType); - if (label == null) { - LOGGER.info("Error: no table icon defined for type '" + fieldType + "'."); - return null; - } else { - return label; - } - } - public static void updateEntryEditorColors() { GUIGlobals.activeBackgroundColor = JabRefPreferences.getInstance().getColor(JabRefPreferences.ACTIVE_FIELD_EDITOR_BACKGROUND_COLOR); GUIGlobals.validFieldBackgroundColor = JabRefPreferences.getInstance().getColor(JabRefPreferences.VALID_FIELD_BACKGROUND_COLOR); @@ -75,79 +53,6 @@ public static void updateEntryEditorColors() { * on Un*x is unavailable. */ public static void init() { - JLabel label; - label = new JLabel(IconTheme.JabRefIcons.PDF_FILE.getSmallIcon()); - label.setToolTipText(Localization.lang("Open") + " PDF"); - GUIGlobals.TABLE_ICONS.put(FieldName.PDF, label); - - label = new JLabel(IconTheme.JabRefIcons.WWW.getSmallIcon()); - label.setToolTipText(Localization.lang("Open") + " URL"); - GUIGlobals.TABLE_ICONS.put(FieldName.URL, label); - - label = new JLabel(IconTheme.JabRefIcons.WWW.getSmallIcon()); - label.setToolTipText(Localization.lang("Open") + " CiteSeer URL"); - GUIGlobals.TABLE_ICONS.put("citeseerurl", label); - - label = new JLabel(IconTheme.JabRefIcons.WWW.getSmallIcon()); - label.setToolTipText(Localization.lang("Open") + " ArXiv URL"); - GUIGlobals.TABLE_ICONS.put(FieldName.EPRINT, label); - - label = new JLabel(IconTheme.JabRefIcons.DOI.getSmallIcon()); - label.setToolTipText(Localization.lang("Open") + " DOI " + Localization.lang("web link")); - GUIGlobals.TABLE_ICONS.put(FieldName.DOI, label); - - label = new JLabel(IconTheme.JabRefIcons.FILE.getSmallIcon()); - label.setToolTipText(Localization.lang("Open") + " PS"); - GUIGlobals.TABLE_ICONS.put(FieldName.PS, label); - - label = new JLabel(IconTheme.JabRefIcons.FOLDER.getSmallIcon()); - label.setToolTipText(Localization.lang("Open folder")); - GUIGlobals.TABLE_ICONS.put(FieldName.FOLDER, label); - - label = new JLabel(IconTheme.JabRefIcons.FILE.getSmallIcon()); - label.setToolTipText(Localization.lang("Open file")); - GUIGlobals.TABLE_ICONS.put(FieldName.FILE, label); - - for (ExternalFileType fileType : ExternalFileTypes.getInstance().getExternalFileTypeSelection()) { - label = new JLabel(fileType.getIcon().getSmallIcon()); - label.setToolTipText(Localization.lang("Open %0 file", fileType.getName())); - GUIGlobals.TABLE_ICONS.put(fileType.getName(), label); - } - - SpecialFieldViewModel relevanceViewModel = new SpecialFieldViewModel(SpecialField.RELEVANCE); - label = new JLabel(relevanceViewModel.getRepresentingIcon()); - label.setToolTipText(relevanceViewModel.getLocalization()); - GUIGlobals.TABLE_ICONS.put(SpecialField.RELEVANCE.getFieldName(), label); - - SpecialFieldViewModel qualityViewModel = new SpecialFieldViewModel(SpecialField.QUALITY); - label = new JLabel(qualityViewModel.getRepresentingIcon()); - label.setToolTipText(qualityViewModel.getLocalization()); - GUIGlobals.TABLE_ICONS.put(SpecialField.QUALITY.getFieldName(), label); - - // Ranking item in the menu uses one star - SpecialFieldViewModel rankViewModel = new SpecialFieldViewModel(SpecialField.RANKING); - label = new JLabel(rankViewModel.getRepresentingIcon()); - label.setToolTipText(rankViewModel.getLocalization()); - GUIGlobals.TABLE_ICONS.put(SpecialField.RANKING.getFieldName(), label); - - // Priority icon used for the menu - SpecialFieldViewModel priorityViewModel = new SpecialFieldViewModel(SpecialField.PRIORITY); - label = new JLabel(priorityViewModel.getRepresentingIcon()); - label.setToolTipText(priorityViewModel.getLocalization()); - GUIGlobals.TABLE_ICONS.put(SpecialField.PRIORITY.getFieldName(), label); - - // Read icon used for menu - SpecialFieldViewModel readViewModel = new SpecialFieldViewModel(SpecialField.READ_STATUS); - label = new JLabel(readViewModel.getRepresentingIcon()); - label.setToolTipText(readViewModel.getLocalization()); - GUIGlobals.TABLE_ICONS.put(SpecialField.READ_STATUS.getFieldName(), label); - - // Print icon used for menu - SpecialFieldViewModel printedViewModel = new SpecialFieldViewModel(SpecialField.PRINTED); - label = new JLabel(printedViewModel.getRepresentingIcon()); - label.setToolTipText(printedViewModel.getLocalization()); - GUIGlobals.TABLE_ICONS.put(SpecialField.PRINTED.getFieldName(), label); - if (Globals.prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS)) { EmacsKeyBindings.load(); } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index c759ce7083e..cf8cb11071d 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -49,7 +49,6 @@ import javax.swing.JPopupMenu; import javax.swing.JProgressBar; import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; import javax.swing.JToggleButton; import javax.swing.KeyStroke; import javax.swing.MenuElement; @@ -60,6 +59,12 @@ import javax.swing.WindowConstants; import javafx.application.Platform; +import javafx.collections.ListChangeListener; +import javafx.embed.swing.JFXPanel; +import javafx.scene.Scene; +import javafx.scene.control.Tab; +import javafx.scene.control.TabPane; +import javafx.scene.control.Tooltip; import org.jabref.Globals; import org.jabref.JabRefExecutorService; @@ -82,6 +87,7 @@ import org.jabref.gui.bibtexkeypattern.BibtexKeyPatternDialog; import org.jabref.gui.copyfiles.CopyFilesAction; import org.jabref.gui.customentrytypes.EntryCustomizationDialog; +import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.dbproperties.DatabasePropertiesDialog; import org.jabref.gui.documentviewer.ShowDocumentViewerAction; import org.jabref.gui.exporter.ExportAction; @@ -147,6 +153,7 @@ import com.jgoodies.looks.Options; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.fxmisc.easybind.EasyBind; import osx.macadapter.MacAdapter; /** @@ -447,10 +454,9 @@ public void actionPerformed(ActionEvent e) { private final List twoEntriesOnlyActions = new LinkedList<>(); private final List atLeastOneEntryActions = new LinkedList<>(); private PreferencesDialog prefsDialog; - private int lastTabbedPanelSelectionIndex = -1; // The sidepane manager takes care of populating the sidepane. private SidePaneManager sidePaneManager; - private JTabbedPane tabbedPane; // initialized at constructor + private final TabPane tabbedPane = new TabPane(); private final AbstractAction exportAll = ExportAction.getExportAction(this, false); private final AbstractAction exportSelected = ExportAction.getExportAction(this, true); /* References to the toggle buttons in the toolbar */ @@ -461,12 +467,10 @@ public void actionPerformed(ActionEvent e) { private GeneralFetcher generalFetcher; private OpenOfficePanel openOfficePanel; private GroupSidePane groupSidePane; - private int previousTabCount = -1; private JMenu newSpec; public JabRefFrame() { init(); - updateEnabledState(); } private static Action enableToggle(Action a, boolean initialValue) { @@ -560,7 +564,8 @@ private JPopupMenu tabPopupMenu() { private void init() { - tabbedPane = new DragDropPopupPane(tabPopupMenu()); + // TODO: popup + // tabbedPane = new DragDropPopupPane(tabPopupMenu()); MyGlassPane glassPane = new MyGlassPane(); setGlassPane(glassPane); @@ -596,16 +601,18 @@ public void windowClosing(WindowEvent e) { pw.displayWindowAtStoredLocation(); tabbedPane.setBorder(null); - tabbedPane.setForeground(GUIGlobals.INACTIVE_TABBED_COLOR); + // TODO: Color + //tabbedPane.setForeground(GUIGlobals.INACTIVE_TABBED_COLOR); /* * The following state listener makes sure focus is registered with the * correct database when the user switches tabs. Without this, * cut/paste/copy operations would some times occur in the wrong tab. */ - tabbedPane.addChangeListener(e -> { - - markActiveBasePanel(); + EasyBind.subscribe(tabbedPane.getSelectionModel().selectedItemProperty(), e -> { + if (e == null) { + return; + } BasePanel currentBasePanel = getCurrentBasePanel(); if (currentBasePanel == null) { @@ -634,7 +641,8 @@ public void windowClosing(WindowEvent e) { previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class)); openOfficePanel.getToggleAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class)); - Globals.getFocusListener().setFocused(currentBasePanel.getMainTable()); + // TODO: Can't notify focus listener since it is expecting a swing component + //Globals.getFocusListener().setFocused(currentBasePanel.getMainTable()); setWindowTitle(); editModeAction.initName(); // Update search autocompleter with information for the correct database: @@ -832,12 +840,11 @@ public boolean quit() { boolean close = true; List filenames = new ArrayList<>(); - if (tabbedPane.getTabCount() > 0) { - for (int i = 0; i < tabbedPane.getTabCount(); i++) { + for (int i = 0; i < tabbedPane.getTabs().size(); i++) { BibDatabaseContext context = getBasePanelAt(i).getBibDatabaseContext(); if (getBasePanelAt(i).isModified() && (context.getLocation() == DatabaseLocation.LOCAL)) { - tabbedPane.setSelectedIndex(i); + tabbedPane.getSelectionModel().select(i); String filename = context.getDatabaseFile().map(File::getAbsolutePath).orElse(GUIGlobals.UNTITLED_TITLE); int answer = showSaveDialog(filename); @@ -873,10 +880,9 @@ public boolean quit() { BackupManager.shutdown(context); context.getDatabaseFile().map(File::getAbsolutePath).ifPresent(filenames::add); } - } if (close) { - for (int i = 0; i < tabbedPane.getTabCount(); i++) { + 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); @@ -895,8 +901,6 @@ public boolean quit() { } private void initLayout() { - tabbedPane.putClientProperty(Options.NO_CONTENT_BORDER_KEY, Boolean.TRUE); - setProgressBarVisible(false); pushApplications = new PushToApplications(); @@ -913,7 +917,8 @@ private void initLayout() { splitPane.setDividerSize(2); splitPane.setBorder(null); - splitPane.setRightComponent(tabbedPane); + JFXPanel tabbedPaneContainer = CustomJFXPanel.wrap(new Scene(tabbedPane)); + splitPane.setRightComponent(tabbedPaneContainer); splitPane.setLeftComponent(sidePaneManager.getPanel()); getContentPane().add(splitPane, BorderLayout.CENTER); @@ -947,7 +952,8 @@ private void initLayout() { // Drag and drop for tabbedPane: TransferHandler xfer = new EntryTableTransferHandler(null, this, null); - tabbedPane.setTransferHandler(xfer); + // TODO: + //tabbedPane.setTransferHandler(xfer); tlb.setTransferHandler(xfer); mb.setTransferHandler(xfer); sidePaneManager.getPanel().setTransferHandler(xfer); @@ -959,7 +965,7 @@ private void initLayout() { * @param i Index of base */ public BasePanel getBasePanelAt(int i) { - return (BasePanel) tabbedPane.getComponentAt(i); + return (BasePanel) tabbedPane.getTabs().get(i).getContent(); } /** @@ -969,68 +975,57 @@ public BasePanel getBasePanelAt(int i) { public List getBasePanelList() { List returnList = new ArrayList<>(); for (int i = 0; i < getBasePanelCount(); i++) { - returnList.add((BasePanel) tabbedPane.getComponentAt(i)); + returnList.add(getBasePanelAt(i)); } return returnList; } public void showBasePanelAt(int i) { - tabbedPane.setSelectedIndex(i); + tabbedPane.getSelectionModel().select(i); } public void showBasePanel(BasePanel bp) { - tabbedPane.setSelectedComponent(bp); + tabbedPane.getSelectionModel().select(getTab(bp)); } /** * Returns the currently viewed BasePanel. */ public BasePanel getCurrentBasePanel() { - if (tabbedPane == null) { + if (tabbedPane == null || tabbedPane.getSelectionModel().getSelectedItem() == null) { return null; } - return (BasePanel) tabbedPane.getSelectedComponent(); + return (BasePanel) tabbedPane.getSelectionModel().getSelectedItem().getContent(); } /** * @return the BasePanel count. */ public int getBasePanelCount() { - return tabbedPane.getComponentCount(); - } - - /** - * handle the color of active and inactive JTabbedPane tabs - */ - private void markActiveBasePanel() { - int now = tabbedPane.getSelectedIndex(); - int len = tabbedPane.getTabCount(); - if ((lastTabbedPanelSelectionIndex > -1) && (lastTabbedPanelSelectionIndex < len)) { - tabbedPane.setForegroundAt(lastTabbedPanelSelectionIndex, GUIGlobals.INACTIVE_TABBED_COLOR); - } - if ((now > -1) && (now < len)) { - tabbedPane.setForegroundAt(now, GUIGlobals.ACTIVE_TABBED_COLOR); - } - lastTabbedPanelSelectionIndex = now; + return tabbedPane.getTabs().size(); } - private int getTabIndex(JComponent comp) { - for (int i = 0; i < tabbedPane.getTabCount(); i++) { - if (tabbedPane.getComponentAt(i) == comp) { - return i; + private Tab getTab(BasePanel comp) { + for (Tab tab : tabbedPane.getTabs()) { + if (tab.getContent() == comp) { + return tab; } } - return -1; + return null; } - public JTabbedPane getTabbedPane() { + /** + * @deprecated do not operate on tabs but on BibDatabaseContexts + */ + @Deprecated + public TabPane getTabbedPane() { return tabbedPane; } - public void setTabTitle(JComponent comp, String title, String toolTip) { - int index = getTabIndex(comp); - tabbedPane.setTitleAt(index, title); - tabbedPane.setToolTipTextAt(index, toolTip); + public void setTabTitle(BasePanel comp, String title, String toolTip) { + Tab tab = getTab(comp); + tab.setText(title); + tab.setTooltip(new Tooltip(toolTip)); } private void fillMenu() { @@ -1299,7 +1294,7 @@ public void addParserResult(ParserResult pr, boolean focusPanel) { .filter(p -> p.getBibDatabaseContext().getDatabaseFile().equals(pr.getFile())).findFirst(); if (panel.isPresent()) { - tabbedPane.setSelectedComponent(panel.get()); + tabbedPane.getSelectionModel().select(getTab(panel.get())); } else { addTab(pr.getDatabaseContext(), focusPanel); } @@ -1445,8 +1440,7 @@ dupliCheck, autoSetFile, newEntryAction, newSpec, customizeAction, plainTextImpo atLeastOneEntryActions.clear(); atLeastOneEntryActions.addAll(Arrays.asList(downloadFullText, lookupIdentifiers, exportLinkedFiles)); - tabbedPane.addChangeListener(event -> updateEnabledState()); - + tabbedPane.getTabs().addListener(this::updateEnabledState); } /** @@ -1454,10 +1448,12 @@ dupliCheck, autoSetFile, newEntryAction, newSpec, customizeAction, plainTextImpo *

* The action that are affected are set in initActions. */ - public void updateEnabledState() { - int tabCount = tabbedPane.getTabCount(); - if (tabCount != previousTabCount) { - previousTabCount = tabCount; + public void updateEnabledState(ListChangeListener.Change change) { + int tabCount = tabbedPane.getTabs().size(); + if (!change.next()) { + return; + } + if (change.wasAdded() || change.wasRemoved()) { setEnabled(openDatabaseOnlyActions, tabCount > 0); setEnabled(severalDatabasesOnlyActions, tabCount > 1); } @@ -1503,7 +1499,7 @@ public void setupAllTables() { // We want to notify all tabs about the changes to // avoid problems when changing the column set. - for (int i = 0; i < tabbedPane.getTabCount(); i++) { + for (int i = 0; i < tabbedPane.getTabs().size(); i++) { BasePanel bf = getBasePanelAt(i); // Update tables: @@ -1548,43 +1544,46 @@ public void updateAllTabTitles() { if (!uniqPath.equals(file.get().getName()) && uniqPath.contains(File.separator)) { // remove filename uniqPath = uniqPath.substring(0, uniqPath.lastIndexOf(File.separator)); - tabbedPane.setTitleAt(i, getBasePanelAt(i).getTabTitle() + " \u2014 " + uniqPath); + tabbedPane.getTabs().get(i).setText(getBasePanelAt(i).getTabTitle() + " \u2014 " + uniqPath); } else { // set original filename (again) - tabbedPane.setTitleAt(i, getBasePanelAt(i).getTabTitle()); + tabbedPane.getTabs().get(i).setText(getBasePanelAt(i).getTabTitle()); } } else { - tabbedPane.setTitleAt(i, getBasePanelAt(i).getTabTitle()); + tabbedPane.getTabs().get(i).setText(getBasePanelAt(i).getTabTitle()); } - tabbedPane.setToolTipTextAt(i, file.map(File::getAbsolutePath).orElse(null)); + tabbedPane.getTabs().get(i).setTooltip(new Tooltip(file.map(File::getAbsolutePath).orElse(null))); } } public void addTab(BasePanel basePanel, boolean raisePanel) { - // add tab - tabbedPane.add(basePanel.getTabTitle(), basePanel); + DefaultTaskExecutor.runInJavaFXThread(() -> { + // add tab + Tab newTab = new Tab(basePanel.getTabTitle(), basePanel); + tabbedPane.getTabs().add(newTab); - // update all tab titles - updateAllTabTitles(); + // update all tab titles + updateAllTabTitles(); - if (raisePanel) { - tabbedPane.setSelectedComponent(basePanel); - } + if (raisePanel) { + tabbedPane.getSelectionModel().select(newTab); + } - // Register undo/redo listener - basePanel.getUndoManager().registerListener(new UndoRedoEventManager()); + // Register undo/redo listener + basePanel.getUndoManager().registerListener(new UndoRedoEventManager()); - BibDatabaseContext context = basePanel.getBibDatabaseContext(); + BibDatabaseContext context = basePanel.getBibDatabaseContext(); - if (readyForAutosave(context)) { - AutosaveManager autosaver = AutosaveManager.start(context); - autosaver.registerListener(new AutosaveUIManager(basePanel)); - } + if (readyForAutosave(context)) { + AutosaveManager autosaver = AutosaveManager.start(context); + autosaver.registerListener(new AutosaveUIManager(basePanel)); + } - BackupManager.start(context); + BackupManager.start(context); - // Track opening - trackOpenNewDatabase(basePanel); + // Track opening + trackOpenNewDatabase(basePanel); + }); } private void trackOpenNewDatabase(BasePanel basePanel) { @@ -1642,6 +1641,15 @@ public void createDisabledIconsForButtons(Container container) { } } + public void sortTabs() { + // We are going to be crude: remove all tabs and re-add them in a sorted way + // This is ugly, but otherwise we run into issues: https://stackoverflow.com/questions/37328760/javafx-tabpane-sorting-tabs-creates-havoc + List tabs = new ArrayList<>(tabbedPane.getTabs()); + tabs.sort((o1, o2) -> o2.getText().compareTo(o1.getText())); + tabbedPane.getTabs().clear(); + tabbedPane.getTabs().setAll(tabs); + } + /** * This method does the job of adding imported entries into the active * database, or into a new one. It shows the ImportInspectionDialog if @@ -1815,6 +1823,14 @@ private int showSaveDialog(String filename) { JOptionPane.WARNING_MESSAGE, null, options, options[2]); } + private void closeTab(Tab tab) { + closeTab(getBasePanel(tab)); + } + + private BasePanel getBasePanel(Tab tab) { + return (BasePanel) tab.getContent(); + } + private void closeTab(BasePanel panel) { // empty tab without database if (panel == null) { @@ -1868,12 +1884,8 @@ private boolean confirmClose(BasePanel panel) { private void removeTab(BasePanel panel) { panel.cleanUp(); - tabbedPane.remove(panel); - if (tabbedPane.getTabCount() > 0) { - markActiveBasePanel(); - } + tabbedPane.getTabs().remove(getTab(panel)); setWindowTitle(); - updateEnabledState(); output(Localization.lang("Closed library") + '.'); // update tab titles updateAllTabTitles(); @@ -1988,7 +2000,7 @@ public void actionPerformed(ActionEvent evt) { initName(); // update all elements in current base panel - JabRefFrame.this.getCurrentBasePanel().hideBottomComponent(); + JabRefFrame.this.getCurrentBasePanel().closeBottomPane(); JabRefFrame.this.getCurrentBasePanel().updateEntryEditorIfShowing(); } } @@ -2047,9 +2059,9 @@ public GeneralAction(String command, String text, String description, KeyStroke @Override public void actionPerformed(ActionEvent e) { - if (tabbedPane.getTabCount() > 0) { + if (tabbedPane.getTabs().size() > 0) { try { - ((BasePanel) tabbedPane.getSelectedComponent()).runCommand(command); + getCurrentBasePanel().runCommand(command); } catch (Throwable ex) { LOGGER.error("Problem with executing command: " + command, ex); } @@ -2080,7 +2092,7 @@ public void actionPerformed(ActionEvent e) { private class ShowPrefsAction extends MnemonicAwareAction { public ShowPrefsAction() { - super(IconTheme.JabRefIcon.PREFERENCES.getIcon()); + super(IconTheme.JabRefIcons.PREFERENCES.getIcon()); putValue(Action.NAME, Localization.menuTitle("Preferences")); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Preferences")); } @@ -2105,15 +2117,11 @@ public ChangeTabAction(boolean next) { @Override public void actionPerformed(ActionEvent e) { - int i = tabbedPane.getSelectedIndex(); - int newI = next ? i + 1 : i - 1; - if (newI < 0) { - newI = tabbedPane.getTabCount() - 1; - } - if (newI == tabbedPane.getTabCount()) { - newI = 0; + if (next) { + tabbedPane.getSelectionModel().selectNext(); + } else { + tabbedPane.getSelectionModel().selectPrevious(); } - tabbedPane.setSelectedIndex(newI); } } @@ -2317,7 +2325,7 @@ public void actionPerformed(ActionEvent event) { private class CloseDatabaseAction extends MnemonicAwareAction { public CloseDatabaseAction() { - super(IconTheme.JabRefIcon.CLOSE.getSmallIcon()); + super(IconTheme.JabRefIcons.CLOSE.getSmallIcon()); putValue(Action.NAME, Localization.menuTitle("Close library")); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Close the current library")); putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DATABASE)); @@ -2333,10 +2341,10 @@ private class CloseAllDatabasesAction extends MnemonicAwareAction { @Override public void actionPerformed(ActionEvent e) { - final Component[] panels = tabbedPane.getComponents(); + final List tabs = tabbedPane.getTabs(); - for (Component p : panels) { - closeTab((BasePanel) p); + for (Tab tab : tabs) { + closeTab(tab); } } } @@ -2346,11 +2354,11 @@ private class CloseOtherDatabasesAction extends MnemonicAwareAction { @Override public void actionPerformed(ActionEvent e) { final BasePanel active = getCurrentBasePanel(); - final Component[] panels = tabbedPane.getComponents(); + final List tabs = tabbedPane.getTabs(); - for (Component p : panels) { - if (!Objects.equals(p, active)) { - closeTab((BasePanel) p); + for (Tab tab : tabs) { + if (!tab.getContent().equals(active)) { + closeTab(tab); } } } diff --git a/src/main/java/org/jabref/gui/Main.css b/src/main/java/org/jabref/gui/Main.css index 5f01e7afd41..95a63836304 100644 --- a/src/main/java/org/jabref/gui/Main.css +++ b/src/main/java/org/jabref/gui/Main.css @@ -23,6 +23,11 @@ */ -fx-info: #2c3e50; + /* + * A dark gray to indicate something not so important + */ + -fx-unimportant: #595959; + /* * A light gray for accented background */ diff --git a/src/main/java/org/jabref/gui/PreviewPanel.java b/src/main/java/org/jabref/gui/PreviewPanel.java index 49958ceb3cf..181c4395c45 100644 --- a/src/main/java/org/jabref/gui/PreviewPanel.java +++ b/src/main/java/org/jabref/gui/PreviewPanel.java @@ -297,7 +297,7 @@ public void print() { } public void close() { - basePanel.ifPresent(BasePanel::hideBottomComponent); + basePanel.ifPresent(BasePanel::closeBottomPane); } private void copyPreviewToClipBoard() { diff --git a/src/main/java/org/jabref/gui/SidePaneManager.java b/src/main/java/org/jabref/gui/SidePaneManager.java index 500c78af892..e6b22170a11 100644 --- a/src/main/java/org/jabref/gui/SidePaneManager.java +++ b/src/main/java/org/jabref/gui/SidePaneManager.java @@ -9,8 +9,6 @@ import java.util.Map; import java.util.stream.Collectors; -import javax.swing.SwingUtilities; - import org.jabref.Globals; import org.jabref.gui.maintable.MainTable; import org.jabref.preferences.JabRefPreferences; @@ -40,8 +38,8 @@ public SidePaneManager(JabRefFrame frame) { * side pane components, we get rid of the annoying latency when * switching tabs: */ - frame.getTabbedPane().addChangeListener(event -> SwingUtilities.invokeLater( - () -> setActiveBasePanel(SidePaneManager.this.frame.getCurrentBasePanel()))); + //frame.getTabbedPane().addChangeListener(event -> SwingUtilities.invokeLater( + // () -> setActiveBasePanel(SidePaneManager.this.frame.getCurrentBasePanel()))); sidep = new SidePane(); sidep.setVisible(false); } @@ -105,7 +103,7 @@ public synchronized void hide(Class sidePaneCom hideComponent(component); if (frame.getCurrentBasePanel() != null) { MainTable mainTable = frame.getCurrentBasePanel().getMainTable(); - mainTable.setSelected(mainTable.getSelectedRow()); + //mainTable.setSelected(mainTable.getSelectedRow()); mainTable.requestFocus(); } } diff --git a/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java b/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java index 590c2795028..177ddb1efc5 100644 --- a/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java +++ b/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java @@ -88,7 +88,7 @@ protected void done() { } if (messages.isEmpty()) { - JOptionPane.showMessageDialog(frame.getCurrentBasePanel(), Localization.lang("No problems found.")); + JOptionPane.showMessageDialog(frame, Localization.lang("No problems found.")); } else { Map showMessage = new HashMap<>(); // prepare data model diff --git a/src/main/java/org/jabref/gui/actions/SortTabsAction.java b/src/main/java/org/jabref/gui/actions/SortTabsAction.java index 55f2432b0ce..952ad7ca64c 100644 --- a/src/main/java/org/jabref/gui/actions/SortTabsAction.java +++ b/src/main/java/org/jabref/gui/actions/SortTabsAction.java @@ -3,12 +3,9 @@ import java.awt.event.ActionEvent; import java.util.Comparator; import java.util.Locale; -import java.util.Map; -import java.util.TreeMap; import javax.swing.Action; -import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; import org.jabref.logic.l10n.Localization; @@ -27,17 +24,7 @@ public SortTabsAction(JabRefFrame frame) { @Override public void actionPerformed(ActionEvent e) { - // Make a sorted Map that compares case-insensitively: - Map map = new TreeMap<>(this); - - for (BasePanel panel : frame.getBasePanelList()) { - map.put(panel.getTabTitle(), panel); - } - - frame.getTabbedPane().removeAll(); - for (Map.Entry entry : map.entrySet()) { - frame.addTab(entry.getValue(), false); - } + frame.sortTabs(); } @Override diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index 2de98920b40..88e80b993c0 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -16,10 +16,11 @@ import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.JTextField; +import javafx.scene.control.TabPane; + import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; @@ -58,7 +59,7 @@ public class FromAuxDialog extends JabRefDialog { private JTextArea statusInfos; // all open databases from JabRefFrame - private final JTabbedPane parentTabbedPane; + private final TabPane parentTabbedPane; private boolean generatePressed; @@ -66,7 +67,7 @@ public class FromAuxDialog extends JabRefDialog { private final JabRefFrame parentFrame; - public FromAuxDialog(JabRefFrame frame, String title, boolean modal, JTabbedPane viewedDBs) { + public FromAuxDialog(JabRefFrame frame, String title, boolean modal, TabPane viewedDBs) { super(frame, title, modal, FromAuxDialog.class); parentTabbedPane = viewedDBs; @@ -143,10 +144,10 @@ public void actionPerformed(ActionEvent e) { private void initPanels() { // collect the names of all open databases - int len = parentTabbedPane.getTabCount(); + int len = parentTabbedPane.getTabs().size(); int toSelect = -1; for (int i = 0; i < len; i++) { - dbChooser.addItem(parentTabbedPane.getTitleAt(i)); + dbChooser.addItem(parentTabbedPane.getTabs().get(i).getText()); if (parentFrame.getBasePanelAt(i) == parentFrame.getCurrentBasePanel()) { toSelect = i; } @@ -200,7 +201,7 @@ private void initPanels() { private void parseActionPerformed() { parseButton.setEnabled(false); - BasePanel bp = (BasePanel) parentTabbedPane.getComponentAt(dbChooser.getSelectedIndex()); + BasePanel bp = (BasePanel) parentTabbedPane.getTabs().get(dbChooser.getSelectedIndex()).getContent(); notFoundList.removeAll(); statusInfos.setText(null); BibDatabase refBase = bp.getDatabase(); diff --git a/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java b/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java index ef63583e117..edad6d83284 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java +++ b/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java @@ -32,7 +32,6 @@ import javax.swing.event.ListDataListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.table.AbstractTableModel; import org.jabref.Globals; import org.jabref.gui.BasePanel; @@ -315,7 +314,6 @@ private void applyChanges() { } } - updateTables(); CustomEntryTypesManager.saveCustomEntryTypes(Globals.prefs); } @@ -357,13 +355,6 @@ private void updateEntriesForChangedTypes(List actuallyChangedTypes) { } } - private void updateTables() { - for (BasePanel basePanel : frame.getBasePanelList()) { - ((AbstractTableModel) basePanel.getMainTable().getModel()).fireTableDataChanged(); - } - } - - // DEFAULT button pressed. Remember that this entry should be reset to default, // unless changes are made later. private class DefaultListener implements ActionListener { diff --git a/src/main/java/org/jabref/gui/customjfx/CustomJFXPanel.java b/src/main/java/org/jabref/gui/customjfx/CustomJFXPanel.java index d1459537890..e54b390b9e1 100644 --- a/src/main/java/org/jabref/gui/customjfx/CustomJFXPanel.java +++ b/src/main/java/org/jabref/gui/customjfx/CustomJFXPanel.java @@ -6,6 +6,7 @@ import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; +import org.jabref.gui.AbstractView; import org.jabref.gui.customjfx.support.InputMethodSupport; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.logic.util.OS; @@ -41,6 +42,7 @@ public static JFXPanel create() { public static JFXPanel wrap(Scene scene) { JFXPanel container = OS.LINUX ? new CustomJFXPanel() : new JFXPanel(); + scene.getStylesheets().add(AbstractView.class.getResource("Main.css").toExternalForm()); DefaultTaskExecutor.runInJavaFXThread(() -> container.setScene(scene)); return container; } diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index 25007ea94a2..5d09c8f3c2f 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -205,7 +205,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) if (ex.specificEntry()) { BibEntry entry = ex.getEntry(); // Error occured during processing of an entry. Highlight it! - panel.highlightEntry(entry); + panel.clearAndSelect(entry); } else { LOGGER.error("A problem occured when trying to save the file", ex); } @@ -287,7 +287,6 @@ public void runCommand() throws Exception { public void save() throws Exception { runCommand(); - frame.updateEnabledState(); } public void saveAs() throws Exception { @@ -357,7 +356,6 @@ public void saveAs(File file) throws Exception { } context.getDatabaseFile().ifPresent(presentFile -> frame.getFileHistory().newFile(presentFile.getPath())); - frame.updateEnabledState(); } private boolean readyForAutosave(BibDatabaseContext context) { diff --git a/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java b/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java index c822f61458f..3ac4f7313d1 100644 --- a/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java +++ b/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java @@ -217,7 +217,6 @@ public void run() { fileTypes.add(newType); Collections.sort(fileTypes); ExternalFileTypes.getInstance().setExternalFileTypes(fileTypes); - panel.getMainTable().repaint(); } } else { // User wants to change the type of this link. diff --git a/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java b/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java index 9eb50acadbf..f2673716b55 100644 --- a/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java @@ -28,6 +28,7 @@ import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; +import org.jabref.gui.JabRefFrame; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.worker.AbstractWorker; import org.jabref.logic.l10n.Localization; @@ -45,6 +46,7 @@ public class WriteXMPAction extends AbstractWorker { private final BasePanel panel; + private final JabRefFrame frame; private Collection entries; @@ -61,6 +63,7 @@ public class WriteXMPAction extends AbstractWorker { public WriteXMPAction(BasePanel panel) { this.panel = panel; + this.frame = panel.frame(); } @Override @@ -76,7 +79,7 @@ public void init() { if (entries.isEmpty()) { - JOptionPane.showMessageDialog(panel, + JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires one or more entries to be selected."), Localization.lang("Write XMP-metadata"), JOptionPane.ERROR_MESSAGE); goOn = false; @@ -84,7 +87,7 @@ public void init() { } else { - int response = JOptionPane.showConfirmDialog(panel, Localization.lang("Write XMP-metadata for all PDFs in current library?"), + int response = JOptionPane.showConfirmDialog(frame, Localization.lang("Write XMP-metadata for all PDFs in current library?"), Localization.lang("Write XMP-metadata"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); @@ -218,8 +221,6 @@ public void actionPerformed(ActionEvent e) { d.height += scrollPane.getHorizontalScrollBar().getHeight() + 15; d.width += scrollPane.getVerticalScrollBar().getWidth() + 15; - panel.setSize(d); - progressArea.setBackground(Color.WHITE); progressArea.setEditable(false); progressArea.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java index bf286e86ed3..76e07c9592c 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java @@ -372,9 +372,6 @@ public void actionPerformed(ActionEvent e) { } editor.setValues(); editor.setVisible(true); - if ((frame != null) && (frame.getCurrentBasePanel() != null)) { - frame.getCurrentBasePanel().getMainTable().repaint(); - } } } diff --git a/src/main/java/org/jabref/gui/groups/EntryTableTransferHandler.java b/src/main/java/org/jabref/gui/groups/EntryTableTransferHandler.java index 7b669fb0e90..e5c2521e75b 100644 --- a/src/main/java/org/jabref/gui/groups/EntryTableTransferHandler.java +++ b/src/main/java/org/jabref/gui/groups/EntryTableTransferHandler.java @@ -172,12 +172,15 @@ public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) { @Override public void exportAsDrag(JComponent comp, InputEvent e, int action) { if (e instanceof MouseEvent) { + // TODO: Reimplement drag & drop + /* int columnIndex = entryTable.columnAtPoint(((MouseEvent) e).getPoint()); int modelIndex = entryTable.getColumnModel().getColumn(columnIndex).getModelIndex(); if (entryTable.isFileColumn(modelIndex)) { LOGGER.info("Dragging file"); draggingFile = true; } + */ } super.exportAsDrag(comp, e, DnDConstants.ACTION_LINK); } diff --git a/src/main/java/org/jabref/gui/importer/ImportMenuItem.java b/src/main/java/org/jabref/gui/importer/ImportMenuItem.java index d85d1cb5136..fd5c54965e0 100644 --- a/src/main/java/org/jabref/gui/importer/ImportMenuItem.java +++ b/src/main/java/org/jabref/gui/importer/ImportMenuItem.java @@ -178,7 +178,7 @@ public void update() { frame.output( Localization.lang("Imported entries") + ": " + bibtexResult.getDatabase().getEntryCount()); } else { - final BasePanel panel = (BasePanel) frame.getTabbedPane().getSelectedComponent(); + final BasePanel panel = frame.getCurrentBasePanel(); ImportInspectionDialog diag = new ImportInspectionDialog(frame, panel, Localization.lang("Import"), openInNew); diff --git a/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java index 76b7350198a..3797481171a 100644 --- a/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java @@ -147,7 +147,7 @@ private static void addGroups(GroupTreeNode newGroups, CompoundEdit ce) { public void action() { filesToOpen.clear(); final MergeDialog dialog = new MergeDialog(frame, Localization.lang("Append library"), true); - dialog.setLocationRelativeTo(panel); + dialog.setLocationRelativeTo(frame); dialog.setVisible(true); if (dialog.isOkPressed()) { @@ -187,7 +187,7 @@ private void openIt(boolean importEntries, boolean importStrings, boolean import panel.output(Localization.lang("Imported from library") + " '" + file + "'"); } catch (IOException | KeyCollisionException ex) { LOGGER.warn("Could not open database", ex); - JOptionPane.showMessageDialog(panel, ex.getMessage(), Localization.lang("Open library"), + JOptionPane.showMessageDialog(frame, ex.getMessage(), Localization.lang("Open library"), JOptionPane.ERROR_MESSAGE); } } 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 814daa83dd8..af02bd48f03 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -89,7 +89,7 @@ public static void performPostOpenActions(BasePanel panel, ParserResult result) for (GUIPostOpenAction action : OpenDatabaseAction.POST_OPEN_ACTIONS) { if (action.isActionNecessary(result)) { action.performAction(panel, result); - panel.frame().getTabbedPane().setSelectedComponent(panel); + panel.frame().showBasePanel(panel); } } } @@ -148,7 +148,7 @@ public void openFiles(List filesToOpen, boolean raisePanel) { // Check if any of the files are already open: for (Iterator iterator = filesToOpen.iterator(); iterator.hasNext();) { Path file = iterator.next(); - for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) { + for (int i = 0; i < frame.getTabbedPane().getTabs().size(); i++) { BasePanel basePanel = frame.getBasePanelAt(i); if ((basePanel.getBibDatabaseContext().getDatabasePath().isPresent()) && basePanel.getBibDatabaseContext().getDatabasePath().get().equals(file)) { @@ -183,7 +183,7 @@ public void openFiles(List filesToOpen, boolean raisePanel) { else if (toRaise != null) { frame.output(Localization.lang("File '%0' is already open.", toRaise.getBibDatabaseContext().getDatabaseFile().get().getPath())); - frame.getTabbedPane().setSelectedComponent(toRaise); + frame.showBasePanel(toRaise); } frame.output(Localization.lang("Files opened") + ": " + (filesToOpen.size())); diff --git a/src/main/java/org/jabref/gui/maintable/CellFactory.java b/src/main/java/org/jabref/gui/maintable/CellFactory.java new file mode 100644 index 00000000000..263343eb986 --- /dev/null +++ b/src/main/java/org/jabref/gui/maintable/CellFactory.java @@ -0,0 +1,103 @@ +package org.jabref.gui.maintable; + +import java.util.HashMap; +import java.util.Map; + +import javafx.scene.Node; + +import org.jabref.gui.IconTheme; +import org.jabref.gui.externalfiletype.ExternalFileType; +import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.gui.specialfields.SpecialFieldViewModel; +import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.specialfields.SpecialField; + +public class CellFactory { + + private final Map TABLE_ICONS = new HashMap<>(); + + public CellFactory() { + Node label; + label = IconTheme.JabRefIcons.PDF_FILE.getGraphicNode(); + //label.setToo(Localization.lang("Open") + " PDF"); + TABLE_ICONS.put(FieldName.PDF, label); + + label = IconTheme.JabRefIcons.WWW.getGraphicNode(); + //label.setToolTipText(Localization.lang("Open") + " URL"); + TABLE_ICONS.put(FieldName.URL, label); + + label = IconTheme.JabRefIcons.WWW.getGraphicNode(); + //label.setToolTipText(Localization.lang("Open") + " CiteSeer URL"); + TABLE_ICONS.put("citeseerurl", label); + + label = IconTheme.JabRefIcons.WWW.getGraphicNode(); + //label.setToolTipText(Localization.lang("Open") + " ArXiv URL"); + TABLE_ICONS.put(FieldName.EPRINT, label); + + label = IconTheme.JabRefIcons.DOI.getGraphicNode(); + //label.setToolTipText(Localization.lang("Open") + " DOI " + Localization.lang("web link")); + TABLE_ICONS.put(FieldName.DOI, label); + + label = IconTheme.JabRefIcons.FILE.getGraphicNode(); + //label.setToolTipText(Localization.lang("Open") + " PS"); + TABLE_ICONS.put(FieldName.PS, label); + + label = IconTheme.JabRefIcons.FOLDER.getGraphicNode(); + //label.setToolTipText(Localization.lang("Open folder")); + TABLE_ICONS.put(FieldName.FOLDER, label); + + label = IconTheme.JabRefIcons.FILE.getGraphicNode(); + //label.setToolTipText(Localization.lang("Open file")); + TABLE_ICONS.put(FieldName.FILE, label); + + for (ExternalFileType fileType : ExternalFileTypes.getInstance().getExternalFileTypeSelection()) { + label = fileType.getIcon().getGraphicNode(); + //label.setToolTipText(Localization.lang("Open %0 file", fileType.getName())); + TABLE_ICONS.put(fileType.getName(), label); + } + + SpecialFieldViewModel relevanceViewModel = new SpecialFieldViewModel(SpecialField.RELEVANCE); + label = relevanceViewModel.getIcon().getGraphicNode(); + //label.setToolTipText(relevanceViewModel.getLocalization()); + TABLE_ICONS.put(SpecialField.RELEVANCE.getFieldName(), label); + + SpecialFieldViewModel qualityViewModel = new SpecialFieldViewModel(SpecialField.QUALITY); + label = qualityViewModel.getIcon().getGraphicNode(); + //label.setToolTipText(qualityViewModel.getLocalization()); + TABLE_ICONS.put(SpecialField.QUALITY.getFieldName(), label); + + // Ranking item in the menu uses one star + SpecialFieldViewModel rankViewModel = new SpecialFieldViewModel(SpecialField.RANKING); + label = rankViewModel.getIcon().getGraphicNode(); + //label.setToolTipText(rankViewModel.getLocalization()); + TABLE_ICONS.put(SpecialField.RANKING.getFieldName(), label); + + // Priority icon used for the menu + SpecialFieldViewModel priorityViewModel = new SpecialFieldViewModel(SpecialField.PRIORITY); + label = priorityViewModel.getIcon().getGraphicNode(); + //label.setToolTipText(priorityViewModel.getLocalization()); + TABLE_ICONS.put(SpecialField.PRIORITY.getFieldName(), label); + + // Read icon used for menu + SpecialFieldViewModel readViewModel = new SpecialFieldViewModel(SpecialField.READ_STATUS); + label = readViewModel.getIcon().getGraphicNode(); + //label.setToolTipText(readViewModel.getLocalization()); + TABLE_ICONS.put(SpecialField.READ_STATUS.getFieldName(), label); + + // Print icon used for menu + SpecialFieldViewModel printedViewModel = new SpecialFieldViewModel(SpecialField.PRINTED); + label = printedViewModel.getIcon().getGraphicNode(); + //label.setToolTipText(printedViewModel.getLocalization()); + TABLE_ICONS.put(SpecialField.PRINTED.getFieldName(), label); + } + + public Node getTableIcon(String fieldType) { + Node label = TABLE_ICONS.get(fieldType); + if (label == null) { + //LOGGER.info("Error: no table icon defined for type '" + fieldType + "'."); + return null; + } else { + return label; + } + } +} diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.css b/src/main/java/org/jabref/gui/maintable/MainTable.css new file mode 100644 index 00000000000..651b8376d4a --- /dev/null +++ b/src/main/java/org/jabref/gui/maintable/MainTable.css @@ -0,0 +1,48 @@ +.table-view { + +} + +.table-view .column-header-background { + -fx-background-color: -fx-control-inner-background; +} + +.table-view .column-header, +.table-view .filler { + -fx-background-color: -fx-control-inner-background; + -fx-font-weight: bold; + -fx-size: 3em; + -fx-border-width: 0 0 1 0; + -fx-border-color: darkgrey; +} + +.table-view .column-header > .label { + -fx-padding: 0 1em 0 1em; + -fx-alignment: center-left; + -fx-text-fill: -fx-unimportant; +} + +.table-view .column-header .glyph-icon { + -fx-alignment: baseline-center; + -fx-text-fill: -fx-unimportant; + -fx-fill: -fx-unimportant; +} + +.table-cell { + -fx-padding: 0.5em 1em 0.5em 1em; + -fx-cell-size: 4.0em; +} + +.table-row-cell:odd { + -fx-background: -fx-control-inner-background; +} + +.column-icon { + -fx-alignment: baseline-center; + -fx-padding: 0; +} + +.column-header.column-icon > .label { + -fx-padding: 0; + -fx-alignment: baseline-center; +} + diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 9edd6805dba..ca003724cc6 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -1,68 +1,36 @@ package org.jabref.gui.maintable; import java.awt.Color; -import java.awt.Dimension; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.MouseEvent; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; -import java.util.Locale; import java.util.Optional; +import java.util.stream.Collectors; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JScrollBar; -import javax.swing.JScrollPane; import javax.swing.JTable; -import javax.swing.JViewport; -import javax.swing.TransferHandler; -import javax.swing.plaf.TableUI; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumnModel; + +import javafx.collections.ListChangeListener; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.SelectionMode; +import javafx.scene.control.TableView; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.EntryMarker; -import org.jabref.gui.GUIGlobals; import org.jabref.gui.JabRefFrame; -import org.jabref.gui.groups.EntryTableTransferHandler; -import org.jabref.gui.groups.GroupMatcher; -import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.renderer.CompleteRenderer; import org.jabref.gui.renderer.GeneralRenderer; import org.jabref.gui.renderer.IncompleteRenderer; -import org.jabref.gui.search.matchers.SearchMatcher; -import org.jabref.gui.util.comparator.FirstColumnComparator; -import org.jabref.gui.util.comparator.IconComparator; -import org.jabref.gui.util.comparator.RankingFieldComparator; +import org.jabref.gui.util.ViewModelTableRowFactory; import org.jabref.logic.TypedBibEntry; -import org.jabref.logic.bibtex.comparator.FieldComparator; -import org.jabref.model.EntryTypes; +import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibtexSingleField; -import org.jabref.model.entry.EntryType; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.specialfields.SpecialField; import org.jabref.preferences.JabRefPreferences; -import ca.odell.glazedlists.EventList; -import ca.odell.glazedlists.SortedList; -import ca.odell.glazedlists.event.ListEventListener; -import ca.odell.glazedlists.gui.AbstractTableComparatorChooser; import ca.odell.glazedlists.matchers.Matcher; -import ca.odell.glazedlists.swing.DefaultEventSelectionModel; -import ca.odell.glazedlists.swing.GlazedListsSwing; -import ca.odell.glazedlists.swing.TableComparatorChooser; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -public class MainTable extends JTable { +public class MainTable extends TableView { private static GeneralRenderer defRenderer; private static GeneralRenderer reqRenderer; private static GeneralRenderer optRenderer; @@ -80,17 +48,14 @@ public class MainTable extends JTable { private static List markedNumberRenderers; private static final Log LOGGER = LogFactory.getLog(MainTable.class); - private final MainTableFormat tableFormat; private final BasePanel panel; private final boolean tableColorCodes; private final boolean tableResolvedColorCodes; - private final DefaultEventSelectionModel localSelectionModel; - private final TableComparatorChooser comparatorChooser; - private final JScrollPane pane; + private final ScrollPane pane; // needed to activate/deactivate the listener - private final PersistenceTableColumnListener tableColumnListener; + private PersistenceTableColumnListener tableColumnListener; private final MainTableDataModel model; // Enum used to define how a cell should be rendered. @@ -105,60 +70,73 @@ private enum CellRendererMode { MainTable.updateRenderers(); } - public MainTable(MainTableFormat tableFormat, MainTableDataModel model, JabRefFrame frame, - BasePanel panel) { + public MainTable(MainTableDataModel model, JabRefFrame frame, + BasePanel panel, BibDatabase database) { super(); this.model = model; - addFocusListener(Globals.getFocusListener()); - setAutoResizeMode(Globals.prefs.getInt(JabRefPreferences.AUTO_RESIZE_MODE)); + this.getColumns().addAll(new ColumnFactory(database).createColumns()); + this.setRowFactory(new ViewModelTableRowFactory() + .withOnMouseClickedEvent((entry, event) -> { + if (event.getClickCount() == 2) { + panel.showAndEdit(entry.getEntry()); + } + })); + if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_RESIZE_MODE)) { + this.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); + } + this.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + this.setItems(model.getTableRows()); + + // TODO: Cannot add focus listener as it is expecting an swing component + //addFocusListener(Globals.getFocusListener()); - this.tableFormat = tableFormat; this.panel = panel; - setModel(GlazedListsSwing - .eventTableModelWithThreadProxyList(model.getTableRows(), tableFormat)); + pane = new ScrollPane(this); + pane.setFitToHeight(true); + pane.setFitToWidth(true); + this.pane.getStylesheets().add(MainTable.class.getResource("MainTable.css").toExternalForm()); + // TODO: Color tableColorCodes = Globals.prefs.getBoolean(JabRefPreferences.TABLE_COLOR_CODES_ON); tableResolvedColorCodes = Globals.prefs.getBoolean(JabRefPreferences.TABLE_RESOLVED_COLOR_CODES_ON); - localSelectionModel = (DefaultEventSelectionModel) GlazedListsSwing - .eventSelectionModelWithThreadProxyList(model.getTableRows()); - setSelectionModel(localSelectionModel); - pane = new JScrollPane(this); - pane.setBorder(BorderFactory.createEmptyBorder()); - pane.getViewport().setBackground(Globals.prefs.getColor(JabRefPreferences.TABLE_BACKGROUND)); - setGridColor(Globals.prefs.getColor(JabRefPreferences.GRID_COLOR)); - if (Globals.prefs.getBoolean(JabRefPreferences.TABLE_SHOW_GRID)) { - setShowGrid(true); - } else { - setShowGrid(false); - setIntercellSpacing(new Dimension(0, 0)); + //pane.getViewport().setBackground(Globals.prefs.getColor(JabRefPreferences.TABLE_BACKGROUND)); + //setGridColor(Globals.prefs.getColor(JabRefPreferences.GRID_COLOR)); + if (!Globals.prefs.getBoolean(JabRefPreferences.TABLE_SHOW_GRID)) { + this.setStyle("-fx-table-cell-border-color: transparent;"); } - this.setTableHeader(new PreventDraggingJTableHeader(this, tableFormat)); - - comparatorChooser = this.createTableComparatorChooser(this, model.getSortedForUserDefinedTableColumnSorting(), - AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD); - - this.tableColumnListener = new PersistenceTableColumnListener(this); + // TODO: Tooltip for column header + /* + @Override + public String getToolTipText(MouseEvent event) { + int index = columnModel.getColumnIndexAtX(event.getX()); + int realIndex = columnModel.getColumn(index).getModelIndex(); + MainTableColumn column = tableFormat.getTableColumn(realIndex); + return column.getDisplayName(); + } + */ - // set table header render AFTER creation of comparatorChooser (this enables sort arrow rendering) - this.getTableHeader().setDefaultRenderer(new MainTableHeaderRenderer(this.getTableHeader().getDefaultRenderer())); + // TODO: store column widths + //this.tableColumnListener = new PersistenceTableColumnListener(this); + //setWidths(); - // TODO: Figure out, whether this call is needed. - getSelected(); + // TODO: enable DnD + //setDragEnabled(true); + //TransferHandler xfer = new EntryTableTransferHandler(this, frame, panel); + //setTransferHandler(xfer); + //pane.setTransferHandler(xfer); - // enable DnD - setDragEnabled(true); - TransferHandler xfer = new EntryTableTransferHandler(this, frame, panel); - setTransferHandler(xfer); - pane.setTransferHandler(xfer); + // Todo: Set default sort order + // setupComparatorChooser(); - setupComparatorChooser(); - model.updateMarkingState(Globals.prefs.getBoolean(JabRefPreferences.FLOAT_MARKED_ENTRIES)); - setWidths(); + // TODO: Float marked entries + //model.updateMarkingState(Globals.prefs.getBoolean(JabRefPreferences.FLOAT_MARKED_ENTRIES)); + // TODO: Keybindings //Override 'selectNextColumnCell' and 'selectPreviousColumnCell' to move rows instead of cells on TAB + /* ActionMap actionMap = getActionMap(); InputMap inputMap = getInputMap(); actionMap.put("selectNextColumnCell", new AbstractAction() { @@ -202,14 +180,14 @@ public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) { panel.selectLastEntry(); } - }); + });*/ } - public void addSelectionListener(ListEventListener listener) { - getSelected().addListEventListener(listener); + public void addSelectionListener(ListChangeListener listener) { + getSelectionModel().getSelectedItems().addListener(listener); } - public JScrollPane getPane() { + public ScrollPane getPane() { return pane; } @@ -217,6 +195,8 @@ public MainTableDataModel getTableModel() { return model; } + /* + // TODO: if the content of the cell is bigger than the cell itself render it as the tooltip @Override public String getToolTipText(MouseEvent e) { String toolTipText = super.getToolTipText(e); @@ -233,6 +213,7 @@ public String getToolTipText(MouseEvent e) { return toolTipText; } + // TODO: Support float mode @Override public TableCellRenderer getCellRenderer(int row, int column) { @@ -304,6 +285,7 @@ else if (column == 0) { return renderer; } + // TODO: Set column widths private void setWidths() { // Setting column widths: int ncWidth = Globals.prefs.getInt(JabRefPreferences.NUMBER_COL_WIDTH); @@ -338,40 +320,17 @@ private void setWidths() { } } } + */ public BibEntry getEntryAt(int row) { - return model.getTableRows().get(row); + return model.getTableRows().get(row).getEntry(); } - /** - * @return the return value is never null - */ public List getSelectedEntries() { - return new ArrayList<>(getSelected()); - } - - private List getCurrentSortOrder() { - List order = new ArrayList<>(); - List sortCols = comparatorChooser.getSortingColumns(); - for (Integer i : sortCols) { - order.add(comparatorChooser.isColumnReverse(i)); - } - return order; - } - - private List getCurrentSortFields() { - List sortCols = comparatorChooser.getSortingColumns(); - List fields = new ArrayList<>(); - for (Integer i : sortCols) { - // TODO check whether this really works - String name = tableFormat.getColumnName(i); - //TODO OLD - // String name = tableFormat.getColumnType(i); - if (name != null) { - fields.add(name.toLowerCase(Locale.ROOT)); - } - } - return fields; + return getSelectionModel() + .getSelectedItems().stream() + .map(BibEntryTableViewModel::getEntry) + .collect(Collectors.toList()); } /** @@ -381,6 +340,8 @@ private List getCurrentSortFields() { * is initialized with the sort order defined in Preferences. */ private void setupComparatorChooser() { + // TODO: Proper sorting + /* // First column: List comparators = comparatorChooser.getComparatorsForColumn(0); comparators.clear(); @@ -468,9 +429,10 @@ private void setupComparatorChooser() { Globals.prefs.putBoolean(JabRefPreferences.TABLE_TERTIARY_SORT_DESCENDING, false); } }); - +*/ } - +/* + // TODO: Reenable background coloring of fields (required/optional/...) private CellRendererMode getCellStatus(int row, int col, boolean checkResolved) { try { BibEntry be = getEntryAt(row); @@ -492,48 +454,12 @@ private CellRendererMode getCellStatus(int row, int col, boolean checkResolved) return CellRendererMode.OTHER; } } + */ - /** - * Use with caution! If you modify an entry in the table, the selection changes - * - * You can avoid it with - * .getSelected().getReadWriteLock().writeLock().lock() - * and then .unlock() - */ - public EventList getSelected() { - return localSelectionModel.getSelected(); - } - - /** - * Selects the given row - * - * @param row the row to select - */ - public void setSelected(int row) { - localSelectionModel.setSelectionInterval(row, row); - } - - public int findEntry(BibEntry entry) { - EventList tableRows = model.getTableRows(); - for (int row = 0; row < tableRows.size(); row++) { - BibEntry bibEntry = tableRows.get(row); - if (entry == bibEntry) { // NOPMD (equals doesn't recognise duplicates) - return row; - } - } - return -1; - } - - /** - * Method to check whether a MainTableColumn at the modelIndex refers to the file field (either as a specific - * file extension filter or not) - * - * @param modelIndex model index of the column to check - * @return true if the column shows the "file" field; false otherwise - */ - public boolean isFileColumn(int modelIndex) { - return (tableFormat.getTableColumn(modelIndex) != null) && tableFormat.getTableColumn(modelIndex) - .getBibtexFields().contains(FieldName.FILE); + public Optional findEntry(BibEntry entry) { + return model.getTableRows().stream() + .filter(viewModel -> viewModel.getEntry().equals(entry)) + .findFirst(); } private boolean matches(int row, Matcher m) { @@ -561,17 +487,12 @@ private int isMarked(int row) { private Optional getBibEntry(int row) { try { - return Optional.of(model.getTableRows().get(row)); + return Optional.of(model.getTableRows().get(row).getEntry()); } catch (IndexOutOfBoundsException e) { return Optional.empty(); } } - public void scrollTo(int y) { - JScrollBar scb = pane.getVerticalScrollBar(); - scb.setValue(y * scb.getUnitIncrement(1)); - } - public void showFloatSearch() { this.getTableModel().updateSearchState(MainTableDataModel.DisplayOption.FLOAT); @@ -582,79 +503,17 @@ public void showFloatSearch() { * Repaints the table with the most recent font configuration */ public void updateFont() { + /* + // TODO: Font & padding customization setFont(GUIGlobals.currentFont); int maxOfIconsAndFontSize = Math.max(GUIGlobals.currentFont.getSize(), Globals.prefs.getInt(JabRefPreferences.ICON_SIZE_SMALL)); setRowHeight(Globals.prefs.getInt(JabRefPreferences.TABLE_ROW_PADDING) + maxOfIconsAndFontSize); // Update Table header with new settings this.getTableHeader().setDefaultRenderer(new MainTableHeaderRenderer(this.getTableHeader().getDefaultRenderer())); this.getTableHeader().resizeAndRepaint(); + */ } - public void ensureVisible(int row) { - JScrollBar vert = pane.getVerticalScrollBar(); - int y = row * getRowHeight(); - if ((y < vert.getValue()) || ((y >= (vert.getValue() + vert.getVisibleAmount())) - && (model.getSearchState() != MainTableDataModel.DisplayOption.FLOAT))) { - scrollToCenter(row, 1); - } - } - - /** - * Ensures that the given entry is shown in the maintable. - * It also selects the given entry - * The execution is executed directly. Be sure that it happens in the EDT. - * - * @param entry the BibEntry to be shown - */ - public void ensureVisible(BibEntry entry) { - final int row = this.findEntry(entry); - if (row >= 0) { - if (this.getSelectedRowCount() == 0) { - this.setRowSelectionInterval(row, row); - } - this.ensureVisible(row); - } - } - - public void scrollToCenter(int rowIndex, int vColIndex) { - if (!(this.getParent() instanceof JViewport)) { - return; - } - - JViewport viewport = (JViewport) this.getParent(); - - // This rectangle is relative to the table where the - // northwest corner of cell (0,0) is always (0,0). - Rectangle rect = this.getCellRect(rowIndex, vColIndex, true); - - // The location of the view relative to the table - Rectangle viewRect = viewport.getViewRect(); - - // Translate the cell location so that it is relative - // to the view, assuming the northwest corner of the - // view is (0,0). - rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y); - - // Calculate location of rect if it were at the center of view - int centerX = (viewRect.width - rect.width) / 2; - int centerY = (viewRect.height - rect.height) / 2; - - // Fake the location of the cell so that scrollRectToVisible - // will move the cell to the center - if (rect.x < centerX) { - centerX = -centerX; - } - if (rect.y < centerY) { - centerY = -centerY; - } - rect.translate(centerX, centerY); - - // Scroll the area into view. - viewport.scrollRectToVisible(rect); - - revalidate(); - repaint(); - } public static void updateRenderers() { @@ -692,40 +551,4 @@ public static void updateRenderers() { private static Color mixColors(Color one, Color two) { return new Color((one.getRed() + two.getRed()) / 2, (one.getGreen() + two.getGreen()) / 2, (one.getBlue() + two.getBlue()) / 2); } - - private TableComparatorChooser createTableComparatorChooser(JTable table, SortedList list, Object sortingStrategy) { - return TableComparatorChooser.install(table, list, sortingStrategy); - } - - /** - * Morten Alver: This override is a workaround NullPointerException when - * dragging stuff into the table. I found this in a forum, but have no idea - * why it works. - * @param newUI - */ - @Override - public void setUI(TableUI newUI) { - super.setUI(newUI); - TransferHandler handler = getTransferHandler(); - setTransferHandler(null); - setTransferHandler(handler); - } - - /** - * Find out which column is set as sort column. - * @param number The position in the sort hierarchy (primary, secondary, etc.) - * @return The sort column number. - */ - public int getSortingColumn(int number) { - List l = comparatorChooser.getSortingColumns(); - if (l.size() <= number) { - return -1; - } else { - return l.get(number); - } - } - - public MainTableColumn getMainTableColumn(int modelIndex) { - return tableFormat.getTableColumn(modelIndex); - } } diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumn.java b/src/main/java/org/jabref/gui/maintable/MainTableColumn.java index 18fd5e141dc..815f623f3a0 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumn.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumn.java @@ -1,160 +1,15 @@ package org.jabref.gui.maintable; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.StringJoiner; +import javafx.beans.value.ObservableValue; +import javafx.scene.control.TableColumn; -import javax.swing.JLabel; +abstract class MainTableColumn extends TableColumn { -import org.jabref.logic.layout.LayoutFormatter; -import org.jabref.logic.layout.format.LatexToUnicodeFormatter; -import org.jabref.model.database.BibDatabase; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.FieldProperty; -import org.jabref.model.entry.InternalBibtexFields; + MainTableColumn(String text) { + super(text); -public class MainTableColumn { - - private final String columnName; - - private final List bibtexFields; - - private final boolean isIconColumn; - - private final Optional iconLabel; - - private final Optional database; - - private final LayoutFormatter toUnicode = new LatexToUnicodeFormatter(); - - public MainTableColumn(String columnName) { - this.columnName = columnName; - this.bibtexFields = Collections.emptyList(); - this.isIconColumn = false; - this.iconLabel = Optional.empty(); - this.database = Optional.empty(); - } - - public MainTableColumn(String columnName, List bibtexFields, BibDatabase database) { - this.columnName = columnName; - this.bibtexFields = Collections.unmodifiableList(bibtexFields); - this.isIconColumn = false; - this.iconLabel = Optional.empty(); - this.database = Optional.of(database); - } - - public MainTableColumn(String columnName, List bibtexFields, JLabel iconLabel) { - this.columnName = columnName; - this.bibtexFields = Collections.unmodifiableList(bibtexFields); - this.isIconColumn = true; - this.iconLabel = Optional.of(iconLabel); - this.database = Optional.empty(); - } - - /** - * Get the table column name to be displayed in the UI - * - * @return name to be displayed. null if field is empty. - */ - public String getDisplayName() { - if (bibtexFields.isEmpty()) { - return null; - } - - StringJoiner joiner = new StringJoiner(FieldName.FIELD_SEPARATOR); - for (String field : bibtexFields) { - joiner.add(field); - } - return joiner.toString(); - } - - public String getColumnName() { - return columnName; - } - - public List getBibtexFields() { - return bibtexFields; - } - - public boolean isIconColumn() { - return isIconColumn; - } - - public boolean isFileFilter() { - return false; // Overridden in SpecialMainTableColumns for file filter columns + setCellValueFactory(param -> getColumnValue(param.getValue())); } - public Object getColumnValue(BibEntry entry) { - if (bibtexFields.isEmpty()) { - return null; - } - boolean isNameColumn = false; - - Optional content = Optional.empty(); - for (String field : bibtexFields) { - content = entry.getResolvedFieldOrAlias(field, database.orElse(null)); - if (content.isPresent()) { - isNameColumn = InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.PERSON_NAMES); - break; - } - } - - String result = content.orElse(null); - - if (isNameColumn) { - result = toUnicode.format(MainTableNameFormatter.formatName(result)); - } - - if (result != null && !BibEntry.KEY_FIELD.equals(columnName)) { - result = toUnicode.format(result).trim(); - } - - return result; - } - - public JLabel getHeaderLabel() { - if (isIconColumn) { - return iconLabel.get(); - } else { - return new JLabel(getDisplayName()); - } - } - - /** - * Check if the value returned by getColumnValue() is the same as a simple check of the entry's field(s) would give - * The reasons for being different are (combinations may also happen): - * - The entry has a crossref where the field content is obtained from - * - The field has a string in it (which getColumnValue() resolves) - * - There are some alias fields. For example, if the entry has a date field but no year field, - * {@link BibEntry#getResolvedFieldOrAlias(String, BibDatabase)} will return the year value from the date field - * when queried for year - * - * @param entry the BibEntry - * @return true if the value returned by getColumnValue() is resolved as outlined above - */ - public boolean isResolved(BibEntry entry) { - if (bibtexFields.isEmpty()) { - return false; - } - - Optional resolvedFieldContent = Optional.empty(); - Optional plainFieldContent = Optional.empty(); - for (String field : bibtexFields) { - // entry type or bibtex key will never be resolved - if (BibEntry.TYPE_HEADER.equals(field) || BibEntry.OBSOLETE_TYPE_HEADER.equals(field) - || BibEntry.KEY_FIELD.equals(field)) { - return false; - } else { - plainFieldContent = entry.getField(field); - resolvedFieldContent = entry.getResolvedFieldOrAlias(field, database.orElse(null)); - } - - if (resolvedFieldContent.isPresent()) { - break; - } - } - return (!resolvedFieldContent.equals(plainFieldContent)); - } + abstract ObservableValue getColumnValue(BibEntryTableViewModel entry); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java index 3fc3065d8ac..b2696d6d04f 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java @@ -6,6 +6,9 @@ import java.util.Objects; import java.util.stream.Collectors; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + import org.jabref.gui.groups.GroupMatcher; import org.jabref.gui.search.HitOrMissComparator; import org.jabref.gui.search.matchers.EverythingMatcher; @@ -27,7 +30,7 @@ public class MainTableDataModel { private final SortedList sortedForMarkingSearchGrouping; private final StartStopListFilterAction filterSearchToggle; private final StartStopListFilterAction filterGroupToggle; - private final EventList finalList; + private final ObservableList finalList; private final FilterAndSortingState filterAndSortingState = new FilterAndSortingState(); public MainTableDataModel(BibDatabaseContext context) { @@ -51,7 +54,9 @@ public MainTableDataModel(BibDatabaseContext context) { filterSearchToggle = new StartStopListFilterAction(searchFilterList, SearchMatcher.INSTANCE, EverythingMatcher.INSTANCE); - finalList = searchFilterList; + // TODO + //finalList = searchFilterList; + finalList = FXCollections.observableArrayList(entries.stream().map(BibEntryTableViewModel::new).collect(Collectors.toList())); } public void updateSortOrder() { @@ -146,15 +151,11 @@ public void updateMarkingState(boolean floatMarkedEntries) { return; } - if (floatMarkedEntries) { - filterAndSortingState.markingState = true; - } else { - filterAndSortingState.markingState = false; - } + filterAndSortingState.markingState = floatMarkedEntries; updateSortOrder(); } - EventList getTableRows() { + ObservableList getTableRows() { return finalList; } diff --git a/src/main/java/org/jabref/gui/maintable/MainTableFormat.java b/src/main/java/org/jabref/gui/maintable/MainTableFormat.java deleted file mode 100644 index 2dda88ae52f..00000000000 --- a/src/main/java/org/jabref/gui/maintable/MainTableFormat.java +++ /dev/null @@ -1,153 +0,0 @@ -package org.jabref.gui.maintable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import javax.swing.JLabel; - -import org.jabref.Globals; -import org.jabref.gui.IconTheme; -import org.jabref.model.database.BibDatabase; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; -import org.jabref.preferences.JabRefPreferences; - -import ca.odell.glazedlists.gui.TableFormat; - -/** - * Class defining the contents and column headers of the main table. - */ -public class MainTableFormat implements TableFormat { - - // Values to gather iconImages for those columns - // These values are also used to put a heading into the table; see getColumnName(int) - private static final List URL_FIRST = Arrays.asList(FieldName.URL, FieldName.DOI); - private static final List DOI_FIRST = Arrays.asList(FieldName.DOI, FieldName.URL); - private static final List ARXIV = Collections.singletonList(FieldName.EPRINT); - - private final BibDatabase database; - - private final List tableColumns = new ArrayList<>(); - - public MainTableFormat(BibDatabase database) { - this.database = database; - } - - @Override - public int getColumnCount() { - return tableColumns.size(); - } - - /** - * @return the string that should be put in the column header. null if field is empty. - */ - @Override - public String getColumnName(int col) { - return tableColumns.get(col).getDisplayName(); - - } - - public MainTableColumn getTableColumn(int index) { - return tableColumns.get(index); - } - - /** - * Finds the column index for the given column name. - * - * @param colName The column name - * @return The column index if any, or -1 if no column has that name. - */ - public int getColumnIndex(String colName) { - - for (MainTableColumn tableColumn : tableColumns) { - if (tableColumn.getColumnName().equalsIgnoreCase(colName)) { - return tableColumns.lastIndexOf(tableColumn); - } - } - - return -1; - } - - @Override - public Object getColumnValue(BibEntry be, int col) { - return tableColumns.get(col).getColumnValue(be); - } - - public void updateTableFormat() { - // clear existing column configuration - tableColumns.clear(); - - SpecialMainTableColumnsBuilder builder = new SpecialMainTableColumnsBuilder(); - // Add numbering column to tableColumns - tableColumns.add(builder.buildNumberColumn()); - - // Add all file based columns - if (Globals.prefs.getBoolean(JabRefPreferences.FILE_COLUMN)) { - tableColumns.add(builder.buildFileColumn()); - } - - if (Globals.prefs.getBoolean(JabRefPreferences.URL_COLUMN)) { - if (Globals.prefs.getBoolean(JabRefPreferences.PREFER_URL_DOI)) { - tableColumns.add(builder - .createIconColumn(JabRefPreferences.URL_COLUMN, MainTableFormat.DOI_FIRST, - new JLabel(IconTheme.JabRefIcon.DOI.getSmallIcon()))); - } else { - tableColumns.add(builder - .createIconColumn(JabRefPreferences.URL_COLUMN, MainTableFormat.URL_FIRST, - new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon()))); - } - - } - - if (Globals.prefs.getBoolean(JabRefPreferences.ARXIV_COLUMN)) { - tableColumns.add(builder - .createIconColumn(JabRefPreferences.ARXIV_COLUMN, MainTableFormat.ARXIV, - new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon()))); - } - - if (Globals.prefs.getBoolean(JabRefPreferences.EXTRA_FILE_COLUMNS)) { - List desiredColumns = Globals.prefs.getStringList(JabRefPreferences.LIST_OF_FILE_COLUMNS); - for (String desiredColumn : desiredColumns) { - tableColumns.add(builder.createFileIconColumn(desiredColumn)); - } - } - - // Add 'normal' bibtex fields as configured in the preferences - // Read table columns from prefs: - List colSettings = Globals.prefs.getStringList(JabRefPreferences.COLUMN_NAMES); - - for (String columnName : colSettings) { - // stored column name will be used as columnName - // There might be more than one field to display, e.g., "author/editor" or "date/year" - so split - // at MainTableFormat.COL_DEFINITION_FIELD_SEPARATOR - String[] fields = columnName.split(FieldName.FIELD_SEPARATOR); - tableColumns.add(new MainTableColumn(columnName, Arrays.asList(fields), database)); - } - - // Add the "special" icon columns (e.g., ranking, file, ...) that are enabled in preferences. - if (Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) { - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) { - tableColumns.add(builder.buildRankingColumn()); - } - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RELEVANCE)) { - tableColumns.add(builder.buildRelevanceColumn()); - } - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_QUALITY)) { - tableColumns.add(builder.buildQualityColumn()); - } - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) { - tableColumns.add(builder.buildPriorityColumn()); - } - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRINTED)) { - tableColumns.add(builder.buildPrintedColumn()); - } - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) { - tableColumns.add(builder.buildReadStatusColumn()); - } - } - - } - -} diff --git a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRenderer.java b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRenderer.java deleted file mode 100644 index 475ed261b0c..00000000000 --- a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRenderer.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.jabref.gui.maintable; - -import java.awt.Component; - -import javax.swing.Icon; -import javax.swing.JLabel; -import javax.swing.JTable; -import javax.swing.table.TableCellRenderer; - -import org.jabref.gui.GUIGlobals; - -public class MainTableHeaderRenderer implements TableCellRenderer { - - private final TableCellRenderer delegate; - - public MainTableHeaderRenderer(TableCellRenderer delegate) { - this.delegate = delegate; - } - - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, - boolean hasFocus, int row, int column) { - // delegate to previously used TableCellRenderer which styles the component - Component resultFromDelegate = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - - // Changing style is only possible if both value and resultFromDelegate are JLabels - if ((value instanceof JLabel) && (resultFromDelegate instanceof JLabel)) { - String text = ((JLabel) value).getText(); - Icon icon = ((JLabel) value).getIcon(); - if (icon == null) { - ((JLabel) resultFromDelegate).setText(text); - resultFromDelegate.setFont(GUIGlobals.currentFont); - } else { - ((JLabel) resultFromDelegate).setIcon(icon); - ((JLabel) resultFromDelegate).setText(null); - } - } - - return resultFromDelegate; - } -} diff --git a/src/main/java/org/jabref/gui/maintable/MainTableSelectionListener.java b/src/main/java/org/jabref/gui/maintable/MainTableSelectionListener.java index 8977efcf50a..dcbf0fdc7d7 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableSelectionListener.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableSelectionListener.java @@ -6,43 +6,17 @@ import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.io.IOException; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import javax.swing.Icon; -import javax.swing.JLabel; import javax.swing.JPopupMenu; -import javax.swing.SwingUtilities; import javax.swing.Timer; -import org.jabref.Globals; -import org.jabref.JabRefExecutorService; -import org.jabref.JabRefGUI; import org.jabref.gui.BasePanel; import org.jabref.gui.BasePanelMode; -import org.jabref.gui.GUIGlobals; -import org.jabref.gui.IconTheme; import org.jabref.gui.PreviewPanel; -import org.jabref.gui.actions.CopyDoiUrlAction; -import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.entryeditor.EntryEditor; -import org.jabref.gui.externalfiletype.ExternalFileMenuItem; -import org.jabref.gui.externalfiletype.ExternalFileType; -import org.jabref.gui.filelist.FileListEntry; -import org.jabref.gui.filelist.FileListTableModel; -import org.jabref.gui.menus.RightClickMenu; -import org.jabref.gui.specialfields.SpecialFieldMenuAction; -import org.jabref.gui.specialfields.SpecialFieldValueViewModel; -import org.jabref.gui.specialfields.SpecialFieldViewModel; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.specialfields.SpecialField; -import org.jabref.model.entry.specialfields.SpecialFieldValue; +import ca.odell.glazedlists.BasicEventList; import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.event.ListEvent; import ca.odell.glazedlists.event.ListEventListener; @@ -74,7 +48,7 @@ public class MainTableSelectionListener implements ListEventListener, public MainTableSelectionListener(BasePanel panel, MainTable table) { this.table = table; this.panel = panel; - this.tableRows = table.getTableModel().getTableRows(); + this.tableRows = new BasicEventList<>(); preview = panel.getPreviewPanel(); } @@ -101,6 +75,8 @@ public void listChanged(ListEvent e) { } if (newSelected != null) { + // TODO: Update entry editor / preview on selection change + /* final BasePanelMode mode = panel.getMode(); // What is the panel already showing? if ((mode == BasePanelMode.WILL_SHOW_EDITOR) || (mode == BasePanelMode.SHOWING_EDITOR)) { panel.showAndEdit(newSelected); @@ -109,6 +85,7 @@ public void listChanged(ListEvent e) { // Either nothing or a preview was shown. Update the preview. updatePreview(newSelected); } + */ } } @@ -126,6 +103,7 @@ private void updatePreview(final BibEntry toShow, int repeats) { t.start(); return; } + /* EventList list = table.getSelected(); // Check if the entry to preview is still selected: if ((list.size() != 1) || (list.get(0) != toShow)) { @@ -136,28 +114,13 @@ private void updatePreview(final BibEntry toShow, int repeats) { panel.showPreview(toShow); workingOnPreview = false; }); - } - - public void editSignalled() { - if (table.getSelected().size() == 1) { - editSignalled(table.getSelected().get(0)); - } - } - - public void editSignalled(BibEntry entry) { - panel.showAndEdit(entry); + */ } @Override public void mouseReleased(MouseEvent e) { - // First find the column and row on which the user has clicked. - final int col = table.columnAtPoint(e.getPoint()); - final int row = table.rowAtPoint(e.getPoint()); - - // get the MainTableColumn which is currently visible at col - int modelIndex = table.getColumnModel().getColumn(col).getModelIndex(); - MainTableColumn modelColumn = table.getMainTableColumn(modelIndex); - + // TODO: Right-click menu for special columns + /* // Check if the user has right-clicked. If so, open the right-click menu. if (e.isPopupTrigger() || (e.getButton() == MouseEvent.BUTTON3)) { if ((modelColumn == null) || !modelColumn.isIconColumn()) { @@ -168,6 +131,7 @@ public void mouseReleased(MouseEvent e) { showIconRightClickMenu(e, row, modelColumn); } } + */ } @Override @@ -177,14 +141,14 @@ public void mousePressed(MouseEvent e) { @Override public void mouseClicked(MouseEvent e) { - + /* // First find the column on which the user has clicked. final int row = table.rowAtPoint(e.getPoint()); // A double click on an entry should open the entry's editor. if (e.getClickCount() == 2) { BibEntry toShow = tableRows.get(row); - editSignalled(toShow); + panel.showAndEdit(toShow); return; } @@ -269,6 +233,7 @@ public void mouseClicked(MouseEvent e) { .ifPresent(crossref -> panel.getDatabase().getEntryByKey(crossref).ifPresent(entry -> panel.highlightEntry(entry))); } panel.frame().updateEnabledState(); + */ } /** @@ -279,6 +244,7 @@ public void mouseClicked(MouseEvent e) { * @param columnName the name of the specialfield column */ private void handleSpecialFieldLeftClick(MouseEvent e, String columnName) { + /* if ((e.getClickCount() == 1)) { SpecialField.getSpecialFieldInstanceFromFieldName(columnName).ifPresent(field -> { // special field found @@ -294,6 +260,7 @@ private void handleSpecialFieldLeftClick(MouseEvent e, String columnName) { } }); } + */ } /** @@ -303,12 +270,14 @@ private void handleSpecialFieldLeftClick(MouseEvent e, String columnName) { * @param row The row where the event occurred. */ private void processPopupTrigger(MouseEvent e, int row) { + /* int selRow = table.getSelectedRow(); if ((selRow == -1) || !table.isRowSelected(table.rowAtPoint(e.getPoint()))) { table.setRowSelectionInterval(row, row); } RightClickMenu rightClickMenu = new RightClickMenu(JabRefGUI.getMainFrame(), panel); rightClickMenu.show(table, e.getX(), e.getY()); + */ } /** @@ -325,6 +294,7 @@ private void showIconRightClickMenu(MouseEvent e, int row, MainTableColumn colum JPopupMenu menu = new JPopupMenu(); boolean showDefaultPopup = true; + /* // See if this is a simple file link field, or if it is a file-list // field that can specify a list of links: if (!column.getBibtexFields().isEmpty()) { @@ -378,9 +348,11 @@ private void showIconRightClickMenu(MouseEvent e, int row, MainTableColumn colum menu.show(table, e.getX(), e.getY()); } } + */ } public void entryEditorClosing(EntryEditor editor) { + /* if (Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()) { panel.showPreview(editor.getEntry()); } else { @@ -388,6 +360,7 @@ public void entryEditorClosing(EntryEditor editor) { panel.adjustSplitter(); } table.requestFocus(); + */ } @Override @@ -408,6 +381,7 @@ public void mouseExited(MouseEvent e) { */ @Override public void keyTyped(KeyEvent e) { + /* if ((!e.isActionKey()) && Character.isLetterOrDigit(e.getKeyChar()) && (e.getModifiers() == 0)) { long time = System.currentTimeMillis(); @@ -456,6 +430,7 @@ public void keyTyped(KeyEvent e) { lastPressedCount = 0; } panel.frame().updateEnabledState(); + */ } @Override diff --git a/src/main/java/org/jabref/gui/maintable/PersistenceTableColumnListener.java b/src/main/java/org/jabref/gui/maintable/PersistenceTableColumnListener.java index 538d9ac695f..a2fde3ff259 100644 --- a/src/main/java/org/jabref/gui/maintable/PersistenceTableColumnListener.java +++ b/src/main/java/org/jabref/gui/maintable/PersistenceTableColumnListener.java @@ -1,18 +1,10 @@ package org.jabref.gui.maintable; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - import javax.swing.event.ChangeEvent; import javax.swing.event.ListSelectionEvent; import javax.swing.event.TableColumnModelEvent; import javax.swing.event.TableColumnModelListener; -import org.jabref.Globals; -import org.jabref.model.entry.FieldName; -import org.jabref.preferences.JabRefPreferences; - /** * Listens for TableColumnModelEvents to keep track of changes made to the * MainTable columns, like reordering or resizing. @@ -46,6 +38,7 @@ public PersistenceTableColumnListener(final MainTable mainTable) { * update columns names and their width, store it in the global prefs. */ private void updateColumnPrefs() { + /* final int columnCount = mainTable.getColumnCount(); List storedColumns = new ArrayList<>(columnCount - 1); List columnsWidths = new ArrayList<>(columnCount - 1); @@ -69,6 +62,7 @@ private void updateColumnPrefs() { // width of the number ("#") column Globals.prefs.putInt(JabRefPreferences.NUMBER_COL_WIDTH, ncWidth); + */ } /** diff --git a/src/main/java/org/jabref/gui/maintable/PreventDraggingJTableHeader.java b/src/main/java/org/jabref/gui/maintable/PreventDraggingJTableHeader.java deleted file mode 100644 index cefacd64f2c..00000000000 --- a/src/main/java/org/jabref/gui/maintable/PreventDraggingJTableHeader.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.jabref.gui.maintable; - -import java.awt.event.MouseEvent; -import java.util.Collections; -import java.util.Enumeration; - -import javax.swing.JTable; -import javax.swing.table.JTableHeader; -import javax.swing.table.TableColumn; - -/** - * Related to MainTable class.
- * Prevents dragging of the first header column ("#") and shows icons in the table header if an icon has to be set. - * - * This might not be the best way to solve this problem. Overriding - * getDraggedColumn produces some ugly gui dragging artifacts if a - * user attempts to drag something before the first columns. - * - * @author Daniel Waeber - * @author Fabian Bieker - * @since 12/2008 - */ -class PreventDraggingJTableHeader extends JTableHeader { - - private final MainTableFormat tableFormat; - - public PreventDraggingJTableHeader(JTable table, MainTableFormat tableFormat) { - super(table.getColumnModel()); - this.setTable(table); - this.tableFormat = tableFormat; - setupTableHeaderIcons(); - } - - private void setupTableHeaderIcons() { - - Enumeration columns = columnModel.getColumns(); - for (TableColumn column : Collections.list(columns)) { - MainTableColumn mainTableColumn = tableFormat.getTableColumn(column.getModelIndex()); - column.setHeaderValue(mainTableColumn.getHeaderLabel()); - } - - } - - @Override - public String getToolTipText(MouseEvent event) { - int index = columnModel.getColumnIndexAtX(event.getX()); - int realIndex = columnModel.getColumn(index).getModelIndex(); - MainTableColumn column = tableFormat.getTableColumn(realIndex); - return column.getDisplayName(); - } - - /** - * Overridden to prevent dragging of first column ("#") - */ - @Override - public void setDraggedColumn(TableColumn column) { - - if ((column != null) && (column.getModelIndex() == 0)) { - return; - } - super.setDraggedColumn(column); - } - - /** - * Overridden to prevent dragging of an other column before the first column ("#"). - */ - @Override - public TableColumn getDraggedColumn() { - TableColumn column = super.getDraggedColumn(); - if (column != null) { - PreventDraggingJTableHeader.preventDragBeforeNumberColumn(this.getTable(), column.getModelIndex()); - } - - return column; - } - - /** - * Transform model index modelIndex to a view based index and - * prevent dragging before model index toIndex (inclusive). - */ - private static void preventDragBeforeNumberColumn(JTable table, int modelIndex) { - - for (int columnIndex = 0; columnIndex < table.getColumnCount(); columnIndex++) { - - TableColumn col = table.getColumnModel().getColumn(columnIndex); - - // found the element in the view ... - // ... and check if it should not be dragged - if ((col.getModelIndex() == modelIndex) && (columnIndex < 1)) { - // prevent dragging (move it back ...) - table.getColumnModel().moveColumn(columnIndex, 1); - return; // we are done now - } - - } - } -} diff --git a/src/main/java/org/jabref/gui/maintable/SpecialMainTableColumnsBuilder.java b/src/main/java/org/jabref/gui/maintable/SpecialMainTableColumnsBuilder.java deleted file mode 100644 index 415b3082fe5..00000000000 --- a/src/main/java/org/jabref/gui/maintable/SpecialMainTableColumnsBuilder.java +++ /dev/null @@ -1,203 +0,0 @@ -package org.jabref.gui.maintable; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import javax.swing.JLabel; - -import org.jabref.gui.GUIGlobals; -import org.jabref.gui.IconTheme; -import org.jabref.gui.externalfiletype.ExternalFileType; -import org.jabref.gui.filelist.FileListTableModel; -import org.jabref.gui.specialfields.SpecialFieldValueViewModel; -import org.jabref.gui.specialfields.SpecialFieldViewModel; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.specialfields.SpecialField; - -class SpecialMainTableColumnsBuilder { - - MainTableColumn buildNumberColumn() { - - return new MainTableColumn(FieldName.NUMBER_COL) { - - @Override - public Object getColumnValue(BibEntry entry) { - return "#"; - } - - @Override - public String getDisplayName() { - return "#"; - } - } - - ; - } - - MainTableColumn buildRankingColumn() { - - return new MainTableColumn(SpecialField.RANKING.getFieldName(), - Collections.singletonList(SpecialField.RANKING.getFieldName()), - new JLabel(SpecialField.RANKING.getFieldName())) { - - @Override - public Object getColumnValue(BibEntry entry) { - - return entry.getField(SpecialField.RANKING.getFieldName()) - .flatMap(SpecialField.RANKING::parse).map(rank -> new SpecialFieldValueViewModel(rank).createSpecialFieldValueLabel()).orElse(null); - } - }; - } - - MainTableColumn buildPriorityColumn() { - return new MainTableColumn(SpecialField.PRIORITY.getFieldName(), - Collections.singletonList(SpecialField.PRIORITY.getFieldName()), - new JLabel(new SpecialFieldViewModel(SpecialField.PRIORITY).getRepresentingIcon())) { - - @Override - public Object getColumnValue(BibEntry entry) { - - return entry.getField(SpecialField.PRIORITY.getFieldName()) - .flatMap(SpecialField.PRIORITY::parse).map(prio -> new SpecialFieldValueViewModel(prio).createSpecialFieldValueLabel()).orElse(null); - } - }; - } - - MainTableColumn buildReadStatusColumn() { - return new MainTableColumn(SpecialField.READ_STATUS.getFieldName(), - Collections.singletonList(SpecialField.READ_STATUS.getFieldName()), - new JLabel(new SpecialFieldViewModel(SpecialField.READ_STATUS).getRepresentingIcon())) { - - @Override - public Object getColumnValue(BibEntry entry) { - - return entry.getField(SpecialField.READ_STATUS.getFieldName()) - .flatMap(SpecialField.READ_STATUS::parse).map(status -> new SpecialFieldValueViewModel(status).createSpecialFieldValueLabel()).orElse(null); - } - }; - } - - MainTableColumn buildRelevanceColumn() { - return createIconColumn(SpecialField.RELEVANCE.getFieldName(), - Collections.singletonList(SpecialField.RELEVANCE.getFieldName()), - new JLabel(new SpecialFieldViewModel(SpecialField.RELEVANCE).getRepresentingIcon())); - } - - MainTableColumn buildPrintedColumn() { - return createIconColumn(SpecialField.PRINTED.getFieldName(), - Collections.singletonList(SpecialField.PRINTED.getFieldName()), - new JLabel(new SpecialFieldViewModel(SpecialField.PRINTED).getRepresentingIcon())); - } - - MainTableColumn buildQualityColumn() { - return createIconColumn(SpecialField.QUALITY.getFieldName(), - Collections.singletonList(SpecialField.QUALITY.getFieldName()), - new JLabel(new SpecialFieldViewModel(SpecialField.QUALITY).getRepresentingIcon())); - } - - MainTableColumn buildFileColumn() { - - return new MainTableColumn(FieldName.FILE, - Collections.singletonList(FieldName.FILE), new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon())) { - - @Override - public Object getColumnValue(BibEntry entry) { - // We use a FileListTableModel to parse the field content: - FileListTableModel fileList = new FileListTableModel(); - entry.getField(FieldName.FILE).ifPresent(fileList::setContent); - if (fileList.getRowCount() > 1) { - return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon()); - } else if (fileList.getRowCount() == 1) { - Optional type = fileList.getEntry(0).getType(); - if (type.isPresent()) { - return type.get().getIconLabel(); - } else { - return new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon()); - } - } - - return null; - } - }; - } - - /** - * Creates a MainTableColumn which shows an icon instead textual content - * - * @param columnName the name of the column - * @param fields the entry fields which should be shown - * @return the crated MainTableColumn - */ - MainTableColumn createIconColumn(String columnName, List fields, JLabel iconLabel) { - return new MainTableColumn(columnName, fields, iconLabel) { - - @Override - public Object getColumnValue(BibEntry entry) { - JLabel iconLabel = null; - boolean iconFound = false; - - // check for each field whether content is available - for (String field : fields) { - if (entry.hasField(field)) { - if (iconFound) { - return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon()); - } else { - iconLabel = GUIGlobals.getTableIcon(field); - iconFound = true; - } - - } - } - return iconLabel; - } - }; - } - - /** - * create a MainTableColumn for specific file types. - *

- * Shows the icon for the given type (or the FILE_MULTIPLE icon) - * - * @param externalFileTypeName the name of the externalFileType - * @return the created MainTableColumn - */ - MainTableColumn createFileIconColumn(String externalFileTypeName) { - - return new MainTableColumn(externalFileTypeName, Collections.singletonList(FieldName.FILE), new JLabel()) { - - @Override - public boolean isFileFilter() { - return true; - } - - @Override - public String getDisplayName() { - return externalFileTypeName; - } - - @Override - public Object getColumnValue(BibEntry entry) { - - boolean iconFound = false; - JLabel iconLabel = null; - FileListTableModel fileList = new FileListTableModel(); - entry.getField(FieldName.FILE).ifPresent(fileList::setContent); - for (int i = 0; i < fileList.getRowCount(); i++) { - if ((fileList.getEntry(i).getType().isPresent()) - && externalFileTypeName.equalsIgnoreCase(fileList.getEntry(i).getType().get().getName())) { - if (iconFound) { - // already found another file of the desired type - show FILE_MULTIPLE Icon - return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon()); - } else { - iconLabel = fileList.getEntry(i).getType().get().getIconLabel(); - iconFound = true; - } - } - } - return iconLabel; - } - }; - } -} diff --git a/src/main/java/org/jabref/gui/menus/RightClickMenu.java b/src/main/java/org/jabref/gui/menus/RightClickMenu.java index f77f2ed3101..4903310c535 100644 --- a/src/main/java/org/jabref/gui/menus/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/menus/RightClickMenu.java @@ -59,8 +59,8 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { // If only one entry is selected, get a reference to it for adapting the menu. BibEntry be = null; - if (panel.getMainTable().getSelectedRowCount() == 1) { - be = panel.getMainTable().getSelected().get(0); + if (panel.getMainTable().getSelectedEntries().size() == 1) { + be = panel.getMainTable().getSelectedEntries().get(0); } addPopupMenuListener(this); @@ -229,11 +229,11 @@ public static void populateSpecialFieldMenu(JMenu menu, SpecialField field, JabR } private boolean areMultipleEntriesSelected() { - return panel.getMainTable().getSelectedRowCount() > 1; + return panel.getMainTable().getSelectedEntries().size() > 1; } private boolean areExactlyTwoEntriesSelected() { - return panel.getMainTable().getSelectedRowCount() == 2; + return panel.getMainTable().getSelectedEntries().size() == 2; } /** @@ -262,16 +262,16 @@ private boolean isFieldSetForSelectedEntry(String fieldname) { } private boolean isAnyFieldSetForSelectedEntry(List fieldnames) { - if (panel.getMainTable().getSelectedRowCount() == 1) { - BibEntry entry = panel.getMainTable().getSelected().get(0); + if (panel.getMainTable().getSelectedEntries().size() == 1) { + BibEntry entry = panel.getMainTable().getSelectedEntries().get(0); return !Collections.disjoint(fieldnames, entry.getFieldNames()); } return false; } private Icon getFileIconForSelectedEntry() { - if (panel.getMainTable().getSelectedRowCount() == 1) { - BibEntry entry = panel.getMainTable().getSelected().get(0); + if (panel.getMainTable().getSelectedEntries().size() == 1) { + BibEntry entry = panel.getMainTable().getSelectedEntries().get(0); if (entry.hasField(FieldName.FILE)) { JLabel label = FileListTableModel.getFirstLabel(entry.getField(FieldName.FILE).get()); if (label != null) { diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index 0ea66468474..71ddb2eb270 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -22,7 +22,6 @@ import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JMenuItem; @@ -43,7 +42,6 @@ import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.desktop.os.NativeDesktop; import org.jabref.gui.help.HelpAction; -import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableKeyChange; import org.jabref.gui.util.DefaultTaskExecutor; @@ -304,9 +302,11 @@ public void actionPerformed(ActionEvent e) { content.setLayout(new BorderLayout()); content.add(mainBuilder.getPanel(), BorderLayout.CENTER); + /* frame.getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(Globals.getKeyPrefs().getKey(KeyBinding.REFRESH_OO), "Refresh OO"); frame.getTabbedPane().getActionMap().put("Refresh OO", updateAction); + */ } diff --git a/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java b/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java index 6e600ed7e13..525b223b06e 100644 --- a/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java +++ b/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java @@ -614,12 +614,14 @@ public void actionPerformed(ActionEvent e) { final HashMap map = new HashMap<>(); // first element (#) not inside tableRows - for (int i = 1; i < panel.getMainTable().getColumnCount(); i++) { - String name = panel.getMainTable().getColumnName(i); + /* + for (TableColumn column : panel.getMainTable().getColumns()) { + String name = column.getText(); if ((name != null) && !name.isEmpty()) { map.put(name.toLowerCase(Locale.ROOT), i); } } + */ Collections.sort(tableRows, (o1, o2) -> { Integer n1 = map.get(o1.getName()); Integer n2 = map.get(o2.getName()); @@ -647,6 +649,7 @@ public void actionPerformed(ActionEvent e) { if (panel == null) { return; } + /* TableColumnModel colMod = panel.getMainTable().getColumnModel(); colSetup.setValueAt(String.valueOf(colMod.getColumn(0).getWidth()), 0, 1); for (int i = 1; i < colMod.getColumnCount(); i++) { @@ -669,6 +672,7 @@ public void actionPerformed(ActionEvent e) { colSetup.revalidate(); colSetup.repaint(); } + */ } } diff --git a/src/main/java/org/jabref/gui/preftabs/TablePrefsTab.java b/src/main/java/org/jabref/gui/preftabs/TablePrefsTab.java index 6d73757e08d..0ae9570d1c9 100644 --- a/src/main/java/org/jabref/gui/preftabs/TablePrefsTab.java +++ b/src/main/java/org/jabref/gui/preftabs/TablePrefsTab.java @@ -13,7 +13,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; -import javax.swing.JTable; import javax.swing.JTextField; import org.jabref.Globals; @@ -208,8 +207,7 @@ public TablePrefsTab(JabRefPreferences prefs) { @Override public void setValues() { - autoResizeMode - .setSelected(prefs.getInt(JabRefPreferences.AUTO_RESIZE_MODE) == JTable.AUTO_RESIZE_ALL_COLUMNS); + autoResizeMode.setSelected(prefs.getBoolean(JabRefPreferences.AUTO_RESIZE_MODE)); priField.setText(prefs.get(JabRefPreferences.TABLE_PRIMARY_SORT_FIELD)); secField.setText(prefs.get(JabRefPreferences.TABLE_SECONDARY_SORT_FIELD)); @@ -267,8 +265,7 @@ public void storeSettings() { prefs.putBoolean(JabRefPreferences.NAMES_LAST_ONLY, lastNamesOnly.isSelected()); prefs.putBoolean(JabRefPreferences.ABBR_AUTHOR_NAMES, abbrNames.isSelected()); - prefs.putInt(JabRefPreferences.AUTO_RESIZE_MODE, - autoResizeMode.isSelected() ? JTable.AUTO_RESIZE_ALL_COLUMNS : JTable.AUTO_RESIZE_OFF); + prefs.putBoolean(JabRefPreferences.AUTO_RESIZE_MODE, autoResizeMode.isSelected()); prefs.putBoolean(JabRefPreferences.TABLE_PRIMARY_SORT_DESCENDING, priDesc.isSelected()); prefs.putBoolean(JabRefPreferences.TABLE_SECONDARY_SORT_DESCENDING, secDesc.isSelected()); prefs.putBoolean(JabRefPreferences.TABLE_TERTIARY_SORT_DESCENDING, terDesc.isSelected()); diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 5ded0d496b0..1ea33721900 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -18,7 +18,6 @@ import javax.swing.JPanel; import javax.swing.JToggleButton; import javax.swing.JToolBar; -import javax.swing.SwingUtilities; import javafx.css.PseudoClass; import javafx.embed.swing.JFXPanel; @@ -29,7 +28,6 @@ import javafx.scene.text.TextFlow; import org.jabref.Globals; -import org.jabref.gui.AbstractView; import org.jabref.gui.BasePanel; import org.jabref.gui.GUIGlobals; import org.jabref.gui.IconTheme; @@ -184,13 +182,8 @@ public void actionPerformed(ActionEvent e) { EasyBind.subscribe(searchField.textProperty(), searchText -> performSearch()); - container = CustomJFXPanel.create(); - DefaultTaskExecutor.runInJavaFXThread(() -> { - Scene scene = new Scene(searchField); - scene.getStylesheets().add(AbstractView.class.getResource("Main.css").toExternalForm()); - container.setScene(scene); - container.addKeyListener(new SearchKeyAdapter()); - }); + container = CustomJFXPanel.wrap(new Scene(searchField)); + container.addKeyListener(new SearchKeyAdapter()); setLayout(new FlowLayout(FlowLayout.RIGHT)); JToolBar toolBar = new OSXCompatibleToolbar(); @@ -284,9 +277,9 @@ public void endSearch() { if (currentBasePanel != null) { clearSearch(currentBasePanel); MainTable mainTable = frame.getCurrentBasePanel().getMainTable(); - Globals.getFocusListener().setFocused(mainTable); + //Globals.getFocusListener().setFocused(mainTable); mainTable.requestFocus(); - SwingUtilities.invokeLater(() -> mainTable.ensureVisible(mainTable.getSelectedRow())); + //SwingUtilities.invokeLater(() -> mainTable.ensureVisible(mainTable.getSelectedRow())); } } diff --git a/src/main/java/org/jabref/gui/search/SearchResultFrame.java b/src/main/java/org/jabref/gui/search/SearchResultFrame.java index 94b82a245d0..7b119820756 100644 --- a/src/main/java/org/jabref/gui/search/SearchResultFrame.java +++ b/src/main/java/org/jabref/gui/search/SearchResultFrame.java @@ -406,7 +406,7 @@ private void selectEntryInBasePanel(BibEntry entry) { BasePanel basePanel = entryHome.get(entry); frame.showBasePanel(basePanel); basePanel.requestFocus(); - basePanel.highlightEntry(entry); + basePanel.clearAndSelect(entry); } public void dispose() { diff --git a/src/main/java/org/jabref/gui/search/SearchWorker.java b/src/main/java/org/jabref/gui/search/SearchWorker.java index db3c4495cfc..0a67414f214 100644 --- a/src/main/java/org/jabref/gui/search/SearchWorker.java +++ b/src/main/java/org/jabref/gui/search/SearchWorker.java @@ -99,13 +99,14 @@ private void updateUIWithSearchResult(List matchedEntries) { List selectedEntries = basePanel.getSelectedEntries(); boolean isHitSelected = selectedEntries.stream().anyMatch(BibEntry::isSearchHit); if (!isHitSelected && !matchedEntries.isEmpty()) { - for (int i = 0; i < basePanel.getMainTable().getRowCount(); i++) { + /*for (int i = 0; i < basePanel.getMainTable().getRowCount(); i++) { BibEntry entry = basePanel.getMainTable().getEntryAt(i); if (entry.isSearchHit()) { basePanel.getMainTable().setSelected(i); break; } } + */ } } diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java index 4825c7f0c05..a129af12f07 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java @@ -60,7 +60,6 @@ public void listen(ConnectionLostEvent connectionLostEvent) { } else if (answer == 1) { connectionLostEvent.getBibDatabaseContext().convertToLocalDatabase(); jabRefFrame.refreshTitleAndTabs(); - jabRefFrame.updateEnabledState(); jabRefFrame.output(Localization.lang("Working offline.")); } else { jabRefFrame.closeCurrentTab(); @@ -90,7 +89,7 @@ public void listen(SharedEntryNotPresentEvent event) { + "\n" + Localization.lang("You can restore the entry using the \"Undo\" operation."), Localization.lang("Shared entry is no longer present"), JOptionPane.INFORMATION_MESSAGE); - SwingUtilities.invokeLater(() -> panel.hideBottomComponent()); + SwingUtilities.invokeLater(() -> panel.closeBottomPane()); } } diff --git a/src/main/java/org/jabref/gui/util/BindingsHelper.java b/src/main/java/org/jabref/gui/util/BindingsHelper.java index 22b26f2db82..959190c060a 100644 --- a/src/main/java/org/jabref/gui/util/BindingsHelper.java +++ b/src/main/java/org/jabref/gui/util/BindingsHelper.java @@ -14,6 +14,7 @@ import javafx.beans.property.Property; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.MapChangeListener; import javafx.collections.ObservableList; @@ -21,6 +22,7 @@ import javafx.css.PseudoClass; import javafx.scene.Node; +import org.fxmisc.easybind.PreboundBinding; /** * Helper methods for javafx binding. @@ -72,6 +74,19 @@ public static MappedList mapBacked(ObservableList source, Function(source, mapper); } + public static ObservableList map(ObservableValue source, Function> mapper) { + PreboundBinding> binding = new PreboundBinding>(source) { + @Override + protected List computeValue() { + return mapper.apply(source.getValue()); + } + }; + + ObservableList list = FXCollections.observableArrayList(); + binding.addListener((observable, oldValue, newValue) -> list.setAll(newValue)); + return list; + } + /** * Binds propertA bidirectional to propertyB using the provided map functions to convert between them. */ diff --git a/src/main/java/org/jabref/gui/util/ValueTableCellFactory.java b/src/main/java/org/jabref/gui/util/ValueTableCellFactory.java index 56dff50f25c..2d4892086de 100644 --- a/src/main/java/org/jabref/gui/util/ValueTableCellFactory.java +++ b/src/main/java/org/jabref/gui/util/ValueTableCellFactory.java @@ -13,7 +13,7 @@ /** * Constructs a {@link TableCell} based on the value of the cell and a bunch of specified converter methods. * - * @param view model + * @param view model of table row * @param cell value */ public class ValueTableCellFactory implements Callback, TableCell> { diff --git a/src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java b/src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java new file mode 100644 index 00000000000..4f43b5e072e --- /dev/null +++ b/src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java @@ -0,0 +1,39 @@ +package org.jabref.gui.util; + +import java.util.function.BiConsumer; + +import javafx.scene.control.TableRow; +import javafx.scene.control.TableView; +import javafx.scene.control.TreeTableCell; +import javafx.scene.input.MouseEvent; +import javafx.util.Callback; + +/** + * Constructs a {@link TreeTableCell} based on the view model of the row and a bunch of specified converter methods. + * + * @param view model + */ +public class ViewModelTableRowFactory implements Callback, TableRow> { + + private BiConsumer onMouseClickedEvent; + + public ViewModelTableRowFactory withOnMouseClickedEvent(BiConsumer onMouseClickedEvent) { + this.onMouseClickedEvent = onMouseClickedEvent; + return this; + } + + @Override + public TableRow call(TableView tableView) { + TableRow row = new TableRow<>(); + + if (onMouseClickedEvent != null) { + row.setOnMouseClicked(event -> { + if (!row.isEmpty()) { + onMouseClickedEvent.accept(row.getItem(), event); + } + }); + } + + return row; + } +} diff --git a/src/main/java/org/jabref/pdfimport/PdfImporter.java b/src/main/java/org/jabref/pdfimport/PdfImporter.java index f5273dbc88a..07e4d6df5de 100644 --- a/src/main/java/org/jabref/pdfimport/PdfImporter.java +++ b/src/main/java/org/jabref/pdfimport/PdfImporter.java @@ -133,7 +133,7 @@ private List importPdfFilesInternal(List fileNames) { if (dropRow >= 0) { dfh.linkPdfToEntry(fileName, entryTable, dropRow); } else { - dfh.linkPdfToEntry(fileName, entryTable, entryTable.getSelectedRow()); + entryTable.getSelectedEntries().forEach(entry -> dfh.linkPdfToEntry(fileName, entry)); } break; default: @@ -220,7 +220,7 @@ private void doContentImport(String fileName, List res) { DroppedFileHandler dfh = new DroppedFileHandler(frame, panel); dfh.linkPdfToEntry(fileName, entry); - SwingUtilities.invokeLater(() -> panel.highlightEntry(entry)); + SwingUtilities.invokeLater(() -> panel.clearAndSelect(entry)); if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) { panel.showAndEdit(entry); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 6e31892613a..631f0b48f1a 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -31,7 +31,6 @@ import java.util.prefs.Preferences; import java.util.stream.Collectors; -import javax.swing.JTable; import javax.swing.UIManager; import org.jabref.JabRefException; @@ -502,8 +501,8 @@ private JabRefPreferences() { defaults.put(SIZE_X, 1024); defaults.put(SIZE_Y, 768); defaults.put(WINDOW_MAXIMISED, Boolean.FALSE); - defaults.put(AUTO_RESIZE_MODE, JTable.AUTO_RESIZE_ALL_COLUMNS); - defaults.put(ENTRY_EDITOR_HEIGHT, 400); + defaults.put(AUTO_RESIZE_MODE, Boolean.TRUE); + defaults.put(ENTRY_EDITOR_HEIGHT, 0.75); defaults.put(TABLE_COLOR_CODES_ON, Boolean.FALSE); defaults.put(TABLE_RESOLVED_COLOR_CODES_ON, Boolean.FALSE); defaults.put(NAMES_AS_IS, Boolean.FALSE); // "Show names unchanged" @@ -1033,7 +1032,7 @@ public int getIntDefault(String key) { } private double getDoubleDefault(String key) { - return (double) defaults.get(key); + return ((Number) defaults.get(key)).doubleValue(); } public void put(String key, String value) { @@ -1475,7 +1474,7 @@ public JabRefPreferences storePreviewPreferences(PreviewPreferences previewPrefe public PreviewPreferences getPreviewPreferences() { int cyclePos = getInt(CYCLE_PREVIEW_POS); List cycle = getStringList(CYCLE_PREVIEW); - int panelHeight = getInt(PREVIEW_PANEL_HEIGHT); + double panelHeight = getDouble(PREVIEW_PANEL_HEIGHT); String style = get(PREVIEW_STYLE); String styleDefault = (String) defaults.get(PREVIEW_STYLE); boolean enabled = getBoolean(PREVIEW_ENABLED); diff --git a/src/test/java/org/jabref/gui/search/SearchResultsTest.java b/src/test/java/org/jabref/gui/search/SearchResultsTest.java index add7153d26b..33def0c2c4e 100644 --- a/src/test/java/org/jabref/gui/search/SearchResultsTest.java +++ b/src/test/java/org/jabref/gui/search/SearchResultsTest.java @@ -1,12 +1,9 @@ package org.jabref.gui.search; -import java.util.Collection; import java.util.concurrent.TimeUnit; import javax.swing.JFrame; -import org.jabref.gui.BasePanel; -import org.jabref.model.entry.BibEntry; import org.jabref.testutils.TestUtils; import org.jabref.testutils.category.GUITest; @@ -16,7 +13,6 @@ import org.assertj.swing.fixture.FrameFixture; import org.assertj.swing.fixture.JTextComponentFixture; import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -51,6 +47,7 @@ public void testSearchFieldQuery() { frameFixture.menuItemWithPath("Search", "Search").click(); JTextComponentFixture searchField = frameFixture.textBox(); ComponentFinder finder = robot().finder(); + /* BasePanel panel = finder.findByType(BasePanel.class); Collection entries = panel.getDatabase().getEntries(); @@ -68,10 +65,12 @@ public void testSearchFieldQuery() { searchField.deleteText().enterText("entrytype=book"); Assert.assertFalse(entries.stream().noneMatch(entry -> entry.isSearchHit())); Assert.assertEquals(1, entries.stream().filter(entry -> entry.isSearchHit()).count()); + */ } @Test public void testSeachWithoutResults() { + /* frameFixture.menuItemWithPath("Search", "Search").click(); JTextComponentFixture searchField = frameFixture.textBox(); ComponentFinder finder = robot().finder(); @@ -80,10 +79,12 @@ public void testSeachWithoutResults() { searchField.deleteText().enterText("asdf"); Assert.assertTrue(entries.stream().noneMatch(entry -> entry.isSearchHit())); + */ } @Test public void testSearchInvalidQuery() { + /* frameFixture.menuItemWithPath("Search", "Search").click(); JTextComponentFixture searchField = frameFixture.textBox(); ComponentFinder finder = robot().finder(); @@ -92,6 +93,7 @@ public void testSearchInvalidQuery() { searchField.deleteText().enterText("asdf["); Assert.assertTrue(entries.stream().noneMatch(entry -> entry.isSearchHit())); + */ } } From b2335176959afaad7a48122608350edaf90aa030 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sun, 31 Dec 2017 12:49:26 +0100 Subject: [PATCH 006/827] Add new classes --- .../gui/maintable/BibEntryTableViewModel.java | 46 ++++ .../jabref/gui/maintable/ColumnFactory.java | 207 ++++++++++++++++++ .../gui/maintable/StringTableColumn.java | 158 +++++++++++++ 3 files changed, 411 insertions(+) create mode 100644 src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java create mode 100644 src/main/java/org/jabref/gui/maintable/ColumnFactory.java create mode 100644 src/main/java/org/jabref/gui/maintable/StringTableColumn.java diff --git a/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java b/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java new file mode 100644 index 00000000000..61e02904f88 --- /dev/null +++ b/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java @@ -0,0 +1,46 @@ +package org.jabref.gui.maintable; + +import java.util.List; +import java.util.Optional; + +import javafx.beans.binding.ObjectBinding; +import javafx.beans.value.ObservableValue; + +import org.jabref.gui.specialfields.SpecialFieldValueViewModel; +import org.jabref.model.database.BibDatabase; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.FileFieldParser; +import org.jabref.model.entry.LinkedFile; +import org.jabref.model.entry.specialfields.SpecialField; + +import org.fxmisc.easybind.EasyBind; + +public class BibEntryTableViewModel { + private final BibEntry entry; + + public BibEntryTableViewModel(BibEntry entry) { + this.entry = entry; + } + + public BibEntry getEntry() { + return entry; + } + + public Optional getResolvedFieldOrAlias(String field, BibDatabase database) { + return entry.getResolvedFieldOrAlias(field, database); + } + + public ObjectBinding getField(String fieldName) { + return entry.getFieldBinding(fieldName); + } + + public ObservableValue> getSpecialField(SpecialField field) { + return EasyBind.map(getField(field.getFieldName()), + value -> field.parse(value).map(SpecialFieldValueViewModel::new)); + } + + public ObservableValue> getLinkedFiles() { + return EasyBind.map(getField(FieldName.FILE), FileFieldParser::parse); + } +} diff --git a/src/main/java/org/jabref/gui/maintable/ColumnFactory.java b/src/main/java/org/jabref/gui/maintable/ColumnFactory.java new file mode 100644 index 00000000000..b93b5dff34c --- /dev/null +++ b/src/main/java/org/jabref/gui/maintable/ColumnFactory.java @@ -0,0 +1,207 @@ +package org.jabref.gui.maintable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import javafx.scene.Node; +import javafx.scene.control.TableColumn; + +import org.jabref.Globals; +import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefIcon; +import org.jabref.gui.externalfiletype.ExternalFileType; +import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.gui.specialfields.SpecialFieldValueViewModel; +import org.jabref.gui.specialfields.SpecialFieldViewModel; +import org.jabref.gui.util.ValueTableCellFactory; +import org.jabref.model.database.BibDatabase; +import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.LinkedFile; +import org.jabref.model.entry.specialfields.SpecialField; +import org.jabref.preferences.JabRefPreferences; + +import org.fxmisc.easybind.EasyBind; + +class ColumnFactory { + + private static final String STYLE_ICON = "column-icon"; + + private final ExternalFileTypes externalFileTypes; + private final BibDatabase database; + private final CellFactory cellFactory; + + public ColumnFactory(BibDatabase database) { + this.database = database; + externalFileTypes = ExternalFileTypes.getInstance(); + cellFactory = new CellFactory(); + } + + public List> createColumns() { + List> columns = new ArrayList<>(); + + // Add column for linked files + if (Globals.prefs.getBoolean(JabRefPreferences.FILE_COLUMN)) { + columns.add(createFileColumn()); + } + + // Add column for DOI/URL + if (Globals.prefs.getBoolean(JabRefPreferences.URL_COLUMN)) { + if (Globals.prefs.getBoolean(JabRefPreferences.PREFER_URL_DOI)) { + columns.add(createIconColumn(IconTheme.JabRefIcons.DOI, FieldName.DOI, FieldName.URL)); + } else { + columns.add(createIconColumn(IconTheme.JabRefIcons.WWW, FieldName.URL, FieldName.DOI)); + } + } + + // Add column for eprints + if (Globals.prefs.getBoolean(JabRefPreferences.ARXIV_COLUMN)) { + columns.add(createIconColumn(IconTheme.JabRefIcons.WWW, FieldName.EPRINT)); + } + + // Add columns for other file types + if (Globals.prefs.getBoolean(JabRefPreferences.EXTRA_FILE_COLUMNS)) { + List desiredColumns = Globals.prefs.getStringList(JabRefPreferences.LIST_OF_FILE_COLUMNS); + for (String desiredColumn : desiredColumns) { + columns.add(createExtraFileColumn(desiredColumn)); + } + } + + // Add 'normal' bibtex fields as configured in the preferences + columns.addAll(createNormalColumns()); + + // Add the "special" icon columns (e.g., ranking, file, ...) that are enabled in preferences + if (Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) { + if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) { + columns.add(createSpecialFieldColumn(SpecialField.RANKING)); + } + if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RELEVANCE)) { + columns.add(createSpecialFieldColumn(SpecialField.RELEVANCE)); + } + if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_QUALITY)) { + columns.add(createSpecialFieldColumn(SpecialField.QUALITY)); + } + + if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) { + columns.add(createSpecialFieldColumn(SpecialField.PRIORITY)); + } + + if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRINTED)) { + columns.add(createSpecialFieldColumn(SpecialField.PRINTED)); + } + + if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) { + columns.add(createSpecialFieldColumn(SpecialField.READ_STATUS)); + } + } + + return columns; + } + + private List> createNormalColumns() { + List> columns = new ArrayList<>(); + + // Read table columns from preferences + List columnSettings = Globals.prefs.getStringList(JabRefPreferences.COLUMN_NAMES); + for (String columnName : columnSettings) { + // Stored column name will be used as header + // There might be more than one field to display, e.g., "author/editor" or "date/year" - so split + String[] fields = columnName.split(FieldName.FIELD_SEPARATOR); + columns.add(new StringTableColumn(columnName, Arrays.asList(fields), database)); + } + return columns; + } + + private TableColumn> createSpecialFieldColumn(SpecialField specialField) { + TableColumn> column = new TableColumn<>(); + column.setGraphic(new SpecialFieldViewModel(specialField).getIcon().getGraphicNode()); + column.getStyleClass().add(STYLE_ICON); + column.setMinWidth(30); + column.setMaxWidth(30); + column.setCellValueFactory(cellData -> cellData.getValue().getSpecialField(specialField)); + column.setCellFactory( + new ValueTableCellFactory>() + .withGraphic(param -> param.map(specialFieldValue -> specialFieldValue.getIcon().getGraphicNode()).orElse(null))); + + return column; + } + + private TableColumn> createFileColumn() { + TableColumn> column = new TableColumn<>(); + column.setGraphic(IconTheme.JabRefIcons.FILE.getGraphicNode()); + column.getStyleClass().add(STYLE_ICON); + column.setMinWidth(30); + column.setMaxWidth(30); + column.setCellValueFactory(cellData -> cellData.getValue().getLinkedFiles()); + column.setCellFactory( + new ValueTableCellFactory>() + .withGraphic(this::createFileIcon)); + return column; + } + + /** + * Creates a column which shows an icon instead of the textual content + */ + private TableColumn createIconColumn(JabRefIcon icon, String firstField, String secondField) { + TableColumn column = new TableColumn<>(); + column.setGraphic(icon.getGraphicNode()); + column.getStyleClass().add(STYLE_ICON); + column.setMinWidth(30); + column.setMaxWidth(30); + column.setCellValueFactory(cellData -> EasyBind.monadic(cellData.getValue().getField(firstField)).orElse(cellData.getValue().getField(secondField))); + column.setCellFactory( + new ValueTableCellFactory() + .withGraphic(cellFactory::getTableIcon)); + return column; + } + + private TableColumn createIconColumn(JabRefIcon icon, String field) { + TableColumn column = new TableColumn<>(); + column.setGraphic(icon.getGraphicNode()); + column.getStyleClass().add(STYLE_ICON); + column.setMinWidth(30); + column.setMaxWidth(30); + column.setCellValueFactory(cellData -> cellData.getValue().getField(field)); + column.setCellFactory( + new ValueTableCellFactory() + .withGraphic(cellFactory::getTableIcon)); + return column; + } + + /** + * Creates a column for specific file types. Shows the icon for the given type (or the FILE_MULTIPLE icon) + * + * @param externalFileTypeName the name of the externalFileType + */ + private TableColumn> createExtraFileColumn(String externalFileTypeName) { + TableColumn> column = new TableColumn<>(); + column.setGraphic( + externalFileTypes.getExternalFileTypeByName(externalFileTypeName) + .map(ExternalFileType::getIcon).orElse(IconTheme.JabRefIcons.FILE) + .getGraphicNode()); + column.getStyleClass().add(STYLE_ICON); + column.setMinWidth(30); + column.setMaxWidth(30); + column.setCellValueFactory(cellData -> cellData.getValue().getLinkedFiles()); + column.setCellFactory( + new ValueTableCellFactory>() + .withGraphic(linkedFiles -> createFileIcon(linkedFiles.stream().filter(linkedFile -> linkedFile.getFileType().equalsIgnoreCase(externalFileTypeName)).collect(Collectors.toList())))); + + return column; + } + + private Node createFileIcon(List linkedFiles) { + if (linkedFiles.size() > 1) { + return IconTheme.JabRefIcons.FILE_MULTIPLE.getGraphicNode(); + } else if (linkedFiles.size() == 1) { + return externalFileTypes.fromLinkedFile(linkedFiles.get(0), false) + .map(ExternalFileType::getIcon) + .orElse(IconTheme.JabRefIcons.FILE) + .getGraphicNode(); + } else { + return null; + } + } +} diff --git a/src/main/java/org/jabref/gui/maintable/StringTableColumn.java b/src/main/java/org/jabref/gui/maintable/StringTableColumn.java new file mode 100644 index 00000000000..7b6bfaa0e65 --- /dev/null +++ b/src/main/java/org/jabref/gui/maintable/StringTableColumn.java @@ -0,0 +1,158 @@ +package org.jabref.gui.maintable; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.StringJoiner; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.value.ObservableValue; +import javafx.scene.Node; +import javafx.scene.control.Label; + +import org.jabref.gui.JabRefIcon; +import org.jabref.logic.layout.LayoutFormatter; +import org.jabref.logic.layout.format.LatexToUnicodeFormatter; +import org.jabref.model.database.BibDatabase; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.FieldProperty; +import org.jabref.model.entry.InternalBibtexFields; + +public class StringTableColumn extends MainTableColumn { + + private final List bibtexFields; + + private final boolean isIconColumn; + + private final Optional iconLabel; + + private final Optional database; + + private final LayoutFormatter toUnicode = new LatexToUnicodeFormatter(); + + public StringTableColumn(String columnName) { + super(columnName); + this.bibtexFields = Collections.emptyList(); + this.isIconColumn = false; + this.iconLabel = Optional.empty(); + this.database = Optional.empty(); + } + + public StringTableColumn(String columnName, List bibtexFields, BibDatabase database) { + super(columnName); + this.bibtexFields = Collections.unmodifiableList(bibtexFields); + this.isIconColumn = false; + this.iconLabel = Optional.empty(); + this.database = Optional.of(database); + } + + public StringTableColumn(String columnName, List bibtexFields, JabRefIcon iconLabel) { + super(columnName); + this.bibtexFields = Collections.unmodifiableList(bibtexFields); + this.isIconColumn = true; + this.iconLabel = Optional.of(iconLabel); + this.database = Optional.empty(); + } + + /** + * Get the table column name to be displayed in the UI + * + * @return name to be displayed. null if field is empty. + */ + public String getDisplayName() { + if (bibtexFields.isEmpty()) { + return null; + } + + StringJoiner joiner = new StringJoiner(FieldName.FIELD_SEPARATOR); + for (String field : bibtexFields) { + joiner.add(field); + } + return joiner.toString(); + } + + public List getBibtexFields() { + return bibtexFields; + } + + public boolean isIconColumn() { + return isIconColumn; + } + + public boolean isFileFilter() { + return false; // Overridden in SpecialMainTableColumns for file filter columns + } + + @Override + public ObservableValue getColumnValue(BibEntryTableViewModel entry) { + if (bibtexFields.isEmpty()) { + return null; + } + boolean isNameColumn = false; + + Optional content = Optional.empty(); + for (String field : bibtexFields) { + content = entry.getResolvedFieldOrAlias(field, database.orElse(null)); + if (content.isPresent()) { + isNameColumn = InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.PERSON_NAMES); + break; + } + } + + String result = content.orElse(null); + + if (isNameColumn) { + result = toUnicode.format(MainTableNameFormatter.formatName(result)); + } + + if (result != null && !bibtexFields.contains(BibEntry.KEY_FIELD)) { + result = toUnicode.format(result).trim(); + } + + return new SimpleStringProperty(result); + } + + public Node getHeaderLabel() { + if (isIconColumn) { + return iconLabel.map(JabRefIcon::getGraphicNode).get(); + } else { + return new Label(getDisplayName()); + } + } + + /** + * Check if the value returned by getColumnValue() is the same as a simple check of the entry's field(s) would give + * The reasons for being different are (combinations may also happen): - The entry has a crossref where the field + * content is obtained from - The field has a string in it (which getColumnValue() resolves) - There are some alias + * fields. For example, if the entry has a date field but no year field, {@link + * BibEntry#getResolvedFieldOrAlias(String, BibDatabase)} will return the year value from the date field when + * queried for year + * + * @param entry the BibEntry + * @return true if the value returned by getColumnValue() is resolved as outlined above + */ + public boolean isResolved(BibEntry entry) { + if (bibtexFields.isEmpty()) { + return false; + } + + Optional resolvedFieldContent = Optional.empty(); + Optional plainFieldContent = Optional.empty(); + for (String field : bibtexFields) { + // entry type or bibtex key will never be resolved + if (BibEntry.TYPE_HEADER.equals(field) || BibEntry.OBSOLETE_TYPE_HEADER.equals(field) + || BibEntry.KEY_FIELD.equals(field)) { + return false; + } else { + plainFieldContent = entry.getField(field); + resolvedFieldContent = entry.getResolvedFieldOrAlias(field, database.orElse(null)); + } + + if (resolvedFieldContent.isPresent()) { + break; + } + } + return (!resolvedFieldContent.equals(plainFieldContent)); + } +} From c2b70c3fe8ec92ebcd1fa4e936262ffac056a4b6 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 1 Jan 2018 15:21:43 +0100 Subject: [PATCH 007/827] Hold reference of divider pane position binding --- src/main/java/org/jabref/gui/BasePanel.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 4eced8b9227..21bfd44fb1b 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -141,6 +141,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.fxmisc.easybind.EasyBind; +import org.fxmisc.easybind.Subscription; public class BasePanel extends StackPane implements ClipboardOwner { @@ -187,6 +188,8 @@ public class BasePanel extends StackPane implements ClipboardOwner { private StringDialog stringDialog; private SuggestionProviders suggestionProviders; + private Subscription dividerPositionSubscription; + // the query the user searches when this BasePanel is active private Optional currentSearchQuery = Optional.empty(); @@ -232,7 +235,7 @@ public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) { this.getDatabase().registerListener(new UpdateTimestampListener(Globals.prefs)); - entryEditor = new EntryEditor(this); + this.entryEditor = new EntryEditor(this); this.preview = new PreviewPanel(this, getBibDatabaseContext()); DefaultTaskExecutor.runInJavaFXThread(() -> frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview)); @@ -346,7 +349,7 @@ private void setupActions() { new SaveSelectedAction(SavePreferences.DatabaseSaveType.PLAIN_BIBTEX)); // The action for copying selected entries. - actions.put(Actions.COPY, (BaseAction) () -> copy()); + actions.put(Actions.COPY, (BaseAction) this::copy); actions.put(Actions.PRINT_PREVIEW, new PrintPreviewAction()); @@ -362,7 +365,7 @@ private void setupActions() { // This allows you to (a) paste entire bibtex entries from a text editor, web browser, etc // (b) copy and paste entries between multiple instances of JabRef (since // only the text representation seems to get as far as the X clipboard, at least on my system) - actions.put(Actions.PASTE, (BaseAction) () -> paste()); + actions.put(Actions.PASTE, (BaseAction) this::paste); actions.put(Actions.SELECT_ALL, (BaseAction) mainTable.getSelectionModel()::selectAll); @@ -1342,7 +1345,8 @@ public void setupMainPanel() { mainTable.showFloatSearch(); } // Saves the divider position as soon as it changes - EasyBind.monadic(Bindings.valueAt(splitPane.getDividers(), 0)) + // We need to keep a reference to the subscription, otherwise the binding gets garbage collected + dividerPositionSubscription = EasyBind.monadic(Bindings.valueAt(splitPane.getDividers(), 0)) .flatMap(SplitPane.Divider::positionProperty) .subscribe((observable, oldValue, newValue) -> saveDividerLocation(newValue)); } From 452147d241d0995631f2c9a20b14cf1a5b86ece9 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 1 Jan 2018 22:58:39 +0100 Subject: [PATCH 008/827] Fix divider location storage --- build.gradle | 4 +- src/main/java/org/jabref/gui/BasePanel.java | 72 +++++++----- .../org/jabref/gui/BasePanelPreferences.java | 80 +++++++++++++ .../org/jabref/gui/GenFieldsCustomizer.java | 10 +- src/main/java/org/jabref/gui/JabRefFrame.java | 13 ++- .../java/org/jabref/gui/PreviewPanel.java | 69 ++++++----- .../gui/actions/NewSubDatabaseAction.java | 4 +- .../ResolveDuplicateLabelDialog.java | 2 +- .../gui/collab/EntryAddChangeViewModel.java | 3 +- .../collab/EntryDeleteChangeViewModel.java | 3 +- .../jabref/gui/entryeditor/EntryEditor.java | 28 +++-- .../entryeditor/EntryEditorPreferences.java | 69 +++++++++++ .../gui/entryeditor/EntryEditorTabList.java | 49 +++----- .../gui/entryeditor/FieldsEditorTab.java | 6 + .../gui/entryeditor/OtherFieldsTab.java | 8 +- .../gui/entryeditor/RelatedArticlesTab.java | 6 +- .../org/jabref/gui/entryeditor/SourceTab.java | 13 +-- .../gui/importer/ImportInspectionDialog.java | 6 +- .../importer/actions/OpenDatabaseAction.java | 4 +- .../org/jabref/gui/maintable/CellFactory.java | 4 +- .../jabref/gui/maintable/ColumnFactory.java | 56 +++------ .../gui/maintable/ColumnPreferences.java | 107 ++++++++++++++++++ .../org/jabref/gui/maintable/MainTable.java | 19 ++-- .../gui/maintable/MainTablePreferences.java | 36 ++++++ .../jabref/gui/menus/ChangeEntryTypeMenu.java | 20 ++-- .../org/jabref/gui/menus/RightClickMenu.java | 2 +- .../jabref/gui/mergeentries/MergeEntries.java | 2 +- .../gui/openoffice/StyleSelectDialog.java | 2 +- .../jabref/gui/preftabs/PreviewPrefsTab.java | 4 +- .../jabref/gui/search/SearchResultFrame.java | 2 +- .../SpecialFieldDatabaseChangeListener.java | 13 +-- .../migrations/FileLinksUpgradeWarning.java | 14 +-- .../jabref/preferences/JabRefPreferences.java | 6 +- .../preferences/PreviewPreferences.java | 10 ++ .../java/org/jabref/gui/BasePanelTest.java | 69 +++++++++++ .../gui/entryeditor/EntryEditorTest.java | 38 ++++--- 36 files changed, 603 insertions(+), 250 deletions(-) create mode 100644 src/main/java/org/jabref/gui/BasePanelPreferences.java create mode 100644 src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java create mode 100644 src/main/java/org/jabref/gui/maintable/ColumnPreferences.java create mode 100644 src/main/java/org/jabref/gui/maintable/MainTablePreferences.java create mode 100644 src/test/java/org/jabref/gui/BasePanelTest.java diff --git a/build.gradle b/build.gradle index d7d66b3d18f..48cc742b8c3 100644 --- a/build.gradle +++ b/build.gradle @@ -169,7 +169,7 @@ dependencies { testCompile 'com.tngtech.archunit:archunit-junit:0.5.0' testCompile 'org.slf4j:slf4j-jcl:1.7.25' // required by ArchUnit to enable logging over jcl testCompile "org.testfx:testfx-core:4.0.+" - testCompile "org.testfx:testfx-junit:4.0.+" + testCompile "org.testfx:testfx-junit5:4.0.+" checkstyle 'com.puppycrawl.tools:checkstyle:8.5' } @@ -503,7 +503,7 @@ task releaseJar(dependsOn: "shadowJar") { } } // set executable with read permissions (first true) and for all (false) - file("$buildDir/releases/JabRef-${project.version}.jar").setExecutable(true, false); + file("$buildDir/releases/JabRef-${project.version}.jar").setExecutable(true, false) } } diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 5da42396d01..27de1eee72e 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -43,7 +43,6 @@ import org.jabref.JabRefExecutorService; import org.jabref.gui.actions.Actions; import org.jabref.gui.actions.BaseAction; -import org.jabref.gui.actions.CleanupAction; import org.jabref.gui.actions.CopyBibTeXKeyAndLinkAction; import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.autocompleter.AutoCompleteUpdater; @@ -92,7 +91,6 @@ import org.jabref.gui.worker.AbstractWorker; import org.jabref.gui.worker.CallBack; import org.jabref.gui.worker.CitationStyleToClipboardWorker; -import org.jabref.gui.worker.MarkEntriesAction; import org.jabref.gui.worker.SendAsEMailAction; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import org.jabref.logic.citationstyle.CitationStyleCache; @@ -138,6 +136,7 @@ import com.google.common.eventbus.Subscribe; import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; +import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.fxmisc.easybind.EasyBind; @@ -164,6 +163,8 @@ public class BasePanel extends StackPane implements ClipboardOwner { private final Map actions = new HashMap<>(); private final SidePaneManager sidePaneManager; private final PreviewPanel preview; + private final BasePanelPreferences preferences; + private final ExternalFileTypes externalFileTypes; // To contain instantiated entry editors. This is to save time // As most enums, this must not be null @@ -195,25 +196,21 @@ public class BasePanel extends StackPane implements ClipboardOwner { private Optional changeMonitor = Optional.empty(); - public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) { - Objects.requireNonNull(frame); - Objects.requireNonNull(bibDatabaseContext); + public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabaseContext bibDatabaseContext, ExternalFileTypes externalFileTypes) { + this.preferences = Objects.requireNonNull(preferences); + this.frame = Objects.requireNonNull(frame); + this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext); + this.externalFileTypes = Objects.requireNonNull(externalFileTypes); - this.bibDatabaseContext = bibDatabaseContext; bibDatabaseContext.getDatabase().registerListener(this); bibDatabaseContext.getMetaData().registerListener(this); this.sidePaneManager = frame.getSidePaneManager(); - this.frame = frame; this.tableModel = new MainTableDataModel(getBibDatabaseContext()); citationStyleCache = new CitationStyleCache(bibDatabaseContext); annotationCache = new FileAnnotationCache(bibDatabaseContext); - this.preview = new PreviewPanel(this, getBibDatabaseContext()); - DefaultTaskExecutor.runInJavaFXThread(() -> frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview)); - this.previewContainer = CustomJFXPanel.wrap(new Scene(preview)); - setupMainPanel(); setupActions(); @@ -239,9 +236,9 @@ public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) { this.getDatabase().registerListener(new UpdateTimestampListener(Globals.prefs)); - this.entryEditor = new EntryEditor(this); + this.entryEditor = new EntryEditor(this, preferences.getEntryEditorPreferences()); - this.preview = new PreviewPanel(this, getBibDatabaseContext()); + this.preview = new PreviewPanel(this, getBibDatabaseContext(), preferences.getKeyBindings(), preferences.getPreviewPreferences()); DefaultTaskExecutor.runInJavaFXThread(() -> frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview)); } @@ -267,7 +264,8 @@ public static void runWorker(AbstractWorker worker) throws Exception { @Subscribe public void listen(BibDatabaseContextChangedEvent event) { - SwingUtilities.invokeLater(() -> this.markBaseChanged()); + // TODO: + //SwingUtilities.invokeLater(() -> this.markBaseChanged()); } @@ -330,7 +328,8 @@ public void output(String s) { private void setupActions() { SaveDatabaseAction saveAction = new SaveDatabaseAction(this); - CleanupAction cleanUpAction = new CleanupAction(this, Globals.prefs); + // TODO + //CleanupAction cleanUpAction = new CleanupAction(this, Globals.prefs); actions.put(Actions.UNDO, undoAction); actions.put(Actions.REDO, redoAction); @@ -486,7 +485,7 @@ public void update() { }); // The action for cleaning up entry. - actions.put(Actions.CLEANUP, cleanUpAction); + //actions.put(Actions.CLEANUP, cleanUpAction); actions.put(Actions.MERGE_ENTRIES, (BaseAction) () -> new MergeEntriesDialog(BasePanel.this)); @@ -602,7 +601,8 @@ public void update() { } }); - actions.put(Actions.MARK_ENTRIES, new MarkEntriesAction(frame, 0)); + // TODO + //actions.put(Actions.MARK_ENTRIES, new MarkEntriesAction(frame, 0)); actions.put(Actions.UNMARK_ENTRIES, (BaseAction) () -> { try { @@ -1218,7 +1218,7 @@ private void createMainTable() { bibDatabaseContext.getDatabase().registerListener(tableModel.getListSynchronizer()); bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.getInstance()); - mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext.getDatabase()); + mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext.getDatabase(), preferences.getTablePreferences(), externalFileTypes); mainTable.updateFont(); @@ -1359,7 +1359,7 @@ public void setupMainPanel() { * Set up auto completion for this database */ private void setupAutoCompletion() { - AutoCompletePreferences autoCompletePreferences = Globals.prefs.getAutoCompletePreferences(); + AutoCompletePreferences autoCompletePreferences = preferences.getAutoCompletePreferences(); if (autoCompletePreferences.shouldAutoComplete()) { suggestionProviders = new SuggestionProviders(autoCompletePreferences, Globals.journalAbbreviationLoader); suggestionProviders.indexDatabase(getDatabase()); @@ -1401,11 +1401,11 @@ public void updateStringDialog() { } } - public void adjustSplitter() { + private void adjustSplitter() { if (mode == BasePanelMode.SHOWING_PREVIEW) { splitPane.setDividerPositions(Globals.prefs.getPreviewPreferences().getPreviewPanelDividerPosition().doubleValue()); - } else { - splitPane.setDividerPositions(Globals.prefs.getDouble(JabRefPreferences.ENTRY_EDITOR_HEIGHT)); + } else if (mode == BasePanelMode.SHOWING_EDITOR) { + splitPane.setDividerPositions(preferences.getEntryEditorDividerPosition()); } } @@ -1421,8 +1421,7 @@ public EntryEditor getEntryEditor() { * @param entry The entry to edit. */ public void showAndEdit(BibEntry entry) { - mode = BasePanelMode.SHOWING_EDITOR; - showBottomPane(entryEditor); + showBottomPane(BasePanelMode.SHOWING_EDITOR); if (entry != getShowing()) { entryEditor.setEntry(entry); @@ -1431,12 +1430,27 @@ public void showAndEdit(BibEntry entry) { entryEditor.requestFocus(); } - private void showBottomPane(Node pane) { + private void showBottomPane(BasePanelMode newMode) { + Node pane; + switch (newMode) { + case SHOWING_PREVIEW: + pane = preview; + break; + case SHOWING_EDITOR: + pane = entryEditor; + break; + default: + throw new NotImplementedException("new mode not recognized: " + newMode.name()); + } + if (splitPane.getItems().size() == 2) { splitPane.getItems().set(1, pane); } else { splitPane.getItems().add(1, pane); } + + mode = newMode; + adjustSplitter(); } @@ -1452,8 +1466,7 @@ private void showAndEdit() { * @param entry The entry to show in the preview. */ private void showPreview(BibEntry entry) { - mode = BasePanelMode.SHOWING_PREVIEW; - showBottomPane(preview); + showBottomPane(BasePanelMode.SHOWING_PREVIEW); preview.setEntry(entry); } @@ -1720,7 +1733,7 @@ private void saveDividerLocation(Number position) { .build(); Globals.prefs.storePreviewPreferences(previewPreferences); } else if (mode == BasePanelMode.SHOWING_EDITOR) { - Globals.prefs.putDouble(JabRefPreferences.ENTRY_EDITOR_HEIGHT, position.doubleValue()); + preferences.setEntryEditorDividerPosition(position.doubleValue()); } } @@ -1979,12 +1992,15 @@ public void listen(EntryAddedEvent addedEntryEvent) { return; } + // TODO: // Automatically add new entry to the selected group (or set of groups) + /* if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)) { final List entries = Collections.singletonList(addedEntryEvent.getBibEntry()); Globals.stateManager.getSelectedGroup(bibDatabaseContext).forEach( selectedGroup -> selectedGroup.addEntriesToGroup(entries)); } + */ } } diff --git a/src/main/java/org/jabref/gui/BasePanelPreferences.java b/src/main/java/org/jabref/gui/BasePanelPreferences.java new file mode 100644 index 00000000000..52415e959b4 --- /dev/null +++ b/src/main/java/org/jabref/gui/BasePanelPreferences.java @@ -0,0 +1,80 @@ +package org.jabref.gui; + +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.SimpleDoubleProperty; + +import org.jabref.Globals; +import org.jabref.gui.autocompleter.AutoCompletePreferences; +import org.jabref.gui.entryeditor.EntryEditorPreferences; +import org.jabref.gui.keyboard.KeyBindingRepository; +import org.jabref.gui.maintable.MainTablePreferences; +import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreviewPreferences; + +import org.fxmisc.easybind.EasyBind; + +public class BasePanelPreferences { + private MainTablePreferences tablePreferences; + private AutoCompletePreferences autoCompletePreferences; + private EntryEditorPreferences entryEditorPreferences; + private KeyBindingRepository keyBindings; + private PreviewPreferences previewPreferences; + private DoubleProperty entryEditorDividerPosition = new SimpleDoubleProperty(); + + public BasePanelPreferences(MainTablePreferences tablePreferences, AutoCompletePreferences autoCompletePreferences, EntryEditorPreferences entryEditorPreferences, KeyBindingRepository keyBindings, PreviewPreferences previewPreferences, Double entryEditorDividerPosition) { + this.tablePreferences = tablePreferences; + this.autoCompletePreferences = autoCompletePreferences; + this.entryEditorPreferences = entryEditorPreferences; + this.keyBindings = keyBindings; + this.previewPreferences = previewPreferences; + this.entryEditorDividerPosition.setValue(entryEditorDividerPosition); + } + + public static BasePanelPreferences from(JabRefPreferences preferences) { + BasePanelPreferences basePanelPreferences = new BasePanelPreferences( + MainTablePreferences.from(preferences), + preferences.getAutoCompletePreferences(), + EntryEditorPreferences.from(preferences), + Globals.getKeyPrefs(), + preferences.getPreviewPreferences(), + preferences.getDouble(JabRefPreferences.ENTRY_EDITOR_HEIGHT)); + EasyBind.subscribe(basePanelPreferences.entryEditorDividerPosition, value -> preferences.putDouble(JabRefPreferences.ENTRY_EDITOR_HEIGHT, value.doubleValue())); + return basePanelPreferences; + } + + public double getEntryEditorDividerPosition() { + return entryEditorDividerPosition.get(); + } + + public void setEntryEditorDividerPosition(double entryEditorDividerPosition) { + this.entryEditorDividerPosition.set(entryEditorDividerPosition); + } + + public DoubleProperty entryEditorDividerPositionProperty() { + return entryEditorDividerPosition; + } + + public MainTablePreferences getTablePreferences() { + return tablePreferences; + } + + public AutoCompletePreferences getAutoCompletePreferences() { + return autoCompletePreferences; + } + + public void setAutoCompletePreferences(AutoCompletePreferences autoCompletePreferences) { + this.autoCompletePreferences = autoCompletePreferences; + } + + public EntryEditorPreferences getEntryEditorPreferences() { + return entryEditorPreferences; + } + + public KeyBindingRepository getKeyBindings() { + return keyBindings; + } + + public PreviewPreferences getPreviewPreferences() { + return previewPreferences; + } +} diff --git a/src/main/java/org/jabref/gui/GenFieldsCustomizer.java b/src/main/java/org/jabref/gui/GenFieldsCustomizer.java index d7b93d7b349..1136dc163f5 100644 --- a/src/main/java/org/jabref/gui/GenFieldsCustomizer.java +++ b/src/main/java/org/jabref/gui/GenFieldsCustomizer.java @@ -6,7 +6,9 @@ import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; +import java.util.List; import java.util.Locale; +import java.util.Map; import javax.swing.AbstractAction; import javax.swing.ActionMap; @@ -21,7 +23,6 @@ import javax.swing.JTextArea; import org.jabref.Globals; -import org.jabref.gui.entryeditor.EntryEditorTabList; import org.jabref.gui.help.HelpAction; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; @@ -143,11 +144,10 @@ private void okActionPerformed() { private void setFieldsText() { StringBuilder sb = new StringBuilder(); - EntryEditorTabList tabList = Globals.prefs.getEntryEditorTabList(); - for (int i = 0; i < tabList.getTabCount(); i++) { - sb.append(tabList.getTabName(i)); + for (Map.Entry> tab : Globals.prefs.getEntryEditorTabList().entrySet()) { + sb.append(tab.getKey()); sb.append(':'); - sb.append(String.join(";", tabList.getTabFields(i))); + sb.append(String.join(";", tab.getValue())); sb.append('\n'); } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index cf8cb11071d..732c43aadbf 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -95,6 +95,7 @@ import org.jabref.gui.exporter.SaveAllAction; import org.jabref.gui.exporter.SaveDatabaseAction; import org.jabref.gui.externalfiletype.ExternalFileTypeEditor; +import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.groups.EntryTableTransferHandler; import org.jabref.gui.groups.GroupSidePane; import org.jabref.gui.help.AboutAction; @@ -525,7 +526,7 @@ private List getNewEntryActions() { // only Bibtex List actions = new ArrayList<>(); for (EntryType type : BibtexEntryTypes.ALL) { - KeyStroke keyStroke = new ChangeEntryTypeMenu().entryShortCuts.get(type.getName()); + KeyStroke keyStroke = new ChangeEntryTypeMenu(Globals.getKeyPrefs()).entryShortCuts.get(type.getName()); if (keyStroke == null) { actions.add(new NewEntryAction(this, type.getName())); } else { @@ -635,7 +636,7 @@ public void windowClosing(WindowEvent e) { globalSearchBar.setSearchTerm(content); } - currentBasePanel.getPreviewPanel().updateLayout(); + currentBasePanel.getPreviewPanel().updateLayout(Globals.prefs.getPreviewPreferences()); groupSidePane.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class)); previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); @@ -1597,9 +1598,11 @@ private void trackOpenNewDatabase(BasePanel basePanel) { public BasePanel addTab(BibDatabaseContext databaseContext, boolean raisePanel) { Objects.requireNonNull(databaseContext); - BasePanel bp = new BasePanel(JabRefFrame.this, databaseContext); - addTab(bp, raisePanel); - return bp; + return DefaultTaskExecutor.runInJavaFXThread(() -> { + BasePanel bp = new BasePanel(this, BasePanelPreferences.from(Globals.prefs), databaseContext, ExternalFileTypes.getInstance()); + addTab(bp, raisePanel); + return bp; + }); } private boolean readyForAutosave(BibDatabaseContext context) { diff --git a/src/main/java/org/jabref/gui/PreviewPanel.java b/src/main/java/org/jabref/gui/PreviewPanel.java index 181c4395c45..57b03c3d86d 100644 --- a/src/main/java/org/jabref/gui/PreviewPanel.java +++ b/src/main/java/org/jabref/gui/PreviewPanel.java @@ -26,6 +26,7 @@ import org.jabref.logic.exporter.ExportFormats; import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.Layout; +import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.layout.LayoutHelper; import org.jabref.logic.search.SearchQueryHighlightListener; import org.jabref.model.database.BibDatabaseContext; @@ -66,41 +67,40 @@ public class PreviewPanel extends ScrollPane implements SearchQueryHighlightList private Optional> citationStyleFuture = Optional.empty(); /** + * @param preferences * @param panel (may be null) Only set this if the preview is associated to the main window. * @param databaseContext (may be null) Used for resolving pdf directories for links. */ - public PreviewPanel(BasePanel panel, BibDatabaseContext databaseContext) { + public PreviewPanel(BasePanel panel, BibDatabaseContext databaseContext, KeyBindingRepository keyBindingRepository, PreviewPreferences preferences) { this.databaseContext = Optional.ofNullable(databaseContext); this.basePanel = Optional.ofNullable(panel); this.clipBoardManager = new ClipBoardManager(); this.dialogService = new FXDialogService(); - this.keyBindingRepository = Globals.getKeyPrefs(); + this.keyBindingRepository = keyBindingRepository; + + // Set up scroll pane for preview pane + setFitToHeight(true); + setFitToWidth(true); + previewView = new WebView(); + setContent(previewView); + previewView.setContextMenuEnabled(false); + setContextMenu(createPopupMenu()); + + if (this.basePanel.isPresent()) { + // Handler for drag content of preview to different window + // only created for main window (not for windows like the search results dialog) + setOnDragDetected(event -> { + Dragboard dragboard = startDragAndDrop(TransferMode.COPY); + ClipboardContent content = new ClipboardContent(); + content.putHtml((String) previewView.getEngine().executeScript("window.getSelection().toString()")); + dragboard.setContent(content); - DefaultTaskExecutor.runInJavaFXThread(() -> { - // Set up scroll pane for preview pane - setFitToHeight(true); - setFitToWidth(true); - previewView = new WebView(); - setContent(previewView); - previewView.setContextMenuEnabled(false); - setContextMenu(createPopupMenu()); - - if (this.basePanel.isPresent()) { - // Handler for drag content of preview to different window - // only created for main window (not for windows like the search results dialog) - setOnDragDetected(event -> { - Dragboard dragboard = startDragAndDrop(TransferMode.COPY); - ClipboardContent content = new ClipboardContent(); - content.putHtml((String) previewView.getEngine().executeScript("window.getSelection().toString()")); - dragboard.setContent(content); - - event.consume(); - } - ); - } - createKeyBindings(); - updateLayout(); - }); + event.consume(); + } + ); + } + createKeyBindings(); + updateLayout(preferences); } private void createKeyBindings() { @@ -162,8 +162,7 @@ public void updateLayout(PreviewPreferences previewPreferences) { return; } - String style = previewPreferences.getPreviewCycle().get(previewPreferences.getPreviewCyclePosition()); - + String style = previewPreferences.getCurrentPreviewStyle(); if (CitationStyle.isCitationStyleFile(style)) { if (basePanel.isPresent()) { layout = Optional.empty(); @@ -174,22 +173,18 @@ public void updateLayout(PreviewPreferences previewPreferences) { } } } else { - updatePreviewLayout(previewPreferences.getPreviewStyle()); + updatePreviewLayout(previewPreferences.getPreviewStyle(), previewPreferences.getLayoutFormatterPreferences()); basePanel.ifPresent(panel -> panel.output(Localization.lang("Preview style changed to: %0", Localization.lang("Preview")))); } update(); } - public void updateLayout() { - updateLayout(Globals.prefs.getPreviewPreferences()); - } - - private void updatePreviewLayout(String layoutFile) { + private void updatePreviewLayout(String layoutFile, LayoutFormatterPreferences layoutFormatterPreferences) { StringReader sr = new StringReader(layoutFile.replace("__NEWLINE__", "\n")); try { layout = Optional.of( - new LayoutHelper(sr, Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader)) + new LayoutHelper(sr, layoutFormatterPreferences) .getLayoutFromText()); } catch (IOException e) { layout = Optional.empty(); @@ -276,7 +271,7 @@ public void highlightPattern(Optional newPattern) { */ public void setFixedLayout(String layout) { this.fixedLayout = true; - updatePreviewLayout(layout); + updatePreviewLayout(layout, Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader)); } public void print() { diff --git a/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java b/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java index e5fc7c6bc4e..6de3ce4fedf 100644 --- a/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java +++ b/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java @@ -6,9 +6,11 @@ import org.jabref.Globals; import org.jabref.gui.BasePanel; +import org.jabref.gui.BasePanelPreferences; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.gui.auximport.FromAuxDialog; +import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.logic.l10n.Localization; import org.jabref.model.Defaults; import org.jabref.model.database.BibDatabaseContext; @@ -38,7 +40,7 @@ public void actionPerformed(ActionEvent e) { if (dialog.generatePressed()) { Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode()); - BasePanel bp = new BasePanel(jabRefFrame, new BibDatabaseContext(dialog.getGenerateDB(), defaults)); + BasePanel bp = new BasePanel(jabRefFrame, BasePanelPreferences.from(Globals.prefs), new BibDatabaseContext(dialog.getGenerateDB(), defaults), ExternalFileTypes.getInstance()); jabRefFrame.addTab(bp, true); jabRefFrame.output(Localization.lang("New library created.")); } diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java b/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java index 88b21423bdb..f82cecc4adc 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java @@ -56,7 +56,7 @@ public ResolveDuplicateLabelDialog(BasePanel panel, String key, List e JCheckBox cb = new JCheckBox(Localization.lang("Generate BibTeX key"), !first); b.appendRows("1dlu, p"); b.add(cb).xy(1, row); - PreviewPanel previewPanel = new PreviewPanel(null, null); + PreviewPanel previewPanel = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); previewPanel.setEntry(entry); JFXPanel container = CustomJFXPanel.wrap(new Scene(previewPanel)); container.setPreferredSize(new Dimension(800, 90)); diff --git a/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java b/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java index 5905d1a67ff..d0cdf431ea7 100644 --- a/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java @@ -5,6 +5,7 @@ import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; +import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.PreviewPanel; import org.jabref.gui.customjfx.CustomJFXPanel; @@ -25,7 +26,7 @@ public EntryAddChangeViewModel(BibEntry diskEntry) { super(Localization.lang("Added entry")); this.diskEntry = diskEntry; - PreviewPanel previewPanel = new PreviewPanel(null, null); + PreviewPanel previewPanel = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); previewPanel.setEntry(diskEntry); container = CustomJFXPanel.wrap(new Scene(previewPanel)); } diff --git a/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java b/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java index 425f0bae798..9e7499e9c1c 100644 --- a/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java @@ -5,6 +5,7 @@ import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; +import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.PreviewPanel; import org.jabref.gui.customjfx.CustomJFXPanel; @@ -42,7 +43,7 @@ public EntryDeleteChangeViewModel(BibEntry memEntry, BibEntry tmpEntry) { LOGGER.debug("Modified entry: " + memEntry.getCiteKeyOptional().orElse("") + "\n Modified locally: " + isModifiedLocally); - PreviewPanel previewPanel = new PreviewPanel(null, null); + PreviewPanel previewPanel = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); previewPanel.setEntry(memEntry); container = CustomJFXPanel.wrap(new Scene(previewPanel)); } diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 3bfc5967dd3..3e5e4cc22a7 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; @@ -18,7 +19,6 @@ import javafx.scene.input.KeyEvent; import javafx.scene.layout.BorderPane; -import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.entryeditor.fileannotationtab.FileAnnotationTab; import org.jabref.gui.help.HelpAction; @@ -35,7 +35,6 @@ import org.jabref.logic.search.SearchQueryHighlightListener; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; -import org.jabref.preferences.JabRefPreferences; import org.fxmisc.easybind.EasyBind; @@ -66,16 +65,17 @@ public class EntryEditor extends BorderPane { private final List tabs; private SourceTab sourceTab; @FXML private Label typeLabel; + private final EntryEditorPreferences preferences; - public EntryEditor(BasePanel panel) { + public EntryEditor(BasePanel panel, EntryEditorPreferences preferences) { this.panel = panel; this.bibDatabaseContext = panel.getBibDatabaseContext(); this.undoManager = panel.getUndoManager(); + this.preferences = Objects.requireNonNull(preferences); ControlHelper.loadFXMLForControl(this); getStylesheets().add(EntryEditor.class.getResource("EntryEditor.css").toExternalForm()); - setStyle("-fx-font-size: " + Globals.prefs.getFontSizeFX() + "pt;"); EasyBind.subscribe(tabbed.getSelectionModel().selectedItemProperty(), tab -> { EntryEditorTab activeTab = (EntryEditorTab) tab; @@ -94,7 +94,7 @@ public EntryEditor(BasePanel panel) { */ private void setupKeyBindings() { tabbed.addEventFilter(KeyEvent.KEY_PRESSED, event -> { - Optional keyBinding = Globals.getKeyPrefs().mapToKeyBinding(event); + Optional keyBinding = preferences.getKeyBindings().mapToKeyBinding(event); if (keyBinding.isPresent()) { switch (keyBinding.get()) { case ENTRY_EDITOR_NEXT_PANEL: @@ -154,21 +154,20 @@ private List createTabs() { tabs.add(new DeprecatedFieldsTab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager)); // Other fields - tabs.add(new OtherFieldsTab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager)); + tabs.add(new OtherFieldsTab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager, preferences.getCustomTabFieldNames())); // General fields from preferences - EntryEditorTabList tabList = Globals.prefs.getEntryEditorTabList(); - for (int i = 0; i < tabList.getTabCount(); i++) { - tabs.add(new UserDefinedFieldsTab(tabList.getTabName(i), tabList.getTabFields(i), panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager)); + for (Map.Entry> tab : preferences.getEntryEditorTabList().entrySet()) { + tabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager)); } // Special tabs tabs.add(new MathSciNetTab()); tabs.add(new FileAnnotationTab(panel.getAnnotationCache())); - tabs.add(new RelatedArticlesTab(Globals.prefs)); + tabs.add(new RelatedArticlesTab(preferences)); // Source tab - sourceTab = new SourceTab(bibDatabaseContext, undoManager, Globals.prefs.getLatexFieldFormatterPreferences(), Globals.prefs); + sourceTab = new SourceTab(bibDatabaseContext, undoManager, preferences.getLatexFieldFormatterPreferences(), preferences.getImportFormatPreferences()); tabs.add(sourceTab); return tabs; } @@ -215,7 +214,7 @@ public void setEntry(BibEntry entry) { DefaultTaskExecutor.runInJavaFXThread(() -> { recalculateVisibleTabs(); - if (Globals.prefs.getBoolean(JabRefPreferences.DEFAULT_SHOW_SOURCE)) { + if (preferences.showSourceTabByDefault()) { tabbed.getSelectionModel().select(sourceTab); } @@ -233,14 +232,13 @@ private void setupToolBar() { typeLabel.setText(typedEntry.getTypeForDisplay()); // Add type change menu - ContextMenu typeMenu = new ChangeEntryTypeMenu().getChangeEntryTypePopupMenu(entry, bibDatabaseContext, undoManager); + ContextMenu typeMenu = new ChangeEntryTypeMenu(preferences.getKeyBindings()).getChangeEntryTypePopupMenu(entry, bibDatabaseContext, undoManager); typeLabel.setOnMouseClicked(event -> typeMenu.show(typeLabel, Side.RIGHT, 0, 0)); typeChangeButton.setOnMouseClicked(event -> typeMenu.show(typeChangeButton, Side.RIGHT, 0, 0)); // Add menu for fetching bibliographic information ContextMenu fetcherMenu = new ContextMenu(); - for (EntryBasedFetcher fetcher : WebFetchers - .getEntryBasedFetchers(Globals.prefs.getImportFormatPreferences())) { + for (EntryBasedFetcher fetcher : WebFetchers.getEntryBasedFetchers(preferences.getImportFormatPreferences())) { MenuItem fetcherMenuItem = new MenuItem(fetcher.getName()); fetcherMenuItem.setOnAction(event -> new EntryFetchAndMergeWorker(panel, getEntry(), fetcher).execute()); fetcherMenu.getItems().add(fetcherMenuItem); diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java new file mode 100644 index 00000000000..0cf074aaf6a --- /dev/null +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java @@ -0,0 +1,69 @@ +package org.jabref.gui.entryeditor; + +import java.util.List; +import java.util.Map; + +import org.jabref.Globals; +import org.jabref.gui.keyboard.KeyBindingRepository; +import org.jabref.logic.bibtex.LatexFieldFormatterPreferences; +import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.preferences.JabRefPreferences; + +public class EntryEditorPreferences { + private Map> entryEditorTabList; + private LatexFieldFormatterPreferences latexFieldFormatterPreferences; + private ImportFormatPreferences importFormatPreferences; + private List customTabFieldNames; + private boolean shouldShowRecommendationsTab; + private boolean showSourceTabByDefault; + private KeyBindingRepository keyBindings; + + public EntryEditorPreferences(Map> entryEditorTabList, LatexFieldFormatterPreferences latexFieldFormatterPreferences, ImportFormatPreferences importFormatPreferences, List customTabFieldNames, boolean shouldShowRecommendationsTab, boolean showSourceTabByDefault, KeyBindingRepository keyBindings) { + this.entryEditorTabList = entryEditorTabList; + this.latexFieldFormatterPreferences = latexFieldFormatterPreferences; + this.importFormatPreferences = importFormatPreferences; + this.customTabFieldNames = customTabFieldNames; + this.shouldShowRecommendationsTab = shouldShowRecommendationsTab; + this.showSourceTabByDefault = showSourceTabByDefault; + this.keyBindings = keyBindings; + } + + public static EntryEditorPreferences from(JabRefPreferences preferences) { + return new EntryEditorPreferences( + preferences.getEntryEditorTabList(), + preferences.getLatexFieldFormatterPreferences(), + preferences.getImportFormatPreferences(), + preferences.getCustomTabFieldNames(), + preferences.getBoolean(JabRefPreferences.SHOW_RECOMMENDATIONS), + preferences.getBoolean(JabRefPreferences.DEFAULT_SHOW_SOURCE), + Globals.getKeyPrefs()); + } + + public Map> getEntryEditorTabList() { + return entryEditorTabList; + } + + public LatexFieldFormatterPreferences getLatexFieldFormatterPreferences() { + return latexFieldFormatterPreferences; + } + + public ImportFormatPreferences getImportFormatPreferences() { + return importFormatPreferences; + } + + public List getCustomTabFieldNames() { + return customTabFieldNames; + } + + public boolean shouldShowRecommendationsTab() { + return shouldShowRecommendationsTab; + } + + public boolean showSourceTabByDefault() { + return showSourceTabByDefault; + } + + public KeyBindingRepository getKeyBindings() { + return keyBindings; + } +} diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTabList.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTabList.java index ac5033e002e..f35f8c94ad6 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTabList.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTabList.java @@ -1,61 +1,44 @@ package org.jabref.gui.entryeditor; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.TreeMap; -import org.jabref.Globals; import org.jabref.preferences.JabRefPreferences; /** - * Class for holding the information about customizable entry editor tabs. + * Class for creating the information about customizable entry editor tabs. */ public final class EntryEditorTabList { - private List> list; - private List names; + private EntryEditorTabList() { - public EntryEditorTabList() { - init(); } - private void init() { - list = new ArrayList<>(); - names = new ArrayList<>(); + public static Map> create(JabRefPreferences preferences) { + Map> tabs = new TreeMap<>(); int i = 0; String name; - if (Globals.prefs.hasKey(JabRefPreferences.CUSTOM_TAB_NAME + 0)) { + if (preferences.hasKey(JabRefPreferences.CUSTOM_TAB_NAME + 0)) { // The user has modified from the default values: - while (Globals.prefs.hasKey(JabRefPreferences.CUSTOM_TAB_NAME + i)) { - name = Globals.prefs.get(JabRefPreferences.CUSTOM_TAB_NAME + i); + while (preferences.hasKey(JabRefPreferences.CUSTOM_TAB_NAME + i)) { + name = preferences.get(JabRefPreferences.CUSTOM_TAB_NAME + i); List entry = Arrays - .asList(Globals.prefs.get(JabRefPreferences.CUSTOM_TAB_FIELDS + i).split(";")); - names.add(name); - list.add(entry); + .asList(preferences.get(JabRefPreferences.CUSTOM_TAB_FIELDS + i).split(";")); + tabs.put(name, entry); i++; } } else { // Nothing set, so we use the default values: - while (Globals.prefs.get(JabRefPreferences.CUSTOM_TAB_NAME + "_def" + i) != null) { - name = Globals.prefs.get(JabRefPreferences.CUSTOM_TAB_NAME + "_def" + i); + while (preferences.get(JabRefPreferences.CUSTOM_TAB_NAME + "_def" + i) != null) { + name = preferences.get(JabRefPreferences.CUSTOM_TAB_NAME + "_def" + i); List entry = Arrays - .asList(Globals.prefs.get(JabRefPreferences.CUSTOM_TAB_FIELDS + "_def" + i).split(";")); - names.add(name); - list.add(entry); + .asList(preferences.get(JabRefPreferences.CUSTOM_TAB_FIELDS + "_def" + i).split(";")); + tabs.put(name, entry); i++; } } - } - - public int getTabCount() { - return list.size(); - } - - public String getTabName(int tab) { - return names.get(tab); - } - - public List getTabFields(int tab) { - return list.get(tab); + return tabs; } } diff --git a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java index b1ac6b38071..6ed9ce119af 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java @@ -71,6 +71,12 @@ private String convertToHex(java.awt.Color color) { } private Region setupPanel(BibEntry entry, boolean compressed, SuggestionProviders suggestionProviders, UndoManager undoManager) { + // The preferences might be not initialized in tests -> return empty node + // TODO: Replace this ugly workaround by proper injection propagation + if (Globals.prefs == null) { + return new Region(); + } + editors.clear(); EntryType entryType = EntryTypes.getTypeOrDefault(entry.getType(), databaseContext.getMode()); diff --git a/src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java b/src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java index 4896d0a9236..ba9e55cf341 100644 --- a/src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java @@ -8,7 +8,6 @@ import javafx.scene.control.Tooltip; -import org.jabref.Globals; import org.jabref.gui.IconTheme; import org.jabref.gui.autocompleter.SuggestionProviders; import org.jabref.logic.l10n.Localization; @@ -18,12 +17,15 @@ public class OtherFieldsTab extends FieldsEditorTab { - public OtherFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager) { + private final List customTabFieldNames; + + public OtherFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, List customTabFieldNames) { super(false, databaseContext, suggestionProviders, undoManager); setText(Localization.lang("Other fields")); setTooltip(new Tooltip(Localization.lang("Show remaining fields"))); setGraphic(IconTheme.JabRefIcons.OPTIONAL.getGraphicNode()); + this.customTabFieldNames = customTabFieldNames; } @Override @@ -35,7 +37,7 @@ protected Collection determineFieldsToShow(BibEntry entry, EntryType ent otherFields.removeAll(entryType.getDeprecatedFields()); otherFields.remove(BibEntry.KEY_FIELD); - otherFields.removeAll(Globals.prefs.getCustomTabFieldNames()); + otherFields.removeAll(customTabFieldNames); return otherFields; } } diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index 98a5ebd0bea..49d2f7d3023 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -20,9 +20,9 @@ public class RelatedArticlesTab extends EntryEditorTab { - private final JabRefPreferences preferences; + private final EntryEditorPreferences preferences; - public RelatedArticlesTab(JabRefPreferences preferences) { + public RelatedArticlesTab(EntryEditorPreferences preferences) { setText(Localization.lang("Related articles")); setTooltip(new Tooltip(Localization.lang("Related articles"))); this.preferences = preferences; @@ -81,7 +81,7 @@ private String convertToHtml(List list) { @Override public boolean shouldShow(BibEntry entry) { - return preferences.getBoolean(JabRefPreferences.SHOW_RECOMMENDATIONS); + return preferences.shouldShowRecommendationsTab(); } @Override diff --git a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java index 9b52b739fe8..2ad5a83d533 100644 --- a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java @@ -24,6 +24,7 @@ import org.jabref.logic.bibtex.InvalidFieldValueException; import org.jabref.logic.bibtex.LatexFieldFormatter; import org.jabref.logic.bibtex.LatexFieldFormatterPreferences; +import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.l10n.Localization; @@ -32,7 +33,6 @@ import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.InternalBibtexFields; -import org.jabref.preferences.JabRefPreferences; import de.saxsys.mvvmfx.utils.validation.ObservableRuleBasedValidator; import de.saxsys.mvvmfx.utils.validation.ValidationMessage; @@ -47,19 +47,19 @@ public class SourceTab extends EntryEditorTab { private static final Log LOGGER = LogFactory.getLog(SourceTab.class); private final LatexFieldFormatterPreferences fieldFormatterPreferences; private final BibDatabaseMode mode; - private final JabRefPreferences preferences; private UndoManager undoManager; private final ObjectProperty sourceIsValid = new SimpleObjectProperty<>(); private final ObservableRuleBasedValidator sourceValidator = new ObservableRuleBasedValidator(sourceIsValid); + private final ImportFormatPreferences importFormatPreferences; - public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, LatexFieldFormatterPreferences fieldFormatterPreferences, JabRefPreferences preferences) { + public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, LatexFieldFormatterPreferences fieldFormatterPreferences, ImportFormatPreferences importFormatPreferences) { this.mode = bibDatabaseContext.getMode(); this.setText(Localization.lang("%0 source", mode.getFormattedName())); this.setTooltip(new Tooltip(Localization.lang("Show/edit %0 source", mode.getFormattedName()))); this.setGraphic(IconTheme.JabRefIcons.SOURCE.getGraphicNode()); this.undoManager = undoManager; this.fieldFormatterPreferences = fieldFormatterPreferences; - this.preferences = preferences; + this.importFormatPreferences = importFormatPreferences; } private static String getSourceString(BibEntry entry, BibDatabaseMode type, LatexFieldFormatterPreferences fieldFormatterPreferences) throws IOException { @@ -73,7 +73,6 @@ private static String getSourceString(BibEntry entry, BibDatabaseMode type, Late private CodeArea createSourceEditor() { CodeArea codeArea = new CodeArea(); codeArea.setWrapText(true); - codeArea.lookup(".styled-text-area").setStyle("-fx-font-size: " + preferences.getFontSizeFX() + "pt;"); return codeArea; } @@ -119,7 +118,7 @@ private void storeSource(String text) { return; } - BibtexParser bibtexParser = new BibtexParser(preferences.getImportFormatPreferences()); + BibtexParser bibtexParser = new BibtexParser(importFormatPreferences); try { ParserResult parserResult = bibtexParser.parse(new StringReader(text)); BibDatabase database = parserResult.getDatabase(); @@ -166,7 +165,7 @@ private void storeSource(String text) { String newValue = field.getValue(); if (!Objects.equals(oldValue, newValue)) { // Test if the field is legally set. - new LatexFieldFormatter(preferences.getLatexFieldFormatterPreferences()) + new LatexFieldFormatter(fieldFormatterPreferences) .format(newValue, fieldName); compound.addEdit(new UndoableFieldChange(currentEntry, fieldName, oldValue, newValue)); diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index 85564a70dc8..6c2d81b90e2 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -53,6 +53,7 @@ import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; +import org.jabref.gui.BasePanelPreferences; import org.jabref.gui.DuplicateResolverDialog; import org.jabref.gui.DuplicateResolverDialog.DuplicateResolverResult; import org.jabref.gui.EntryMarker; @@ -66,6 +67,7 @@ import org.jabref.gui.externalfiles.AutoSetLinks; import org.jabref.gui.externalfiles.DownloadExternalFile; import org.jabref.gui.externalfiletype.ExternalFileMenuItem; +import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.filelist.FileListEntry; import org.jabref.gui.filelist.FileListEntryEditor; import org.jabref.gui.filelist.FileListTableModel; @@ -200,7 +202,7 @@ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoNam this.undoName = undoName; this.newDatabase = newDatabase; setIconImages(IconTheme.getLogoSet()); - preview = new PreviewPanel(panel, bibDatabaseContext); + preview = new PreviewPanel(panel, bibDatabaseContext, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); duplLabel.setToolTipText(Localization.lang("Possible duplicate of existing entry. Click to resolve.")); @@ -802,7 +804,7 @@ private void addSelectedEntries(NamedCompound ce, final List selected) if (newDatabase) { // Create a new BasePanel for the entries: Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode()); - panel = new BasePanel(frame, new BibDatabaseContext(defaults)); + panel = new BasePanel(frame, BasePanelPreferences.from(Globals.prefs), new BibDatabaseContext(defaults), ExternalFileTypes.getInstance()); } boolean groupingCanceled = false; 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 af02bd48f03..93a2fb1a2be 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -21,12 +21,14 @@ import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; +import org.jabref.gui.BasePanelPreferences; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.gui.actions.MnemonicAwareAction; import org.jabref.gui.autosaveandbackup.BackupUIManager; +import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.importer.ParserResultWarningDialog; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.shared.SharedDatabaseUIManager; @@ -270,7 +272,7 @@ private BasePanel addNewDatabase(ParserResult result, final Path file, boolean r .execute(() -> ParserResultWarningDialog.showParserResultWarningDialog(result, frame)); } - BasePanel basePanel = new BasePanel(frame, result.getDatabaseContext()); + BasePanel basePanel = new BasePanel(frame, BasePanelPreferences.from(Globals.prefs), result.getDatabaseContext(), ExternalFileTypes.getInstance()); // file is set to null inside the EventDispatcherThread SwingUtilities.invokeLater(() -> frame.addTab(basePanel, raisePanel)); diff --git a/src/main/java/org/jabref/gui/maintable/CellFactory.java b/src/main/java/org/jabref/gui/maintable/CellFactory.java index 263343eb986..72b118cfcb2 100644 --- a/src/main/java/org/jabref/gui/maintable/CellFactory.java +++ b/src/main/java/org/jabref/gui/maintable/CellFactory.java @@ -16,7 +16,7 @@ public class CellFactory { private final Map TABLE_ICONS = new HashMap<>(); - public CellFactory() { + public CellFactory(ExternalFileTypes externalFileTypes) { Node label; label = IconTheme.JabRefIcons.PDF_FILE.getGraphicNode(); //label.setToo(Localization.lang("Open") + " PDF"); @@ -50,7 +50,7 @@ public CellFactory() { //label.setToolTipText(Localization.lang("Open file")); TABLE_ICONS.put(FieldName.FILE, label); - for (ExternalFileType fileType : ExternalFileTypes.getInstance().getExternalFileTypeSelection()) { + for (ExternalFileType fileType : externalFileTypes.getExternalFileTypeSelection()) { label = fileType.getIcon().getGraphicNode(); //label.setToolTipText(Localization.lang("Open %0 file", fileType.getName())); TABLE_ICONS.put(fileType.getName(), label); diff --git a/src/main/java/org/jabref/gui/maintable/ColumnFactory.java b/src/main/java/org/jabref/gui/maintable/ColumnFactory.java index b93b5dff34c..2c50844b8b9 100644 --- a/src/main/java/org/jabref/gui/maintable/ColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/ColumnFactory.java @@ -3,13 +3,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import javafx.scene.Node; import javafx.scene.control.TableColumn; -import org.jabref.Globals; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefIcon; import org.jabref.gui.externalfiletype.ExternalFileType; @@ -21,7 +21,6 @@ import org.jabref.model.entry.FieldName; import org.jabref.model.entry.LinkedFile; import org.jabref.model.entry.specialfields.SpecialField; -import org.jabref.preferences.JabRefPreferences; import org.fxmisc.easybind.EasyBind; @@ -29,27 +28,29 @@ class ColumnFactory { private static final String STYLE_ICON = "column-icon"; + private final ColumnPreferences preferences; private final ExternalFileTypes externalFileTypes; private final BibDatabase database; private final CellFactory cellFactory; - public ColumnFactory(BibDatabase database) { - this.database = database; - externalFileTypes = ExternalFileTypes.getInstance(); - cellFactory = new CellFactory(); + public ColumnFactory(BibDatabase database, ColumnPreferences preferences, ExternalFileTypes externalFileTypes) { + this.database = Objects.requireNonNull(database); + this.preferences = Objects.requireNonNull(preferences); + this.externalFileTypes = Objects.requireNonNull(externalFileTypes); + this.cellFactory = new CellFactory(externalFileTypes); } public List> createColumns() { List> columns = new ArrayList<>(); // Add column for linked files - if (Globals.prefs.getBoolean(JabRefPreferences.FILE_COLUMN)) { + if (preferences.showFileColumn()) { columns.add(createFileColumn()); } // Add column for DOI/URL - if (Globals.prefs.getBoolean(JabRefPreferences.URL_COLUMN)) { - if (Globals.prefs.getBoolean(JabRefPreferences.PREFER_URL_DOI)) { + if (preferences.showUrlColumn()) { + if (preferences.preferDoiOverUrl()) { columns.add(createIconColumn(IconTheme.JabRefIcons.DOI, FieldName.DOI, FieldName.URL)); } else { columns.add(createIconColumn(IconTheme.JabRefIcons.WWW, FieldName.URL, FieldName.DOI)); @@ -57,44 +58,22 @@ public ColumnFactory(BibDatabase database) { } // Add column for eprints - if (Globals.prefs.getBoolean(JabRefPreferences.ARXIV_COLUMN)) { + if (preferences.showEprintColumn()) { columns.add(createIconColumn(IconTheme.JabRefIcons.WWW, FieldName.EPRINT)); } // Add columns for other file types - if (Globals.prefs.getBoolean(JabRefPreferences.EXTRA_FILE_COLUMNS)) { - List desiredColumns = Globals.prefs.getStringList(JabRefPreferences.LIST_OF_FILE_COLUMNS); - for (String desiredColumn : desiredColumns) { - columns.add(createExtraFileColumn(desiredColumn)); - } + for (String column : preferences.getExtraFileColumns()) { + columns.add(createExtraFileColumn(column)); } + // Add 'normal' bibtex fields as configured in the preferences columns.addAll(createNormalColumns()); // Add the "special" icon columns (e.g., ranking, file, ...) that are enabled in preferences - if (Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) { - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) { - columns.add(createSpecialFieldColumn(SpecialField.RANKING)); - } - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RELEVANCE)) { - columns.add(createSpecialFieldColumn(SpecialField.RELEVANCE)); - } - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_QUALITY)) { - columns.add(createSpecialFieldColumn(SpecialField.QUALITY)); - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) { - columns.add(createSpecialFieldColumn(SpecialField.PRIORITY)); - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRINTED)) { - columns.add(createSpecialFieldColumn(SpecialField.PRINTED)); - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) { - columns.add(createSpecialFieldColumn(SpecialField.READ_STATUS)); - } + for (SpecialField field : preferences.getSpecialFieldColumns()) { + columns.add(createSpecialFieldColumn((field))); } return columns; @@ -104,8 +83,7 @@ public ColumnFactory(BibDatabase database) { List> columns = new ArrayList<>(); // Read table columns from preferences - List columnSettings = Globals.prefs.getStringList(JabRefPreferences.COLUMN_NAMES); - for (String columnName : columnSettings) { + for (String columnName : preferences.getNormalColumns()) { // Stored column name will be used as header // There might be more than one field to display, e.g., "author/editor" or "date/year" - so split String[] fields = columnName.split(FieldName.FIELD_SEPARATOR); diff --git a/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java b/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java new file mode 100644 index 00000000000..40ad69e7453 --- /dev/null +++ b/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java @@ -0,0 +1,107 @@ +package org.jabref.gui.maintable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.jabref.model.entry.specialfields.SpecialField; +import org.jabref.preferences.JabRefPreferences; + +public class ColumnPreferences { + + private final boolean showFileColumn; + private final boolean showUrlColumn; + private final boolean preferDoiOverUrl; + private final boolean showEprintColumn; + private final List normalColumns; + private final List specialFieldColumns; + private final List extraFileColumns; + + public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean preferDoiOverUrl, boolean showEprintColumn, List normalColumns, List specialFieldColumns, List extraFileColumns) { + this.showFileColumn = showFileColumn; + this.showUrlColumn = showUrlColumn; + this.preferDoiOverUrl = preferDoiOverUrl; + this.showEprintColumn = showEprintColumn; + this.normalColumns = normalColumns; + this.specialFieldColumns = specialFieldColumns; + this.extraFileColumns = extraFileColumns; + } + + public static ColumnPreferences from(JabRefPreferences preferences) { + return new ColumnPreferences( + preferences.getBoolean(JabRefPreferences.FILE_COLUMN), + preferences.getBoolean(JabRefPreferences.URL_COLUMN), + preferences.getBoolean(JabRefPreferences.PREFER_URL_DOI), + preferences.getBoolean(JabRefPreferences.ARXIV_COLUMN), + preferences.getStringList(JabRefPreferences.COLUMN_NAMES), + createSpecialFieldColumns(preferences), + createExtraFileColumns(preferences) + ); + } + + private static List createExtraFileColumns(JabRefPreferences preferences) { + if (preferences.getBoolean(JabRefPreferences.EXTRA_FILE_COLUMNS)) { + return preferences.getStringList(JabRefPreferences.LIST_OF_FILE_COLUMNS); + } else { + return Collections.emptyList(); + } + } + + private static List createSpecialFieldColumns(JabRefPreferences preferences) { + if (preferences.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) { + List fieldsToShow = new ArrayList<>(); + if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) { + fieldsToShow.add(SpecialField.RANKING); + } + if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_RELEVANCE)) { + fieldsToShow.add(SpecialField.RELEVANCE); + } + if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_QUALITY)) { + fieldsToShow.add(SpecialField.QUALITY); + } + + if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) { + fieldsToShow.add(SpecialField.PRIORITY); + } + + if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_PRINTED)) { + fieldsToShow.add(SpecialField.PRINTED); + } + + if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) { + fieldsToShow.add(SpecialField.READ_STATUS); + } + return fieldsToShow; + } else { + return Collections.emptyList(); + } + } + + public boolean showFileColumn() { + return showFileColumn; + } + + public boolean showUrlColumn() { + return showUrlColumn; + } + + public boolean preferDoiOverUrl() { + return preferDoiOverUrl; + } + + public boolean showEprintColumn() { + return showEprintColumn; + } + + public List getExtraFileColumns() { + return extraFileColumns; + } + + public List getSpecialFieldColumns() { + return specialFieldColumns; + } + + public List getNormalColumns() { + return normalColumns; + } +} diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index ca003724cc6..dcaaaf63405 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -17,6 +17,7 @@ import org.jabref.gui.BasePanel; import org.jabref.gui.EntryMarker; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.renderer.CompleteRenderer; import org.jabref.gui.renderer.GeneralRenderer; import org.jabref.gui.renderer.IncompleteRenderer; @@ -50,8 +51,8 @@ public class MainTable extends TableView { private static final Log LOGGER = LogFactory.getLog(MainTable.class); private final BasePanel panel; - private final boolean tableColorCodes; - private final boolean tableResolvedColorCodes; + //private final boolean tableColorCodes; + //private final boolean tableResolvedColorCodes; private final ScrollPane pane; // needed to activate/deactivate the listener @@ -67,22 +68,22 @@ private enum CellRendererMode { } static { - MainTable.updateRenderers(); + //MainTable.updateRenderers(); } public MainTable(MainTableDataModel model, JabRefFrame frame, - BasePanel panel, BibDatabase database) { + BasePanel panel, BibDatabase database, MainTablePreferences preferences, ExternalFileTypes externalFileTypes) { super(); this.model = model; - this.getColumns().addAll(new ColumnFactory(database).createColumns()); + this.getColumns().addAll(new ColumnFactory(database, preferences.getColumnPreferences(), externalFileTypes).createColumns()); this.setRowFactory(new ViewModelTableRowFactory() .withOnMouseClickedEvent((entry, event) -> { if (event.getClickCount() == 2) { panel.showAndEdit(entry.getEntry()); } })); - if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_RESIZE_MODE)) { + if (preferences.resizeColumnsToFit()) { this.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); } this.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); @@ -99,11 +100,11 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, this.pane.getStylesheets().add(MainTable.class.getResource("MainTable.css").toExternalForm()); // TODO: Color - tableColorCodes = Globals.prefs.getBoolean(JabRefPreferences.TABLE_COLOR_CODES_ON); - tableResolvedColorCodes = Globals.prefs.getBoolean(JabRefPreferences.TABLE_RESOLVED_COLOR_CODES_ON); + //tableColorCodes = Globals.prefs.getBoolean(JabRefPreferences.TABLE_COLOR_CODES_ON); + //tableResolvedColorCodes = Globals.prefs.getBoolean(JabRefPreferences.TABLE_RESOLVED_COLOR_CODES_ON); //pane.getViewport().setBackground(Globals.prefs.getColor(JabRefPreferences.TABLE_BACKGROUND)); //setGridColor(Globals.prefs.getColor(JabRefPreferences.GRID_COLOR)); - if (!Globals.prefs.getBoolean(JabRefPreferences.TABLE_SHOW_GRID)) { + if (!preferences.showGrid()) { this.setStyle("-fx-table-cell-border-color: transparent;"); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTablePreferences.java b/src/main/java/org/jabref/gui/maintable/MainTablePreferences.java new file mode 100644 index 00000000000..a16aed83f92 --- /dev/null +++ b/src/main/java/org/jabref/gui/maintable/MainTablePreferences.java @@ -0,0 +1,36 @@ +package org.jabref.gui.maintable; + +import org.jabref.Globals; +import org.jabref.preferences.JabRefPreferences; + +public class MainTablePreferences { + private final boolean showGrid; + private final ColumnPreferences columnPreferences; + private final boolean resizeColumnsToFit; + + public MainTablePreferences(boolean showGrid, ColumnPreferences columnPreferences, boolean resizeColumnsToFit) { + this.showGrid = showGrid; + this.columnPreferences = columnPreferences; + this.resizeColumnsToFit = resizeColumnsToFit; + } + + public static MainTablePreferences from(JabRefPreferences preferences) { + return new MainTablePreferences( + Globals.prefs.getBoolean(JabRefPreferences.TABLE_SHOW_GRID), + ColumnPreferences.from(preferences), + Globals.prefs.getBoolean(JabRefPreferences.AUTO_RESIZE_MODE)); + } + + public ColumnPreferences getColumnPreferences() { + return columnPreferences; + } + + public boolean resizeColumnsToFit() { + + return resizeColumnsToFit; + } + + public boolean showGrid() { + return showGrid; + } +} diff --git a/src/main/java/org/jabref/gui/menus/ChangeEntryTypeMenu.java b/src/main/java/org/jabref/gui/menus/ChangeEntryTypeMenu.java index dac3baaec81..0b5b7625a24 100644 --- a/src/main/java/org/jabref/gui/menus/ChangeEntryTypeMenu.java +++ b/src/main/java/org/jabref/gui/menus/ChangeEntryTypeMenu.java @@ -15,10 +15,10 @@ import javafx.scene.control.Menu; import javafx.scene.control.SeparatorMenuItem; -import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.actions.ChangeTypeAction; import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.undo.CountingUndoManager; import org.jabref.logic.l10n.Localization; import org.jabref.model.EntryTypes; @@ -32,15 +32,15 @@ public class ChangeEntryTypeMenu { public final Map entryShortCuts = new HashMap<>(); - public ChangeEntryTypeMenu () { - entryShortCuts.put(BibtexEntryTypes.ARTICLE.getName(), Globals.getKeyPrefs().getKey(KeyBinding.NEW_ARTICLE)); - entryShortCuts.put(BibtexEntryTypes.BOOK.getName(), Globals.getKeyPrefs().getKey(KeyBinding.NEW_BOOK)); - entryShortCuts.put(BibtexEntryTypes.PHDTHESIS.getName(), Globals.getKeyPrefs().getKey(KeyBinding.NEW_PHDTHESIS)); - entryShortCuts.put(BibtexEntryTypes.INBOOK.getName(), Globals.getKeyPrefs().getKey(KeyBinding.NEW_MASTERSTHESIS)); - entryShortCuts.put(BibtexEntryTypes.INBOOK.getName(), Globals.getKeyPrefs().getKey(KeyBinding.NEW_INBOOK)); - entryShortCuts.put(BibtexEntryTypes.PROCEEDINGS.getName(), Globals.getKeyPrefs().getKey(KeyBinding.NEW_PROCEEDINGS)); - entryShortCuts.put(BibtexEntryTypes.UNPUBLISHED.getName(), Globals.getKeyPrefs().getKey(KeyBinding.NEW_UNPUBLISHED)); - entryShortCuts.put(BibtexEntryTypes.TECHREPORT.getName(), Globals.getKeyPrefs().getKey(KeyBinding.NEW_TECHREPORT)); + public ChangeEntryTypeMenu(KeyBindingRepository keyBindings) { + entryShortCuts.put(BibtexEntryTypes.ARTICLE.getName(), keyBindings.getKey(KeyBinding.NEW_ARTICLE)); + entryShortCuts.put(BibtexEntryTypes.BOOK.getName(), keyBindings.getKey(KeyBinding.NEW_BOOK)); + entryShortCuts.put(BibtexEntryTypes.PHDTHESIS.getName(), keyBindings.getKey(KeyBinding.NEW_PHDTHESIS)); + entryShortCuts.put(BibtexEntryTypes.INBOOK.getName(), keyBindings.getKey(KeyBinding.NEW_MASTERSTHESIS)); + entryShortCuts.put(BibtexEntryTypes.INBOOK.getName(), keyBindings.getKey(KeyBinding.NEW_INBOOK)); + entryShortCuts.put(BibtexEntryTypes.PROCEEDINGS.getName(), keyBindings.getKey(KeyBinding.NEW_PROCEEDINGS)); + entryShortCuts.put(BibtexEntryTypes.UNPUBLISHED.getName(), keyBindings.getKey(KeyBinding.NEW_UNPUBLISHED)); + entryShortCuts.put(BibtexEntryTypes.TECHREPORT.getName(), keyBindings.getKey(KeyBinding.NEW_TECHREPORT)); } public JMenu getChangeEntryTypeMenu(BasePanel panel) { diff --git a/src/main/java/org/jabref/gui/menus/RightClickMenu.java b/src/main/java/org/jabref/gui/menus/RightClickMenu.java index 4903310c535..f2dc69df8db 100644 --- a/src/main/java/org/jabref/gui/menus/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/menus/RightClickMenu.java @@ -53,7 +53,7 @@ public class RightClickMenu extends JPopupMenu implements PopupMenuListener { public RightClickMenu(JabRefFrame frame, BasePanel panel) { this.panel = panel; - JMenu typeMenu = new ChangeEntryTypeMenu().getChangeEntryTypeMenu(panel); + JMenu typeMenu = new ChangeEntryTypeMenu(Globals.getKeyPrefs()).getChangeEntryTypeMenu(panel); // Are multiple entries selected? boolean multiple = areMultipleEntriesSelected(); diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java index 82bca6c916e..e1f81c3a663 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntries.java @@ -183,7 +183,7 @@ private void initialize() { // Setup a PreviewPanel and a Bibtex source box for the merged entry mainPanel.add(boldFontLabel(Localization.lang("Merged entry")), CELL_CONSTRAINTS.xyw(1, 6, 6)); - entryPreview = new PreviewPanel(null, null); + entryPreview = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); entryPreview.setEntry(mergedEntry); JFXPanel container = CustomJFXPanel.wrap(new Scene(entryPreview)); mainPanel.add(container, CELL_CONSTRAINTS.xyw(1, 8, 6)); diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java index 1c0caa80c2d..189f27cd92a 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java @@ -139,7 +139,7 @@ private void init() { // Create a preview panel for previewing styles // Must be done before creating the table to avoid NPEs - preview = new PreviewPanel(null, null); + preview = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); // Use the test entry from the Preview settings tab in Preferences: preview.setEntry(prevEntry); diff --git a/src/main/java/org/jabref/gui/preftabs/PreviewPrefsTab.java b/src/main/java/org/jabref/gui/preftabs/PreviewPrefsTab.java index f1f36925e83..b709e206ced 100644 --- a/src/main/java/org/jabref/gui/preftabs/PreviewPrefsTab.java +++ b/src/main/java/org/jabref/gui/preftabs/PreviewPrefsTab.java @@ -121,7 +121,7 @@ private void setupLogic() { btnTest.addActionListener(event -> { try { - PreviewPanel testPane = new PreviewPanel(null, null); + PreviewPanel testPane = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); testPane.setFixedLayout(layout.getText()); testPane.setEntry(TestEntry.getTestEntry()); JFXPanel container = CustomJFXPanel.wrap(new Scene(testPane)); @@ -251,7 +251,7 @@ public void storeSettings() { // update preview for (BasePanel basePanel : JabRefGUI.getMainFrame().getBasePanelList()) { - basePanel.getPreviewPanel().updateLayout(); + basePanel.getPreviewPanel().updateLayout(Globals.prefs.getPreviewPreferences()); } } diff --git a/src/main/java/org/jabref/gui/search/SearchResultFrame.java b/src/main/java/org/jabref/gui/search/SearchResultFrame.java index 7b119820756..fb1683da614 100644 --- a/src/main/java/org/jabref/gui/search/SearchResultFrame.java +++ b/src/main/java/org/jabref/gui/search/SearchResultFrame.java @@ -128,7 +128,7 @@ private void init(String title) { searchResultFrame.setTitle(title); searchResultFrame.setIconImages(IconTheme.getLogoSet()); - preview = new PreviewPanel(null, null); + preview = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); sortedEntries = new SortedList<>(entries, new EntryComparator(false, true, FieldName.AUTHOR)); model = (DefaultEventTableModel) GlazedListsSwing.eventTableModelWithThreadProxyList(sortedEntries, diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java index 4b4f0d23e79..6813f8f9183 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java @@ -1,15 +1,6 @@ package org.jabref.gui.specialfields; -import java.util.List; - -import org.jabref.Globals; -import org.jabref.gui.undo.NamedCompound; -import org.jabref.gui.undo.UndoableFieldChange; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.specialfields.SpecialFieldsUtils; -import org.jabref.model.FieldChange; import org.jabref.model.database.event.EntryAddedEvent; -import org.jabref.model.entry.BibEntry; import com.google.common.eventbus.Subscribe; @@ -26,10 +17,13 @@ public static SpecialFieldDatabaseChangeListener getInstance() { @Subscribe public void listen(EntryAddedEvent event) { + // TODO + /* if (!Globals.prefs.isKeywordSyncEnabled()) { return; } + final BibEntry entry = event.getBibEntry(); // NamedCompount code similar to SpecialFieldUpdateListener NamedCompound nc = new NamedCompound(Localization.lang("Synchronized special fields based on keywords")); @@ -40,5 +34,6 @@ public void listen(EntryAddedEvent event) { // Don't insert the compound into the undoManager, // it would be added before the component which undoes the insertion of the entry and creates heavy problems // (which prohibits the undo the deleting multiple entries) + */ } } diff --git a/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java b/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java index 410deea49fe..1e7c11fc8b2 100644 --- a/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java +++ b/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java @@ -1,6 +1,7 @@ package org.jabref.migrations; import java.util.List; +import java.util.Map; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -13,7 +14,6 @@ import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; -import org.jabref.gui.entryeditor.EntryEditorTabList; import org.jabref.gui.importer.actions.GUIPostOpenAction; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableFieldChange; @@ -248,17 +248,13 @@ private void makeChanges(BasePanel panel, ParserResult pr, boolean upgradePrefs, } private boolean showsFileInGenFields() { - boolean found = false; - EntryEditorTabList tabList = Globals.prefs.getEntryEditorTabList(); - outer: for (int i = 0; i < tabList.getTabCount(); i++) { - List fields = tabList.getTabFields(i); - for (String field : fields) { + for (Map.Entry> tab : Globals.prefs.getEntryEditorTabList().entrySet()) { + for (String field : tab.getValue()) { if (field.equals(FieldName.FILE)) { - found = true; - break outer; + return true; } } } - return found; + return false; } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 631f0b48f1a..c840405e1fe 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -431,7 +431,7 @@ public class JabRefPreferences implements PreferencesService { private final Preferences prefs; private GlobalBibtexKeyPattern keyPattern; // Object containing info about customized entry editor tabs. - private EntryEditorTabList tabList; + private Map> tabList; // The constructor is made private to enforce this as a singleton class: private JabRefPreferences() { @@ -1309,7 +1309,7 @@ public void purgeSeries(String prefix, int number) { } } - public EntryEditorTabList getEntryEditorTabList() { + public Map> getEntryEditorTabList() { if (tabList == null) { updateEntryEditorTabList(); } @@ -1317,7 +1317,7 @@ public EntryEditorTabList getEntryEditorTabList() { } public void updateEntryEditorTabList() { - tabList = new EntryEditorTabList(); + tabList = EntryEditorTabList.create(this); } /** diff --git a/src/main/java/org/jabref/preferences/PreviewPreferences.java b/src/main/java/org/jabref/preferences/PreviewPreferences.java index a4099ca8e54..4d7e9bb91b3 100644 --- a/src/main/java/org/jabref/preferences/PreviewPreferences.java +++ b/src/main/java/org/jabref/preferences/PreviewPreferences.java @@ -2,6 +2,8 @@ import java.util.List; +import org.jabref.Globals; +import org.jabref.logic.layout.LayoutFormatterPreferences; public class PreviewPreferences { @@ -49,6 +51,14 @@ public Builder getBuilder() { return new Builder(this); } + public String getCurrentPreviewStyle() { + return getPreviewCycle().get(getPreviewCyclePosition()); + } + + public LayoutFormatterPreferences getLayoutFormatterPreferences() { + return Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader); + } + public static class Builder { private List previewCycle; private int previeCyclePosition; diff --git a/src/test/java/org/jabref/gui/BasePanelTest.java b/src/test/java/org/jabref/gui/BasePanelTest.java new file mode 100644 index 00000000000..33969b7e6e8 --- /dev/null +++ b/src/test/java/org/jabref/gui/BasePanelTest.java @@ -0,0 +1,69 @@ +package org.jabref.gui; + +import javafx.scene.Scene; +import javafx.scene.control.SplitPane; +import javafx.stage.Stage; + +import org.jabref.gui.autocompleter.AutoCompletePreferences; +import org.jabref.gui.entryeditor.EntryEditorPreferences; +import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.gui.keyboard.KeyBindingRepository; +import org.jabref.gui.maintable.MainTablePreferences; +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.entry.BibEntry; +import org.jabref.preferences.PreviewPreferences; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.testfx.api.FxRobot; +import org.testfx.framework.junit5.ApplicationExtension; +import org.testfx.framework.junit5.Start; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.RETURNS_MOCKS; +import static org.mockito.Mockito.mock; + +@ExtendWith(ApplicationExtension.class) +public class BasePanelTest { + + private BasePanel panel; + private BibDatabaseContext bibDatabaseContext; + private BasePanelPreferences preferences; + + @Start + public void onStart(Stage stage) { + JabRefFrame frame = mock(JabRefFrame.class, RETURNS_MOCKS); + ExternalFileTypes externalFileTypes = mock(ExternalFileTypes.class); + bibDatabaseContext = new BibDatabaseContext(); + preferences = new BasePanelPreferences( + mock(MainTablePreferences.class, RETURNS_MOCKS), + mock(AutoCompletePreferences.class, RETURNS_MOCKS), + mock(EntryEditorPreferences.class, RETURNS_MOCKS), + mock(KeyBindingRepository.class, RETURNS_MOCKS), + mock(PreviewPreferences.class, RETURNS_MOCKS), + 0.5 + ); + panel = new BasePanel(frame, preferences, bibDatabaseContext, externalFileTypes); + + stage.setScene(new Scene(panel)); + stage.show(); + } + + @Test + void dividerPositionIsRestoredOnReopenEntryEditor(FxRobot robot) throws Exception { + BibEntry entry = new BibEntry(); + bibDatabaseContext.getDatabase().insertEntry(entry); + + SplitPane splitPane = robot.lookup(".split-pane").query(); + + robot.interact(() -> panel.showAndEdit(entry)); + robot.interact(() -> splitPane.getDividers().get(0).setPosition(0.8)); + robot.sleep(1000); + + robot.interact(() -> panel.closeBottomPane()); + robot.sleep(1000); + robot.interact(() -> panel.showAndEdit(entry)); + + assertEquals(0.8, splitPane.getDividers().get(0).getPosition(), 0.1); + } +} diff --git a/src/test/java/org/jabref/gui/entryeditor/EntryEditorTest.java b/src/test/java/org/jabref/gui/entryeditor/EntryEditorTest.java index 2e8e4746b39..957e036ceb1 100644 --- a/src/test/java/org/jabref/gui/entryeditor/EntryEditorTest.java +++ b/src/test/java/org/jabref/gui/entryeditor/EntryEditorTest.java @@ -8,18 +8,21 @@ import org.jabref.gui.undo.CountingUndoManager; import org.jabref.logic.bibtex.LatexFieldFormatterPreferences; +import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; -import org.jabref.preferences.JabRefPreferences; import org.fxmisc.richtext.CodeArea; -import org.junit.Test; -import org.mockito.Answers; -import org.testfx.framework.junit.ApplicationTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.testfx.api.FxRobot; +import org.testfx.framework.junit5.ApplicationExtension; +import org.testfx.framework.junit5.Start; import static org.mockito.Mockito.mock; -public class EntryEditorTest extends ApplicationTest { +@ExtendWith(ApplicationExtension.class) +public class EntryEditorTest { private Stage stage; private Scene scene; @@ -27,12 +30,11 @@ public class EntryEditorTest extends ApplicationTest { private TabPane pane; private SourceTab sourceTab; - @Override - public void start(Stage stage) throws Exception { + @Start + public void onStart(Stage stage) { area = new CodeArea(); area.appendText("some example\n text to go here\n across a couple of \n lines...."); - JabRefPreferences preferences = mock(JabRefPreferences.class, Answers.RETURNS_DEEP_STUBS); - sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), preferences); + sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), mock(ImportFormatPreferences.class)); pane = new TabPane( new Tab("main area", area), new Tab("other tab", new Label("some text")), @@ -51,22 +53,22 @@ public void start(Stage stage) throws Exception { } @Test - public void switchingFromSourceTabDoesNotThrowException() throws Exception { + void switchingFromSourceTabDoesNotThrowException(FxRobot robot) throws Exception { BibEntry entry = new BibEntry(); entry.setField("test", "testvalue"); // Update source editor - interact(() -> pane.getSelectionModel().select(2)); - interact(() -> sourceTab.bindToEntry(entry)); - clickOn(1200, 500); - interrupt(100); + robot.interact(() -> pane.getSelectionModel().select(2)); + robot.interact(() -> sourceTab.bindToEntry(entry)); + robot.clickOn(1200, 500); + robot.interrupt(100); // Switch to different tab & update entry - interact(() -> pane.getSelectionModel().select(1)); - interact(() -> stage.setWidth(600)); - interact(() -> entry.setField("test", "new value")); + robot.interact(() -> pane.getSelectionModel().select(1)); + robot.interact(() -> stage.setWidth(600)); + robot.interact(() -> entry.setField("test", "new value")); // No exception should be thrown - interrupt(100); + robot.interrupt(100); } } From 09b000b9e97a14531c21f6905e731a799a2b7759 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 2 Jan 2018 00:54:29 +0100 Subject: [PATCH 009/827] Flat design for tab header --- src/main/java/org/jabref/gui/Main.css | 71 +++++++++++++++++++ .../jabref/gui/entryeditor/EntryEditor.css | 21 ------ .../org/jabref/gui/maintable/MainTable.css | 10 +-- 3 files changed, 77 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/jabref/gui/Main.css b/src/main/java/org/jabref/gui/Main.css index 95a63836304..c5b650767b6 100644 --- a/src/main/java/org/jabref/gui/Main.css +++ b/src/main/java/org/jabref/gui/Main.css @@ -48,6 +48,10 @@ */ -fx-active-background: #6A9FCD; + /* + * A dark gray for borders + */ + -fx-border: #868786; } .hyperlink { @@ -121,3 +125,70 @@ .flatButtonNoSpaceTop { -fx-padding: -0.1em 0.5em 0.5em 0.5em; } + +.tab-pane { + -fx-open-tab-animation: NONE; + -fx-close-tab-animation: NONE; +} + +.tab-pane > .tab-header-area > .headers-region > .tab { + -fx-background-insets: 0; + -fx-background-radius: 0; + -fx-background-color: -fx-accented-background; + -fx-border-color: -fx-border; + -fx-border-width: 0.5 0.5 0.5 0.5; + -fx-padding: 0.4em 0.9em 0.4em 0.9em; +} + +.tab-pane > .tab-header-area > .headers-region > .tab .tab-label { + -fx-text-fill: -fx-unimportant; +} + +.tab-pane > .tab-header-area > .headers-region > .tab:selected { + -fx-background-color: -fx-light-background; + -fx-border-color: -fx-active-background; + -fx-border-width: 3 0 0 0; +} + +.tab-pane > .tab-header-area > .headers-region > .tab:selected .tab-label { + -fx-text-fill: black; +} + +.tab-pane:focused > .tab-header-area > .headers-region > .tab:selected .focus-indicator { + -fx-border-width: 0; + -fx-border-insets: 0; + -fx-border-radius: 0; +} + +.tab-pane > .tab-header-area > .tab-header-background { + -fx-background-color: -fx-accented-background; +} + +.tab-pane > .tab-header-area > .headers-region > .tab .glyph-icon { + -glyph-size: 13px; + -fx-text-fill: -fx-unimportant; + -fx-fill: -fx-unimportant; +} + +.tab-pane > .tab-header-area > .headers-region > .tab:selected .glyph-icon { + -fx-text-fill: black; + -fx-fill: black; +} + +.tab-pane > .tab-header-area { + -fx-padding: 0.416667em 5 0.0em 0em; +} + +.table-view { + -fx-background-insets: 0; + -fx-padding: 0; +} + +.table-view:focused { + -fx-background-insets: 0; +} + +.split-pane > .split-pane-divider { + -fx-background-color: -fx-accented-background; + -fx-padding: 0 0.15ex 0 0.15ex; +} diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.css b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.css index 0e66bb6c607..34db97e415b 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.css +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.css @@ -54,27 +54,6 @@ -fx-padding: -0.2em 0.1em 0.1em 0.1em; } -#tabbed { - -fx-open-tab-animation: NONE; - -fx-close-tab-animation: NONE; -} - -#tabbed > .tab-header-area > .tab-header-background { - -fx-background-color: #dadad8; -} - -#tabbed > .tab-header-area > .headers-region > .tab:selected { - -fx-background-color: -fx-outer-border, -fx-inner-border, -fx-light-background; -} - -#tabbed > .tab-header-area .glyph-icon { - -glyph-size: 13px; -} - -#tabbed > .tab-header-area { - -fx-padding: 0.416667em 5 0.0em 0em; -} - .editorPane .glyph-icon { -glyph-size: 16px; } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.css b/src/main/java/org/jabref/gui/maintable/MainTable.css index 651b8376d4a..1bb042ca76d 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.css +++ b/src/main/java/org/jabref/gui/maintable/MainTable.css @@ -1,14 +1,17 @@ .table-view { - + -fx-border-width: 0; + -fx-padding: 0; + -fx-border-insets: 0; + -fx-background-color: -fx-light-background; } .table-view .column-header-background { - -fx-background-color: -fx-control-inner-background; + -fx-background-color: -fx-light-background; } .table-view .column-header, .table-view .filler { - -fx-background-color: -fx-control-inner-background; + -fx-background-color: -fx-light-background; -fx-font-weight: bold; -fx-size: 3em; -fx-border-width: 0 0 1 0; @@ -45,4 +48,3 @@ -fx-padding: 0; -fx-alignment: baseline-center; } - From d7d00a8f5d81eb54bd920eff5762d107e052f638 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 2 Jan 2018 23:04:39 +0100 Subject: [PATCH 010/827] Add dummy context menu to row --- src/main/java/org/jabref/gui/JabRefFrame.java | 2 +- .../org/jabref/gui/maintable/MainTable.java | 3 ++- .../{menus => maintable}/RightClickMenu.java | 15 ++++++++++++++- .../gui/util/ViewModelTableRowFactory.java | 19 +++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) rename src/main/java/org/jabref/gui/{menus => maintable}/RightClickMenu.java (96%) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 732c43aadbf..06c06d161e3 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -108,9 +108,9 @@ import org.jabref.gui.journals.ManageJournalsAction; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.keyboard.KeyBindingAction; +import org.jabref.gui.maintable.RightClickMenu; import org.jabref.gui.menus.ChangeEntryTypeMenu; import org.jabref.gui.menus.FileHistoryMenu; -import org.jabref.gui.menus.RightClickMenu; import org.jabref.gui.openoffice.OpenOfficePanel; import org.jabref.gui.openoffice.OpenOfficeSidePanel; import org.jabref.gui.preftabs.PreferencesDialog; diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index dcaaaf63405..6930debf1a5 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -82,7 +82,8 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, if (event.getClickCount() == 2) { panel.showAndEdit(entry.getEntry()); } - })); + }) + .withContextMenu(RightClickMenu::create)); if (preferences.resizeColumnsToFit()) { this.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); } diff --git a/src/main/java/org/jabref/gui/menus/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java similarity index 96% rename from src/main/java/org/jabref/gui/menus/RightClickMenu.java rename to src/main/java/org/jabref/gui/maintable/RightClickMenu.java index f2dc69df8db..88b80af064f 100644 --- a/src/main/java/org/jabref/gui/menus/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -1,4 +1,4 @@ -package org.jabref.gui.menus; +package org.jabref.gui.maintable; import java.awt.event.ActionEvent; import java.util.Arrays; @@ -16,6 +16,8 @@ import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; +import javafx.scene.control.ContextMenu; + import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.EntryMarker; @@ -25,6 +27,7 @@ import org.jabref.gui.copyfiles.CopyFilesAction; import org.jabref.gui.filelist.FileListTableModel; import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.gui.menus.ChangeEntryTypeMenu; import org.jabref.gui.mergeentries.FetchAndMergeEntry; import org.jabref.gui.specialfields.SpecialFieldMenuAction; import org.jabref.gui.specialfields.SpecialFieldValueViewModel; @@ -318,4 +321,14 @@ public void actionPerformed(ActionEvent e) { } } + public static ContextMenu create(BibEntryTableViewModel entry) { + ContextMenu contextMenu = new ContextMenu(); + + javafx.scene.control.MenuItem copy = new javafx.scene.control.MenuItem(); + copy.setText(Localization.lang("Copy")); + copy.setGraphic(IconTheme.JabRefIcons.COPY.getGraphicNode()); + contextMenu.getItems().add(copy); + + return contextMenu; + } } diff --git a/src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java b/src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java index 4f43b5e072e..3bd35d101fb 100644 --- a/src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java +++ b/src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java @@ -1,7 +1,9 @@ package org.jabref.gui.util; import java.util.function.BiConsumer; +import java.util.function.Function; +import javafx.scene.control.ContextMenu; import javafx.scene.control.TableRow; import javafx.scene.control.TableView; import javafx.scene.control.TreeTableCell; @@ -16,12 +18,18 @@ public class ViewModelTableRowFactory implements Callback, TableRow> { private BiConsumer onMouseClickedEvent; + private Function contextMenuFactory; public ViewModelTableRowFactory withOnMouseClickedEvent(BiConsumer onMouseClickedEvent) { this.onMouseClickedEvent = onMouseClickedEvent; return this; } + public ViewModelTableRowFactory withContextMenu(Function contextMenuFactory) { + this.contextMenuFactory = contextMenuFactory; + return this; + } + @Override public TableRow call(TableView tableView) { TableRow row = new TableRow<>(); @@ -34,6 +42,17 @@ public TableRow call(TableView tableView) { }); } + if (contextMenuFactory != null) { + // We only create the context menu when really necessary + row.setOnContextMenuRequested(event -> { + if (!row.isEmpty()) { + row.setContextMenu(contextMenuFactory.apply(row.getItem())); + row.getContextMenu().show(row, event.getScreenX(), event.getScreenY()); + } + event.consume(); + }); + } + return row; } } From 7f6c9243caa63887b8499c8f5707e8f0b51a43cb Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 3 Jan 2018 20:57:03 +0100 Subject: [PATCH 011/827] Improve hover and selected row style --- src/main/java/org/jabref/gui/Main.css | 23 +++++++++++++++++++ .../java/org/jabref/gui/groups/GroupTree.css | 14 ----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/jabref/gui/Main.css b/src/main/java/org/jabref/gui/Main.css index c5b650767b6..13c2785c77d 100644 --- a/src/main/java/org/jabref/gui/Main.css +++ b/src/main/java/org/jabref/gui/Main.css @@ -192,3 +192,26 @@ -fx-background-color: -fx-accented-background; -fx-padding: 0 0.15ex 0 0.15ex; } + +.table-row-cell:hover, +.tree-table-row-cell:hover { + -fx-background-color: lightgrey; +} + +.table-row-cell:selected, +.tree-table-row-cell:selected { + -fx-background-color: #6A9FCD; + -fx-text-fill: white; + -fx-fill: white; +} + +.tree-table-row-cell:selected > .tree-table-cell > .glyph-icon { + -fx-fill: white; + -fx-text-fill: white; +} + +.table-view > .virtual-flow > .clipped-container > .sheet > .table-row-cell .table-cell:selected, +.tree-table-view > .virtual-flow > .clipped-container > .sheet > .tree-table-row-cell .tree-table-cell:selected { + -fx-border-color: transparent; + -fx-background-insets: 0; +} diff --git a/src/main/java/org/jabref/gui/groups/GroupTree.css b/src/main/java/org/jabref/gui/groups/GroupTree.css index 22708ffeb20..ec41e9ac5a1 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTree.css +++ b/src/main/java/org/jabref/gui/groups/GroupTree.css @@ -76,20 +76,6 @@ -fx-padding: 0.45em 0.2em 0.45em 0.2em; } -.tree-table-row-cell:hover { - -fx-background-color: lightgrey; -} - -.tree-table-row-cell:selected { - -fx-background-color: #6A9FCD; - -fx-text-fill: white; - -fx-fill: white; -} - -.tree-table-row-cell:selected > .tree-table-cell > .icon { - -fx-fill: white; -} - .tree-table-row-cell:selected > .tree-table-cell > .tree-disclosure-node > .arrow { -fx-background-color: white; } From dc41f2959b4597cab6c05484a52aeeebe5c21156 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 3 Jan 2018 21:05:35 +0100 Subject: [PATCH 012/827] Further improve hover and selected row style --- src/main/java/org/jabref/gui/Main.css | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/org/jabref/gui/Main.css b/src/main/java/org/jabref/gui/Main.css index 13c2785c77d..cf74e532701 100644 --- a/src/main/java/org/jabref/gui/Main.css +++ b/src/main/java/org/jabref/gui/Main.css @@ -215,3 +215,25 @@ -fx-border-color: transparent; -fx-background-insets: 0; } + +/* Selected rows */ +.list-view:focused > .virtual-flow > .clipped-container > .sheet > .list-cell:filled:selected, +.tree-view:focused > .virtual-flow > .clipped-container > .sheet > .tree-cell:filled:selected, +.table-view:focused > .virtual-flow > .clipped-container > .sheet > .table-row-cell:filled:selected, +.tree-table-view:focused > .virtual-flow > .clipped-container > .sheet > .tree-table-row-cell:filled:selected, +.table-view:focused > .virtual-flow > .clipped-container > .sheet > .table-row-cell .table-cell:selected, +.tree-table-view:focused > .virtual-flow > .clipped-container > .sheet > .tree-table-row-cell .tree-table-cell:selected { + -fx-background: -fx-selection-bar; + -fx-table-cell-border-color: transparent; +} + +/* Selected when control is not focused */ +.list-cell:filled:selected, +.tree-cell:filled:selected, +.table-row-cell:filled:selected, +.tree-table-row-cell:filled:selected, +.table-row-cell:filled > .table-cell:selected, +.tree-table-row-cell:filled > .tree-table-cell:selected { + -fx-background: -fx-selection-bar; + -fx-table-cell-border-color: transparent; +} From 38f0d15a046f742e0f556c255e95f58fffcf221a Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 4 Jan 2018 16:08:30 +0100 Subject: [PATCH 013/827] Restore column width (except when "fit to width" option is enabled) --- src/main/java/org/jabref/gui/JabRefFrame.java | 3 +- .../gui/importer/ImportInspectionDialog.java | 4 +- .../jabref/gui/maintable/ColumnFactory.java | 30 ++++--- .../gui/maintable/ColumnPreferences.java | 42 +++++++++- .../org/jabref/gui/maintable/MainTable.java | 36 -------- .../SmartConstraintedResizePolicy.java | 23 +++++ .../jabref/gui/preftabs/TableColumnsTab.java | 84 +++++++++---------- .../jabref/gui/search/SearchResultFrame.java | 8 +- .../jabref/model/entry/BibtexSingleField.java | 9 +- .../model/entry/InternalBibtexFields.java | 2 +- 10 files changed, 135 insertions(+), 106 deletions(-) create mode 100644 src/main/java/org/jabref/gui/maintable/SmartConstraintedResizePolicy.java diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 70f113615be..0255e88edfd 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -1503,8 +1503,7 @@ public void setupAllTables() { // Update tables: if (bf.getDatabase() != null) { - bf.setupMainPanel(); - + DefaultTaskExecutor.runInJavaFXThread(bf::setupMainPanel); } } } diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index 5d70a3cf0af..d87b66da8f5 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -582,8 +582,8 @@ private void setWidths() { } for (int i = 0; i < INSPECTION_FIELDS.size(); i++) { - int width = InternalBibtexFields.getFieldLength(INSPECTION_FIELDS.get(i)); - glTable.getColumnModel().getColumn(i + PAD).setPreferredWidth(width); + Double width = InternalBibtexFields.getFieldLength(INSPECTION_FIELDS.get(i)); + glTable.getColumnModel().getColumn(i + PAD).setPreferredWidth(width.intValue()); } } diff --git a/src/main/java/org/jabref/gui/maintable/ColumnFactory.java b/src/main/java/org/jabref/gui/maintable/ColumnFactory.java index 2c50844b8b9..93515a85f9a 100644 --- a/src/main/java/org/jabref/gui/maintable/ColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/ColumnFactory.java @@ -10,6 +10,7 @@ import javafx.scene.Node; import javafx.scene.control.TableColumn; +import org.jabref.gui.GUIGlobals; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefIcon; import org.jabref.gui.externalfiletype.ExternalFileType; @@ -87,7 +88,9 @@ public ColumnFactory(BibDatabase database, ColumnPreferences preferences, Extern // Stored column name will be used as header // There might be more than one field to display, e.g., "author/editor" or "date/year" - so split String[] fields = columnName.split(FieldName.FIELD_SEPARATOR); - columns.add(new StringTableColumn(columnName, Arrays.asList(fields), database)); + StringTableColumn column = new StringTableColumn(columnName, Arrays.asList(fields), database); + column.setPrefWidth(preferences.getPrefColumnWidth(columnName)); + columns.add(column); } return columns; } @@ -96,8 +99,13 @@ private TableColumn TableColumn> column = new TableColumn<>(); column.setGraphic(new SpecialFieldViewModel(specialField).getIcon().getGraphicNode()); column.getStyleClass().add(STYLE_ICON); - column.setMinWidth(30); - column.setMaxWidth(30); + if (specialField == SpecialField.RANKING) { + column.setMinWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); + column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); + } else { + column.setMinWidth(GUIGlobals.WIDTH_ICON_COL); + column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL); + } column.setCellValueFactory(cellData -> cellData.getValue().getSpecialField(specialField)); column.setCellFactory( new ValueTableCellFactory>() @@ -110,8 +118,8 @@ private TableColumn> createFileColumn() TableColumn> column = new TableColumn<>(); column.setGraphic(IconTheme.JabRefIcons.FILE.getGraphicNode()); column.getStyleClass().add(STYLE_ICON); - column.setMinWidth(30); - column.setMaxWidth(30); + column.setMinWidth(GUIGlobals.WIDTH_ICON_COL); + column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> cellData.getValue().getLinkedFiles()); column.setCellFactory( new ValueTableCellFactory>() @@ -126,8 +134,8 @@ private TableColumn createIconColumn(JabRefIcon TableColumn column = new TableColumn<>(); column.setGraphic(icon.getGraphicNode()); column.getStyleClass().add(STYLE_ICON); - column.setMinWidth(30); - column.setMaxWidth(30); + column.setMinWidth(GUIGlobals.WIDTH_ICON_COL); + column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> EasyBind.monadic(cellData.getValue().getField(firstField)).orElse(cellData.getValue().getField(secondField))); column.setCellFactory( new ValueTableCellFactory() @@ -139,8 +147,8 @@ private TableColumn createIconColumn(JabRefIcon TableColumn column = new TableColumn<>(); column.setGraphic(icon.getGraphicNode()); column.getStyleClass().add(STYLE_ICON); - column.setMinWidth(30); - column.setMaxWidth(30); + column.setMinWidth(GUIGlobals.WIDTH_ICON_COL); + column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> cellData.getValue().getField(field)); column.setCellFactory( new ValueTableCellFactory() @@ -160,8 +168,8 @@ private TableColumn> createExtraFileCol .map(ExternalFileType::getIcon).orElse(IconTheme.JabRefIcons.FILE) .getGraphicNode()); column.getStyleClass().add(STYLE_ICON); - column.setMinWidth(30); - column.setMaxWidth(30); + column.setMinWidth(GUIGlobals.WIDTH_ICON_COL); + column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> cellData.getValue().getLinkedFiles()); column.setCellFactory( new ValueTableCellFactory>() diff --git a/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java b/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java index 40ad69e7453..e83048bc4a3 100644 --- a/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java +++ b/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java @@ -3,12 +3,21 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.stream.Collectors; +import org.jabref.model.entry.BibtexSingleField; import org.jabref.model.entry.specialfields.SpecialField; import org.jabref.preferences.JabRefPreferences; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + public class ColumnPreferences { + private static final Log LOGGER = LogFactory.getLog(ColumnPreferences.class); + private final boolean showFileColumn; private final boolean showUrlColumn; private final boolean preferDoiOverUrl; @@ -16,8 +25,9 @@ public class ColumnPreferences { private final List normalColumns; private final List specialFieldColumns; private final List extraFileColumns; + private final Map columnWidths; - public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean preferDoiOverUrl, boolean showEprintColumn, List normalColumns, List specialFieldColumns, List extraFileColumns) { + public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean preferDoiOverUrl, boolean showEprintColumn, List normalColumns, List specialFieldColumns, List extraFileColumns, Map columnWidths) { this.showFileColumn = showFileColumn; this.showUrlColumn = showUrlColumn; this.preferDoiOverUrl = preferDoiOverUrl; @@ -25,6 +35,7 @@ public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean this.normalColumns = normalColumns; this.specialFieldColumns = specialFieldColumns; this.extraFileColumns = extraFileColumns; + this.columnWidths = columnWidths; } public static ColumnPreferences from(JabRefPreferences preferences) { @@ -35,10 +46,33 @@ public static ColumnPreferences from(JabRefPreferences preferences) { preferences.getBoolean(JabRefPreferences.ARXIV_COLUMN), preferences.getStringList(JabRefPreferences.COLUMN_NAMES), createSpecialFieldColumns(preferences), - createExtraFileColumns(preferences) + createExtraFileColumns(preferences), + createColumnWidths(preferences) ); } + private static Map createColumnWidths(JabRefPreferences preferences) { + List columns = preferences.getStringList(JabRefPreferences.COLUMN_NAMES); + List widths = preferences + .getStringList(JabRefPreferences.COLUMN_WIDTHS) + .stream() + .map(string -> { + try { + return Double.parseDouble(string); + } catch (NumberFormatException e) { + LOGGER.error("Exception while parsing column widths. Choosing default.", e); + return BibtexSingleField.DEFAULT_FIELD_LENGTH; + } + }) + .collect(Collectors.toList()); + + Map map = new TreeMap<>(); + for (int i = 0; i < columns.size(); i++) { + map.put(columns.get(i), widths.get(i)); + } + return map; + } + private static List createExtraFileColumns(JabRefPreferences preferences) { if (preferences.getBoolean(JabRefPreferences.EXTRA_FILE_COLUMNS)) { return preferences.getStringList(JabRefPreferences.LIST_OF_FILE_COLUMNS); @@ -104,4 +138,8 @@ public List getSpecialFieldColumns() { public List getNormalColumns() { return normalColumns; } + + public double getPrefColumnWidth(String columnName) { + return columnWidths.getOrDefault(columnName, BibtexSingleField.DEFAULT_FIELD_LENGTH); + } } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 6930debf1a5..a5ab554b249 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -286,42 +286,6 @@ else if (column == 0) { return renderer; } - - // TODO: Set column widths - private void setWidths() { - // Setting column widths: - int ncWidth = Globals.prefs.getInt(JabRefPreferences.NUMBER_COL_WIDTH); - List widthsFromPreferences = Globals.prefs.getStringList(JabRefPreferences.COLUMN_WIDTHS); - TableColumnModel cm = getColumnModel(); - cm.getColumn(0).setPreferredWidth(ncWidth); - for (int i = 1; i < cm.getColumnCount(); i++) { - MainTableColumn mainTableColumn = tableFormat.getTableColumn(cm.getColumn(i).getModelIndex()); - if (SpecialField.RANKING.getFieldName().equals(mainTableColumn.getColumnName())) { - cm.getColumn(i).setPreferredWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); - cm.getColumn(i).setMinWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); - cm.getColumn(i).setMaxWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); - } else if (mainTableColumn.isIconColumn()) { - cm.getColumn(i).setPreferredWidth(GUIGlobals.WIDTH_ICON_COL); - cm.getColumn(i).setMinWidth(GUIGlobals.WIDTH_ICON_COL); - cm.getColumn(i).setMaxWidth(GUIGlobals.WIDTH_ICON_COL); - } else { - List allColumns = Globals.prefs.getStringList(JabRefPreferences.COLUMN_NAMES); - // find index of current mainTableColumn in allColumns - for (int j = 0; j < allColumns.size(); j++) { - if (allColumns.get(j).equalsIgnoreCase(mainTableColumn.getDisplayName())) { - try { - // set preferred width by using found index j in the width array - cm.getColumn(i).setPreferredWidth(Integer.parseInt(widthsFromPreferences.get(j))); - } catch (NumberFormatException e) { - LOGGER.info("Exception while setting column widths. Choosing default.", e); - cm.getColumn(i).setPreferredWidth(BibtexSingleField.DEFAULT_FIELD_LENGTH); - } - break; - } - } - } - } - } */ public BibEntry getEntryAt(int row) { diff --git a/src/main/java/org/jabref/gui/maintable/SmartConstraintedResizePolicy.java b/src/main/java/org/jabref/gui/maintable/SmartConstraintedResizePolicy.java new file mode 100644 index 00000000000..5b173dd03cb --- /dev/null +++ b/src/main/java/org/jabref/gui/maintable/SmartConstraintedResizePolicy.java @@ -0,0 +1,23 @@ +package org.jabref.gui.maintable; + +import javafx.scene.control.TableView; +import javafx.util.Callback; + +public class SmartConstraintedResizePolicy implements Callback { + private boolean isFirstRun = true; + private Callback basePolicy = TableView.CONSTRAINED_RESIZE_POLICY; + + @Override + public Boolean call(TableView.ResizeFeatures prop) { + Boolean result = basePolicy.call(prop); + + // The CONSTRAINED_RESIZE_POLICY resizes all columns to the same width + // We want to resize them to (almost) their preferred width + if (isFirstRun) { + + } + + isFirstRun = isFirstRun && !result; + return result; + } +} diff --git a/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java b/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java index 525b223b06e..627220033bc 100644 --- a/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java +++ b/src/main/java/org/jabref/gui/preftabs/TableColumnsTab.java @@ -93,47 +93,6 @@ class TableColumnsTab extends JPanel implements PrefsTab { private boolean oldWriteSpecialFields; - /*** end: special fields ***/ - - static class TableRow { - - private String name; - private int length; - - - public TableRow() { - name = ""; - length = BibtexSingleField.DEFAULT_FIELD_LENGTH; - } - - public TableRow(String name) { - this.name = name; - length = BibtexSingleField.DEFAULT_FIELD_LENGTH; - } - - public TableRow(String name, int length) { - this.name = name; - this.length = length; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getLength() { - return length; - } - - public void setLength(int length) { - this.length = length; - } - } - - /** * Customization of external program paths. * @@ -174,7 +133,7 @@ public Object getValueAt(int row, int column) { if (column == 0) { return rowContent.getName(); } else { - return rowContent.getLength() > 0 ? Integer.toString(rowContent.getLength()) : ""; + return rowContent.getLength() > 0 ? Double.toString(rowContent.getLength()) : ""; } } @@ -373,6 +332,45 @@ public void setValueAt(Object value, int row, int col) { add(pan, BorderLayout.CENTER); } + /*** end: special fields ***/ + + static class TableRow { + + private String name; + private double length; + + public TableRow() { + name = ""; + length = BibtexSingleField.DEFAULT_FIELD_LENGTH; + } + + public TableRow(String name) { + this.name = name; + length = BibtexSingleField.DEFAULT_FIELD_LENGTH; + } + + public TableRow(String name, int length) { + this.name = name; + this.length = length; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getLength() { + return length; + } + + public void setLength(int length) { + this.length = length; + } + } + @Override public void setValues() { fileColumn.setSelected(prefs.getBoolean(JabRefPreferences.FILE_COLUMN)); @@ -770,12 +768,10 @@ public void storeSettings() { // Then we make arrays List names = new ArrayList<>(tableRows.size()); List widths = new ArrayList<>(tableRows.size()); - List nWidths = new ArrayList<>(tableRows.size()); prefs.putInt(JabRefPreferences.NUMBER_COL_WIDTH, ncWidth); for (TableRow tr : tableRows) { names.add(tr.getName().toLowerCase(Locale.ROOT)); - nWidths.add(tr.getLength()); widths.add(String.valueOf(tr.getLength())); } diff --git a/src/main/java/org/jabref/gui/search/SearchResultFrame.java b/src/main/java/org/jabref/gui/search/SearchResultFrame.java index fb1683da614..a4b31d17bd5 100644 --- a/src/main/java/org/jabref/gui/search/SearchResultFrame.java +++ b/src/main/java/org/jabref/gui/search/SearchResultFrame.java @@ -362,13 +362,13 @@ private void setWidths() { cm.getColumn(i).setMaxWidth(GUIGlobals.WIDTH_ICON_COL); break; case DATABASE_COL: { - int width = InternalBibtexFields.getFieldLength(FieldName.AUTHOR); - cm.getColumn(i).setPreferredWidth(width); + Double width = InternalBibtexFields.getFieldLength(FieldName.AUTHOR); + cm.getColumn(i).setPreferredWidth(width.intValue()); break; } default: { - int width = InternalBibtexFields.getFieldLength(FIELDS[i - PAD]); - cm.getColumn(i).setPreferredWidth(width); + Double width = InternalBibtexFields.getFieldLength(FIELDS[i - PAD]); + cm.getColumn(i).setPreferredWidth(width.intValue()); break; } } diff --git a/src/main/java/org/jabref/model/entry/BibtexSingleField.java b/src/main/java/org/jabref/model/entry/BibtexSingleField.java index 5c1f8776e93..14722ee9579 100644 --- a/src/main/java/org/jabref/model/entry/BibtexSingleField.java +++ b/src/main/java/org/jabref/model/entry/BibtexSingleField.java @@ -8,7 +8,8 @@ */ public class BibtexSingleField { - public static final int DEFAULT_FIELD_LENGTH = 100; + // TODO: This constant should be moved to the gui package, probably to ColumnFactory + public static final double DEFAULT_FIELD_LENGTH = 100; private enum Flag { STANDARD, @@ -24,7 +25,7 @@ private enum Flag { // default is: not standard, public, displayable and writable private final Set flags = EnumSet.of(Flag.DISPLAYABLE, Flag.WRITEABLE); - private final int length; + private final double length; // properties contains a set of FieldProperty to e.g. tell the EntryEditor to add a specific // function to this field, to format names, or to control the integrity checks. @@ -38,7 +39,7 @@ public BibtexSingleField(String fieldName, boolean pStandard) { this(fieldName, pStandard, DEFAULT_FIELD_LENGTH); } - public BibtexSingleField(String fieldName, boolean pStandard, int pLength) { + public BibtexSingleField(String fieldName, boolean pStandard, double pLength) { name = fieldName; setFlag(pStandard, Flag.STANDARD); length = pLength; @@ -105,7 +106,7 @@ public Set getProperties() { /** * @return The maximum (expected) length of the field value; not the length of the field name */ - public int getLength() { + public double getLength() { return this.length; } diff --git a/src/main/java/org/jabref/model/entry/InternalBibtexFields.java b/src/main/java/org/jabref/model/entry/InternalBibtexFields.java index 3cf4886c36f..7b13f6f33c0 100644 --- a/src/main/java/org/jabref/model/entry/InternalBibtexFields.java +++ b/src/main/java/org/jabref/model/entry/InternalBibtexFields.java @@ -402,7 +402,7 @@ private static Optional getField(String name) { return Optional.empty(); } - public static int getFieldLength(String name) { + public static Double getFieldLength(String name) { return InternalBibtexFields.getField(name) .map(BibtexSingleField::getLength) .orElse(BibtexSingleField.DEFAULT_FIELD_LENGTH); From 7e21bc415e4be76ac7af57066ca86fe3a0d39851 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 5 Jan 2018 22:49:13 +0100 Subject: [PATCH 014/827] Update entry editor and preview --- src/main/java/org/jabref/gui/BasePanel.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 64cfa4ff936..2cc7f8cc676 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1219,6 +1219,16 @@ private void createMainTable() { // Add the listener that binds selection to state manager (TODO: should be replaced by proper JavaFX binding as soon as table is implemented in JavaFX) mainTable.addSelectionListener(listEvent -> Globals.stateManager.setSelectedEntries(mainTable.getSelectedEntries())); + // Update entry editor and preview according to selected entries + mainTable.addSelectionListener(event -> + mainTable.getSelectedEntries().stream() + .findFirst() + .ifPresent(entry -> { + preview.setEntry(entry); + entryEditor.setEntry(entry); + }) + ); + // TODO: Register these actions globally /* String clearSearch = "clearSearch"; From 667f1c4ad59eab247fc6ffe4fc226301bf8c9b41 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 5 Jan 2018 23:54:23 +0100 Subject: [PATCH 015/827] Filter by groups and search --- src/main/java/org/jabref/gui/BasePanel.java | 13 +- .../java/org/jabref/gui/StateManager.java | 15 ++ .../org/jabref/gui/groups/GroupSidePane.java | 52 ---- .../org/jabref/gui/groups/GroupingWorker.java | 42 --- .../org/jabref/gui/maintable/MainTable.java | 14 +- .../gui/maintable/MainTableDataModel.java | 254 +++--------------- .../jabref/gui/search/GlobalSearchBar.java | 18 +- .../org/jabref/gui/search/SearchWorker.java | 48 ---- 8 files changed, 70 insertions(+), 386 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/groups/GroupingWorker.java diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 2cc7f8cc676..235c8c1dfbe 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1209,7 +1209,6 @@ public void updateTableFont() { } private void createMainTable() { - bibDatabaseContext.getDatabase().registerListener(tableModel.getListSynchronizer()); bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.getInstance()); mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext.getDatabase(), preferences.getTablePreferences(), externalFileTypes); @@ -1327,8 +1326,8 @@ public void setupMainPanel() { splitPane.setOrientation(Orientation.VERTICAL); adjustSplitter(); // restore last splitting state (before mainTable is created as creation affects the stored size of the entryEditors) - // check whether a mainTable already existed and a floatSearch was active - boolean floatSearchActive = (mainTable != null) && (this.tableModel.getSearchState() == MainTableDataModel.DisplayOption.FLOAT); + // TODO: check whether a mainTable already existed and a floatSearch was active + //boolean floatSearchActive = (mainTable != null) && (this.tableModel.getSearchState() == MainTableDataModel.DisplayOption.FLOAT); createMainTable(); @@ -1347,11 +1346,11 @@ public void setupMainPanel() { setupAutoCompletion(); - // restore floating search result + // TODO: restore floating search result // (needed if preferences have been changed which causes a recreation of the main table) - if (floatSearchActive) { - mainTable.showFloatSearch(); - } + //if (floatSearchActive) { + // mainTable.showFloatSearch(); + //} // Saves the divider position as soon as it changes // We need to keep a reference to the subscription, otherwise the binding gets garbage collected dividerPositionSubscription = EasyBind.monadic(Bindings.valueAt(splitPane.getDividers(), 0)) diff --git a/src/main/java/org/jabref/gui/StateManager.java b/src/main/java/org/jabref/gui/StateManager.java index c09a7024372..6f5f79cb41e 100644 --- a/src/main/java/org/jabref/gui/StateManager.java +++ b/src/main/java/org/jabref/gui/StateManager.java @@ -14,6 +14,7 @@ import javafx.collections.ObservableList; import javafx.collections.ObservableMap; +import org.jabref.logic.search.SearchQuery; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.groups.GroupTreeNode; @@ -37,6 +38,12 @@ public class StateManager { private final ObservableList selectedEntries = FXCollections.observableArrayList(); private final ObservableMap> selectedGroups = FXCollections.observableHashMap(); + private final ObjectProperty> activeSearchQuery = new SimpleObjectProperty<>(Optional.empty()); + + public ObjectProperty> activeSearchQueryProperty() { + return activeSearchQuery; + } + public StateManager() { MonadicBinding currentDatabase = EasyBind.map(activeDatabase, database -> database.orElse(null)); activeGroups.bind(Bindings.valueAt(selectedGroups, currentDatabase)); @@ -80,4 +87,12 @@ public List getEntriesInCurrentDatabase() { return OptionalUtil.flatMap(activeDatabase.get(), BibDatabaseContext::getEntries) .collect(Collectors.toList()); } + + public void clearSearchQuery() { + activeSearchQuery.setValue(Optional.empty()); + } + + public void setSearchQuery(SearchQuery searchQuery) { + activeSearchQuery.setValue(Optional.of(searchQuery)); + } } diff --git a/src/main/java/org/jabref/gui/groups/GroupSidePane.java b/src/main/java/org/jabref/gui/groups/GroupSidePane.java index 448e1dc1030..dffa6529d2f 100644 --- a/src/main/java/org/jabref/gui/groups/GroupSidePane.java +++ b/src/main/java/org/jabref/gui/groups/GroupSidePane.java @@ -1,8 +1,5 @@ package org.jabref.gui.groups; -import java.util.Collections; -import java.util.List; - import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; @@ -16,18 +13,9 @@ import org.jabref.gui.SidePaneManager; import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.gui.maintable.MainTableDataModel; -import org.jabref.logic.groups.DefaultGroupsFactory; import org.jabref.logic.l10n.Localization; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.event.FieldChangedEvent; -import org.jabref.model.groups.GroupTreeNode; -import org.jabref.model.search.matchers.MatcherSet; -import org.jabref.model.search.matchers.MatcherSets; import org.jabref.preferences.JabRefPreferences; -import com.google.common.eventbus.Subscribe; - /** * The groups side pane. * This class is just a Swing wrapper around the JavaFX implementation {@link GroupTreeView}. @@ -44,18 +32,6 @@ public class GroupSidePane extends SidePaneComponent { public GroupSidePane(JabRefFrame frame, SidePaneManager manager) { super(manager, IconTheme.JabRefIcons.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups")); - Globals.stateManager.activeGroupProperty() - .addListener((observable, oldValue, newValue) -> updateShownEntriesAccordingToSelectedGroups(newValue)); - - // register the panel the current active context - Globals.stateManager.activeDatabaseProperty() - .addListener((observable, oldValue, newValue) -> { - newValue.ifPresent(databaseContext -> - databaseContext.getDatabase().registerListener(this)); - oldValue.ifPresent(databaseContext -> - databaseContext.getDatabase().unregisterListener(this)); - }); - toggleAction = new ToggleAction(Localization.menuTitle("Toggle groups interface"), Localization.lang("Toggle groups interface"), Globals.getKeyPrefs().getKey(KeyBinding.TOGGLE_GROUPS_INTERFACE), @@ -75,31 +51,6 @@ public GroupSidePane(JabRefFrame frame, SidePaneManager manager) { }); } - @Subscribe - public synchronized void listen(FieldChangedEvent event) { - if (FieldName.GROUPS.equals(event.getFieldName())) { - updateShownEntriesAccordingToSelectedGroups(Globals.stateManager.activeGroupProperty()); - } - } - - private void updateShownEntriesAccordingToSelectedGroups(List selectedGroups) { - if ((selectedGroups == null) || selectedGroups.isEmpty()) { - // No selected group, show all entries - selectedGroups = Collections.singletonList(new GroupTreeNode(DefaultGroupsFactory.getAllEntriesGroup())); - } - - final MatcherSet searchRules = MatcherSets.build( - Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS) ? MatcherSets.MatcherType.AND : MatcherSets.MatcherType.OR); - - for (GroupTreeNode node : selectedGroups) { - searchRules.addRule(node.getSearchMatcher()); - } - - GroupingWorker worker = new GroupingWorker(frame, panel); - worker.run(searchRules); - worker.update(); - } - @Override public void componentOpening() { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE, Boolean.TRUE); @@ -112,9 +63,6 @@ public int getRescalingWeight() { @Override public void componentClosing() { - if (panel != null) { // panel may be null if no file is open any more - panel.getMainTable().getTableModel().updateGroupingState(MainTableDataModel.DisplayOption.DISABLED); - } getToggleAction().setSelected(false); Globals.prefs.putBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE, Boolean.FALSE); } diff --git a/src/main/java/org/jabref/gui/groups/GroupingWorker.java b/src/main/java/org/jabref/gui/groups/GroupingWorker.java deleted file mode 100644 index 6ce158e0fba..00000000000 --- a/src/main/java/org/jabref/gui/groups/GroupingWorker.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.jabref.gui.groups; - -import org.jabref.Globals; -import org.jabref.gui.BasePanel; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.maintable.MainTableDataModel; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.search.SearchMatcher; -import org.jabref.preferences.JabRefPreferences; - -class GroupingWorker { - - private final JabRefFrame frame; - private final BasePanel panel; - - public GroupingWorker(JabRefFrame frame, BasePanel panel) { - this.frame = frame; - this.panel = panel; - } - - public void run(SearchMatcher matcher) { - for (BibEntry entry : panel.getDatabase().getEntries()) { - boolean hit = matcher.isMatch(entry); - entry.setGroupHit(hit); - } - } - - public void update() { - // Show the result in the chosen way: - if (Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)) { - panel.getMainTable().getTableModel().updateGroupingState(MainTableDataModel.DisplayOption.FLOAT); - } else { - panel.getMainTable().getTableModel().updateGroupingState(MainTableDataModel.DisplayOption.FILTER); - } - panel.getMainTable().getTableModel().updateSortOrder(); - panel.getMainTable().getTableModel().updateGroupFilter(); - panel.getMainTable().scrollTo(0); - - frame.output(Localization.lang("Updated group selection") + "."); - } -} diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index a5ab554b249..350aa95c33b 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -88,7 +88,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, this.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); } this.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); - this.setItems(model.getTableRows()); + this.setItems(model.getEntriesFiltered()); // TODO: Cannot add focus listener as it is expecting an swing component //addFocusListener(Globals.getFocusListener()); @@ -289,7 +289,7 @@ else if (column == 0) { */ public BibEntry getEntryAt(int row) { - return model.getTableRows().get(row).getEntry(); + return model.getEntriesFiltered().get(row).getEntry(); } public List getSelectedEntries() { @@ -423,7 +423,7 @@ private CellRendererMode getCellStatus(int row, int col, boolean checkResolved) */ public Optional findEntry(BibEntry entry) { - return model.getTableRows().stream() + return model.getEntriesFiltered().stream() .filter(viewModel -> viewModel.getEntry().equals(entry)) .findFirst(); } @@ -453,18 +453,12 @@ private int isMarked(int row) { private Optional getBibEntry(int row) { try { - return Optional.of(model.getTableRows().get(row).getEntry()); + return Optional.of(model.getEntriesFiltered().get(row).getEntry()); } catch (IndexOutOfBoundsException e) { return Optional.empty(); } } - public void showFloatSearch() { - this.getTableModel().updateSearchState(MainTableDataModel.DisplayOption.FLOAT); - - scrollTo(0); - } - /** * Repaints the table with the most recent font configuration */ diff --git a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java index b2696d6d04f..ebb5aa92132 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java @@ -1,247 +1,67 @@ package org.jabref.gui.maintable; -import java.util.Arrays; -import java.util.Comparator; import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; +import java.util.Optional; -import javafx.collections.FXCollections; +import javafx.beans.binding.Bindings; import javafx.collections.ObservableList; +import javafx.collections.transformation.FilteredList; -import org.jabref.gui.groups.GroupMatcher; -import org.jabref.gui.search.HitOrMissComparator; -import org.jabref.gui.search.matchers.EverythingMatcher; -import org.jabref.gui.search.matchers.SearchMatcher; -import org.jabref.gui.util.comparator.IsMarkedComparator; +import org.jabref.Globals; +import org.jabref.gui.util.BindingsHelper; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; - -import ca.odell.glazedlists.BasicEventList; -import ca.odell.glazedlists.EventList; -import ca.odell.glazedlists.FilterList; -import ca.odell.glazedlists.SortedList; -import ca.odell.glazedlists.matchers.Matcher; +import org.jabref.model.groups.GroupTreeNode; +import org.jabref.model.search.matchers.MatcherSet; +import org.jabref.model.search.matchers.MatcherSets; +import org.jabref.preferences.JabRefPreferences; public class MainTableDataModel { - - private final ListSynchronizer listSynchronizer; - private final SortedList sortedForUserDefinedTableColumnSorting; - private final SortedList sortedForMarkingSearchGrouping; - private final StartStopListFilterAction filterSearchToggle; - private final StartStopListFilterAction filterGroupToggle; - private final ObservableList finalList; - private final FilterAndSortingState filterAndSortingState = new FilterAndSortingState(); + private final FilteredList entriesFiltered; public MainTableDataModel(BibDatabaseContext context) { - List entries = context.getDatabase().getEntries(); - - EventList initialEventList = new BasicEventList<>(); - initialEventList.addAll(entries); - - listSynchronizer = new ListSynchronizer(initialEventList); - - // This SortedList has a Comparator controlled by the TableComparatorChooser - // we are going to install, which responds to user sorting selections: - sortedForUserDefinedTableColumnSorting = new SortedList<>(initialEventList, null); - // This SortedList applies afterwards, and floats marked entries: - sortedForMarkingSearchGrouping = new SortedList<>(sortedForUserDefinedTableColumnSorting, null); - - FilterList groupFilterList = new FilterList<>(sortedForMarkingSearchGrouping, EverythingMatcher.INSTANCE); - filterGroupToggle = new StartStopListFilterAction(groupFilterList, GroupMatcher.INSTANCE, - EverythingMatcher.INSTANCE); - FilterList searchFilterList = new FilterList<>(groupFilterList, EverythingMatcher.INSTANCE); - filterSearchToggle = new StartStopListFilterAction(searchFilterList, SearchMatcher.INSTANCE, - EverythingMatcher.INSTANCE); - - // TODO - //finalList = searchFilterList; - finalList = FXCollections.observableArrayList(entries.stream().map(BibEntryTableViewModel::new).collect(Collectors.toList())); - } + ObservableList allEntries = context.getDatabase().getEntries(); - public void updateSortOrder() { - Comparator markingComparator = filterAndSortingState.markingState ? IsMarkedComparator.INSTANCE : null; - Comparator searchComparator = getSearchState() == DisplayOption.FLOAT ? new HitOrMissComparator(SearchMatcher.INSTANCE) : null; - Comparator groupingComparator = getGroupingState() == DisplayOption.FLOAT ? new HitOrMissComparator(GroupMatcher.INSTANCE) : null; - GenericCompositeComparator comparator = new GenericCompositeComparator( - markingComparator, - searchComparator, - groupingComparator + entriesFiltered = new FilteredList<>( + BindingsHelper.mapBacked(allEntries, BibEntryTableViewModel::new)); + entriesFiltered.predicateProperty().bind( + Bindings.createObjectBinding(() -> this::isMatched, + Globals.stateManager.activeGroupProperty(), Globals.stateManager.activeSearchQueryProperty()) ); - - sortedForMarkingSearchGrouping.getReadWriteLock().writeLock().lock(); - try { - if (sortedForMarkingSearchGrouping.getComparator() != comparator) { - sortedForMarkingSearchGrouping.setComparator(comparator); - } - } finally { - sortedForMarkingSearchGrouping.getReadWriteLock().writeLock().unlock(); - } - } - - public void updateSearchState(DisplayOption searchState) { - Objects.requireNonNull(searchState); - - // fail fast - if (filterAndSortingState.searchState == searchState) { - return; - } - - boolean updateSortOrder = false; - if (filterAndSortingState.searchState == DisplayOption.FLOAT) { - updateSortOrder = true; - } else if (filterAndSortingState.searchState == DisplayOption.FILTER) { - filterSearchToggle.stop(); - } - - if (searchState == DisplayOption.FLOAT) { - updateSortOrder = true; - } else if (searchState == DisplayOption.FILTER) { - filterSearchToggle.start(); - } - - filterAndSortingState.searchState = searchState; - if (updateSortOrder) { - updateSortOrder(); - } - } - - public void updateGroupingState(DisplayOption groupingState) { - Objects.requireNonNull(groupingState); - - // fail fast - if (filterAndSortingState.groupingState == groupingState) { - return; - } - - boolean updateSortOrder = false; - if (filterAndSortingState.groupingState == DisplayOption.FLOAT) { - updateSortOrder = true; - } else if (filterAndSortingState.groupingState == DisplayOption.FILTER) { - filterGroupToggle.stop(); - } - - if (groupingState == DisplayOption.FLOAT) { - updateSortOrder = true; - } else if (groupingState == DisplayOption.FILTER) { - filterGroupToggle.start(); - } - - filterAndSortingState.groupingState = groupingState; - if (updateSortOrder) { - updateSortOrder(); - } } - public DisplayOption getSearchState() { - return filterAndSortingState.searchState; + private boolean isMatched(BibEntryTableViewModel entry) { + return isMatchedByGroup(entry) && isMatchedBySearch(entry); } - DisplayOption getGroupingState() { - return filterAndSortingState.groupingState; + private boolean isMatchedBySearch(BibEntryTableViewModel entry) { + return Globals.stateManager.activeSearchQueryProperty().getValue() + .map(matcher -> matcher.isMatch(entry.getEntry())) + .orElse(true); } - public ListSynchronizer getListSynchronizer() { - return this.listSynchronizer; + private boolean isMatchedByGroup(BibEntryTableViewModel entry) { + return createGroupMatcher(Globals.stateManager.activeGroupProperty().getValue()) + .map(matcher -> matcher.isMatch(entry.getEntry())) + .orElse(true); } - public void updateMarkingState(boolean floatMarkedEntries) { - // fail fast - if (filterAndSortingState.markingState == floatMarkedEntries) { - return; + private Optional createGroupMatcher(List selectedGroups) { + if ((selectedGroups == null) || selectedGroups.isEmpty()) { + // No selected group, show all entries + return Optional.empty(); } - filterAndSortingState.markingState = floatMarkedEntries; - updateSortOrder(); - } - - ObservableList getTableRows() { - return finalList; - } - - /** - * Returns the List of entries sorted by a user-selected term. This is the - * sorting before marking, search etc. applies. - *

- * Note: The returned List must not be modified from the outside - * - * @return The sorted list of entries. - */ - SortedList getSortedForUserDefinedTableColumnSorting() { - return sortedForUserDefinedTableColumnSorting; - } + final MatcherSet searchRules = MatcherSets.build( + Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS) ? MatcherSets.MatcherType.AND : MatcherSets.MatcherType.OR); - public void updateGroupFilter() { - if (getGroupingState() == DisplayOption.FILTER) { - filterGroupToggle.start(); - } else { - filterGroupToggle.stop(); + for (GroupTreeNode node : selectedGroups) { + searchRules.addRule(node.getSearchMatcher()); } + return Optional.of(searchRules); } - public enum DisplayOption { - FLOAT, FILTER, DISABLED - } - - static class FilterAndSortingState { - // at the beginning, everything is disabled - private DisplayOption searchState = DisplayOption.DISABLED; - private DisplayOption groupingState = DisplayOption.DISABLED; - private boolean markingState = false; + public ObservableList getEntriesFiltered() { + return entriesFiltered; } - - private static class GenericCompositeComparator implements Comparator { - - private final List> comparators; - - - @SafeVarargs - public GenericCompositeComparator(Comparator... comparators) { - this.comparators = Arrays.asList(comparators).stream().filter(Objects::nonNull).collect(Collectors.toList()); - } - - @Override - public int compare(BibEntry lhs, BibEntry rhs) { - for (Comparator comp : comparators) { - int result = comp.compare(lhs, rhs); - if (result != 0) { - return result; - } - } - return 0; - } - } - - private static class StartStopListFilterAction { - - private final Matcher active; - private final Matcher inactive; - private final FilterList list; - - private StartStopListFilterAction(FilterList list, Matcher active, Matcher inactive) { - this.list = list; - this.active = active; - this.inactive = inactive; - - list.setMatcher(inactive); - } - - public void start() { - update(active); - } - - public void stop() { - update(inactive); - } - - private void update(Matcher comparator) { - list.getReadWriteLock().writeLock().lock(); - try { - list.setMatcher(comparator); - } finally { - list.getReadWriteLock().writeLock().unlock(); - } - } - } - } diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 1ea33721900..47cc5c8ee5f 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -42,7 +42,6 @@ import org.jabref.gui.help.HelpAction; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.maintable.MainTable; -import org.jabref.gui.maintable.MainTableDataModel; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; @@ -275,7 +274,7 @@ private void updateSearchModeButtonText() { public void endSearch() { BasePanel currentBasePanel = frame.getCurrentBasePanel(); if (currentBasePanel != null) { - clearSearch(currentBasePanel); + clearSearch(); MainTable mainTable = frame.getCurrentBasePanel().getMainTable(); //Globals.getFocusListener().setFocused(mainTable); mainTable.requestFocus(); @@ -294,16 +293,13 @@ public void focus() { searchField.selectAll(); } - private void clearSearch(BasePanel currentBasePanel) { + private void clearSearch() { currentResults.setText(""); searchField.setText(""); searchQueryHighlightObservable.reset(); openCurrentResultsInDialog.setEnabled(false); - if (currentBasePanel != null) { - currentBasePanel.getMainTable().getTableModel().updateSearchState(MainTableDataModel.DisplayOption.DISABLED); - currentBasePanel.setCurrentSearchQuery(null); - } + Globals.stateManager.clearSearchQuery(); if (dontSelectSearchBar) { dontSelectSearchBar = false; @@ -324,7 +320,7 @@ public void performSearch() { // An empty search field should cause the search to be cleared. if (searchField.getText().isEmpty()) { - clearSearch(currentBasePanel); + clearSearch(); return; } @@ -334,6 +330,9 @@ public void performSearch() { return; } + Globals.stateManager.setSearchQuery(searchQuery); + + // TODO: Remove search worker as this is doing the work twice now searchWorker = new SearchWorker(currentBasePanel, searchQuery, searchDisplayMode); searchWorker.execute(); } @@ -343,8 +342,7 @@ private void informUserAboutInvalidSearchQuery() { searchQueryHighlightObservable.reset(); - BasePanel currentBasePanel = frame.getCurrentBasePanel(); - currentBasePanel.getMainTable().getTableModel().updateSearchState(MainTableDataModel.DisplayOption.DISABLED); + Globals.stateManager.clearSearchQuery(); String illegalSearch = Localization.lang("Search failed: illegal search expression"); currentResults.setText(illegalSearch); diff --git a/src/main/java/org/jabref/gui/search/SearchWorker.java b/src/main/java/org/jabref/gui/search/SearchWorker.java index 0a67414f214..75756776a0f 100644 --- a/src/main/java/org/jabref/gui/search/SearchWorker.java +++ b/src/main/java/org/jabref/gui/search/SearchWorker.java @@ -9,8 +9,6 @@ import org.jabref.JabRefGUI; import org.jabref.gui.BasePanel; -import org.jabref.gui.BasePanelMode; -import org.jabref.gui.maintable.MainTableDataModel; import org.jabref.gui.search.rules.describer.SearchDescribers; import org.jabref.logic.search.SearchQuery; import org.jabref.model.database.BibDatabase; @@ -64,52 +62,6 @@ protected void done() { private void updateUIWithSearchResult(List matchedEntries) { GlobalSearchBar globalSearchBar = JabRefGUI.getMainFrame().getGlobalSearchBar(); - // check if still the current query - if (!globalSearchBar.isStillValidQuery(searchQuery)) { - // do not update - another search was already issued - return; - } - - // clear - for (BibEntry entry : basePanel.getDatabase().getEntries()) { - entry.setSearchHit(false); - } - // and mark - for (BibEntry entry : matchedEntries) { - entry.setSearchHit(true); - } - - basePanel.getMainTable().getTableModel().updateSearchState(MainTableDataModel.DisplayOption.DISABLED); - // Show the result in the chosen way: - switch (searchDisplayMode) { - case FLOAT: - basePanel.getMainTable().getTableModel().updateSearchState(MainTableDataModel.DisplayOption.FLOAT); - break; - case FILTER: - basePanel.getMainTable().getTableModel().updateSearchState(MainTableDataModel.DisplayOption.FILTER); - break; - default: - LOGGER.error("Following searchDisplayMode was not defined: " + searchDisplayMode); - break; - } - - // only selects the first match if the selected entries are no hits or no entry is selected - // and no editor is open (to avoid jumping around when editing an entry) - if (basePanel.getMode() != BasePanelMode.SHOWING_EDITOR && basePanel.getMode() != BasePanelMode.WILL_SHOW_EDITOR) { - List selectedEntries = basePanel.getSelectedEntries(); - boolean isHitSelected = selectedEntries.stream().anyMatch(BibEntry::isSearchHit); - if (!isHitSelected && !matchedEntries.isEmpty()) { - /*for (int i = 0; i < basePanel.getMainTable().getRowCount(); i++) { - BibEntry entry = basePanel.getMainTable().getEntryAt(i); - if (entry.isSearchHit()) { - basePanel.getMainTable().setSelected(i); - break; - } - } - */ - } - } - globalSearchBar.updateResults(matchedEntries.size(), SearchDescribers.getSearchDescriberFor(searchQuery).getDescription(), searchQuery.isGrammarBasedSearch()); From d6fe1f1557f54f6edb58d30bbe888e564e959eae Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 8 Jan 2018 13:15:12 +0100 Subject: [PATCH 016/827] Fix a few smaller bugs --- src/main/java/org/jabref/gui/BasePanel.java | 4 ++++ src/main/java/org/jabref/gui/JabRefFrame.java | 8 +++++--- .../org/jabref/gui/importer/ImportInspectionDialog.java | 3 ++- src/main/java/org/jabref/logic/util/io/FileUtil.java | 2 ++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 235c8c1dfbe..c7d30cf880e 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1726,6 +1726,10 @@ public void autoGenerateKeysBeforeSaving() { * 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) { + return; + } + if (mode == BasePanelMode.SHOWING_PREVIEW) { PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences() .getBuilder() diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 0255e88edfd..1b5da59cde9 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -1023,9 +1023,11 @@ public TabPane getTabbedPane() { } public void setTabTitle(BasePanel comp, String title, String toolTip) { - Tab tab = getTab(comp); - tab.setText(title); - tab.setTooltip(new Tooltip(toolTip)); + DefaultTaskExecutor.runInJavaFXThread(() -> { + Tab tab = getTab(comp); + tab.setText(title); + tab.setTooltip(new Tooltip(toolTip)); + }); } private void fillMenu() { diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index d87b66da8f5..35b524ed50c 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -79,6 +79,7 @@ import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableInsertEntry; import org.jabref.gui.undo.UndoableRemoveEntry; +import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.comparator.IconComparator; import org.jabref.gui.util.component.CheckBoxMessage; import org.jabref.logic.bibtex.DuplicateCheck; @@ -202,7 +203,7 @@ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoNam this.undoName = undoName; this.newDatabase = newDatabase; setIconImages(IconTheme.getLogoSet()); - preview = new PreviewPanel(panel, bibDatabaseContext, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); + preview = DefaultTaskExecutor.runInJavaFXThread(() -> new PreviewPanel(panel, bibDatabaseContext, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences())); duplLabel.setToolTipText(Localization.lang("Possible duplicate of existing entry. Click to resolve.")); diff --git a/src/main/java/org/jabref/logic/util/io/FileUtil.java b/src/main/java/org/jabref/logic/util/io/FileUtil.java index d5dcfa139f7..eb458547bc1 100644 --- a/src/main/java/org/jabref/logic/util/io/FileUtil.java +++ b/src/main/java/org/jabref/logic/util/io/FileUtil.java @@ -186,7 +186,9 @@ public static boolean renameFile(Path fromFile, Path toFile) { * @param toFile The target fileName * @param replaceExisting Wether to replace existing files or not * @return True if the rename was successful, false if an exception occurred + * @deprecated Use {@link #renameFileWithException(Path, Path, boolean)} instead and handle exception properly */ + @Deprecated public static boolean renameFile(Path fromFile, Path toFile, boolean replaceExisting) { try { return renameFileWithException(fromFile, toFile, replaceExisting); From 530530a42ef993009feed10077c7435348767a5a Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 8 Jan 2018 13:40:35 +0100 Subject: [PATCH 017/827] Fix keyboard shortcuts --- src/main/java/org/jabref/gui/BasePanel.java | 2 +- src/main/java/org/jabref/gui/JabRefFrame.java | 24 +++++++++++++++++++ .../jabref/gui/entryeditor/EntryEditor.java | 15 ++++++++++-- .../gui/entryeditor/FieldsEditorTab.java | 12 ---------- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index c7d30cf880e..61a20a4826f 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -189,7 +189,7 @@ public class BasePanel extends StackPane implements ClipboardOwner { private StringDialog stringDialog; private SuggestionProviders suggestionProviders; - private Subscription dividerPositionSubscription; + @SuppressWarnings({"FieldCanBeLocal", "unused"}) private Subscription dividerPositionSubscription; // the query the user searches when this BasePanel is active private Optional currentSearchQuery = Optional.empty(); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 1b5da59cde9..f226cd73409 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -13,6 +13,7 @@ import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -918,6 +919,29 @@ private void initLayout() { splitPane.setDividerSize(2); splitPane.setBorder(null); JFXPanel tabbedPaneContainer = CustomJFXPanel.wrap(new Scene(tabbedPane)); + // TODO: Remove this hack as soon as toolbar is implemented in JavaFX and these events are no longer captured globally + tabbedPaneContainer.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + // We need to consume a few events that have a global listener + // Otherwise, they propagate to the JFrame (i.e. "Ctrl + A" in the entry editor still triggers the "Select all" action) + Optional keyBinding = Globals.getKeyPrefs().mapToKeyBinding(e); + if (keyBinding.isPresent()) { + switch (keyBinding.get()) { + case CUT: + case COPY: + case PASTE: + case DELETE_ENTRY: + case SELECT_ALL: + e.consume(); + break; + default: + //do nothing + } + } + } + }); + splitPane.setRightComponent(tabbedPaneContainer); splitPane.setLeftComponent(sidePaneManager.getPanel()); getContentPane().add(splitPane, BorderLayout.CENTER); diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 956f981b414..a6bf1dc33cd 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -20,6 +20,7 @@ import javafx.scene.layout.BorderPane; import org.jabref.gui.BasePanel; +import org.jabref.gui.GUIGlobals; import org.jabref.gui.entryeditor.fileannotationtab.FileAnnotationTab; import org.jabref.gui.help.HelpAction; import org.jabref.gui.keyboard.KeyBinding; @@ -75,6 +76,12 @@ public EntryEditor(BasePanel panel, EntryEditorPreferences preferences) { ControlHelper.loadFXMLForControl(this); getStylesheets().add(EntryEditor.class.getResource("EntryEditor.css").toExternalForm()); + if (GUIGlobals.currentFont != null) { + setStyle( + "text-area-background: " + convertToHex(GUIGlobals.validFieldBackgroundColor) + ";" + + "text-area-foreground: " + convertToHex(GUIGlobals.editorTextColor) + ";" + + "text-area-highlight: " + convertToHex(GUIGlobals.activeBackgroundColor) + ";"); + } EasyBind.subscribe(tabbed.getSelectionModel().selectedItemProperty(), tab -> { EntryEditorTab activeTab = (EntryEditorTab) tab; @@ -92,7 +99,7 @@ public EntryEditor(BasePanel panel, EntryEditorPreferences preferences) { * Set-up key bindings specific for the entry editor. */ private void setupKeyBindings() { - tabbed.addEventFilter(KeyEvent.KEY_PRESSED, event -> { + tabbed.addEventHandler(KeyEvent.KEY_PRESSED, event -> { Optional keyBinding = preferences.getKeyBindings().mapToKeyBinding(event); if (keyBinding.isPresent()) { switch (keyBinding.get()) { @@ -115,7 +122,7 @@ private void setupKeyBindings() { event.consume(); break; default: - // Pass other keys to children + // Pass other keys to parent } } }); @@ -262,4 +269,8 @@ public void setFocusToField(String fieldName) { } }); } + + private String convertToHex(java.awt.Color color) { + return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue()); + } } diff --git a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java index 6ed9ce119af..80b64831e19 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java @@ -23,7 +23,6 @@ import org.jabref.Globals; import org.jabref.gui.FXDialogService; -import org.jabref.gui.GUIGlobals; import org.jabref.gui.autocompleter.SuggestionProviders; import org.jabref.gui.fieldeditors.FieldEditorFX; import org.jabref.gui.fieldeditors.FieldEditors; @@ -66,10 +65,6 @@ private static void addColumn(GridPane gridPane, int columnIndex, Stream gridPane.addColumn(columnIndex, nodes.toArray(Node[]::new)); } - private String convertToHex(java.awt.Color color) { - return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue()); - } - private Region setupPanel(BibEntry entry, boolean compressed, SuggestionProviders suggestionProviders, UndoManager undoManager) { // The preferences might be not initialized in tests -> return empty node // TODO: Replace this ugly workaround by proper injection propagation @@ -133,13 +128,6 @@ private Region setupPanel(BibEntry entry, boolean compressed, SuggestionProvider setRegularRowLayout(gridPane, rows); } - if (GUIGlobals.currentFont != null) { - gridPane.setStyle( - "text-area-background: " + convertToHex(GUIGlobals.validFieldBackgroundColor) + ";" - + "text-area-foreground: " + convertToHex(GUIGlobals.editorTextColor) + ";" - + "text-area-highlight: " + convertToHex(GUIGlobals.activeBackgroundColor) + ";"); - } - // Warp everything in a scroll-pane ScrollPane scrollPane = new ScrollPane(); scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); From 11d4d59d951e254034ab84fc79ade8d0c169311e Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 8 Jan 2018 13:49:06 +0100 Subject: [PATCH 018/827] Fix cleanup action --- src/main/java/org/jabref/gui/BasePanel.java | 6 +++--- src/main/java/org/jabref/gui/actions/CleanupAction.java | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 61a20a4826f..1a8a6df410c 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -43,6 +43,7 @@ import org.jabref.JabRefExecutorService; import org.jabref.gui.actions.Actions; import org.jabref.gui.actions.BaseAction; +import org.jabref.gui.actions.CleanupAction; import org.jabref.gui.actions.CopyBibTeXKeyAndLinkAction; import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.autocompleter.AutoCompleteUpdater; @@ -328,8 +329,7 @@ public void output(String s) { private void setupActions() { SaveDatabaseAction saveAction = new SaveDatabaseAction(this); - // TODO - //CleanupAction cleanUpAction = new CleanupAction(this, Globals.prefs); + CleanupAction cleanUpAction = new CleanupAction(this, Globals.prefs); actions.put(Actions.UNDO, undoAction); actions.put(Actions.REDO, redoAction); @@ -479,7 +479,7 @@ public void update() { }); // The action for cleaning up entry. - //actions.put(Actions.CLEANUP, cleanUpAction); + actions.put(Actions.CLEANUP, cleanUpAction); actions.put(Actions.MERGE_ENTRIES, (BaseAction) () -> new MergeEntriesDialog(BasePanel.this)); diff --git a/src/main/java/org/jabref/gui/actions/CleanupAction.java b/src/main/java/org/jabref/gui/actions/CleanupAction.java index 89e8d94ab90..b62a01c607d 100644 --- a/src/main/java/org/jabref/gui/actions/CleanupAction.java +++ b/src/main/java/org/jabref/gui/actions/CleanupAction.java @@ -1,7 +1,6 @@ package org.jabref.gui.actions; import java.util.List; -import java.util.Objects; import javax.swing.JOptionPane; @@ -38,7 +37,7 @@ public class CleanupAction extends AbstractWorker { public CleanupAction(BasePanel panel, JabRefPreferences preferences) { this.panel = panel; this.frame = panel.frame(); - this.preferences = Objects.requireNonNull(preferences); + this.preferences = preferences; } @Override From 3a690913cd108f17dbd0b76c57f57fed3763b704 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 8 Jan 2018 13:50:26 +0100 Subject: [PATCH 019/827] Changes to entry triggers change of list of entries --- src/main/java/org/jabref/model/database/BibDatabase.java | 2 +- src/main/java/org/jabref/model/entry/BibEntry.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/model/database/BibDatabase.java b/src/main/java/org/jabref/model/database/BibDatabase.java index a5df29c3157..e2132648810 100644 --- a/src/main/java/org/jabref/model/database/BibDatabase.java +++ b/src/main/java/org/jabref/model/database/BibDatabase.java @@ -47,7 +47,7 @@ public class BibDatabase { /** * State attributes */ - private final ObservableList entries = FXCollections.synchronizedObservableList(FXCollections.observableArrayList()); + private final ObservableList entries = FXCollections.synchronizedObservableList(FXCollections.observableArrayList(BibEntry::getObservables)); private final Map bibtexStrings = new ConcurrentHashMap<>(); /** * this is kept in sync with the database (upon adding/removing an entry, it is updated as well) diff --git a/src/main/java/org/jabref/model/entry/BibEntry.java b/src/main/java/org/jabref/model/entry/BibEntry.java index 6e21b4ee4bc..800670be0c9 100644 --- a/src/main/java/org/jabref/model/entry/BibEntry.java +++ b/src/main/java/org/jabref/model/entry/BibEntry.java @@ -15,6 +15,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern; +import javafx.beans.Observable; import javafx.beans.binding.Bindings; import javafx.beans.binding.ObjectBinding; import javafx.collections.FXCollections; @@ -854,6 +855,13 @@ public ObservableMap getFieldsObservable() { return fields; } + /** + * Returns a list of observables that represent the data of the entry. + */ + public Observable[] getObservables() { + return new Observable[]{fields}; + } + private interface GetFieldInterface { Optional getValueForField(String fieldName); From ccd643a5fa0a8676bcfaa17e3a91cd335c690ba4 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 9 Jan 2018 13:41:33 +0100 Subject: [PATCH 020/827] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 519edd800dc..a9d888edf33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# ### Changed - We added [oaDOI](https://oadoi.org/) as a fulltext provider, so that JabRef is now able to provide fulltexts for more than 90 million open-access articles. +- We completely reworked and redesigned the main table. ### Fixed From 2c7b3a7a8e329ccc06b71e9c8aa53ae83a12a62b Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 9 Jan 2018 17:57:20 +0100 Subject: [PATCH 021/827] Remove clear Search keybinding as this overlaps with Close entry editor and it is not used anylonger --- src/main/java/org/jabref/gui/keyboard/KeyBinding.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java index 1a0eddd0ff9..6138ae09dd2 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java @@ -11,10 +11,9 @@ public enum KeyBinding { BACK("Back", Localization.lang("Back"), "alt+LEFT", KeyBindingCategory.VIEW), CHECK_INTEGRITY("Check integrity", Localization.menuTitle("Check integrity"), "ctrl+F8", KeyBindingCategory.QUALITY), CLEANUP("Cleanup", Localization.lang("Cleanup entries"), "alt+F8", KeyBindingCategory.QUALITY), - CLEAR_SEARCH("Clear search", Localization.lang("Clear search"), "ESCAPE", KeyBindingCategory.SEARCH), CLOSE_DATABASE("Close library", Localization.lang("Close library"), "ctrl+W", KeyBindingCategory.FILE), CLOSE_DIALOG("Close dialog", Localization.lang("Close dialog"), "ESCAPE", KeyBindingCategory.FILE), - CLOSE_ENTRY_EDITOR("Close entry editor", Localization.lang("Close entry editor"), "Esc", KeyBindingCategory.VIEW), + CLOSE_ENTRY_EDITOR("Close entry editor", Localization.lang("Close entry editor"), "ESCAPE", KeyBindingCategory.VIEW), COPY("Copy", Localization.lang("Copy"), "ctrl+C", KeyBindingCategory.EDIT), COPY_TITLE("Copy title", Localization.lang("Copy title"), "ctrl+shift+alt+T", KeyBindingCategory.EDIT), COPY_CITE_BIBTEX_KEY("Copy \\cite{BibTeX key}", Localization.lang("Copy \\cite{BibTeX key}"), "ctrl+K", KeyBindingCategory.EDIT), From 35d32c5b3f3761ae7360691f02ff148567c11de3 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 9 Jan 2018 18:11:04 +0100 Subject: [PATCH 022/827] wrap showandEdit in javafx thread to make new entry actions work --- src/main/java/org/jabref/gui/BasePanel.java | 30 +++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 1a8a6df410c..1bae4e7cc46 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1219,14 +1219,12 @@ private void createMainTable() { mainTable.addSelectionListener(listEvent -> Globals.stateManager.setSelectedEntries(mainTable.getSelectedEntries())); // Update entry editor and preview according to selected entries - mainTable.addSelectionListener(event -> - mainTable.getSelectedEntries().stream() - .findFirst() - .ifPresent(entry -> { - preview.setEntry(entry); - entryEditor.setEntry(entry); - }) - ); + mainTable.addSelectionListener(event -> mainTable.getSelectedEntries().stream() + .findFirst() + .ifPresent(entry -> { + preview.setEntry(entry); + entryEditor.setEntry(entry); + })); // TODO: Register these actions globally /* @@ -1424,13 +1422,17 @@ public EntryEditor getEntryEditor() { * @param entry The entry to edit. */ public void showAndEdit(BibEntry entry) { - showBottomPane(BasePanelMode.SHOWING_EDITOR); + DefaultTaskExecutor.runInJavaFXThread(() -> { - if (entry != getShowing()) { - entryEditor.setEntry(entry); - newEntryShowing(entry); - } - entryEditor.requestFocus(); + showBottomPane(BasePanelMode.SHOWING_EDITOR); + + if (entry != getShowing()) { + entryEditor.setEntry(entry); + newEntryShowing(entry); + } + entryEditor.requestFocus(); + + }); } private void showBottomPane(BasePanelMode newMode) { From e3515e9979bc8753abbfdb294c8d312986904d24 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 9 Jan 2018 23:51:58 +0100 Subject: [PATCH 023/827] Improve automatic sizing of columns --- .../jabref/gui/maintable/ColumnFactory.java | 24 ++--- .../org/jabref/gui/maintable/MainTable.java | 2 +- .../SmartConstrainedResizePolicy.java | 97 +++++++++++++++++++ .../SmartConstraintedResizePolicy.java | 23 ----- 4 files changed, 110 insertions(+), 36 deletions(-) create mode 100644 src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java delete mode 100644 src/main/java/org/jabref/gui/maintable/SmartConstraintedResizePolicy.java diff --git a/src/main/java/org/jabref/gui/maintable/ColumnFactory.java b/src/main/java/org/jabref/gui/maintable/ColumnFactory.java index 93515a85f9a..344e105d29d 100644 --- a/src/main/java/org/jabref/gui/maintable/ColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/ColumnFactory.java @@ -100,11 +100,9 @@ private TableColumn column.setGraphic(new SpecialFieldViewModel(specialField).getIcon().getGraphicNode()); column.getStyleClass().add(STYLE_ICON); if (specialField == SpecialField.RANKING) { - column.setMinWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); - column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); + setExactWidth(column, GUIGlobals.WIDTH_ICON_COL_RANKING); } else { - column.setMinWidth(GUIGlobals.WIDTH_ICON_COL); - column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL); + setExactWidth(column, GUIGlobals.WIDTH_ICON_COL); } column.setCellValueFactory(cellData -> cellData.getValue().getSpecialField(specialField)); column.setCellFactory( @@ -114,12 +112,17 @@ private TableColumn return column; } + private void setExactWidth(TableColumn column, int widthIconCol) { + column.setMinWidth(widthIconCol); + column.setPrefWidth(widthIconCol); + column.setMaxWidth(widthIconCol); + } + private TableColumn> createFileColumn() { TableColumn> column = new TableColumn<>(); column.setGraphic(IconTheme.JabRefIcons.FILE.getGraphicNode()); column.getStyleClass().add(STYLE_ICON); - column.setMinWidth(GUIGlobals.WIDTH_ICON_COL); - column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL); + setExactWidth(column, GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> cellData.getValue().getLinkedFiles()); column.setCellFactory( new ValueTableCellFactory>() @@ -134,8 +137,7 @@ private TableColumn createIconColumn(JabRefIcon TableColumn column = new TableColumn<>(); column.setGraphic(icon.getGraphicNode()); column.getStyleClass().add(STYLE_ICON); - column.setMinWidth(GUIGlobals.WIDTH_ICON_COL); - column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL); + setExactWidth(column, GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> EasyBind.monadic(cellData.getValue().getField(firstField)).orElse(cellData.getValue().getField(secondField))); column.setCellFactory( new ValueTableCellFactory() @@ -147,8 +149,7 @@ private TableColumn createIconColumn(JabRefIcon TableColumn column = new TableColumn<>(); column.setGraphic(icon.getGraphicNode()); column.getStyleClass().add(STYLE_ICON); - column.setMinWidth(GUIGlobals.WIDTH_ICON_COL); - column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL); + setExactWidth(column, GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> cellData.getValue().getField(field)); column.setCellFactory( new ValueTableCellFactory() @@ -168,8 +169,7 @@ private TableColumn> createExtraFileCol .map(ExternalFileType::getIcon).orElse(IconTheme.JabRefIcons.FILE) .getGraphicNode()); column.getStyleClass().add(STYLE_ICON); - column.setMinWidth(GUIGlobals.WIDTH_ICON_COL); - column.setMaxWidth(GUIGlobals.WIDTH_ICON_COL); + setExactWidth(column, GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> cellData.getValue().getLinkedFiles()); column.setCellFactory( new ValueTableCellFactory>() diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 350aa95c33b..ad0c14b26b4 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -85,7 +85,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, }) .withContextMenu(RightClickMenu::create)); if (preferences.resizeColumnsToFit()) { - this.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); + this.setColumnResizePolicy(new SmartConstrainedResizePolicy()); } this.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); this.setItems(model.getEntriesFiltered()); diff --git a/src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java b/src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java new file mode 100644 index 00000000000..425a59eac5c --- /dev/null +++ b/src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java @@ -0,0 +1,97 @@ +package org.jabref.gui.maintable; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; + +import javafx.scene.control.ResizeFeaturesBase; +import javafx.scene.control.TableColumnBase; +import javafx.scene.control.TableView; +import javafx.util.Callback; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * This resize policy is almost the same as {@link TableView#CONSTRAINED_RESIZE_POLICY} + * We make sure that the width of all columns sums up to the total width of the table. + * However, in contrast to {@link TableView#CONSTRAINED_RESIZE_POLICY} we size the columns initially by their preferred width. + */ +public class SmartConstrainedResizePolicy implements Callback { + + private static final Log LOGGER = LogFactory.getLog(SmartConstrainedResizePolicy.class); + + @Override + public Boolean call(TableView.ResizeFeatures prop) { + if (prop.getColumn() == null) { + return initColumnSize(prop.getTable()); + } else { + return constrainedResize(prop); + } + } + + private Boolean initColumnSize(TableView table) { + double tableWidth = table.getWidth(); + List> visibleLeafColumns = table.getVisibleLeafColumns(); + double totalWidth = visibleLeafColumns.stream().mapToDouble(TableColumnBase::getWidth).sum(); + + if (Math.abs(totalWidth - tableWidth) > 1) { + double totalPrefWidth = visibleLeafColumns.stream().mapToDouble(TableColumnBase::getPrefWidth).sum(); + if (totalPrefWidth > 0) { + for (TableColumnBase col : visibleLeafColumns) { + double share = col.getPrefWidth() / totalPrefWidth; + double newSize = tableWidth * share; + resize(col, newSize - col.getWidth()); + } + } + } + + return false; + } + + private void resize(TableColumnBase column, double delta) { + // We have to use reflection since TableUtil is not visible to us + try { + Class clazz = Class.forName("javafx.scene.control.TableUtil"); + Method constrainedResize = clazz.getDeclaredMethod("resize", TableColumnBase.class, double.class); + constrainedResize.setAccessible(true); + constrainedResize.invoke(null, column, delta); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) { + LOGGER.error("Could not invoke resize in TableUtil", e); + } + } + + private Boolean constrainedResize(TableView.ResizeFeatures prop) { + TableView table = prop.getTable(); + List> visibleLeafColumns = table.getVisibleLeafColumns(); + return constrainedResize(prop, + false, + getContentWidth(table), + visibleLeafColumns); + } + + private Boolean constrainedResize(TableView.ResizeFeatures prop, Boolean isFirstRun, Double contentWidth, List> visibleLeafColumns) { + // We have to use reflection since TableUtil is not visible to us + try { + Class clazz = Class.forName("javafx.scene.control.TableUtil"); + Method constrainedResize = clazz.getDeclaredMethod("constrainedResize", ResizeFeaturesBase.class, Boolean.TYPE, Double.TYPE, List.class); + constrainedResize.setAccessible(true); + Object returnValue = constrainedResize.invoke(null, prop, isFirstRun, contentWidth, visibleLeafColumns); + return (Boolean) returnValue; + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) { + LOGGER.error("Could not invoke constrainedResize in TableUtil", e); + return false; + } + } + + private Double getContentWidth(TableView table) { + try { + Field privateStringField = TableView.class.getDeclaredField("contentWidth"); + privateStringField.setAccessible(true); + return (Double) privateStringField.get(table); + } catch (IllegalAccessException | NoSuchFieldException e) { + return 0d; + } + } +} diff --git a/src/main/java/org/jabref/gui/maintable/SmartConstraintedResizePolicy.java b/src/main/java/org/jabref/gui/maintable/SmartConstraintedResizePolicy.java deleted file mode 100644 index 5b173dd03cb..00000000000 --- a/src/main/java/org/jabref/gui/maintable/SmartConstraintedResizePolicy.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.jabref.gui.maintable; - -import javafx.scene.control.TableView; -import javafx.util.Callback; - -public class SmartConstraintedResizePolicy implements Callback { - private boolean isFirstRun = true; - private Callback basePolicy = TableView.CONSTRAINED_RESIZE_POLICY; - - @Override - public Boolean call(TableView.ResizeFeatures prop) { - Boolean result = basePolicy.call(prop); - - // The CONSTRAINED_RESIZE_POLICY resizes all columns to the same width - // We want to resize them to (almost) their preferred width - if (isFirstRun) { - - } - - isFirstRun = isFirstRun && !result; - return result; - } -} From bd2c1e3f09e7a2ddc0ea18f3e7724c51a133c485 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 10 Jan 2018 00:04:31 +0100 Subject: [PATCH 024/827] Implement feedback --- src/main/java/org/jabref/gui/maintable/MainTable.java | 2 +- .../{ColumnFactory.java => MainTableColumnFactory.java} | 9 +++------ .../org/jabref/migrations/FileLinksUpgradeWarning.java | 6 ++---- .../java/org/jabref/model/entry/BibtexSingleField.java | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) rename src/main/java/org/jabref/gui/maintable/{ColumnFactory.java => MainTableColumnFactory.java} (96%) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index ad0c14b26b4..07e4044b26e 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -76,7 +76,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, super(); this.model = model; - this.getColumns().addAll(new ColumnFactory(database, preferences.getColumnPreferences(), externalFileTypes).createColumns()); + this.getColumns().addAll(new MainTableColumnFactory(database, preferences.getColumnPreferences(), externalFileTypes).createColumns()); this.setRowFactory(new ViewModelTableRowFactory() .withOnMouseClickedEvent((entry, event) -> { if (event.getClickCount() == 2) { diff --git a/src/main/java/org/jabref/gui/maintable/ColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java similarity index 96% rename from src/main/java/org/jabref/gui/maintable/ColumnFactory.java rename to src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index 344e105d29d..aa5c0a10b66 100644 --- a/src/main/java/org/jabref/gui/maintable/ColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -25,7 +25,7 @@ import org.fxmisc.easybind.EasyBind; -class ColumnFactory { +class MainTableColumnFactory { private static final String STYLE_ICON = "column-icon"; @@ -34,7 +34,7 @@ class ColumnFactory { private final BibDatabase database; private final CellFactory cellFactory; - public ColumnFactory(BibDatabase database, ColumnPreferences preferences, ExternalFileTypes externalFileTypes) { + public MainTableColumnFactory(BibDatabase database, ColumnPreferences preferences, ExternalFileTypes externalFileTypes) { this.database = Objects.requireNonNull(database); this.preferences = Objects.requireNonNull(preferences); this.externalFileTypes = Objects.requireNonNull(externalFileTypes); @@ -64,10 +64,7 @@ public ColumnFactory(BibDatabase database, ColumnPreferences preferences, Extern } // Add columns for other file types - for (String column : preferences.getExtraFileColumns()) { - columns.add(createExtraFileColumn(column)); - } - + columns.addAll(preferences.getExtraFileColumns().stream().map(this::createExtraFileColumn).collect(Collectors.toList())); // Add 'normal' bibtex fields as configured in the preferences columns.addAll(createNormalColumns()); diff --git a/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java b/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java index 1e7c11fc8b2..552fbc36f23 100644 --- a/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java +++ b/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java @@ -1,7 +1,6 @@ package org.jabref.migrations; import java.util.List; -import java.util.Map; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -56,7 +55,6 @@ public class FileLinksUpgradeWarning implements GUIPostOpenAction { * GUIGlobals.FILE_FIELD. * * @param database The database to modify. - * @param fields The fields to find links in. * @return A CompoundEdit specifying the undo operation for the whole operation. */ private static NamedCompound upgradePdfPsToFile(BibDatabase database) { @@ -248,8 +246,8 @@ private void makeChanges(BasePanel panel, ParserResult pr, boolean upgradePrefs, } private boolean showsFileInGenFields() { - for (Map.Entry> tab : Globals.prefs.getEntryEditorTabList().entrySet()) { - for (String field : tab.getValue()) { + for (List fields : Globals.prefs.getEntryEditorTabList().values()) { + for (String field : fields) { if (field.equals(FieldName.FILE)) { return true; } diff --git a/src/main/java/org/jabref/model/entry/BibtexSingleField.java b/src/main/java/org/jabref/model/entry/BibtexSingleField.java index 14722ee9579..fa67cefc2ef 100644 --- a/src/main/java/org/jabref/model/entry/BibtexSingleField.java +++ b/src/main/java/org/jabref/model/entry/BibtexSingleField.java @@ -8,7 +8,7 @@ */ public class BibtexSingleField { - // TODO: This constant should be moved to the gui package, probably to ColumnFactory + // TODO: This constant should be moved to the gui package, probably to MainTableColumnFactory public static final double DEFAULT_FIELD_LENGTH = 100; private enum Flag { From 8980713f22531606075a9990b9d8986bc6c266bd Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 29 Jan 2018 12:59:14 +0100 Subject: [PATCH 025/827] Bring back the context menu (#3666) * First prototype * Make old actions list an enum * Make it work! * Implement feedback --- build.gradle | 1 + src/main/java/org/jabref/gui/BasePanel.java | 28 +- .../jabref/gui/FindUnlinkedFilesDialog.java | 1 - src/main/java/org/jabref/gui/JabRefFrame.java | 37 +- .../org/jabref/gui/actions/ActionFactory.java | 45 +++ .../java/org/jabref/gui/actions/Actions.java | 150 +++---- .../org/jabref/gui/actions/ActionsFX.java | 101 +++++ .../org/jabref/gui/actions/JabRefAction.java | 25 ++ .../jabref/gui/actions/OldCommandWrapper.java | 50 +++ .../JTextAreaWithHighlighting.java | 2 +- .../jabref/gui/fieldeditors/TextField.java | 2 +- .../org/jabref/gui/maintable/MainTable.java | 5 +- .../jabref/gui/maintable/RightClickMenu.java | 372 ++++++------------ .../jabref/gui/menus/ChangeEntryTypeMenu.java | 41 +- .../gui/mergeentries/FetchAndMergeEntry.java | 7 - .../specialfields/SpecialFieldDropDown.java | 8 +- .../specialfields/SpecialFieldMenuAction.java | 27 -- .../SpecialFieldValueViewModel.java | 144 +++---- .../specialfields/SpecialFieldViewModel.java | 53 +-- .../org/jabref/gui/util/BindingsHelper.java | 9 + 20 files changed, 574 insertions(+), 534 deletions(-) create mode 100644 src/main/java/org/jabref/gui/actions/ActionFactory.java create mode 100644 src/main/java/org/jabref/gui/actions/ActionsFX.java create mode 100644 src/main/java/org/jabref/gui/actions/JabRefAction.java create mode 100644 src/main/java/org/jabref/gui/actions/OldCommandWrapper.java delete mode 100644 src/main/java/org/jabref/gui/specialfields/SpecialFieldMenuAction.java diff --git a/build.gradle b/build.gradle index d3d94ed8d22..0362677a4e9 100644 --- a/build.gradle +++ b/build.gradle @@ -128,6 +128,7 @@ dependencies { compile 'de.codecentric.centerdevice:javafxsvg:1.2.1' compile 'de.jensd:fontawesomefx-materialdesignfont:1.7.22-4' compile 'de.saxsys:mvvmfx-validation:1.7.0' + compile 'de.saxsys:mvvmfx:1.7.0' compile 'org.fxmisc.easybind:easybind:1.0.3' compile 'org.fxmisc.flowless:flowless:0.6' compile 'org.fxmisc.richtext:richtextfx:0.8.1' diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 668a0046864..c62a8ed2c41 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -161,7 +161,7 @@ public class BasePanel extends StackPane implements ClipboardOwner { private final List previousEntries = new ArrayList<>(); private final List nextEntries = new ArrayList<>(); // Keeps track of the string dialog if it is open. - private final Map actions = new HashMap<>(); + private final Map actions = new HashMap<>(); private final SidePaneManager sidePaneManager; private final PreviewPanel preview; private final BasePanelPreferences preferences; @@ -395,7 +395,7 @@ private void setupActions() { } }); - actions.put(FindUnlinkedFilesDialog.ACTION_COMMAND, (BaseAction) () -> { + actions.put(Actions.findUnlinkedFiles, (BaseAction) () -> { final FindUnlinkedFilesDialog dialog = new FindUnlinkedFilesDialog(frame, frame, BasePanel.this); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); @@ -637,26 +637,26 @@ public void update() { }); // Note that we can't put the number of entries that have been reverted into the undoText as the concrete number cannot be injected - actions.put(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getActionName(), + actions.put(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getCommand(), new SpecialFieldViewModel(SpecialField.RELEVANCE).getSpecialFieldAction( SpecialField.RELEVANCE.getValues().get(0), frame)); - actions.put(new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getActionName(), + actions.put(new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getCommand(), new SpecialFieldViewModel(SpecialField.QUALITY) .getSpecialFieldAction(SpecialField.QUALITY.getValues().get(0), frame)); - actions.put(new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getActionName(), + actions.put(new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getCommand(), new SpecialFieldViewModel(SpecialField.PRINTED).getSpecialFieldAction( SpecialField.PRINTED.getValues().get(0), frame)); for (SpecialFieldValue prio : SpecialField.PRIORITY.getValues()) { - actions.put(new SpecialFieldValueViewModel(prio).getActionName(), + actions.put(new SpecialFieldValueViewModel(prio).getCommand(), new SpecialFieldViewModel(SpecialField.PRIORITY).getSpecialFieldAction(prio, this.frame)); } for (SpecialFieldValue rank : SpecialField.RANKING.getValues()) { - actions.put(new SpecialFieldValueViewModel(rank).getActionName(), + actions.put(new SpecialFieldValueViewModel(rank).getCommand(), new SpecialFieldViewModel(SpecialField.RANKING).getSpecialFieldAction(rank, this.frame)); } for (SpecialFieldValue status : SpecialField.READ_STATUS.getValues()) { - actions.put(new SpecialFieldValueViewModel(status).getActionName(), + actions.put(new SpecialFieldValueViewModel(status).getCommand(), new SpecialFieldViewModel(SpecialField.READ_STATUS).getSpecialFieldAction(status, this.frame)); } @@ -998,15 +998,15 @@ private void openExternalFile() { * This method is called from JabRefFrame if a database specific action is requested by the user. Runs the command * if it is defined, or prints an error message to the standard error stream. * - * @param _command The name of the command to run. + * @param command The name of the command to run. */ - public void runCommand(final String _command) { - if (!actions.containsKey(_command)) { - LOGGER.info("No action defined for '" + _command + '\''); + public void runCommand(final Actions command) { + if (!actions.containsKey(command)) { + LOGGER.info("No action defined for '" + command + '\''); return; } - Object o = actions.get(_command); + Object o = actions.get(command); try { if (o instanceof BaseAction) { ((BaseAction) o).action(); @@ -1211,7 +1211,7 @@ public void updateTableFont() { private void createMainTable() { bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.getInstance()); - mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext.getDatabase(), preferences.getTablePreferences(), externalFileTypes); + mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext.getDatabase(), preferences.getTablePreferences(), externalFileTypes, Globals.getKeyPrefs()); mainTable.updateFont(); diff --git a/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java b/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java index 3bc4e339797..fbeb4ead8be 100644 --- a/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java +++ b/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java @@ -93,7 +93,6 @@ public class FindUnlinkedFilesDialog extends JabRefDialog { /** * Keys to be used for referencing this Action. */ - public static final String ACTION_COMMAND = "findUnlinkedFiles"; public static final String ACTION_MENU_TITLE = Localization.menuTitle("Find unlinked files..."); public static final String ACTION_SHORT_DESCRIPTION = Localization diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index f226cd73409..6b1b2f37cb5 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -109,7 +109,6 @@ import org.jabref.gui.journals.ManageJournalsAction; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.keyboard.KeyBindingAction; -import org.jabref.gui.maintable.RightClickMenu; import org.jabref.gui.menus.ChangeEntryTypeMenu; import org.jabref.gui.menus.FileHistoryMenu; import org.jabref.gui.openoffice.OpenOfficePanel; @@ -274,17 +273,17 @@ public class JabRefFrame extends JFrame implements OutputPrinter { Globals.getKeyPrefs().getKey(KeyBinding.UNMARK_ENTRIES), IconTheme.JabRefIcons.UNMARK_ENTRIES.getIcon()); private final AbstractAction unmarkAll = new GeneralAction(Actions.UNMARK_ALL, Localization.menuTitle("Unmark all")); private final AbstractAction toggleRelevance = new GeneralAction( - new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getActionName(), + new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getCommand(), new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getMenuString(), new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getToolTipText(), IconTheme.JabRefIcons.RELEVANCE.getIcon()); private final AbstractAction toggleQualityAssured = new GeneralAction( - new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getActionName(), + new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getCommand(), new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getMenuString(), new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getToolTipText(), IconTheme.JabRefIcons.QUALITY_ASSURED.getIcon()); private final AbstractAction togglePrinted = new GeneralAction( - new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getActionName(), + new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getCommand(), new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getMenuString(), new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getToolTipText(), IconTheme.JabRefIcons.PRINTED.getIcon()); @@ -427,7 +426,7 @@ public void actionPerformed(ActionEvent e) { private final ManageKeywordsAction manageKeywords = new ManageKeywordsAction(this); private final JMenu lookupIdentifiers = JabRefFrame.subMenu(Localization.menuTitle("Look up document identifier...")); private final GeneralAction findUnlinkedFiles = new GeneralAction( - FindUnlinkedFilesDialog.ACTION_COMMAND, + Actions.findUnlinkedFiles, FindUnlinkedFilesDialog.ACTION_MENU_TITLE, FindUnlinkedFilesDialog.ACTION_SHORT_DESCRIPTION, Globals.getKeyPrefs().getKey(KeyBinding.FIND_UNLINKED_FILES) ); @@ -1131,7 +1130,7 @@ private void fillMenu() { boolean menuitem = false; if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) { rankSubMenu = new JMenu(); - RightClickMenu.populateSpecialFieldMenu(rankSubMenu, SpecialField.RANKING, this); + // TODO RightClickMenu.createSpecialFieldMenu(rankSubMenu, SpecialField.RANKING, this); edit.add(rankSubMenu); menuitem = true; } @@ -1145,7 +1144,7 @@ private void fillMenu() { } if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) { rankSubMenu = new JMenu(); - RightClickMenu.populateSpecialFieldMenu(rankSubMenu, SpecialField.PRIORITY, this); + // TODO RightClickMenu.createSpecialFieldMenu(rankSubMenu, SpecialField.PRIORITY, this); edit.add(rankSubMenu); menuitem = true; } @@ -1155,7 +1154,7 @@ private void fillMenu() { } if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) { rankSubMenu = new JMenu(); - RightClickMenu.populateSpecialFieldMenu(rankSubMenu, SpecialField.READ_STATUS, this); + // TODO RightClickMenu.createSpecialFieldMenu(rankSubMenu, SpecialField.READ_STATUS, this); edit.add(rankSubMenu); menuitem = true; } @@ -2033,27 +2032,27 @@ public void actionPerformed(ActionEvent evt) { private class GeneralAction extends MnemonicAwareAction { - private final String command; + private final Actions command; - public GeneralAction(String command, String text) { + public GeneralAction(Actions command, String text) { this.command = command; putValue(Action.NAME, text); } - public GeneralAction(String command, String text, String description) { + public GeneralAction(Actions command, String text, String description) { this.command = command; putValue(Action.NAME, text); putValue(Action.SHORT_DESCRIPTION, description); } - public GeneralAction(String command, String text, Icon icon) { + public GeneralAction(Actions command, String text, Icon icon) { super(icon); this.command = command; putValue(Action.NAME, text); } - public GeneralAction(String command, String text, String description, Icon icon) { + public GeneralAction(Actions command, String text, String description, Icon icon) { super(icon); this.command = command; @@ -2061,20 +2060,20 @@ public GeneralAction(String command, String text, String description, Icon icon) putValue(Action.SHORT_DESCRIPTION, description); } - public GeneralAction(String command, String text, KeyStroke key) { + public GeneralAction(Actions command, String text, KeyStroke key) { this.command = command; putValue(Action.NAME, text); putValue(Action.ACCELERATOR_KEY, key); } - public GeneralAction(String command, String text, String description, KeyStroke key) { + public GeneralAction(Actions command, String text, String description, KeyStroke key) { this.command = command; putValue(Action.NAME, text); putValue(Action.SHORT_DESCRIPTION, description); putValue(Action.ACCELERATOR_KEY, key); } - public GeneralAction(String command, String text, String description, KeyStroke key, Icon icon) { + public GeneralAction(Actions command, String text, String description, KeyStroke key, Icon icon) { super(icon); this.command = command; @@ -2158,9 +2157,9 @@ public void actionPerformed(ActionEvent e) { */ private class EditAction extends MnemonicAwareAction { - private final String command; + private final Actions command; - public EditAction(String command, String menuTitle, String description, KeyStroke key, Icon icon) { + public EditAction(Actions command, String menuTitle, String description, KeyStroke key, Icon icon) { super(icon); this.command = command; putValue(Action.NAME, menuTitle); @@ -2174,7 +2173,7 @@ public EditAction(String command, String menuTitle, String description, KeyStrok JComponent source = Globals.getFocusListener().getFocused(); Action action = source.getActionMap().get(command); if (action != null) { - action.actionPerformed(new ActionEvent(source, 0, command)); + action.actionPerformed(new ActionEvent(source, 0, command.name())); } } } diff --git a/src/main/java/org/jabref/gui/actions/ActionFactory.java b/src/main/java/org/jabref/gui/actions/ActionFactory.java new file mode 100644 index 00000000000..e8374353d20 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/ActionFactory.java @@ -0,0 +1,45 @@ +package org.jabref.gui.actions; + +import java.util.Objects; + +import javafx.scene.control.Menu; +import javafx.scene.control.MenuItem; + +import org.jabref.gui.keyboard.KeyBindingRepository; + +import de.saxsys.mvvmfx.utils.commands.Command; +import org.controlsfx.control.action.ActionUtils; + +/** + * Helper class to create and style controls according to an {@link ActionsFX}. + */ +public class ActionFactory { + + private KeyBindingRepository keyBindingRepository; + + public ActionFactory(KeyBindingRepository keyBindingRepository) { + this.keyBindingRepository = Objects.requireNonNull(keyBindingRepository); + } + + public MenuItem configureMenuItem(ActionsFX action, Command command, MenuItem menuItem) { + return ActionUtils.configureMenuItem(new JabRefAction(action, command, keyBindingRepository), menuItem); + } + + public MenuItem createMenuItem(ActionsFX action, Command command) { + MenuItem menuItem = ActionUtils.createMenuItem(new JabRefAction(action, command, keyBindingRepository)); + + // For some reason the graphic is not set correctly, so let's fix this + menuItem.graphicProperty().unbind(); + action.getIcon().ifPresent(icon -> menuItem.setGraphic(icon.getGraphicNode())); + return menuItem; + } + + public Menu createMenu(ActionsFX action) { + Menu menu = ActionUtils.createMenu(new JabRefAction(action, keyBindingRepository)); + + // For some reason the graphic is not set correctly, so let's fix this + menu.graphicProperty().unbind(); + action.getIcon().ifPresent(icon -> menu.setGraphic(icon.getGraphicNode())); + return menu; + } +} diff --git a/src/main/java/org/jabref/gui/actions/Actions.java b/src/main/java/org/jabref/gui/actions/Actions.java index 8f93cd76970..b987cba8220 100644 --- a/src/main/java/org/jabref/gui/actions/Actions.java +++ b/src/main/java/org/jabref/gui/actions/Actions.java @@ -3,73 +3,87 @@ /** * Global String constants for GUI actions */ -public class Actions { +public enum Actions { - public static final String ABBREVIATE_ISO = "abbreviateIso"; - public static final String ABBREVIATE_MEDLINE = "abbreviateMedline"; - public static final String ADD_FILE_LINK = "addFileLink"; - public static final String ADD_TO_GROUP = "addToGroup"; - public static final String AUTO_SET_FILE = "autoSetFile"; - public static final String BACK = "back"; - public static final String CLEANUP = "Cleanup"; - public static final String COPY = "copy"; - public static final String COPY_CITATION_ASCII_DOC = "copyCitaitonAsciidoc"; - public static final String COPY_CITATION_XSLFO = "copyCitaitonFo"; - public static final String COPY_CITATION_HTML = "copyCitaitonHtml"; - public static final String COPY_CITATION_RTF = "copyCitaitonRtf"; - public static final String COPY_CITATION_TEXT = "copyCitaitonText"; - public static final String COPY_KEY = "copyKey"; - public static final String COPY_CITE_KEY = "copyCiteKey"; - public static final String COPY_KEY_AND_TITLE = "copyKeyAndTitle"; - public static final String COPY_KEY_AND_LINK = "copyKeyAndLink"; - public static final String COPY_TITLE = "copyTitle"; - public static final String CUT = "cut"; - public static final String DELETE = "delete"; - public static final String DOWNLOAD_FULL_TEXT = "downloadFullText"; - public static final String DUPLI_CHECK = "dupliCheck"; - public static final String EDIT = "edit"; - public static final String EDIT_PREAMBLE = "editPreamble"; - public static final String EDIT_STRINGS = "editStrings"; - public static final String EXPORT_TO_CLIPBOARD = "exportToClipboard"; - public static final String FOCUS_TABLE = "focusTable"; - public static final String FORWARD = "forward"; - public static final String MAKE_KEY = "makeKey"; - public static final String MANAGE_SELECTORS = "manageSelectors"; - public static final String MARK_ENTRIES = "markEntries"; - public static final String MERGE_DATABASE = "mergeDatabase"; - public static final String MERGE_ENTRIES = "mergeEntries"; - public static final String MERGE_WITH_FETCHED_ENTRY = "mergeWithFetchedEntry"; - public static final String NEXT_PREVIEW_STYLE = "nextPreviewStyle"; - public static final String MOVE_TO_GROUP = "moveToGroup"; - public static final String OPEN_CONSOLE = "openConsole"; - public static final String OPEN_EXTERNAL_FILE = "openExternalFile"; - public static final String OPEN_FOLDER = "openFolder"; - public static final String OPEN_URL = "openUrl"; - public static final String PASTE = "paste"; - public static final String PLAIN_TEXT_IMPORT = "plainTextImport"; - public static final String PREVIOUS_PREVIEW_STYLE = "previousPreviewStyle"; - public static final String PULL_CHANGES_FROM_SHARED_DATABASE = "pullChangesFromSharedDatabase"; - public static final String REDO = "redo"; - public static final String REMOVE_FROM_GROUP = "removeFromGroup"; - public static final String REPLACE_ALL = "replaceAll"; - public static final String RESOLVE_DUPLICATE_KEYS = "resolveDuplicateKeys"; - public static final String SAVE = "save"; - public static final String SAVE_AS = "saveAs"; - public static final String SAVE_SELECTED_AS = "saveSelectedAs"; - public static final String SAVE_SELECTED_AS_PLAIN = "saveSelectedAsPlain"; - public static final String SEARCH = "search"; - public static final String GLOBAL_SEARCH = "globalSearch"; - public static final String SELECT_ALL = "selectAll"; - public static final String SEND_AS_EMAIL = "sendAsEmail"; - public static final String TOGGLE_GROUPS = "toggleGroups"; - public static final String TOGGLE_PREVIEW = "togglePreview"; - public static final String UNABBREVIATE = "unabbreviate"; - public static final String UNDO = "undo"; - public static final String UNMARK_ALL = "unmarkAll"; - public static final String UNMARK_ENTRIES = "unmarkEntries"; - public static final String WRITE_XMP = "writeXMP"; - public static final String PRINT_PREVIEW = "printPreview"; - - private Actions() { - } + ABBREVIATE_ISO, + ABBREVIATE_MEDLINE, + ADD_FILE_LINK, + ADD_TO_GROUP, + AUTO_SET_FILE, + BACK, + CLEANUP, + COPY, + COPY_CITATION_ASCII_DOC, + COPY_CITATION_XSLFO, + COPY_CITATION_HTML, + COPY_CITATION_RTF, + COPY_CITATION_TEXT, + COPY_KEY, + COPY_CITE_KEY, + COPY_KEY_AND_TITLE, + COPY_KEY_AND_LINK, + COPY_TITLE, + CUT, + DELETE, + DOWNLOAD_FULL_TEXT, + DUPLI_CHECK, + EDIT, + EDIT_PREAMBLE, + EDIT_STRINGS, + EXPORT_TO_CLIPBOARD, + FOCUS_TABLE, + FORWARD, + MAKE_KEY, + MANAGE_SELECTORS, + MARK_ENTRIES, + MERGE_DATABASE, + MERGE_ENTRIES, + MERGE_WITH_FETCHED_ENTRY, + NEXT_PREVIEW_STYLE, + MOVE_TO_GROUP, + OPEN_CONSOLE, + OPEN_EXTERNAL_FILE, + OPEN_FOLDER, + OPEN_URL, + PASTE, + PLAIN_TEXT_IMPORT, + PREVIOUS_PREVIEW_STYLE, + PULL_CHANGES_FROM_SHARED_DATABASE, + REDO, + REMOVE_FROM_GROUP, + REPLACE_ALL, + RESOLVE_DUPLICATE_KEYS, + SAVE, + SAVE_AS, + SAVE_SELECTED_AS, + SAVE_SELECTED_AS_PLAIN, + SEARCH, + GLOBAL_SEARCH, + SELECT_ALL, + SEND_AS_EMAIL, + TOGGLE_GROUPS, + TOGGLE_PREVIEW, + UNABBREVIATE, + UNDO, + UNMARK_ALL, + UNMARK_ENTRIES, + WRITE_XMP, + PRINT_PREVIEW, + togglePrinted, + clearPriority, + setPriority1, + setPriority2, + setPriority3, + toggleQualityAssured, + clearRank, + setRank1, + setRank2, + setRank3, + setRank4, + setRank5, + clearReadStatus, + setReadStatusToRead, + setReadStatusToSkimmed, + toggleRelevance, + findUnlinkedFiles } diff --git a/src/main/java/org/jabref/gui/actions/ActionsFX.java b/src/main/java/org/jabref/gui/actions/ActionsFX.java new file mode 100644 index 00000000000..64c6276f1b0 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/ActionsFX.java @@ -0,0 +1,101 @@ +package org.jabref.gui.actions; + +import java.util.Optional; + +import org.jabref.gui.IconTheme; +import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.logic.l10n.Localization; + +public enum ActionsFX { + + COPY_MORE(Localization.lang("Copy") + "..."), + COPY_TITLE(Localization.lang("Copy title"), KeyBinding.COPY_TITLE), + COPY_KEY(Localization.lang("Copy BibTeX key"), KeyBinding.COPY_BIBTEX_KEY), + COPY_CITE_KEY(Localization.lang("Copy \\cite{BibTeX key}"), KeyBinding.COPY_CITE_BIBTEX_KEY), + COPY_KEY_AND_TITLE(Localization.lang("Copy BibTeX key and title"), KeyBinding.COPY_BIBTEX_KEY_AND_TITLE), + COPY_KEY_AND_LINK(Localization.lang("Copy BibTeX key and link"), KeyBinding.COPY_BIBTEX_KEY_AND_LINK), + COPY_CITATION_HTML(Localization.menuTitle("Copy citation") + " (HTML)", KeyBinding.COPY_PREVIEW), + COPY_CITATION_MORE(Localization.menuTitle("Copy citation") + "..."), + COPY_CITATION_TEXT("Text"), + COPY_CITATION_RTF("RTF"), + COPY_CITATION_ASCII_DOC("AsciiDoc"), + COPY_CITATION_XSLFO("XSL-FO"), + COPY_CITATION_PREVIEW(Localization.lang("Copy preview"), KeyBinding.COPY_PREVIEW), + EXPORT_TO_CLIPBOARD(Localization.lang("Export to clipboard"), IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD), + COPY(Localization.lang("Copy"), IconTheme.JabRefIcons.COPY, KeyBinding.COPY), + PASTE(Localization.lang("Paste"), IconTheme.JabRefIcons.PASTE, KeyBinding.PASTE), + CUT(Localization.lang("Cut"), IconTheme.JabRefIcons.CUT, KeyBinding.CUT), + DELETE(Localization.lang("Delete"), IconTheme.JabRefIcons.DELETE_ENTRY, KeyBinding.DELETE_ENTRY), + SEND_AS_EMAIL(Localization.lang("Send as email"), IconTheme.JabRefIcons.EMAIL), + OPEN_FOLDER(Localization.lang("Open folder"), KeyBinding.OPEN_FOLDER), + OPEN_EXTERNAL_FILE(Localization.lang("Open file"), IconTheme.JabRefIcons.FILE, KeyBinding.OPEN_FILE), + OPEN_URL(Localization.lang("Open URL or DOI"), IconTheme.JabRefIcons.WWW, KeyBinding.OPEN_URL_OR_DOI), + MERGE_WITH_FETCHED_ENTRY(Localization.lang("Get BibTeX data from %0", "DOI/ISBN/...")), + ADD_FILE_LINK(Localization.lang("Attach file"), IconTheme.JabRefIcons.ATTACH_FILE), + MERGE_ENTRIES(Localization.lang("Merge entries") + "...", IconTheme.JabRefIcons.MERGE_ENTRIES), + ADD_TO_GROUP(Localization.lang("Add to group")), + REMOVE_FROM_GROUP(Localization.lang("Remove from group")), + MOVE_TO_GROUP(Localization.lang("Move to group")), + PRIORITY(Localization.lang("Priority"), IconTheme.JabRefIcons.PRIORITY), + CLEAR_PRIORITY(Localization.lang("Clear priority")), + PRIORITY_HIGH(Localization.lang("Set priority to high"), IconTheme.JabRefIcons.PRIORITY_HIGH), + PRIORITY_MEDIUM(Localization.lang("Set priority to medium"), IconTheme.JabRefIcons.PRIORITY_MEDIUM), + PRIORITY_LOW(Localization.lang("Set priority to low"), IconTheme.JabRefIcons.PRIORITY_LOW), + QUALITY(Localization.lang("Quality"), IconTheme.JabRefIcons.QUALITY), + QUALITY_ASSURED(Localization.lang("Toggle quality assured"), IconTheme.JabRefIcons.QUALITY_ASSURED), + RANKING(Localization.lang("Rank"), IconTheme.JabRefIcons.RANKING), + CLEAR_RANK(Localization.lang("Clear rank")), + RANK_1("", IconTheme.JabRefIcons.RANK1), + RANK_2("", IconTheme.JabRefIcons.RANK2), + RANK_3("", IconTheme.JabRefIcons.RANK3), + RANK_4("", IconTheme.JabRefIcons.RANK4), + RANK_5("", IconTheme.JabRefIcons.RANK5), + PRINTED(Localization.lang("Printed"), IconTheme.JabRefIcons.PRINTED), + TOGGLE_PRINTED(Localization.lang("Toggle print status"), IconTheme.JabRefIcons.PRINTED), + READ_STATUS(Localization.lang("Read status"), IconTheme.JabRefIcons.READ_STATUS), + CLEAR_READ_STATUS(Localization.lang("Clear read status")), + READ(Localization.lang("Set read status to read"), IconTheme.JabRefIcons.READ_STATUS_READ), + SKIMMED(Localization.lang("Set read status to skimmed"), IconTheme.JabRefIcons.READ_STATUS_SKIMMED), + RELEVANCE(Localization.lang("Relevance"), IconTheme.JabRefIcons.RELEVANCE), + RELEVANT(Localization.lang("Toggle relevance"), IconTheme.JabRefIcons.RELEVANCE); + + private final String text; + private final Optional icon; + private final Optional keyBinding; + + ActionsFX(String text) { + this.text = text; + this.icon = Optional.empty(); + this.keyBinding = Optional.empty(); + } + + ActionsFX(String text, IconTheme.JabRefIcons icon) { + this.text = text; + this.icon = Optional.of(icon); + this.keyBinding = Optional.empty(); + } + + ActionsFX(String text, IconTheme.JabRefIcons icon, KeyBinding keyBinding) { + this.text = text; + this.icon = Optional.of(icon); + this.keyBinding = Optional.of(keyBinding); + } + + ActionsFX(String text, KeyBinding keyBinding) { + this.text = text; + this.keyBinding = Optional.of(keyBinding); + this.icon = Optional.empty(); + } + + public Optional getIcon() { + return icon; + } + + public Optional getKeyBinding() { + return keyBinding; + } + + public String getText() { + return text; + } +} diff --git a/src/main/java/org/jabref/gui/actions/JabRefAction.java b/src/main/java/org/jabref/gui/actions/JabRefAction.java new file mode 100644 index 00000000000..dd99c18044b --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/JabRefAction.java @@ -0,0 +1,25 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.keyboard.KeyBindingRepository; + +import de.saxsys.mvvmfx.utils.commands.Command; +import org.controlsfx.control.action.Action; + +/** + * Wrapper around one of our actions from {@link ActionsFX} to convert them to controlsfx {@link Action}. + */ +class JabRefAction extends Action { + + public JabRefAction(ActionsFX action, KeyBindingRepository keyBindingRepository) { + super(action.getText()); + action.getIcon() + .ifPresent(icon -> setGraphic(icon.getGraphicNode())); + action.getKeyBinding() + .ifPresent(keyBinding -> setAccelerator(keyBindingRepository.getKeyCombination(keyBinding))); + } + + public JabRefAction(ActionsFX action, Command command, KeyBindingRepository keyBindingRepository) { + this(action, keyBindingRepository); + setEventHandler(event -> command.execute()); + } +} diff --git a/src/main/java/org/jabref/gui/actions/OldCommandWrapper.java b/src/main/java/org/jabref/gui/actions/OldCommandWrapper.java new file mode 100644 index 00000000000..1fa7ac6774a --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/OldCommandWrapper.java @@ -0,0 +1,50 @@ +package org.jabref.gui.actions; + +import javafx.beans.property.ReadOnlyDoubleProperty; + +import org.jabref.gui.BasePanel; +import org.jabref.gui.util.BindingsHelper; + +import de.saxsys.mvvmfx.utils.commands.CommandBase; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * This wraps the old Swing commands so that they fit into the new infrastructure. + * In the long term, this class should be removed. + */ +public class OldCommandWrapper extends CommandBase { + + private static final Log LOGGER = LogFactory.getLog(OldCommandWrapper.class); + + private final Actions command; + private final BasePanel panel; + + public OldCommandWrapper(Actions command, BasePanel panel) { + this.command = command; + this.panel = panel; + } + + @Override + public void execute() { + try { + panel.runCommand(command); + } catch (Throwable ex) { + LOGGER.debug("Cannot execute command " + command + ".", ex); + } + } + + @Override + public double getProgress() { + return 0; + } + + @Override + public ReadOnlyDoubleProperty progressProperty() { + return null; + } + + public void setExecutable(boolean executable) { + this.executable.bind(BindingsHelper.constantOf(executable)); + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/JTextAreaWithHighlighting.java b/src/main/java/org/jabref/gui/fieldeditors/JTextAreaWithHighlighting.java index f633b142e4b..909fa05778d 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/JTextAreaWithHighlighting.java +++ b/src/main/java/org/jabref/gui/fieldeditors/JTextAreaWithHighlighting.java @@ -85,7 +85,7 @@ public void actionPerformed(ActionEvent evt) { getInputMap().put(Globals.getKeyPrefs().getKey(org.jabref.gui.keyboard.KeyBinding.UNDO), "Undo"); // Create a redo action and add it to the text component - getActionMap().put("Redo", new AbstractAction(Actions.REDO) { + getActionMap().put("Redo", new AbstractAction(Actions.REDO.name()) { @Override public void actionPerformed(ActionEvent evt) { diff --git a/src/main/java/org/jabref/gui/fieldeditors/TextField.java b/src/main/java/org/jabref/gui/fieldeditors/TextField.java index 6a240db224d..ba89717e38f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/TextField.java +++ b/src/main/java/org/jabref/gui/fieldeditors/TextField.java @@ -163,7 +163,7 @@ public void actionPerformed(ActionEvent evt) { getInputMap().put(Globals.getKeyPrefs().getKey(org.jabref.gui.keyboard.KeyBinding.UNDO), "Undo"); // Create a redo action and add it to the text component - getActionMap().put("Redo", new AbstractAction(Actions.REDO) { + getActionMap().put("Redo", new AbstractAction(Actions.REDO.name()) { @Override public void actionPerformed(ActionEvent evt) { diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 07e4044b26e..63ef218c6ca 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -18,6 +18,7 @@ import org.jabref.gui.EntryMarker; import org.jabref.gui.JabRefFrame; import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.renderer.CompleteRenderer; import org.jabref.gui.renderer.GeneralRenderer; import org.jabref.gui.renderer.IncompleteRenderer; @@ -72,7 +73,7 @@ private enum CellRendererMode { } public MainTable(MainTableDataModel model, JabRefFrame frame, - BasePanel panel, BibDatabase database, MainTablePreferences preferences, ExternalFileTypes externalFileTypes) { + BasePanel panel, BibDatabase database, MainTablePreferences preferences, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository) { super(); this.model = model; @@ -83,7 +84,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, panel.showAndEdit(entry.getEntry()); } }) - .withContextMenu(RightClickMenu::create)); + .withContextMenu(entry1 -> RightClickMenu.create(entry1, keyBindingRepository, panel, Globals.getKeyPrefs()))); if (preferences.resizeColumnsToFit()) { this.setColumnResizePolicy(new SmartConstrainedResizePolicy()); } diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index 88b80af064f..ce7e20d7b7d 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -1,40 +1,26 @@ package org.jabref.gui.maintable; -import java.awt.event.ActionEvent; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JPopupMenu; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; import javafx.scene.control.ContextMenu; +import javafx.scene.control.Menu; +import javafx.scene.control.MenuItem; +import javafx.scene.control.SeparatorMenuItem; import org.jabref.Globals; import org.jabref.gui.BasePanel; -import org.jabref.gui.EntryMarker; -import org.jabref.gui.IconTheme; -import org.jabref.gui.JabRefFrame; +import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.Actions; -import org.jabref.gui.copyfiles.CopyFilesAction; -import org.jabref.gui.filelist.FileListTableModel; -import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.gui.actions.ActionsFX; +import org.jabref.gui.actions.OldCommandWrapper; +import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.menus.ChangeEntryTypeMenu; import org.jabref.gui.mergeentries.FetchAndMergeEntry; -import org.jabref.gui.specialfields.SpecialFieldMenuAction; import org.jabref.gui.specialfields.SpecialFieldValueViewModel; import org.jabref.gui.specialfields.SpecialFieldViewModel; -import org.jabref.gui.worker.MarkEntriesAction; import org.jabref.logic.citationstyle.CitationStyle; -import org.jabref.logic.l10n.Localization; +import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; import org.jabref.model.entry.specialfields.SpecialField; @@ -45,290 +31,184 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -public class RightClickMenu extends JPopupMenu implements PopupMenuListener { +public class RightClickMenu { private static final Log LOGGER = LogFactory.getLog(RightClickMenu.class); - private final BasePanel panel; - private final JMenuItem groupAdd; - private final JMenuItem groupRemove; - private final JMenuItem groupMoveTo; - - - public RightClickMenu(JabRefFrame frame, BasePanel panel) { - this.panel = panel; - JMenu typeMenu = new ChangeEntryTypeMenu(Globals.getKeyPrefs()).getChangeEntryTypeMenu(panel); - // Are multiple entries selected? - boolean multiple = areMultipleEntriesSelected(); - - // If only one entry is selected, get a reference to it for adapting the menu. - BibEntry be = null; - if (panel.getMainTable().getSelectedEntries().size() == 1) { - be = panel.getMainTable().getSelectedEntries().get(0); - } - - addPopupMenuListener(this); - - JMenu copySpecialMenu = new JMenu(Localization.lang("Copy") + "..."); - copySpecialMenu.add(new GeneralAction(Actions.COPY_TITLE, Localization.lang("Copy title"), KeyBinding.COPY_TITLE)); - copySpecialMenu.add(new GeneralAction(Actions.COPY_KEY, Localization.lang("Copy BibTeX key"), KeyBinding.COPY_BIBTEX_KEY)); - copySpecialMenu.add(new GeneralAction(Actions.COPY_CITE_KEY, Localization.lang("Copy \\cite{BibTeX key}"), KeyBinding.COPY_CITE_BIBTEX_KEY)); - copySpecialMenu.add(new GeneralAction(Actions.COPY_KEY_AND_TITLE, Localization.lang("Copy BibTeX key and title"), KeyBinding.COPY_BIBTEX_KEY_AND_TITLE)); - copySpecialMenu.add(new GeneralAction(Actions.COPY_KEY_AND_LINK, Localization.lang("Copy BibTeX key and link"), KeyBinding.COPY_BIBTEX_KEY_AND_LINK)); - - // the submenu will behave dependent on what style is currently selected (citation/preview) - PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences(); - String style = previewPreferences.getPreviewCycle().get(previewPreferences.getPreviewCyclePosition()); - if (CitationStyle.isCitationStyleFile(style)) { - copySpecialMenu.add(new GeneralAction(Actions.COPY_CITATION_HTML, Localization.menuTitle("Copy citation") + " (HTML)", KeyBinding.COPY_PREVIEW)); - JMenu copyCitationMenu = new JMenu(Localization.menuTitle("Copy citation") + "..."); - copyCitationMenu.add(new GeneralAction(Actions.COPY_CITATION_TEXT, "Text")); - copyCitationMenu.add(new GeneralAction(Actions.COPY_CITATION_RTF, "RTF")); - copyCitationMenu.add(new GeneralAction(Actions.COPY_CITATION_ASCII_DOC, "AsciiDoc")); - copyCitationMenu.add(new GeneralAction(Actions.COPY_CITATION_XSLFO, "XSL-FO")); - copySpecialMenu.add(copyCitationMenu); - } else { - copySpecialMenu.add(new GeneralAction(Actions.COPY_CITATION_HTML, Localization.lang("Copy preview"), KeyBinding.COPY_PREVIEW)); - } - - copySpecialMenu.add(new GeneralAction(Actions.EXPORT_TO_CLIPBOARD, Localization.lang("Export to clipboard"), - IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD.getSmallIcon())); + public static ContextMenu create(BibEntryTableViewModel entry, KeyBindingRepository keyBindingRepository, BasePanel panel, KeyBindingRepository keyBindings) { + ContextMenu contextMenu = new ContextMenu(); + ActionFactory factory = new ActionFactory(keyBindingRepository); - add(new GeneralAction(Actions.COPY, Localization.lang("Copy"), IconTheme.JabRefIcons.COPY.getSmallIcon(), KeyBinding.COPY)); - add(copySpecialMenu); - add(new GeneralAction(Actions.PASTE, Localization.lang("Paste"), IconTheme.JabRefIcons.PASTE.getSmallIcon(), KeyBinding.PASTE)); - add(new GeneralAction(Actions.CUT, Localization.lang("Cut"), IconTheme.JabRefIcons.CUT.getSmallIcon(), KeyBinding.CUT)); - add(new GeneralAction(Actions.DELETE, Localization.lang("Delete"), IconTheme.JabRefIcons.DELETE_ENTRY.getSmallIcon(), KeyBinding.DELETE_ENTRY)); - GeneralAction printPreviewAction = new GeneralAction(Actions.PRINT_PREVIEW, Localization.lang("Print entry preview"), IconTheme.JabRefIcons.PRINTED.getSmallIcon()); - printPreviewAction.setEnabled(!multiple); - add(printPreviewAction); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY, new OldCommandWrapper(Actions.COPY, panel))); + contextMenu.getItems().add(createCopySubMenu(panel, factory)); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.PASTE, new OldCommandWrapper(Actions.PASTE, panel))); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.CUT, new OldCommandWrapper(Actions.CUT, panel))); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.DELETE, new OldCommandWrapper(Actions.DELETE, panel))); - addSeparator(); + contextMenu.getItems().add(new SeparatorMenuItem()); - add(new GeneralAction(Actions.SEND_AS_EMAIL, Localization.lang("Send as email"), IconTheme.JabRefIcons.EMAIL.getSmallIcon())); - addSeparator(); - add(new CopyFilesAction()); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.SEND_AS_EMAIL, new OldCommandWrapper(Actions.SEND_AS_EMAIL, panel))); - JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color")); - markSpecific.setIcon(IconTheme.JabRefIcons.MARK_ENTRIES.getSmallIcon()); - for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) { - markSpecific.add(new MarkEntriesAction(frame, i).getMenuItem()); - } - - if (multiple) { - add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entries"), IconTheme.JabRefIcons.MARK_ENTRIES.getSmallIcon(), KeyBinding.MARK_ENTRIES)); - add(markSpecific); - add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entries"), IconTheme.JabRefIcons.UNMARK_ENTRIES.getSmallIcon(), KeyBinding.UNMARK_ENTRIES)); - } else if (be != null) { - Optional marked = be.getField(FieldName.MARKED_INTERNAL); - // We have to check for "" too as the marked field may be empty - if ((!marked.isPresent()) || marked.get().isEmpty()) { - add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entry"), IconTheme.JabRefIcons.MARK_ENTRIES.getSmallIcon(), KeyBinding.MARK_ENTRIES)); - add(markSpecific); - } else { - add(markSpecific); - add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entry"), IconTheme.JabRefIcons.UNMARK_ENTRIES.getSmallIcon(), KeyBinding.UNMARK_ENTRIES)); - } - } + contextMenu.getItems().add(new SeparatorMenuItem()); if (Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) { if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) { - JMenu rankingMenu = new JMenu(); - RightClickMenu.populateSpecialFieldMenu(rankingMenu, SpecialField.RANKING, frame); - add(rankingMenu); + contextMenu.getItems().add(createSpecialFieldMenu(SpecialField.RANKING, factory, panel)); } - // TODO: multiple handling for relevance and quality-assurance - // if multiple values are selected ("if (multiple)"), two options (set / clear) should be offered - // if one value is selected either set or clear should be offered if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RELEVANCE)) { - add(new SpecialFieldMenuAction(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)), frame)); + contextMenu.getItems().add(getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, panel)); } + if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_QUALITY)) { - add(new SpecialFieldMenuAction(new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)), frame)); + contextMenu.getItems().add(getSpecialFieldSingleItem(SpecialField.QUALITY, factory, panel)); } + if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRINTED)) { - add(new SpecialFieldMenuAction(new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)), frame)); + contextMenu.getItems().add(getSpecialFieldSingleItem(SpecialField.PRINTED, factory, panel)); } if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) { - JMenu priorityMenu = new JMenu(); - RightClickMenu.populateSpecialFieldMenu(priorityMenu, SpecialField.PRIORITY, frame); - add(priorityMenu); + Menu priorityMenu = createSpecialFieldMenu(SpecialField.PRIORITY, factory, panel); + contextMenu.getItems().add(priorityMenu); } if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) { - JMenu readStatusMenu = new JMenu(); - RightClickMenu.populateSpecialFieldMenu(readStatusMenu, SpecialField.READ_STATUS, frame); - add(readStatusMenu); + Menu readStatusMenu = createSpecialFieldMenu(SpecialField.READ_STATUS, factory, panel); + contextMenu.getItems().add(readStatusMenu); } - } - addSeparator(); - - GeneralAction openFolderAction = new GeneralAction(Actions.OPEN_FOLDER, Localization.lang("Open folder"), - KeyBinding.OPEN_FOLDER); - openFolderAction.setEnabled(isFieldSetForSelectedEntry(FieldName.FILE)); - add(openFolderAction); - - GeneralAction openFileAction = new GeneralAction(Actions.OPEN_EXTERNAL_FILE, Localization.lang("Open file"), - getFileIconForSelectedEntry(), KeyBinding.OPEN_FILE); - openFileAction.setEnabled(isFieldSetForSelectedEntry(FieldName.FILE)); - add(openFileAction); + contextMenu.getItems().add(new SeparatorMenuItem()); - GeneralAction openUrlAction = new GeneralAction(Actions.OPEN_URL, Localization.lang("Open URL or DOI"), - IconTheme.JabRefIcons.WWW.getSmallIcon(), KeyBinding.OPEN_URL_OR_DOI); - openUrlAction.setEnabled(isFieldSetForSelectedEntry(FieldName.URL) || isFieldSetForSelectedEntry(FieldName.DOI)); - add(openUrlAction); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.OPEN_FOLDER, getOpenFolderCommand(panel))); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.OPEN_EXTERNAL_FILE, getOpenExternalFileCommand(panel))); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.OPEN_URL, getOpenUrlCommand(panel))); - addSeparator(); + contextMenu.getItems().add(new SeparatorMenuItem()); - add(typeMenu); + contextMenu.getItems().add(new ChangeEntryTypeMenu(keyBindings).getChangeEntryTypeMenu(entry.getEntry(), panel.getBibDatabaseContext(), panel.getUndoManager())); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.MERGE_WITH_FETCHED_ENTRY, getFetchEntryData(panel))); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.ADD_FILE_LINK, getAddFileLinkCommand(panel))); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.MERGE_ENTRIES, mergeEntries(panel))); - GeneralAction mergeFetchedEntryAction = new GeneralAction(Actions.MERGE_WITH_FETCHED_ENTRY, - Localization.lang("Get BibTeX data from %0", FetchAndMergeEntry.getDisplayNameOfSupportedFields())); - mergeFetchedEntryAction.setEnabled(isAnyFieldSetForSelectedEntry(FetchAndMergeEntry.SUPPORTED_FIELDS)); - add(mergeFetchedEntryAction); + contextMenu.getItems().add(new SeparatorMenuItem()); - add(frame.getMassSetField()); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.ADD_TO_GROUP, addToGroup(panel))); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.REMOVE_FROM_GROUP, removeFromGroup(panel))); + contextMenu.getItems().add(factory.createMenuItem(ActionsFX.MOVE_TO_GROUP, moveToGroup(panel))); - GeneralAction attachFileAction = new GeneralAction(Actions.ADD_FILE_LINK, Localization.lang("Attach file"), - IconTheme.JabRefIcons.ATTACH_FILE.getSmallIcon()); - attachFileAction.setEnabled(!multiple); - add(attachFileAction); - - add(frame.getManageKeywords()); - - GeneralAction mergeEntriesAction = new GeneralAction(Actions.MERGE_ENTRIES, - Localization.lang("Merge entries") + "...", IconTheme.JabRefIcons.MERGE_ENTRIES.getSmallIcon()); - mergeEntriesAction.setEnabled(areExactlyTwoEntriesSelected()); - add(mergeEntriesAction); - - addSeparator(); // for "add/move/remove to/from group" entries (appended here) - - groupAdd = new JMenuItem(new GeneralAction(Actions.ADD_TO_GROUP, Localization.lang("Add to group"))); - add(groupAdd); - groupRemove = new JMenuItem(new GeneralAction(Actions.REMOVE_FROM_GROUP, Localization.lang("Remove from group"))); - add(groupRemove); - - groupMoveTo = add(new GeneralAction(Actions.MOVE_TO_GROUP, Localization.lang("Move to group"))); - add(groupMoveTo); - - // create disabledIcons for all menu entries - frame.createDisabledIconsForMenuEntries(this); + return contextMenu; } - /** - * Remove all types from the menu. - * Then cycle through all available values, and add them. - */ - public static void populateSpecialFieldMenu(JMenu menu, SpecialField field, JabRefFrame frame) { - SpecialFieldViewModel viewModel = new SpecialFieldViewModel(field); - menu.setText(viewModel.getLocalization()); - menu.setIcon(viewModel.getRepresentingIcon()); - for (SpecialFieldValue val : field.getValues()) { - menu.add(new SpecialFieldMenuAction(new SpecialFieldValueViewModel(val), frame)); - } + private static OldCommandWrapper moveToGroup(BasePanel panel) { + OldCommandWrapper command = new OldCommandWrapper(Actions.MOVE_TO_GROUP, panel); + command.setExecutable(areGroupsPresent(panel.getBibDatabaseContext())); + return command; } - private boolean areMultipleEntriesSelected() { - return panel.getMainTable().getSelectedEntries().size() > 1; + private static OldCommandWrapper removeFromGroup(BasePanel panel) { + OldCommandWrapper command = new OldCommandWrapper(Actions.REMOVE_FROM_GROUP, panel); + command.setExecutable(areGroupsPresent(panel.getBibDatabaseContext())); + return command; } - private boolean areExactlyTwoEntriesSelected() { - return panel.getMainTable().getSelectedEntries().size() == 2; + private static OldCommandWrapper addToGroup(BasePanel panel) { + OldCommandWrapper command = new OldCommandWrapper(Actions.ADD_TO_GROUP, panel); + command.setExecutable(areGroupsPresent(panel.getBibDatabaseContext())); + return command; } - /** - * Set the dynamic contents of "Add to group ..." submenu. - */ - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - boolean groupsPresent = panel.getBibDatabaseContext().getMetaData().getGroups().isPresent(); - groupAdd.setEnabled(groupsPresent); - groupRemove.setEnabled(groupsPresent); - groupMoveTo.setEnabled(groupsPresent); + private static OldCommandWrapper mergeEntries(BasePanel panel) { + OldCommandWrapper command = new OldCommandWrapper(Actions.MERGE_ENTRIES, panel); + command.setExecutable(panel.getMainTable().getSelectedEntries().size() == 2); + return command; } - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - // Nothing to do + private static OldCommandWrapper getAddFileLinkCommand(BasePanel panel) { + OldCommandWrapper command = new OldCommandWrapper(Actions.ADD_FILE_LINK, panel); + command.setExecutable(panel.getMainTable().getSelectedEntries().size() == 1); + return command; } - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - // nothing to do + private static OldCommandWrapper getFetchEntryData(BasePanel panel) { + OldCommandWrapper command = new OldCommandWrapper(Actions.MERGE_WITH_FETCHED_ENTRY, panel); + command.setExecutable(isAnyFieldSetForSelectedEntry(FetchAndMergeEntry.SUPPORTED_FIELDS, panel)); + return command; } - private boolean isFieldSetForSelectedEntry(String fieldname) { - return isAnyFieldSetForSelectedEntry(Arrays.asList(fieldname)); + private static OldCommandWrapper getOpenUrlCommand(BasePanel panel) { + OldCommandWrapper command = new OldCommandWrapper(Actions.OPEN_URL, panel); + command.setExecutable(isFieldSetForSelectedEntry(FieldName.URL, panel) || isFieldSetForSelectedEntry(FieldName.DOI, panel)); + return command; } - private boolean isAnyFieldSetForSelectedEntry(List fieldnames) { - if (panel.getMainTable().getSelectedEntries().size() == 1) { - BibEntry entry = panel.getMainTable().getSelectedEntries().get(0); - return !Collections.disjoint(fieldnames, entry.getFieldNames()); - } - return false; + private static OldCommandWrapper getOpenExternalFileCommand(BasePanel panel) { + OldCommandWrapper command = new OldCommandWrapper(Actions.OPEN_EXTERNAL_FILE, panel); + command.setExecutable(isFieldSetForSelectedEntry(FieldName.FILE, panel)); + return command; } - private Icon getFileIconForSelectedEntry() { - if (panel.getMainTable().getSelectedEntries().size() == 1) { - BibEntry entry = panel.getMainTable().getSelectedEntries().get(0); - if (entry.hasField(FieldName.FILE)) { - JLabel label = FileListTableModel.getFirstLabel(entry.getField(FieldName.FILE).get()); - if (label != null) { - return label.getIcon(); - } - } - } - return IconTheme.JabRefIcons.FILE.getSmallIcon(); + private static OldCommandWrapper getOpenFolderCommand(BasePanel panel) { + OldCommandWrapper command = new OldCommandWrapper(Actions.OPEN_FOLDER, panel); + command.setExecutable(isFieldSetForSelectedEntry(FieldName.FILE, panel)); + return command; } - class GeneralAction extends AbstractAction { - - private final String command; - - public GeneralAction(String command, String name) { - super(name); - this.command = command; - } + private static MenuItem getSpecialFieldSingleItem(SpecialField field, ActionFactory factory, BasePanel panel) { + SpecialFieldValueViewModel specialField = new SpecialFieldValueViewModel(field.getValues().get(0)); + return factory.createMenuItem(specialField.getAction(), new OldCommandWrapper(specialField.getCommand(), panel)); + } - public GeneralAction(String command, String name, Icon icon) { - super(name, icon); - this.command = command; - } + private static Menu createCopySubMenu(BasePanel panel, ActionFactory factory) { + Menu copySpecialMenu = factory.createMenu(ActionsFX.COPY_MORE); + copySpecialMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY_TITLE, new OldCommandWrapper(Actions.COPY_TITLE, panel))); + copySpecialMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY_KEY, new OldCommandWrapper(Actions.COPY_KEY, panel))); + copySpecialMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY_CITE_KEY, new OldCommandWrapper(Actions.COPY_CITE_KEY, panel))); + copySpecialMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY_KEY_AND_TITLE, new OldCommandWrapper(Actions.COPY_KEY_AND_TITLE, panel))); + copySpecialMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY_KEY_AND_LINK, new OldCommandWrapper(Actions.COPY_KEY_AND_LINK, panel))); - public GeneralAction(String command, String name, KeyBinding key) { - super(name); - this.command = command; - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(key)); + // the submenu will behave dependent on what style is currently selected (citation/preview) + PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences(); + String style = previewPreferences.getPreviewCycle().get(previewPreferences.getPreviewCyclePosition()); + if (CitationStyle.isCitationStyleFile(style)) { + copySpecialMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY_CITATION_HTML, new OldCommandWrapper(Actions.COPY_CITATION_HTML, panel))); + Menu copyCitationMenu = factory.createMenu(ActionsFX.COPY_CITATION_MORE); + copyCitationMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY_CITATION_TEXT, new OldCommandWrapper(Actions.COPY_CITATION_TEXT, panel))); + copyCitationMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY_CITATION_RTF, new OldCommandWrapper(Actions.COPY_CITATION_RTF, panel))); + copyCitationMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY_CITATION_ASCII_DOC, new OldCommandWrapper(Actions.COPY_CITATION_ASCII_DOC, panel))); + copyCitationMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY_CITATION_XSLFO, new OldCommandWrapper(Actions.COPY_CITATION_XSLFO, panel))); + copySpecialMenu.getItems().add(copyCitationMenu); + } else { + copySpecialMenu.getItems().add(factory.createMenuItem(ActionsFX.COPY_CITATION_PREVIEW, new OldCommandWrapper(Actions.COPY_CITATION_HTML, panel))); } - public GeneralAction(String command, String name, Icon icon, KeyBinding key) { - super(name, icon); - this.command = command; - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(key)); - } + copySpecialMenu.getItems().add(factory.createMenuItem(ActionsFX.EXPORT_TO_CLIPBOARD, new OldCommandWrapper(Actions.EXPORT_TO_CLIPBOARD, panel))); + return copySpecialMenu; + } - @Override - public void actionPerformed(ActionEvent e) { - try { - panel.runCommand(command); - } catch (Throwable ex) { - LOGGER.debug("Cannot execute command " + command + ".", ex); - } + private static Menu createSpecialFieldMenu(SpecialField field, ActionFactory factory, BasePanel panel) { + SpecialFieldViewModel viewModel = new SpecialFieldViewModel(field); + Menu menu = factory.createMenu(viewModel.getAction()); + for (SpecialFieldValue val : field.getValues()) { + SpecialFieldValueViewModel specialField = new SpecialFieldValueViewModel(val); + menu.getItems().add(factory.createMenuItem(specialField.getAction(), new OldCommandWrapper(specialField.getCommand(), panel))); } + return menu; } - public static ContextMenu create(BibEntryTableViewModel entry) { - ContextMenu contextMenu = new ContextMenu(); + private static boolean areGroupsPresent(BibDatabaseContext database) { + return database.getMetaData().getGroups().isPresent(); + } - javafx.scene.control.MenuItem copy = new javafx.scene.control.MenuItem(); - copy.setText(Localization.lang("Copy")); - copy.setGraphic(IconTheme.JabRefIcons.COPY.getGraphicNode()); - contextMenu.getItems().add(copy); + private static boolean isFieldSetForSelectedEntry(String field, BasePanel panel) { + return isAnyFieldSetForSelectedEntry(Collections.singletonList(field), panel); + } - return contextMenu; + private static boolean isAnyFieldSetForSelectedEntry(List fields, BasePanel panel) { + if (panel.getMainTable().getSelectedEntries().size() == 1) { + BibEntry entry = panel.getMainTable().getSelectedEntries().get(0); + return !Collections.disjoint(fields, entry.getFieldNames()); + } + return false; } } diff --git a/src/main/java/org/jabref/gui/menus/ChangeEntryTypeMenu.java b/src/main/java/org/jabref/gui/menus/ChangeEntryTypeMenu.java index 0b5b7625a24..d8b62b42b00 100644 --- a/src/main/java/org/jabref/gui/menus/ChangeEntryTypeMenu.java +++ b/src/main/java/org/jabref/gui/menus/ChangeEntryTypeMenu.java @@ -11,8 +11,10 @@ import javax.swing.KeyStroke; import javax.swing.undo.UndoManager; +import javafx.collections.ObservableList; import javafx.scene.control.ContextMenu; import javafx.scene.control.Menu; +import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import org.jabref.gui.BasePanel; @@ -51,47 +53,54 @@ public JMenu getChangeEntryTypeMenu(BasePanel panel) { public ContextMenu getChangeEntryTypePopupMenu(BibEntry entry, BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager) { ContextMenu menu = new ContextMenu(); + populateComplete(menu.getItems(), entry, bibDatabaseContext, undoManager); + return menu; + } + + public Menu getChangeEntryTypeMenu(BibEntry entry, BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager) { + Menu menu = new Menu(); + menu.setText(Localization.lang("Change entry type")); + populateComplete(menu.getItems(), entry, bibDatabaseContext, undoManager); + return menu; + } + private void populateComplete(ObservableList items, BibEntry entry, BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager) { if (bibDatabaseContext.isBiblatexMode()) { // Default BibLaTeX - populate(menu, EntryTypes.getAllValues(BibDatabaseMode.BIBLATEX), entry, undoManager); + populate(items, EntryTypes.getAllValues(BibDatabaseMode.BIBLATEX), entry, undoManager); // Custom types - populateSubMenu(menu, Localization.lang("Custom"), EntryTypes.getAllCustomTypes(BibDatabaseMode.BIBLATEX), entry, undoManager); + populateSubMenu(items, Localization.lang("Custom"), EntryTypes.getAllCustomTypes(BibDatabaseMode.BIBLATEX), entry, undoManager); } else { // Default BibTeX - populateSubMenu(menu, Localization.BIBTEX, BibtexEntryTypes.ALL, entry, undoManager); - menu.getItems().remove(0); // Remove separator + populateSubMenu(items, Localization.BIBTEX, BibtexEntryTypes.ALL, entry, undoManager); + items.remove(0); // Remove separator // IEEETran - populateSubMenu(menu, "IEEETran", IEEETranEntryTypes.ALL, entry, undoManager); + populateSubMenu(items, "IEEETran", IEEETranEntryTypes.ALL, entry, undoManager); // Custom types - populateSubMenu(menu, Localization.lang("Custom"), EntryTypes.getAllCustomTypes(BibDatabaseMode.BIBTEX), entry, undoManager); + populateSubMenu(items, Localization.lang("Custom"), EntryTypes.getAllCustomTypes(BibDatabaseMode.BIBTEX), entry, undoManager); } - - return menu; } - private void populateSubMenu(ContextMenu menu, String text, List entryTypes, BibEntry entry, CountingUndoManager undoManager) { + private void populateSubMenu(ObservableList items, String text, List entryTypes, BibEntry entry, CountingUndoManager undoManager) { if (!entryTypes.isEmpty()) { - menu.getItems().add(new SeparatorMenuItem()); + items.add(new SeparatorMenuItem()); Menu custom = new Menu(text); populate(custom, entryTypes, entry, undoManager); - menu.getItems().add(custom); + items.add(custom); } } - private void populate(ContextMenu menu, Collection types, BibEntry entry, UndoManager undoManager) { + private void populate(ObservableList items, Collection types, BibEntry entry, UndoManager undoManager) { for (EntryType type : types) { - menu.getItems().add(ChangeTypeAction.as(type, entry, undoManager)); + items.add(ChangeTypeAction.as(type, entry, undoManager)); } } private void populate(Menu menu, Collection types, BibEntry entry, UndoManager undoManager) { - for (EntryType type : types) { - menu.getItems().add(ChangeTypeAction.as(type, entry, undoManager)); - } + populate(menu.getItems(), types, entry, undoManager); } /** diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index 2dcda823439..add51e29eb4 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -2,7 +2,6 @@ import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; import org.jabref.JabRefGUI; import org.jabref.gui.BasePanel; @@ -50,10 +49,4 @@ public FetchAndMergeEntry(BibEntry entry, BasePanel panel, List fields) } } } - - public static String getDisplayNameOfSupportedFields() { - return FieldName.orFields(SUPPORTED_FIELDS.stream() - .map(FieldName::getDisplayName) - .collect(Collectors.toList())); - } } diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldDropDown.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldDropDown.java index 7e3245571fc..bf854ef6f8d 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldDropDown.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldDropDown.java @@ -11,6 +11,7 @@ import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.actions.Actions; import org.jabref.logic.util.OS; import org.jabref.model.entry.specialfields.SpecialField; import org.jabref.model.entry.specialfields.SpecialFieldValue; @@ -66,7 +67,7 @@ public void actionPerformed(ActionEvent e) { JMenuItem item = new JMenuItem(viewModel.getSpecialFieldValueIcon()); item.setText(viewModel.getMenuString()); item.setToolTipText(viewModel.getToolTipText()); - item.addActionListener(new PopupitemActionListener(frame.getCurrentBasePanel(), new SpecialFieldValueViewModel(val).getActionName())); + item.addActionListener(new PopupitemActionListener(frame.getCurrentBasePanel(), new SpecialFieldValueViewModel(val).getCommand())); item.setMargin(new Insets(0, 0, 0, 0)); popup.add(item); } @@ -77,10 +78,9 @@ public void actionPerformed(ActionEvent e) { private class PopupitemActionListener implements ActionListener { private final BasePanel panel; - private final String actionName; + private final Actions actionName; - - public PopupitemActionListener(BasePanel panel, String actionName) { + public PopupitemActionListener(BasePanel panel, Actions actionName) { this.panel = panel; this.actionName = actionName; } diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldMenuAction.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldMenuAction.java deleted file mode 100644 index f845fc0d971..00000000000 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldMenuAction.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.jabref.gui.specialfields; - -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; - -import org.jabref.gui.JabRefFrame; - -public class SpecialFieldMenuAction extends AbstractAction { - - private final JabRefFrame frame; - private final String actionName; - - - public SpecialFieldMenuAction(SpecialFieldValueViewModel val, JabRefFrame frame) { - super(val.getMenuString(), val.getSpecialFieldValueIcon()); - this.frame = frame; - this.actionName = val.getActionName(); - } - - @Override - public void actionPerformed(ActionEvent evt) { - if (frame.getCurrentBasePanel() != null) { - frame.getCurrentBasePanel().runCommand(actionName); - } - } -} diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java index 54b6166d949..0273b9f59a4 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java @@ -5,8 +5,9 @@ import javax.swing.Icon; import javax.swing.JLabel; -import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefIcon; +import org.jabref.gui.actions.Actions; +import org.jabref.gui.actions.ActionsFX; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.specialfields.SpecialFieldValue; @@ -30,42 +31,7 @@ public Icon getSpecialFieldValueIcon() { } public JabRefIcon getIcon() { - switch (value) { - case PRINTED: - return IconTheme.JabRefIcons.PRINTED; - case CLEAR_PRIORITY: - return null; - case PRIORITY_HIGH: - return IconTheme.JabRefIcons.PRIORITY_HIGH; - case PRIORITY_MEDIUM: - return IconTheme.JabRefIcons.PRIORITY_MEDIUM; - case PRIORITY_LOW: - return IconTheme.JabRefIcons.PRIORITY_LOW; - case QUALITY_ASSURED: - return IconTheme.JabRefIcons.QUALITY_ASSURED; - case CLEAR_RANK: - return null; - case RANK_1: - return IconTheme.JabRefIcons.RANK1; - case RANK_2: - return IconTheme.JabRefIcons.RANK2; - case RANK_3: - return IconTheme.JabRefIcons.RANK3; - case RANK_4: - return IconTheme.JabRefIcons.RANK4; - case RANK_5: - return IconTheme.JabRefIcons.RANK5; - case CLEAR_READ_STATUS: - return null; - case READ: - return IconTheme.JabRefIcons.READ_STATUS_READ; - case SKIMMED: - return IconTheme.JabRefIcons.READ_STATUS_SKIMMED; - case RELEVANT: - return IconTheme.JabRefIcons.RELEVANCE; - default: - throw new IllegalArgumentException("There is no icon mapping for special field value " + value); - } + return getAction().getIcon().orElse(null); } public JLabel createSpecialFieldValueLabel() { @@ -75,38 +41,42 @@ public JLabel createSpecialFieldValueLabel() { } public String getMenuString() { + return getAction().getText(); + } + + public String getToolTipText() { switch (value) { case PRINTED: return Localization.lang("Toggle print status"); case CLEAR_PRIORITY: - return Localization.lang("Clear priority"); + return Localization.lang("No priority information"); case PRIORITY_HIGH: - return Localization.lang("Set priority to high"); + return Localization.lang("Priority high"); case PRIORITY_MEDIUM: - return Localization.lang("Set priority to medium"); + return Localization.lang("Priority medium"); case PRIORITY_LOW: - return Localization.lang("Set priority to low"); + return Localization.lang("Priority low"); case QUALITY_ASSURED: return Localization.lang("Toggle quality assured"); case CLEAR_RANK: - return Localization.lang("Clear rank"); + return Localization.lang("No rank information"); case RANK_1: - return ""; + return Localization.lang("One star"); case RANK_2: - return ""; + return Localization.lang("Two stars"); case RANK_3: - return ""; + return Localization.lang("Three stars"); case RANK_4: - return ""; + return Localization.lang("Four stars"); case RANK_5: - return ""; + return Localization.lang("Five stars"); case CLEAR_READ_STATUS: - return Localization.lang("Clear read status"); + return Localization.lang("No read status information"); case READ: - return Localization.lang("Set read status to read"); + return Localization.lang("Read status read"); case SKIMMED: - return Localization.lang("Set read status to skimmed"); + return Localization.lang("Read status skimmed"); case RELEVANT: return Localization.lang("Toggle relevance"); default: @@ -114,83 +84,81 @@ public String getMenuString() { } } - public String getToolTipText() { - + public Actions getCommand() { switch (value) { case PRINTED: - return Localization.lang("Toggle print status"); + return Actions.togglePrinted; case CLEAR_PRIORITY: - return Localization.lang("No priority information"); + return Actions.clearPriority; case PRIORITY_HIGH: - return Localization.lang("Priority high"); + return Actions.setPriority1; case PRIORITY_MEDIUM: - return Localization.lang("Priority medium"); + return Actions.setPriority2; case PRIORITY_LOW: - return Localization.lang("Priority low"); + return Actions.setPriority3; case QUALITY_ASSURED: - return Localization.lang("Toggle quality assured"); + return Actions.toggleQualityAssured; case CLEAR_RANK: - return Localization.lang("No rank information"); + return Actions.clearRank; case RANK_1: - return Localization.lang("One star"); + return Actions.setRank1; case RANK_2: - return Localization.lang("Two stars"); + return Actions.setRank2; case RANK_3: - return Localization.lang("Three stars"); + return Actions.setRank3; case RANK_4: - return Localization.lang("Four stars"); + return Actions.setRank4; case RANK_5: - return Localization.lang("Five stars"); + return Actions.setRank5; case CLEAR_READ_STATUS: - return Localization.lang("No read status information"); + return Actions.clearReadStatus; case READ: - return Localization.lang("Read status read"); + return Actions.setReadStatusToRead; case SKIMMED: - return Localization.lang("Read status skimmed"); + return Actions.setReadStatusToSkimmed; case RELEVANT: - return Localization.lang("Toggle relevance"); + return Actions.toggleRelevance; default: - throw new IllegalArgumentException("There is no tooltip localization for special field value " + value); + throw new IllegalArgumentException("There is no action name for special field value " + value); } } - public String getActionName() { - + public ActionsFX getAction() { switch (value) { case PRINTED: - return "togglePrinted"; + return ActionsFX.TOGGLE_PRINTED; case CLEAR_PRIORITY: - return "clearPriority"; + return ActionsFX.CLEAR_PRIORITY; case PRIORITY_HIGH: - return "setPriority1"; + return ActionsFX.PRIORITY_HIGH; case PRIORITY_MEDIUM: - return "setPriority2"; + return ActionsFX.PRIORITY_MEDIUM; case PRIORITY_LOW: - return "setPriority3"; + return ActionsFX.PRIORITY_LOW; case QUALITY_ASSURED: - return "toggleQualityAssured"; + return ActionsFX.QUALITY_ASSURED; case CLEAR_RANK: - return "clearRank"; + return ActionsFX.CLEAR_RANK; case RANK_1: - return "setRank1"; + return ActionsFX.RANK_1; case RANK_2: - return "setRank2"; + return ActionsFX.RANK_2; case RANK_3: - return "setRank3"; + return ActionsFX.RANK_3; case RANK_4: - return "setRank4"; + return ActionsFX.RANK_4; case RANK_5: - return "setRank5"; + return ActionsFX.RANK_5; case CLEAR_READ_STATUS: - return "clearReadStatus"; + return ActionsFX.CLEAR_READ_STATUS; case READ: - return "setReadStatusToRead"; + return ActionsFX.READ; case SKIMMED: - return "setReadStatusToSkimmed"; + return ActionsFX.SKIMMED; case RELEVANT: - return "toggleRelevance"; + return ActionsFX.RELEVANT; default: - throw new IllegalArgumentException("There is no action name for special field value " + value); + throw new IllegalArgumentException("There is no tooltip localization for special field value " + value); } } } diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java index a372ba71417..2df8d05be52 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java @@ -7,7 +7,7 @@ import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.gui.JabRefIcon; -import org.jabref.logic.l10n.Localization; +import org.jabref.gui.actions.ActionsFX; import org.jabref.model.entry.specialfields.SpecialField; import org.jabref.model.entry.specialfields.SpecialFieldValue; @@ -29,60 +29,33 @@ public SpecialFieldAction getSpecialFieldAction(SpecialFieldValue value, JabRefF } public Icon getRepresentingIcon() { - switch (field) { - case PRINTED: - return IconTheme.JabRefIcons.PRINTED.getSmallIcon(); - case PRIORITY: - return IconTheme.JabRefIcons.PRIORITY.getSmallIcon(); - case QUALITY: - return IconTheme.JabRefIcons.QUALITY.getSmallIcon(); - case RANKING: - return IconTheme.JabRefIcons.RANKING.getIcon(); - case READ_STATUS: - return IconTheme.JabRefIcons.READ_STATUS.getSmallIcon(); - case RELEVANCE: - return IconTheme.JabRefIcons.RELEVANCE.getSmallIcon(); - default: - throw new IllegalArgumentException("There is no icon mapping for special field " + field); - } + return getAction().getIcon().map(IconTheme.JabRefIcons::getSmallIcon).orElse(null); } public JabRefIcon getIcon() { - switch (field) { - case PRINTED: - return IconTheme.JabRefIcons.PRINTED; - case PRIORITY: - return IconTheme.JabRefIcons.PRIORITY; - case QUALITY: - return IconTheme.JabRefIcons.QUALITY; - case RANKING: - return IconTheme.JabRefIcons.RANKING; - case READ_STATUS: - return IconTheme.JabRefIcons.READ_STATUS; - case RELEVANCE: - return IconTheme.JabRefIcons.RELEVANCE; - default: - throw new IllegalArgumentException("There is no icon mapping for special field " + field); - } + return getAction().getIcon().orElse(null); } public String getLocalization() { + return getAction().getText(); + } + + public ActionsFX getAction() { switch (field) { case PRINTED: - return Localization.lang("Printed"); + return ActionsFX.PRINTED; case PRIORITY: - return Localization.lang("Priority"); + return ActionsFX.PRIORITY; case QUALITY: - return Localization.lang("Quality"); + return ActionsFX.QUALITY; case RANKING: - return Localization.lang("Rank"); + return ActionsFX.RANKING; case READ_STATUS: - return Localization.lang("Read status"); + return ActionsFX.READ_STATUS; case RELEVANCE: - return Localization.lang("Relevance"); + return ActionsFX.RELEVANCE; default: throw new IllegalArgumentException("There is no icon mapping for special field " + field); } } - } diff --git a/src/main/java/org/jabref/gui/util/BindingsHelper.java b/src/main/java/org/jabref/gui/util/BindingsHelper.java index 022205e9314..3b344e30469 100644 --- a/src/main/java/org/jabref/gui/util/BindingsHelper.java +++ b/src/main/java/org/jabref/gui/util/BindingsHelper.java @@ -165,6 +165,15 @@ public static void bindContentBidirectional(ObservableMap proper updateB); } + public static ObservableValue constantOf(boolean value) { + return new BooleanBinding() { + @Override + protected boolean computeValue() { + return value; + } + }; + } + private static class BidirectionalBinding { private final ObservableValue propertyA; From fbc57073f6e2c5ed8387ef880121269fde27472a Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 29 Jan 2018 13:07:52 +0100 Subject: [PATCH 026/827] Reimplement special field and file columns (#3647) * Show special field icons properly in main table * Make icons functional * Fix NPE * Handle file icon click --- src/main/java/org/jabref/gui/BasePanel.java | 17 +-- src/main/java/org/jabref/gui/IconTheme.java | 5 +- .../gui/InternalMaterialDesignIcon.java | 40 +++--- src/main/java/org/jabref/gui/JabRefFrame.java | 6 + .../org/jabref/gui/desktop/JabRefDesktop.java | 20 +-- .../fieldeditors/AbstractEditorViewModel.java | 2 +- .../gui/fieldeditors/LinkedFileViewModel.java | 26 +++- .../gui/fieldeditors/LinkedFilesEditor.java | 2 +- .../org/jabref/gui/maintable/CellFactory.java | 16 ++- .../org/jabref/gui/maintable/MainTable.css | 28 ++++ .../org/jabref/gui/maintable/MainTable.java | 6 +- .../gui/maintable/MainTableColumnFactory.java | 122 +++++++++++++++--- .../jabref/gui/maintable/RightClickMenu.java | 2 +- .../gui/specialfields/SpecialFieldAction.java | 2 +- .../specialfields/SpecialFieldDropDown.java | 2 +- .../SpecialFieldValueViewModel.java | 16 +-- .../specialfields/SpecialFieldViewModel.java | 42 +++++- .../java/org/jabref/gui/util/ColorUtil.java | 28 ++++ .../util/OptionalValueTableCellFactory.java | 41 ++++++ .../gui/util/ValueTableCellFactory.java | 87 ++++++++++--- .../specialfields/SpecialFieldsUtils.java | 6 +- .../specialfields/SpecialFieldValue.java | 33 +++++ .../jabref/preferences/JabRefPreferences.java | 8 +- src/test/resources/testbib/complex.bib | 102 +++++++-------- 24 files changed, 492 insertions(+), 167 deletions(-) create mode 100644 src/main/java/org/jabref/gui/util/ColorUtil.java create mode 100644 src/main/java/org/jabref/gui/util/OptionalValueTableCellFactory.java diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index c62a8ed2c41..a67c65147ac 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -157,7 +157,7 @@ public class BasePanel extends StackPane implements ClipboardOwner { // The undo manager. private final UndoAction undoAction = new UndoAction(); private final RedoAction redoAction = new RedoAction(); - private final CountingUndoManager undoManager = new CountingUndoManager(); + private final CountingUndoManager undoManager; private final List previousEntries = new ArrayList<>(); private final List nextEntries = new ArrayList<>(); // Keeps track of the string dialog if it is open. @@ -202,6 +202,7 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas this.frame = Objects.requireNonNull(frame); this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext); this.externalFileTypes = Objects.requireNonNull(externalFileTypes); + this.undoManager = frame.getUndoManager(); bibDatabaseContext.getDatabase().registerListener(this); bibDatabaseContext.getMetaData().registerListener(this); @@ -638,26 +639,26 @@ public void update() { // Note that we can't put the number of entries that have been reverted into the undoText as the concrete number cannot be injected actions.put(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getCommand(), - new SpecialFieldViewModel(SpecialField.RELEVANCE).getSpecialFieldAction( + 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) + 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).getSpecialFieldAction( + 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).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).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).getSpecialFieldAction(status, this.frame)); + new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame)); } actions.put(Actions.TOGGLE_PREVIEW, (BaseAction) () -> { @@ -1211,7 +1212,7 @@ public void updateTableFont() { private void createMainTable() { bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.getInstance()); - mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext.getDatabase(), preferences.getTablePreferences(), externalFileTypes, Globals.getKeyPrefs()); + mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext, preferences.getTablePreferences(), externalFileTypes, Globals.getKeyPrefs()); mainTable.updateFont(); diff --git a/src/main/java/org/jabref/gui/IconTheme.java b/src/main/java/org/jabref/gui/IconTheme.java index da228780bd5..49de563c05f 100644 --- a/src/main/java/org/jabref/gui/IconTheme.java +++ b/src/main/java/org/jabref/gui/IconTheme.java @@ -27,6 +27,7 @@ import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import org.jabref.gui.util.ColorUtil; import org.jabref.logic.groups.DefaultGroupsFactory; import org.jabref.preferences.JabRefPreferences; @@ -71,7 +72,7 @@ private static InputStream getMaterialDesignIconsStream() { } public static javafx.scene.paint.Color getDefaultColor() { - return javafx.scene.paint.Color.rgb(DEFAULT_COLOR.getRed(), DEFAULT_COLOR.getGreen(), DEFAULT_COLOR.getBlue(), DEFAULT_COLOR.getAlpha() / 255.0); + return ColorUtil.toFX(DEFAULT_COLOR); } /** @@ -277,7 +278,7 @@ public enum JabRefIcons implements JabRefIcon { private final JabRefIcon icon; JabRefIcons(MaterialDesignIcon... icons) { - this(IconTheme.DEFAULT_COLOR, icons); + icon = new InternalMaterialDesignIcon(icons); } JabRefIcons(Color color, MaterialDesignIcon... icons) { diff --git a/src/main/java/org/jabref/gui/InternalMaterialDesignIcon.java b/src/main/java/org/jabref/gui/InternalMaterialDesignIcon.java index d8d9f44e338..e568773f91f 100644 --- a/src/main/java/org/jabref/gui/InternalMaterialDesignIcon.java +++ b/src/main/java/org/jabref/gui/InternalMaterialDesignIcon.java @@ -2,13 +2,16 @@ import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import javax.swing.Icon; import javafx.scene.Node; import javafx.scene.paint.Color; +import javafx.scene.text.Text; +import org.jabref.gui.util.ColorUtil; import org.jabref.preferences.JabRefPreferences; import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; @@ -16,11 +19,11 @@ public class InternalMaterialDesignIcon implements JabRefIcon { private final List icons; - private final Color color; + private Optional color; private final String unicode; public InternalMaterialDesignIcon(java.awt.Color color, MaterialDesignIcon... icons) { - this(toFX(color), Arrays.asList(icons)); + this(ColorUtil.toFX(color), Arrays.asList(icons)); } public InternalMaterialDesignIcon(Color color, MaterialDesignIcon... icons) { @@ -28,45 +31,40 @@ public InternalMaterialDesignIcon(Color color, MaterialDesignIcon... icons) { } InternalMaterialDesignIcon(Color color, List icons) { - this.icons = icons; - this.color = color; - this.unicode = icons.stream().map(MaterialDesignIcon::unicode).collect(Collectors.joining()); + this(icons); + this.color = Optional.of(color); } - public static java.awt.Color toAWT(Color color) { - return new java.awt.Color((float) color.getRed(), - (float) color.getGreen(), - (float) color.getBlue(), - (float) color.getOpacity()); + public InternalMaterialDesignIcon(MaterialDesignIcon... icons) { + this(Arrays.asList(icons)); } - public static Color toFX(java.awt.Color awtColor) { - int r = awtColor.getRed(); - int g = awtColor.getGreen(); - int b = awtColor.getBlue(); - int a = awtColor.getAlpha(); - double opacity = a / 255.0; - return javafx.scene.paint.Color.rgb(r, g, b, opacity); + public InternalMaterialDesignIcon(List icons) { + this.icons = icons; + this.unicode = icons.stream().map(MaterialDesignIcon::unicode).collect(Collectors.joining()); + this.color = Optional.empty(); } @Override public Icon getIcon() { - return new IconTheme.FontBasedIcon(this.unicode, toAWT(this.color)); + return new IconTheme.FontBasedIcon(this.unicode, ColorUtil.toAWT(this.color.orElse(IconTheme.getDefaultColor()))); } @Override public Icon getSmallIcon() { - return new IconTheme.FontBasedIcon(this.unicode, toAWT(this.color), JabRefPreferences.getInstance().getInt(JabRefPreferences.ICON_SIZE_SMALL)); + return new IconTheme.FontBasedIcon(this.unicode, ColorUtil.toAWT(this.color.orElse(IconTheme.getDefaultColor())), JabRefPreferences.getInstance().getInt(JabRefPreferences.ICON_SIZE_SMALL)); } @Override public Node getGraphicNode() { - return MaterialDesignIconFactory.get().createIcon(this.icons.get(0)); + Text icon = MaterialDesignIconFactory.get().createIcon(icons.get(0)); + color.ifPresent(color -> icon.setStyle(icon.getStyle() + String.format("-fx-fill: %s;", ColorUtil.toRGBCode(color)))); + return icon; } @Override public JabRefIcon disabled() { - return new InternalMaterialDesignIcon(toFX(IconTheme.DEFAULT_DISABLED_COLOR), icons); + return new InternalMaterialDesignIcon(ColorUtil.toFX(IconTheme.DEFAULT_DISABLED_COLOR), icons); } public String getCode() { diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 6b1b2f37cb5..b138bf0a0b5 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -120,6 +120,7 @@ import org.jabref.gui.search.GlobalSearchBar; import org.jabref.gui.specialfields.SpecialFieldDropDown; import org.jabref.gui.specialfields.SpecialFieldValueViewModel; +import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.WindowLocation; import org.jabref.gui.worker.MarkEntriesAction; @@ -467,6 +468,7 @@ public void actionPerformed(ActionEvent e) { private OpenOfficePanel openOfficePanel; private GroupSidePane groupSidePane; private JMenu newSpec; + private final CountingUndoManager undoManager = new CountingUndoManager(); public JabRefFrame() { init(); @@ -1972,6 +1974,10 @@ public GlobalSearchBar getGlobalSearchBar() { return globalSearchBar; } + public CountingUndoManager getUndoManager() { + return undoManager; + } + private static class MyGlassPane extends JPanel { public MyGlassPane() { addKeyListener(new KeyAdapter() { diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index a362446b26f..d5ad147d0a6 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -132,26 +132,16 @@ private static void openDoi(String doi) throws IOException { */ public static boolean openExternalFileAnyFormat(final BibDatabaseContext databaseContext, String link, final Optional type) throws IOException { - boolean httpLink = false; if (REMOTE_LINK_PATTERN.matcher(link.toLowerCase(Locale.ROOT)).matches()) { - httpLink = true; - } - - // For other platforms we'll try to find the file type: - Path file = null; - if (!httpLink) { - Optional tmp = FileHelper.expandFilename(databaseContext, link, - Globals.prefs.getFileDirectoryPreferences()); - if (tmp.isPresent()) { - file = tmp.get(); - } + openExternalFilePlatformIndependent(type, link); + return true; } - // Check if we have arrived at a file type, and either an http link or an existing file: - if (httpLink || ((file != null) && Files.exists(file) && (type.isPresent()))) { + Optional file = FileHelper.expandFilename(databaseContext, link, Globals.prefs.getFileDirectoryPreferences()); + if (file.isPresent() && Files.exists(file.get()) && (type.isPresent())) { // Open the file: - String filePath = httpLink ? link : file.toString(); + String filePath = file.get().toString(); openExternalFilePlatformIndependent(type, filePath); return true; } else { diff --git a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java index f249aa1c37a..e88226ac0ba 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java @@ -64,7 +64,7 @@ public void bindToEntry(BibEntry entry) { if (newValue != null) { String oldValue = entry.getField(fieldName).orElse(null); entry.setField(fieldName, newValue); - UndoManager undoManager = JabRefGUI.getMainFrame().getCurrentBasePanel().getUndoManager(); + UndoManager undoManager = JabRefGUI.getMainFrame().getUndoManager(); undoManager.addEdit(new UndoableFieldChange(entry, fieldName, oldValue, newValue)); } }); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 6612a752c20..ac995be2994 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -24,6 +24,8 @@ import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; +import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefIcon; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; @@ -38,9 +40,8 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.LinkedFile; +import org.jabref.model.strings.StringUtil; -import de.jensd.fx.glyphs.GlyphIcons; -import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -100,6 +101,14 @@ public String getDescription() { return linkedFile.getDescription(); } + public String getDescriptionAndLink() { + if (StringUtil.isBlank(linkedFile.getDescription())) { + return linkedFile.getLink(); + } else { + return linkedFile.getDescription() + " (" + linkedFile.getLink() + ")"; + } + } + public Optional findIn(List directories) { return linkedFile.findIn(directories); } @@ -108,8 +117,8 @@ public Optional findIn(List directories) { * TODO: Be a bit smarter and try to infer correct icon, for example using {@link * org.jabref.gui.externalfiletype.ExternalFileTypes#getExternalFileTypeByName(String)} */ - public GlyphIcons getTypeIcon() { - return MaterialDesignIcon.FILE_PDF; + public JabRefIcon getTypeIcon() { + return IconTheme.JabRefIcons.PDF_FILE; } public void markAsAutomaticallyFound() { @@ -131,9 +140,14 @@ public Observable[] getObservables() { public void open() { try { Optional type = ExternalFileTypes.getInstance().fromLinkedFile(linkedFile, true); - JabRefDesktop.openExternalFileAnyFormat(databaseContext, linkedFile.getLink(), type); + boolean successful = JabRefDesktop.openExternalFileAnyFormat(databaseContext, linkedFile.getLink(), type); + if (!successful) { + dialogService.showErrorDialogAndWait( + Localization.lang("File not found"), + Localization.lang("Could not find file '%0'.", linkedFile.getLink())); + } } catch (IOException e) { - LOGGER.warn("Cannot open selected file.", e); + dialogService.showErrorDialogAndWait(Localization.lang("Error opening file '%0'.", getLink()), e); } } diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 306bb3b148c..b01af694d40 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -148,7 +148,7 @@ private void handleOnDragDropped(LinkedFileViewModel originalItem, DragEvent eve } private static Node createFileDisplay(LinkedFileViewModel linkedFile) { - Text icon = MaterialDesignIconFactory.get().createIcon(linkedFile.getTypeIcon()); + Node icon = linkedFile.getTypeIcon().getGraphicNode(); icon.setOnMouseClicked(event -> linkedFile.open()); Text link = new Text(linkedFile.getLink()); Text desc = new Text(linkedFile.getDescription()); diff --git a/src/main/java/org/jabref/gui/maintable/CellFactory.java b/src/main/java/org/jabref/gui/maintable/CellFactory.java index 72b118cfcb2..f3ab65dbf5d 100644 --- a/src/main/java/org/jabref/gui/maintable/CellFactory.java +++ b/src/main/java/org/jabref/gui/maintable/CellFactory.java @@ -3,6 +3,8 @@ import java.util.HashMap; import java.util.Map; +import javax.swing.undo.UndoManager; + import javafx.scene.Node; import org.jabref.gui.IconTheme; @@ -16,7 +18,7 @@ public class CellFactory { private final Map TABLE_ICONS = new HashMap<>(); - public CellFactory(ExternalFileTypes externalFileTypes) { + public CellFactory(ExternalFileTypes externalFileTypes, UndoManager undoManager) { Node label; label = IconTheme.JabRefIcons.PDF_FILE.getGraphicNode(); //label.setToo(Localization.lang("Open") + " PDF"); @@ -56,36 +58,36 @@ public CellFactory(ExternalFileTypes externalFileTypes) { TABLE_ICONS.put(fileType.getName(), label); } - SpecialFieldViewModel relevanceViewModel = new SpecialFieldViewModel(SpecialField.RELEVANCE); + SpecialFieldViewModel relevanceViewModel = new SpecialFieldViewModel(SpecialField.RELEVANCE, undoManager); label = relevanceViewModel.getIcon().getGraphicNode(); //label.setToolTipText(relevanceViewModel.getLocalization()); TABLE_ICONS.put(SpecialField.RELEVANCE.getFieldName(), label); - SpecialFieldViewModel qualityViewModel = new SpecialFieldViewModel(SpecialField.QUALITY); + SpecialFieldViewModel qualityViewModel = new SpecialFieldViewModel(SpecialField.QUALITY, undoManager); label = qualityViewModel.getIcon().getGraphicNode(); //label.setToolTipText(qualityViewModel.getLocalization()); TABLE_ICONS.put(SpecialField.QUALITY.getFieldName(), label); // Ranking item in the menu uses one star - SpecialFieldViewModel rankViewModel = new SpecialFieldViewModel(SpecialField.RANKING); + SpecialFieldViewModel rankViewModel = new SpecialFieldViewModel(SpecialField.RANKING, undoManager); label = rankViewModel.getIcon().getGraphicNode(); //label.setToolTipText(rankViewModel.getLocalization()); TABLE_ICONS.put(SpecialField.RANKING.getFieldName(), label); // Priority icon used for the menu - SpecialFieldViewModel priorityViewModel = new SpecialFieldViewModel(SpecialField.PRIORITY); + SpecialFieldViewModel priorityViewModel = new SpecialFieldViewModel(SpecialField.PRIORITY, undoManager); label = priorityViewModel.getIcon().getGraphicNode(); //label.setToolTipText(priorityViewModel.getLocalization()); TABLE_ICONS.put(SpecialField.PRIORITY.getFieldName(), label); // Read icon used for menu - SpecialFieldViewModel readViewModel = new SpecialFieldViewModel(SpecialField.READ_STATUS); + SpecialFieldViewModel readViewModel = new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager); label = readViewModel.getIcon().getGraphicNode(); //label.setToolTipText(readViewModel.getLocalization()); TABLE_ICONS.put(SpecialField.READ_STATUS.getFieldName(), label); // Print icon used for menu - SpecialFieldViewModel printedViewModel = new SpecialFieldViewModel(SpecialField.PRINTED); + SpecialFieldViewModel printedViewModel = new SpecialFieldViewModel(SpecialField.PRINTED, undoManager); label = printedViewModel.getIcon().getGraphicNode(); //label.setToolTipText(printedViewModel.getLocalization()); TABLE_ICONS.put(SpecialField.PRINTED.getFieldName(), label); diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.css b/src/main/java/org/jabref/gui/maintable/MainTable.css index 1bb042ca76d..00b26481afe 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.css +++ b/src/main/java/org/jabref/gui/maintable/MainTable.css @@ -48,3 +48,31 @@ -fx-padding: 0; -fx-alignment: baseline-center; } + +.empty-special-field { + visibility: hidden; +} + +.table-row-cell:hover .empty-special-field { + visibility: visible; + -fx-fill: -fx-unimportant; +} + +.rating > .container { + -fx-spacing: 2; +} + +.rating > .container > .button { + -fx-pref-width: 10; + -fx-pref-height: 10; + -fx-background-size: cover; + -fx-padding: 0; +} + +.rating > .container > .button.strong { + +} + +.rating > .container > .button:hover { + -fx-effect: dropshadow(three-pass-box, rgba(0, 0, 0, 0.6), 8, 0.0, 0, 0); +} diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 63ef218c6ca..4731efc8eb3 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -24,7 +24,7 @@ import org.jabref.gui.renderer.IncompleteRenderer; import org.jabref.gui.util.ViewModelTableRowFactory; import org.jabref.logic.TypedBibEntry; -import org.jabref.model.database.BibDatabase; +import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; @@ -73,11 +73,11 @@ private enum CellRendererMode { } public MainTable(MainTableDataModel model, JabRefFrame frame, - BasePanel panel, BibDatabase database, MainTablePreferences preferences, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository) { + BasePanel panel, BibDatabaseContext database, MainTablePreferences preferences, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository) { super(); this.model = model; - this.getColumns().addAll(new MainTableColumnFactory(database, preferences.getColumnPreferences(), externalFileTypes).createColumns()); + this.getColumns().addAll(new MainTableColumnFactory(database, preferences.getColumnPreferences(), externalFileTypes, panel.getUndoManager()).createColumns()); this.setRowFactory(new ViewModelTableRowFactory() .withOnMouseClickedEvent((entry, event) -> { if (event.getClickCount() == 2) { diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index aa5c0a10b66..435e9e7fc89 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -7,22 +7,33 @@ import java.util.Optional; import java.util.stream.Collectors; +import javax.swing.undo.UndoManager; + import javafx.scene.Node; +import javafx.scene.control.ContextMenu; +import javafx.scene.control.MenuItem; import javafx.scene.control.TableColumn; +import javafx.scene.input.MouseButton; +import org.jabref.Globals; import org.jabref.gui.GUIGlobals; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefIcon; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.gui.fieldeditors.LinkedFileViewModel; import org.jabref.gui.specialfields.SpecialFieldValueViewModel; import org.jabref.gui.specialfields.SpecialFieldViewModel; +import org.jabref.gui.util.OptionalValueTableCellFactory; import org.jabref.gui.util.ValueTableCellFactory; -import org.jabref.model.database.BibDatabase; +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; import org.jabref.model.entry.LinkedFile; import org.jabref.model.entry.specialfields.SpecialField; +import org.jabref.model.entry.specialfields.SpecialFieldValue; +import org.controlsfx.control.Rating; import org.fxmisc.easybind.EasyBind; class MainTableColumnFactory { @@ -31,14 +42,16 @@ class MainTableColumnFactory { private final ColumnPreferences preferences; private final ExternalFileTypes externalFileTypes; - private final BibDatabase database; + private final BibDatabaseContext database; private final CellFactory cellFactory; + private final UndoManager undoManager; - public MainTableColumnFactory(BibDatabase database, ColumnPreferences preferences, ExternalFileTypes externalFileTypes) { + public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences preferences, ExternalFileTypes externalFileTypes, UndoManager undoManager) { this.database = Objects.requireNonNull(database); this.preferences = Objects.requireNonNull(preferences); this.externalFileTypes = Objects.requireNonNull(externalFileTypes); - this.cellFactory = new CellFactory(externalFileTypes); + this.cellFactory = new CellFactory(externalFileTypes, undoManager); + this.undoManager = undoManager; } public List> createColumns() { @@ -85,7 +98,7 @@ public MainTableColumnFactory(BibDatabase database, ColumnPreferences preference // Stored column name will be used as header // There might be more than one field to display, e.g., "author/editor" or "date/year" - so split String[] fields = columnName.split(FieldName.FIELD_SEPARATOR); - StringTableColumn column = new StringTableColumn(columnName, Arrays.asList(fields), database); + StringTableColumn column = new StringTableColumn(columnName, Arrays.asList(fields), database.getDatabase()); column.setPrefWidth(preferences.getPrefColumnWidth(columnName)); columns.add(column); } @@ -94,21 +107,70 @@ public MainTableColumnFactory(BibDatabase database, ColumnPreferences preference private TableColumn> createSpecialFieldColumn(SpecialField specialField) { TableColumn> column = new TableColumn<>(); - column.setGraphic(new SpecialFieldViewModel(specialField).getIcon().getGraphicNode()); + SpecialFieldViewModel specialFieldViewModel = new SpecialFieldViewModel(specialField, undoManager); + column.setGraphic(specialFieldViewModel.getIcon().getGraphicNode()); column.getStyleClass().add(STYLE_ICON); if (specialField == SpecialField.RANKING) { setExactWidth(column, GUIGlobals.WIDTH_ICON_COL_RANKING); + new OptionalValueTableCellFactory() + .withGraphicIfPresent(this::createRating) + .install(column); } else { setExactWidth(column, GUIGlobals.WIDTH_ICON_COL); + + if (specialField.isSingleValueField()) { + new OptionalValueTableCellFactory() + .withGraphic((entry, value) -> createSpecialFieldIcon(value, specialFieldViewModel)) + .withOnMouseClickedEvent((entry, value) -> event -> { + if (event.getButton() == MouseButton.PRIMARY) { + specialFieldViewModel.toggle(entry.getEntry()); + } + }) + .install(column); + } else { + new OptionalValueTableCellFactory() + .withGraphic((entry, value) -> createSpecialFieldIcon(value, specialFieldViewModel)) + .withMenu((entry, value) -> createSpecialFieldMenu(entry.getEntry(), specialFieldViewModel)) + .install(column); + } } column.setCellValueFactory(cellData -> cellData.getValue().getSpecialField(specialField)); - column.setCellFactory( - new ValueTableCellFactory>() - .withGraphic(param -> param.map(specialFieldValue -> specialFieldValue.getIcon().getGraphicNode()).orElse(null))); return column; } + private Rating createRating(BibEntryTableViewModel entry, SpecialFieldValueViewModel value) { + Rating ranking = new Rating(); + ranking.setRating(value.getValue().toRating()); + EasyBind.subscribe(ranking.ratingProperty(), rating -> + new SpecialFieldViewModel(SpecialField.RANKING, undoManager).setSpecialFieldValue(entry.getEntry(), SpecialFieldValue.getRating(rating.intValue())) + ); + return ranking; + } + + private ContextMenu createSpecialFieldMenu(BibEntry entry, SpecialFieldViewModel specialField) { + ContextMenu contextMenu = new ContextMenu(); + + for (SpecialFieldValueViewModel value : specialField.getValues()) { + MenuItem menuItem = new MenuItem(value.getMenuString(), value.getIcon().map(JabRefIcon::getGraphicNode).orElse(null)); + menuItem.setOnAction(event -> specialField.setSpecialFieldValue(entry, value.getValue())); + contextMenu.getItems().add(menuItem); + } + + return contextMenu; + } + + private Node createSpecialFieldIcon(Optional fieldValue, SpecialFieldViewModel specialField) { + return fieldValue + .flatMap(SpecialFieldValueViewModel::getIcon) + .map(JabRefIcon::getGraphicNode) + .orElseGet(() -> { + Node node = specialField.getEmptyIcon().getGraphicNode(); + node.getStyleClass().add("empty-special-field"); + return node; + }); + } + private void setExactWidth(TableColumn column, int widthIconCol) { column.setMinWidth(widthIconCol); column.setPrefWidth(widthIconCol); @@ -121,12 +183,38 @@ private TableColumn> createFileColumn() column.getStyleClass().add(STYLE_ICON); setExactWidth(column, GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> cellData.getValue().getLinkedFiles()); - column.setCellFactory( new ValueTableCellFactory>() - .withGraphic(this::createFileIcon)); + .withGraphic(this::createFileIcon) + .withMenu(this::createFileMenu) + .withOnMouseClickedEvent((entry, linkedFiles) -> event -> { + if (event.getButton() == MouseButton.PRIMARY && linkedFiles.size() == 1) { + // Only one linked file -> open directly + LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFiles.get(0), entry.getEntry(), database, Globals.TASK_EXECUTOR); + linkedFileViewModel.open(); + } + }) + .install(column); return column; } + private ContextMenu createFileMenu(BibEntryTableViewModel entry, List linkedFiles) { + if (linkedFiles.size() <= 1) { + return null; + } + + ContextMenu contextMenu = new ContextMenu(); + + for (LinkedFile linkedFile : linkedFiles) { + LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFile, entry.getEntry(), database, Globals.TASK_EXECUTOR); + + MenuItem menuItem = new MenuItem(linkedFileViewModel.getDescriptionAndLink(), linkedFileViewModel.getTypeIcon().getGraphicNode()); + menuItem.setOnAction(event -> linkedFileViewModel.open()); + contextMenu.getItems().add(menuItem); + } + + return contextMenu; + } + /** * Creates a column which shows an icon instead of the textual content */ @@ -136,9 +224,9 @@ private TableColumn createIconColumn(JabRefIcon column.getStyleClass().add(STYLE_ICON); setExactWidth(column, GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> EasyBind.monadic(cellData.getValue().getField(firstField)).orElse(cellData.getValue().getField(secondField))); - column.setCellFactory( new ValueTableCellFactory() - .withGraphic(cellFactory::getTableIcon)); + .withGraphic(cellFactory::getTableIcon) + .install(column); return column; } @@ -148,9 +236,9 @@ private TableColumn createIconColumn(JabRefIcon column.getStyleClass().add(STYLE_ICON); setExactWidth(column, GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> cellData.getValue().getField(field)); - column.setCellFactory( new ValueTableCellFactory() - .withGraphic(cellFactory::getTableIcon)); + .withGraphic(cellFactory::getTableIcon) + .install(column); return column; } @@ -168,9 +256,9 @@ private TableColumn> createExtraFileCol column.getStyleClass().add(STYLE_ICON); setExactWidth(column, GUIGlobals.WIDTH_ICON_COL); column.setCellValueFactory(cellData -> cellData.getValue().getLinkedFiles()); - column.setCellFactory( new ValueTableCellFactory>() - .withGraphic(linkedFiles -> createFileIcon(linkedFiles.stream().filter(linkedFile -> linkedFile.getFileType().equalsIgnoreCase(externalFileTypeName)).collect(Collectors.toList())))); + .withGraphic(linkedFiles -> createFileIcon(linkedFiles.stream().filter(linkedFile -> linkedFile.getFileType().equalsIgnoreCase(externalFileTypeName)).collect(Collectors.toList()))) + .install(column); return column; } diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index ce7e20d7b7d..5e817414d5d 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -187,7 +187,7 @@ private static Menu createCopySubMenu(BasePanel panel, ActionFactory factory) { } private static Menu createSpecialFieldMenu(SpecialField field, ActionFactory factory, BasePanel panel) { - SpecialFieldViewModel viewModel = new SpecialFieldViewModel(field); + viewModel = new SpecialFieldViewModel(field); Menu menu = factory.createMenu(viewModel.getAction()); for (SpecialFieldValue val : field.getValues()) { SpecialFieldValueViewModel specialField = new SpecialFieldValueViewModel(val); diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java index bed9b589bc7..ea0f6b6c8d0 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java @@ -83,7 +83,7 @@ public void action() { private String getTextDone(SpecialField field, String... params) { Objects.requireNonNull(params); - SpecialFieldViewModel viewModel = new SpecialFieldViewModel(field); + SpecialFieldViewModel viewModel = new SpecialFieldViewModel(field, frame.getCurrentBasePanel().getUndoManager()); if (field.isSingleValueField() && (params.length == 1) && (params[0] != null)) { // Single value fields can be toggled only diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldDropDown.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldDropDown.java index bf854ef6f8d..95979a18e66 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldDropDown.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldDropDown.java @@ -23,7 +23,7 @@ private SpecialFieldDropDown() { public static JButton generateSpecialFieldButtonWithDropDown(SpecialField field, JabRefFrame frame) { Dimension buttonDim = new Dimension(23, 23); - SpecialFieldViewModel viewModel = new SpecialFieldViewModel(field); + SpecialFieldViewModel viewModel = new SpecialFieldViewModel(field, frame.getUndoManager()); JButton button = new JButton(viewModel.getRepresentingIcon()); button.setToolTipText(viewModel.getLocalization()); button.setPreferredSize(buttonDim); diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java index 0273b9f59a4..7813c0e89a8 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java @@ -1,6 +1,7 @@ package org.jabref.gui.specialfields; import java.util.Objects; +import java.util.Optional; import javax.swing.Icon; import javax.swing.JLabel; @@ -13,6 +14,10 @@ public class SpecialFieldValueViewModel { + public SpecialFieldValue getValue() { + return value; + } + private final SpecialFieldValue value; public SpecialFieldValueViewModel(SpecialFieldValue value) { @@ -22,16 +27,11 @@ public SpecialFieldValueViewModel(SpecialFieldValue value) { } public Icon getSpecialFieldValueIcon() { - JabRefIcon icon = getIcon(); - if (icon == null) { - return null; - } else { - return icon.getSmallIcon(); - } + return getIcon().map(JabRefIcon::getSmallIcon).orElse(null); } - public JabRefIcon getIcon() { - return getAction().getIcon().orElse(null); + public Optional getIcon() { + return getAction().getIcon(); } public JLabel createSpecialFieldValueLabel() { diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java index 2df8d05be52..0f620e21154 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java @@ -1,23 +1,38 @@ package org.jabref.gui.specialfields; +import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import javax.swing.Icon; +import javax.swing.undo.UndoManager; +import org.jabref.Globals; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.gui.JabRefIcon; import org.jabref.gui.actions.ActionsFX; +import org.jabref.gui.undo.UndoableFieldChange; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.specialfields.SpecialFieldsUtils; +import org.jabref.model.FieldChange; +import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.specialfields.SpecialField; import org.jabref.model.entry.specialfields.SpecialFieldValue; public class SpecialFieldViewModel { + private UndoManager undoManager; + + public SpecialFieldViewModel(SpecialField field, UndoManager undoManager) { + this.field = Objects.requireNonNull(field); + this.undoManager = Objects.requireNonNull(undoManager); + } + private final SpecialField field; - public SpecialFieldViewModel(SpecialField field) { - Objects.requireNonNull(field); - this.field = field; + public SpecialField getField() { + return field; } public SpecialFieldAction getSpecialFieldAction(SpecialFieldValue value, JabRefFrame frame) { @@ -58,4 +73,25 @@ public ActionsFX getAction() { throw new IllegalArgumentException("There is no icon mapping for special field " + field); } } + + public JabRefIcon getEmptyIcon() { + return getIcon(); + } + + public List getValues() { + return field.getValues().stream() + .map(SpecialFieldValueViewModel::new) + .collect(Collectors.toList()); + } + + public void setSpecialFieldValue(BibEntry be, SpecialFieldValue value) { + List changes = SpecialFieldsUtils.updateField(getField(), value.getFieldValue().orElse(null), be, getField().isSingleValueField(), Globals.prefs.isKeywordSyncEnabled(), Globals.prefs.getKeywordDelimiter()); + for (FieldChange change : changes) { + undoManager.addEdit(new UndoableFieldChange(change)); + } + } + + public void toggle(BibEntry entry) { + setSpecialFieldValue(entry, getField().getValues().get(0)); + } } diff --git a/src/main/java/org/jabref/gui/util/ColorUtil.java b/src/main/java/org/jabref/gui/util/ColorUtil.java new file mode 100644 index 00000000000..3b713ded83c --- /dev/null +++ b/src/main/java/org/jabref/gui/util/ColorUtil.java @@ -0,0 +1,28 @@ +package org.jabref.gui.util; + +import javafx.scene.paint.Color; + +public class ColorUtil { + public static java.awt.Color toAWT(Color color) { + return new java.awt.Color((float) color.getRed(), + (float) color.getGreen(), + (float) color.getBlue(), + (float) color.getOpacity()); + } + + public static Color toFX(java.awt.Color awtColor) { + int r = awtColor.getRed(); + int g = awtColor.getGreen(); + int b = awtColor.getBlue(); + int a = awtColor.getAlpha(); + double opacity = a / 255.0; + return Color.rgb(r, g, b, opacity); + } + + public static String toRGBCode(Color color) { + return String.format("#%02X%02X%02X", + (int) (color.getRed() * 255), + (int) (color.getGreen() * 255), + (int) (color.getBlue() * 255)); + } +} diff --git a/src/main/java/org/jabref/gui/util/OptionalValueTableCellFactory.java b/src/main/java/org/jabref/gui/util/OptionalValueTableCellFactory.java new file mode 100644 index 00000000000..2232561583b --- /dev/null +++ b/src/main/java/org/jabref/gui/util/OptionalValueTableCellFactory.java @@ -0,0 +1,41 @@ +package org.jabref.gui.util; + +import java.util.Optional; +import java.util.function.BiFunction; + +import javafx.scene.Node; +import javafx.scene.control.TableCell; + +/** + * Constructs a {@link TableCell} based on an optional value of the cell and a bunch of specified converter methods. + * + * @param view model of table row + * @param cell value + */ +public class OptionalValueTableCellFactory extends ValueTableCellFactory> { + + private BiFunction toGraphicIfPresent; + private Node defaultGraphic; + + public OptionalValueTableCellFactory withGraphicIfPresent(BiFunction toGraphicIfPresent) { + this.toGraphicIfPresent = toGraphicIfPresent; + setToGraphic(); + return this; + } + + public OptionalValueTableCellFactory withDefaultGraphic(Node defaultGraphic) { + this.defaultGraphic = defaultGraphic; + setToGraphic(); + return this; + } + + private void setToGraphic() { + withGraphic((rowItem, item) -> { + if (item.isPresent() && toGraphicIfPresent != null) { + return toGraphicIfPresent.apply(rowItem, item.get()); + } else { + return defaultGraphic; + } + }); + } +} diff --git a/src/main/java/org/jabref/gui/util/ValueTableCellFactory.java b/src/main/java/org/jabref/gui/util/ValueTableCellFactory.java index 2d4892086de..82468f56578 100644 --- a/src/main/java/org/jabref/gui/util/ValueTableCellFactory.java +++ b/src/main/java/org/jabref/gui/util/ValueTableCellFactory.java @@ -1,10 +1,16 @@ package org.jabref.gui.util; +import java.util.function.BiFunction; +import java.util.function.Function; + import javafx.event.EventHandler; import javafx.scene.Node; +import javafx.scene.control.ContextMenu; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; +import javafx.scene.control.TableRow; import javafx.scene.control.Tooltip; +import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; import javafx.util.Callback; @@ -18,32 +24,53 @@ */ public class ValueTableCellFactory implements Callback, TableCell> { - private Callback toText; - private Callback toGraphic; - private Callback> toOnMouseClickedEvent; - private Callback toTooltip; + private Function toText; + private BiFunction toGraphic; + private BiFunction> toOnMouseClickedEvent; + private Function toTooltip; + private Function contextMenuFactory; + private BiFunction menuFactory; - public ValueTableCellFactory withText(Callback toText) { + public ValueTableCellFactory withText(Function toText) { this.toText = toText; return this; } - public ValueTableCellFactory withGraphic(Callback toGraphic) { + public ValueTableCellFactory withGraphic(Function toGraphic) { + this.toGraphic = (rowItem, value) -> toGraphic.apply(value); + return this; + } + + public ValueTableCellFactory withGraphic(BiFunction toGraphic) { this.toGraphic = toGraphic; return this; } - public ValueTableCellFactory withTooltip(Callback toTooltip) { + public ValueTableCellFactory withTooltip(Function toTooltip) { this.toTooltip = toTooltip; return this; } - public ValueTableCellFactory withOnMouseClickedEvent( - Callback> toOnMouseClickedEvent) { + public ValueTableCellFactory withOnMouseClickedEvent(BiFunction> toOnMouseClickedEvent) { this.toOnMouseClickedEvent = toOnMouseClickedEvent; return this; } + public ValueTableCellFactory withOnMouseClickedEvent(Function> toOnMouseClickedEvent) { + this.toOnMouseClickedEvent = (rowItem, value) -> toOnMouseClickedEvent.apply(value); + return this; + } + + public ValueTableCellFactory withContextMenu(Function contextMenuFactory) { + this.contextMenuFactory = contextMenuFactory; + return this; + } + + public ValueTableCellFactory withMenu(BiFunction menuFactory) { + this.menuFactory = menuFactory; + return this; + } + @Override public TableCell call(TableColumn param) { @@ -53,29 +80,59 @@ public TableCell call(TableColumn param) { protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); - if (empty || (item == null)) { + if (empty || (item == null) || (getTableRow() == null) || (getTableRow().getItem() == null)) { setText(null); setGraphic(null); setOnMouseClicked(null); setTooltip(null); } else { + S rowItem = ((TableRow) getTableRow()).getItem(); + if (toText != null) { - setText(toText.call(item)); + setText(toText.apply(item)); } if (toGraphic != null) { - setGraphic(toGraphic.call(item)); + setGraphic(toGraphic.apply(rowItem, item)); } if (toTooltip != null) { - String tooltipText = toTooltip.call(item); + String tooltipText = toTooltip.apply(item); if (StringUtil.isNotBlank(tooltipText)) { setTooltip(new Tooltip(tooltipText)); } } - if (toOnMouseClickedEvent != null) { - setOnMouseClicked(toOnMouseClickedEvent.call(item)); + + if (contextMenuFactory != null) { + // We only create the context menu when really necessary + setOnContextMenuRequested(event -> { + if (!isEmpty()) { + setContextMenu(contextMenuFactory.apply(item)); + getContextMenu().show(this, event.getScreenX(), event.getScreenY()); + } + event.consume(); + }); } + + setOnMouseClicked(event -> { + if (toOnMouseClickedEvent != null) { + toOnMouseClickedEvent.apply(rowItem, item).handle(event); + } + + if (menuFactory != null && !event.isConsumed()) { + if (event.getButton() == MouseButton.PRIMARY) { + ContextMenu menu = menuFactory.apply(rowItem, item); + if (menu != null) { + menu.show(this, event.getScreenX(), event.getScreenY()); + event.consume(); + } + } + } + }); } } }; } + + public void install(TableColumn column) { + column.setCellFactory(this); + } } diff --git a/src/main/java/org/jabref/logic/specialfields/SpecialFieldsUtils.java b/src/main/java/org/jabref/logic/specialfields/SpecialFieldsUtils.java index 084239efe0d..0152f2fed86 100644 --- a/src/main/java/org/jabref/logic/specialfields/SpecialFieldsUtils.java +++ b/src/main/java/org/jabref/logic/specialfields/SpecialFieldsUtils.java @@ -32,7 +32,7 @@ public static List updateField(SpecialField field, String value, Bi List fieldChanges = new ArrayList<>(); UpdateField.updateField(entry, field.getFieldName(), value, nullFieldIfValueIsTheSame) - .ifPresent(fieldChange -> fieldChanges.add(fieldChange)); + .ifPresent(fieldChanges::add); // we cannot use "value" here as updateField has side effects: "nullFieldIfValueIsTheSame" nulls the field if value is the same if (isKeywordSyncEnabled) { fieldChanges.addAll(SpecialFieldsUtils.exportFieldToKeywords(field, entry, keywordDelimiter)); @@ -79,9 +79,7 @@ private static List importKeywordsForField(KeywordList keywordList, } UpdateField.updateNonDisplayableField(entry, field.getFieldName(), newValue.map(Keyword::toString).orElse(null)) - .ifPresent(fieldChange -> { - fieldChanges.add(fieldChange); - }); + .ifPresent(fieldChanges::add); return fieldChanges; } diff --git a/src/main/java/org/jabref/model/entry/specialfields/SpecialFieldValue.java b/src/main/java/org/jabref/model/entry/specialfields/SpecialFieldValue.java index 742b707bd36..7176b39a6ce 100644 --- a/src/main/java/org/jabref/model/entry/specialfields/SpecialFieldValue.java +++ b/src/main/java/org/jabref/model/entry/specialfields/SpecialFieldValue.java @@ -34,6 +34,23 @@ public enum SpecialFieldValue { this.keyword = Optional.ofNullable(keyword).map(Keyword::new); } + public static SpecialFieldValue getRating(int ranking) { + switch (ranking) { + case 1: + return RANK_1; + case 2: + return RANK_2; + case 3: + return RANK_3; + case 4: + return RANK_4; + case 5: + return RANK_5; + default: + throw new UnsupportedOperationException(ranking + "is not a valid ranking"); + } + } + public Optional getKeyword() { return keyword; } @@ -42,4 +59,20 @@ public Optional getFieldValue() { return keyword.map(Keyword::toString); } + public int toRating() { + switch (this) { + case RANK_1: + return 1; + case RANK_2: + return 2; + case RANK_3: + return 3; + case RANK_4: + return 4; + case RANK_5: + return 5; + default: + throw new UnsupportedOperationException(this + "is not a valid ranking"); + } + } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index fa1fdcc2425..80422e2a647 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -632,7 +632,7 @@ private JabRefPreferences() { defaults.put(FIELD_EDITOR_TEXT_COLOR, "0:0:0"); // default icon colors - defaults.put(ICON_ENABLED_COLOR, "79:95:143"); + defaults.put(ICON_ENABLED_COLOR, "0:0:0"); defaults.put(ICON_DISABLED_COLOR, "200:200:200"); defaults.put(INCOMPLETE_ENTRY_BACKGROUND, "250:175:175"); @@ -1292,7 +1292,11 @@ private Object getObject(String key) { try { return this.getBoolean(key); } catch (ClassCastException e2) { - return this.getInt(key); + try { + return this.getInt(key); + } catch (ClassCastException e3) { + return this.getDouble(key); + } } } } diff --git a/src/test/resources/testbib/complex.bib b/src/test/resources/testbib/complex.bib index dd64afe4e54..84a8899d40f 100644 --- a/src/test/resources/testbib/complex.bib +++ b/src/test/resources/testbib/complex.bib @@ -18,20 +18,20 @@ @PhdThesis{deBraga2001 school = {Department of Zoology, University of Toronto}, } -@ARTICLE{1102917, - author = {E. Bardram}, - title = {The trouble with login: on usability and computer security in ubiquitous - computing}, - journal = {Personal Ubiquitous Comput.}, - year = {2005}, - volume = {9}, - pages = {357--367}, - number = {6}, - address = {London, UK}, +@Article{1102917, + author = {E. Bardram}, + title = {The trouble with login: on usability and computer security in ubiquitous computing}, + journal = {Personal Ubiquitous Comput.}, + year = {2005}, + volume = {9}, + number = {6}, + pages = {357--367}, + issn = {1617-4909}, + doi = {http://dx.doi.org/10.1007/s00779-005-0347-6}, + address = {London, UK}, bdsk-url-1 = {http://dx.doi.org/10.1007/s00779-005-0347-6}, - doi = {http://dx.doi.org/10.1007/s00779-005-0347-6}, - issn = {1617-4909}, - publisher = {Springer-Verlag} + priority = {prio1}, + publisher = {Springer-Verlag}, } @InProceedings{1137631, @@ -65,20 +65,19 @@ @INPROCEEDINGS{1132768 location = {Montreal, Canada} } -@INPROCEEDINGS{1137628, - author = {Danilo Bruschi and Bart De Win and Mattia Monga}, - title = {Introduction to software engineering for secure systems: SESS06 -- - secure by design}, - booktitle = {SESS '06: Proceedings of the 2006 international workshop on Software - engineering for secure systems}, - year = {2006}, - pages = {1--2}, - address = {New York, NY, USA}, - publisher = {ACM}, +@InProceedings{1137628, + author = {Danilo Bruschi and Bart De Win and Mattia Monga}, + title = {Introduction to software engineering for secure systems: SESS06 -- secure by design}, + booktitle = {SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems}, + year = {2006}, + publisher = {ACM}, + location = {Shanghai, China}, + isbn = {1-59593-411-1}, + pages = {1--2}, + doi = {http://doi.acm.org/10.1145/1137627.1137628}, + address = {New York, NY, USA}, bdsk-url-1 = {http://doi.acm.org/10.1145/1137627.1137628}, - doi = {http://doi.acm.org/10.1145/1137627.1137628}, - isbn = {1-59593-411-1}, - location = {Shanghai, China} + readstatus = {read}, } @ARTICLE{1373163, @@ -96,20 +95,20 @@ @ARTICLE{1373163 publisher = {IEEE Educational Activities Department} } -@ARTICLE{820136, - author = {Tony Clear}, - title = {Design and usability in security systems: daily life as a context - of use?}, - journal = {SIGCSE Bull.}, - year = {2002}, - volume = {34}, - pages = {13--14}, - number = {4}, - address = {New York, NY, USA}, +@Article{820136, + author = {Tony Clear}, + title = {Design and usability in security systems: daily life as a context of use?}, + journal = {SIGCSE Bull.}, + year = {2002}, + volume = {34}, + number = {4}, + pages = {13--14}, + issn = {0097-8418}, + doi = {http://doi.acm.org/10.1145/820127.820136}, + address = {New York, NY, USA}, bdsk-url-1 = {http://doi.acm.org/10.1145/820127.820136}, - doi = {http://doi.acm.org/10.1145/820127.820136}, - issn = {0097-8418}, - publisher = {ACM} + publisher = {ACM}, + readstatus = {skimmed}, } @BOOK{1098730, @@ -150,19 +149,20 @@ @InProceedings{1233448 groups = {StaticGroup}, } -@ARTICLE{10250999, - author = {von Hippel, Eric and Reagle, Jr., Joseph M. and Sherry, John F., Jr. and van den Huevel, Jr., Johan A}, - title = {Article with complex Authornames}, - journal = {IEEE Security and Privacy}, - year = {2004}, - volume = {2}, - pages = {25--31}, - number = {5}, - address = {Piscataway, NJ, USA}, +@Article{10250999, + author = {von Hippel, Eric and Reagle, Jr., Joseph M. and Sherry, John F., Jr. and van den Huevel, Jr., Johan A}, + title = {Article with complex Authornames}, + journal = {IEEE Security and Privacy}, + year = {2004}, + volume = {2}, + number = {5}, + pages = {25--31}, + issn = {1540-7993}, + doi = {http://dx.doi.org/10.1109/MSP.2004.81}, + address = {Piscataway, NJ, USA}, bdsk-url-1 = {http://dx.doi.org/10.1109/MSP.2004.81}, - doi = {http://dx.doi.org/10.1109/MSP.2004.81}, - issn = {1540-7993}, - publisher = {IEEE Educational Activities Department} + priority = {prio2}, + publisher = {IEEE Educational Activities Department}, } @InProceedings{1314293, From 250f9b9e7a069db4c756bc463a7418da66597578 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 29 Jan 2018 16:25:02 +0100 Subject: [PATCH 027/827] Fix build --- src/main/java/org/jabref/gui/BasePanel.java | 6 +++--- src/main/java/org/jabref/gui/JabRefFrame.java | 4 ++-- src/main/java/org/jabref/gui/actions/ActionsFX.java | 5 +++-- .../java/org/jabref/gui/actions/OldCommandWrapper.java | 6 +++--- src/main/java/org/jabref/gui/entryeditor/EntryEditor.java | 7 +++++-- .../java/org/jabref/gui/maintable/ColumnPreferences.java | 6 +++--- src/main/java/org/jabref/gui/maintable/MainTable.java | 4 ---- .../java/org/jabref/gui/maintable/RightClickMenu.java | 6 +----- .../gui/maintable/SmartConstrainedResizePolicy.java | 6 +++--- .../jabref/gui/specialfields/SpecialFieldViewModel.java | 7 ++----- .../java/org/jabref/gui/util/IconValidationDecorator.java | 4 ++-- src/main/java/org/jabref/model/groups/TexGroup.java | 8 ++++---- 12 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 170be93fb01..831357474c6 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -138,10 +138,10 @@ import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; import org.apache.commons.lang3.NotImplementedException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.Subscription; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class BasePanel extends StackPane implements ClipboardOwner { @@ -238,7 +238,7 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas this.getDatabase().registerListener(new UpdateTimestampListener(Globals.prefs)); - this.entryEditor = new EntryEditor(this, preferences.getEntryEditorPreferences()); + this.entryEditor = new EntryEditor(this, preferences.getEntryEditorPreferences(), Globals.getFileUpdateMonitor()); this.preview = new PreviewPanel(this, getBibDatabaseContext(), preferences.getKeyBindings(), preferences.getPreviewPreferences()); DefaultTaskExecutor.runInJavaFXThread(() -> frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview)); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 2cbc61d9588..65a44046b06 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -151,9 +151,9 @@ import org.jabref.preferences.SearchPreferences; import com.google.common.eventbus.Subscribe; +import org.fxmisc.easybind.EasyBind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.fxmisc.easybind.EasyBind; import osx.macadapter.MacAdapter; /** @@ -201,7 +201,7 @@ public class JabRefFrame extends JFrame implements OutputPrinter { IconTheme.getImage("about"), IconTheme.getImage("about")); private final AbstractAction jabrefFacebookAction = new OpenBrowserAction("https://www.facebook.com/JabRef/", "Facebook", Localization.lang("Opens JabRef's Facebook page"), - IconTheme.JabRefIcons.FACEBOOK.getSmallIcon(), IconTheme.JabRefIcosn.FACEBOOK.getIcon()); + IconTheme.JabRefIcons.FACEBOOK.getSmallIcon(), IconTheme.JabRefIcons.FACEBOOK.getIcon()); private final AbstractAction jabrefTwitterAction = new OpenBrowserAction("https://twitter.com/jabref_org", "Twitter", Localization.lang("Opens JabRef's Twitter page"), IconTheme.JabRefIcons.TWITTER.getSmallIcon(), IconTheme.JabRefIcons.TWITTER.getIcon()); diff --git a/src/main/java/org/jabref/gui/actions/ActionsFX.java b/src/main/java/org/jabref/gui/actions/ActionsFX.java index 64c6276f1b0..2ca8b48e5d2 100644 --- a/src/main/java/org/jabref/gui/actions/ActionsFX.java +++ b/src/main/java/org/jabref/gui/actions/ActionsFX.java @@ -3,6 +3,7 @@ import java.util.Optional; import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefIcon; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.l10n.Localization; @@ -60,7 +61,7 @@ public enum ActionsFX { RELEVANT(Localization.lang("Toggle relevance"), IconTheme.JabRefIcons.RELEVANCE); private final String text; - private final Optional icon; + private final Optional icon; private final Optional keyBinding; ActionsFX(String text) { @@ -87,7 +88,7 @@ public enum ActionsFX { this.icon = Optional.empty(); } - public Optional getIcon() { + public Optional getIcon() { return icon; } diff --git a/src/main/java/org/jabref/gui/actions/OldCommandWrapper.java b/src/main/java/org/jabref/gui/actions/OldCommandWrapper.java index 1fa7ac6774a..c187b412684 100644 --- a/src/main/java/org/jabref/gui/actions/OldCommandWrapper.java +++ b/src/main/java/org/jabref/gui/actions/OldCommandWrapper.java @@ -6,8 +6,8 @@ import org.jabref.gui.util.BindingsHelper; import de.saxsys.mvvmfx.utils.commands.CommandBase; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This wraps the old Swing commands so that they fit into the new infrastructure. @@ -15,7 +15,7 @@ */ public class OldCommandWrapper extends CommandBase { - private static final Log LOGGER = LogFactory.getLog(OldCommandWrapper.class); + private static final Logger LOGGER = LoggerFactory.getLogger(OldCommandWrapper.class); private final Actions command; private final BasePanel panel; diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 9538098bab5..e3d93d09940 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -36,6 +36,7 @@ import org.jabref.logic.search.SearchQueryHighlightListener; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.util.FileUpdateMonitor; import org.fxmisc.easybind.EasyBind; @@ -56,6 +57,7 @@ public class EntryEditor extends BorderPane { private final BasePanel panel; private final List searchListeners = new ArrayList<>(); private final List tabs; + private final FileUpdateMonitor fileMonitor; /** * A reference to the entry this editor works on. */ @@ -67,11 +69,12 @@ public class EntryEditor extends BorderPane { @FXML private Label typeLabel; private final EntryEditorPreferences preferences; - public EntryEditor(BasePanel panel, EntryEditorPreferences preferences) { + public EntryEditor(BasePanel panel, EntryEditorPreferences preferences, FileUpdateMonitor fileMonitor) { this.panel = panel; this.bibDatabaseContext = panel.getBibDatabaseContext(); this.undoManager = panel.getUndoManager(); this.preferences = Objects.requireNonNull(preferences); + this.fileMonitor = fileMonitor; ControlHelper.loadFXMLForControl(this); @@ -173,7 +176,7 @@ private List createTabs() { tabs.add(new RelatedArticlesTab(preferences)); // Source tab - sourceTab = new SourceTab(bibDatabaseContext, undoManager, preferences.getLatexFieldFormatterPreferences(), preferences.getImportFormatPreferences(), Globals.getFileUpdateMonitor()); + sourceTab = new SourceTab(bibDatabaseContext, undoManager, preferences.getLatexFieldFormatterPreferences(), preferences.getImportFormatPreferences(), fileMonitor); tabs.add(sourceTab); return tabs; } diff --git a/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java b/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java index e83048bc4a3..ceebacb1e40 100644 --- a/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java +++ b/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java @@ -11,12 +11,12 @@ import org.jabref.model.entry.specialfields.SpecialField; import org.jabref.preferences.JabRefPreferences; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ColumnPreferences { - private static final Log LOGGER = LogFactory.getLog(ColumnPreferences.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ColumnPreferences.class); private final boolean showFileColumn; private final boolean showUrlColumn; diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 6038c327836..896cd13d0a7 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -29,8 +29,6 @@ import org.jabref.preferences.JabRefPreferences; import ca.odell.glazedlists.matchers.Matcher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class MainTable extends TableView { private static GeneralRenderer defRenderer; @@ -49,8 +47,6 @@ public class MainTable extends TableView { private static List markedNumberRenderers; - private static final Log LOGGER = LogFactory.getLog(MainTable.class); - private final BasePanel panel; //private final boolean tableColorCodes; //private final boolean tableResolvedColorCodes; diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index 5e817414d5d..b23eb3c401f 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -28,11 +28,7 @@ import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.PreviewPreferences; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - public class RightClickMenu { - private static final Log LOGGER = LogFactory.getLog(RightClickMenu.class); public static ContextMenu create(BibEntryTableViewModel entry, KeyBindingRepository keyBindingRepository, BasePanel panel, KeyBindingRepository keyBindings) { ContextMenu contextMenu = new ContextMenu(); @@ -187,7 +183,7 @@ private static Menu createCopySubMenu(BasePanel panel, ActionFactory factory) { } private static Menu createSpecialFieldMenu(SpecialField field, ActionFactory factory, BasePanel panel) { - viewModel = new SpecialFieldViewModel(field); + SpecialFieldViewModel viewModel = new SpecialFieldViewModel(field, panel.getUndoManager()); Menu menu = factory.createMenu(viewModel.getAction()); for (SpecialFieldValue val : field.getValues()) { SpecialFieldValueViewModel specialField = new SpecialFieldValueViewModel(val); diff --git a/src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java b/src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java index 425a59eac5c..b38ecab13dd 100644 --- a/src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java +++ b/src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java @@ -10,8 +10,8 @@ import javafx.scene.control.TableView; import javafx.util.Callback; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This resize policy is almost the same as {@link TableView#CONSTRAINED_RESIZE_POLICY} @@ -20,7 +20,7 @@ */ public class SmartConstrainedResizePolicy implements Callback { - private static final Log LOGGER = LogFactory.getLog(SmartConstrainedResizePolicy.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SmartConstrainedResizePolicy.class); @Override public Boolean call(TableView.ResizeFeatures prop) { diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java index 0f620e21154..62cc87de661 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldViewModel.java @@ -8,12 +8,10 @@ import javax.swing.undo.UndoManager; import org.jabref.Globals; -import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.gui.JabRefIcon; import org.jabref.gui.actions.ActionsFX; import org.jabref.gui.undo.UndoableFieldChange; -import org.jabref.logic.l10n.Localization; import org.jabref.logic.specialfields.SpecialFieldsUtils; import org.jabref.model.FieldChange; import org.jabref.model.entry.BibEntry; @@ -22,6 +20,7 @@ public class SpecialFieldViewModel { + private final SpecialField field; private UndoManager undoManager; public SpecialFieldViewModel(SpecialField field, UndoManager undoManager) { @@ -29,8 +28,6 @@ public SpecialFieldViewModel(SpecialField field, UndoManager undoManager) { this.undoManager = Objects.requireNonNull(undoManager); } - private final SpecialField field; - public SpecialField getField() { return field; } @@ -44,7 +41,7 @@ public SpecialFieldAction getSpecialFieldAction(SpecialFieldValue value, JabRefF } public Icon getRepresentingIcon() { - return getAction().getIcon().map(IconTheme.JabRefIcons::getSmallIcon).orElse(null); + return getAction().getIcon().map(JabRefIcon::getSmallIcon).orElse(null); } public JabRefIcon getIcon() { diff --git a/src/main/java/org/jabref/gui/util/IconValidationDecorator.java b/src/main/java/org/jabref/gui/util/IconValidationDecorator.java index 39268ea4562..d4e7d2caf8d 100644 --- a/src/main/java/org/jabref/gui/util/IconValidationDecorator.java +++ b/src/main/java/org/jabref/gui/util/IconValidationDecorator.java @@ -32,11 +32,11 @@ public IconValidationDecorator(Pos position) { } protected Node createErrorNode() { - return IconTheme.JabRefIcon.ERROR.getGraphicNode(); + return IconTheme.JabRefIcons.ERROR.getGraphicNode(); } protected Node createWarningNode() { - return IconTheme.JabRefIcon.WARNING.getGraphicNode(); + return IconTheme.JabRefIcons.WARNING.getGraphicNode(); } public Node createDecorationNode(ValidationMessage message) { diff --git a/src/main/java/org/jabref/model/groups/TexGroup.java b/src/main/java/org/jabref/model/groups/TexGroup.java index 50f027ea778..3c0ef915db9 100644 --- a/src/main/java/org/jabref/model/groups/TexGroup.java +++ b/src/main/java/org/jabref/model/groups/TexGroup.java @@ -11,12 +11,12 @@ import org.jabref.model.util.FileUpdateListener; import org.jabref.model.util.FileUpdateMonitor; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TexGroup extends AbstractGroup implements FileUpdateListener { - private static final Log LOGGER = LogFactory.getLog(TexGroup.class); + private static final Logger LOGGER = LoggerFactory.getLogger(TexGroup.class); private Path filePath; private Set keysUsedInAux = null; @@ -52,7 +52,7 @@ public AbstractGroup deepCopy() { return new TexGroup(name, context, filePath, auxParser, fileMonitor); } catch (IOException ex) { // This should never happen because we were able to monitor the file just fine until now - LOGGER.error(ex); + LOGGER.error("Problem creating copy of group", ex); return null; } } From 08ecea857e1427c01a09265cb9fc38ad16662962 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 29 Jan 2018 16:40:23 +0100 Subject: [PATCH 028/827] Fix test build --- .../java/org/jabref/architecture/TestArchitectureTests.java | 2 +- .../entryeditor/{EntryEditorTest.java => SourceTabTest.java} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/test/java/org/jabref/gui/entryeditor/{EntryEditorTest.java => SourceTabTest.java} (96%) diff --git a/src/test/java/org/jabref/architecture/TestArchitectureTests.java b/src/test/java/org/jabref/architecture/TestArchitectureTests.java index 04d5b0e8cf0..7e6feac1b3c 100644 --- a/src/test/java/org/jabref/architecture/TestArchitectureTests.java +++ b/src/test/java/org/jabref/architecture/TestArchitectureTests.java @@ -27,7 +27,7 @@ public class TestArchitectureTests { private static final String CLASS_ORG_JABREF_PREFERENCES_TEST = "JabRefPreferencesTest"; private static final String CLASS_ORG_JABREF_PREFERENCES_MIGRATIONS_TEST = "PreferencesMigrationsTest"; private static final String CLASS_ORG_JABREF_UPDATE_TIMESTAMP_LISTENER_TEST = "UpdateTimestampListenerTest"; - private static final String CLASS_ORG_JABREF_ENTRY_EDITOR_TEST = "EntryEditorTest"; + private static final String CLASS_ORG_JABREF_ENTRY_EDITOR_TEST = "SourceTabTest"; private final String forbiddenPackage; diff --git a/src/test/java/org/jabref/gui/entryeditor/EntryEditorTest.java b/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java similarity index 96% rename from src/test/java/org/jabref/gui/entryeditor/EntryEditorTest.java rename to src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java index a48a71b2eeb..48bf1243fc7 100644 --- a/src/test/java/org/jabref/gui/entryeditor/EntryEditorTest.java +++ b/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java @@ -23,7 +23,7 @@ import static org.mockito.Mockito.mock; @ExtendWith(ApplicationExtension.class) -public class EntryEditorTest { +public class SourceTabTest { private Stage stage; private Scene scene; @@ -35,7 +35,7 @@ public class EntryEditorTest { public void onStart(Stage stage) { area = new CodeArea(); area.appendText("some example\n text to go here\n across a couple of \n lines...."); - sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), mock(ImportFormatPreferences.class)); + sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), mock(ImportFormatPreferences.class), new DummyFileUpdateMonitor()); pane = new TabPane( new Tab("main area", area), new Tab("other tab", new Label("some text")), From e034d56a783081f50c2e7fcc645aea22911d93a6 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 29 Jan 2018 23:55:09 +0100 Subject: [PATCH 029/827] Fixes sorting --- .../java/org/jabref/gui/maintable/MainTable.java | 8 +++++++- .../org/jabref/gui/maintable/MainTableDataModel.java | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 896cd13d0a7..9afd2bfb8e8 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -9,6 +9,7 @@ import javax.swing.JTable; import javafx.collections.ListChangeListener; +import javafx.collections.transformation.SortedList; import javafx.scene.control.ScrollPane; import javafx.scene.control.SelectionMode; import javafx.scene.control.TableView; @@ -85,7 +86,12 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, this.setColumnResizePolicy(new SmartConstrainedResizePolicy()); } this.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); - this.setItems(model.getEntriesFiltered()); + + SortedList entries = model.getEntriesFiltered(); + this.setItems(entries); + + // Enable sorting + entries.comparatorProperty().bind(this.comparatorProperty()); // TODO: Cannot add focus listener as it is expecting an swing component //addFocusListener(Globals.getFocusListener()); diff --git a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java index ebb5aa92132..bd7643b266b 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java @@ -6,6 +6,7 @@ import javafx.beans.binding.Bindings; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; +import javafx.collections.transformation.SortedList; import org.jabref.Globals; import org.jabref.gui.util.BindingsHelper; @@ -17,17 +18,20 @@ import org.jabref.preferences.JabRefPreferences; public class MainTableDataModel { - private final FilteredList entriesFiltered; + private final SortedList entries; public MainTableDataModel(BibDatabaseContext context) { ObservableList allEntries = context.getDatabase().getEntries(); - entriesFiltered = new FilteredList<>( + FilteredList entriesFiltered = new FilteredList<>( BindingsHelper.mapBacked(allEntries, BibEntryTableViewModel::new)); entriesFiltered.predicateProperty().bind( Bindings.createObjectBinding(() -> this::isMatched, Globals.stateManager.activeGroupProperty(), Globals.stateManager.activeSearchQueryProperty()) ); + + // We need to wrap the list since otherwise sorting in the table does not work + entries = new SortedList<>(entriesFiltered); } private boolean isMatched(BibEntryTableViewModel entry) { @@ -61,7 +65,7 @@ private Optional createGroupMatcher(List selectedGrou return Optional.of(searchRules); } - public ObservableList getEntriesFiltered() { - return entriesFiltered; + public SortedList getEntriesFiltered() { + return entries; } } From df749ca856553accb003805a09d61d6f2db5878a Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 30 Jan 2018 00:40:07 +0100 Subject: [PATCH 030/827] Fix not JavaFX thread bug --- .../gui/importer/actions/OpenDatabaseAction.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 7e6b2d29d19..38ad18f94c4 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -272,11 +272,6 @@ private BasePanel addNewDatabase(ParserResult result, final Path file, boolean r .execute(() -> ParserResultWarningDialog.showParserResultWarningDialog(result, frame)); } - BasePanel basePanel = new BasePanel(frame, BasePanelPreferences.from(Globals.prefs), result.getDatabaseContext(), ExternalFileTypes.getInstance()); - - // file is set to null inside the EventDispatcherThread - SwingUtilities.invokeLater(() -> frame.addTab(basePanel, raisePanel)); - if (Objects.nonNull(file)) { frame.output(Localization.lang("Opened library") + " '" + file.toString() + "' " + Localization.lang("with") @@ -284,7 +279,12 @@ private BasePanel addNewDatabase(ParserResult result, final Path file, boolean r + database.getEntryCount() + " " + Localization.lang("entries") + "."); } - return basePanel; + return DefaultTaskExecutor.runInJavaFXThread(() -> { + BasePanel basePanel = new BasePanel(frame, BasePanelPreferences.from(Globals.prefs), result.getDatabaseContext(), ExternalFileTypes.getInstance()); + frame.addTab(basePanel, raisePanel); + return basePanel; + } + ); } } From 85342350f6f5e0313764d5d4a3f40f9cb76bc7f1 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 30 Jan 2018 00:49:55 +0100 Subject: [PATCH 031/827] Revert sorting fix --- src/main/java/org/jabref/gui/maintable/MainTable.java | 6 +++--- .../java/org/jabref/gui/maintable/MainTableDataModel.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 9afd2bfb8e8..5ccec1f8a24 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -9,7 +9,7 @@ import javax.swing.JTable; import javafx.collections.ListChangeListener; -import javafx.collections.transformation.SortedList; +import javafx.collections.ObservableList; import javafx.scene.control.ScrollPane; import javafx.scene.control.SelectionMode; import javafx.scene.control.TableView; @@ -87,11 +87,11 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, } this.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); - SortedList entries = model.getEntriesFiltered(); + ObservableList entries = model.getEntriesFiltered(); this.setItems(entries); // Enable sorting - entries.comparatorProperty().bind(this.comparatorProperty()); + //entries.comparatorProperty().bind(this.comparatorProperty()); // TODO: Cannot add focus listener as it is expecting an swing component //addFocusListener(Globals.getFocusListener()); diff --git a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java index bd7643b266b..f3f2f73c536 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java @@ -4,9 +4,9 @@ import java.util.Optional; import javafx.beans.binding.Bindings; +import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; -import javafx.collections.transformation.SortedList; import org.jabref.Globals; import org.jabref.gui.util.BindingsHelper; @@ -18,7 +18,7 @@ import org.jabref.preferences.JabRefPreferences; public class MainTableDataModel { - private final SortedList entries; + private final ObservableList entries; public MainTableDataModel(BibDatabaseContext context) { ObservableList allEntries = context.getDatabase().getEntries(); @@ -31,7 +31,7 @@ public MainTableDataModel(BibDatabaseContext context) { ); // We need to wrap the list since otherwise sorting in the table does not work - entries = new SortedList<>(entriesFiltered); + entries = FXCollections.synchronizedObservableList(entriesFiltered); } private boolean isMatched(BibEntryTableViewModel entry) { @@ -65,7 +65,7 @@ private Optional createGroupMatcher(List selectedGrou return Optional.of(searchRules); } - public SortedList getEntriesFiltered() { + public ObservableList getEntriesFiltered() { return entries; } } From 4e5f46b17afbe3d10fd2fa5bd964af643ac18a14 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 30 Jan 2018 13:02:25 +0100 Subject: [PATCH 032/827] Now fix sorting for real --- .../org/jabref/gui/maintable/MainTable.java | 2 +- .../gui/maintable/MainTableColumnFactory.java | 3 +++ .../gui/maintable/MainTableDataModel.java | 20 +++++++++++++------ .../gui/maintable/StringTableColumn.java | 12 ++++++++--- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 5ccec1f8a24..ec4033de312 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -91,7 +91,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, this.setItems(entries); // Enable sorting - //entries.comparatorProperty().bind(this.comparatorProperty()); + model.bindComparator(this.comparatorProperty()); // TODO: Cannot add focus listener as it is expecting an swing component //addFocusListener(Globals.getFocusListener()); diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index 435e9e7fc89..c0face6c670 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -99,6 +99,9 @@ public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences pre // There might be more than one field to display, e.g., "author/editor" or "date/year" - so split String[] fields = columnName.split(FieldName.FIELD_SEPARATOR); StringTableColumn column = new StringTableColumn(columnName, Arrays.asList(fields), database.getDatabase()); + new ValueTableCellFactory() + .withText(text -> text) + .install(column); column.setPrefWidth(preferences.getPrefColumnWidth(columnName)); columns.add(column); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java index f3f2f73c536..7b4ea1ffce9 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java @@ -1,12 +1,14 @@ package org.jabref.gui.maintable; +import java.util.Comparator; import java.util.List; import java.util.Optional; import javafx.beans.binding.Bindings; -import javafx.collections.FXCollections; +import javafx.beans.property.ReadOnlyObjectProperty; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; +import javafx.collections.transformation.SortedList; import org.jabref.Globals; import org.jabref.gui.util.BindingsHelper; @@ -18,20 +20,22 @@ import org.jabref.preferences.JabRefPreferences; public class MainTableDataModel { - private final ObservableList entries; + private final FilteredList entriesFiltered; + private final SortedList entriesSorted; public MainTableDataModel(BibDatabaseContext context) { ObservableList allEntries = context.getDatabase().getEntries(); - FilteredList entriesFiltered = new FilteredList<>( - BindingsHelper.mapBacked(allEntries, BibEntryTableViewModel::new)); + ObservableList entriesViewModel = BindingsHelper.mapBacked(allEntries, BibEntryTableViewModel::new); + + entriesFiltered = new FilteredList<>(entriesViewModel); entriesFiltered.predicateProperty().bind( Bindings.createObjectBinding(() -> this::isMatched, Globals.stateManager.activeGroupProperty(), Globals.stateManager.activeSearchQueryProperty()) ); // We need to wrap the list since otherwise sorting in the table does not work - entries = FXCollections.synchronizedObservableList(entriesFiltered); + entriesSorted = new SortedList<>(entriesViewModel); } private boolean isMatched(BibEntryTableViewModel entry) { @@ -66,6 +70,10 @@ private Optional createGroupMatcher(List selectedGrou } public ObservableList getEntriesFiltered() { - return entries; + return entriesSorted; + } + + public void bindComparator(ReadOnlyObjectProperty> comparator) { + entriesSorted.comparatorProperty().bind(comparator); } } diff --git a/src/main/java/org/jabref/gui/maintable/StringTableColumn.java b/src/main/java/org/jabref/gui/maintable/StringTableColumn.java index 7b6bfaa0e65..252ff5970c6 100644 --- a/src/main/java/org/jabref/gui/maintable/StringTableColumn.java +++ b/src/main/java/org/jabref/gui/maintable/StringTableColumn.java @@ -5,7 +5,8 @@ import java.util.Optional; import java.util.StringJoiner; -import javafx.beans.property.SimpleStringProperty; +import javafx.beans.binding.Bindings; +import javafx.beans.binding.ObjectBinding; import javafx.beans.value.ObservableValue; import javafx.scene.Node; import javafx.scene.control.Label; @@ -89,6 +90,12 @@ public ObservableValue getColumnValue(BibEntryTableViewModel entry) { if (bibtexFields.isEmpty()) { return null; } + + ObjectBinding[] dependencies = bibtexFields.stream().map(entry::getField).toArray(ObjectBinding[]::new); + return Bindings.createStringBinding(() -> computeText(entry), dependencies); + } + + private String computeText(BibEntryTableViewModel entry) { boolean isNameColumn = false; Optional content = Optional.empty(); @@ -109,8 +116,7 @@ public ObservableValue getColumnValue(BibEntryTableViewModel entry) { if (result != null && !bibtexFields.contains(BibEntry.KEY_FIELD)) { result = toUnicode.format(result).trim(); } - - return new SimpleStringProperty(result); + return result; } public Node getHeaderLabel() { From 1d1b3e756c33a35b301b1bad369507e80846607b Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 30 Jan 2018 13:06:15 +0100 Subject: [PATCH 033/827] Fix changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1443f7cc00..fafe7140a38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We added [oaDOI](https://oadoi.org/) as a fulltext provider, so that JabRef is now able to provide fulltexts for more than 90 million open-access articles. - We completely reworked and redesigned the main table. - We changed one default of [Cleanup entries dialog](http://help.jabref.org/en/CleanupEntries): Per default, the PDF are not moved to the default file directory anymore. [#3619](https://github.com/JabRef/jabref/issues/3619) -- We completely reworked and redesigned the main table. +- We added a new type of group that shows all items referenced in a given LaTeX file (actually the generated AUX file). [#1664](https://github.com/JabRef/jabref/issues/1664) +- We added the export of the `translator` field to the according MS-Office XML field. [#1750, comment](https://github.com/JabRef/jabref/issues/1750#issuecomment-357350986) - We added the export of the the `translator` field to the according MS-Office XML field. [#1750, comment](https://github.com/JabRef/jabref/issues/1750#issuecomment-357350986) - We changed the import of the MS-Office XML fields `bookauthor` and `translator`. Both are now imported to their corresponding bibtex/biblatex fields. - We improved the export of the `address` and `location` field to the MS-Office XML fields. If the address field does not contain a comma, it is treated as single value and exported to the field `city`. [#1750, comment](https://github.com/JabRef/jabref/issues/1750#issuecomment-357539167) From 63f962d9c31c29fddf6956c513fa29f504221f1e Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 30 Jan 2018 13:15:20 +0100 Subject: [PATCH 034/827] Fix filtering --- src/main/java/org/jabref/gui/maintable/MainTableDataModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java index 7b4ea1ffce9..6ee7c5d7c2d 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java @@ -35,7 +35,7 @@ public MainTableDataModel(BibDatabaseContext context) { ); // We need to wrap the list since otherwise sorting in the table does not work - entriesSorted = new SortedList<>(entriesViewModel); + entriesSorted = new SortedList<>(entriesFiltered); } private boolean isMatched(BibEntryTableViewModel entry) { From 904a2878300793b54c5b53eec3c19e5ee9edd9bf Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 30 Jan 2018 13:26:06 +0100 Subject: [PATCH 035/827] Fix exception in external file type dialog --- .../jabref/gui/externalfiletype/ExternalFileTypeEditor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java index 76e07c9592c..3b0fa5a70b4 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java @@ -15,7 +15,6 @@ import javax.swing.Action; import javax.swing.ActionMap; import javax.swing.BorderFactory; -import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.InputMap; import javax.swing.JButton; @@ -33,6 +32,7 @@ import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefDialog; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.JabRefIcon; import org.jabref.gui.actions.MnemonicAwareAction; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.l10n.Localization; @@ -258,7 +258,7 @@ static class IconRenderer implements TableCellRenderer { public Component getTableCellRendererComponent(JTable tab, Object value, boolean isSelected, boolean hasFocus, int row, int column) { lab.setText(null); - lab.setIcon((Icon) value); + lab.setIcon(((JabRefIcon) value).getIcon()); return lab; } } From 298e7fef4b54a316c5b9af432cb5cd260e1a64a1 Mon Sep 17 00:00:00 2001 From: Joerg Lenhard Date: Tue, 30 Jan 2018 13:56:12 +0100 Subject: [PATCH 036/827] Entry changes should mark panel as changed --- src/main/java/org/jabref/gui/BasePanel.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 831357474c6..431c2e857e1 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -222,6 +222,8 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas // ensure that at each addition of a new entry, the entry is added to the groups interface this.bibDatabaseContext.getDatabase().registerListener(new GroupTreeListener()); + // ensure that all entry changes mark the panel as changed + this.bibDatabaseContext.getDatabase().registerListener(this); Optional file = bibDatabaseContext.getDatabaseFile(); if (file.isPresent()) { @@ -2060,6 +2062,11 @@ public void listen(EntryRemovedEvent removedEntryEvent) { } } + @Subscribe + public void listen(EntryChangedEvent entryChangedEvent) { + this.markBaseChanged(); + } + private class UndoAction implements BaseAction { @Override From 28333351887f0ac09d4ad4f86172cc85c2e530ce Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 2 Feb 2018 01:06:00 +0100 Subject: [PATCH 037/827] Fix build --- src/main/java/org/jabref/JabRefGUI.java | 11 +++- src/main/java/org/jabref/gui/BasePanel.java | 2 - .../java/org/jabref/gui/EntryTypeDialog.java | 26 +++++++++ .../org/jabref/gui/GenFieldsCustomizer.java | 3 + src/main/java/org/jabref/gui/JabRefFrame.java | 16 ++--- .../gui/actions/IntegrityCheckAction.java | 26 ++++++++- .../jabref/gui/actions/NewEntryAction.java | 7 +++ .../jabref/gui/auximport/FromAuxDialog.java | 4 ++ .../ResolveDuplicateLabelDialog.java | 4 ++ .../org/jabref/gui/collab/ChangeScanner.java | 11 ++++ .../ContentSelectorDialog.java | 28 +++++++++ .../EntryCustomizationDialog.java | 2 + .../org/jabref/gui/desktop/JabRefDesktop.java | 15 +++++ .../gui/exporter/CustomExportDialog.java | 20 +++++++ .../exporter/ExportCustomizationDialog.java | 4 ++ .../gui/exporter/ExportToClipboardAction.java | 2 - .../gui/exporter/SaveDatabaseAction.java | 10 ++++ .../externalfiles/DownloadExternalFile.java | 11 ++++ .../gui/externalfiles/DroppedFileHandler.java | 23 +++++++- .../gui/externalfiles/FindFullTextAction.java | 13 ++++- .../gui/externalfiles/WriteXMPAction.java | 4 +- .../ExternalFileMenuItem.java | 9 +++ .../org/jabref/gui/groups/GroupDialog.java | 5 ++ .../importer/ImportCustomizationDialog.java | 27 +++++++++ .../jabref/gui/importer/ImportFormats.java | 2 +- .../gui/importer/ImportInspectionDialog.java | 6 ++ .../actions/AppendDatabaseAction.java | 3 +- .../importer/actions/OpenDatabaseAction.java | 18 ++++++ .../gui/openoffice/StyleSelectDialog.java | 1 + .../gui/plaintextimport/TextInputDialog.java | 58 +++++++++++++++++++ .../gui/preftabs/PreferencesDialog.java | 1 + .../protectedterms/ProtectedTermsDialog.java | 35 +++++++++++ .../java/org/jabref/gui/push/PushToEmacs.java | 9 +++ .../java/org/jabref/gui/push/PushToVim.java | 9 +++ .../shared/ConnectToSharedDatabaseDialog.java | 32 ++++++++++ .../org/jabref/pdfimport/PdfImporter.java | 11 ++++ 36 files changed, 444 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index fe3becbe307..2e85d6903d2 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -2,6 +2,7 @@ import java.awt.Frame; import java.io.File; +import java.lang.annotation.Native; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; @@ -15,6 +16,12 @@ import javax.swing.UnsupportedLookAndFeelException; import javax.swing.plaf.FontUIResource; +import javafx.application.Platform; +import javafx.scene.Scene; +import javafx.scene.control.TextArea; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + import org.jabref.gui.BasePanel; import org.jabref.gui.GUIGlobals; import org.jabref.gui.JabRefFrame; @@ -34,10 +41,10 @@ import org.jabref.model.database.shared.DatabaseNotSupportedException; import org.jabref.preferences.JabRefPreferences; +import com.sun.star.awt.Pointer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.sun.jna.platform.win32.WinUser.GWL_STYLE; public class JabRefGUI { @@ -158,6 +165,7 @@ private void openWindow(Stage mainStage) { mainStage.setScene(scene); mainStage.show(); + /* //gets this window (stage) long lhwnd = com.sun.glass.ui.Window.getWindows().get(0).getNativeWindow(); Pointer lpVoid = new Pointer(lhwnd); @@ -182,6 +190,7 @@ private void openWindow(Stage mainStage) { newStyle = newStyle & ~0x00040000;//WS_THICKFRAME user32.SetWindowLong(hwnd, GWL_STYLE, newStyle); } + */ mainStage.setOnCloseRequest(event -> { mainFrame.quit(); diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 5c9ab374631..c10a6b41e39 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -568,7 +568,6 @@ public void update() { actions.put(Actions.PLAIN_TEXT_IMPORT, (BaseAction) () -> { // get Type of new entry EntryTypeDialog etd = new EntryTypeDialog(frame); - etd.setLocationRelativeTo(frame); etd.setVisible(true); EntryType tp = etd.getChoice(); if (tp == null) { @@ -577,7 +576,6 @@ public void update() { BibEntry bibEntry = new BibEntry(tp.getName()); TextInputDialog tidialog = new TextInputDialog(frame, bibEntry); - tidialog.setLocationRelativeTo(frame); tidialog.setVisible(true); if (tidialog.okPressed()) { diff --git a/src/main/java/org/jabref/gui/EntryTypeDialog.java b/src/main/java/org/jabref/gui/EntryTypeDialog.java index afdfabeff2d..357d70fdd48 100644 --- a/src/main/java/org/jabref/gui/EntryTypeDialog.java +++ b/src/main/java/org/jabref/gui/EntryTypeDialog.java @@ -1,5 +1,31 @@ package org.jabref.gui; +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; + +import javax.swing.AbstractAction; +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; + import com.jgoodies.forms.builder.ButtonBarBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/org/jabref/gui/GenFieldsCustomizer.java b/src/main/java/org/jabref/gui/GenFieldsCustomizer.java index 2773c12a157..cd7b0747edc 100644 --- a/src/main/java/org/jabref/gui/GenFieldsCustomizer.java +++ b/src/main/java/org/jabref/gui/GenFieldsCustomizer.java @@ -35,6 +35,9 @@ import java.awt.event.ActionEvent; import java.util.Locale; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.layout.Sizes; + public class GenFieldsCustomizer extends JabRefDialog { private final JPanel buttons = new JPanel(); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index ce8fe2e115d..6d13df14341 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -62,10 +62,14 @@ import javafx.application.Platform; import javafx.collections.ListChangeListener; import javafx.embed.swing.JFXPanel; +import javafx.embed.swing.SwingNode; import javafx.scene.Scene; +import javafx.scene.control.SplitPane; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.control.Tooltip; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.StackPane; import org.jabref.Globals; import org.jabref.JabRefExecutorService; @@ -898,8 +902,6 @@ private void initLayout() { toolbarPanel.add(globalSearchBar); //getContentPane().add(toolbarPanel, BorderLayout.PAGE_START); - splitPane.setDividerSize(2); - splitPane.setBorder(null); JFXPanel tabbedPaneContainer = CustomJFXPanel.wrap(new Scene(tabbedPane)); // TODO: Remove this hack as soon as toolbar is implemented in JavaFX and these events are no longer captured globally tabbedPaneContainer.addKeyListener(new KeyAdapter() { @@ -924,25 +926,17 @@ public void keyPressed(KeyEvent e) { } }); - splitPane.setRightComponent(tabbedPaneContainer); - splitPane.setLeftComponent(sidePaneManager.getPanel()); - getContentPane().add(splitPane, BorderLayout.CENTER); - StackPane header = new StackPane(); header.setId("header"); header.setPrefHeight(50); header.setStyle("-fx-background-color: #4d4674; -fx-text-fill: white;"); setTop(header); - SwingNode swingTabbedPane = new SwingNode(); SwingNode swingSidePane = new SwingNode(); SwingUtilities.invokeLater(() -> { - swingTabbedPane.setContent(tabbedPane); swingSidePane.setContent(sidePaneManager.getPanel()); }); - StackPane centerPane = new StackPane(); - centerPane.getChildren().addAll(swingTabbedPane, new Button("test")); - splitPane.getItems().addAll(swingSidePane, swingTabbedPane); + splitPane.getItems().addAll(swingSidePane, tabbedPane); UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0)); sidePaneManager.updateView(); diff --git a/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java b/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java index f0b79193673..83abbd8c558 100644 --- a/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java +++ b/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java @@ -1,5 +1,29 @@ package org.jabref.gui.actions; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.Action; +import javax.swing.JButton; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JPopupMenu; +import javax.swing.JProgressBar; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.RowFilter; +import javax.swing.SwingWorker; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumnModel; +import javax.swing.table.TableModel; +import javax.swing.table.TableRowSorter; + import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; import org.apache.commons.logging.Log; @@ -68,7 +92,7 @@ protected void done() { } if (messages.isEmpty()) { - JOptionPane.showMessageDialog(frame, Localization.lang("No problems found.")); + JOptionPane.showMessageDialog(null, Localization.lang("No problems found.")); } else { Map showMessage = new HashMap<>(); // prepare data model diff --git a/src/main/java/org/jabref/gui/actions/NewEntryAction.java b/src/main/java/org/jabref/gui/actions/NewEntryAction.java index af67122aa9e..c7df5260d9a 100644 --- a/src/main/java/org/jabref/gui/actions/NewEntryAction.java +++ b/src/main/java/org/jabref/gui/actions/NewEntryAction.java @@ -1,5 +1,12 @@ package org.jabref.gui.actions; +import java.awt.event.ActionEvent; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.Action; +import javax.swing.KeyStroke; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jabref.Globals; diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index 51a3cc2ea37..c7a493a5728 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -41,6 +41,10 @@ import java.nio.file.Path; import java.util.Optional; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.DefaultFormBuilder; +import com.jgoodies.forms.layout.FormLayout; + /** * A wizard dialog for generating a new sub database from existing TeX AUX file */ diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java b/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java index 224c62bde1d..f06bfe2b80e 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java @@ -33,6 +33,10 @@ import java.util.ArrayList; import java.util.List; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; + /** * Dialog box for resolving duplicate bibte keys */ diff --git a/src/main/java/org/jabref/gui/collab/ChangeScanner.java b/src/main/java/org/jabref/gui/collab/ChangeScanner.java index a49395cc07b..b2d5a07a6e0 100644 --- a/src/main/java/org/jabref/gui/collab/ChangeScanner.java +++ b/src/main/java/org/jabref/gui/collab/ChangeScanner.java @@ -1,5 +1,16 @@ package org.jabref.gui.collab; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; + +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; +import javax.swing.tree.DefaultMutableTreeNode; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jabref.Globals; diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java index 54eb3a70c6e..e61d4d0e89f 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java @@ -1,5 +1,33 @@ package org.jabref.gui.contentselector; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; + import com.jgoodies.forms.builder.ButtonBarBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java b/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java index 2e7d16ad49b..d53e494be78 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java +++ b/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java @@ -60,6 +60,8 @@ import java.util.List; import java.util.stream.Collectors; +import com.jgoodies.forms.builder.ButtonBarBuilder; + public class EntryCustomizationDialog extends JabRefDialog implements ListSelectionListener { protected GridBagLayout gbl = new GridBagLayout(); diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index 58cc83f608a..332729c7616 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -1,5 +1,20 @@ package org.jabref.gui.desktop; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.Optional; +import java.util.regex.Pattern; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jabref.Globals; diff --git a/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java b/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java index 1616b4b626a..164684836e0 100644 --- a/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java +++ b/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java @@ -1,5 +1,25 @@ package org.jabref.gui.exporter; +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.nio.file.Path; +import java.nio.file.Paths; + +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + import com.jgoodies.forms.builder.ButtonBarBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java index a6ec089b356..8c667760ad5 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java @@ -38,6 +38,10 @@ import java.util.Arrays; import java.util.List; +import ca.odell.glazedlists.gui.TableFormat; +import ca.odell.glazedlists.swing.DefaultEventTableModel; +import com.jgoodies.forms.builder.ButtonBarBuilder; + /** *

Title:

*

Description:

diff --git a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java index 0097b03d932..13c8974c1db 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java +++ b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java @@ -6,8 +6,6 @@ import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; import org.jabref.gui.worker.AbstractWorker; -import org.jabref.logic.exporter.ExportFormats; -import org.jabref.logic.exporter.IExportFormat; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index 7a38819b2d8..db91429ab9b 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -1,5 +1,15 @@ package org.jabref.gui.exporter; +import java.io.File; +import java.nio.charset.Charset; +import java.nio.charset.UnsupportedCharsetException; +import java.nio.file.Path; +import java.util.Optional; + +import javax.swing.JOptionPane; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; + import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; import org.apache.commons.logging.Log; diff --git a/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java b/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java index 9cbd408ff19..988ca5a09b9 100644 --- a/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java +++ b/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java @@ -1,5 +1,16 @@ package org.jabref.gui.externalfiles; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.Paths; +import java.util.List; +import java.util.Optional; + +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jabref.Globals; diff --git a/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java b/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java index 4f6bdc3270b..9e35130b352 100644 --- a/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java @@ -1,5 +1,26 @@ package org.jabref.gui.externalfiles; +import java.awt.BorderLayout; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Optional; + +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; import org.apache.commons.logging.Log; @@ -504,7 +525,7 @@ private boolean doMove(String fileName, String destFilename, NamedCompound edits private boolean doCopy(String fileName, String toFile, NamedCompound edits) { List dirs = panel.getBibDatabaseContext() - .getFileDirectories(Globals.prefs.getFileDirectoryPreferences()); + .getFileDirectories(Globals.prefs.getFileDirectoryPreferences()); int found = -1; for (int i = 0; i < dirs.size(); i++) { if (new File(dirs.get(i)).exists()) { diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index c667af3c5aa..0d3b998724e 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -1,5 +1,16 @@ package org.jabref.gui.externalfiles; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; + +import javax.swing.JOptionPane; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jabref.Globals; @@ -69,7 +80,7 @@ public void run() { @Override public void update() { List> remove = new ArrayList<>(); - for (Entry, BibEntry> download : downloads.entrySet()) { + for (Map.Entry, BibEntry> download : downloads.entrySet()) { BibEntry entry = download.getValue(); Optional result = download.getKey(); if (result.isPresent()) { diff --git a/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java b/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java index 604095a14d7..760f9857e10 100644 --- a/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java @@ -63,7 +63,7 @@ public void init() { if (entries.isEmpty()) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("This operation requires one or more entries to be selected."), Localization.lang("Write XMP-metadata"), JOptionPane.ERROR_MESSAGE); goOn = false; @@ -71,7 +71,7 @@ public void init() { } else { - int response = JOptionPane.showConfirmDialog(frame, Localization.lang("Write XMP-metadata for all PDFs in current library?"), + int response = JOptionPane.showConfirmDialog(null, Localization.lang("Write XMP-metadata for all PDFs in current library?"), Localization.lang("Write XMP-metadata"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java index 9e6d417ee02..71d786a503a 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java @@ -1,5 +1,14 @@ package org.jabref.gui.externalfiletype; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.util.Optional; + +import javax.swing.Icon; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jabref.gui.JabRefFrame; diff --git a/src/main/java/org/jabref/gui/groups/GroupDialog.java b/src/main/java/org/jabref/gui/groups/GroupDialog.java index ea463995623..4d9439b7ac5 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialog.java @@ -70,6 +70,11 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.DefaultFormBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; + /** * Dialog for creating or modifying groups. Operates directly on the Vector * containing group information. diff --git a/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java b/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java index 5f4c3355e4d..466e1fcd801 100644 --- a/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java @@ -1,5 +1,32 @@ package org.jabref.gui.importer; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.EnumSet; +import java.util.Optional; +import java.util.zip.ZipFile; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.ScrollPaneConstants; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumnModel; + import com.jgoodies.forms.builder.ButtonBarBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/org/jabref/gui/importer/ImportFormats.java b/src/main/java/org/jabref/gui/importer/ImportFormats.java index 499487417d7..26568a9c10d 100644 --- a/src/main/java/org/jabref/gui/importer/ImportFormats.java +++ b/src/main/java/org/jabref/gui/importer/ImportFormats.java @@ -83,7 +83,7 @@ public void actionPerformed(ActionEvent e) { private void doImport(Path file, SortedSet importers, FileChooser.ExtensionFilter selectedExtensionFilter) { if (!Files.exists(file)) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Localization.lang("File not found") + ": '" + file.getFileName() + "'.", Localization.lang("Import"), JOptionPane.ERROR_MESSAGE); return; diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index 2368a729a1c..06fb17dbcfc 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -56,6 +56,12 @@ import org.jabref.gui.BasePanelPreferences; import org.jabref.gui.DuplicateResolverDialog; import org.jabref.gui.DuplicateResolverDialog.DuplicateResolverResult; +import org.jabref.gui.EntryMarker; +import org.jabref.gui.GUIGlobals; +import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefDialog; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.PreviewPanel; import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.externalfiles.AutoSetLinks; diff --git a/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java index 7d54439a193..3c0fd4fbb79 100644 --- a/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java @@ -147,7 +147,6 @@ private static void addGroups(GroupTreeNode newGroups, CompoundEdit ce) { public void action() { filesToOpen.clear(); final MergeDialog dialog = new MergeDialog(frame, Localization.lang("Append library"), true); - dialog.setLocationRelativeTo(frame); dialog.setVisible(true); if (dialog.isOkPressed()) { @@ -187,7 +186,7 @@ private void openIt(boolean importEntries, boolean importStrings, boolean import panel.output(Localization.lang("Imported from library") + " '" + file + "'"); } catch (IOException | KeyCollisionException ex) { LOGGER.warn("Could not open database", ex); - JOptionPane.showMessageDialog(frame, ex.getMessage(), Localization.lang("Open library"), + JOptionPane.showMessageDialog(null, ex.getMessage(), Localization.lang("Open library"), JOptionPane.ERROR_MESSAGE); } } 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 956cfebcbd8..1e4235a7c47 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -1,5 +1,23 @@ package org.jabref.gui.importer.actions; +import java.awt.event.ActionEvent; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.FileTime; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +import javax.swing.Action; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jabref.Globals; diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java index c0a3eec5c03..c45bd696f09 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java @@ -20,6 +20,7 @@ import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDialog; +import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPopupMenu; diff --git a/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java b/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java index 844705fdc03..1f1a2d6c29c 100644 --- a/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java +++ b/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java @@ -1,5 +1,63 @@ package org.jabref.gui.plaintextimport; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.DefaultListCellRenderer; +import javax.swing.Icon; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.JTextPane; +import javax.swing.JToolBar; +import javax.swing.ListSelectionModel; +import javax.swing.ScrollPaneConstants; +import javax.swing.border.TitledBorder; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.text.BadLocationException; +import javax.swing.text.EditorKit; +import javax.swing.text.Style; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyleContext; +import javax.swing.text.StyledDocument; + import com.jgoodies.forms.builder.ButtonBarBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java b/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java index fbae7d194e9..145008b2902 100644 --- a/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java +++ b/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java @@ -14,6 +14,7 @@ import javax.swing.AbstractAction; import javax.swing.BorderFactory; import javax.swing.JButton; +import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; diff --git a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java b/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java index f2f0bb9ad4d..90f92a2161b 100644 --- a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java +++ b/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java @@ -1,5 +1,40 @@ package org.jabref.gui.protectedterms; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Objects; +import java.util.Optional; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.KeyStroke; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumnModel; + import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; diff --git a/src/main/java/org/jabref/gui/push/PushToEmacs.java b/src/main/java/org/jabref/gui/push/PushToEmacs.java index 2b149731214..06cb076ca40 100644 --- a/src/main/java/org/jabref/gui/push/PushToEmacs.java +++ b/src/main/java/org/jabref/gui/push/PushToEmacs.java @@ -1,5 +1,14 @@ package org.jabref.gui.push; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +import javax.swing.Icon; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jabref.Globals; diff --git a/src/main/java/org/jabref/gui/push/PushToVim.java b/src/main/java/org/jabref/gui/push/PushToVim.java index 0de36d3175d..a171130dc11 100644 --- a/src/main/java/org/jabref/gui/push/PushToVim.java +++ b/src/main/java/org/jabref/gui/push/PushToVim.java @@ -1,5 +1,14 @@ package org.jabref.gui.push; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +import javax.swing.Icon; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jabref.Globals; diff --git a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java index c8d45c1d4ac..70e2c204d32 100644 --- a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java +++ b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java @@ -1,5 +1,37 @@ package org.jabref.gui.shared; +import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.io.UnsupportedEncodingException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.GeneralSecurityException; +import java.sql.SQLException; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JTextField; +import javax.swing.KeyStroke; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jabref.Globals; diff --git a/src/main/java/org/jabref/pdfimport/PdfImporter.java b/src/main/java/org/jabref/pdfimport/PdfImporter.java index da9fcfb17b8..23e6a37be54 100644 --- a/src/main/java/org/jabref/pdfimport/PdfImporter.java +++ b/src/main/java/org/jabref/pdfimport/PdfImporter.java @@ -1,5 +1,16 @@ package org.jabref.pdfimport; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.Optional; + +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jabref.Globals; From 6d7d4e5120b869781ceaacee72f3f44b53e1aa7a Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 2 Feb 2018 01:15:36 +0100 Subject: [PATCH 038/827] Fix import orders --- src/main/java/org/jabref/JabRefGUI.java | 3 -- src/main/java/org/jabref/JabRefMain.java | 4 +- src/main/java/org/jabref/gui/BasePanel.java | 17 +++++-- .../jabref/gui/DuplicateResolverDialog.java | 14 +++--- .../java/org/jabref/gui/EntryTypeDialog.java | 9 ++-- src/main/java/org/jabref/gui/FXDialog.java | 9 ++-- .../org/jabref/gui/GenFieldsCustomizer.java | 6 +-- src/main/java/org/jabref/gui/JabRefFrame.java | 37 +++++++--------- src/main/java/org/jabref/gui/MergeDialog.java | 20 +++++++-- .../java/org/jabref/gui/PreambleEditor.java | 23 +++++++--- .../org/jabref/gui/ReplaceStringDialog.java | 28 +++++++++--- .../java/org/jabref/gui/StringDialog.java | 43 ++++++++++++------ .../org/jabref/gui/WaitForSaveOperation.java | 18 +++++--- .../gui/actions/AutoLinkFilesAction.java | 12 +++-- .../org/jabref/gui/actions/CleanupAction.java | 4 -- .../gui/actions/IntegrityCheckAction.java | 4 -- .../gui/actions/ManageKeywordsAction.java | 44 +++++++++++++------ .../gui/actions/MassSetFieldAction.java | 37 ++++++++++++---- .../jabref/gui/actions/NewEntryAction.java | 2 - .../gui/actions/NewSubDatabaseAction.java | 7 +-- .../autosaveandbackup/BackupUIManager.java | 8 ++-- .../jabref/gui/auximport/FromAuxDialog.java | 13 +++--- .../BibtexKeyPatternDialog.java | 20 ++++++--- .../ResolveDuplicateLabelDialog.java | 7 +-- .../org/jabref/gui/collab/ChangeScanner.java | 9 ++-- .../ContentSelectorDialog.java | 3 -- .../EntryCustomizationDialog.java | 14 +----- .../org/jabref/gui/desktop/JabRefDesktop.java | 8 ++-- .../gui/exporter/CustomExportDialog.java | 3 -- .../exporter/ExportCustomizationDialog.java | 9 +--- .../gui/exporter/ExportToClipboardAction.java | 12 +---- .../gui/exporter/SaveDatabaseAction.java | 10 ++--- .../externalfiles/DownloadExternalFile.java | 2 - .../gui/externalfiles/DroppedFileHandler.java | 4 -- .../gui/externalfiles/FindFullTextAction.java | 2 - .../externalfiles/SynchronizeFileField.java | 40 ++++++++++++----- .../gui/externalfiles/WriteXMPAction.java | 36 ++++++++++----- .../ExternalFileMenuItem.java | 2 - .../ExternalFileTypeEditor.java | 16 +------ .../gui/groups/GroupAddRemoveDialog.java | 34 +++++++++----- .../org/jabref/gui/groups/GroupDialog.java | 11 +---- .../gui/importer/FetcherPreviewDialog.java | 44 +++++++++++++------ .../importer/ImportCustomizationDialog.java | 3 -- .../jabref/gui/importer/ImportFormats.java | 3 +- .../gui/importer/ImportInspectionDialog.java | 8 +++- .../jabref/gui/importer/ImportMenuItem.java | 30 ++++++++----- .../importer/ParserResultWarningDialog.java | 13 +++--- .../actions/CheckForNewEntryTypesAction.java | 20 ++++++--- .../importer/actions/OpenDatabaseAction.java | 2 - .../gui/importer/fetcher/GeneralFetcher.java | 27 ++++++++---- .../org/jabref/gui/menus/FileHistoryMenu.java | 17 ++++--- .../gui/mergeentries/MergeEntriesDialog.java | 19 +++++--- .../mergeentries/MergeFetchedEntryDialog.java | 26 ++++++----- .../MergeWithFetchedEntryAction.java | 4 +- .../gui/openoffice/AdvancedCiteDialog.java | 24 +++++++--- .../gui/openoffice/CitationManager.java | 39 ++++++++++------ .../gui/openoffice/OpenOfficePanel.java | 8 +++- .../gui/openoffice/StyleSelectDialog.java | 7 ++- .../gui/plaintextimport/TextInputDialog.java | 18 +++++--- .../org/jabref/gui/preftabs/ExternalTab.java | 22 ++++++++-- .../java/org/jabref/gui/preftabs/FileTab.java | 28 ++++++++---- .../gui/preftabs/PreferencesDialog.java | 6 ++- .../NewProtectedTermsFileDialog.java | 26 +++++++---- .../protectedterms/ProtectedTermsDialog.java | 11 +++-- .../gui/push/PushToApplicationAction.java | 14 +++--- .../gui/push/PushToApplicationButton.java | 37 +++++++++++----- .../java/org/jabref/gui/push/PushToEmacs.java | 2 - .../java/org/jabref/gui/push/PushToVim.java | 2 - .../shared/ConnectToSharedDatabaseDialog.java | 8 ++-- .../gui/shared/MergeSharedEntryDialog.java | 20 ++++++--- .../gui/shared/SharedDatabaseUIManager.java | 13 +++--- .../org/jabref/gui/worker/VersionWorker.java | 10 +---- .../migrations/FileLinksUpgradeWarning.java | 15 +++++-- .../org/jabref/pdfimport/PdfImporter.java | 2 - src/main/java/osx/macadapter/MacAdapter.java | 18 +++++--- .../java/org/jabref/gui/AbstractUITest.java | 19 ++++---- .../org/jabref/gui/ClipBoardManagerTest.java | 2 +- .../gui/groups/GroupTreeViewModelTest.java | 6 +-- .../logic/integrity/BracesCorrectorTest.java | 3 +- .../AuthorAndToSemicolonReplacerTest.java | 1 + .../logic/shared/DBMSProcessorTest.java | 4 +- .../specialfields/SpecialFieldsUtilsTest.java | 2 +- .../org/jabref/model/entry/BibEntryTests.java | 5 +-- .../jabref/model/entry/EntryLinkListTest.java | 7 +-- 84 files changed, 735 insertions(+), 464 deletions(-) diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index 2e85d6903d2..25c1097dd16 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -1,8 +1,6 @@ package org.jabref; -import java.awt.Frame; import java.io.File; -import java.lang.annotation.Native; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; @@ -41,7 +39,6 @@ import org.jabref.model.database.shared.DatabaseNotSupportedException; import org.jabref.preferences.JabRefPreferences; -import com.sun.star.awt.Pointer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/jabref/JabRefMain.java b/src/main/java/org/jabref/JabRefMain.java index 6563f618f65..ba2ef4836a6 100644 --- a/src/main/java/org/jabref/JabRefMain.java +++ b/src/main/java/org/jabref/JabRefMain.java @@ -4,13 +4,11 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; import javafx.application.Application; import javafx.application.Platform; import javafx.stage.Stage; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; + import org.jabref.cli.ArgumentProcessor; import org.jabref.gui.remote.JabRefMessageHandler; import org.jabref.logic.exporter.ExporterFactory; diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index c10a6b41e39..f0237e25b55 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -38,8 +38,7 @@ import javafx.scene.control.SplitPane; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.StackPane; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; + import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.actions.Actions; @@ -80,7 +79,13 @@ import org.jabref.gui.specialfields.SpecialFieldDatabaseChangeListener; import org.jabref.gui.specialfields.SpecialFieldValueViewModel; import org.jabref.gui.specialfields.SpecialFieldViewModel; -import org.jabref.gui.undo.*; +import org.jabref.gui.undo.CountingUndoManager; +import org.jabref.gui.undo.NamedCompound; +import org.jabref.gui.undo.UndoableChangeType; +import org.jabref.gui.undo.UndoableFieldChange; +import org.jabref.gui.undo.UndoableInsertEntry; +import org.jabref.gui.undo.UndoableKeyChange; +import org.jabref.gui.undo.UndoableRemoveEntry; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.component.CheckBoxMessage; @@ -91,7 +96,11 @@ import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.citationstyle.CitationStyleCache; import org.jabref.logic.citationstyle.CitationStyleOutputFormat; -import org.jabref.logic.exporter.*; +import org.jabref.logic.exporter.BibtexDatabaseWriter; +import org.jabref.logic.exporter.FileSaveSession; +import org.jabref.logic.exporter.SaveException; +import org.jabref.logic.exporter.SavePreferences; +import org.jabref.logic.exporter.SaveSession; import org.jabref.logic.l10n.Encodings; import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.Layout; diff --git a/src/main/java/org/jabref/gui/DuplicateResolverDialog.java b/src/main/java/org/jabref/gui/DuplicateResolverDialog.java index ff0a2976d54..2151be6eaa3 100644 --- a/src/main/java/org/jabref/gui/DuplicateResolverDialog.java +++ b/src/main/java/org/jabref/gui/DuplicateResolverDialog.java @@ -1,5 +1,14 @@ package org.jabref.gui; +import java.awt.BorderLayout; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; + import org.jabref.gui.help.HelpAction; import org.jabref.gui.importer.ImportInspectionDialog; import org.jabref.gui.mergeentries.MergeEntries; @@ -9,11 +18,6 @@ import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.awt.*; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - public class DuplicateResolverDialog extends JabRefDialog { public enum DuplicateResolverType { diff --git a/src/main/java/org/jabref/gui/EntryTypeDialog.java b/src/main/java/org/jabref/gui/EntryTypeDialog.java index 357d70fdd48..5bbde2f50e3 100644 --- a/src/main/java/org/jabref/gui/EntryTypeDialog.java +++ b/src/main/java/org/jabref/gui/EntryTypeDialog.java @@ -26,9 +26,6 @@ import javax.swing.SwingUtilities; import javax.swing.SwingWorker; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.importer.ImportInspectionDialog; import org.jabref.gui.keyboard.KeyBinding; @@ -41,7 +38,11 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.EntryTypes; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.*; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BiblatexEntryTypes; +import org.jabref.model.entry.BibtexEntryTypes; +import org.jabref.model.entry.EntryType; +import org.jabref.model.entry.IEEETranEntryTypes; import com.jgoodies.forms.builder.ButtonBarBuilder; import org.slf4j.Logger; diff --git a/src/main/java/org/jabref/gui/FXDialog.java b/src/main/java/org/jabref/gui/FXDialog.java index 1affaba5f0d..515ca87ea23 100644 --- a/src/main/java/org/jabref/gui/FXDialog.java +++ b/src/main/java/org/jabref/gui/FXDialog.java @@ -1,5 +1,9 @@ package org.jabref.gui; +import java.awt.Window; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + import javafx.application.Platform; import javafx.fxml.FXMLLoader; import javafx.scene.control.Alert; @@ -8,14 +12,11 @@ import javafx.scene.image.Image; import javafx.stage.Modality; import javafx.stage.Stage; + import org.jabref.Globals; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.keyboard.KeyBindingRepository; -import java.awt.*; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - /** * This class provides a super class for all dialogs implemented in JavaFX. * It mimics the behavior of a Swing JDialog which means once a object of this class diff --git a/src/main/java/org/jabref/gui/GenFieldsCustomizer.java b/src/main/java/org/jabref/gui/GenFieldsCustomizer.java index cd7b0747edc..4d2fc236d93 100644 --- a/src/main/java/org/jabref/gui/GenFieldsCustomizer.java +++ b/src/main/java/org/jabref/gui/GenFieldsCustomizer.java @@ -16,6 +16,7 @@ import javax.swing.InputMap; import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -30,11 +31,6 @@ import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.util.Locale; - import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.layout.Sizes; diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 6d13df14341..57da7b86ea3 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -1,12 +1,9 @@ package org.jabref.gui; -import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Cursor; import java.awt.FlowLayout; -import java.awt.Frame; -import java.awt.GraphicsEnvironment; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; @@ -15,11 +12,8 @@ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -40,7 +34,6 @@ import javax.swing.JCheckBoxMenuItem; import javax.swing.JComponent; import javax.swing.JDialog; -import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; @@ -49,7 +42,6 @@ import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JProgressBar; -import javax.swing.JSplitPane; import javax.swing.JToggleButton; import javax.swing.KeyStroke; import javax.swing.MenuElement; @@ -57,7 +49,6 @@ import javax.swing.SwingUtilities; import javax.swing.TransferHandler; import javax.swing.UIManager; -import javax.swing.WindowConstants; import javafx.application.Platform; import javafx.collections.ListChangeListener; @@ -73,7 +64,21 @@ import org.jabref.Globals; import org.jabref.JabRefExecutorService; -import org.jabref.gui.actions.*; +import org.jabref.gui.actions.Actions; +import org.jabref.gui.actions.AutoLinkFilesAction; +import org.jabref.gui.actions.ConnectToSharedDatabaseAction; +import org.jabref.gui.actions.ErrorConsoleAction; +import org.jabref.gui.actions.IntegrityCheckAction; +import org.jabref.gui.actions.LookupIdentifierAction; +import org.jabref.gui.actions.ManageKeywordsAction; +import org.jabref.gui.actions.MassSetFieldAction; +import org.jabref.gui.actions.MnemonicAwareAction; +import org.jabref.gui.actions.NewDatabaseAction; +import org.jabref.gui.actions.NewEntryAction; +import org.jabref.gui.actions.NewSubDatabaseAction; +import org.jabref.gui.actions.OpenBrowserAction; +import org.jabref.gui.actions.SearchForUpdateAction; +import org.jabref.gui.actions.SortTabsAction; import org.jabref.gui.autosaveandbackup.AutosaveUIManager; import org.jabref.gui.bibtexkeypattern.BibtexKeyPatternDialog; import org.jabref.gui.copyfiles.CopyFilesAction; @@ -145,18 +150,6 @@ import org.slf4j.LoggerFactory; import osx.macadapter.MacAdapter; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.MouseAdapter; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; -import java.util.List; - /** * The main window of the application. */ diff --git a/src/main/java/org/jabref/gui/MergeDialog.java b/src/main/java/org/jabref/gui/MergeDialog.java index eb7ef41919e..3148e9ecc6d 100644 --- a/src/main/java/org/jabref/gui/MergeDialog.java +++ b/src/main/java/org/jabref/gui/MergeDialog.java @@ -1,13 +1,25 @@ package org.jabref.gui; +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JPanel; + import org.jabref.Globals; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.l10n.Localization; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; - /** *

Title: MergeDialog

*

Description: Asks for details about merge database operation.

diff --git a/src/main/java/org/jabref/gui/PreambleEditor.java b/src/main/java/org/jabref/gui/PreambleEditor.java index 382538d1922..72a65a7e474 100644 --- a/src/main/java/org/jabref/gui/PreambleEditor.java +++ b/src/main/java/org/jabref/gui/PreambleEditor.java @@ -1,5 +1,23 @@ package org.jabref.gui; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Container; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JPanel; +import javax.swing.LayoutFocusTraversalPolicy; +import javax.swing.text.JTextComponent; + import org.jabref.Globals; import org.jabref.gui.actions.Actions; import org.jabref.gui.fieldeditors.FieldEditor; @@ -11,11 +29,6 @@ import org.jabref.model.database.BibDatabase; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import javax.swing.text.JTextComponent; -import java.awt.*; -import java.awt.event.*; - class PreambleEditor extends JabRefDialog { // A reference to the entry this object works on. private final BibDatabase database; diff --git a/src/main/java/org/jabref/gui/ReplaceStringDialog.java b/src/main/java/org/jabref/gui/ReplaceStringDialog.java index e9cc37fcb0b..6d3e6fec37f 100644 --- a/src/main/java/org/jabref/gui/ReplaceStringDialog.java +++ b/src/main/java/org/jabref/gui/ReplaceStringDialog.java @@ -1,5 +1,27 @@ package org.jabref.gui; +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Locale; + +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JTextField; + import org.jabref.Globals; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.undo.NamedCompound; @@ -7,12 +29,6 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Locale; - /** * Dialog for replacing strings. */ diff --git a/src/main/java/org/jabref/gui/StringDialog.java b/src/main/java/org/jabref/gui/StringDialog.java index 1960d244caf..fafe58f3a71 100644 --- a/src/main/java/org/jabref/gui/StringDialog.java +++ b/src/main/java/org/jabref/gui/StringDialog.java @@ -1,5 +1,35 @@ package org.jabref.gui; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Container; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.DefaultCellEditor; +import javax.swing.InputMap; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.JToolBar; +import javax.swing.LayoutFocusTraversalPolicy; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumnModel; +import javax.swing.undo.CompoundEdit; + import org.jabref.Globals; import org.jabref.gui.actions.Actions; import org.jabref.gui.help.HelpAction; @@ -18,19 +48,6 @@ import org.jabref.model.entry.BibtexString; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableColumnModel; -import javax.swing.undo.CompoundEdit; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - class StringDialog extends JabRefDialog { private static final String STRINGS_TITLE = Localization.lang("Strings for library"); diff --git a/src/main/java/org/jabref/gui/WaitForSaveOperation.java b/src/main/java/org/jabref/gui/WaitForSaveOperation.java index 47a7bfdd969..86b2e0a2f8b 100644 --- a/src/main/java/org/jabref/gui/WaitForSaveOperation.java +++ b/src/main/java/org/jabref/gui/WaitForSaveOperation.java @@ -1,13 +1,21 @@ package org.jabref.gui; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.jabref.logic.l10n.Localization; - -import javax.swing.*; -import java.awt.*; +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. */ diff --git a/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java b/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java index 5f9dc72b230..ca5b069637d 100644 --- a/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java +++ b/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java @@ -1,5 +1,13 @@ package org.jabref.gui.actions; +import java.awt.event.ActionEvent; +import java.util.List; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JDialog; +import javax.swing.JFrame; + import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.JabRefGUI; @@ -10,10 +18,6 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.util.List; - /** * This Action may only be used in a menu or button. * Never in the entry editor. FileListEditor and EntryEditor have other ways to update the file links diff --git a/src/main/java/org/jabref/gui/actions/CleanupAction.java b/src/main/java/org/jabref/gui/actions/CleanupAction.java index 9e4cc1e3a85..dbfe060c2c3 100644 --- a/src/main/java/org/jabref/gui/actions/CleanupAction.java +++ b/src/main/java/org/jabref/gui/actions/CleanupAction.java @@ -20,10 +20,6 @@ import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.util.List; -import java.util.Objects; - public class CleanupAction extends AbstractWorker { private final BasePanel panel; diff --git a/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java b/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java index 83abbd8c558..b4c6caf6a24 100644 --- a/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java +++ b/src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java @@ -24,10 +24,6 @@ import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.JabRefFrame; import org.jabref.gui.keyboard.KeyBinding; diff --git a/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java b/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java index 9f8c678d8e7..2f37be3ca28 100644 --- a/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java +++ b/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java @@ -1,8 +1,32 @@ package org.jabref.gui.actions; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.Enumeration; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.DefaultListModel; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JList; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTextField; + import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; @@ -17,17 +41,9 @@ import org.jabref.model.entry.KeywordList; import org.jabref.model.strings.StringUtil; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.util.Enumeration; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; /** * An Action for launching keyword managing dialog diff --git a/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java b/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java index 64dc0af9219..775733a2952 100644 --- a/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java +++ b/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java @@ -1,8 +1,30 @@ package org.jabref.gui.actions; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.util.Collection; +import java.util.List; +import java.util.Locale; +import java.util.Optional; +import java.util.Set; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JRadioButton; +import javax.swing.JTextField; +import javax.swing.undo.UndoableEdit; + import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; @@ -12,12 +34,9 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -import javax.swing.*; -import javax.swing.undo.UndoableEdit; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.util.*; -import java.util.List; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; /** * An Action for launching mass field. diff --git a/src/main/java/org/jabref/gui/actions/NewEntryAction.java b/src/main/java/org/jabref/gui/actions/NewEntryAction.java index c7df5260d9a..a1d3cb028c3 100644 --- a/src/main/java/org/jabref/gui/actions/NewEntryAction.java +++ b/src/main/java/org/jabref/gui/actions/NewEntryAction.java @@ -7,8 +7,6 @@ import javax.swing.Action; import javax.swing.KeyStroke; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.EntryTypeDialog; import org.jabref.gui.IconTheme; diff --git a/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java b/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java index da7d9b272d9..cf0f9769339 100644 --- a/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java +++ b/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java @@ -1,5 +1,9 @@ package org.jabref.gui.actions; +import java.awt.event.ActionEvent; + +import javax.swing.Action; + import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.BasePanelPreferences; @@ -11,9 +15,6 @@ import org.jabref.model.Defaults; import org.jabref.model.database.BibDatabaseContext; -import javax.swing.*; -import java.awt.event.ActionEvent; - /** * The action concerned with generate a new (sub-)database from latex AUX file. */ diff --git a/src/main/java/org/jabref/gui/autosaveandbackup/BackupUIManager.java b/src/main/java/org/jabref/gui/autosaveandbackup/BackupUIManager.java index 66d6a2be189..62393ea89a9 100644 --- a/src/main/java/org/jabref/gui/autosaveandbackup/BackupUIManager.java +++ b/src/main/java/org/jabref/gui/autosaveandbackup/BackupUIManager.java @@ -1,11 +1,13 @@ package org.jabref.gui.autosaveandbackup; +import java.nio.file.Path; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; + import org.jabref.logic.autosaveandbackup.BackupManager; import org.jabref.logic.l10n.Localization; -import javax.swing.*; -import java.nio.file.Path; - /** * Stores all user dialogs related to {@link BackupManager}. */ diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index c7a493a5728..9b2950e11df 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -13,6 +13,7 @@ import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; +import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; @@ -23,7 +24,11 @@ import javafx.scene.control.TabPane; import org.jabref.Globals; -import org.jabref.gui.*; +import org.jabref.gui.BasePanel; +import org.jabref.gui.DialogService; +import org.jabref.gui.FXDialogService; +import org.jabref.gui.JabRefDialog; +import org.jabref.gui.JabRefFrame; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.FileDialogConfiguration; @@ -35,12 +40,6 @@ import org.jabref.model.database.BibDatabase; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.nio.file.Path; -import java.util.Optional; - import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.DefaultFormBuilder; import com.jgoodies.forms.layout.FormLayout; diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java index 3aa00ec1e1c..21cf1a6eb48 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java @@ -1,6 +1,19 @@ package org.jabref.gui.bibtexkeypattern; -import com.jgoodies.forms.builder.ButtonBarBuilder; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.WindowEvent; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.WindowConstants; + import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; @@ -10,10 +23,7 @@ import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import org.jabref.model.metadata.MetaData; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.WindowEvent; +import com.jgoodies.forms.builder.ButtonBarBuilder; public class BibtexKeyPatternDialog extends JabRefDialog { diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java b/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java index f06bfe2b80e..7692696e14a 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java @@ -14,6 +14,7 @@ import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JDialog; +import javax.swing.JFrame; import javax.swing.JLabel; import javafx.embed.swing.JFXPanel; @@ -27,12 +28,6 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.List; - import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; diff --git a/src/main/java/org/jabref/gui/collab/ChangeScanner.java b/src/main/java/org/jabref/gui/collab/ChangeScanner.java index b2d5a07a6e0..ae1b1355832 100644 --- a/src/main/java/org/jabref/gui/collab/ChangeScanner.java +++ b/src/main/java/org/jabref/gui/collab/ChangeScanner.java @@ -11,8 +11,6 @@ import javax.swing.SwingUtilities; import javax.swing.tree.DefaultMutableTreeNode; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; @@ -21,7 +19,12 @@ import org.jabref.logic.bibtex.comparator.BibDatabaseDiff; import org.jabref.logic.bibtex.comparator.BibEntryDiff; import org.jabref.logic.bibtex.comparator.BibStringDiff; -import org.jabref.logic.exporter.*; +import org.jabref.logic.exporter.BibDatabaseWriter; +import org.jabref.logic.exporter.BibtexDatabaseWriter; +import org.jabref.logic.exporter.FileSaveSession; +import org.jabref.logic.exporter.SaveException; +import org.jabref.logic.exporter.SavePreferences; +import org.jabref.logic.exporter.SaveSession; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.OpenDatabase; import org.jabref.logic.importer.ParserResult; diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java index e61d4d0e89f..1a180891503 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java @@ -28,9 +28,6 @@ import javax.swing.JScrollPane; import javax.swing.JTextField; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; import org.jabref.gui.JabRefFrame; diff --git a/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java b/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java index d53e494be78..d8ef951c9f8 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java +++ b/src/main/java/org/jabref/gui/customentrytypes/EntryCustomizationDialog.java @@ -24,6 +24,7 @@ import javax.swing.InputMap; import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -47,19 +48,6 @@ import org.jabref.model.entry.InternalBibtexFields; import org.jabref.model.strings.StringUtil; -import javax.swing.*; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.table.AbstractTableModel; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.*; -import java.util.List; -import java.util.stream.Collectors; - import com.jgoodies.forms.builder.ButtonBarBuilder; public class EntryCustomizationDialog extends JabRefDialog implements ListSelectionListener { diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index 332729c7616..998f12d485e 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -15,14 +15,16 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefGUI; import org.jabref.gui.ClipBoardManager; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; -import org.jabref.gui.desktop.os.*; +import org.jabref.gui.desktop.os.DefaultDesktop; +import org.jabref.gui.desktop.os.Linux; +import org.jabref.gui.desktop.os.NativeDesktop; +import org.jabref.gui.desktop.os.OSX; +import org.jabref.gui.desktop.os.Windows; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypeEntryEditor; import org.jabref.gui.externalfiletype.ExternalFileTypes; diff --git a/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java b/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java index 164684836e0..6cfa38e1227 100644 --- a/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java +++ b/src/main/java/org/jabref/gui/exporter/CustomExportDialog.java @@ -20,9 +20,6 @@ import javax.swing.JPanel; import javax.swing.JTextField; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java index 8c667760ad5..e6158243ca8 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.java @@ -13,6 +13,7 @@ import javax.swing.InputMap; import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; @@ -30,14 +31,6 @@ import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.LayoutFormatterPreferences; -import javax.swing.*; -import javax.swing.table.TableColumnModel; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - import ca.odell.glazedlists.gui.TableFormat; import ca.odell.glazedlists.swing.DefaultEventTableModel; import com.jgoodies.forms.builder.ButtonBarBuilder; diff --git a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java index 13c8974c1db..94eeae9c59b 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java +++ b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java @@ -1,16 +1,6 @@ package org.jabref.gui.exporter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jabref.Globals; -import org.jabref.gui.BasePanel; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.worker.AbstractWorker; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.entry.BibEntry; - -import javax.swing.*; -import java.awt.*; +import java.awt.Toolkit; import java.awt.datatransfer.ClipboardOwner; import java.io.File; import java.io.FileInputStream; diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index db91429ab9b..d3143dd5193 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -10,10 +10,6 @@ import javax.swing.JTextArea; import javax.swing.SwingUtilities; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; @@ -28,7 +24,11 @@ import org.jabref.gui.worker.AbstractWorker; import org.jabref.logic.autosaveandbackup.AutosaveManager; import org.jabref.logic.autosaveandbackup.BackupManager; -import org.jabref.logic.exporter.*; +import org.jabref.logic.exporter.BibtexDatabaseWriter; +import org.jabref.logic.exporter.FileSaveSession; +import org.jabref.logic.exporter.SaveException; +import org.jabref.logic.exporter.SavePreferences; +import org.jabref.logic.exporter.SaveSession; import org.jabref.logic.l10n.Encodings; import org.jabref.logic.l10n.Localization; import org.jabref.logic.shared.prefs.SharedDatabasePreferences; diff --git a/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java b/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java index 988ca5a09b9..8985ccd4f02 100644 --- a/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java +++ b/src/main/java/org/jabref/gui/externalfiles/DownloadExternalFile.java @@ -11,8 +11,6 @@ import javax.swing.JOptionPane; import javax.swing.SwingUtilities; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.JabRefFrame; diff --git a/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java b/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java index 9e35130b352..9e59e95c78e 100644 --- a/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java @@ -21,10 +21,6 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; diff --git a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java index 0d3b998724e..a743d05a00d 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindFullTextAction.java @@ -11,8 +11,6 @@ import javax.swing.JOptionPane; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.undo.UndoableFieldChange; diff --git a/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java b/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java index caa5583a8c9..c03c78e4595 100644 --- a/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java +++ b/src/main/java/org/jabref/gui/externalfiles/SynchronizeFileField.java @@ -1,8 +1,32 @@ package org.jabref.gui.externalfiles; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; + import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; @@ -25,13 +49,9 @@ import org.jabref.model.entry.FieldName; import org.jabref.model.entry.LinkedFile; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.*; -import java.util.List; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; /** * This action goes through all selected entries in the BasePanel, and attempts to autoset the diff --git a/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java b/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java index 760f9857e10..136521971d1 100644 --- a/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java @@ -1,6 +1,30 @@ package org.jabref.gui.externalfiles; -import com.jgoodies.forms.builder.ButtonBarBuilder; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.ScrollPaneConstants; +import javax.swing.SwingUtilities; + import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; @@ -12,15 +36,7 @@ import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; +import com.jgoodies.forms.builder.ButtonBarBuilder; /** * diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java index 71d786a503a..81d747347df 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java @@ -9,8 +9,6 @@ import javax.swing.JMenuItem; import javax.swing.JOptionPane; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.gui.JabRefFrame; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.logic.l10n.Localization; diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java index 2e835d8f8d7..1850dc3f321 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java @@ -1,19 +1,7 @@ package org.jabref.gui.externalfiletype; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.ButtonStackBuilder; -import org.jabref.Globals; -import org.jabref.gui.IconTheme; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.actions.MnemonicAwareAction; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.logic.l10n.Localization; - -import javax.swing.*; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableCellRenderer; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; diff --git a/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java b/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java index d3340caca84..6497cdd0db4 100644 --- a/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupAddRemoveDialog.java @@ -1,6 +1,28 @@ package org.jabref.gui.groups; -import com.jgoodies.forms.builder.ButtonBarBuilder; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.util.List; +import java.util.Optional; + +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.SwingUtilities; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; + import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.actions.BaseAction; @@ -9,15 +31,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.groups.GroupTreeNode; -import javax.swing.*; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeSelectionModel; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.util.List; -import java.util.Optional; +import com.jgoodies.forms.builder.ButtonBarBuilder; public class GroupAddRemoveDialog implements BaseAction { diff --git a/src/main/java/org/jabref/gui/groups/GroupDialog.java b/src/main/java/org/jabref/gui/groups/GroupDialog.java index 4d9439b7ac5..fb743b8c4c0 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialog.java @@ -20,6 +20,7 @@ import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; +import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; @@ -33,6 +34,7 @@ import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.text.TextFlow; + import org.jabref.Globals; import org.jabref.JabRefGUI; import org.jabref.gui.Dialog; @@ -61,15 +63,6 @@ import org.jabref.model.strings.StringUtil; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import javax.swing.event.CaretListener; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ItemListener; -import java.util.Optional; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.DefaultFormBuilder; import com.jgoodies.forms.builder.FormBuilder; diff --git a/src/main/java/org/jabref/gui/importer/FetcherPreviewDialog.java b/src/main/java/org/jabref/gui/importer/FetcherPreviewDialog.java index aa85d58a02f..814de298e21 100644 --- a/src/main/java/org/jabref/gui/importer/FetcherPreviewDialog.java +++ b/src/main/java/org/jabref/gui/importer/FetcherPreviewDialog.java @@ -1,5 +1,35 @@ package org.jabref.gui.importer; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.util.LinkedHashMap; +import java.util.Map; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableModel; + +import org.jabref.Globals; +import org.jabref.gui.JabRefDialog; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.logic.importer.OutputPrinter; +import org.jabref.logic.l10n.Localization; + import ca.odell.glazedlists.BasicEventList; import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.gui.TableFormat; @@ -8,20 +38,6 @@ import ca.odell.glazedlists.swing.GlazedListsSwing; import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.ButtonStackBuilder; -import org.jabref.Globals; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.logic.importer.OutputPrinter; -import org.jabref.logic.l10n.Localization; - -import javax.swing.*; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableModel; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.util.LinkedHashMap; -import java.util.Map; /** * diff --git a/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java b/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java index 466e1fcd801..dcb6d1e1442 100644 --- a/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportCustomizationDialog.java @@ -27,9 +27,6 @@ import javax.swing.table.AbstractTableModel; import javax.swing.table.TableColumnModel; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; diff --git a/src/main/java/org/jabref/gui/importer/ImportFormats.java b/src/main/java/org/jabref/gui/importer/ImportFormats.java index 26568a9c10d..fe321b7dc41 100644 --- a/src/main/java/org/jabref/gui/importer/ImportFormats.java +++ b/src/main/java/org/jabref/gui/importer/ImportFormats.java @@ -14,8 +14,7 @@ import javax.swing.JOptionPane; import javafx.stage.FileChooser; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; + import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index 06fb17dbcfc..43009f41902 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -94,7 +94,13 @@ import org.jabref.model.FieldChange; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.entry.*; +import org.jabref.model.entry.AuthorList; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.FieldProperty; +import org.jabref.model.entry.IdGenerator; +import org.jabref.model.entry.InternalBibtexFields; +import org.jabref.model.entry.LinkedFile; import org.jabref.model.groups.AllEntriesGroup; import org.jabref.model.groups.GroupEntryChanger; import org.jabref.model.groups.GroupTreeNode; diff --git a/src/main/java/org/jabref/gui/importer/ImportMenuItem.java b/src/main/java/org/jabref/gui/importer/ImportMenuItem.java index 706cf5a2422..ae491f6d2a4 100644 --- a/src/main/java/org/jabref/gui/importer/ImportMenuItem.java +++ b/src/main/java/org/jabref/gui/importer/ImportMenuItem.java @@ -1,7 +1,24 @@ package org.jabref.gui.importer; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; + import org.jabref.Globals; -import org.jabref.gui.*; +import org.jabref.gui.BasePanel; +import org.jabref.gui.DialogService; +import org.jabref.gui.EntryMarker; +import org.jabref.gui.FXDialogService; +import org.jabref.gui.JabRefFrame; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.FileDialogConfiguration; @@ -18,17 +35,6 @@ import org.jabref.model.entry.BibtexString; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - /* * TODO: could separate the "menu item" functionality from the importing functionality */ diff --git a/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java b/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java index a952cd7678f..45dbf2fc9e7 100644 --- a/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java +++ b/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java @@ -1,14 +1,17 @@ package org.jabref.gui.importer; +import java.awt.Dimension; +import java.util.List; +import java.util.Objects; + +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + import org.jabref.gui.JabRefFrame; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.l10n.Localization; -import javax.swing.*; -import java.awt.*; -import java.util.List; -import java.util.Objects; - /** * Class for generating a dialog showing warnings from ParserResult * diff --git a/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java b/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java index 274952bc106..0bd40d19b8c 100644 --- a/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java @@ -1,5 +1,19 @@ package org.jabref.gui.importer.actions; +import java.awt.Font; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.swing.BoxLayout; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; + import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.customentrytypes.CustomEntryTypesManager; @@ -10,12 +24,6 @@ import org.jabref.model.entry.CustomEntryType; import org.jabref.model.entry.EntryType; -import javax.swing.*; -import java.awt.*; -import java.util.*; -import java.util.List; -import java.util.stream.Collectors; - /** * This action checks whether any new custom entry types were loaded from this * BIB file. If so, an offer to remember these entry types is given. 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 1e4235a7c47..96fa5d15222 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -18,8 +18,6 @@ import javax.swing.JOptionPane; import javax.swing.SwingUtilities; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; diff --git a/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java b/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java index 295cecf4430..cc25e205b2e 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java @@ -1,5 +1,24 @@ package org.jabref.gui.importer.fetcher; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.IconTheme; @@ -14,14 +33,6 @@ import org.jabref.logic.util.OS; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - public class GeneralFetcher extends SidePaneComponent implements ActionListener { private final JTextField tf = new JTextField(); diff --git a/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java b/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java index 7d661002a2c..0e2a8ab085a 100644 --- a/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java +++ b/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java @@ -1,18 +1,21 @@ package org.jabref.gui.menus; -import org.jabref.JabRefExecutorService; -import org.jabref.gui.JabRefFrame; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.util.io.FileHistory; -import org.jabref.preferences.JabRefPreferences; - -import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; + +import org.jabref.JabRefExecutorService; +import org.jabref.gui.JabRefFrame; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.io.FileHistory; +import org.jabref.preferences.JabRefPreferences; + public class FileHistoryMenu extends JMenu implements ActionListener { private final FileHistory history; diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java index a49c2858ebe..ef951e6a2d7 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java @@ -1,10 +1,12 @@ package org.jabref.gui.mergeentries; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.layout.CellConstraints; -import com.jgoodies.forms.layout.ColumnSpec; -import com.jgoodies.forms.layout.FormLayout; -import com.jgoodies.forms.layout.RowSpec; +import java.util.List; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JSeparator; + import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; import org.jabref.gui.undo.NamedCompound; @@ -15,8 +17,11 @@ import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.util.List; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.layout.CellConstraints; +import com.jgoodies.forms.layout.ColumnSpec; +import com.jgoodies.forms.layout.FormLayout; +import com.jgoodies.forms.layout.RowSpec; /** * @author Oscar diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeFetchedEntryDialog.java b/src/main/java/org/jabref/gui/mergeentries/MergeFetchedEntryDialog.java index ac4cbc478fc..1b54098bec5 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeFetchedEntryDialog.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeFetchedEntryDialog.java @@ -1,10 +1,16 @@ package org.jabref.gui.mergeentries; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.layout.CellConstraints; -import com.jgoodies.forms.layout.ColumnSpec; -import com.jgoodies.forms.layout.FormLayout; -import com.jgoodies.forms.layout.RowSpec; +import java.awt.event.ActionEvent; +import java.util.Optional; +import java.util.Set; +import java.util.TreeSet; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JSeparator; + import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; import org.jabref.gui.undo.NamedCompound; @@ -16,11 +22,11 @@ import org.jabref.model.entry.InternalBibtexFields; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.util.Optional; -import java.util.Set; -import java.util.TreeSet; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.layout.CellConstraints; +import com.jgoodies.forms.layout.ColumnSpec; +import com.jgoodies.forms.layout.FormLayout; +import com.jgoodies.forms.layout.RowSpec; /** * Dialog for merging Bibtex entry with fetched data diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java b/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java index d5c9e531951..28015717f25 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java @@ -1,13 +1,13 @@ package org.jabref.gui.mergeentries; +import javax.swing.JOptionPane; + import org.jabref.gui.BasePanel; import org.jabref.gui.actions.BaseAction; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; -import javax.swing.*; - public class MergeWithFetchedEntryAction implements BaseAction { private final BasePanel basePanel; diff --git a/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java b/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java index 228cc82f861..4b920f36c61 100644 --- a/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java +++ b/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java @@ -1,17 +1,27 @@ package org.jabref.gui.openoffice; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JRadioButton; +import javax.swing.JTextField; + import org.jabref.Globals; import org.jabref.gui.JabRefFrame; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.l10n.Localization; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; /** * Dialog for adding citation with page number info. diff --git a/src/main/java/org/jabref/gui/openoffice/CitationManager.java b/src/main/java/org/jabref/gui/openoffice/CitationManager.java index 2e32f902c22..fe69d79f67e 100644 --- a/src/main/java/org/jabref/gui/openoffice/CitationManager.java +++ b/src/main/java/org/jabref/gui/openoffice/CitationManager.java @@ -1,5 +1,31 @@ package org.jabref.gui.openoffice; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.List; +import java.util.Optional; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; + +import org.jabref.Globals; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.openoffice.CitationEntry; + import ca.odell.glazedlists.BasicEventList; import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.gui.TableFormat; @@ -17,19 +43,6 @@ import com.sun.star.lang.WrappedTargetException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.jabref.Globals; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.openoffice.CitationEntry; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.List; -import java.util.Optional; /** * Dialog for modifying existing citations. diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index 1f46cb09016..f58be1651bf 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -32,7 +32,13 @@ import javax.swing.JTextField; import org.jabref.Globals; -import org.jabref.gui.*; +import org.jabref.gui.BasePanel; +import org.jabref.gui.DialogService; +import org.jabref.gui.FXDialogService; +import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.SidePaneComponent; +import org.jabref.gui.SidePaneManager; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.desktop.os.NativeDesktop; import org.jabref.gui.help.HelpAction; diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java index c45bd696f09..d7f992df2cb 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java @@ -36,7 +36,12 @@ import javafx.scene.Scene; import org.jabref.Globals; -import org.jabref.gui.*; +import org.jabref.gui.DialogService; +import org.jabref.gui.FXDialogService; +import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefDialog; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.PreviewPanel; import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.externalfiletype.ExternalFileType; diff --git a/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java b/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java index 1f1a2d6c29c..9423c113ca2 100644 --- a/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java +++ b/src/main/java/org/jabref/gui/plaintextimport/TextInputDialog.java @@ -58,11 +58,15 @@ import javax.swing.text.StyleContext; import javax.swing.text.StyledDocument; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; -import org.jabref.gui.*; +import org.jabref.gui.ClipBoardManager; +import org.jabref.gui.DialogService; +import org.jabref.gui.EntryMarker; +import org.jabref.gui.FXDialogService; +import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefDialog; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.OSXCompatibleToolbar; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.util.DefaultTaskExecutor; @@ -77,7 +81,11 @@ import org.jabref.logic.util.OS; import org.jabref.logic.util.UpdateField; import org.jabref.model.EntryTypes; -import org.jabref.model.entry.*; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.EntryType; +import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.FieldProperty; +import org.jabref.model.entry.InternalBibtexFields; import org.jabref.preferences.JabRefPreferences; import com.jgoodies.forms.builder.ButtonBarBuilder; diff --git a/src/main/java/org/jabref/gui/preftabs/ExternalTab.java b/src/main/java/org/jabref/gui/preftabs/ExternalTab.java index c66bb714b28..0b8468ea90c 100644 --- a/src/main/java/org/jabref/gui/preftabs/ExternalTab.java +++ b/src/main/java/org/jabref/gui/preftabs/ExternalTab.java @@ -1,7 +1,21 @@ package org.jabref.gui.preftabs; -import com.jgoodies.forms.builder.DefaultFormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Insets; + +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JTextField; + import org.jabref.Globals; import org.jabref.gui.JabRefFrame; import org.jabref.gui.externalfiletype.ExternalFileTypeEditor; @@ -11,8 +25,8 @@ import org.jabref.logic.util.OS; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.awt.*; +import com.jgoodies.forms.builder.DefaultFormBuilder; +import com.jgoodies.forms.layout.FormLayout; class ExternalTab extends JPanel implements PrefsTab { private final JabRefPreferences prefs; diff --git a/src/main/java/org/jabref/gui/preftabs/FileTab.java b/src/main/java/org/jabref/gui/preftabs/FileTab.java index 0322b86158a..825dd3c1d82 100644 --- a/src/main/java/org/jabref/gui/preftabs/FileTab.java +++ b/src/main/java/org/jabref/gui/preftabs/FileTab.java @@ -1,7 +1,23 @@ package org.jabref.gui.preftabs; -import com.jgoodies.forms.builder.DefaultFormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ItemListener; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JTextField; + import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; import org.jabref.gui.JabRefFrame; @@ -15,12 +31,8 @@ import org.jabref.model.metadata.FileDirectoryPreferences; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ItemListener; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import com.jgoodies.forms.builder.DefaultFormBuilder; +import com.jgoodies.forms.layout.FormLayout; /** * Preferences tab for file options. These options were moved out from GeneralTab to diff --git a/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java b/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java index 145008b2902..d314c6d5ce8 100644 --- a/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java +++ b/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java @@ -23,7 +23,11 @@ import org.jabref.Globals; import org.jabref.JabRefException; -import org.jabref.gui.*; +import org.jabref.gui.DialogService; +import org.jabref.gui.FXDialogService; +import org.jabref.gui.GUIGlobals; +import org.jabref.gui.JabRefDialog; +import org.jabref.gui.JabRefFrame; import org.jabref.gui.keyboard.KeyBinder; import org.jabref.gui.maintable.MainTable; import org.jabref.gui.util.DefaultTaskExecutor; diff --git a/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java b/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java index de83a5a4337..d10f203fba4 100644 --- a/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java +++ b/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java @@ -1,8 +1,20 @@ package org.jabref.gui.protectedterms; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.nio.file.Path; +import java.util.Optional; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JTextField; + import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; @@ -16,11 +28,9 @@ import org.jabref.logic.util.FileType; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.nio.file.Path; -import java.util.Optional; +import com.jgoodies.forms.builder.ButtonBarBuilder; +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; public class NewProtectedTermsFileDialog extends JabRefDialog { diff --git a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java b/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java index 90f92a2161b..fd9a7d9c4af 100644 --- a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java +++ b/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java @@ -35,13 +35,12 @@ import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumnModel; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; -import org.jabref.gui.*; +import org.jabref.gui.DialogService; +import org.jabref.gui.FXDialogService; +import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefDialog; +import org.jabref.gui.JabRefFrame; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationAction.java b/src/main/java/org/jabref/gui/push/PushToApplicationAction.java index 835061a3eb1..41b9dbf1243 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplicationAction.java +++ b/src/main/java/org/jabref/gui/push/PushToApplicationAction.java @@ -1,16 +1,20 @@ package org.jabref.gui.push; +import java.awt.event.ActionEvent; +import java.util.List; +import java.util.Optional; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; + import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.util.List; -import java.util.Optional; - /** * An Action class representing the process of invoking a PushToApplication operation. */ diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationButton.java b/src/main/java/org/jabref/gui/push/PushToApplicationButton.java index 79262926daf..2f12e5f9c06 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplicationButton.java +++ b/src/main/java/org/jabref/gui/push/PushToApplicationButton.java @@ -1,6 +1,31 @@ package org.jabref.gui.push; -import com.jgoodies.forms.builder.ButtonBarBuilder; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.Icon; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; + import org.jabref.Globals; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; @@ -10,15 +35,7 @@ import org.jabref.logic.util.OS; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.jgoodies.forms.builder.ButtonBarBuilder; /** * Customized UI component for pushing to external applications. Has a selection popup menu to change the selected diff --git a/src/main/java/org/jabref/gui/push/PushToEmacs.java b/src/main/java/org/jabref/gui/push/PushToEmacs.java index 06cb076ca40..ef20cf52626 100644 --- a/src/main/java/org/jabref/gui/push/PushToEmacs.java +++ b/src/main/java/org/jabref/gui/push/PushToEmacs.java @@ -9,8 +9,6 @@ import javax.swing.JPanel; import javax.swing.JTextField; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; diff --git a/src/main/java/org/jabref/gui/push/PushToVim.java b/src/main/java/org/jabref/gui/push/PushToVim.java index a171130dc11..fdb413f54ac 100644 --- a/src/main/java/org/jabref/gui/push/PushToVim.java +++ b/src/main/java/org/jabref/gui/push/PushToVim.java @@ -9,8 +9,6 @@ import javax.swing.JPanel; import javax.swing.JTextField; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; diff --git a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java index 70e2c204d32..3851c4f0da3 100644 --- a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java +++ b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java @@ -32,12 +32,14 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.JabRefException; import org.jabref.JabRefGUI; -import org.jabref.gui.*; +import org.jabref.gui.BasePanel; +import org.jabref.gui.DialogService; +import org.jabref.gui.FXDialogService; +import org.jabref.gui.JabRefDialog; +import org.jabref.gui.JabRefFrame; import org.jabref.gui.exporter.SaveDatabaseAction; import org.jabref.gui.help.HelpAction; import org.jabref.gui.util.DefaultTaskExecutor; diff --git a/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java b/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java index 244374de423..e2ac256b025 100644 --- a/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java +++ b/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java @@ -1,5 +1,19 @@ package org.jabref.gui.shared; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.WindowConstants; +import javax.swing.border.EmptyBorder; + import org.jabref.gui.JabRefFrame; import org.jabref.gui.mergeentries.MergeEntries; import org.jabref.logic.l10n.Localization; @@ -7,12 +21,6 @@ import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.model.entry.BibEntry; -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import java.awt.*; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - public class MergeSharedEntryDialog { private final JabRefFrame jabRefFrame; diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java index 9227cbdca8c..eec194140a3 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java @@ -1,6 +1,12 @@ package org.jabref.gui.shared; -import com.google.common.eventbus.Subscribe; +import java.sql.SQLException; +import java.util.Objects; +import java.util.Optional; + +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; + import org.jabref.Globals; import org.jabref.JabRefGUI; import org.jabref.gui.BasePanel; @@ -25,10 +31,7 @@ import org.jabref.model.database.shared.DatabaseNotSupportedException; import org.jabref.model.database.shared.DatabaseSynchronizer; -import javax.swing.*; -import java.sql.SQLException; -import java.util.Objects; -import java.util.Optional; +import com.google.common.eventbus.Subscribe; public class SharedDatabaseUIManager { diff --git a/src/main/java/org/jabref/gui/worker/VersionWorker.java b/src/main/java/org/jabref/gui/worker/VersionWorker.java index 4006935e1ec..0c9fb213ef5 100644 --- a/src/main/java/org/jabref/gui/worker/VersionWorker.java +++ b/src/main/java/org/jabref/gui/worker/VersionWorker.java @@ -1,13 +1,5 @@ package org.jabref.gui.worker; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.help.NewVersionDialog; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.util.Version; - -import javax.swing.*; import java.io.IOException; import java.util.Collections; import java.util.List; @@ -15,6 +7,8 @@ import java.util.Optional; import java.util.concurrent.ExecutionException; +import javax.swing.JOptionPane; +import javax.swing.SwingWorker; import org.jabref.gui.JabRefFrame; import org.jabref.gui.help.NewVersionDialog; diff --git a/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java b/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java index a5e32bdf8e9..f39c012df20 100644 --- a/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java +++ b/src/main/java/org/jabref/migrations/FileLinksUpgradeWarning.java @@ -1,7 +1,14 @@ package org.jabref.migrations; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +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; @@ -21,8 +28,8 @@ import org.jabref.model.metadata.FileDirectoryPreferences; import org.jabref.preferences.JabRefPreferences; -import javax.swing.*; -import java.util.List; +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 diff --git a/src/main/java/org/jabref/pdfimport/PdfImporter.java b/src/main/java/org/jabref/pdfimport/PdfImporter.java index 23e6a37be54..90c076dd6e0 100644 --- a/src/main/java/org/jabref/pdfimport/PdfImporter.java +++ b/src/main/java/org/jabref/pdfimport/PdfImporter.java @@ -11,8 +11,6 @@ import javax.swing.JOptionPane; import javax.swing.SwingUtilities; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.BasePanelMode; diff --git a/src/main/java/osx/macadapter/MacAdapter.java b/src/main/java/osx/macadapter/MacAdapter.java index 9ab97bec96d..34a33cb8e34 100644 --- a/src/main/java/osx/macadapter/MacAdapter.java +++ b/src/main/java/osx/macadapter/MacAdapter.java @@ -1,14 +1,22 @@ package osx.macadapter; -import com.apple.eawt.*; +import java.io.File; +import java.util.List; + +import org.jabref.gui.JabRefFrame; + +import com.apple.eawt.AboutHandler; +import com.apple.eawt.AppEvent; import com.apple.eawt.AppEvent.AboutEvent; import com.apple.eawt.AppEvent.OpenFilesEvent; import com.apple.eawt.AppEvent.PreferencesEvent; import com.apple.eawt.AppEvent.QuitEvent; -import org.jabref.gui.JabRefFrame; - -import java.io.File; -import java.util.List; +import com.apple.eawt.AppReOpenedListener; +import com.apple.eawt.Application; +import com.apple.eawt.OpenFilesHandler; +import com.apple.eawt.PreferencesHandler; +import com.apple.eawt.QuitHandler; +import com.apple.eawt.QuitResponse; public class MacAdapter implements PreferencesHandler, AboutHandler, QuitHandler, OpenFilesHandler, AppReOpenedListener { diff --git a/src/test/java/org/jabref/gui/AbstractUITest.java b/src/test/java/org/jabref/gui/AbstractUITest.java index 790e170f178..77c64d3e1bb 100644 --- a/src/test/java/org/jabref/gui/AbstractUITest.java +++ b/src/test/java/org/jabref/gui/AbstractUITest.java @@ -1,5 +1,15 @@ package org.jabref.gui; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.jabref.JabRefMain; +import org.jabref.testutils.category.GUITest; + import org.assertj.swing.fixture.AbstractWindowFixture; import org.assertj.swing.fixture.FrameFixture; import org.assertj.swing.fixture.JFileChooserFixture; @@ -7,18 +17,9 @@ import org.assertj.swing.image.ScreenshotTaker; import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase; import org.assertj.swing.timing.Pause; -import org.jabref.JabRefMain; -import org.jabref.testutils.category.GUITest; import org.junit.Assert; import org.junit.experimental.categories.Category; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - import static org.assertj.swing.launcher.ApplicationLauncher.application; @Category(GUITest.class) diff --git a/src/test/java/org/jabref/gui/ClipBoardManagerTest.java b/src/test/java/org/jabref/gui/ClipBoardManagerTest.java index b0b5e2dcf76..64bf9b7d317 100644 --- a/src/test/java/org/jabref/gui/ClipBoardManagerTest.java +++ b/src/test/java/org/jabref/gui/ClipBoardManagerTest.java @@ -16,7 +16,7 @@ import org.junit.Test; import org.mockito.ArgumentMatchers; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java index 6663c6acd64..5a2f923d94a 100644 --- a/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java +++ b/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java @@ -10,10 +10,10 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; import org.jabref.model.groups.AllEntriesGroup; - import org.jabref.model.groups.ExplicitGroup; import org.jabref.model.groups.GroupHierarchyType; import org.jabref.model.groups.WordKeywordGroup; + import org.junit.Before; import org.junit.Test; @@ -42,7 +42,7 @@ public void rootGroupIsAllEntriesByDefault() throws Exception { } @Test - public void explicitGroupsAreRemovedFromEntriesOnDelete() {; + public void explicitGroupsAreRemovedFromEntriesOnDelete() { ExplicitGroup group = new ExplicitGroup("group", GroupHierarchyType.INDEPENDENT,','); BibEntry entry = new BibEntry(); databaseContext.getDatabase().insertEntry(entry); @@ -55,7 +55,7 @@ public void rootGroupIsAllEntriesByDefault() throws Exception { } @Test - public void keywordGroupsAreNotRemovedFromEntriesOnDelete() {; + public void keywordGroupsAreNotRemovedFromEntriesOnDelete() { String groupName = "A"; WordKeywordGroup group = new WordKeywordGroup(groupName, GroupHierarchyType.INCLUDING, "keywords", groupName, true, ',', true); BibEntry entry = new BibEntry(); diff --git a/src/test/java/org/jabref/logic/integrity/BracesCorrectorTest.java b/src/test/java/org/jabref/logic/integrity/BracesCorrectorTest.java index 1535ece93b9..8a78f37e151 100644 --- a/src/test/java/org/jabref/logic/integrity/BracesCorrectorTest.java +++ b/src/test/java/org/jabref/logic/integrity/BracesCorrectorTest.java @@ -2,7 +2,8 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public class BracesCorrectorTest { diff --git a/src/test/java/org/jabref/logic/layout/format/AuthorAndToSemicolonReplacerTest.java b/src/test/java/org/jabref/logic/layout/format/AuthorAndToSemicolonReplacerTest.java index f4e0f2b85c0..5f7115339d1 100644 --- a/src/test/java/org/jabref/logic/layout/format/AuthorAndToSemicolonReplacerTest.java +++ b/src/test/java/org/jabref/logic/layout/format/AuthorAndToSemicolonReplacerTest.java @@ -4,6 +4,7 @@ import java.util.Collection; import org.jabref.logic.layout.LayoutFormatter; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java index 6aa6e2ec8e2..a7e57ed7bfb 100644 --- a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java +++ b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java @@ -9,10 +9,10 @@ import java.util.Map; import java.util.Optional; -import org.jabref.model.database.shared.DBMSType; -import org.jabref.model.entry.BibEntry; import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; import org.jabref.logic.shared.exception.OfflineLockException; +import org.jabref.model.database.shared.DBMSType; +import org.jabref.model.entry.BibEntry; import org.jabref.testutils.category.DatabaseTest; import org.junit.jupiter.api.AfterEach; diff --git a/src/test/java/org/jabref/logic/specialfields/SpecialFieldsUtilsTest.java b/src/test/java/org/jabref/logic/specialfields/SpecialFieldsUtilsTest.java index 792a09f3363..de9ab4c2a33 100644 --- a/src/test/java/org/jabref/logic/specialfields/SpecialFieldsUtilsTest.java +++ b/src/test/java/org/jabref/logic/specialfields/SpecialFieldsUtilsTest.java @@ -6,11 +6,11 @@ import org.jabref.model.FieldChange; import org.jabref.model.entry.BibEntry; - import org.jabref.model.entry.FieldName; import org.jabref.model.entry.Keyword; import org.jabref.model.entry.KeywordList; import org.jabref.model.entry.specialfields.SpecialField; + import org.junit.Test; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/org/jabref/model/entry/BibEntryTests.java b/src/test/java/org/jabref/model/entry/BibEntryTests.java index c4bd826a453..b4c480ff3d8 100644 --- a/src/test/java/org/jabref/model/entry/BibEntryTests.java +++ b/src/test/java/org/jabref/model/entry/BibEntryTests.java @@ -6,16 +6,15 @@ import java.util.List; import java.util.Optional; -import com.google.common.collect.Sets; import org.jabref.model.FieldChange; - import org.jabref.model.entry.specialfields.SpecialField; + +import com.google.common.collect.Sets; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class BibEntryTests { diff --git a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java index dba0cfb9c45..ff9bb0b2543 100644 --- a/src/test/java/org/jabref/model/entry/EntryLinkListTest.java +++ b/src/test/java/org/jabref/model/entry/EntryLinkListTest.java @@ -1,12 +1,13 @@ package org.jabref.model.entry; +import java.util.List; +import java.util.Optional; + import org.jabref.model.database.BibDatabase; + import org.junit.Before; import org.junit.Test; -import java.util.List; -import java.util.Optional; - import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; From 94027da11fef3d33bf10dc77b3a2bd7624d83cb5 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 2 Feb 2018 01:29:14 +0100 Subject: [PATCH 039/827] Show main table --- src/main/java/org/jabref/JabRefGUI.java | 37 ++----------------- src/main/java/org/jabref/gui/JabRefFrame.java | 10 ++--- 2 files changed, 9 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index 25c1097dd16..17c122ebad0 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -16,10 +16,9 @@ import javafx.application.Platform; import javafx.scene.Scene; -import javafx.scene.control.TextArea; -import javafx.scene.layout.VBox; import javafx.stage.Stage; +import org.jabref.gui.AbstractView; import org.jabref.gui.BasePanel; import org.jabref.gui.GUIGlobals; import org.jabref.gui.JabRefFrame; @@ -155,40 +154,12 @@ private void openWindow(Stage mainStage) { mainStage.setTitle(JabRefFrame.FRAME_TITLE); - TextArea ta = new TextArea("output\n"); - VBox root = new VBox(5, ta); - Scene scene = new Scene(root, 800, 200); + Scene scene = new Scene(JabRefGUI.mainFrame, 800, 200); + scene.getStylesheets().add(AbstractView.class.getResource("Main.css").toExternalForm()); mainStage.setTitle("Find this window"); mainStage.setScene(scene); mainStage.show(); - /* - //gets this window (stage) - long lhwnd = com.sun.glass.ui.Window.getWindows().get(0).getNativeWindow(); - Pointer lpVoid = new Pointer(lhwnd); - //gets the foreground (focused) window - final User32 user32 = User32.INSTANCE; - char[] windowText = new char[512]; - WinDef.HWND hwnd = user32.GetForegroundWindow(); - //see what the title is - user32.GetWindowText(hwnd, windowText, 512); - //user32.GetWindowText(new HWND(lpVoid), windowText, 512);//to use the hwnd from stage - String text = (Native.toString(windowText)); - //see if it's the same pointer - ta.appendText("HWND java:" + lpVoid + " HWND user32:" + hwnd + " text:" + text + "\n"); - //change the window style if it's the right title - if (text.equals(mainStage.getTitle())) { - //the style to change - int WS_DLGFRAME = 0x00400000;//s/b long I think - //not the same constant here?? - ta.appendText("windows api:" + WS_DLGFRAME + " JNA: " + WinUser.SM_CXDLGFRAME); - int oldStyle = user32.GetWindowLong(hwnd, GWL_STYLE); - int newStyle = oldStyle & ~0x00400000; //bitwise not WS_DLGFRAME means remove the style - newStyle = newStyle & ~0x00040000;//WS_THICKFRAME - user32.SetWindowLong(hwnd, GWL_STYLE, newStyle); - } - */ - mainStage.setOnCloseRequest(event -> { mainFrame.quit(); Platform.exit(); @@ -227,7 +198,7 @@ private void openWindow(Stage mainStage) { LOGGER.debug("Finished adding panels"); if (!bibDatabases.isEmpty()) { - JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable().requestFocus(); + //JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable().requestFocus(); } } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 57da7b86ea3..753cc386498 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -930,6 +930,7 @@ public void keyPressed(KeyEvent e) { swingSidePane.setContent(sidePaneManager.getPanel()); }); splitPane.getItems().addAll(swingSidePane, tabbedPane); + setCenter(splitPane); UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0)); sidePaneManager.updateView(); @@ -1609,11 +1610,10 @@ private void trackOpenNewDatabase(BasePanel basePanel) { public BasePanel addTab(BibDatabaseContext databaseContext, boolean raisePanel) { Objects.requireNonNull(databaseContext); - return DefaultTaskExecutor.runInJavaFXThread(() -> { - BasePanel bp = new BasePanel(this, BasePanelPreferences.from(Globals.prefs), databaseContext, ExternalFileTypes.getInstance()); - addTab(bp, raisePanel); - return bp; - }); + + BasePanel bp = new BasePanel(this, BasePanelPreferences.from(Globals.prefs), databaseContext, ExternalFileTypes.getInstance()); + addTab(bp, raisePanel); + return bp; } private boolean readyForAutosave(BibDatabaseContext context) { From 86d03935c29e93e804e87f3d220de86e922391ea Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 3 Feb 2018 11:57:09 +0100 Subject: [PATCH 040/827] Reimplement copy and paste of entries (#3681) --- src/main/java/org/jabref/Globals.java | 2 + src/main/java/org/jabref/gui/BasePanel.java | 88 +-------- .../java/org/jabref/gui/ClipBoardManager.java | 39 +++- .../java/org/jabref/gui/DefaultInjector.java | 2 + .../jabref/gui/DragAndDropDataFormats.java | 2 +- .../java/org/jabref/gui/DuplicateSearch.java | 2 +- .../actions/CopyBibTeXKeyAndLinkAction.java | 12 +- .../gui/collab/EntryAddChangeViewModel.java | 2 +- .../gui/externalfiles/DroppedFileHandler.java | 2 +- .../importer/EntryFromFileCreatorManager.java | 2 +- .../gui/importer/ImportInspectionDialog.java | 2 +- .../actions/AppendDatabaseAction.java | 2 +- .../org/jabref/gui/maintable/MainTable.java | 182 ++++++++++++------ .../gui/mergeentries/MergeEntriesDialog.java | 2 +- .../jabref/gui/undo/UndoableInsertEntry.java | 9 +- .../jabref/logic/bibtex/BibEntryWriter.java | 11 ++ .../org/jabref/pdfimport/PdfImporter.java | 2 +- 17 files changed, 202 insertions(+), 161 deletions(-) diff --git a/src/main/java/org/jabref/Globals.java b/src/main/java/org/jabref/Globals.java index 10ed3c89e30..02f5cd7f6b9 100644 --- a/src/main/java/org/jabref/Globals.java +++ b/src/main/java/org/jabref/Globals.java @@ -4,6 +4,7 @@ import java.util.Optional; import java.util.UUID; +import org.jabref.gui.ClipBoardManager; import org.jabref.gui.GlobalFocusListener; import org.jabref.gui.StateManager; import org.jabref.gui.keyboard.KeyBindingRepository; @@ -57,6 +58,7 @@ public class Globals { private static GlobalFocusListener focusListener; private static DefaultFileUpdateMonitor fileUpdateMonitor; private static TelemetryClient telemetryClient; + public static ClipBoardManager clipboardManager = new ClipBoardManager(); private Globals() { } diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 431c2e857e1..9a258d836b8 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -13,7 +13,6 @@ import java.nio.charset.UnsupportedCharsetException; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -179,7 +178,7 @@ public class BasePanel extends StackPane implements ClipboardOwner { private boolean baseChanged; private boolean nonUndoableChange; // Used to track whether the base has changed since last save. - private MainTable mainTable; + public MainTable mainTable; private BibEntry showing; // Variable to prevent erroneous update of back/forward histories at the time // when a Back or Forward operation is being processed: @@ -355,11 +354,11 @@ private void setupActions() { new SaveSelectedAction(SavePreferences.DatabaseSaveType.PLAIN_BIBTEX)); // The action for copying selected entries. - actions.put(Actions.COPY, (BaseAction) this::copy); + actions.put(Actions.COPY, (BaseAction) mainTable::copy); actions.put(Actions.PRINT_PREVIEW, new PrintPreviewAction()); - actions.put(Actions.CUT, (BaseAction) this::cut); + actions.put(Actions.CUT, (BaseAction) mainTable::cut); //when you modify this action be sure to adjust Actions.CUT, //they are the same except of the Localization, delete confirmation and Actions.COPY call @@ -371,7 +370,7 @@ private void setupActions() { // This allows you to (a) paste entire bibtex entries from a text editor, web browser, etc // (b) copy and paste entries between multiple instances of JabRef (since // only the text representation seems to get as far as the X clipboard, at least on my system) - actions.put(Actions.PASTE, (BaseAction) this::paste); + actions.put(Actions.PASTE, (BaseAction) mainTable::paste); actions.put(Actions.SELECT_ALL, (BaseAction) mainTable.getSelectionModel()::selectAll); @@ -715,30 +714,13 @@ private void copyCitationToClipboard(CitationStyleOutputFormat outputFormat) { new CitationStyleToClipboardWorker(this, outputFormat).execute(); } - private void copy() { - List bes = mainTable.getSelectedEntries(); - - if (!bes.isEmpty()) { - TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes); - // ! look at ClipBoardManager - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, BasePanel.this); - output(formatOutputMessage(Localization.lang("Copied"), bes.size())); - } - } - - private void cut() { - runCommand(Actions.COPY); - // cannot call runCommand(Actions.DELETE), b/c it will call delete(false) with the wrong parameter - delete(true); - } - /** * Removes the selected entries from the database * * @param cut If false the user will get asked if he really wants to delete the entries, and it will be localized as * "deleted". If true the action will be localized as "cut" */ - private void delete(boolean cut) { + public void delete(boolean cut) { delete(cut, mainTable.getSelectedEntries()); } @@ -792,54 +774,6 @@ public void delete(BibEntry entry) { delete(false, Collections.singletonList(entry)); } - private void paste() { - Collection bes = new ClipBoardManager().extractBibEntriesFromClipboard(); - - // finally we paste in the entries (if any), which either came from TransferableBibtexEntries - // or were parsed from a string - if (!bes.isEmpty()) { - - NamedCompound ce = new NamedCompound( - (bes.size() > 1 ? Localization.lang("paste entries") : Localization.lang("paste entry"))); - - // Store the first inserted bibtexentry. - // bes[0] does not work as bes[0] is first clonded, - // then inserted. - // This entry is used to open up an entry editor - // for the first inserted entry. - BibEntry firstBE = null; - - for (BibEntry be1 : bes) { - - BibEntry be = (BibEntry) be1.clone(); - if (firstBE == null) { - firstBE = be; - } - UpdateField.setAutomaticFields(be, Globals.prefs.getUpdateFieldPreferences()); - - // We have to clone the - // entries, since the pasted - // entries must exist - // independently of the copied - // ones. - bibDatabaseContext.getDatabase().insertEntry(be); - - ce.addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), be, BasePanel.this)); - } - ce.end(); - getUndoManager().addEdit(ce); - output(formatOutputMessage(Localization.lang("Pasted"), bes.size())); - markBaseChanged(); - - clearAndSelect(firstBE); - mainTable.requestFocus(); - - if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) { - showAndEdit(firstBE); - } - } - } - private void copyTitle() { List selectedBibEntries = mainTable.getSelectedEntries(); if (!selectedBibEntries.isEmpty()) { @@ -1144,7 +1078,7 @@ public BibEntry newEntry(EntryType type) { UpdateField.setAutomaticFields(list, true, true, Globals.prefs.getUpdateFieldPreferences()); // Create an UndoableInsertEntry object. - getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), be, BasePanel.this)); + getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), be)); output(Localization.lang("Added new '%0' entry.", actualType.getName().toLowerCase(Locale.ROOT))); // We are going to select the new entry. Before that, make sure that we are in @@ -1184,7 +1118,7 @@ public void insertEntry(final BibEntry bibEntry) { UpdateField.setAutomaticFields(bibEntry, true, true, Globals.prefs.getUpdateFieldPreferences()); } // Create an UndoableInsertEntry object. - getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), bibEntry, BasePanel.this)); + getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), bibEntry)); output(Localization.lang("Added new '%0' entry.", bibEntry.getType())); markBaseChanged(); // The database just changed. @@ -1516,11 +1450,7 @@ public void closeBottomPane() { * given focus afterwards. */ public void clearAndSelect(final BibEntry bibEntry) { - mainTable.findEntry(bibEntry) - .ifPresent(entry -> { - mainTable.getSelectionModel().clearSelection(); - mainTable.getSelectionModel().select(entry); - }); + mainTable.clearAndSelect(bibEntry); } /** @@ -1879,7 +1809,7 @@ public void setBackAndForwardEnabledState() { frame.getForwardAction().setEnabled(!nextEntries.isEmpty()); } - private String formatOutputMessage(String start, int count) { + public String formatOutputMessage(String start, int count) { return String.format("%s %d %s.", start, count, (count > 1 ? Localization.lang("entries") : Localization.lang("entry"))); } diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index a79eb860213..eddcd6a67de 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -11,13 +11,19 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; + +import javafx.scene.input.ClipboardContent; import org.jabref.Globals; +import org.jabref.logic.bibtex.BibEntryWriter; +import org.jabref.logic.bibtex.LatexFieldFormatter; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportException; import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.importer.ImportFormatReader.UnknownFormatImport; import org.jabref.logic.importer.fetcher.DoiFetcher; +import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.identifier.DOI; @@ -77,10 +83,40 @@ public String getClipboardContents() { return result; } + public void setClipboardHtmlContent(String html) { + // TODO: This works on Mac and Windows 10, but not on Ubuntu 16.04 + final javafx.scene.input.Clipboard clipboard = javafx.scene.input.Clipboard.getSystemClipboard(); + final ClipboardContent content = new ClipboardContent(); + content.putHtml(html); + clipboard.setContent(content); + } + + public void setClipboardContent(String string) { + // TODO: This works on Mac and Windows 10, but not on Ubuntu 16.04 + final javafx.scene.input.Clipboard clipboard = javafx.scene.input.Clipboard.getSystemClipboard(); + final ClipboardContent content = new ClipboardContent(); + content.putString(string); + clipboard.setContent(content); + } + + public void setClipboardContent(List entries) throws IOException { + // TODO: This works on Mac and Windows 10, but not on Ubuntu 16.04 + final javafx.scene.input.Clipboard clipboard = javafx.scene.input.Clipboard.getSystemClipboard(); + final ClipboardContent content = new ClipboardContent(); + BibEntryWriter writer = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()), false); + String serializedEntries = writer.serializeAll(entries, BibDatabaseMode.BIBTEX); + content.put(DragAndDropDataFormats.ENTRIES, serializedEntries); + content.putString(serializedEntries); + clipboard.setContent(content); + } + /** * Place a String on the clipboard, and make this class the * owner of the Clipboard's contents. + * + * @deprecated use {@link #setClipboardContent(String)} instead */ + @Deprecated public void setClipboardContents(String aString) { StringSelection stringSelection = new StringSelection(aString); clipboard.setContents(stringSelection, this); @@ -96,7 +132,8 @@ public List extractBibEntriesFromClipboard() { try { @SuppressWarnings("unchecked") List contents = (List) content.getTransferData(TransferableBibtexEntry.ENTRY_FLAVOR); - result = contents; + // We clone the entries to make sure we don't accidentally paste references + result = contents.stream().map(entry -> (BibEntry) entry.clone()).collect(Collectors.toList()); } catch (UnsupportedFlavorException | ClassCastException ex) { LOGGER.warn("Could not paste this type", ex); } catch (IOException ex) { diff --git a/src/main/java/org/jabref/gui/DefaultInjector.java b/src/main/java/org/jabref/gui/DefaultInjector.java index a5ba5206faa..8e312d9c5ce 100644 --- a/src/main/java/org/jabref/gui/DefaultInjector.java +++ b/src/main/java/org/jabref/gui/DefaultInjector.java @@ -38,6 +38,8 @@ private static Object createDependency(Class clazz) { return Globals.stateManager; } else if (clazz == DefaultFileUpdateMonitor.class) { return Globals.getFileUpdateMonitor(); + } else if (clazz == ClipBoardManager.class) { + return Globals.clipboardManager; } else { try { return clazz.newInstance(); diff --git a/src/main/java/org/jabref/gui/DragAndDropDataFormats.java b/src/main/java/org/jabref/gui/DragAndDropDataFormats.java index 9ffe3125c10..bee99cbd86a 100644 --- a/src/main/java/org/jabref/gui/DragAndDropDataFormats.java +++ b/src/main/java/org/jabref/gui/DragAndDropDataFormats.java @@ -9,5 +9,5 @@ public class DragAndDropDataFormats { public static final DataFormat GROUP = new DataFormat("dnd/org.jabref.model.groups.GroupTreeNode"); public static final DataFormat LINKED_FILE = new DataFormat("dnd/org.jabref.model.entry.LinkedFile"); - public static final DataFormat ENTRIES = new DataFormat("application/x-java-jvm-local-objectref"); + public static final DataFormat ENTRIES = new DataFormat("dnd/org.jabref.model.entry.BibEntries"); } diff --git a/src/main/java/org/jabref/gui/DuplicateSearch.java b/src/main/java/org/jabref/gui/DuplicateSearch.java index fd6537ea3c5..75352d71835 100644 --- a/src/main/java/org/jabref/gui/DuplicateSearch.java +++ b/src/main/java/org/jabref/gui/DuplicateSearch.java @@ -125,7 +125,7 @@ public void run() { if (!toAdd.isEmpty()) { for (BibEntry entry : toAdd) { panel.getDatabase().insertEntry(entry); - ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), entry, panel)); + ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), entry)); } panel.markBaseChanged(); } diff --git a/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java b/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java index d5b1652b6c4..948f2108c1e 100644 --- a/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java +++ b/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java @@ -3,9 +3,7 @@ import java.util.List; import java.util.stream.Collectors; -import javafx.scene.input.Clipboard; -import javafx.scene.input.ClipboardContent; - +import org.jabref.Globals; import org.jabref.JabRefGUI; import org.jabref.gui.maintable.MainTable; import org.jabref.gui.util.DefaultTaskExecutor; @@ -47,13 +45,7 @@ public void action() throws Exception { sb.append(OS.NEWLINE); } - // This works on Mac and Windows 10, but not on Ubuntu 16.04 - DefaultTaskExecutor.runInJavaFXThread(() -> { - final Clipboard clipboard = Clipboard.getSystemClipboard(); - final ClipboardContent content = new ClipboardContent(); - content.putHtml(sb.toString()); - clipboard.setContent(content); - }); + DefaultTaskExecutor.runInJavaFXThread(() -> Globals.clipboardManager.setClipboardHtmlContent(sb.toString())); int copied = entriesWithKey.size(); int toCopy = entries.size(); diff --git a/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java b/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java index d0cdf431ea7..c2ce9d16515 100644 --- a/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java @@ -36,7 +36,7 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound diskEntry.setId(IdGenerator.next()); panel.getDatabase().insertEntry(diskEntry); secondary.insertEntry(diskEntry); - undoEdit.addEdit(new UndoableInsertEntry(panel.getDatabase(), diskEntry, panel)); + undoEdit.addEdit(new UndoableInsertEntry(panel.getDatabase(), diskEntry)); return true; } diff --git a/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java b/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java index 239c23dc36d..b320b5b3185 100644 --- a/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/DroppedFileHandler.java @@ -304,7 +304,7 @@ private boolean tryXmpImport(String fileName, ExternalFileType fileType, NamedCo for (BibEntry aXmpEntriesInFile : xmpEntriesInFile) { aXmpEntriesInFile.setId(IdGenerator.next()); - edits.addEdit(new UndoableInsertEntry(panel.getDatabase(), aXmpEntriesInFile, panel)); + edits.addEdit(new UndoableInsertEntry(panel.getDatabase(), aXmpEntriesInFile)); panel.getDatabase().insertEntry(aXmpEntriesInFile); doLink(aXmpEntriesInFile, fileType, destFilename, true, edits); diff --git a/src/main/java/org/jabref/gui/importer/EntryFromFileCreatorManager.java b/src/main/java/org/jabref/gui/importer/EntryFromFileCreatorManager.java index 49afd6f0f6d..222ec173be5 100644 --- a/src/main/java/org/jabref/gui/importer/EntryFromFileCreatorManager.java +++ b/src/main/java/org/jabref/gui/importer/EntryFromFileCreatorManager.java @@ -152,7 +152,7 @@ public int addEntriesFromFiles(List files, } else { count++; if (panel != null) { - ce.addEdit(new UndoableInsertEntry(database, entry.get(), panel)); + ce.addEdit(new UndoableInsertEntry(database, entry.get())); } } } diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index e6bd6324621..993f65c157a 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -834,7 +834,7 @@ private void addSelectedEntries(NamedCompound ce, final List selected) } entry.setId(IdGenerator.next()); - ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), entry, panel)); + ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), entry)); } panel.getDatabase().insertEntries(selected); diff --git a/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java index 7d54439a193..1641f11631f 100644 --- a/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java @@ -78,7 +78,7 @@ private static void mergeFromBibtex(BasePanel panel, ParserResult parserResult, database.insertEntry(entry); appendedEntries.add(entry); originalEntries.add(originalEntry); - ce.addEdit(new UndoableInsertEntry(database, entry, panel)); + ce.addEdit(new UndoableInsertEntry(database, entry)); } } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index ec4033de312..c46ef080ce6 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -1,37 +1,51 @@ package org.jabref.gui.maintable; import java.awt.Color; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import javax.swing.JTable; +import javax.swing.undo.UndoManager; import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; import javafx.scene.control.ScrollPane; import javafx.scene.control.SelectionMode; import javafx.scene.control.TableView; +import javafx.scene.input.KeyEvent; import org.jabref.Globals; import org.jabref.gui.BasePanel; +import org.jabref.gui.ClipBoardManager; import org.jabref.gui.EntryMarker; import org.jabref.gui.JabRefFrame; import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.renderer.CompleteRenderer; import org.jabref.gui.renderer.GeneralRenderer; import org.jabref.gui.renderer.IncompleteRenderer; +import org.jabref.gui.undo.NamedCompound; +import org.jabref.gui.undo.UndoableInsertEntry; import org.jabref.gui.util.ViewModelTableRowFactory; import org.jabref.logic.TypedBibEntry; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.UpdateField; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; import ca.odell.glazedlists.matchers.Matcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MainTable extends TableView { + + private static final Logger LOGGER = LoggerFactory.getLogger(MainTable.class); + private static GeneralRenderer defRenderer; private static GeneralRenderer reqRenderer; private static GeneralRenderer optRenderer; @@ -53,26 +67,19 @@ public class MainTable extends TableView { //private final boolean tableResolvedColorCodes; private final ScrollPane pane; + private final BibDatabaseContext database; + private final UndoManager undoManager; // needed to activate/deactivate the listener private PersistenceTableColumnListener tableColumnListener; private final MainTableDataModel model; - // Enum used to define how a cell should be rendered. - private enum CellRendererMode { - REQUIRED, - RESOLVED, - OPTIONAL, - OTHER - } - - static { - //MainTable.updateRenderers(); - } public MainTable(MainTableDataModel model, JabRefFrame frame, BasePanel panel, BibDatabaseContext database, MainTablePreferences preferences, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository) { super(); this.model = model; + this.database = Objects.requireNonNull(database); + this.undoManager = panel.getUndoManager(); this.getColumns().addAll(new MainTableColumnFactory(database, preferences.getColumnPreferences(), externalFileTypes, panel.getUndoManager()).createColumns()); this.setRowFactory(new ViewModelTableRowFactory() @@ -87,8 +94,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, } this.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); - ObservableList entries = model.getEntriesFiltered(); - this.setItems(entries); + this.setItems(model.getEntriesFiltered()); // Enable sorting model.bindComparator(this.comparatorProperty()); @@ -139,53 +145,121 @@ public String getToolTipText(MouseEvent event) { // TODO: Float marked entries //model.updateMarkingState(Globals.prefs.getBoolean(JabRefPreferences.FLOAT_MARKED_ENTRIES)); - // TODO: Keybindings - //Override 'selectNextColumnCell' and 'selectPreviousColumnCell' to move rows instead of cells on TAB - /* - ActionMap actionMap = getActionMap(); - InputMap inputMap = getInputMap(); - actionMap.put("selectNextColumnCell", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - panel.selectNextEntry(); - } - }); - actionMap.put("selectPreviousColumnCell", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - panel.selectPreviousEntry(); - } - }); - actionMap.put("selectNextRow", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - panel.selectNextEntry(); + setupKeyBindings(keyBindingRepository); + } + + public void clearAndSelect(BibEntry bibEntry) { + findEntry(bibEntry) + .ifPresent(entry -> { + getSelectionModel().clearSelection(); + getSelectionModel().select(entry); + scrollTo(entry); + }); + } + + public void copy() { + List selectedEntries = getSelectedEntries(); + + if (!selectedEntries.isEmpty()) { + try { + Globals.clipboardManager.setClipboardContent(selectedEntries); + panel.output(panel.formatOutputMessage(Localization.lang("Copied"), selectedEntries.size())); + } catch (IOException e) { + LOGGER.error("Error while copying selected entries to clipboard", e); } - }); - actionMap.put("selectPreviousRow", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - panel.selectPreviousEntry(); + } + } + + // Enum used to define how a cell should be rendered. + private enum CellRendererMode { + REQUIRED, + RESOLVED, + OPTIONAL, + OTHER + } + + static { + //MainTable.updateRenderers(); + } + + public void cut() { + copy(); + panel.delete(true); + } + + private void setupKeyBindings(KeyBindingRepository keyBindings) { + this.addEventHandler(KeyEvent.KEY_PRESSED, event -> { + Optional keyBinding = keyBindings.mapToKeyBinding(event); + if (keyBinding.isPresent()) { + switch (keyBinding.get()) { + case SELECT_FIRST_ENTRY: + clearAndSelectFirst(); + event.consume(); + break; + case SELECT_LAST_ENTRY: + clearAndSelectLast(); + event.consume(); + break; + case PASTE: + paste(); + event.consume(); + break; + case COPY: + copy(); + event.consume(); + break; + case CUT: + cut(); + event.consume(); + break; + default: + // Pass other keys to parent + } } }); + } + + private void clearAndSelectFirst() { + getSelectionModel().clearSelection(); + getSelectionModel().selectFirst(); + scrollTo(0); + } + + private void clearAndSelectLast() { + getSelectionModel().clearSelection(); + getSelectionModel().selectLast(); + scrollTo(getItems().size() - 1); + } + + public void paste() { + // Find entries in clipboard + List entriesToAdd = new ClipBoardManager().extractBibEntriesFromClipboard(); - String selectFirst = "selectFirst"; - inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_FIRST_ENTRY), selectFirst); - actionMap.put(selectFirst, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent event) { - panel.selectFirstEntry(); + if (!entriesToAdd.isEmpty()) { + // Add new entries + NamedCompound ce = new NamedCompound((entriesToAdd.size() > 1 ? Localization.lang("paste entries") : Localization.lang("paste entry"))); + for (BibEntry entryToAdd : entriesToAdd) { + UpdateField.setAutomaticFields(entryToAdd, Globals.prefs.getUpdateFieldPreferences()); + + database.getDatabase().insertEntry(entryToAdd); + + ce.addEdit(new UndoableInsertEntry(database.getDatabase(), entryToAdd)); } - }); + ce.end(); + undoManager.addEdit(ce); - String selectLast = "selectLast"; - inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_LAST_ENTRY), selectLast); - actionMap.put(selectLast, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent event) { - panel.selectLastEntry(); + panel.output(panel.formatOutputMessage(Localization.lang("Pasted"), entriesToAdd.size())); + + // Show editor if user want us to do this + BibEntry firstNewEntry = entriesToAdd.get(0); + if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) { + panel.showAndEdit(firstNewEntry); } - });*/ + + // Select and focus first new entry + clearAndSelect(firstNewEntry); + this.requestFocus(); + } } public void addSelectionListener(ListChangeListener listener) { diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java index 3ecc385a7dd..32bbd0cbaa4 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java @@ -92,7 +92,7 @@ private void init(List selected) { // Remove the other two entries and add them to the undo stack (which is not working...) BibEntry mergedEntry = mergeEntries.getMergeEntry(); panel.insertEntry(mergedEntry); - ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), mergedEntry, panel)); + ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), mergedEntry)); ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), one, panel)); panel.getDatabase().removeEntry(one); ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), two, panel)); diff --git a/src/main/java/org/jabref/gui/undo/UndoableInsertEntry.java b/src/main/java/org/jabref/gui/undo/UndoableInsertEntry.java index e016caf3850..8bb0249f798 100644 --- a/src/main/java/org/jabref/gui/undo/UndoableInsertEntry.java +++ b/src/main/java/org/jabref/gui/undo/UndoableInsertEntry.java @@ -1,6 +1,5 @@ package org.jabref.gui.undo; -import org.jabref.gui.BasePanel; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; @@ -21,13 +20,9 @@ public class UndoableInsertEntry extends AbstractUndoableJabRefEdit { private final BibDatabase base; private final BibEntry entry; - private final BasePanel panel; - - public UndoableInsertEntry(BibDatabase base, BibEntry entry, - BasePanel panel) { + public UndoableInsertEntry(BibDatabase base, BibEntry entry) { this.base = base; this.entry = entry; - this.panel = panel; } @Override @@ -43,8 +38,6 @@ public void undo() { // Revert the change. try { base.removeEntry(entry); - // If the entry has an editor currently open, we must close it. - panel.ensureNotShowingBottomPanel(entry); } catch (Throwable ex) { LOGGER.warn("Problem to undo `insert entry`", ex); } diff --git a/src/main/java/org/jabref/logic/bibtex/BibEntryWriter.java b/src/main/java/org/jabref/logic/bibtex/BibEntryWriter.java index b3a4d0c6a69..bebdf3f7b28 100644 --- a/src/main/java/org/jabref/logic/bibtex/BibEntryWriter.java +++ b/src/main/java/org/jabref/logic/bibtex/BibEntryWriter.java @@ -1,9 +1,11 @@ package org.jabref.logic.bibtex; import java.io.IOException; +import java.io.StringWriter; import java.io.Writer; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Locale; import java.util.Optional; import java.util.Set; @@ -30,6 +32,15 @@ public BibEntryWriter(LatexFieldFormatter fieldFormatter, boolean write) { this.write = write; } + public String serializeAll(List entries, BibDatabaseMode databaseMode) throws IOException { + StringWriter writer = new StringWriter(); + + for (BibEntry entry : entries) { + write(entry, writer, databaseMode); + } + return writer.toString(); + } + public void write(BibEntry entry, Writer out, BibDatabaseMode bibDatabaseMode) throws IOException { write(entry, out, bibDatabaseMode, false); } diff --git a/src/main/java/org/jabref/pdfimport/PdfImporter.java b/src/main/java/org/jabref/pdfimport/PdfImporter.java index 96ec06ece33..112419cbca1 100644 --- a/src/main/java/org/jabref/pdfimport/PdfImporter.java +++ b/src/main/java/org/jabref/pdfimport/PdfImporter.java @@ -245,7 +245,7 @@ private Optional createNewEntry() { UpdateField.setAutomaticFields(list, true, true, Globals.prefs.getUpdateFieldPreferences()); // Create an UndoableInsertEntry object. - panel.getUndoManager().addEdit(new UndoableInsertEntry(panel.getDatabase(), bibEntry, panel)); + panel.getUndoManager().addEdit(new UndoableInsertEntry(panel.getDatabase(), bibEntry)); panel.output(Localization.lang("Added new") + " '" + type.getName().toLowerCase(Locale.ROOT) + "' " + Localization.lang("entry") + "."); From 8130a8f643d2ed421c279be408dc0a033ea3db60 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 3 Feb 2018 12:19:36 +0100 Subject: [PATCH 041/827] Fix annotation tab (#3682) --- src/main/java/org/jabref/gui/DefaultInjector.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/DefaultInjector.java b/src/main/java/org/jabref/gui/DefaultInjector.java index 8e312d9c5ce..5c96fe7395b 100644 --- a/src/main/java/org/jabref/gui/DefaultInjector.java +++ b/src/main/java/org/jabref/gui/DefaultInjector.java @@ -4,9 +4,9 @@ import org.jabref.Globals; import org.jabref.gui.keyboard.KeyBindingRepository; -import org.jabref.gui.util.DefaultFileUpdateMonitor; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.journals.JournalAbbreviationLoader; +import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.injection.Injector; @@ -36,7 +36,7 @@ private static Object createDependency(Class clazz) { return Globals.journalAbbreviationLoader; } else if (clazz == StateManager.class) { return Globals.stateManager; - } else if (clazz == DefaultFileUpdateMonitor.class) { + } else if (clazz == FileUpdateMonitor.class) { return Globals.getFileUpdateMonitor(); } else if (clazz == ClipBoardManager.class) { return Globals.clipboardManager; From 08f4cf428eb5419f5dbdc27869f57cf094b769c9 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 3 Feb 2018 12:37:34 +0100 Subject: [PATCH 042/827] fix checkstyle and implement singleton using enum --- src/main/java/org/jabref/Globals.java | 1 - src/main/java/org/jabref/gui/BasePanel.java | 4 ++-- src/main/java/org/jabref/gui/StateManager.java | 9 ++++----- .../java/org/jabref/gui/maintable/MainTable.java | 16 +++++++--------- .../SpecialFieldDatabaseChangeListener.java | 11 ++--------- .../SpecialFieldValueViewModel.java | 9 ++++----- 6 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/jabref/Globals.java b/src/main/java/org/jabref/Globals.java index 02f5cd7f6b9..d819bddb824 100644 --- a/src/main/java/org/jabref/Globals.java +++ b/src/main/java/org/jabref/Globals.java @@ -71,7 +71,6 @@ public static synchronized KeyBindingRepository getKeyPrefs() { return keyBindingRepository; } - // Background tasks public static void startBackgroundTasks() { Globals.focusListener = new GlobalFocusListener(); diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 9a258d836b8..96aab75cec6 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1146,7 +1146,7 @@ public void updateTableFont() { } private void createMainTable() { - bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.getInstance()); + bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.INSTANCE); mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext, preferences.getTablePreferences(), externalFileTypes, Globals.getKeyPrefs()); @@ -1907,7 +1907,7 @@ public void searchAndOpen() { // Run the search operation: FileFinder fileFinder = FileFinders.constructFromConfiguration(Globals.prefs.getAutoLinkPreferences()); try { - List files = fileFinder.findAssociatedFiles(entry, dirs, extensions); + List files = fileFinder.findAssociatedFiles(entry, dirs, extensions); if (!files.isEmpty()) { Path file = files.get(0); Optional type = ExternalFileTypes.getInstance().getExternalFileTypeByFile(file); diff --git a/src/main/java/org/jabref/gui/StateManager.java b/src/main/java/org/jabref/gui/StateManager.java index 6f5f79cb41e..2acc073ae7b 100644 --- a/src/main/java/org/jabref/gui/StateManager.java +++ b/src/main/java/org/jabref/gui/StateManager.java @@ -37,13 +37,8 @@ public class StateManager { private final ReadOnlyListWrapper activeGroups = new ReadOnlyListWrapper<>(FXCollections.observableArrayList()); private final ObservableList selectedEntries = FXCollections.observableArrayList(); private final ObservableMap> selectedGroups = FXCollections.observableHashMap(); - private final ObjectProperty> activeSearchQuery = new SimpleObjectProperty<>(Optional.empty()); - public ObjectProperty> activeSearchQueryProperty() { - return activeSearchQuery; - } - public StateManager() { MonadicBinding currentDatabase = EasyBind.map(activeDatabase, database -> database.orElse(null)); activeGroups.bind(Bindings.valueAt(selectedGroups, currentDatabase)); @@ -53,6 +48,10 @@ public ObjectProperty> activeDatabaseProperty() { return activeDatabase; } + public ObjectProperty> activeSearchQueryProperty() { + return activeSearchQuery; + } + public ReadOnlyListProperty activeGroupProperty() { return activeGroups.getReadOnlyProperty(); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index c46ef080ce6..46a35fad284 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -75,7 +75,7 @@ public class MainTable extends TableView { private final MainTableDataModel model; public MainTable(MainTableDataModel model, JabRefFrame frame, - BasePanel panel, BibDatabaseContext database, MainTablePreferences preferences, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository) { + BasePanel panel, BibDatabaseContext database, MainTablePreferences preferences, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository) { super(); this.model = model; this.database = Objects.requireNonNull(database); @@ -121,12 +121,12 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, // TODO: Tooltip for column header /* @Override - public String getToolTipText(MouseEvent event) { + public String getToolTipText(MouseEvent event) { int index = columnModel.getColumnIndexAtX(event.getX()); int realIndex = columnModel.getColumn(index).getModelIndex(); MainTableColumn column = tableFormat.getTableColumn(realIndex); return column.getDisplayName(); - } + } */ // TODO: store column widths @@ -427,7 +427,7 @@ private void setupComparatorChooser() { int index = -1; // TODO where is this prefix set? -// if (!sortFields[i].startsWith(MainTableFormat.ICON_COLUMN_PREFIX)) + // if (!sortFields[i].startsWith(MainTableFormat.ICON_COLUMN_PREFIX)) if (sortFields[i].startsWith("iconcol:")) { for (int j = 0; j < tableFormat.getColumnCount(); j++) { if (sortFields[i].equals(tableFormat.getColumnName(j))) { @@ -472,9 +472,9 @@ private void setupComparatorChooser() { Globals.prefs.putBoolean(JabRefPreferences.TABLE_TERTIARY_SORT_DESCENDING, false); } }); -*/ + */ } -/* + /* // TODO: Reenable background coloring of fields (required/optional/...) private CellRendererMode getCellStatus(int row, int col, boolean checkResolved) { try { @@ -551,13 +551,11 @@ public void updateFont() { */ } - public static void updateRenderers() { MainTable.defRenderer = new GeneralRenderer(Globals.prefs.getColor(JabRefPreferences.TABLE_BACKGROUND), Globals.prefs.getColor(JabRefPreferences.TABLE_TEXT)); - Color sel = MainTable.defRenderer.getTableCellRendererComponent - (new JTable(), "", true, false, 0, 0).getBackground(); + Color sel = MainTable.defRenderer.getTableCellRendererComponent(new JTable(), "", true, false, 0, 0).getBackground(); MainTable.reqRenderer = new GeneralRenderer(Globals.prefs.getColor(JabRefPreferences.TABLE_REQ_FIELD_BACKGROUND), Globals.prefs.getColor(JabRefPreferences.TABLE_TEXT)); MainTable.optRenderer = new GeneralRenderer(Globals.prefs.getColor(JabRefPreferences.TABLE_OPT_FIELD_BACKGROUND), Globals.prefs.getColor(JabRefPreferences.TABLE_TEXT)); MainTable.resolvedRenderer = new GeneralRenderer( diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java index 6813f8f9183..8b7f0ec6ec1 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java @@ -4,16 +4,9 @@ import com.google.common.eventbus.Subscribe; -public class SpecialFieldDatabaseChangeListener { +public enum SpecialFieldDatabaseChangeListener { - private static SpecialFieldDatabaseChangeListener INSTANCE; - - public static SpecialFieldDatabaseChangeListener getInstance() { - if (SpecialFieldDatabaseChangeListener.INSTANCE == null) { - SpecialFieldDatabaseChangeListener.INSTANCE = new SpecialFieldDatabaseChangeListener(); - } - return SpecialFieldDatabaseChangeListener.INSTANCE; - } + INSTANCE; @Subscribe public void listen(EntryAddedEvent event) { diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java index 7813c0e89a8..9362f928be5 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldValueViewModel.java @@ -14,18 +14,17 @@ public class SpecialFieldValueViewModel { - public SpecialFieldValue getValue() { - return value; - } - private final SpecialFieldValue value; public SpecialFieldValueViewModel(SpecialFieldValue value) { Objects.requireNonNull(value); - this.value = value; } + public SpecialFieldValue getValue() { + return value; + } + public Icon getSpecialFieldValueIcon() { return getIcon().map(JabRefIcon::getSmallIcon).orElse(null); } From 07e6b89ed26735cc86a87ce5136b28500489f6bb Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 3 Feb 2018 12:54:12 +0100 Subject: [PATCH 043/827] another round at checkstyle --- src/main/java/org/jabref/Globals.java | 4 +++- src/main/java/org/jabref/gui/BasePanel.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/Globals.java b/src/main/java/org/jabref/Globals.java index d819bddb824..b854ef1a3c4 100644 --- a/src/main/java/org/jabref/Globals.java +++ b/src/main/java/org/jabref/Globals.java @@ -50,6 +50,9 @@ public class Globals { /** * Manager for the state of the GUI. */ + + public static ClipBoardManager clipboardManager = new ClipBoardManager(); + public static StateManager stateManager = new StateManager(); public static ExporterFactory exportFactory; // Key binding preferences @@ -58,7 +61,6 @@ public class Globals { private static GlobalFocusListener focusListener; private static DefaultFileUpdateMonitor fileUpdateMonitor; private static TelemetryClient telemetryClient; - public static ClipBoardManager clipboardManager = new ClipBoardManager(); private Globals() { } diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 96aab75cec6..798588750f5 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -166,10 +166,11 @@ public class BasePanel extends StackPane implements ClipboardOwner { private final BasePanelPreferences preferences; private final ExternalFileTypes externalFileTypes; + private final EntryEditor entryEditor; + private MainTable mainTable; // To contain instantiated entry editors. This is to save time // As most enums, this must not be null private BasePanelMode mode = BasePanelMode.SHOWING_NOTHING; - private final EntryEditor entryEditor; private SplitPane splitPane; private boolean saving; @@ -178,7 +179,6 @@ public class BasePanel extends StackPane implements ClipboardOwner { private boolean baseChanged; private boolean nonUndoableChange; // Used to track whether the base has changed since last save. - public MainTable mainTable; private BibEntry showing; // Variable to prevent erroneous update of back/forward histories at the time // when a Back or Forward operation is being processed: From 7fb331130d0b822ae22018f5f226cdb1d2a48fce Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 3 Feb 2018 12:59:48 +0100 Subject: [PATCH 044/827] checkstyle --- .../SpecialFieldDatabaseChangeListener.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java index 8b7f0ec6ec1..ad315c82d9e 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java @@ -11,22 +11,21 @@ public enum SpecialFieldDatabaseChangeListener { @Subscribe public void listen(EntryAddedEvent event) { // TODO - /* - if (!Globals.prefs.isKeywordSyncEnabled()) { - return; - } - + } + /* + if (!Globals.prefs.isKeywordSyncEnabled()) { + return; + } - final BibEntry entry = event.getBibEntry(); - // NamedCompount code similar to SpecialFieldUpdateListener - NamedCompound nc = new NamedCompound(Localization.lang("Synchronized special fields based on keywords")); - List changes = SpecialFieldsUtils.syncSpecialFieldsFromKeywords(entry, Globals.prefs.getKeywordDelimiter()); - for (FieldChange change: changes) { - nc.addEdit(new UndoableFieldChange(change)); - } - // Don't insert the compound into the undoManager, - // it would be added before the component which undoes the insertion of the entry and creates heavy problems - // (which prohibits the undo the deleting multiple entries) - */ + final BibEntry entry = event.getBibEntry(); + // NamedCompount code similar to SpecialFieldUpdateListener + NamedCompound nc = new NamedCompound(Localization.lang("Synchronized special fields based on keywords")); + List changes = SpecialFieldsUtils.syncSpecialFieldsFromKeywords(entry, Globals.prefs.getKeywordDelimiter()); + for (FieldChange change: changes) { + nc.addEdit(new UndoableFieldChange(change)); } + // Don't insert the compound into the undoManager, + // it would be added before the component which undoes the insertion of the entry and creates heavy problems + // (which prohibits the undo the deleting multiple entries) + */ } From 2fc5a347ec36bccb8096e5ac7a89c743228aad1a Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 5 Feb 2018 22:17:28 +0100 Subject: [PATCH 045/827] Add test menu --- src/main/java/org/jabref/gui/JabRefFrame.java | 27 +++++++++++++------ src/main/java/org/jabref/gui/Main.css | 23 ++++++++++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 753cc386498..12d717d91fa 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -55,16 +55,19 @@ import javafx.embed.swing.JFXPanel; import javafx.embed.swing.SwingNode; import javafx.scene.Scene; +import javafx.scene.control.Menu; +import javafx.scene.control.MenuBar; import javafx.scene.control.SplitPane; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.control.Tooltip; import javafx.scene.layout.BorderPane; -import javafx.scene.layout.StackPane; import org.jabref.Globals; import org.jabref.JabRefExecutorService; +import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.Actions; +import org.jabref.gui.actions.ActionsFX; import org.jabref.gui.actions.AutoLinkFilesAction; import org.jabref.gui.actions.ConnectToSharedDatabaseAction; import org.jabref.gui.actions.ErrorConsoleAction; @@ -168,6 +171,7 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { private final ToolBar tlb = new ToolBar(); private final GlobalSearchBar globalSearchBar = new GlobalSearchBar(this); private final JMenuBar mb = new JMenuBar(); + private final MenuBar menu = new MenuBar(); private final JLabel statusLine = new JLabel("", SwingConstants.LEFT); private final JLabel statusLabel = new JLabel( Localization.lang("Status") @@ -887,7 +891,7 @@ private void initLayout() { pushExternalButton = new PushToApplicationButton(this, pushApplications.getApplications()); fillMenu(); createToolBar(); - //setJMenuBar(mb); + setTop(menu); //getContentPane().setLayout(new BorderLayout()); JPanel toolbarPanel = new JPanel(new WrapLayout(FlowLayout.LEFT)); @@ -919,12 +923,6 @@ public void keyPressed(KeyEvent e) { } }); - StackPane header = new StackPane(); - header.setId("header"); - header.setPrefHeight(50); - header.setStyle("-fx-background-color: #4d4674; -fx-text-fill: white;"); - setTop(header); - SwingNode swingSidePane = new SwingNode(); SwingUtilities.invokeLater(() -> { swingSidePane.setContent(sidePaneManager.getPanel()); @@ -1041,6 +1039,19 @@ public void setTabTitle(BasePanel comp, String title, String toolTip) { } private void fillMenu() { + ActionFactory factory = new ActionFactory(Globals.getKeyPrefs()); + + Menu fileMenu = new Menu(Localization.menuTitle("File")); + Menu editMenu = new Menu(Localization.menuTitle("Edit")); + + fileMenu.getItems().addAll( + factory.createMenuItem(ActionsFX.ADD_FILE_LINK, null), + factory.createMenuItem(ActionsFX.READ, null), + factory.createMenuItem(ActionsFX.RANKING, null) + ); + + menu.getMenus().addAll(fileMenu, editMenu); + mb.setBorder(null); JMenu file = JabRefFrame.subMenu(Localization.menuTitle("File")); JMenu edit = JabRefFrame.subMenu(Localization.menuTitle("Edit")); diff --git a/src/main/java/org/jabref/gui/Main.css b/src/main/java/org/jabref/gui/Main.css index cf74e532701..7c0488cdd1a 100644 --- a/src/main/java/org/jabref/gui/Main.css +++ b/src/main/java/org/jabref/gui/Main.css @@ -52,6 +52,11 @@ * A dark gray for borders */ -fx-border: #868786; + + /* + * A light gray for background for active items in list like elements such as menus, lists, trees, and tables. + */ + -fx-selection-bar: #e5e5e5; } .hyperlink { @@ -126,6 +131,24 @@ -fx-padding: -0.1em 0.5em 0.5em 0.5em; } +.menu-bar { + -fx-background-color: white; + -fx-background-insets: 0; + -fx-background-radius: 0; +} + +.menu-bar > .container > .menu-button > .label { + -fx-padding: 0.41777em 0.41777em 0.41777em 0.41777em; /* 5 5 5 5 */ +} + +.menu-bar > .menu { + -fx-padding: 0.0em 0.666667em 0.0em 0.666667em; /* 0 8 0 8 */ +} + +.menu-item { + -fx-padding: 0.5em 0.41777em 0.5em 0.41777em; /* 6 5 6 5 */ +} + .tab-pane { -fx-open-tab-animation: NONE; -fx-close-tab-animation: NONE; From 4ea3f35a6390c1f4d60b3accc3c0bd2659f08ae8 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 6 Feb 2018 11:33:08 +0100 Subject: [PATCH 046/827] Visually improve display of maintable (#3689) * Fix padding issues and restyle text input controls * Improve look of scrollbars --- src/main/java/org/jabref/gui/Main.css | 99 +++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/src/main/java/org/jabref/gui/Main.css b/src/main/java/org/jabref/gui/Main.css index cf74e532701..45cff6c8c18 100644 --- a/src/main/java/org/jabref/gui/Main.css +++ b/src/main/java/org/jabref/gui/Main.css @@ -237,3 +237,102 @@ -fx-background: -fx-selection-bar; -fx-table-cell-border-color: transparent; } + +.scroll-pane, +.split-pane { + -fx-background-insets: 0, 0; + -fx-padding: 0; +} + +.text-input { + -fx-background-color: #cacbca, -fx-control-inner-background; + -fx-background-insets: 0, 1; +} + +.text-input:focused { + -fx-background-color: -fx-active-background, -fx-control-inner-background; + -fx-background-insets: 0, 2; +} + +.text-area { + -fx-background-color: white; +} + +.text-area .content { + -fx-background-color: #cacbca, -fx-control-inner-background; + -fx-background-insets: 0, 1; + -fx-padding: 0.333333em 0.583em 0.333333em 0.583em; +} + +.text-area:focused .content { + -fx-background-color: -fx-active-background, -fx-control-inner-background; + -fx-background-insets: 0, 2; +} + +.date-picker > .text-field:focused { + -fx-background-color: -fx-active-background, -fx-control-inner-background; + -fx-background-insets: 0, 2; +} + +.scroll-bar { + -fx-background-color: transparent; + -fx-opacity: 0; +} + +.scroll-bar:horizontal .track, +.scroll-bar:vertical .track { + -fx-background-color: derive(#868786, 20%); + -fx-opacity: 0.2; + -fx-background-radius: 0em; +} + +.scroll-bar:horizontal .thumb, +.scroll-bar:vertical .thumb { + -fx-background-color: derive(#757575, 60%); + -fx-background-insets: 0, 0, 0; + -fx-background-radius: 0em; +} + +.scroll-bar .thumb:hover, +.scroll-bar .thumb:pressed { + -fx-background-color: derive(black, 70%); +} + +/* Hide increment and decrement buttons */ +.scroll-bar > .increment-button, +.scroll-bar > .decrement-button { + -fx-background-color: null; + -fx-background-radius: 0; + -fx-background-insets: 0; + -fx-padding: 0; +} + +/* Hide increment and decrement arrows */ +.scroll-bar:horizontal > .decrement-button > .decrement-arrow, +.scroll-bar:horizontal > .increment-button > .increment-arrow, +.scroll-bar:vertical > .decrement-button > .decrement-arrow, +.scroll-bar:vertical > .increment-button > .increment-arrow { + -fx-background-color: null; + -fx-background-radius: 0; + -fx-background-insets: 0; + -fx-shape: null; + -fx-padding: 0; +} + +/* Need some padding since otherwise no scroll-bar is displayed at all */ +.scroll-bar:horizontal > .decrement-button > .decrement-arrow { + -fx-padding: 0.333em 0.167em 0.333em 0.167em; /* 4 2 4 2 */ +} + +.scroll-bar:vertical > .decrement-button > .decrement-arrow { + -fx-padding: 0em 0.333em 0em 0.333em; /* 2 4 2 4 */ +} + +/* Only show scrollbars for hovered elements */ +.list-view:hover .scroll-bar, +.tree-view:hover .scroll-bar, +.table-view:hover .scroll-bar, +.tree-table-view:hover .scroll-bar, +.text-input:hover .scroll-bar { + -fx-opacity: 1; +} From 40a9df31e50fb7e30d4a250121c7f7a24d6ecd04 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 6 Feb 2018 11:35:18 +0100 Subject: [PATCH 047/827] Fix select entries my holding mouse (#3683) --- .../org/jabref/gui/maintable/MainTable.java | 23 ++++- .../gui/util/ViewModelTableRowFactory.java | 97 +++++++++++++++++++ 2 files changed, 118 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 46a35fad284..8425094afcb 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -14,8 +14,11 @@ import javafx.collections.ListChangeListener; import javafx.scene.control.ScrollPane; import javafx.scene.control.SelectionMode; +import javafx.scene.control.TableRow; import javafx.scene.control.TableView; import javafx.scene.input.KeyEvent; +import javafx.scene.input.MouseDragEvent; +import javafx.scene.input.MouseEvent; import org.jabref.Globals; import org.jabref.gui.BasePanel; @@ -82,13 +85,16 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, this.undoManager = panel.getUndoManager(); this.getColumns().addAll(new MainTableColumnFactory(database, preferences.getColumnPreferences(), externalFileTypes, panel.getUndoManager()).createColumns()); - this.setRowFactory(new ViewModelTableRowFactory() + new ViewModelTableRowFactory() .withOnMouseClickedEvent((entry, event) -> { if (event.getClickCount() == 2) { panel.showAndEdit(entry.getEntry()); } }) - .withContextMenu(entry1 -> RightClickMenu.create(entry1, keyBindingRepository, panel, Globals.getKeyPrefs()))); + .withContextMenu(entry1 -> RightClickMenu.create(entry1, keyBindingRepository, panel, Globals.getKeyPrefs())) + .setOnDragDetected(this::handleOnDragDetected) + .setOnMouseDragEntered(this::handleOnDragEntered) + .install(this); if (preferences.resizeColumnsToFit()) { this.setColumnResizePolicy(new SmartConstrainedResizePolicy()); } @@ -262,6 +268,19 @@ public void paste() { } } + private void handleOnDragEntered(TableRow row, BibEntryTableViewModel entry, MouseDragEvent event) { + // Support the following gesture to select entries: click on one row -> hold mouse button -> move over other rows + // We need to select all items between the starting row and the row where the user currently hovers the mouse over + // It is not enough to just select the currently hovered row since then sometimes rows are not marked selected if the user moves to fast + TableRow sourceRow = (TableRow) event.getGestureSource(); + getSelectionModel().selectRange(sourceRow.getIndex(), row.getIndex()); + } + + private void handleOnDragDetected(TableRow row, BibEntryTableViewModel entry, MouseEvent event) { + // Start drag'n'drop + row.startFullDrag(); + } + public void addSelectionListener(ListChangeListener listener) { getSelectionModel().getSelectedItems().addListener(listener); } diff --git a/src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java b/src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java index 3bd35d101fb..72d1de5e572 100644 --- a/src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java +++ b/src/main/java/org/jabref/gui/util/ViewModelTableRowFactory.java @@ -7,9 +7,13 @@ import javafx.scene.control.TableRow; import javafx.scene.control.TableView; import javafx.scene.control.TreeTableCell; +import javafx.scene.input.DragEvent; +import javafx.scene.input.MouseDragEvent; import javafx.scene.input.MouseEvent; import javafx.util.Callback; +import org.reactfx.util.TriConsumer; + /** * Constructs a {@link TreeTableCell} based on the view model of the row and a bunch of specified converter methods. * @@ -19,6 +23,12 @@ public class ViewModelTableRowFactory implements Callback, Table private BiConsumer onMouseClickedEvent; private Function contextMenuFactory; + private TriConsumer, S, ? super MouseEvent> toOnDragDetected; + private BiConsumer toOnDragDropped; + private BiConsumer toOnDragEntered; + private BiConsumer toOnDragExited; + private BiConsumer toOnDragOver; + private TriConsumer, S, ? super MouseDragEvent> toOnMouseDragEntered; public ViewModelTableRowFactory withOnMouseClickedEvent(BiConsumer onMouseClickedEvent) { this.onMouseClickedEvent = onMouseClickedEvent; @@ -30,6 +40,46 @@ public ViewModelTableRowFactory withContextMenu(Function cont return this; } + public ViewModelTableRowFactory setOnDragDetected(TriConsumer, S, ? super MouseEvent> toOnDragDetected) { + this.toOnDragDetected = toOnDragDetected; + return this; + } + + public ViewModelTableRowFactory setOnDragDetected(BiConsumer toOnDragDetected) { + this.toOnDragDetected = (row, viewModel, event) -> toOnDragDetected.accept(viewModel, event); + return this; + } + + public ViewModelTableRowFactory setOnDragDropped(BiConsumer toOnDragDropped) { + this.toOnDragDropped = toOnDragDropped; + return this; + } + + public ViewModelTableRowFactory setOnDragEntered(BiConsumer toOnDragEntered) { + this.toOnDragEntered = toOnDragEntered; + return this; + } + + public ViewModelTableRowFactory setOnMouseDragEntered(BiConsumer toOnDragEntered) { + this.toOnMouseDragEntered = (row, viewModel, event) -> toOnDragEntered.accept(viewModel, event); + return this; + } + + public ViewModelTableRowFactory setOnMouseDragEntered(TriConsumer, S, ? super MouseDragEvent> toOnDragEntered) { + this.toOnMouseDragEntered = toOnDragEntered; + return this; + } + + public ViewModelTableRowFactory setOnDragExited(BiConsumer toOnDragExited) { + this.toOnDragExited = toOnDragExited; + return this; + } + + public ViewModelTableRowFactory setOnDragOver(BiConsumer toOnDragOver) { + this.toOnDragOver = toOnDragOver; + return this; + } + @Override public TableRow call(TableView tableView) { TableRow row = new TableRow<>(); @@ -53,6 +103,53 @@ public TableRow call(TableView tableView) { }); } + if (toOnDragDetected != null) { + row.setOnDragDetected(event -> { + if (!row.isEmpty()) { + toOnDragDetected.accept(row, row.getItem(), event); + } + }); + } + if (toOnDragDropped != null) { + row.setOnDragDropped(event -> { + if (!row.isEmpty()) { + toOnDragDropped.accept(row.getItem(), event); + } + }); + } + if (toOnDragEntered != null) { + row.setOnDragEntered(event -> { + if (!row.isEmpty()) { + toOnDragEntered.accept(row.getItem(), event); + } + }); + } + if (toOnDragExited != null) { + row.setOnDragExited(event -> { + if (!row.isEmpty()) { + toOnDragExited.accept(row.getItem(), event); + } + }); + } + if (toOnDragOver != null) { + row.setOnDragOver(event -> { + if (!row.isEmpty()) { + toOnDragOver.accept(row.getItem(), event); + } + }); + } + + if (toOnMouseDragEntered != null) { + row.setOnMouseDragEntered(event -> { + if (!row.isEmpty()) { + toOnMouseDragEntered.accept(row, row.getItem(), event); + } + }); + } return row; } + + public void install(TableView table) { + table.setRowFactory(this); + } } From ddc5325e226e857df72b55a506f3fee560e20ad3 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 7 Feb 2018 10:45:37 +0100 Subject: [PATCH 048/827] Start reworking file menu --- src/main/java/org/jabref/gui/BasePanel.java | 31 ---- src/main/java/org/jabref/gui/JabRefFrame.java | 175 ++++++++---------- .../java/org/jabref/gui/actions/Actions.java | 1 - .../org/jabref/gui/actions/ActionsFX.java | 62 ++++++- .../org/jabref/gui/actions/JabRefAction.java | 1 + .../jabref/gui/actions/NewDatabaseAction.java | 15 +- .../actions/OldDatabaseCommandWrapper.java | 55 ++++++ .../org/jabref/gui/actions/SimpleCommand.java | 26 +++ .../jabref/gui/exporter/SaveAllAction.java | 21 +-- .../gui/groups/EntryTableTransferHandler.java | 2 +- .../jabref/gui/importer/ImportFormats.java | 39 +--- .../importer/actions/OpenDatabaseAction.java | 45 ++--- 12 files changed, 248 insertions(+), 225 deletions(-) create mode 100644 src/main/java/org/jabref/gui/actions/OldDatabaseCommandWrapper.java create mode 100644 src/main/java/org/jabref/gui/actions/SimpleCommand.java diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index f0237e25b55..a36c2fe08c8 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -87,7 +87,6 @@ import org.jabref.gui.undo.UndoableKeyChange; import org.jabref.gui.undo.UndoableRemoveEntry; import org.jabref.gui.util.DefaultTaskExecutor; -import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.component.CheckBoxMessage; import org.jabref.gui.worker.AbstractWorker; import org.jabref.gui.worker.CallBack; @@ -107,7 +106,6 @@ import org.jabref.logic.layout.LayoutHelper; import org.jabref.logic.pdf.FileAnnotationCache; import org.jabref.logic.search.SearchQuery; -import org.jabref.logic.util.FileType; import org.jabref.logic.util.UpdateField; import org.jabref.logic.util.io.FileFinder; import org.jabref.logic.util.io.FileFinders; @@ -2167,33 +2165,4 @@ public void action() throws Exception { preview.print(); } } - - private class SaveSelectedAction implements BaseAction { - - private final SavePreferences.DatabaseSaveType saveType; - - public SaveSelectedAction(SavePreferences.DatabaseSaveType saveType) { - this.saveType = saveType; - } - - @Override - public void action() throws SaveException { - FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .withDefaultExtension(FileType.BIBTEX_DB) - .addExtensionFilter(FileType.BIBTEX_DB) - .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); - - DialogService ds = new FXDialogService(); - - Optional chosenFile = DefaultTaskExecutor - .runInJavaFXThread(() -> ds.showFileSaveDialog(fileDialogConfiguration)); - - if (chosenFile.isPresent()) { - Path path = chosenFile.get(); - saveDatabase(path.toFile(), true, Globals.prefs.getDefaultEncoding(), saveType); - frame.getFileHistory().newFile(path.toString()); - frame.output(Localization.lang("Saved selected to '%0'.", path.toString())); - } - } - } } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 12d717d91fa..d2a19565c59 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -36,7 +36,6 @@ import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JMenu; -import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -79,6 +78,7 @@ import org.jabref.gui.actions.NewDatabaseAction; import org.jabref.gui.actions.NewEntryAction; import org.jabref.gui.actions.NewSubDatabaseAction; +import org.jabref.gui.actions.OldDatabaseCommandWrapper; import org.jabref.gui.actions.OpenBrowserAction; import org.jabref.gui.actions.SearchForUpdateAction; import org.jabref.gui.actions.SortTabsAction; @@ -116,7 +116,6 @@ import org.jabref.gui.push.PushToApplicationButton; import org.jabref.gui.push.PushToApplications; import org.jabref.gui.search.GlobalSearchBar; -import org.jabref.gui.specialfields.SpecialFieldDropDown; import org.jabref.gui.specialfields.SpecialFieldValueViewModel; import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.util.DefaultTaskExecutor; @@ -170,15 +169,13 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { private final IntegrityCheckAction checkIntegrity = new IntegrityCheckAction(this); private final ToolBar tlb = new ToolBar(); private final GlobalSearchBar globalSearchBar = new GlobalSearchBar(this); - private final JMenuBar mb = new JMenuBar(); - private final MenuBar menu = new MenuBar(); private final JLabel statusLine = new JLabel("", SwingConstants.LEFT); private final JLabel statusLabel = new JLabel( Localization.lang("Status") + ':', SwingConstants.LEFT); private final JProgressBar progressBar = new JProgressBar(); private final FileHistoryMenu fileHistory = new FileHistoryMenu(prefs, this); - private final OpenDatabaseAction open = new OpenDatabaseAction(this, true); + private final OpenDatabaseAction open = new OpenDatabaseAction(this); private final EditModeAction editModeAction = new EditModeAction(); @@ -190,8 +187,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { // for the name and message strings. private final AbstractAction quit = new CloseAction(); private final AbstractAction keyBindingAction = new KeyBindingAction(); - private final AbstractAction newBibtexDatabaseAction = new NewDatabaseAction(this, BibDatabaseMode.BIBTEX); - private final AbstractAction newBiblatexDatabaseAction = new NewDatabaseAction(this, BibDatabaseMode.BIBLATEX); private final AbstractAction connectToSharedDatabaseAction = new ConnectToSharedDatabaseAction(this); private final AbstractAction newSubDatabaseAction = new NewSubDatabaseAction(this); private final AbstractAction jabrefWebPageAction = new OpenBrowserAction("https://jabref.org", @@ -227,17 +222,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { private final AbstractAction focusTable = new GeneralAction(Actions.FOCUS_TABLE, Localization.menuTitle("Focus entry table"), Localization.lang("Move the keyboard focus to the entry table"), Globals.getKeyPrefs().getKey(KeyBinding.FOCUS_ENTRY_TABLE)); - private final AbstractAction save = new GeneralAction(Actions.SAVE, Localization.menuTitle("Save library"), - Localization.lang("Save library"), Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE), IconTheme.JabRefIcons.SAVE.getIcon()); - private final AbstractAction saveAs = new GeneralAction(Actions.SAVE_AS, - Localization.menuTitle("Save library as..."), Localization.lang("Save library as..."), - Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE_AS)); - private final AbstractAction saveAll = new SaveAllAction(JabRefFrame.this); - private final AbstractAction saveSelectedAs = new GeneralAction(Actions.SAVE_SELECTED_AS, - Localization.menuTitle("Save selected as..."), Localization.lang("Save selected as...")); - private final AbstractAction saveSelectedAsPlain = new GeneralAction(Actions.SAVE_SELECTED_AS_PLAIN, - Localization.menuTitle("Save selected as plain BibTeX..."), - Localization.lang("Save selected as plain BibTeX...")); private final AbstractAction importCurrent = ImportFormats.getImportAction(this, false); private final AbstractAction importNew = ImportFormats.getImportAction(this, true); private final AbstractAction sortTabs = new SortTabsAction(this); @@ -308,9 +292,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { private final AbstractAction copyKeyAndLink = new GeneralAction(Actions.COPY_KEY_AND_LINK, Localization.menuTitle("Copy BibTeX key and link"), Globals.getKeyPrefs().getKey(KeyBinding.COPY_BIBTEX_KEY_AND_LINK)); - private final AbstractAction mergeDatabaseAction = new GeneralAction(Actions.MERGE_DATABASE, - Localization.menuTitle("Append library"), - Localization.lang("Append contents from a BibTeX library into the currently viewed library")); private final AbstractAction selectAll = new GeneralAction(Actions.SELECT_ALL, Localization.menuTitle("Select all"), Globals.getKeyPrefs().getKey(KeyBinding.SELECT_ALL)); private final AbstractAction replaceAll = new GeneralAction(Actions.REPLACE_ALL, @@ -889,9 +870,8 @@ private void initLayout() { pushApplications = new PushToApplications(); pushExternalButton = new PushToApplicationButton(this, pushApplications.getApplications()); - fillMenu(); - createToolBar(); - setTop(menu); + //createToolBar(); + setTop(createMenu()); //getContentPane().setLayout(new BorderLayout()); JPanel toolbarPanel = new JPanel(new WrapLayout(FlowLayout.LEFT)); @@ -963,7 +943,7 @@ public void keyPressed(KeyEvent e) { // TODO: //tabbedPane.setTransferHandler(xfer); tlb.setTransferHandler(xfer); - mb.setTransferHandler(xfer); + // TODO: mb.setTransferHandler(xfer); sidePaneManager.getPanel().setTransferHandler(xfer); } @@ -1038,61 +1018,56 @@ public void setTabTitle(BasePanel comp, String title, String toolTip) { }); } - private void fillMenu() { + private MenuBar createMenu() { ActionFactory factory = new ActionFactory(Globals.getKeyPrefs()); - Menu fileMenu = new Menu(Localization.menuTitle("File")); - Menu editMenu = new Menu(Localization.menuTitle("Edit")); - - fileMenu.getItems().addAll( - factory.createMenuItem(ActionsFX.ADD_FILE_LINK, null), - factory.createMenuItem(ActionsFX.READ, null), - factory.createMenuItem(ActionsFX.RANKING, null) - ); + Menu file = new Menu(Localization.menuTitle("File")); + Menu edit = new Menu(Localization.menuTitle("Edit")); + Menu library = new Menu(Localization.menuTitle("Library")); + Menu quality = new Menu(Localization.menuTitle("Quality")); + Menu view = new Menu(Localization.menuTitle("View")); + Menu tools = new Menu(Localization.menuTitle("Tools")); + Menu options = new Menu(Localization.menuTitle("Options")); + newSpec = JabRefFrame.subMenu(Localization.menuTitle("New entry by type...")); + Menu help = new Menu(Localization.menuTitle("Help")); + + file.getItems().addAll( + factory.createMenuItem(ActionsFX.NEW_LIBRARY_BIBTEX, new NewDatabaseAction(this, BibDatabaseMode.BIBTEX)), + factory.createMenuItem(ActionsFX.NEW_LIBRARY_BIBLATEX, new NewDatabaseAction(this, BibDatabaseMode.BIBLATEX)), + factory.createMenuItem(ActionsFX.OPEN_LIBRARY, getOpenDatabaseAction()), + factory.createMenuItem(ActionsFX.save, new OldDatabaseCommandWrapper(Actions.SAVE, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.saveAs, new OldDatabaseCommandWrapper(Actions.SAVE_AS, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.saveAll, new SaveAllAction(this), + + factory.createMenuItem(ActionsFX.mergeDatabaseAction, new OldDatabaseCommandWrapper(Actions.MERGE_DATABASE, this, Globals.stateManager)), // TODO: merge with import + factory.createMenuItem(ActionsFX.saveSelectedAsPlain, new OldDatabaseCommandWrapper(Actions.SAVE_SELECTED_AS_PLAIN, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.importNew, new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.importCurrent, new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), + factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), + factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), + factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), + + file.add(importNew), + file.add(importCurrent), + file.add(exportAll), + file.add(exportSelected), + file.add(exportLinkedFiles), + file.addSeparator(), + file.add(connectToSharedDatabaseAction), + file.add(pullChangesFromSharedDatabase), + + file.addSeparator(), + file.add(databaseProperties), + file.add(editModeAction), + file.addSeparator(), + + file.add(fileHistory), + file.addSeparator(), + file.add(closeDatabaseAction), + file.add(quit) + ); - menu.getMenus().addAll(fileMenu, editMenu); - mb.setBorder(null); - JMenu file = JabRefFrame.subMenu(Localization.menuTitle("File")); - JMenu edit = JabRefFrame.subMenu(Localization.menuTitle("Edit")); - JMenu search = JabRefFrame.subMenu(Localization.menuTitle("Search")); - JMenu groups = JabRefFrame.subMenu(Localization.menuTitle("Groups")); - JMenu bibtex = JabRefFrame.subMenu("&BibTeX"); - JMenu quality = JabRefFrame.subMenu(Localization.menuTitle("Quality")); - JMenu view = JabRefFrame.subMenu(Localization.menuTitle("View")); - JMenu tools = JabRefFrame.subMenu(Localization.menuTitle("Tools")); - JMenu options = JabRefFrame.subMenu(Localization.menuTitle("Options")); - newSpec = JabRefFrame.subMenu(Localization.menuTitle("New entry by type...")); - JMenu helpMenu = JabRefFrame.subMenu(Localization.menuTitle("Help")); - - file.add(newBibtexDatabaseAction); - file.add(newBiblatexDatabaseAction); - file.add(getOpenDatabaseAction()); - file.add(mergeDatabaseAction); - file.add(save); - file.add(saveAs); - file.add(saveAll); - file.add(saveSelectedAs); - file.add(saveSelectedAsPlain); - file.addSeparator(); - file.add(importNew); - file.add(importCurrent); - file.add(exportAll); - file.add(exportSelected); - file.add(exportLinkedFiles); - file.addSeparator(); - file.add(connectToSharedDatabaseAction); - file.add(pullChangesFromSharedDatabase); - - file.addSeparator(); - file.add(databaseProperties); - file.add(editModeAction); - file.addSeparator(); - - file.add(fileHistory); - file.addSeparator(); - file.add(closeDatabaseAction); - file.add(quit); mb.add(file); edit.add(undo); @@ -1210,23 +1185,23 @@ private void fillMenu() { mb.add(view); - bibtex.add(newEntryAction); + library.add(newEntryAction); for (NewEntryAction a : newSpecificEntryAction) { newSpec.add(a); } - bibtex.add(newSpec); + library.add(newSpec); - bibtex.add(plainTextImport); - bibtex.addSeparator(); - bibtex.add(editEntry); - bibtex.add(editPreamble); - bibtex.add(editStrings); - bibtex.addSeparator(); - bibtex.add(customizeAction); - bibtex.addSeparator(); - bibtex.add(deleteEntry); - mb.add(bibtex); + library.add(plainTextImport); + library.addSeparator(); + library.add(editEntry); + library.add(editPreamble); + library.add(editStrings); + library.addSeparator(); + library.add(customizeAction); + library.addSeparator(); + library.add(deleteEntry); + mb.add(library); quality.add(dupliCheck); quality.add(mergeEntries); @@ -1277,12 +1252,12 @@ private void fillMenu() { options.add(manageSelectors); mb.add(options); - helpMenu.add(help); - helpMenu.add(openForumAction); - helpMenu.addSeparator(); - helpMenu.add(errorConsole); - helpMenu.addSeparator(); - helpMenu.add(new SearchForUpdateAction()); + help.add(this.help); + help.add(openForumAction); + help.addSeparator(); + help.add(errorConsole); + help.addSeparator(); + help.add(new SearchForUpdateAction()); JMenu webMenu = JabRefFrame.subMenu(Localization.menuTitle("JabRef resources")); webMenu.add(jabrefWebPageAction); webMenu.add(jabrefBlogAction); @@ -1294,11 +1269,15 @@ private void fillMenu() { webMenu.add(changeLogAction); webMenu.addSeparator(); webMenu.add(donationAction); - helpMenu.add(webMenu); - helpMenu.add(about); - mb.add(helpMenu); + help.add(webMenu); + help.add(about); + mb.add(help); createDisabledIconsForMenuEntries(mb); + + MenuBar menu = new MenuBar(); + menu.getMenus().addAll(fileMenu, editMenu); + return menu; } public void addParserResult(ParserResult pr, boolean focusPanel) { @@ -1325,6 +1304,7 @@ public void addParserResult(ParserResult pr, boolean focusPanel) { } } + /* private void createToolBar() { tlb.setBorder(null); tlb.setRollover(true); @@ -1413,6 +1393,7 @@ private void createToolBar() { createDisabledIconsForButtons(tlb); } + */ /** * displays the String on the Status Line visible on the bottom of the JabRef mainframe diff --git a/src/main/java/org/jabref/gui/actions/Actions.java b/src/main/java/org/jabref/gui/actions/Actions.java index b987cba8220..db244f3911c 100644 --- a/src/main/java/org/jabref/gui/actions/Actions.java +++ b/src/main/java/org/jabref/gui/actions/Actions.java @@ -55,7 +55,6 @@ public enum Actions { RESOLVE_DUPLICATE_KEYS, SAVE, SAVE_AS, - SAVE_SELECTED_AS, SAVE_SELECTED_AS_PLAIN, SEARCH, GLOBAL_SEARCH, diff --git a/src/main/java/org/jabref/gui/actions/ActionsFX.java b/src/main/java/org/jabref/gui/actions/ActionsFX.java index 2ca8b48e5d2..ad8e9ec6d78 100644 --- a/src/main/java/org/jabref/gui/actions/ActionsFX.java +++ b/src/main/java/org/jabref/gui/actions/ActionsFX.java @@ -2,10 +2,16 @@ import java.util.Optional; +import javax.swing.AbstractAction; +import javax.swing.Action; + +import org.jabref.Globals; import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefFrame; import org.jabref.gui.JabRefIcon; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.l10n.Localization; +import org.jabref.model.database.BibDatabaseMode; public enum ActionsFX { @@ -58,36 +64,80 @@ public enum ActionsFX { READ(Localization.lang("Set read status to read"), IconTheme.JabRefIcons.READ_STATUS_READ), SKIMMED(Localization.lang("Set read status to skimmed"), IconTheme.JabRefIcons.READ_STATUS_SKIMMED), RELEVANCE(Localization.lang("Relevance"), IconTheme.JabRefIcons.RELEVANCE), - RELEVANT(Localization.lang("Toggle relevance"), IconTheme.JabRefIcons.RELEVANCE); + RELEVANT(Localization.lang("Toggle relevance"), IconTheme.JabRefIcons.RELEVANCE), + NEW_LIBRARY_BIBTEX(Localization.menuTitle("New %0 library", BibDatabaseMode.BIBTEX.getFormattedName()), IconTheme.JabRefIcons.NEW), + NEW_LIBRARY_BIBLATEX(Localization.menuTitle("New %0 library", BibDatabaseMode.BIBLATEX.getFormattedName()), IconTheme.JabRefIcons.NEW), + OPEN_LIBRARY(Localization.menuTitle("Open library"), IconTheme.JabRefIcons.OPEN, KeyBinding.OPEN_DATABASE), + mergeDatabaseAction(Localization.menuTitle("Append library"), Localization.lang("Append contents from a BibTeX library into the currently viewed library")), + save(Localization.menuTitle("Save library"), IconTheme.JabRefIcons.SAVE, KeyBinding.SAVE_DATABASE), + private final AbstractAction saveAs = new JabRefFrame.GeneralAction(Actions.SAVE_AS, + Localization.menuTitle("Save library as..."), Localization.lang("Save library as..."), + Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE_AS)); + private final AbstractAction saveSelectedAsPlain = new JabRefFrame.GeneralAction(Actions.SAVE_SELECTED_AS_PLAIN, + Localization.menuTitle("Save selected as plain BibTeX..."), + Localization.lang("Save selected as plain BibTeX..."));) + private final String description;. + + saveAll(super(IconTheme.JabRefIcons.SAVE_ALL.getIcon()) + + putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs()) + + getKey(KeyBinding.SAVE_ALL))) + + putValue(Action.SHORT_DESCRIPTION, Localization.lang("Save all open libraries") + + putValue(Action.NAME, Localization.menuTitle("Save all")) + + importNew(putValue(Action.NAME, Localization.menuTitle("Import into new library"). + + putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs())) + + getKey(KeyBinding.IMPORT_INTO_NEW_DATABASE)) + + importCurrent(putValue(Action.NAME, Localization.menuTitle("Import into current library"). + + putValue(Action.ACCELERATOR_KEY, + Globals.getKeyPrefs())) + private final String text; + + getKey(KeyBinding.IMPORT_INTO_CURRENT_DATABASE) private final Optional icon; private final Optional keyBinding; ActionsFX(String text) { - this.text = text; - this.icon = Optional.empty(); - this.keyBinding = Optional.empty(); + this("", ""); } ActionsFX(String text, IconTheme.JabRefIcons icon) { this.text = text; + this.description = ""; this.icon = Optional.of(icon); this.keyBinding = Optional.empty(); } ActionsFX(String text, IconTheme.JabRefIcons icon, KeyBinding keyBinding) { this.text = text; + this.description = ""; this.icon = Optional.of(icon); this.keyBinding = Optional.of(keyBinding); } ActionsFX(String text, KeyBinding keyBinding) { this.text = text; + this.description = ""; this.keyBinding = Optional.of(keyBinding); this.icon = Optional.empty(); } + ActionsFX(String text, String description) { + this.text = text; + this.description = description; + this.icon = Optional.empty(); + this.keyBinding = Optional.empty(); + } + public Optional getIcon() { return icon; } @@ -99,4 +149,8 @@ public Optional getKeyBinding() { public String getText() { return text; } + + public String getDescription() { + return description; + } } diff --git a/src/main/java/org/jabref/gui/actions/JabRefAction.java b/src/main/java/org/jabref/gui/actions/JabRefAction.java index dd99c18044b..7499cba6963 100644 --- a/src/main/java/org/jabref/gui/actions/JabRefAction.java +++ b/src/main/java/org/jabref/gui/actions/JabRefAction.java @@ -16,6 +16,7 @@ public JabRefAction(ActionsFX action, KeyBindingRepository keyBindingRepository) .ifPresent(icon -> setGraphic(icon.getGraphicNode())); action.getKeyBinding() .ifPresent(keyBinding -> setAccelerator(keyBindingRepository.getKeyCombination(keyBinding))); + setLongText(action.getDescription()); } public JabRefAction(ActionsFX action, Command command, KeyBindingRepository keyBindingRepository) { diff --git a/src/main/java/org/jabref/gui/actions/NewDatabaseAction.java b/src/main/java/org/jabref/gui/actions/NewDatabaseAction.java index f546b9ef6e8..90b2f8ced30 100644 --- a/src/main/java/org/jabref/gui/actions/NewDatabaseAction.java +++ b/src/main/java/org/jabref/gui/actions/NewDatabaseAction.java @@ -1,10 +1,5 @@ package org.jabref.gui.actions; -import java.awt.event.ActionEvent; - -import javax.swing.Action; - -import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.logic.l10n.Localization; import org.jabref.model.Defaults; @@ -12,24 +7,20 @@ import org.jabref.model.database.BibDatabaseMode; /** - * The action concerned with opening a new database. + * Create a new, empty, database. */ -public class NewDatabaseAction extends MnemonicAwareAction { +public class NewDatabaseAction extends SimpleCommand { private final JabRefFrame jabRefFrame; private final BibDatabaseMode mode; public NewDatabaseAction(JabRefFrame jabRefFrame, BibDatabaseMode mode) { - super(IconTheme.JabRefIcons.NEW.getIcon()); this.jabRefFrame = jabRefFrame; this.mode = mode; - putValue(Action.NAME, Localization.menuTitle("New %0 library", mode.getFormattedName())); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("New %0 library", mode.getFormattedName())); } @Override - public void actionPerformed(ActionEvent e) { - // Create a new, empty, database. + public void execute() { BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(BibDatabaseMode.BIBTEX)); bibDatabaseContext.setMode(mode); jabRefFrame.addTab(bibDatabaseContext, true); diff --git a/src/main/java/org/jabref/gui/actions/OldDatabaseCommandWrapper.java b/src/main/java/org/jabref/gui/actions/OldDatabaseCommandWrapper.java new file mode 100644 index 00000000000..a752da3ce9c --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/OldDatabaseCommandWrapper.java @@ -0,0 +1,55 @@ +package org.jabref.gui.actions; + +import java.util.Optional; + +import javafx.beans.property.ReadOnlyDoubleProperty; + +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.StateManager; + +import de.saxsys.mvvmfx.utils.commands.CommandBase; +import org.fxmisc.easybind.EasyBind; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A command that is only executable if a database is open. + */ +public class OldDatabaseCommandWrapper extends CommandBase { + + private static final Logger LOGGER = LoggerFactory.getLogger(OldDatabaseCommandWrapper.class); + + private final Actions command; + private final JabRefFrame frame; + + public OldDatabaseCommandWrapper(Actions command, JabRefFrame frame, StateManager stateManager) { + this.command = command; + this.frame = frame; + + this.executable.bind( + EasyBind.map(stateManager.activeDatabaseProperty(), Optional::isPresent)); + } + + @Override + public void execute() { + if (frame.getTabbedPane().getTabs().size() > 0) { + try { + frame.getCurrentBasePanel().runCommand(command); + } catch (Throwable ex) { + LOGGER.error("Problem with executing command: " + command, ex); + } + } else { + LOGGER.info("Action '" + command + "' must be disabled when no database is open."); + } + } + + @Override + public double getProgress() { + return 0; + } + + @Override + public ReadOnlyDoubleProperty progressProperty() { + return null; + } +} diff --git a/src/main/java/org/jabref/gui/actions/SimpleCommand.java b/src/main/java/org/jabref/gui/actions/SimpleCommand.java new file mode 100644 index 00000000000..78b52e7f206 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/SimpleCommand.java @@ -0,0 +1,26 @@ +package org.jabref.gui.actions; + +import javafx.beans.property.ReadOnlyDoubleProperty; + +import org.jabref.gui.util.BindingsHelper; + +import de.saxsys.mvvmfx.utils.commands.CommandBase; + +/** + * A simple command that does not track progress of the action. + */ +public abstract class SimpleCommand extends CommandBase { + @Override + public double getProgress() { + return 0; + } + + @Override + public ReadOnlyDoubleProperty progressProperty() { + return null; + } + + public void setExecutable(boolean executable) { + this.executable.bind(BindingsHelper.constantOf(executable)); + } +} diff --git a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java index 16c8f1ad454..f7268a254d9 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java @@ -1,25 +1,14 @@ package org.jabref.gui.exporter; -import java.awt.event.ActionEvent; - -import javax.swing.Action; - -import org.jabref.Globals; import org.jabref.gui.BasePanel; -import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.gui.actions.Actions; -import org.jabref.gui.actions.MnemonicAwareAction; -import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.gui.actions.SimpleCommand; import org.jabref.logic.l10n.Localization; import spin.Spin; -/** - * - * @author alver - */ -public class SaveAllAction extends MnemonicAwareAction implements Runnable { +public class SaveAllAction extends SimpleCommand implements Runnable { private final JabRefFrame frame; private int databases; @@ -27,15 +16,11 @@ public class SaveAllAction extends MnemonicAwareAction implements Runnable { /** Creates a new instance of SaveAllAction */ public SaveAllAction(JabRefFrame frame) { - super(IconTheme.JabRefIcons.SAVE_ALL.getIcon()); this.frame = frame; - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.SAVE_ALL)); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Save all open libraries")); - putValue(Action.NAME, Localization.menuTitle("Save all")); } @Override - public void actionPerformed(ActionEvent e) { + public void execute() { databases = frame.getBasePanelCount(); frame.output(Localization.lang("Saving all libraries...")); Spin.off(this); diff --git a/src/main/java/org/jabref/gui/groups/EntryTableTransferHandler.java b/src/main/java/org/jabref/gui/groups/EntryTableTransferHandler.java index 460366637b2..2e9771423fa 100644 --- a/src/main/java/org/jabref/gui/groups/EntryTableTransferHandler.java +++ b/src/main/java/org/jabref/gui/groups/EntryTableTransferHandler.java @@ -324,7 +324,7 @@ private boolean handleDraggedFiles(List files, final int dropRow) { */ private void loadOrImportFiles(List fileNames, int dropRow) { - OpenDatabaseAction openAction = new OpenDatabaseAction(frame, false); + OpenDatabaseAction openAction = new OpenDatabaseAction(frame); List notBibFiles = new ArrayList<>(); List bibFiles = new ArrayList<>(); for (String fileName : fileNames) { diff --git a/src/main/java/org/jabref/gui/importer/ImportFormats.java b/src/main/java/org/jabref/gui/importer/ImportFormats.java index fe321b7dc41..b154faa7aab 100644 --- a/src/main/java/org/jabref/gui/importer/ImportFormats.java +++ b/src/main/java/org/jabref/gui/importer/ImportFormats.java @@ -1,6 +1,5 @@ package org.jabref.gui.importer; -import java.awt.event.ActionEvent; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; @@ -9,8 +8,6 @@ import java.util.SortedSet; import java.util.stream.Collectors; -import javax.swing.AbstractAction; -import javax.swing.Action; import javax.swing.JOptionPane; import javafx.stage.FileChooser; @@ -19,8 +16,7 @@ import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; import org.jabref.gui.JabRefFrame; -import org.jabref.gui.actions.MnemonicAwareAction; -import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.FileFilterConverter; @@ -29,10 +25,11 @@ import org.jabref.logic.util.FileType; import org.jabref.preferences.JabRefPreferences; -public class ImportFormats { +import de.saxsys.mvvmfx.utils.commands.CommandBase; +public class ImportFormats extends SimpleCommand { - private ImportFormats() { + public ImportFormats() { } /** @@ -42,27 +39,11 @@ private ImportFormats() { * into the currently open one. * @return The action. */ - public static AbstractAction getImportAction(JabRefFrame frame, boolean openInNew) { - - class ImportAction extends MnemonicAwareAction { - - private final boolean newDatabase; - - public ImportAction(boolean newDatabase) { - this.newDatabase = newDatabase; - - if (newDatabase) { - putValue(Action.NAME, Localization.menuTitle("Import into new library")); - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_NEW_DATABASE)); - } else { - putValue(Action.NAME, Localization.menuTitle("Import into current library")); - putValue(Action.ACCELERATOR_KEY, - Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_CURRENT_DATABASE)); - } - } + public static CommandBase getImportAction(JabRefFrame frame, boolean openInNew) { + return new SimpleCommand() { @Override - public void actionPerformed(ActionEvent e) { + public void execute() { SortedSet importers = Globals.IMPORT_FORMAT_READER.getImportFormats(); List extensions = importers.stream().map(Importer::getFileType) .collect(Collectors.toList()); @@ -88,13 +69,11 @@ private void doImport(Path file, SortedSet importers, FileChooser.Exte return; } Optional format = FileFilterConverter.getImporter(selectedExtensionFilter, importers); - ImportMenuItem importMenu = new ImportMenuItem(frame, newDatabase, format.orElse(null)); + ImportMenuItem importMenu = new ImportMenuItem(frame, openInNew, format.orElse(null)); importMenu.automatedImport(Collections.singletonList(file.toString())); // Set last working dir for import Globals.prefs.put(JabRefPreferences.IMPORT_WORKING_DIRECTORY, file.getParent().toString()); } - } - - return new ImportAction(openInNew); + }; } } 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 96fa5d15222..8cfb8c3568f 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -1,6 +1,5 @@ package org.jabref.gui.importer.actions; -import java.awt.event.ActionEvent; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -14,7 +13,6 @@ import java.util.Optional; import java.util.stream.Collectors; -import javax.swing.Action; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; @@ -24,13 +22,11 @@ import org.jabref.gui.BasePanelPreferences; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; -import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; -import org.jabref.gui.actions.MnemonicAwareAction; +import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.autosaveandbackup.BackupUIManager; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.importer.ParserResultWarningDialog; -import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.shared.SharedDatabaseUIManager; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.FileDialogConfiguration; @@ -45,7 +41,6 @@ import org.jabref.migrations.FileLinksUpgradeWarning; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.shared.DatabaseNotSupportedException; -import org.jabref.model.strings.StringUtil; import org.jabref.preferences.JabRefPreferences; import org.slf4j.Logger; @@ -53,7 +48,7 @@ // The action concerned with opening an existing database. -public class OpenDatabaseAction extends MnemonicAwareAction { +public class OpenDatabaseAction extends SimpleCommand { public static final Logger LOGGER = LoggerFactory.getLogger(OpenDatabaseAction.class); // List of actions that may need to be called after opening the file. Such as @@ -69,16 +64,10 @@ public class OpenDatabaseAction extends MnemonicAwareAction { POST_OPEN_ACTIONS.add(new HandleDuplicateWarnings()); } - private final boolean showDialog; private final JabRefFrame frame; - public OpenDatabaseAction(JabRefFrame frame, boolean showDialog) { - super(IconTheme.JabRefIcons.OPEN.getIcon()); + public OpenDatabaseAction(JabRefFrame frame) { this.frame = frame; - this.showDialog = showDialog; - putValue(Action.NAME, Localization.menuTitle("Open library")); - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.OPEN_DATABASE)); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Open BibTeX library")); } /** @@ -97,25 +86,19 @@ public static void performPostOpenActions(BasePanel panel, ParserResult result) } @Override - public void actionPerformed(ActionEvent e) { + public void execute() { List filesToOpen = new ArrayList<>(); - if (showDialog) { - - DialogService ds = new FXDialogService(); - FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .addExtensionFilter(FileType.BIBTEX_DB) - .withDefaultExtension(FileType.BIBTEX_DB) - .withInitialDirectory(Paths.get(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY))) - .build(); - - List chosenFiles = DefaultTaskExecutor - .runInJavaFXThread(() -> ds.showFileOpenDialogAndGetMultipleFiles(fileDialogConfiguration)); - filesToOpen.addAll(chosenFiles); - } else { - LOGGER.info(Action.NAME + " " + e.getActionCommand()); - filesToOpen.add(Paths.get(StringUtil.getCorrectFileName(e.getActionCommand(), "bib"))); - } + DialogService ds = new FXDialogService(); + FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() + .addExtensionFilter(FileType.BIBTEX_DB) + .withDefaultExtension(FileType.BIBTEX_DB) + .withInitialDirectory(Paths.get(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY))) + .build(); + + List chosenFiles = DefaultTaskExecutor + .runInJavaFXThread(() -> ds.showFileOpenDialogAndGetMultipleFiles(fileDialogConfiguration)); + filesToOpen.addAll(chosenFiles); openFiles(filesToOpen, true); } From a319de75eb9a9d950090085d5dbb4728e31f8297 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 8 Feb 2018 16:22:47 +0100 Subject: [PATCH 049/827] Finish file menu --- src/main/java/org/jabref/gui/BasePanel.java | 36 +++- src/main/java/org/jabref/gui/IconTheme.java | 2 + src/main/java/org/jabref/gui/JabRefFrame.java | 179 ++++++------------ .../java/org/jabref/gui/PreviewPanel.java | 4 +- .../org/jabref/gui/actions/ActionFactory.java | 6 + .../org/jabref/gui/actions/ActionsFX.java | 58 ++---- .../ConnectToSharedDatabaseAction.java | 31 --- .../ConnectToSharedDatabaseCommand.java | 22 +++ .../org/jabref/gui/exporter/ExportAction.java | 172 ----------------- .../jabref/gui/exporter/ExportCommand.java | 149 +++++++++++++++ .../jabref/gui/importer/ImportCommand.java | 76 ++++++++ .../jabref/gui/importer/ImportFormats.java | 79 -------- .../importer/actions/OpenDatabaseAction.java | 3 +- .../org/jabref/gui/menus/FileHistoryMenu.java | 60 ++---- .../org/jabref/logic/l10n/Localization.java | 12 +- 15 files changed, 393 insertions(+), 496 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/actions/ConnectToSharedDatabaseAction.java create mode 100644 src/main/java/org/jabref/gui/actions/ConnectToSharedDatabaseCommand.java delete mode 100644 src/main/java/org/jabref/gui/exporter/ExportAction.java create mode 100644 src/main/java/org/jabref/gui/exporter/ExportCommand.java create mode 100644 src/main/java/org/jabref/gui/importer/ImportCommand.java delete mode 100644 src/main/java/org/jabref/gui/importer/ImportFormats.java diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index a36c2fe08c8..f8321254548 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -87,6 +87,7 @@ import org.jabref.gui.undo.UndoableKeyChange; import org.jabref.gui.undo.UndoableRemoveEntry; import org.jabref.gui.util.DefaultTaskExecutor; +import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.component.CheckBoxMessage; import org.jabref.gui.worker.AbstractWorker; import org.jabref.gui.worker.CallBack; @@ -106,6 +107,7 @@ import org.jabref.logic.layout.LayoutHelper; import org.jabref.logic.pdf.FileAnnotationCache; import org.jabref.logic.search.SearchQuery; +import org.jabref.logic.util.FileType; import org.jabref.logic.util.UpdateField; import org.jabref.logic.util.io.FileFinder; import org.jabref.logic.util.io.FileFinders; @@ -347,10 +349,7 @@ private void setupActions() { actions.put(Actions.SAVE_AS, (BaseAction) saveAction::saveAs); - actions.put(Actions.SAVE_SELECTED_AS, new SaveSelectedAction(SavePreferences.DatabaseSaveType.ALL)); - - actions.put(Actions.SAVE_SELECTED_AS_PLAIN, - new SaveSelectedAction(SavePreferences.DatabaseSaveType.PLAIN_BIBTEX)); + actions.put(Actions.SAVE_SELECTED_AS_PLAIN, new SaveSelectedAction(SavePreferences.DatabaseSaveType.PLAIN_BIBTEX)); // The action for copying selected entries. actions.put(Actions.COPY, (BaseAction) this::copy); @@ -2165,4 +2164,33 @@ public void action() throws Exception { preview.print(); } } + + private class SaveSelectedAction implements BaseAction { + + private final SavePreferences.DatabaseSaveType saveType; + + public SaveSelectedAction(SavePreferences.DatabaseSaveType saveType) { + this.saveType = saveType; + } + + @Override + public void action() throws SaveException { + FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() + .withDefaultExtension(FileType.BIBTEX_DB) + .addExtensionFilter(FileType.BIBTEX_DB) + .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); + + DialogService ds = new FXDialogService(); + + Optional chosenFile = DefaultTaskExecutor + .runInJavaFXThread(() -> ds.showFileSaveDialog(fileDialogConfiguration)); + + if (chosenFile.isPresent()) { + Path path = chosenFile.get(); + saveDatabase(path.toFile(), true, Globals.prefs.getDefaultEncoding(), saveType); + frame.getFileHistory().newFile(path.toString()); + frame.output(Localization.lang("Saved selected to '%0'.", path.toString())); + } + } + } } diff --git a/src/main/java/org/jabref/gui/IconTheme.java b/src/main/java/org/jabref/gui/IconTheme.java index ae6e594bdbd..ded81e4323b 100644 --- a/src/main/java/org/jabref/gui/IconTheme.java +++ b/src/main/java/org/jabref/gui/IconTheme.java @@ -276,6 +276,8 @@ public enum JabRefIcons implements JabRefIcon { DATE_PICKER(MaterialDesignIcon.CALENDAR), /* css: calendar */ DEFAULT_GROUP_ICON(MaterialDesignIcon.LABEL_OUTLINE), /* css: label-outline */ ALL_ENTRIES_GROUP_ICON(DefaultGroupsFactory.ALL_ENTRIES_GROUP_DEFAULT_ICON), + IMPORT_EXPORT(MaterialDesignIcon.SWAP_VERTICAL), + CLOSE_JABREF(MaterialDesignIcon.GLASSDOOR), // STILL MISSING: GROUP_REGULAR(Color.RED, MaterialDesignIcon.SYNC); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index d2a19565c59..36dfffea402 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -17,8 +17,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -31,7 +29,6 @@ import javax.swing.Action; import javax.swing.Icon; import javax.swing.JButton; -import javax.swing.JCheckBoxMenuItem; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JLabel; @@ -56,6 +53,7 @@ import javafx.scene.Scene; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; +import javafx.scene.control.SeparatorMenuItem; import javafx.scene.control.SplitPane; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; @@ -68,10 +66,9 @@ import org.jabref.gui.actions.Actions; import org.jabref.gui.actions.ActionsFX; import org.jabref.gui.actions.AutoLinkFilesAction; -import org.jabref.gui.actions.ConnectToSharedDatabaseAction; +import org.jabref.gui.actions.ConnectToSharedDatabaseCommand; import org.jabref.gui.actions.ErrorConsoleAction; import org.jabref.gui.actions.IntegrityCheckAction; -import org.jabref.gui.actions.LookupIdentifierAction; import org.jabref.gui.actions.ManageKeywordsAction; import org.jabref.gui.actions.MassSetFieldAction; import org.jabref.gui.actions.MnemonicAwareAction; @@ -80,7 +77,7 @@ import org.jabref.gui.actions.NewSubDatabaseAction; import org.jabref.gui.actions.OldDatabaseCommandWrapper; import org.jabref.gui.actions.OpenBrowserAction; -import org.jabref.gui.actions.SearchForUpdateAction; +import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.actions.SortTabsAction; import org.jabref.gui.autosaveandbackup.AutosaveUIManager; import org.jabref.gui.bibtexkeypattern.BibtexKeyPatternDialog; @@ -89,7 +86,7 @@ import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.dbproperties.DatabasePropertiesDialog; import org.jabref.gui.documentviewer.ShowDocumentViewerAction; -import org.jabref.gui.exporter.ExportAction; +import org.jabref.gui.exporter.ExportCommand; import org.jabref.gui.exporter.ExportCustomizationDialog; import org.jabref.gui.exporter.SaveAllAction; import org.jabref.gui.exporter.SaveDatabaseAction; @@ -99,8 +96,8 @@ import org.jabref.gui.groups.GroupSidePane; import org.jabref.gui.help.AboutAction; import org.jabref.gui.help.HelpAction; +import org.jabref.gui.importer.ImportCommand; import org.jabref.gui.importer.ImportCustomizationDialog; -import org.jabref.gui.importer.ImportFormats; import org.jabref.gui.importer.ImportInspectionDialog; import org.jabref.gui.importer.actions.OpenDatabaseAction; import org.jabref.gui.importer.fetcher.GeneralFetcher; @@ -110,7 +107,6 @@ import org.jabref.gui.menus.ChangeEntryTypeMenu; import org.jabref.gui.menus.FileHistoryMenu; import org.jabref.gui.openoffice.OpenOfficePanel; -import org.jabref.gui.openoffice.OpenOfficeSidePanel; import org.jabref.gui.preftabs.PreferencesDialog; import org.jabref.gui.protectedterms.ProtectedTermsDialog; import org.jabref.gui.push.PushToApplicationButton; @@ -119,14 +115,11 @@ import org.jabref.gui.specialfields.SpecialFieldValueViewModel; import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.util.DefaultTaskExecutor; -import org.jabref.gui.worker.MarkEntriesAction; import org.jabref.logic.autosaveandbackup.AutosaveManager; import org.jabref.logic.autosaveandbackup.BackupManager; import org.jabref.logic.help.HelpFile; -import org.jabref.logic.importer.IdFetcher; import org.jabref.logic.importer.OutputPrinter; import org.jabref.logic.importer.ParserResult; -import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.l10n.Localization; import org.jabref.logic.search.SearchQuery; import org.jabref.logic.undo.AddUndoableActionEvent; @@ -175,9 +168,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { + ':', SwingConstants.LEFT); private final JProgressBar progressBar = new JProgressBar(); private final FileHistoryMenu fileHistory = new FileHistoryMenu(prefs, this); - private final OpenDatabaseAction open = new OpenDatabaseAction(this); - private final EditModeAction editModeAction = new EditModeAction(); - // Here we instantiate menu/toolbar actions. Actions regarding // the currently open database are defined as a GeneralAction @@ -185,9 +175,7 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { // BasePanel's runCommand() method to be called with that command. // Note: GeneralAction's constructor automatically gets translations // for the name and message strings. - private final AbstractAction quit = new CloseAction(); private final AbstractAction keyBindingAction = new KeyBindingAction(); - private final AbstractAction connectToSharedDatabaseAction = new ConnectToSharedDatabaseAction(this); private final AbstractAction newSubDatabaseAction = new NewSubDatabaseAction(this); private final AbstractAction jabrefWebPageAction = new OpenBrowserAction("https://jabref.org", Localization.menuTitle("Website"), Localization.lang("Opens JabRef's website"), @@ -222,8 +210,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { private final AbstractAction focusTable = new GeneralAction(Actions.FOCUS_TABLE, Localization.menuTitle("Focus entry table"), Localization.lang("Move the keyboard focus to the entry table"), Globals.getKeyPrefs().getKey(KeyBinding.FOCUS_ENTRY_TABLE)); - private final AbstractAction importCurrent = ImportFormats.getImportAction(this, false); - private final AbstractAction importNew = ImportFormats.getImportAction(this, true); private final AbstractAction sortTabs = new SortTabsAction(this); private final AbstractAction undo = new GeneralAction(Actions.UNDO, Localization.menuTitle("Undo"), Localization.lang("Undo"), Globals.getKeyPrefs().getKey(KeyBinding.UNDO), IconTheme.JabRefIcons.UNDO.getIcon()); @@ -246,11 +232,7 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { Localization.lang("Open terminal here"), Globals.getKeyPrefs().getKey(KeyBinding.OPEN_CONSOLE), IconTheme.JabRefIcons.CONSOLE.getIcon()); - private final AbstractAction pullChangesFromSharedDatabase = new GeneralAction(Actions.PULL_CHANGES_FROM_SHARED_DATABASE, - Localization.menuTitle("Pull changes from shared database"), - Localization.lang("Pull changes from shared database"), - Globals.getKeyPrefs().getKey(KeyBinding.PULL_CHANGES_FROM_SHARED_DATABASE), - IconTheme.JabRefIcons.PULL.getIcon()); + private final AbstractAction mark = new GeneralAction(Actions.MARK_ENTRIES, Localization.menuTitle("Mark entries"), Localization.lang("Mark entries"), Globals.getKeyPrefs().getKey(KeyBinding.MARK_ENTRIES), IconTheme.JabRefIcons.MARK_ENTRIES.getIcon()); private final JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color")); @@ -418,7 +400,6 @@ public void actionPerformed(ActionEvent e) { private final NewEntryAction newEntryAction = new NewEntryAction(this, Globals.getKeyPrefs().getKey(KeyBinding.NEW_ENTRY)); private final List newSpecificEntryAction = getNewEntryActions(); // The action for closing the current database and leaving the window open. - private final CloseDatabaseAction closeDatabaseAction = new CloseDatabaseAction(); private final CloseAllDatabasesAction closeAllDatabasesAction = new CloseAllDatabasesAction(); private final CloseOtherDatabasesAction closeOtherDatabasesAction = new CloseOtherDatabasesAction(); // The action for opening the preferences dialog. @@ -439,8 +420,6 @@ public void actionPerformed(ActionEvent e) { // The sidepane manager takes care of populating the sidepane. private SidePaneManager sidePaneManager; private final TabPane tabbedPane = new TabPane(); - private final AbstractAction exportAll = ExportAction.getExportAction(this, false); - private final AbstractAction exportSelected = ExportAction.getExportAction(this, true); /* References to the toggle buttons in the toolbar */ private JToggleButton previewToggle; private JMenu rankSubMenu; @@ -525,7 +504,7 @@ private JPopupMenu tabPopupMenu() { JMenuItem close = new JMenuItem(Localization.lang("Close")); JMenuItem closeOthers = new JMenuItem(Localization.lang("Close others")); JMenuItem closeAll = new JMenuItem(Localization.lang("Close all")); - close.addActionListener(closeDatabaseAction); + //close.addActionListener(closeDatabaseAction); closeOthers.addActionListener(closeOtherDatabasesAction); closeAll.addActionListener(closeAllDatabasesAction); popupMenu.add(close); @@ -601,14 +580,13 @@ private void init() { currentBasePanel.getPreviewPanel().updateLayout(Globals.prefs.getPreviewPreferences()); - groupSidePane.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class)); - previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); - generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class)); - openOfficePanel.getToggleAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class)); + // groupSidePane.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class)); + //previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); + //generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class)); + //openOfficePanel.getToggleAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class)); // TODO: Can't notify focus listener since it is expecting a swing component //Globals.getFocusListener().setFocused(currentBasePanel.getMainTable()); setWindowTitle(); - editModeAction.initName(); // Update search autocompleter with information for the correct database: currentBasePanel.updateSearchManager(); // Set correct enabled state for Back and Forward actions: @@ -1028,7 +1006,6 @@ private MenuBar createMenu() { Menu view = new Menu(Localization.menuTitle("View")); Menu tools = new Menu(Localization.menuTitle("Tools")); Menu options = new Menu(Localization.menuTitle("Options")); - newSpec = JabRefFrame.subMenu(Localization.menuTitle("New entry by type...")); Menu help = new Menu(Localization.menuTitle("Help")); file.getItems().addAll( @@ -1037,38 +1014,34 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.OPEN_LIBRARY, getOpenDatabaseAction()), factory.createMenuItem(ActionsFX.save, new OldDatabaseCommandWrapper(Actions.SAVE, this, Globals.stateManager)), factory.createMenuItem(ActionsFX.saveAs, new OldDatabaseCommandWrapper(Actions.SAVE_AS, this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.saveAll, new SaveAllAction(this), + factory.createMenuItem(ActionsFX.saveAll, new SaveAllAction(this)), + factory.createSubMenu(ActionsFX.import_export, factory.createMenuItem(ActionsFX.mergeDatabaseAction, new OldDatabaseCommandWrapper(Actions.MERGE_DATABASE, this, Globals.stateManager)), // TODO: merge with import - factory.createMenuItem(ActionsFX.saveSelectedAsPlain, new OldDatabaseCommandWrapper(Actions.SAVE_SELECTED_AS_PLAIN, this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.importNew, new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.importCurrent, new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), - factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), - factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), - factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), - - file.add(importNew), - file.add(importCurrent), - file.add(exportAll), - file.add(exportSelected), - file.add(exportLinkedFiles), - file.addSeparator(), - file.add(connectToSharedDatabaseAction), - file.add(pullChangesFromSharedDatabase), - - file.addSeparator(), - file.add(databaseProperties), - file.add(editModeAction), - file.addSeparator(), - - file.add(fileHistory), - file.addSeparator(), - file.add(closeDatabaseAction), - file.add(quit) - ); - - - mb.add(file); + factory.createMenuItem(ActionsFX.importCurrent, new ImportCommand(this, true)), + factory.createMenuItem(ActionsFX.importNew, new ImportCommand(this, false)), + factory.createMenuItem(ActionsFX.exportAll, new ExportCommand(this, false)), + factory.createMenuItem(ActionsFX.exportSelected, new ExportCommand(this, true)), + factory.createMenuItem(ActionsFX.saveSelectedAsPlain, new OldDatabaseCommandWrapper(Actions.SAVE_SELECTED_AS_PLAIN, this, Globals.stateManager)) + ), + + new SeparatorMenuItem(), + + factory.createMenuItem(ActionsFX.connectToSharedDatabaseAction, new ConnectToSharedDatabaseCommand(this)), + factory.createMenuItem(ActionsFX.pullChangesFromSharedDatabase, new OldDatabaseCommandWrapper(Actions.PULL_CHANGES_FROM_SHARED_DATABASE, this, Globals.stateManager)), + + new SeparatorMenuItem(), + + fileHistory, + + new SeparatorMenuItem(), + + factory.createMenuItem(ActionsFX.closeDatabaseAction, new CloseDatabaseAction()), + factory.createMenuItem(ActionsFX.quit, new CloseAction()) + ); + + /* + factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), edit.add(undo); edit.add(redo); @@ -1201,6 +1174,8 @@ private MenuBar createMenu() { library.add(customizeAction); library.addSeparator(); library.add(deleteEntry); + library.add(databaseProperties), + newSpec = JabRefFrame.subMenu(Localization.menuTitle("New entry by type...")); mb.add(library); quality.add(dupliCheck); @@ -1233,6 +1208,8 @@ private MenuBar createMenu() { tools.add(openUrl); tools.add(openConsole); tools.addSeparator(); + file.add(exportLinkedFiles), + tools.add(abbreviateIso); tools.add(abbreviateMedline); tools.add(unabbreviate); @@ -1274,9 +1251,19 @@ private MenuBar createMenu() { mb.add(help); createDisabledIconsForMenuEntries(mb); + */ MenuBar menu = new MenuBar(); - menu.getMenus().addAll(fileMenu, editMenu); + menu.getMenus().addAll( + file, + edit, + library, + quality, + view, + tools, + options, + help + ); return menu; } @@ -1406,9 +1393,10 @@ public void output(final String s) { } private void initActions() { + /* openDatabaseOnlyActions.clear(); openDatabaseOnlyActions.addAll(Arrays.asList(manageSelectors, mergeDatabaseAction, newSubDatabaseAction, save, copyPreview, - saveAs, saveSelectedAs, saveSelectedAsPlain, editModeAction, undo, redo, cut, deleteEntry, copy, paste, mark, markSpecific, unmark, + saveAs, saveSelectedAs, saveSelectedAsPlain, undo, redo, cut, deleteEntry, copy, paste, mark, markSpecific, unmark, unmarkAll, rankSubMenu, editEntry, selectAll, copyKey, copyCiteKey, copyKeyAndTitle, copyKeyAndLink, editPreamble, editStrings, groupSidePane.getToggleAction(), makeKeyAction, normalSearch, generalFetcher.getToggleAction(), mergeEntries, cleanupEntries, exportToClipboard, replaceAll, sendAsEmail, downloadFullText, lookupIdentifiers, writeXmpAction, openOfficePanel.getToggleAction(), findUnlinkedFiles, addToGroup, removeFromGroup, @@ -1447,6 +1435,7 @@ dupliCheck, autoSetFile, newEntryAction, newSpec, customizeAction, plainTextImpo atLeastOneEntryActions.addAll(Arrays.asList(downloadFullText, lookupIdentifiers, exportLinkedFiles)); tabbedPane.getTabs().addListener(this::updateEnabledState); + */ } /** @@ -1912,7 +1901,7 @@ public MassSetFieldAction getMassSetField() { } public OpenDatabaseAction getOpenDatabaseAction() { - return open; + return new OpenDatabaseAction(this); } public String getStatusLineText() { @@ -1982,41 +1971,6 @@ public boolean isOpaque() { } } - private class EditModeAction extends AbstractAction { - - public EditModeAction() { - initName(); - } - - public void initName() { - if (JabRefFrame.this.getCurrentBasePanel() == null) { - putValue(Action.NAME, Localization.menuTitle("Switch to %0 mode", "BibTeX/biblatex")); - } else { - BibDatabaseMode mode = JabRefFrame.this.getCurrentBasePanel().getBibDatabaseContext().getMode(); - String modeName = mode.getOppositeMode().getFormattedName(); - putValue(Action.NAME, Localization.menuTitle("Switch to %0 mode", modeName)); - } - } - - @Override - public void actionPerformed(ActionEvent evt) { - if (JabRefFrame.this.getCurrentBasePanel() == null) { - return; - } - - BibDatabaseMode newMode = JabRefFrame.this.getCurrentBasePanel().getBibDatabaseContext().getMode() - .getOppositeMode(); - JabRefFrame.this.getCurrentBasePanel().getBibDatabaseContext().setMode(newMode); - JabRefFrame.this.refreshTitleAndTabs(); - - initName(); - - // update all elements in current base panel - JabRefFrame.this.getCurrentBasePanel().closeBottomPane(); - JabRefFrame.this.getCurrentBasePanel().updateEntryEditorIfShowing(); - } - } - private class GeneralAction extends MnemonicAwareAction { private final Actions command; @@ -2086,16 +2040,10 @@ public void actionPerformed(ActionEvent e) { /** * The action concerned with closing the window. */ - private class CloseAction extends MnemonicAwareAction { - - public CloseAction() { - putValue(Action.NAME, Localization.menuTitle("Quit")); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Quit JabRef")); - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.QUIT_JABREF)); - } + private class CloseAction extends SimpleCommand { @Override - public void actionPerformed(ActionEvent e) { + public void execute() { quit(); Platform.exit(); } @@ -2332,17 +2280,10 @@ public void actionPerformed(ActionEvent event) { } } - private class CloseDatabaseAction extends MnemonicAwareAction { - - public CloseDatabaseAction() { - super(IconTheme.JabRefIcons.CLOSE.getSmallIcon()); - putValue(Action.NAME, Localization.menuTitle("Close library")); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Close the current library")); - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DATABASE)); - } + private class CloseDatabaseAction extends SimpleCommand { @Override - public void actionPerformed(ActionEvent e) { + public void execute() { closeTab(getCurrentBasePanel()); } } diff --git a/src/main/java/org/jabref/gui/PreviewPanel.java b/src/main/java/org/jabref/gui/PreviewPanel.java index f803bcf814e..1307ffb01bd 100644 --- a/src/main/java/org/jabref/gui/PreviewPanel.java +++ b/src/main/java/org/jabref/gui/PreviewPanel.java @@ -128,10 +128,10 @@ private ContextMenu createPopupMenu() { copyPreview.setOnAction(event -> copyPreviewToClipBoard()); MenuItem printEntryPreview = new MenuItem(Localization.lang("Print entry preview"), IconTheme.JabRefIcons.PRINTED.getGraphicNode()); printEntryPreview.setOnAction(event -> print()); - MenuItem previousPreviewLayout = new MenuItem(Localization.menuTitleFX("Previous preview layout")); + MenuItem previousPreviewLayout = new MenuItem(Localization.menuTitle("Previous preview layout")); previousPreviewLayout.setAccelerator(keyBindingRepository.getKeyCombination(KeyBinding.PREVIOUS_PREVIEW_LAYOUT)); previousPreviewLayout.setOnAction(event -> basePanel.ifPresent(BasePanel::previousPreviewStyle)); - MenuItem nextPreviewLayout = new MenuItem(Localization.menuTitleFX("Next preview layout")); + MenuItem nextPreviewLayout = new MenuItem(Localization.menuTitle("Next preview layout")); nextPreviewLayout.setAccelerator(keyBindingRepository.getKeyCombination(KeyBinding.NEXT_PREVIEW_LAYOUT)); nextPreviewLayout.setOnAction(event -> basePanel.ifPresent(BasePanel::nextPreviewStyle)); diff --git a/src/main/java/org/jabref/gui/actions/ActionFactory.java b/src/main/java/org/jabref/gui/actions/ActionFactory.java index e8374353d20..a19d1c7ec0a 100644 --- a/src/main/java/org/jabref/gui/actions/ActionFactory.java +++ b/src/main/java/org/jabref/gui/actions/ActionFactory.java @@ -42,4 +42,10 @@ public Menu createMenu(ActionsFX action) { action.getIcon().ifPresent(icon -> menu.setGraphic(icon.getGraphicNode())); return menu; } + + public Menu createSubMenu(ActionsFX action, MenuItem... children) { + Menu menu = createMenu(action); + menu.getItems().addAll(children); + return menu; + } } diff --git a/src/main/java/org/jabref/gui/actions/ActionsFX.java b/src/main/java/org/jabref/gui/actions/ActionsFX.java index ad8e9ec6d78..98874db4352 100644 --- a/src/main/java/org/jabref/gui/actions/ActionsFX.java +++ b/src/main/java/org/jabref/gui/actions/ActionsFX.java @@ -2,12 +2,7 @@ import java.util.Optional; -import javax.swing.AbstractAction; -import javax.swing.Action; - -import org.jabref.Globals; import org.jabref.gui.IconTheme; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.JabRefIcon; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.l10n.Localization; @@ -68,46 +63,28 @@ public enum ActionsFX { NEW_LIBRARY_BIBTEX(Localization.menuTitle("New %0 library", BibDatabaseMode.BIBTEX.getFormattedName()), IconTheme.JabRefIcons.NEW), NEW_LIBRARY_BIBLATEX(Localization.menuTitle("New %0 library", BibDatabaseMode.BIBLATEX.getFormattedName()), IconTheme.JabRefIcons.NEW), OPEN_LIBRARY(Localization.menuTitle("Open library"), IconTheme.JabRefIcons.OPEN, KeyBinding.OPEN_DATABASE), + import_export(Localization.lang("Import & Export"), IconTheme.JabRefIcons.IMPORT_EXPORT), mergeDatabaseAction(Localization.menuTitle("Append library"), Localization.lang("Append contents from a BibTeX library into the currently viewed library")), save(Localization.menuTitle("Save library"), IconTheme.JabRefIcons.SAVE, KeyBinding.SAVE_DATABASE), - private final AbstractAction saveAs = new JabRefFrame.GeneralAction(Actions.SAVE_AS, - Localization.menuTitle("Save library as..."), Localization.lang("Save library as..."), - Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE_AS)); - private final AbstractAction saveSelectedAsPlain = new JabRefFrame.GeneralAction(Actions.SAVE_SELECTED_AS_PLAIN, - Localization.menuTitle("Save selected as plain BibTeX..."), - Localization.lang("Save selected as plain BibTeX..."));) - private final String description;. - - saveAll(super(IconTheme.JabRefIcons.SAVE_ALL.getIcon()) - - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs()) - - getKey(KeyBinding.SAVE_ALL))) - - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Save all open libraries") - - putValue(Action.NAME, Localization.menuTitle("Save all")) - - importNew(putValue(Action.NAME, Localization.menuTitle("Import into new library"). - - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs())) - - getKey(KeyBinding.IMPORT_INTO_NEW_DATABASE)) - - importCurrent(putValue(Action.NAME, Localization.menuTitle("Import into current library"). - - putValue(Action.ACCELERATOR_KEY, - Globals.getKeyPrefs())) - + saveAs(Localization.lang("Save library as..."), KeyBinding.SAVE_DATABASE_AS), + saveSelectedAsPlain(Localization.lang("Save selected as plain BibTeX...")), + saveAll(Localization.menuTitle("Save all"), Localization.lang("Save all open libraries"), IconTheme.JabRefIcons.SAVE_ALL, KeyBinding.SAVE_ALL), + importNew(Localization.menuTitle("Import into new library"), KeyBinding.IMPORT_INTO_NEW_DATABASE), + importCurrent(Localization.menuTitle("Import into current library"), KeyBinding.IMPORT_INTO_CURRENT_DATABASE), + exportAll(Localization.menuTitle("Export")), + exportSelected(Localization.menuTitle("Export selected entries")), + connectToSharedDatabaseAction(Localization.lang("Connect to shared database")), + pullChangesFromSharedDatabase(Localization.menuTitle("Pull changes from shared database"), IconTheme.JabRefIcons.PULL, KeyBinding.PULL_CHANGES_FROM_SHARED_DATABASE), + closeDatabaseAction(Localization.menuTitle("Close library"), Localization.lang("Close the current library"), IconTheme.JabRefIcons.CLOSE, KeyBinding.CLOSE_DATABASE), + quit(Localization.menuTitle("Quit"), Localization.lang("Quit JabRef"), IconTheme.JabRefIcons.CLOSE_JABREF, KeyBinding.QUIT_JABREF); private final String text; - - getKey(KeyBinding.IMPORT_INTO_CURRENT_DATABASE) + private final String description; private final Optional icon; private final Optional keyBinding; ActionsFX(String text) { - this("", ""); + this(text, ""); } ActionsFX(String text, IconTheme.JabRefIcons icon) { @@ -124,6 +101,13 @@ public enum ActionsFX { this.keyBinding = Optional.of(keyBinding); } + ActionsFX(String text, String description, IconTheme.JabRefIcons icon, KeyBinding keyBinding) { + this.text = text; + this.description = description; + this.icon = Optional.of(icon); + this.keyBinding = Optional.of(keyBinding); + } + ActionsFX(String text, KeyBinding keyBinding) { this.text = text; this.description = ""; diff --git a/src/main/java/org/jabref/gui/actions/ConnectToSharedDatabaseAction.java b/src/main/java/org/jabref/gui/actions/ConnectToSharedDatabaseAction.java deleted file mode 100644 index 1e3f46ec437..00000000000 --- a/src/main/java/org/jabref/gui/actions/ConnectToSharedDatabaseAction.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.jabref.gui.actions; - -import java.awt.event.ActionEvent; - -import javax.swing.Action; - -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.shared.ConnectToSharedDatabaseDialog; -import org.jabref.logic.l10n.Localization; - -/** - * The action concerned with opening a shared database. - */ -public class ConnectToSharedDatabaseAction extends MnemonicAwareAction { - - private final JabRefFrame jabRefFrame; - - - public ConnectToSharedDatabaseAction(JabRefFrame jabRefFrame) { - super(); - this.jabRefFrame = jabRefFrame; - putValue(Action.NAME, Localization.menuTitle("Connect to shared database")); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Connect to shared database")); - } - - @Override - public void actionPerformed(ActionEvent e) { - ConnectToSharedDatabaseDialog connectToSharedDatabaseDialog = new ConnectToSharedDatabaseDialog(jabRefFrame); - connectToSharedDatabaseDialog.setVisible(true); - } -} diff --git a/src/main/java/org/jabref/gui/actions/ConnectToSharedDatabaseCommand.java b/src/main/java/org/jabref/gui/actions/ConnectToSharedDatabaseCommand.java new file mode 100644 index 00000000000..d31b3382c95 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/ConnectToSharedDatabaseCommand.java @@ -0,0 +1,22 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.shared.ConnectToSharedDatabaseDialog; + +/** + * Opens a shared database. + */ +public class ConnectToSharedDatabaseCommand extends SimpleCommand { + + private final JabRefFrame jabRefFrame; + + public ConnectToSharedDatabaseCommand(JabRefFrame jabRefFrame) { + this.jabRefFrame = jabRefFrame; + } + + @Override + public void execute() { + ConnectToSharedDatabaseDialog connectToSharedDatabaseDialog = new ConnectToSharedDatabaseDialog(jabRefFrame); + connectToSharedDatabaseDialog.setVisible(true); + } +} diff --git a/src/main/java/org/jabref/gui/exporter/ExportAction.java b/src/main/java/org/jabref/gui/exporter/ExportAction.java deleted file mode 100644 index 775a9f039d6..00000000000 --- a/src/main/java/org/jabref/gui/exporter/ExportAction.java +++ /dev/null @@ -1,172 +0,0 @@ -package org.jabref.gui.exporter; - -import java.awt.event.ActionEvent; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.stream.Collectors; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JOptionPane; - -import javafx.stage.FileChooser; - -import org.jabref.Globals; -import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.actions.MnemonicAwareAction; -import org.jabref.gui.util.DefaultTaskExecutor; -import org.jabref.gui.util.FileDialogConfiguration; -import org.jabref.gui.util.FileFilterConverter; -import org.jabref.gui.worker.AbstractWorker; -import org.jabref.logic.exporter.Exporter; -import org.jabref.logic.exporter.ExporterFactory; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.util.FileType; -import org.jabref.logic.util.io.FileUtil; -import org.jabref.model.entry.BibEntry; -import org.jabref.preferences.JabRefPreferences; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ExportAction { - - private static final Logger LOGGER = LoggerFactory.getLogger(ExportAction.class); - - private ExportAction() { - } - - - /** - * Create an AbstractAction for performing an export operation. - * - * @param frame - * The JabRefFrame of this JabRef instance. - * @param selectedOnly - * true indicates that only selected entries should be exported, - * false indicates that all entries should be exported. - * @return The action. - */ - public static AbstractAction getExportAction(JabRefFrame frame, boolean selectedOnly) { - - class InternalExportAction extends MnemonicAwareAction { - - private final JabRefFrame frame; - - private final boolean selectedOnly; - - public InternalExportAction(JabRefFrame frame, boolean selectedOnly) { - this.frame = frame; - this.selectedOnly = selectedOnly; - putValue(Action.NAME, selectedOnly ? Localization.menuTitle("Export selected entries") : Localization - .menuTitle("Export")); - } - - @Override - public void actionPerformed(ActionEvent e) { - Globals.exportFactory = ExporterFactory.create(Globals.prefs, Globals.journalAbbreviationLoader); - FileDialogConfiguration fileDialogConfiguration = ExportAction.createExportFileChooser(Globals.exportFactory, Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY)); - DialogService dialogService = new FXDialogService(); - DefaultTaskExecutor.runInJavaFXThread(() -> - dialogService.showFileSaveDialog(fileDialogConfiguration) - .ifPresent(path -> export(path, fileDialogConfiguration.getSelectedExtensionFilter(), Globals.exportFactory.getExporters()))); - } - - private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilter, List exporters) { - String selectedExtension = selectedExtensionFilter.getExtensions().get(0).replace("*", ""); - if (!file.endsWith(selectedExtension)) { - FileUtil.addExtension(file, selectedExtension); - } - - if (Files.exists(file)) { - // Warn that the file exists: - if (JOptionPane.showConfirmDialog(null, - Localization.lang("'%0' exists. Overwrite file?", file.getFileName().toString()), - Localization.lang("Export"), JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) { - return; - } - } - final Exporter format = FileFilterConverter.getExporter(selectedExtensionFilter, exporters).orElseThrow(() -> new IllegalStateException("User didn't selected a file type for the extension")); - List entries; - if (selectedOnly) { - // Selected entries - entries = frame.getCurrentBasePanel().getSelectedEntries(); - } else { - // All entries - entries = frame.getCurrentBasePanel().getDatabase().getEntries(); - } - - // Set the global variable for this database's file directory before exporting, - // so formatters can resolve linked files correctly. - // (This is an ugly hack!) - Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext() - .getFileDirectories(Globals.prefs.getFileDirectoryPreferences()); - - // Make sure we remember which filter was used, to set - // the default for next time: - Globals.prefs.put(JabRefPreferences.LAST_USED_EXPORT, format.getId()); - Globals.prefs.put(JabRefPreferences.EXPORT_WORKING_DIRECTORY, file.getParent().getFileName().toString()); - - final List finEntries = entries; - AbstractWorker exportWorker = new AbstractWorker() { - - String errorMessage; - - @Override - public void run() { - try { - format.export(frame.getCurrentBasePanel().getBibDatabaseContext(), - file, - frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getEncoding() - .orElse(Globals.prefs.getDefaultEncoding()), - finEntries); - } catch (Exception ex) { - LOGGER.warn("Problem exporting", ex); - if (ex.getMessage() == null) { - errorMessage = ex.toString(); - } else { - errorMessage = ex.getMessage(); - } - } - } - - @Override - public void update() { - // No error message. Report success: - if (errorMessage == null) { - frame.output(Localization.lang("%0 export successful", format.getDisplayName())); - } - // ... or show an error dialog: - else { - frame.output(Localization.lang("Could not save file.") + " - " + errorMessage); - // Need to warn the user that saving failed! - JOptionPane.showMessageDialog(null, - Localization.lang("Could not save file.") + "\n" + errorMessage, - Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE); - } - } - }; - - // Run the export action in a background thread: - exportWorker.getWorker().run(); - // Run the update method: - exportWorker.update(); - } - } - - return new InternalExportAction(frame, selectedOnly); - } - - private static FileDialogConfiguration createExportFileChooser(ExporterFactory exportFactory, String currentDir) { - List fileTypes = exportFactory.getExporters().stream().map(Exporter::getFileType).collect(Collectors.toList()); - return new FileDialogConfiguration.Builder() - .addExtensionFilters(fileTypes) - .withDefaultExtension(Globals.prefs.get(JabRefPreferences.LAST_USED_EXPORT)) - .withInitialDirectory(currentDir) - .build(); - } - -} diff --git a/src/main/java/org/jabref/gui/exporter/ExportCommand.java b/src/main/java/org/jabref/gui/exporter/ExportCommand.java new file mode 100644 index 00000000000..a1761a08613 --- /dev/null +++ b/src/main/java/org/jabref/gui/exporter/ExportCommand.java @@ -0,0 +1,149 @@ +package org.jabref.gui.exporter; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Collectors; + +import javax.swing.JOptionPane; + +import javafx.stage.FileChooser; + +import org.jabref.Globals; +import org.jabref.gui.DialogService; +import org.jabref.gui.FXDialogService; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.actions.SimpleCommand; +import org.jabref.gui.util.DefaultTaskExecutor; +import org.jabref.gui.util.FileDialogConfiguration; +import org.jabref.gui.util.FileFilterConverter; +import org.jabref.gui.worker.AbstractWorker; +import org.jabref.logic.exporter.Exporter; +import org.jabref.logic.exporter.ExporterFactory; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.io.FileUtil; +import org.jabref.model.entry.BibEntry; +import org.jabref.preferences.JabRefPreferences; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Performs an export action + */ +public class ExportCommand extends SimpleCommand { + + private static final Logger LOGGER = LoggerFactory.getLogger(ExportCommand.class); + private final JabRefFrame frame; + private final boolean selectedOnly; + + /** + * @param selectedOnly true if only the selected entries should be exported, otherwise all entries are exported + */ + public ExportCommand(JabRefFrame frame, boolean selectedOnly) { + this.frame = frame; + this.selectedOnly = selectedOnly; + } + + @Override + public void execute() { + Globals.exportFactory = ExporterFactory.create(Globals.prefs, Globals.journalAbbreviationLoader); + FileDialogConfiguration fileDialogConfiguration = createExportFileChooser(Globals.exportFactory, Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY)); + DialogService dialogService = new FXDialogService(); + DefaultTaskExecutor.runInJavaFXThread(() -> + dialogService.showFileSaveDialog(fileDialogConfiguration) + .ifPresent(path -> export(path, fileDialogConfiguration.getSelectedExtensionFilter(), Globals.exportFactory.getExporters()))); + } + + private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilter, List exporters) { + String selectedExtension = selectedExtensionFilter.getExtensions().get(0).replace("*", ""); + if (!file.endsWith(selectedExtension)) { + FileUtil.addExtension(file, selectedExtension); + } + + if (Files.exists(file)) { + // Warn that the file exists: + if (JOptionPane.showConfirmDialog(null, + Localization.lang("'%0' exists. Overwrite file?", file.getFileName().toString()), + Localization.lang("Export"), JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) { + return; + } + } + final Exporter format = FileFilterConverter.getExporter(selectedExtensionFilter, exporters).orElseThrow(() -> new IllegalStateException("User didn't selected a file type for the extension")); + List entries; + if (selectedOnly) { + // Selected entries + entries = frame.getCurrentBasePanel().getSelectedEntries(); + } else { + // All entries + entries = frame.getCurrentBasePanel().getDatabase().getEntries(); + } + + // Set the global variable for this database's file directory before exporting, + // so formatters can resolve linked files correctly. + // (This is an ugly hack!) + Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext() + .getFileDirectories(Globals.prefs.getFileDirectoryPreferences()); + + // Make sure we remember which filter was used, to set + // the default for next time: + Globals.prefs.put(JabRefPreferences.LAST_USED_EXPORT, format.getId()); + Globals.prefs.put(JabRefPreferences.EXPORT_WORKING_DIRECTORY, file.getParent().getFileName().toString()); + + final List finEntries = entries; + AbstractWorker exportWorker = new AbstractWorker() { + + String errorMessage; + + @Override + public void run() { + try { + format.export(frame.getCurrentBasePanel().getBibDatabaseContext(), + file, + frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getEncoding() + .orElse(Globals.prefs.getDefaultEncoding()), + finEntries); + } catch (Exception ex) { + LOGGER.warn("Problem exporting", ex); + if (ex.getMessage() == null) { + errorMessage = ex.toString(); + } else { + errorMessage = ex.getMessage(); + } + } + } + + @Override + public void update() { + // No error message. Report success: + if (errorMessage == null) { + frame.output(Localization.lang("%0 export successful", format.getDisplayName())); + } + // ... or show an error dialog: + else { + frame.output(Localization.lang("Could not save file.") + " - " + errorMessage); + // Need to warn the user that saving failed! + JOptionPane.showMessageDialog(null, + Localization.lang("Could not save file.") + "\n" + errorMessage, + Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE); + } + } + }; + + // Run the export action in a background thread: + exportWorker.getWorker().run(); + // Run the update method: + exportWorker.update(); + } + + private static FileDialogConfiguration createExportFileChooser(ExporterFactory exportFactory, String currentDir) { + List fileTypes = exportFactory.getExporters().stream().map(Exporter::getFileType).collect(Collectors.toList()); + return new FileDialogConfiguration.Builder() + .addExtensionFilters(fileTypes) + .withDefaultExtension(Globals.prefs.get(JabRefPreferences.LAST_USED_EXPORT)) + .withInitialDirectory(currentDir) + .build(); + } + +} diff --git a/src/main/java/org/jabref/gui/importer/ImportCommand.java b/src/main/java/org/jabref/gui/importer/ImportCommand.java new file mode 100644 index 00000000000..2855f73f80e --- /dev/null +++ b/src/main/java/org/jabref/gui/importer/ImportCommand.java @@ -0,0 +1,76 @@ +package org.jabref.gui.importer; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.SortedSet; +import java.util.stream.Collectors; + +import javax.swing.JOptionPane; + +import javafx.stage.FileChooser; + +import org.jabref.Globals; +import org.jabref.gui.DialogService; +import org.jabref.gui.FXDialogService; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.actions.SimpleCommand; +import org.jabref.gui.util.DefaultTaskExecutor; +import org.jabref.gui.util.FileDialogConfiguration; +import org.jabref.gui.util.FileFilterConverter; +import org.jabref.logic.importer.Importer; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.preferences.JabRefPreferences; + +/** + * Perform import operation + */ +public class ImportCommand extends SimpleCommand { + + private final JabRefFrame frame; + private final boolean openInNew; + + /** + * @param openInNew Indicate whether the entries should import into a new database or into the currently open one. + */ + public ImportCommand(JabRefFrame frame, boolean openInNew) { + this.frame = frame; + this.openInNew = openInNew; + } + + @Override + public void execute() { + SortedSet importers = Globals.IMPORT_FORMAT_READER.getImportFormats(); + List extensions = importers.stream().map(Importer::getFileType) + .collect(Collectors.toList()); + FileChooser.ExtensionFilter allImports = FileFilterConverter.forAllImporters(importers); + + FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() + .addExtensionFilter(allImports) + .addExtensionFilters(extensions) + .withInitialDirectory(Globals.prefs.get(JabRefPreferences.IMPORT_WORKING_DIRECTORY)) + .build(); + DialogService dialogService = new FXDialogService(); + DefaultTaskExecutor.runInJavaFXThread(() -> { + dialogService.showFileOpenDialog(fileDialogConfiguration) + .ifPresent(path -> doImport(path, importers, fileDialogConfiguration.getSelectedExtensionFilter())); + }); + } + + private void doImport(Path file, SortedSet importers, FileChooser.ExtensionFilter selectedExtensionFilter) { + if (!Files.exists(file)) { + JOptionPane.showMessageDialog(null, + Localization.lang("File not found") + ": '" + file.getFileName() + "'.", + Localization.lang("Import"), JOptionPane.ERROR_MESSAGE); + return; + } + Optional format = FileFilterConverter.getImporter(selectedExtensionFilter, importers); + ImportMenuItem importMenu = new ImportMenuItem(frame, openInNew, format.orElse(null)); + importMenu.automatedImport(Collections.singletonList(file.toString())); + // Set last working dir for import + Globals.prefs.put(JabRefPreferences.IMPORT_WORKING_DIRECTORY, file.getParent().toString()); + } +} diff --git a/src/main/java/org/jabref/gui/importer/ImportFormats.java b/src/main/java/org/jabref/gui/importer/ImportFormats.java deleted file mode 100644 index b154faa7aab..00000000000 --- a/src/main/java/org/jabref/gui/importer/ImportFormats.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.jabref.gui.importer; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.SortedSet; -import java.util.stream.Collectors; - -import javax.swing.JOptionPane; - -import javafx.stage.FileChooser; - -import org.jabref.Globals; -import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.actions.SimpleCommand; -import org.jabref.gui.util.DefaultTaskExecutor; -import org.jabref.gui.util.FileDialogConfiguration; -import org.jabref.gui.util.FileFilterConverter; -import org.jabref.logic.importer.Importer; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.util.FileType; -import org.jabref.preferences.JabRefPreferences; - -import de.saxsys.mvvmfx.utils.commands.CommandBase; - -public class ImportFormats extends SimpleCommand { - - public ImportFormats() { - } - - /** - * Create an AbstractAction for performing an Import operation. - * @param frame The JabRefFrame of this JabRef instance. - * @param openInNew Indicate whether the action should open into a new database or - * into the currently open one. - * @return The action. - */ - public static CommandBase getImportAction(JabRefFrame frame, boolean openInNew) { - - return new SimpleCommand() { - @Override - public void execute() { - SortedSet importers = Globals.IMPORT_FORMAT_READER.getImportFormats(); - List extensions = importers.stream().map(Importer::getFileType) - .collect(Collectors.toList()); - FileChooser.ExtensionFilter allImports = FileFilterConverter.forAllImporters(importers); - - FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .addExtensionFilter(allImports) - .addExtensionFilters(extensions) - .withInitialDirectory(Globals.prefs.get(JabRefPreferences.IMPORT_WORKING_DIRECTORY)) - .build(); - DialogService dialogService = new FXDialogService(); - DefaultTaskExecutor.runInJavaFXThread(() -> { - dialogService.showFileOpenDialog(fileDialogConfiguration) - .ifPresent(path -> doImport(path, importers, fileDialogConfiguration.getSelectedExtensionFilter())); - }); - } - - private void doImport(Path file, SortedSet importers, FileChooser.ExtensionFilter selectedExtensionFilter) { - if (!Files.exists(file)) { - JOptionPane.showMessageDialog(null, - Localization.lang("File not found") + ": '" + file.getFileName() + "'.", - Localization.lang("Import"), JOptionPane.ERROR_MESSAGE); - return; - } - Optional format = FileFilterConverter.getImporter(selectedExtensionFilter, importers); - ImportMenuItem importMenu = new ImportMenuItem(frame, openInNew, format.orElse(null)); - importMenu.automatedImport(Collections.singletonList(file.toString())); - // Set last working dir for import - Globals.prefs.put(JabRefPreferences.IMPORT_WORKING_DIRECTORY, file.getParent().toString()); - } - }; - } -} 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 8cfb8c3568f..9e2eaa1acb1 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -96,8 +96,7 @@ public void execute() { .withInitialDirectory(Paths.get(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY))) .build(); - List chosenFiles = DefaultTaskExecutor - .runInJavaFXThread(() -> ds.showFileOpenDialogAndGetMultipleFiles(fileDialogConfiguration)); + List chosenFiles = ds.showFileOpenDialogAndGetMultipleFiles(fileDialogConfiguration); filesToOpen.addAll(chosenFiles); openFiles(filesToOpen, true); diff --git a/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java b/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java index 0e2a8ab085a..7e0be04ee48 100644 --- a/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java +++ b/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java @@ -1,43 +1,34 @@ package org.jabref.gui.menus; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import javax.swing.JMenu; -import javax.swing.JMenuItem; import javax.swing.JOptionPane; +import javafx.scene.control.Menu; +import javafx.scene.control.MenuItem; + import org.jabref.JabRefExecutorService; import org.jabref.gui.JabRefFrame; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.io.FileHistory; import org.jabref.preferences.JabRefPreferences; -public class FileHistoryMenu extends JMenu implements ActionListener { +public class FileHistoryMenu extends Menu { private final FileHistory history; private final JabRefFrame frame; - private final JabRefPreferences prefs; - - public FileHistoryMenu(JabRefPreferences prefs, JabRefFrame frame) { - String name = Localization.menuTitle("Recent libraries"); - int i = name.indexOf('&'); - if (i >= 0) { - setText(name.substring(0, i) + name.substring(i + 1)); - char mnemonic = Character.toUpperCase(name.charAt(i + 1)); - setMnemonic((int) mnemonic); - } else { - setText(name); - } + private final JabRefPreferences preferences; + + public FileHistoryMenu(JabRefPreferences preferences, JabRefFrame frame) { + setText(Localization.menuTitle("Recent libraries")); this.frame = frame; - this.prefs = prefs; - history = prefs.getFileHistory(); + this.preferences = preferences; + history = preferences.getFileHistory(); if (history.isEmpty()) { - setEnabled(false); + setDisable(true); } else { setItems(); } @@ -52,44 +43,35 @@ public FileHistoryMenu(JabRefPreferences prefs, JabRefFrame frame) { public void newFile(String filename) { history.newFile(filename); setItems(); - if (!isEnabled()) { - setEnabled(true); - } + setDisable(false); } private void setItems() { - removeAll(); + getItems().clear(); for (int count = 0; count < history.size(); count++) { addItem(history.getFileName(count), count + 1); } } - private void addItem(String filename, int num) { + private void addItem(String fileName, int num) { String number = Integer.toString(num); - JMenuItem item = new JMenuItem(number + ". " + filename); - char mnemonic = Character.toUpperCase(number.charAt(0)); - item.setMnemonic((int) mnemonic); - item.addActionListener(this); - add(item); - //history.addFirst(item); + MenuItem item = new MenuItem(number + ". " + fileName); + item.setOnAction(event -> openFile(fileName)); + getItems().add(item); } public void storeHistory() { - prefs.storeFileHistory(history); + preferences.storeFileHistory(history); } - @Override - public void actionPerformed(ActionEvent e) { - String name = ((JMenuItem) e.getSource()).getText(); - int pos = name.indexOf(' '); - name = name.substring(pos + 1); - final Path fileToOpen = Paths.get(name); + public void openFile(String fileName) { + final Path fileToOpen = Paths.get(fileName); // the existence check has to be done here (and not in open.openIt) as we have to call "removeItem" if the file does not exist if (!Files.exists(fileToOpen)) { JOptionPane.showMessageDialog(null, Localization.lang("File not found") + ": " + fileToOpen.getFileName(), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); - history.removeItem(name); + history.removeItem(fileName); setItems(); return; } diff --git a/src/main/java/org/jabref/logic/l10n/Localization.java b/src/main/java/org/jabref/logic/l10n/Localization.java index 318193aefc4..ae975c7fb09 100644 --- a/src/main/java/org/jabref/logic/l10n/Localization.java +++ b/src/main/java/org/jabref/logic/l10n/Localization.java @@ -75,18 +75,8 @@ public static String menuTitle(String key, String... params) { LOGGER.error("Menu entries are not initialized"); setLanguage("en"); } - return lookup(localizedMenuTitles, "menu item", key, params); - } - - /** - * Return the translated string for usage in JavaFX menus. - * - * @implNote This is only a temporary workaround. In the long term, the & sign should be removed from the language - * files. - */ - public static String menuTitleFX(String key, String... params) { // Remove & sign, which is not used by JavaFX to signify the shortcut - return menuTitle(key, params).replace("&", ""); + return lookup(localizedMenuTitles, "menu item", key, params).replace("&", ""); } /** From 3e670d01656bf41de1bff4a1a3e6357425d66b8c Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 8 Feb 2018 23:44:27 +0100 Subject: [PATCH 050/827] Migrate edit menu --- src/main/java/org/jabref/gui/JabRefFrame.java | 125 ++++++------------ .../org/jabref/gui/actions/ActionsFX.java | 9 +- .../gui/actions/ManageKeywordsAction.java | 5 +- .../gui/actions/MassSetFieldAction.java | 5 +- 4 files changed, 56 insertions(+), 88 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 36dfffea402..335395a377b 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -211,28 +211,17 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { Localization.menuTitle("Focus entry table"), Localization.lang("Move the keyboard focus to the entry table"), Globals.getKeyPrefs().getKey(KeyBinding.FOCUS_ENTRY_TABLE)); private final AbstractAction sortTabs = new SortTabsAction(this); - private final AbstractAction undo = new GeneralAction(Actions.UNDO, Localization.menuTitle("Undo"), - Localization.lang("Undo"), Globals.getKeyPrefs().getKey(KeyBinding.UNDO), IconTheme.JabRefIcons.UNDO.getIcon()); - private final AbstractAction redo = new GeneralAction(Actions.REDO, Localization.menuTitle("Redo"), - Localization.lang("Redo"), Globals.getKeyPrefs().getKey(KeyBinding.REDO), IconTheme.JabRefIcons.REDO.getIcon()); private final AbstractAction forward = new GeneralAction(Actions.FORWARD, Localization.menuTitle("Forward"), Localization.lang("Forward"), Globals.getKeyPrefs().getKey(KeyBinding.FORWARD), IconTheme.JabRefIcons.RIGHT.getIcon()); private final AbstractAction back = new GeneralAction(Actions.BACK, Localization.menuTitle("Back"), Localization.lang("Back"), Globals.getKeyPrefs().getKey(KeyBinding.BACK), IconTheme.JabRefIcons.LEFT.getIcon()); private final AbstractAction deleteEntry = new GeneralAction(Actions.DELETE, Localization.menuTitle("Delete entry"), Localization.lang("Delete entry"), Globals.getKeyPrefs().getKey(KeyBinding.DELETE_ENTRY), IconTheme.JabRefIcons.DELETE_ENTRY.getIcon()); - private final AbstractAction copy = new EditAction(Actions.COPY, Localization.menuTitle("Copy"), - Localization.lang("Copy"), Globals.getKeyPrefs().getKey(KeyBinding.COPY), IconTheme.JabRefIcons.COPY.getIcon()); - private final AbstractAction paste = new EditAction(Actions.PASTE, Localization.menuTitle("Paste"), - Localization.lang("Paste"), Globals.getKeyPrefs().getKey(KeyBinding.PASTE), IconTheme.JabRefIcons.PASTE.getIcon()); - private final AbstractAction cut = new EditAction(Actions.CUT, Localization.menuTitle("Cut"), - Localization.lang("Cut"), Globals.getKeyPrefs().getKey(KeyBinding.CUT), IconTheme.JabRefIcons.CUT.getIcon()); private final AbstractAction openConsole = new GeneralAction(Actions.OPEN_CONSOLE, Localization.menuTitle("Open terminal here"), Localization.lang("Open terminal here"), Globals.getKeyPrefs().getKey(KeyBinding.OPEN_CONSOLE), IconTheme.JabRefIcons.CONSOLE.getIcon()); - private final AbstractAction mark = new GeneralAction(Actions.MARK_ENTRIES, Localization.menuTitle("Mark entries"), Localization.lang("Mark entries"), Globals.getKeyPrefs().getKey(KeyBinding.MARK_ENTRIES), IconTheme.JabRefIcons.MARK_ENTRIES.getIcon()); private final JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color")); @@ -259,25 +248,7 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { Localization.lang("Search"), Globals.getKeyPrefs().getKey(KeyBinding.SEARCH), IconTheme.JabRefIcons.SEARCH.getIcon()); private final AbstractAction manageSelectors = new GeneralAction(Actions.MANAGE_SELECTORS, Localization.menuTitle("Manage content selectors")); - private final AbstractAction copyPreview = new GeneralAction(Actions.COPY_CITATION_HTML, Localization.lang("Copy preview"), - Globals.getKeyPrefs().getKey(KeyBinding.COPY_PREVIEW)); - private final AbstractAction copyTitle = new GeneralAction(Actions.COPY_TITLE, Localization.menuTitle("Copy title"), - Globals.getKeyPrefs().getKey(KeyBinding.COPY_TITLE)); - private final AbstractAction copyKey = new GeneralAction(Actions.COPY_KEY, Localization.menuTitle("Copy BibTeX key"), - Globals.getKeyPrefs().getKey(KeyBinding.COPY_BIBTEX_KEY)); - private final AbstractAction copyCiteKey = new GeneralAction(Actions.COPY_CITE_KEY, Localization.menuTitle( - "Copy \\cite{BibTeX key}"), - Globals.getKeyPrefs().getKey(KeyBinding.COPY_CITE_BIBTEX_KEY)); - private final AbstractAction copyKeyAndTitle = new GeneralAction(Actions.COPY_KEY_AND_TITLE, - Localization.menuTitle("Copy BibTeX key and title"), - Globals.getKeyPrefs().getKey(KeyBinding.COPY_BIBTEX_KEY_AND_TITLE)); - private final AbstractAction copyKeyAndLink = new GeneralAction(Actions.COPY_KEY_AND_LINK, - Localization.menuTitle("Copy BibTeX key and link"), - Globals.getKeyPrefs().getKey(KeyBinding.COPY_BIBTEX_KEY_AND_LINK)); - private final AbstractAction selectAll = new GeneralAction(Actions.SELECT_ALL, Localization.menuTitle("Select all"), - Globals.getKeyPrefs().getKey(KeyBinding.SELECT_ALL)); - private final AbstractAction replaceAll = new GeneralAction(Actions.REPLACE_ALL, - Localization.menuTitle("Replace string") + ELLIPSES, Globals.getKeyPrefs().getKey(KeyBinding.REPLACE_STRING)); + private final AbstractAction editPreamble = new GeneralAction(Actions.EDIT_PREAMBLE, Localization.menuTitle("Edit preamble"), Localization.lang("Edit preamble")); @@ -344,9 +315,6 @@ public void actionPerformed(ActionEvent e) { private final AbstractAction customExpAction = new CustomizeExportsAction(); private final AbstractAction customImpAction = new CustomizeImportsAction(); private final AbstractAction customFileTypesAction = ExternalFileTypeEditor.getAction(this); - private final AbstractAction exportToClipboard = new GeneralAction(Actions.EXPORT_TO_CLIPBOARD, - Localization.menuTitle("Export selected entries to clipboard"), - IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD.getIcon()); private final AbstractAction autoSetFile = new GeneralAction(Actions.AUTO_SET_FILE, Localization.lang("Synchronize file links") + ELLIPSES, Globals.getKeyPrefs().getKey(KeyBinding.SYNCHRONIZE_FILES)); @@ -385,10 +353,7 @@ public void actionPerformed(ActionEvent e) { Localization.menuTitle("Resolve duplicate BibTeX keys"), Localization.lang("Find and remove duplicate BibTeX keys"), Globals.getKeyPrefs().getKey(KeyBinding.RESOLVE_DUPLICATE_BIBTEX_KEYS)); - private final AbstractAction sendAsEmail = new GeneralAction(Actions.SEND_AS_EMAIL, - Localization.lang("Send as email"), IconTheme.JabRefIcons.EMAIL.getIcon()); - private final MassSetFieldAction massSetField = new MassSetFieldAction(this); - private final ManageKeywordsAction manageKeywords = new ManageKeywordsAction(this); + private final JMenu lookupIdentifiers = JabRefFrame.subMenu(Localization.menuTitle("Look up document identifier...")); private final GeneralAction findUnlinkedFiles = new GeneralAction( Actions.findUnlinkedFiles, @@ -676,6 +641,10 @@ private void initSidePane() { sidePaneManager = new SidePaneManager(this); groupSidePane = new GroupSidePane(this, sidePaneManager); + if (prefs.getBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE)) { + sidePaneManager.register(groupSidePane); + sidePaneManager.show(GroupSidePane.class); + } openOfficePanel = new OpenOfficePanel(this, sidePaneManager); generalFetcher = new GeneralFetcher(this, sidePaneManager); @@ -1040,30 +1009,33 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.quit, new CloseAction()) ); - /* - factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), + edit.getItems().addAll( + factory.createMenuItem(ActionsFX.undo, new OldDatabaseCommandWrapper(Actions.UNDO, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.redo, new OldDatabaseCommandWrapper(Actions.REDO, this, Globals.stateManager)), - edit.add(undo); - edit.add(redo); + new SeparatorMenuItem(), - edit.addSeparator(); + factory.createMenuItem(ActionsFX.CUT, new EditAction(Actions.CUT)), + factory.createMenuItem(ActionsFX.COPY, new EditAction(Actions.COPY)), + factory.createSubMenu(ActionsFX.COPY_MORE, + factory.createMenuItem(ActionsFX.COPY_TITLE, new OldDatabaseCommandWrapper(Actions.COPY_TITLE, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.COPY_KEY, new OldDatabaseCommandWrapper(Actions.COPY_KEY, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.COPY_CITE_KEY, new OldDatabaseCommandWrapper(Actions.COPY_CITE_KEY, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.COPY_KEY_AND_TITLE, new OldDatabaseCommandWrapper(Actions.COPY_KEY_AND_TITLE, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.COPY_KEY_AND_LINK, new OldDatabaseCommandWrapper(Actions.COPY_KEY_AND_LINK, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.COPY_CITATION_PREVIEW, new OldDatabaseCommandWrapper(Actions.COPY_CITATION_HTML, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.EXPORT_SELECTED_TO_CLIPBOARD, new OldDatabaseCommandWrapper(Actions.EXPORT_TO_CLIPBOARD, this, Globals.stateManager)) + ), - edit.add(cut); - edit.add(copy); - edit.add(paste); + factory.createMenuItem(ActionsFX.PASTE, new EditAction(Actions.PASTE)), - edit.addSeparator(); + new SeparatorMenuItem(), - edit.add(copyTitle); - edit.add(copyKey); - edit.add(copyCiteKey); - edit.add(copyKeyAndTitle); - edit.add(copyKeyAndLink); - edit.add(copyPreview); - edit.add(exportToClipboard); - edit.add(sendAsEmail); + factory.createMenuItem(ActionsFX.sendAsEmail, new OldDatabaseCommandWrapper(Actions.SEND_AS_EMAIL, this, Globals.stateManager)), - edit.addSeparator(); + new SeparatorMenuItem() + ); + /* edit.add(mark); for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) { markSpecific.add(new MarkEntriesAction(this, i).getMenuItem()); @@ -1072,6 +1044,8 @@ private MenuBar createMenu() { edit.add(unmark); edit.add(unmarkAll); edit.addSeparator(); + */ + /* TODO if (Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) { boolean menuitem = false; if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) { @@ -1108,15 +1082,18 @@ private MenuBar createMenu() { edit.addSeparator(); } } + */ - edit.add(getManageKeywords()); - edit.add(getMassSetField()); - edit.addSeparator(); - edit.add(selectAll); - mb.add(edit); + //factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), + + edit.getItems().addAll( + factory.createMenuItem(ActionsFX.manageKeywords, new ManageKeywordsAction(this)), + factory.createMenuItem(ActionsFX.replaceAll, new OldDatabaseCommandWrapper(Actions.REPLACE_ALL, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.massSetField, new MassSetFieldAction(this)) + ); + /* search.add(normalSearch); - search.add(replaceAll); search.addSeparator(); search.add(new JCheckBoxMenuItem(generalFetcher.getToggleAction())); if (prefs.getBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE)) { @@ -1126,10 +1103,6 @@ private MenuBar createMenu() { mb.add(search); groups.add(new JCheckBoxMenuItem(groupSidePane.getToggleAction())); - if (prefs.getBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE)) { - sidePaneManager.register(groupSidePane); - sidePaneManager.show(GroupSidePane.class); - } groups.addSeparator(); groups.add(addToGroup); @@ -1892,14 +1865,6 @@ public void closeCurrentTab() { removeTab(getCurrentBasePanel()); } - public ManageKeywordsAction getManageKeywords() { - return manageKeywords; - } - - public MassSetFieldAction getMassSetField() { - return massSetField; - } - public OpenDatabaseAction getOpenDatabaseAction() { return new OpenDatabaseAction(this); } @@ -2090,20 +2055,16 @@ public void actionPerformed(ActionEvent e) { * kept track of by Globals.focusListener, and we call the action stored under the * relevant name in its action map. */ - private class EditAction extends MnemonicAwareAction { + private class EditAction extends SimpleCommand { private final Actions command; - public EditAction(Actions command, String menuTitle, String description, KeyStroke key, Icon icon) { - super(icon); + public EditAction(Actions command) { this.command = command; - putValue(Action.NAME, menuTitle); - putValue(Action.ACCELERATOR_KEY, key); - putValue(Action.SHORT_DESCRIPTION, description); } - @Override public void actionPerformed(ActionEvent e) { - + @Override + public void execute() { LOGGER.debug(Globals.getFocusListener().getFocused().toString()); JComponent source = Globals.getFocusListener().getFocused(); Action action = source.getActionMap().get(command); @@ -2358,12 +2319,14 @@ public void listen(AddUndoableActionEvent event) { } private void updateTexts(UndoChangeEvent event) { + /* TODO SwingUtilities.invokeLater(() -> { undo.putValue(Action.SHORT_DESCRIPTION, event.getUndoDescription()); undo.setEnabled(event.isCanUndo()); redo.putValue(Action.SHORT_DESCRIPTION, event.getRedoDescription()); redo.setEnabled(event.isCanRedo()); }); + */ } } } diff --git a/src/main/java/org/jabref/gui/actions/ActionsFX.java b/src/main/java/org/jabref/gui/actions/ActionsFX.java index 98874db4352..c5b8e1fafe8 100644 --- a/src/main/java/org/jabref/gui/actions/ActionsFX.java +++ b/src/main/java/org/jabref/gui/actions/ActionsFX.java @@ -24,6 +24,7 @@ public enum ActionsFX { COPY_CITATION_XSLFO("XSL-FO"), COPY_CITATION_PREVIEW(Localization.lang("Copy preview"), KeyBinding.COPY_PREVIEW), EXPORT_TO_CLIPBOARD(Localization.lang("Export to clipboard"), IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD), + EXPORT_SELECTED_TO_CLIPBOARD(Localization.menuTitle("Export selected entries to clipboard"), IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD), COPY(Localization.lang("Copy"), IconTheme.JabRefIcons.COPY, KeyBinding.COPY), PASTE(Localization.lang("Paste"), IconTheme.JabRefIcons.PASTE, KeyBinding.PASTE), CUT(Localization.lang("Cut"), IconTheme.JabRefIcons.CUT, KeyBinding.CUT), @@ -76,7 +77,13 @@ public enum ActionsFX { connectToSharedDatabaseAction(Localization.lang("Connect to shared database")), pullChangesFromSharedDatabase(Localization.menuTitle("Pull changes from shared database"), IconTheme.JabRefIcons.PULL, KeyBinding.PULL_CHANGES_FROM_SHARED_DATABASE), closeDatabaseAction(Localization.menuTitle("Close library"), Localization.lang("Close the current library"), IconTheme.JabRefIcons.CLOSE, KeyBinding.CLOSE_DATABASE), - quit(Localization.menuTitle("Quit"), Localization.lang("Quit JabRef"), IconTheme.JabRefIcons.CLOSE_JABREF, KeyBinding.QUIT_JABREF); + quit(Localization.menuTitle("Quit"), Localization.lang("Quit JabRef"), IconTheme.JabRefIcons.CLOSE_JABREF, KeyBinding.QUIT_JABREF), + undo(Localization.lang("Undo"), IconTheme.JabRefIcons.UNDO, KeyBinding.UNDO), + redo(Localization.lang("Redo"), IconTheme.JabRefIcons.REDO, KeyBinding.REDO), + sendAsEmail(Localization.lang("Send as email"), IconTheme.JabRefIcons.EMAIL), + replaceAll(Localization.menuTitle("Replace string"), KeyBinding.REPLACE_STRING), + manageKeywords(Localization.menuTitle("Manage keywords")), + massSetField(Localization.menuTitle("Set/clear/append/rename fields")); private final String text; private final String description; diff --git a/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java b/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java index 2f37be3ca28..dbb2f7beed6 100644 --- a/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java +++ b/src/main/java/org/jabref/gui/actions/ManageKeywordsAction.java @@ -49,7 +49,7 @@ * An Action for launching keyword managing dialog * */ -public class ManageKeywordsAction extends MnemonicAwareAction { +public class ManageKeywordsAction extends SimpleCommand { private final JabRefFrame frame; private final KeywordList sortedKeywordsOfAllEntriesBeforeUpdateByUser = new KeywordList(); @@ -61,7 +61,6 @@ public class ManageKeywordsAction extends MnemonicAwareAction { public ManageKeywordsAction(JabRefFrame frame) { - putValue(Action.NAME, Localization.menuTitle("Manage keywords")); this.frame = frame; } @@ -241,7 +240,7 @@ private void addKeywordToKeywordListModel(String keyword) { } @Override - public void actionPerformed(ActionEvent e) { + public void execute() { BasePanel bp = frame.getCurrentBasePanel(); if (bp == null) { return; diff --git a/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java b/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java index 775733a2952..24ca4064ff7 100644 --- a/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java +++ b/src/main/java/org/jabref/gui/actions/MassSetFieldAction.java @@ -46,7 +46,7 @@ * * Input field name * * Either set field, or clear field. */ -public class MassSetFieldAction extends MnemonicAwareAction { +public class MassSetFieldAction extends SimpleCommand { private final JabRefFrame frame; private JDialog diag; @@ -65,7 +65,6 @@ public class MassSetFieldAction extends MnemonicAwareAction { public MassSetFieldAction(JabRefFrame frame) { - putValue(Action.NAME, Localization.menuTitle("Set/clear/append/rename fields") + "..."); this.frame = frame; } @@ -208,7 +207,7 @@ private void prepareDialog(boolean selection) { } @Override - public void actionPerformed(ActionEvent e) { + public void execute() { BasePanel bp = frame.getCurrentBasePanel(); if (bp == null) { return; From 29565c5c00f7c742ea118ca0f618db0b3c6849fe Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 9 Feb 2018 00:06:03 +0100 Subject: [PATCH 051/827] Show correct title and image --- src/main/java/org/jabref/JabRefGUI.java | 14 +++++--------- src/main/java/org/jabref/gui/IconTheme.java | 13 +++++++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index 17c122ebad0..d796b1130ba 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -21,6 +21,7 @@ import org.jabref.gui.AbstractView; import org.jabref.gui.BasePanel; import org.jabref.gui.GUIGlobals; +import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.gui.autosaveandbackup.BackupUIManager; import org.jabref.gui.importer.ParserResultWarningDialog; @@ -149,14 +150,13 @@ private void openWindow(Stage mainStage) { // state. This needs to be set after the window has been made visible, so we // do it here: if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) { - //JabRefGUI.getMainFrame().setExtendedState(Frame.MAXIMIZED_BOTH); + mainStage.setMaximized(true); } - mainStage.setTitle(JabRefFrame.FRAME_TITLE); - - Scene scene = new Scene(JabRefGUI.mainFrame, 800, 200); + Scene scene = new Scene(JabRefGUI.mainFrame, 800, 800); scene.getStylesheets().add(AbstractView.class.getResource("Main.css").toExternalForm()); - mainStage.setTitle("Find this window"); + mainStage.setTitle(JabRefFrame.FRAME_TITLE); + mainStage.getIcons().addAll(IconTheme.getLogoSetFX()); mainStage.setScene(scene); mainStage.show(); @@ -196,10 +196,6 @@ private void openWindow(Stage mainStage) { } LOGGER.debug("Finished adding panels"); - - if (!bibDatabases.isEmpty()) { - //JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable().requestFocus(); - } } private void openLastEditedDatabases() { diff --git a/src/main/java/org/jabref/gui/IconTheme.java b/src/main/java/org/jabref/gui/IconTheme.java index ded81e4323b..9a31da6f292 100644 --- a/src/main/java/org/jabref/gui/IconTheme.java +++ b/src/main/java/org/jabref/gui/IconTheme.java @@ -167,6 +167,19 @@ public static List getLogoSet() { return jabrefLogos; } + public static List getLogoSetFX() { + List jabrefLogos = new ArrayList<>(); + jabrefLogos.add(new Image(getIconUrl("jabrefIcon16").toString())); + jabrefLogos.add(new Image(getIconUrl("jabrefIcon20").toString())); + jabrefLogos.add(new Image(getIconUrl("jabrefIcon32").toString())); + jabrefLogos.add(new Image(getIconUrl("jabrefIcon40").toString())); + jabrefLogos.add(new Image(getIconUrl("jabrefIcon48").toString())); + jabrefLogos.add(new Image(getIconUrl("jabrefIcon64").toString())); + jabrefLogos.add(new Image(getIconUrl("jabrefIcon128").toString())); + + return jabrefLogos; + } + public enum JabRefIcons implements JabRefIcon { ADD(MaterialDesignIcon.PLUS_BOX), From 0141abb20c76d0f2bba2fa9b83f41adbfdb598e8 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 9 Feb 2018 21:11:13 +0100 Subject: [PATCH 052/827] Make escape close entry editor when no field is selected Fixes koppor#297 --- src/main/java/org/jabref/gui/entryeditor/EntryEditor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index e3d93d09940..b801f68592b 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -102,7 +102,7 @@ public EntryEditor(BasePanel panel, EntryEditorPreferences preferences, FileUpda * Set-up key bindings specific for the entry editor. */ private void setupKeyBindings() { - tabbed.addEventHandler(KeyEvent.KEY_PRESSED, event -> { + this.addEventHandler(KeyEvent.KEY_PRESSED, event -> { Optional keyBinding = preferences.getKeyBindings().mapToKeyBinding(event); if (keyBinding.isPresent()) { switch (keyBinding.get()) { From 1cf45c22228dc96e29734d2fc2f42976de316404 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 9 Feb 2018 22:48:51 +0100 Subject: [PATCH 053/827] Convert options menu to javafx TODO: ExternalfileType and Content Selectors do not work/throw an NPE --- src/main/java/org/jabref/gui/JabRefFrame.java | 192 +++++------------- .../org/jabref/gui/actions/ActionsFX.java | 41 ++-- .../gui/actions/CustomizeEntryAction.java | 22 ++ .../actions/CustomizeKeyBindingAction.java | 12 ++ .../actions/EditExternalFileTypesAction.java | 20 ++ .../gui/actions/LibraryPropertiesAction.java | 26 +++ .../actions/ManageContentSelectorAction.java | 26 +++ .../actions/ManageCustomExportsAction.java | 23 +++ .../actions/ManageCustomImportsAction.java | 21 ++ .../gui/actions/ManageJournalsAction.java | 12 ++ .../actions/ManageProtectedTermsAction.java | 23 +++ .../gui/actions/SetupGeneralFieldsAction.java | 21 ++ .../gui/actions/ShowPreferencesAction.java | 30 +++ .../ExternalFileTypeEditor.java | 2 +- .../gui/journals/ManageJournalsAction.java | 23 --- .../jabref/gui/keyboard/KeyBindingAction.java | 29 --- src/main/java/osx/macadapter/MacAdapter.java | 2 +- 17 files changed, 312 insertions(+), 213 deletions(-) create mode 100644 src/main/java/org/jabref/gui/actions/CustomizeEntryAction.java create mode 100644 src/main/java/org/jabref/gui/actions/CustomizeKeyBindingAction.java create mode 100644 src/main/java/org/jabref/gui/actions/EditExternalFileTypesAction.java create mode 100644 src/main/java/org/jabref/gui/actions/LibraryPropertiesAction.java create mode 100644 src/main/java/org/jabref/gui/actions/ManageContentSelectorAction.java create mode 100644 src/main/java/org/jabref/gui/actions/ManageCustomExportsAction.java create mode 100644 src/main/java/org/jabref/gui/actions/ManageCustomImportsAction.java create mode 100644 src/main/java/org/jabref/gui/actions/ManageJournalsAction.java create mode 100644 src/main/java/org/jabref/gui/actions/ManageProtectedTermsAction.java create mode 100644 src/main/java/org/jabref/gui/actions/SetupGeneralFieldsAction.java create mode 100644 src/main/java/org/jabref/gui/actions/ShowPreferencesAction.java delete mode 100644 src/main/java/org/jabref/gui/journals/ManageJournalsAction.java delete mode 100644 src/main/java/org/jabref/gui/keyboard/KeyBindingAction.java diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 36dfffea402..0165bba7b89 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -30,7 +30,6 @@ import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JComponent; -import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuItem; @@ -67,9 +66,16 @@ import org.jabref.gui.actions.ActionsFX; import org.jabref.gui.actions.AutoLinkFilesAction; import org.jabref.gui.actions.ConnectToSharedDatabaseCommand; +import org.jabref.gui.actions.CustomizeKeyBindingAction; +import org.jabref.gui.actions.EditExternalFileTypesAction; import org.jabref.gui.actions.ErrorConsoleAction; import org.jabref.gui.actions.IntegrityCheckAction; +import org.jabref.gui.actions.ManageContentSelectorAction; +import org.jabref.gui.actions.ManageCustomExportsAction; +import org.jabref.gui.actions.ManageCustomImportsAction; +import org.jabref.gui.actions.ManageJournalsAction; import org.jabref.gui.actions.ManageKeywordsAction; +import org.jabref.gui.actions.ManageProtectedTermsAction; import org.jabref.gui.actions.MassSetFieldAction; import org.jabref.gui.actions.MnemonicAwareAction; import org.jabref.gui.actions.NewDatabaseAction; @@ -77,38 +83,31 @@ import org.jabref.gui.actions.NewSubDatabaseAction; import org.jabref.gui.actions.OldDatabaseCommandWrapper; import org.jabref.gui.actions.OpenBrowserAction; +import org.jabref.gui.actions.SetupGeneralFieldsAction; +import org.jabref.gui.actions.ShowPreferencesAction; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.actions.SortTabsAction; import org.jabref.gui.autosaveandbackup.AutosaveUIManager; import org.jabref.gui.bibtexkeypattern.BibtexKeyPatternDialog; import org.jabref.gui.copyfiles.CopyFilesAction; -import org.jabref.gui.customentrytypes.EntryCustomizationDialog; import org.jabref.gui.customjfx.CustomJFXPanel; -import org.jabref.gui.dbproperties.DatabasePropertiesDialog; import org.jabref.gui.documentviewer.ShowDocumentViewerAction; import org.jabref.gui.exporter.ExportCommand; -import org.jabref.gui.exporter.ExportCustomizationDialog; import org.jabref.gui.exporter.SaveAllAction; import org.jabref.gui.exporter.SaveDatabaseAction; -import org.jabref.gui.externalfiletype.ExternalFileTypeEditor; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.groups.EntryTableTransferHandler; import org.jabref.gui.groups.GroupSidePane; import org.jabref.gui.help.AboutAction; import org.jabref.gui.help.HelpAction; import org.jabref.gui.importer.ImportCommand; -import org.jabref.gui.importer.ImportCustomizationDialog; import org.jabref.gui.importer.ImportInspectionDialog; import org.jabref.gui.importer.actions.OpenDatabaseAction; import org.jabref.gui.importer.fetcher.GeneralFetcher; -import org.jabref.gui.journals.ManageJournalsAction; import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.gui.keyboard.KeyBindingAction; import org.jabref.gui.menus.ChangeEntryTypeMenu; import org.jabref.gui.menus.FileHistoryMenu; import org.jabref.gui.openoffice.OpenOfficePanel; -import org.jabref.gui.preftabs.PreferencesDialog; -import org.jabref.gui.protectedterms.ProtectedTermsDialog; import org.jabref.gui.push.PushToApplicationButton; import org.jabref.gui.push.PushToApplications; import org.jabref.gui.search.GlobalSearchBar; @@ -175,7 +174,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { // BasePanel's runCommand() method to be called with that command. // Note: GeneralAction's constructor automatically gets translations // for the name and message strings. - private final AbstractAction keyBindingAction = new KeyBindingAction(); private final AbstractAction newSubDatabaseAction = new NewSubDatabaseAction(this); private final AbstractAction jabrefWebPageAction = new OpenBrowserAction("https://jabref.org", Localization.menuTitle("Website"), Localization.lang("Opens JabRef's website"), @@ -257,8 +255,7 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { IconTheme.JabRefIcons.PRINTED.getIcon()); private final AbstractAction normalSearch = new GeneralAction(Actions.SEARCH, Localization.menuTitle("Search"), Localization.lang("Search"), Globals.getKeyPrefs().getKey(KeyBinding.SEARCH), IconTheme.JabRefIcons.SEARCH.getIcon()); - private final AbstractAction manageSelectors = new GeneralAction(Actions.MANAGE_SELECTORS, - Localization.menuTitle("Manage content selectors")); + private final AbstractAction copyPreview = new GeneralAction(Actions.COPY_CITATION_HTML, Localization.lang("Copy preview"), Globals.getKeyPrefs().getKey(KeyBinding.COPY_PREVIEW)); private final AbstractAction copyTitle = new GeneralAction(Actions.COPY_TITLE, Localization.menuTitle("Copy title"), @@ -286,7 +283,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { Localization.lang("Edit strings"), Globals.getKeyPrefs().getKey(KeyBinding.EDIT_STRINGS), IconTheme.JabRefIcons.EDIT_STRINGS.getIcon()); - private final AbstractAction customizeAction = new CustomizeEntryTypeAction(); private final Action toggleToolbar = enableToggle(new AbstractAction(Localization.menuTitle("Hide/show toolbar")) { { @@ -341,9 +337,8 @@ public void actionPerformed(ActionEvent e) { private final AbstractAction plainTextImport = new GeneralAction(Actions.PLAIN_TEXT_IMPORT, Localization.menuTitle("New entry from plain text") + ELLIPSES, Globals.getKeyPrefs().getKey(KeyBinding.NEW_FROM_PLAIN_TEXT)); - private final AbstractAction customExpAction = new CustomizeExportsAction(); - private final AbstractAction customImpAction = new CustomizeImportsAction(); - private final AbstractAction customFileTypesAction = ExternalFileTypeEditor.getAction(this); + + private final AbstractAction exportToClipboard = new GeneralAction(Actions.EXPORT_TO_CLIPBOARD, Localization.menuTitle("Export selected entries to clipboard"), IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD.getIcon()); @@ -362,8 +357,6 @@ public void actionPerformed(ActionEvent e) { Localization.lang("Unabbreviate journal names of the selected entries"), Globals.getKeyPrefs().getKey(KeyBinding.UNABBREVIATE)); private final AbstractAction exportLinkedFiles = new CopyFilesAction(); - private final AbstractAction manageJournals = new ManageJournalsAction(); - private final AbstractAction databaseProperties = new DatabasePropertiesAction(); private final AbstractAction bibtexKeyPattern = new BibtexKeyPatternAction(); private final AbstractAction errorConsole = new ErrorConsoleAction(); private final AbstractAction cleanupEntries = new GeneralAction(Actions.CLEANUP, @@ -402,8 +395,7 @@ public void actionPerformed(ActionEvent e) { // The action for closing the current database and leaving the window open. private final CloseAllDatabasesAction closeAllDatabasesAction = new CloseAllDatabasesAction(); private final CloseOtherDatabasesAction closeOtherDatabasesAction = new CloseOtherDatabasesAction(); - // The action for opening the preferences dialog. - private final AbstractAction showPrefs = new ShowPrefsAction(); + // Lists containing different subsets of actions for different purposes private final List specialFieldButtons = new LinkedList<>(); private final List openDatabaseOnlyActions = new LinkedList<>(); @@ -416,7 +408,6 @@ public void actionPerformed(ActionEvent e) { private final List oneEntryWithURLorDOIOnlyActions = new LinkedList<>(); private final List twoEntriesOnlyActions = new LinkedList<>(); private final List atLeastOneEntryActions = new LinkedList<>(); - private PreferencesDialog prefsDialog; // The sidepane manager takes care of populating the sidepane. private SidePaneManager sidePaneManager; private final TabPane tabbedPane = new TabPane(); @@ -514,7 +505,7 @@ private JPopupMenu tabPopupMenu() { popupMenu.addSeparator(); JMenuItem databasePropertiesMenu = new JMenuItem(Localization.lang("Library properties")); - databasePropertiesMenu.addActionListener(this.databaseProperties); + // databasePropertiesMenu.addActionListener(this.databaseProperties); popupMenu.add(databasePropertiesMenu); JMenuItem bibtexKeyPatternBtn = new JMenuItem(Localization.lang("BibTeX key patterns")); @@ -701,18 +692,7 @@ public void about() { // General preferences dialog. The MacAdapter calls this method when "Preferences..." // is selected from the application menu. - public void showPreferencesDialog() { - output(Localization.lang("Opening preferences...")); - if (prefsDialog == null) { - prefsDialog = new PreferencesDialog(JabRefFrame.this); - //prefsDialog.setLocationRelativeTo(JabRefFrame.this); - } else { - prefsDialog.setValues(); - } - prefsDialog.setVisible(true); - output(""); - } public JabRefPreferences prefs() { return prefs; @@ -958,7 +938,7 @@ public void showBasePanel(BasePanel bp) { * Returns the currently viewed BasePanel. */ public BasePanel getCurrentBasePanel() { - if (tabbedPane == null || tabbedPane.getSelectionModel().getSelectedItem() == null) { + if ((tabbedPane == null) || (tabbedPane.getSelectionModel().getSelectedItem() == null)) { return null; } return (BasePanel) tabbedPane.getSelectionModel().getSelectedItem().getContent(); @@ -996,6 +976,10 @@ public void setTabTitle(BasePanel comp, String title, String toolTip) { }); } + /** + * JavaFX Menus + * @return Menubar + */ private MenuBar createMenu() { ActionFactory factory = new ActionFactory(Globals.getKeyPrefs()); @@ -1012,23 +996,23 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.NEW_LIBRARY_BIBTEX, new NewDatabaseAction(this, BibDatabaseMode.BIBTEX)), factory.createMenuItem(ActionsFX.NEW_LIBRARY_BIBLATEX, new NewDatabaseAction(this, BibDatabaseMode.BIBLATEX)), factory.createMenuItem(ActionsFX.OPEN_LIBRARY, getOpenDatabaseAction()), - factory.createMenuItem(ActionsFX.save, new OldDatabaseCommandWrapper(Actions.SAVE, this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.saveAs, new OldDatabaseCommandWrapper(Actions.SAVE_AS, this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.saveAll, new SaveAllAction(this)), - - factory.createSubMenu(ActionsFX.import_export, - factory.createMenuItem(ActionsFX.mergeDatabaseAction, new OldDatabaseCommandWrapper(Actions.MERGE_DATABASE, this, Globals.stateManager)), // TODO: merge with import - factory.createMenuItem(ActionsFX.importCurrent, new ImportCommand(this, true)), - factory.createMenuItem(ActionsFX.importNew, new ImportCommand(this, false)), - factory.createMenuItem(ActionsFX.exportAll, new ExportCommand(this, false)), - factory.createMenuItem(ActionsFX.exportSelected, new ExportCommand(this, true)), - factory.createMenuItem(ActionsFX.saveSelectedAsPlain, new OldDatabaseCommandWrapper(Actions.SAVE_SELECTED_AS_PLAIN, this, Globals.stateManager)) + factory.createMenuItem(ActionsFX.SAVE_LIBRARY, new OldDatabaseCommandWrapper(Actions.SAVE, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.SAVE_LIBRARY_AS, new OldDatabaseCommandWrapper(Actions.SAVE_AS, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.SAVE_ALL, new SaveAllAction(this)), + + factory.createSubMenu(ActionsFX.IMPORT_EXPORT, + factory.createMenuItem(ActionsFX.MERGE_DATABASE, new OldDatabaseCommandWrapper(Actions.MERGE_DATABASE, this, Globals.stateManager)), // TODO: merge with import + factory.createMenuItem(ActionsFX.IMPORT_INTO_CURRENT_LIBRARY, new ImportCommand(this, true)), + factory.createMenuItem(ActionsFX.IMPORT_INTO_NEW_LIBRARY, new ImportCommand(this, false)), + factory.createMenuItem(ActionsFX.EXPORT_ALL, new ExportCommand(this, false)), + factory.createMenuItem(ActionsFX.EXPORT_SELECTED, new ExportCommand(this, true)), + factory.createMenuItem(ActionsFX.SAVE_SELECTED_AS_PLAIN_BIBTEX, new OldDatabaseCommandWrapper(Actions.SAVE_SELECTED_AS_PLAIN, this, Globals.stateManager)) ), new SeparatorMenuItem(), - factory.createMenuItem(ActionsFX.connectToSharedDatabaseAction, new ConnectToSharedDatabaseCommand(this)), - factory.createMenuItem(ActionsFX.pullChangesFromSharedDatabase, new OldDatabaseCommandWrapper(Actions.PULL_CHANGES_FROM_SHARED_DATABASE, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.CONNECT_TO_SHARED_DB, new ConnectToSharedDatabaseCommand(this)), + factory.createMenuItem(ActionsFX.PULL_CHANGES_FROM_SHARED_DB, new OldDatabaseCommandWrapper(Actions.PULL_CHANGES_FROM_SHARED_DATABASE, this, Globals.stateManager)), new SeparatorMenuItem(), @@ -1036,10 +1020,23 @@ private MenuBar createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(ActionsFX.closeDatabaseAction, new CloseDatabaseAction()), - factory.createMenuItem(ActionsFX.quit, new CloseAction()) + factory.createMenuItem(ActionsFX.CLOSE_LIBRARY, new CloseDatabaseAction()), + factory.createMenuItem(ActionsFX.QUIT, new CloseAction()) ); + options.getItems().addAll( + factory.createMenuItem(ActionsFX.SHOW_PREFS, new ShowPreferencesAction(this)), + factory.createMenuItem(ActionsFX.SETUP_GENERAL_FIELDS, new SetupGeneralFieldsAction(this)), + factory.createMenuItem(ActionsFX.MANAGE_CUSTOM_IMPORTS, new ManageCustomImportsAction(this)), + factory.createMenuItem(ActionsFX.MANAGE_CUSTOM_EXPORTS, new ManageCustomExportsAction(this)), + factory.createMenuItem(ActionsFX.MANAGE_EXTERNAL_FILETYPES, new EditExternalFileTypesAction()), + factory.createMenuItem(ActionsFX.MANAGE_JOURNALS, new ManageJournalsAction()), + factory.createMenuItem(ActionsFX.CUSTOMIZE_KEYBINDING, new CustomizeKeyBindingAction()), + factory.createMenuItem(ActionsFX.MANAGE_PROTECTED_TERMS, new ManageProtectedTermsAction(this, Globals.protectedTermsLoader)), + factory.createMenuItem(ActionsFX.MANAGE_CONTENT_SELECTORS, new ManageContentSelectorAction(getCurrentBasePanel(), this)) + ); + + /* factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), @@ -2049,19 +2046,6 @@ public void execute() { } } - private class ShowPrefsAction extends MnemonicAwareAction { - - public ShowPrefsAction() { - super(IconTheme.JabRefIcons.PREFERENCES.getIcon()); - putValue(Action.NAME, Localization.menuTitle("Preferences")); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Preferences")); - } - - @Override - public void actionPerformed(ActionEvent e) { - showPreferencesDialog(); - } - } private class ChangeTabAction extends MnemonicAwareAction { @@ -2113,93 +2097,11 @@ public EditAction(Actions command, String menuTitle, String description, KeyStro } } - private class CustomizeExportsAction extends MnemonicAwareAction { - - public CustomizeExportsAction() { - putValue(Action.NAME, Localization.menuTitle("Manage custom exports")); - } - - @Override - public void actionPerformed(ActionEvent e) { - ExportCustomizationDialog ecd = new ExportCustomizationDialog(JabRefFrame.this); - ecd.setVisible(true); - } - } - - private class CustomizeImportsAction extends MnemonicAwareAction { - public CustomizeImportsAction() { - putValue(Action.NAME, Localization.menuTitle("Manage custom imports")); - } - @Override - public void actionPerformed(ActionEvent e) { - ImportCustomizationDialog ecd = new ImportCustomizationDialog(JabRefFrame.this); - ecd.setVisible(true); - } - } - private class CustomizeEntryTypeAction extends MnemonicAwareAction { - public CustomizeEntryTypeAction() { - putValue(Action.NAME, Localization.menuTitle("Customize entry types")); - } - @Override - public void actionPerformed(ActionEvent e) { - JDialog dl = new EntryCustomizationDialog(JabRefFrame.this); - dl.setVisible(true); - } - } - - private class GenFieldsCustomizationAction extends MnemonicAwareAction { - - public GenFieldsCustomizationAction() { - putValue(Action.NAME, Localization.menuTitle("Set up general fields")); - } - - @Override - public void actionPerformed(ActionEvent e) { - GenFieldsCustomizer gf = new GenFieldsCustomizer(JabRefFrame.this); - gf.setVisible(true); - - } - } - - private class ProtectedTermsAction extends MnemonicAwareAction { - - public ProtectedTermsAction() { - putValue(Action.NAME, Localization.menuTitle("Manage protected terms")); - } - - @Override - public void actionPerformed(ActionEvent e) { - ProtectedTermsDialog protectTermsDialog = new ProtectedTermsDialog(JabRefFrame.this, - Globals.protectedTermsLoader); - protectTermsDialog.setVisible(true); - } - } - - private class DatabasePropertiesAction extends MnemonicAwareAction { - - private DatabasePropertiesDialog propertiesDialog; - - public DatabasePropertiesAction() { - putValue(Action.NAME, Localization.menuTitle("Library properties")); - } - - @Override - public void actionPerformed(ActionEvent e) { - if (propertiesDialog == null) { - propertiesDialog = new DatabasePropertiesDialog(null); - } - propertiesDialog.setPanel(getCurrentBasePanel()); - propertiesDialog.updateEnableStatus(); - propertiesDialog.setLocationRelativeTo(null); - propertiesDialog.setVisible(true); - } - - } private class BibtexKeyPatternAction extends MnemonicAwareAction { diff --git a/src/main/java/org/jabref/gui/actions/ActionsFX.java b/src/main/java/org/jabref/gui/actions/ActionsFX.java index 98874db4352..83e433ea4a0 100644 --- a/src/main/java/org/jabref/gui/actions/ActionsFX.java +++ b/src/main/java/org/jabref/gui/actions/ActionsFX.java @@ -63,20 +63,33 @@ public enum ActionsFX { NEW_LIBRARY_BIBTEX(Localization.menuTitle("New %0 library", BibDatabaseMode.BIBTEX.getFormattedName()), IconTheme.JabRefIcons.NEW), NEW_LIBRARY_BIBLATEX(Localization.menuTitle("New %0 library", BibDatabaseMode.BIBLATEX.getFormattedName()), IconTheme.JabRefIcons.NEW), OPEN_LIBRARY(Localization.menuTitle("Open library"), IconTheme.JabRefIcons.OPEN, KeyBinding.OPEN_DATABASE), - import_export(Localization.lang("Import & Export"), IconTheme.JabRefIcons.IMPORT_EXPORT), - mergeDatabaseAction(Localization.menuTitle("Append library"), Localization.lang("Append contents from a BibTeX library into the currently viewed library")), - save(Localization.menuTitle("Save library"), IconTheme.JabRefIcons.SAVE, KeyBinding.SAVE_DATABASE), - saveAs(Localization.lang("Save library as..."), KeyBinding.SAVE_DATABASE_AS), - saveSelectedAsPlain(Localization.lang("Save selected as plain BibTeX...")), - saveAll(Localization.menuTitle("Save all"), Localization.lang("Save all open libraries"), IconTheme.JabRefIcons.SAVE_ALL, KeyBinding.SAVE_ALL), - importNew(Localization.menuTitle("Import into new library"), KeyBinding.IMPORT_INTO_NEW_DATABASE), - importCurrent(Localization.menuTitle("Import into current library"), KeyBinding.IMPORT_INTO_CURRENT_DATABASE), - exportAll(Localization.menuTitle("Export")), - exportSelected(Localization.menuTitle("Export selected entries")), - connectToSharedDatabaseAction(Localization.lang("Connect to shared database")), - pullChangesFromSharedDatabase(Localization.menuTitle("Pull changes from shared database"), IconTheme.JabRefIcons.PULL, KeyBinding.PULL_CHANGES_FROM_SHARED_DATABASE), - closeDatabaseAction(Localization.menuTitle("Close library"), Localization.lang("Close the current library"), IconTheme.JabRefIcons.CLOSE, KeyBinding.CLOSE_DATABASE), - quit(Localization.menuTitle("Quit"), Localization.lang("Quit JabRef"), IconTheme.JabRefIcons.CLOSE_JABREF, KeyBinding.QUIT_JABREF); + IMPORT_EXPORT(Localization.lang("Import & Export"), IconTheme.JabRefIcons.IMPORT_EXPORT), + MERGE_DATABASE(Localization.menuTitle("Append library"), Localization.lang("Append contents from a BibTeX library into the currently viewed library")), + SAVE_LIBRARY(Localization.menuTitle("Save library"), IconTheme.JabRefIcons.SAVE, KeyBinding.SAVE_DATABASE), + SAVE_LIBRARY_AS(Localization.lang("Save library as..."), KeyBinding.SAVE_DATABASE_AS), + SAVE_SELECTED_AS_PLAIN_BIBTEX(Localization.lang("Save selected as plain BibTeX...")), + SAVE_ALL(Localization.menuTitle("Save all"), Localization.lang("Save all open libraries"), IconTheme.JabRefIcons.SAVE_ALL, KeyBinding.SAVE_ALL), + IMPORT_INTO_NEW_LIBRARY(Localization.menuTitle("Import into new library"), KeyBinding.IMPORT_INTO_NEW_DATABASE), + IMPORT_INTO_CURRENT_LIBRARY(Localization.menuTitle("Import into current library"), KeyBinding.IMPORT_INTO_CURRENT_DATABASE), + EXPORT_ALL(Localization.menuTitle("Export")), + EXPORT_SELECTED(Localization.menuTitle("Export selected entries")), + CONNECT_TO_SHARED_DB(Localization.lang("Connect to shared database")), + PULL_CHANGES_FROM_SHARED_DB(Localization.menuTitle("Pull changes from shared database"), IconTheme.JabRefIcons.PULL, KeyBinding.PULL_CHANGES_FROM_SHARED_DATABASE), + CLOSE_LIBRARY(Localization.menuTitle("Close library"), Localization.lang("Close the current library"), IconTheme.JabRefIcons.CLOSE, KeyBinding.CLOSE_DATABASE), + QUIT(Localization.menuTitle("Quit"), Localization.lang("Quit JabRef"), IconTheme.JabRefIcons.CLOSE_JABREF, KeyBinding.QUIT_JABREF), + + MANAGE_CUSTOM_EXPORTS(Localization.menuTitle("Manage custom exports")), + MANAGE_CUSTOM_IMPORTS(Localization.menuTitle("Manage custom imports")), + CUSTOMIZE_ENTRY_TYPES(Localization.menuTitle("Customize entry types")), + SETUP_GENERAL_FIELDS(Localization.menuTitle("Set up general fields")), + MANAGE_EXTERNAL_FILETYPES(Localization.menuTitle("Manage external file types")), + MANAGE_PROTECTED_TERMS(Localization.menuTitle("Manage protected terms")), + LIBRARY_PROPERTIES(Localization.menuTitle("Library properties")), + BIBTEX_KEY_PATTERN( Localization.lang("BibTeX key patterns")), + SHOW_PREFS(Localization.menuTitle("Preferences")), + MANAGE_JOURNALS(Localization.menuTitle("Manage journal abbreviations")), + CUSTOMIZE_KEYBINDING(Localization.lang("Customize key bindings"), IconTheme.JabRefIcons.KEY_BINDINGS), + MANAGE_CONTENT_SELECTORS(Localization.menuTitle("Manage content selectors"), IconTheme.JabRefIcons.PREFERENCES); private final String text; private final String description; diff --git a/src/main/java/org/jabref/gui/actions/CustomizeEntryAction.java b/src/main/java/org/jabref/gui/actions/CustomizeEntryAction.java new file mode 100644 index 00000000000..ce2747f4765 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/CustomizeEntryAction.java @@ -0,0 +1,22 @@ +package org.jabref.gui.actions; + +import javax.swing.JDialog; + +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.customentrytypes.EntryCustomizationDialog; + +public class CustomizeEntryAction extends SimpleCommand { + + private final JabRefFrame jabRefFrame; + + public CustomizeEntryAction(JabRefFrame jabRefFrame) { + this.jabRefFrame = jabRefFrame; + } + @Override + public void execute() { + JDialog dl = new EntryCustomizationDialog(jabRefFrame); + dl.setVisible(true); + + } + +} diff --git a/src/main/java/org/jabref/gui/actions/CustomizeKeyBindingAction.java b/src/main/java/org/jabref/gui/actions/CustomizeKeyBindingAction.java new file mode 100644 index 00000000000..fdaa5538ff4 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/CustomizeKeyBindingAction.java @@ -0,0 +1,12 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.keyboard.KeyBindingsDialogView; + +public class CustomizeKeyBindingAction extends SimpleCommand { + + @Override + public void execute() { + new KeyBindingsDialogView().show(); + } + +} diff --git a/src/main/java/org/jabref/gui/actions/EditExternalFileTypesAction.java b/src/main/java/org/jabref/gui/actions/EditExternalFileTypesAction.java new file mode 100644 index 00000000000..59fda7191dd --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/EditExternalFileTypesAction.java @@ -0,0 +1,20 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.externalfiletype.ExternalFileTypeEditor; + +//TODO: DOES NOT SHOW UP +public class EditExternalFileTypesAction extends SimpleCommand { + + private ExternalFileTypeEditor editor; + + + @Override + public void execute() { + if (editor == null) { + editor = new ExternalFileTypeEditor(null); + + } + + } + +} diff --git a/src/main/java/org/jabref/gui/actions/LibraryPropertiesAction.java b/src/main/java/org/jabref/gui/actions/LibraryPropertiesAction.java new file mode 100644 index 00000000000..6892b3fc138 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/LibraryPropertiesAction.java @@ -0,0 +1,26 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.BasePanel; +import org.jabref.gui.dbproperties.DatabasePropertiesDialog; + +public class LibraryPropertiesAction extends SimpleCommand { + + private DatabasePropertiesDialog propertiesDialog; + private final BasePanel basePanel; + + public LibraryPropertiesAction(BasePanel basePanel) { + this.basePanel = basePanel; + } + + @Override + public void execute() { + if (propertiesDialog == null) { + propertiesDialog = new DatabasePropertiesDialog(null); + } + propertiesDialog.setPanel(basePanel); + propertiesDialog.updateEnableStatus(); + propertiesDialog.setLocationRelativeTo(null); + propertiesDialog.setVisible(true); + } + +} diff --git a/src/main/java/org/jabref/gui/actions/ManageContentSelectorAction.java b/src/main/java/org/jabref/gui/actions/ManageContentSelectorAction.java new file mode 100644 index 00000000000..6a552dca717 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/ManageContentSelectorAction.java @@ -0,0 +1,26 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.BasePanel; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.contentselector.ContentSelectorDialog; + +//TODO: Throws an NPE If BasePanel is null +public class ManageContentSelectorAction extends SimpleCommand { + + private final BasePanel basePanel; + private final JabRefFrame frame; + + public ManageContentSelectorAction(BasePanel basePanel, JabRefFrame frame) + { + this.basePanel = basePanel; + this.frame = frame; + } + + @Override + public void execute() { + ContentSelectorDialog csd = new ContentSelectorDialog(null, frame, basePanel, false, null); + csd.setVisible(true); + + } + +} diff --git a/src/main/java/org/jabref/gui/actions/ManageCustomExportsAction.java b/src/main/java/org/jabref/gui/actions/ManageCustomExportsAction.java new file mode 100644 index 00000000000..6106a37b4ba --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/ManageCustomExportsAction.java @@ -0,0 +1,23 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.exporter.ExportCustomizationDialog; + +public class ManageCustomExportsAction extends SimpleCommand { + + private final JabRefFrame jabRefFrame; + + public ManageCustomExportsAction(JabRefFrame jabRefFrame) { + this.jabRefFrame = jabRefFrame; + } + + @Override + public void execute() { + ExportCustomizationDialog ecd = new ExportCustomizationDialog(jabRefFrame); + ecd.setVisible(true); + } + + + + +} diff --git a/src/main/java/org/jabref/gui/actions/ManageCustomImportsAction.java b/src/main/java/org/jabref/gui/actions/ManageCustomImportsAction.java new file mode 100644 index 00000000000..5359168805c --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/ManageCustomImportsAction.java @@ -0,0 +1,21 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.importer.ImportCustomizationDialog; + +public class ManageCustomImportsAction extends SimpleCommand { + + private final JabRefFrame jabRefFrame; + + public ManageCustomImportsAction(JabRefFrame jabRefFrame) { + this.jabRefFrame = jabRefFrame; + } + + @Override + public void execute() { + ImportCustomizationDialog ecd = new ImportCustomizationDialog(jabRefFrame); + ecd.setVisible(true); + + } + +} diff --git a/src/main/java/org/jabref/gui/actions/ManageJournalsAction.java b/src/main/java/org/jabref/gui/actions/ManageJournalsAction.java new file mode 100644 index 00000000000..b089a505a9e --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/ManageJournalsAction.java @@ -0,0 +1,12 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.journals.ManageJournalAbbreviationsView; + +public class ManageJournalsAction extends SimpleCommand { + + @Override + public void execute() { + new ManageJournalAbbreviationsView().show(); + } + +} diff --git a/src/main/java/org/jabref/gui/actions/ManageProtectedTermsAction.java b/src/main/java/org/jabref/gui/actions/ManageProtectedTermsAction.java new file mode 100644 index 00000000000..92fc3bfd8d0 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/ManageProtectedTermsAction.java @@ -0,0 +1,23 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.protectedterms.ProtectedTermsDialog; +import org.jabref.logic.protectedterms.ProtectedTermsLoader; + +public class ManageProtectedTermsAction extends SimpleCommand { + + private final JabRefFrame jabRefFrame; + private final ProtectedTermsLoader termsLoader; + + public ManageProtectedTermsAction(JabRefFrame jabRefFrame, ProtectedTermsLoader termsLoader) { + this.jabRefFrame = jabRefFrame; + this.termsLoader = termsLoader; + } + @Override + public void execute() { + ProtectedTermsDialog protectTermsDialog = new ProtectedTermsDialog(jabRefFrame, termsLoader); + protectTermsDialog.setVisible(true); + + } + +} diff --git a/src/main/java/org/jabref/gui/actions/SetupGeneralFieldsAction.java b/src/main/java/org/jabref/gui/actions/SetupGeneralFieldsAction.java new file mode 100644 index 00000000000..3f75fc14c20 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/SetupGeneralFieldsAction.java @@ -0,0 +1,21 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.GenFieldsCustomizer; +import org.jabref.gui.JabRefFrame; + +public class SetupGeneralFieldsAction extends SimpleCommand { + + private final JabRefFrame jabRefFrame; + + public SetupGeneralFieldsAction(JabRefFrame jabRefFrame) { + this.jabRefFrame = jabRefFrame; + } + + @Override + public void execute() { + GenFieldsCustomizer gf = new GenFieldsCustomizer(jabRefFrame); + gf.setVisible(true); + + } + +} diff --git a/src/main/java/org/jabref/gui/actions/ShowPreferencesAction.java b/src/main/java/org/jabref/gui/actions/ShowPreferencesAction.java new file mode 100644 index 00000000000..c6b551ef0a9 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/ShowPreferencesAction.java @@ -0,0 +1,30 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.preftabs.PreferencesDialog; + +public class ShowPreferencesAction extends SimpleCommand { + + private PreferencesDialog prefsDialog; + private final JabRefFrame jabRefFrame; + + public ShowPreferencesAction(JabRefFrame jabRefFrame) { + this.jabRefFrame = jabRefFrame; + } + + @Override + public void execute() { + // output(Localization.lang("Opening preferences...")); + if (prefsDialog == null) { + prefsDialog = new PreferencesDialog(jabRefFrame); + //prefsDialog.setLocationRelativeTo(JabRefFrame.this); + } else { + prefsDialog.setValues(); + } + + prefsDialog.setVisible(true); + //output(""); + + } + +} diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java index 1850dc3f321..a042f5e3d08 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java @@ -60,7 +60,7 @@ public class ExternalFileTypeEditor extends JabRefDialog { private final EditListener editListener = new EditListener(); - private ExternalFileTypeEditor(JFrame frame) { + public ExternalFileTypeEditor(JFrame frame) { super(frame, Localization.lang("Manage external file types"), true, ExternalFileTypeEditor.class); this.frame = frame; init(); diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalsAction.java b/src/main/java/org/jabref/gui/journals/ManageJournalsAction.java deleted file mode 100644 index cfb89cdd255..00000000000 --- a/src/main/java/org/jabref/gui/journals/ManageJournalsAction.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.jabref.gui.journals; - -import java.awt.event.ActionEvent; - -import javax.swing.Action; - -import javafx.application.Platform; - -import org.jabref.gui.actions.MnemonicAwareAction; -import org.jabref.logic.l10n.Localization; - -public class ManageJournalsAction extends MnemonicAwareAction { - - public ManageJournalsAction() { - super(); - putValue(Action.NAME, Localization.menuTitle("Manage journal abbreviations")); - } - - @Override - public void actionPerformed(ActionEvent actionEvent) { - Platform.runLater(() -> new ManageJournalAbbreviationsView().show()); - } -} diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBindingAction.java b/src/main/java/org/jabref/gui/keyboard/KeyBindingAction.java deleted file mode 100644 index 47c94c20d90..00000000000 --- a/src/main/java/org/jabref/gui/keyboard/KeyBindingAction.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.jabref.gui.keyboard; - -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; -import javax.swing.Action; - -import javafx.application.Platform; - -import org.jabref.gui.IconTheme; -import org.jabref.logic.l10n.Localization; - -public class KeyBindingAction extends AbstractAction { - - - public KeyBindingAction() { - super(Localization.lang("Customize key bindings")); - this.putValue(Action.SMALL_ICON, IconTheme.JabRefIcons.KEY_BINDINGS.getSmallIcon()); - } - - @Override - public void actionPerformed(ActionEvent e) { - Platform.runLater(() -> { - KeyBindingsDialogView view = new KeyBindingsDialogView(); - view.show(); - }); - } - -} diff --git a/src/main/java/osx/macadapter/MacAdapter.java b/src/main/java/osx/macadapter/MacAdapter.java index 34a33cb8e34..9c7938aa5f6 100644 --- a/src/main/java/osx/macadapter/MacAdapter.java +++ b/src/main/java/osx/macadapter/MacAdapter.java @@ -73,7 +73,7 @@ public void handlePreferences(PreferencesEvent arg0) { return; } - parentFrame.showPreferencesDialog(); + // parentFrame.showPreferencesDialog(); } @Override From 6033faa79dd3fd2edd1e4f9829bf14100a1c5a42 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 10 Feb 2018 00:09:58 +0100 Subject: [PATCH 054/827] Convert side pane to JavaFX --- src/main/java/org/jabref/JabRefGUI.java | 2 +- src/main/java/org/jabref/gui/BasePanel.java | 9 +- src/main/java/org/jabref/gui/IconTheme.java | 8 + src/main/java/org/jabref/gui/JabRefFrame.java | 97 ++---- src/main/java/org/jabref/gui/Main.css | 8 +- src/main/java/org/jabref/gui/SidePane.java | 92 +---- .../org/jabref/gui/SidePaneComponent.java | 204 +++++------ .../java/org/jabref/gui/SidePaneManager.java | 316 +++++++----------- .../java/org/jabref/gui/SidePaneType.java | 8 + .../org/jabref/gui/actions/ActionsFX.java | 5 +- .../gui/collab/DatabaseChangeMonitor.java | 16 +- .../jabref/gui/collab/FileUpdatePanel.java | 77 +++-- .../gui/exporter/SaveDatabaseAction.java | 8 +- .../org/jabref/gui/groups/GroupSidePane.java | 77 ++--- .../gui/importer/fetcher/GeneralFetcher.java | 70 ++-- .../gui/openoffice/OpenOfficePanel.java | 68 ++-- .../gui/openoffice/OpenOfficeSidePanel.java | 53 +-- .../jabref/preferences/JabRefPreferences.java | 36 ++ 18 files changed, 491 insertions(+), 663 deletions(-) create mode 100644 src/main/java/org/jabref/gui/SidePaneType.java diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index d796b1130ba..058fb250bed 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -100,7 +100,7 @@ private void openWindow(Stage mainStage) { GUIGlobals.init(); LOGGER.debug("Initializing frame"); - JabRefGUI.mainFrame = new JabRefFrame(); + JabRefGUI.mainFrame = new JabRefFrame(mainStage); // Add all bibDatabases databases to the frame: boolean first = false; diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index f8321254548..3b50e57fb08 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1749,12 +1749,11 @@ public void lostOwnership(Clipboard clipboard, Transferable contents) { public void cleanUp() { changeMonitor.ifPresent(DatabaseChangeMonitor::unregister); - // Check if there is a FileUpdatePanel for this BasePanel being shown. If so, - // remove it: - if (sidePaneManager.hasComponent(FileUpdatePanel.class)) { - FileUpdatePanel fup = (FileUpdatePanel) sidePaneManager.getComponent(FileUpdatePanel.class); + // Check if there is a FileUpdatePanel for this BasePanel being shown. If so remove it: + if (sidePaneManager.isComponentVisible(SidePaneType.FILE_UPDATE_NOTIFICATION)) { + FileUpdatePanel fup = (FileUpdatePanel) sidePaneManager.getComponent(SidePaneType.FILE_UPDATE_NOTIFICATION); if (fup.getPanel() == this) { - sidePaneManager.hideComponent(FileUpdatePanel.class); + sidePaneManager.hide(SidePaneType.FILE_UPDATE_NOTIFICATION); } } } diff --git a/src/main/java/org/jabref/gui/IconTheme.java b/src/main/java/org/jabref/gui/IconTheme.java index 9a31da6f292..ef21e3e9bf7 100644 --- a/src/main/java/org/jabref/gui/IconTheme.java +++ b/src/main/java/org/jabref/gui/IconTheme.java @@ -24,6 +24,7 @@ import javax.swing.ImageIcon; import javafx.scene.Node; +import javafx.scene.control.Button; import javafx.scene.image.Image; import javafx.scene.image.ImageView; @@ -356,6 +357,13 @@ public JabRefIcon disabled() { throw new NotImplementedException("Cannot create disabled version of a file-based icon"); } } + + public Button asButton() { + Button button = new Button(); + button.setGraphic(getGraphicNode()); + button.getStyleClass().add("flatButton"); + return button; + } } public static class FontBasedIcon implements Icon { diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 335395a377b..8c946e07920 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -10,7 +10,6 @@ import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.io.File; import java.io.IOException; @@ -47,10 +46,9 @@ import javax.swing.UIManager; import javafx.application.Platform; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.collections.ListChangeListener; -import javafx.embed.swing.JFXPanel; -import javafx.embed.swing.SwingNode; -import javafx.scene.Scene; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.SeparatorMenuItem; @@ -59,6 +57,7 @@ import javafx.scene.control.TabPane; import javafx.scene.control.Tooltip; import javafx.scene.layout.BorderPane; +import javafx.stage.Stage; import org.jabref.Globals; import org.jabref.JabRefExecutorService; @@ -83,7 +82,6 @@ import org.jabref.gui.bibtexkeypattern.BibtexKeyPatternDialog; import org.jabref.gui.copyfiles.CopyFilesAction; import org.jabref.gui.customentrytypes.EntryCustomizationDialog; -import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.dbproperties.DatabasePropertiesDialog; import org.jabref.gui.documentviewer.ShowDocumentViewerAction; import org.jabref.gui.exporter.ExportCommand; @@ -93,20 +91,17 @@ import org.jabref.gui.externalfiletype.ExternalFileTypeEditor; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.groups.EntryTableTransferHandler; -import org.jabref.gui.groups.GroupSidePane; import org.jabref.gui.help.AboutAction; import org.jabref.gui.help.HelpAction; import org.jabref.gui.importer.ImportCommand; import org.jabref.gui.importer.ImportCustomizationDialog; import org.jabref.gui.importer.ImportInspectionDialog; import org.jabref.gui.importer.actions.OpenDatabaseAction; -import org.jabref.gui.importer.fetcher.GeneralFetcher; import org.jabref.gui.journals.ManageJournalsAction; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.keyboard.KeyBindingAction; import org.jabref.gui.menus.ChangeEntryTypeMenu; import org.jabref.gui.menus.FileHistoryMenu; -import org.jabref.gui.openoffice.OpenOfficePanel; import org.jabref.gui.preftabs.PreferencesDialog; import org.jabref.gui.protectedterms.ProtectedTermsDialog; import org.jabref.gui.push.PushToApplicationButton; @@ -381,6 +376,7 @@ public void actionPerformed(ActionEvent e) { private final List oneEntryWithURLorDOIOnlyActions = new LinkedList<>(); private final List twoEntriesOnlyActions = new LinkedList<>(); private final List atLeastOneEntryActions = new LinkedList<>(); + private final Stage mainStage; private PreferencesDialog prefsDialog; // The sidepane manager takes care of populating the sidepane. private SidePaneManager sidePaneManager; @@ -390,13 +386,11 @@ public void actionPerformed(ActionEvent e) { private JMenu rankSubMenu; private PushToApplicationButton pushExternalButton; private PushToApplications pushApplications; - private GeneralFetcher generalFetcher; - private OpenOfficePanel openOfficePanel; - private GroupSidePane groupSidePane; private JMenu newSpec; private final CountingUndoManager undoManager = new CountingUndoManager(); - public JabRefFrame() { + public JabRefFrame(Stage mainStage) { + this.mainStage = mainStage; init(); } @@ -494,7 +488,7 @@ private void init() { // TODO: popup // tabbedPane = new DragDropPopupPane(tabPopupMenu()); - initSidePane(); + sidePaneManager = new SidePaneManager(Globals.prefs, this); initLayout(); @@ -545,10 +539,10 @@ private void init() { currentBasePanel.getPreviewPanel().updateLayout(Globals.prefs.getPreviewPreferences()); - // groupSidePane.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class)); + // groupSidePane.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class)); //previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); - //generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class)); - //openOfficePanel.getToggleAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class)); + //generalFetcher.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class)); + //openOfficePanel.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class)); // TODO: Can't notify focus listener since it is expecting a swing component //Globals.getFocusListener().setFocused(currentBasePanel.getMainTable()); setWindowTitle(); @@ -637,20 +631,6 @@ public void setWindowTitle() { } } - private void initSidePane() { - sidePaneManager = new SidePaneManager(this); - - groupSidePane = new GroupSidePane(this, sidePaneManager); - if (prefs.getBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE)) { - sidePaneManager.register(groupSidePane); - sidePaneManager.show(GroupSidePane.class); - } - openOfficePanel = new OpenOfficePanel(this, sidePaneManager); - generalFetcher = new GeneralFetcher(this, sidePaneManager); - - sidePaneManager.register(groupSidePane); - } - /** * The MacAdapter calls this method when a "BIB" file has been double-clicked from the Finder. */ @@ -826,39 +806,26 @@ private void initLayout() { toolbarPanel.add(globalSearchBar); //getContentPane().add(toolbarPanel, BorderLayout.PAGE_START); - JFXPanel tabbedPaneContainer = CustomJFXPanel.wrap(new Scene(tabbedPane)); - // TODO: Remove this hack as soon as toolbar is implemented in JavaFX and these events are no longer captured globally - tabbedPaneContainer.addKeyListener(new KeyAdapter() { + splitPane.getItems().addAll(sidePaneManager.getPane(), tabbedPane); + + // We need to wait with setting the divider since it gets reset a few times during the initial set-up + mainStage.showingProperty().addListener(new ChangeListener() { + @Override - public void keyPressed(KeyEvent e) { - // We need to consume a few events that have a global listener - // Otherwise, they propagate to the JFrame (i.e. "Ctrl + A" in the entry editor still triggers the "Select all" action) - Optional keyBinding = Globals.getKeyPrefs().mapToKeyBinding(e); - if (keyBinding.isPresent()) { - switch (keyBinding.get()) { - case CUT: - case COPY: - case PASTE: - case DELETE_ENTRY: - case SELECT_ALL: - e.consume(); - break; - default: - //do nothing - } + public void changed(ObservableValue observable, Boolean oldValue, Boolean showing) { + if (showing) { + splitPane.setDividerPositions(prefs.getDouble(JabRefPreferences.SIDE_PANE_WIDTH)); + EasyBind.subscribe(splitPane.getDividers().get(0).positionProperty(), + position -> prefs.putDouble(JabRefPreferences.SIDE_PANE_WIDTH, position.doubleValue())); + mainStage.showingProperty().removeListener(this); + observable.removeListener(this); } } }); - SwingNode swingSidePane = new SwingNode(); - SwingUtilities.invokeLater(() -> { - swingSidePane.setContent(sidePaneManager.getPanel()); - }); - splitPane.getItems().addAll(swingSidePane, tabbedPane); setCenter(splitPane); UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0)); - sidePaneManager.updateView(); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints con = new GridBagConstraints(); @@ -891,7 +858,7 @@ public void keyPressed(KeyEvent e) { //tabbedPane.setTransferHandler(xfer); tlb.setTransferHandler(xfer); // TODO: mb.setTransferHandler(xfer); - sidePaneManager.getPanel().setTransferHandler(xfer); + // TODO: sidePaneManager.getPanel().setTransferHandler(xfer); } /** @@ -1095,14 +1062,14 @@ private MenuBar createMenu() { /* search.add(normalSearch); search.addSeparator(); - search.add(new JCheckBoxMenuItem(generalFetcher.getToggleAction())); + search.add(new JCheckBoxMenuItem(generalFetcher.getToggleCommand())); if (prefs.getBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE)) { sidePaneManager.register(generalFetcher); sidePaneManager.show(GeneralFetcher.class); } mb.add(search); - groups.add(new JCheckBoxMenuItem(groupSidePane.getToggleAction())); + groups.add(new JCheckBoxMenuItem(groupSidePane.getToggleCommand())); groups.addSeparator(); groups.add(addToGroup); @@ -1122,8 +1089,8 @@ private MenuBar createMenu() { view.add(defaultFontSize); view.addSeparator(); view.add(new JCheckBoxMenuItem(toggleToolbar)); - view.add(new JCheckBoxMenuItem(enableToggle(generalFetcher.getToggleAction()))); - view.add(new JCheckBoxMenuItem(groupSidePane.getToggleAction())); + view.add(new JCheckBoxMenuItem(enableToggle(generalFetcher.getToggleCommand()))); + view.add(new JCheckBoxMenuItem(groupSidePane.getToggleCommand())); view.add(new JCheckBoxMenuItem(togglePreview)); view.add(showPdvViewer); view.add(getNextPreviewStyleAction()); @@ -1173,7 +1140,7 @@ private MenuBar createMenu() { tools.add(newSubDatabaseAction); tools.add(writeXmpAction); - tools.add(new JCheckBoxMenuItem(openOfficePanel.getToggleAction())); + tools.add(new JCheckBoxMenuItem(openOfficePanel.getToggleCommand())); tools.add(pushExternalButton.getMenuAction()); tools.addSeparator(); tools.add(openFolder); @@ -1335,12 +1302,12 @@ private void createToolBar() { } tlb.addSeparator(); - tlb.addJToggleButton(new JToggleButton(generalFetcher.getToggleAction())); + tlb.addJToggleButton(new JToggleButton(generalFetcher.getToggleCommand())); previewToggle = new JToggleButton(togglePreview); tlb.addJToggleButton(previewToggle); - tlb.addJToggleButton(new JToggleButton(groupSidePane.getToggleAction())); + tlb.addJToggleButton(new JToggleButton(groupSidePane.getToggleCommand())); tlb.addSeparator(); @@ -1371,8 +1338,8 @@ private void initActions() { openDatabaseOnlyActions.addAll(Arrays.asList(manageSelectors, mergeDatabaseAction, newSubDatabaseAction, save, copyPreview, saveAs, saveSelectedAs, saveSelectedAsPlain, undo, redo, cut, deleteEntry, copy, paste, mark, markSpecific, unmark, unmarkAll, rankSubMenu, editEntry, selectAll, copyKey, copyCiteKey, copyKeyAndTitle, copyKeyAndLink, editPreamble, editStrings, - groupSidePane.getToggleAction(), makeKeyAction, normalSearch, generalFetcher.getToggleAction(), mergeEntries, cleanupEntries, exportToClipboard, replaceAll, - sendAsEmail, downloadFullText, lookupIdentifiers, writeXmpAction, openOfficePanel.getToggleAction(), findUnlinkedFiles, addToGroup, removeFromGroup, + groupSidePane.getToggleCommand(), makeKeyAction, normalSearch, generalFetcher.getToggleCommand(), mergeEntries, cleanupEntries, exportToClipboard, replaceAll, + sendAsEmail, downloadFullText, lookupIdentifiers, writeXmpAction, openOfficePanel.getToggleCommand(), findUnlinkedFiles, addToGroup, removeFromGroup, moveToGroup, autoLinkFile, resolveDuplicateKeys, openUrl, openFolder, openFile, togglePreview, dupliCheck, autoSetFile, newEntryAction, newSpec, customizeAction, plainTextImport, getMassSetField(), getManageKeywords(), pushExternalButton.getMenuAction(), closeDatabaseAction, getNextPreviewStyleAction(), getPreviousPreviewStyleAction(), checkIntegrity, diff --git a/src/main/java/org/jabref/gui/Main.css b/src/main/java/org/jabref/gui/Main.css index 7c0488cdd1a..b1f7b7c5d66 100644 --- a/src/main/java/org/jabref/gui/Main.css +++ b/src/main/java/org/jabref/gui/Main.css @@ -34,9 +34,9 @@ -fx-accented-background: #dadad8; /* - * A dark gray as background + * A darker gray as background */ - -fx-dark-background: #757575; + -fx-dark-background: #aaaaaa; /* * A strong white as background @@ -260,3 +260,7 @@ -fx-background: -fx-selection-bar; -fx-table-cell-border-color: transparent; } + +.sidePaneComponentHeader { + -fx-background-color: -fx-dark-background; +} diff --git a/src/main/java/org/jabref/gui/SidePane.java b/src/main/java/org/jabref/gui/SidePane.java index 353b74bfc6f..b4f22230346 100644 --- a/src/main/java/org/jabref/gui/SidePane.java +++ b/src/main/java/org/jabref/gui/SidePane.java @@ -1,94 +1,30 @@ package org.jabref.gui; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; import java.util.Collection; -import javax.swing.Box; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.ScrollPaneConstants; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.VBox; /** - * The side pane is displayed at the left side of JabRef and shows instances of - * SidePaneComponents, for instance the GroupSelector, or the SearchManager. + * The side pane is displayed at the left side of JabRef and shows instances of {@link SidePaneComponent}. */ -public class SidePane extends JPanel { - - private final Dimension PREFERRED_SIZE = new Dimension(220, 100); - - private final GridBagLayout gridBagLayout = new GridBagLayout(); - - private final GridBagConstraints constraint = new GridBagConstraints(); - - private final JPanel mainPanel = new JPanel(); +public class SidePane extends BorderPane { + private final VBox mainPanel = new VBox(); public SidePane() { - // For debugging the border: - // setBorder(BorderFactory.createLineBorder(Color.BLUE)); - - setLayout(new BorderLayout()); - mainPanel.setLayout(gridBagLayout); - - // Initialize constraint - constraint.anchor = GridBagConstraints.NORTH; - constraint.fill = GridBagConstraints.BOTH; - constraint.gridwidth = GridBagConstraints.REMAINDER; - constraint.insets = new Insets(1, 1, 1, 1); - constraint.gridheight = 1; - constraint.weightx = 1; - - /* - * Added Scrollpane to fix: - */ - JScrollPane sp = new JScrollPane(mainPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, - ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - sp.setBorder(null); - - // To remove the scroll panel just change sp to mainPanel and comment - // the JScrollPane declaration - super.add(sp); + setCenter(mainPanel); } - public void setComponents(Collection comps) { - mainPanel.removeAll(); + public void setComponents(Collection components) { + mainPanel.getChildren().clear(); - int totalWeights = 0; - for (SidePaneComponent c : comps) { - constraint.weighty = c.getRescalingWeight(); - totalWeights += c.getRescalingWeight(); - gridBagLayout.setConstraints(c, constraint); - mainPanel.add(c); + for (SidePaneComponent component : components) { + BorderPane node = new BorderPane(); + node.setTop(component.getHeader()); + node.setCenter(component.getContentPane()); + mainPanel.getChildren().add(node); + VBox.setVgrow(node, component.getResizePolicy()); } - if (totalWeights <= 0) { - // Fill vertical space so that components start at top - constraint.weighty = 1; - Component bx = Box.createVerticalGlue(); - gridBagLayout.setConstraints(bx, constraint); - mainPanel.add(bx); - } - - revalidate(); - repaint(); - } - - @Override - public void remove(Component c) { - mainPanel.remove(c); - } - - @Override - public Dimension getMaximumSize() { - return getPreferredSize(); - } - - @Override - public Dimension getPreferredSize() { - return PREFERRED_SIZE; } } diff --git a/src/main/java/org/jabref/gui/SidePaneComponent.java b/src/main/java/org/jabref/gui/SidePaneComponent.java index 911ed8b59c4..ea7a7f160f8 100644 --- a/src/main/java/org/jabref/gui/SidePaneComponent.java +++ b/src/main/java/org/jabref/gui/SidePaneComponent.java @@ -1,78 +1,36 @@ package org.jabref.gui; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.InputEvent; +import javafx.scene.Node; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JToolBar; -import javax.swing.KeyStroke; +import org.jabref.gui.actions.ActionsFX; +import org.jabref.gui.actions.SimpleCommand; -import org.jabref.gui.actions.MnemonicAwareAction; - -public abstract class SidePaneComponent extends JPanel { - - protected final JButton close = new JButton(IconTheme.JabRefIcons.CLOSE.getSmallIcon()); +public abstract class SidePaneComponent { protected final SidePaneManager manager; + protected final ToggleCommand toggleCommand; + private final JabRefIcon icon; + private final String title; + private Node contentNode; - protected BasePanel panel; - - - public SidePaneComponent(SidePaneManager manager, Icon icon, String title) { - super(new BorderLayout()); + public SidePaneComponent(SidePaneManager manager, JabRefIcon icon, String title) { this.manager = manager; - - setBorder(BorderFactory.createEmptyBorder()); - - close.setMargin(new Insets(0, 0, 0, 0)); - close.setBorder(null); - close.addActionListener(e -> hideAway()); - - JButton up = new JButton(IconTheme.JabRefIcons.UP.getSmallIcon()); - up.setMargin(new Insets(0, 0, 0, 0)); - up.setBorder(null); - up.addActionListener(e -> moveUp()); - - JButton down = new JButton(IconTheme.JabRefIcons.DOWN.getSmallIcon()); - down.setMargin(new Insets(0, 0, 0, 0)); - down.setBorder(null); - down.addActionListener(e -> moveDown()); - - JPanel titlePanel = new JPanel(new BorderLayout()); - titlePanel.add(new JLabel(icon), BorderLayout.WEST); - JLabel titleLabel = new JLabel(title); - titleLabel.setOpaque(true); - titleLabel.setForeground(new Color(79, 95, 143)); - titlePanel.add(titleLabel, BorderLayout.CENTER); - - JToolBar toolbar = new OSXCompatibleToolbar(); - toolbar.add(up); - toolbar.add(down); - toolbar.add(close); - toolbar.setOpaque(false); - toolbar.setFloatable(false); - - titlePanel.add(toolbar, BorderLayout.EAST); - - - this.add(titlePanel, BorderLayout.NORTH); + this.icon = icon; + this.title = title; + this.toggleCommand = new ToggleCommand(this); } - public void setContentContainer(JPanel panel) { - this.add(panel, BorderLayout.CENTER); + protected void hide() { + manager.hide(this.getType()); } - private void hideAway() { - manager.hideComponent(this); + protected void show() { + manager.show(this.getType()); } private void moveUp() { @@ -83,83 +41,99 @@ private void moveDown() { manager.moveDown(this); } - public void setActiveBasePanel(BasePanel panel) { - this.panel = panel; + /** + * Override this method if the component needs to make any changes before it can close. + */ + public void beforeClosing() { + // Nothing to do by default } - public BasePanel getActiveBasePanel() { - return panel; + /** + * Override this method if the component needs to do any actions after it is shown. + */ + public void afterOpening() { + // Nothing to do by default } /** - * Override this method if the component needs to make any changes before it can close. + * Specifies how to this side pane component behaves if there is additional vertical space. */ - public void componentClosing() { - // Nothing right now + public abstract Priority getResizePolicy(); + + /** + * @return the command which toggles this {@link SidePaneComponent} + */ + public ToggleCommand getToggleCommand() { + return toggleCommand; } /** - * Override this method if the component needs to do any actions when opening. + * @return the action to toggle this {@link SidePaneComponent} */ - public void componentOpening() { - // Nothing right now + public abstract ActionsFX getToggleAction(); + + /** + * @return the content of this component + */ + public final Node getContentPane() { + if (contentNode == null) { + contentNode = createContentPane(); + } + + return contentNode; } - @Override - public Dimension getMinimumSize() { - return getPreferredSize(); + /** + * @return the header pane for this component + */ + public final Node getHeader() { + Button close = IconTheme.JabRefIcons.CLOSE.asButton(); + close.setOnAction(event -> hide()); + + Button up = IconTheme.JabRefIcons.UP.asButton(); + up.setOnAction(event -> moveUp()); + + Button down = IconTheme.JabRefIcons.DOWN.asButton(); + down.setOnAction(event -> moveDown()); + + HBox buttonContainer = new HBox(); + buttonContainer.getChildren().addAll(up, down, close); + BorderPane graphic = new BorderPane(); + graphic.setCenter(icon.getGraphicNode()); + BorderPane container = new BorderPane(); + container.setLeft(graphic); + container.setCenter(new Label(title)); + container.setRight(buttonContainer); + container.getStyleClass().add("sidePaneComponentHeader"); + + return container; } /** - * Specifies how to distribute extra vertical space between side pane components. - * 0: fixed height, 1: fill the remaining space + * Create the content of this component + * + * @implNote The {@link SidePaneManager} always creates an instance of every side component (e.g., to get the toggle action) + * but we only want to create the content view if the component is shown to save resources. + * This is the reason for the lazy loading. */ - public abstract int getRescalingWeight(); + protected abstract Node createContentPane(); /** - * @return the action which toggles this {@link SidePaneComponent} + * @return the type of this component */ - public abstract ToggleAction getToggleAction(); + public abstract SidePaneType getType(); - public class ToggleAction extends MnemonicAwareAction { + public class ToggleCommand extends SimpleCommand { - public ToggleAction(String text, String description, KeyStroke key, JabRefIcon icon) { - super(icon.getIcon()); - putValue(Action.NAME, text); - putValue(Action.ACCELERATOR_KEY, key); - putValue(Action.SHORT_DESCRIPTION, description); - } + private final SidePaneComponent component; - public ToggleAction(String text, String description, KeyStroke key, Icon icon) { - super(icon); - putValue(Action.NAME, text); - putValue(Action.ACCELERATOR_KEY, key); - putValue(Action.SHORT_DESCRIPTION, description); + public ToggleCommand(SidePaneComponent component) { + this.component = component; } @Override - public void actionPerformed(ActionEvent e) { - if (!manager.hasComponent(SidePaneComponent.this.getClass())) { - manager.register(SidePaneComponent.this); - } - - // if clicked by mouse just toggle - if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { - manager.toggle(SidePaneComponent.this.getClass()); - } else { - manager.toggleThreeWay(SidePaneComponent.this.getClass()); - } - putValue(Action.SELECTED_KEY, manager.isComponentVisible(SidePaneComponent.this.getClass())); - } - - public void setSelected(boolean selected) { - putValue(Action.SELECTED_KEY, selected); + public void execute() { + manager.toggle(component.getType()); } - - public boolean isSelected() { - return Boolean.TRUE.equals(getValue(Action.SELECTED_KEY)); - } - } - } diff --git a/src/main/java/org/jabref/gui/SidePaneManager.java b/src/main/java/org/jabref/gui/SidePaneManager.java index b3884471cc0..b70959990e7 100644 --- a/src/main/java/org/jabref/gui/SidePaneManager.java +++ b/src/main/java/org/jabref/gui/SidePaneManager.java @@ -1,231 +1,137 @@ package org.jabref.gui; -import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; +import java.util.stream.Stream; import org.jabref.Globals; -import org.jabref.gui.maintable.MainTable; +import org.jabref.gui.collab.FileUpdatePanel; +import org.jabref.gui.groups.GroupSidePane; +import org.jabref.gui.importer.fetcher.GeneralFetcher; +import org.jabref.gui.openoffice.OpenOfficeSidePanel; +import org.jabref.logic.openoffice.OpenOfficePreferences; import org.jabref.preferences.JabRefPreferences; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** - * Manages visibility of SideShowComponents in a given newly constructed - * sidePane. + * Manages which {@link SidePaneComponent}s are shown. */ public class SidePaneManager { - private static final Logger LOGGER = LoggerFactory.getLogger(SidePaneManager.class); - private final JabRefFrame frame; + private final SidePane sidePane; + private final Map components = new LinkedHashMap<>(); + private final List visibleComponents = new LinkedList<>(); + private final JabRefPreferences preferences; - private final SidePane sidep; + public SidePaneManager(JabRefPreferences preferences, JabRefFrame frame) { + this.preferences = preferences; + this.sidePane = new SidePane(); - private final Map, SidePaneComponent> components = new LinkedHashMap<>(); + OpenOfficePreferences openOfficePreferences = new OpenOfficePreferences(preferences); + Stream.of( + new FileUpdatePanel(this), + new GroupSidePane(this, preferences), + new GeneralFetcher(this, preferences, frame), + new OpenOfficeSidePanel(this, openOfficePreferences, frame)) + .forEach(pane -> components.put(pane.getType(), pane)); - private final List visible = new LinkedList<>(); + if (preferences.getBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE)) { + show(SidePaneType.GROUPS); + } - public SidePaneManager(JabRefFrame frame) { - this.frame = frame; - /* - * Change by Morten Alver 2005.12.04: By postponing the updating of the - * side pane components, we get rid of the annoying latency when - * switching tabs: - */ - //frame.getTabbedPane().addChangeListener(event -> SwingUtilities.invokeLater( - // () -> setActiveBasePanel(SidePaneManager.this.frame.getCurrentBasePanel()))); - sidep = new SidePane(); - sidep.setVisible(false); + if (openOfficePreferences.showPanel()) { + show(SidePaneType.OPEN_OFFICE); + } } - public SidePane getPanel() { - return sidep; + public SidePane getPane() { + return sidePane; } - public synchronized boolean hasComponent(Class sidePaneComponent) { - return components.containsKey(sidePaneComponent); + public boolean isComponentVisible(SidePaneType type) { + return visibleComponents.contains(getComponent(type)); } - public synchronized boolean isComponentVisible(Class sidePaneComponent) { - SidePaneComponent component = components.get(sidePaneComponent); + public SidePaneComponent getComponent(SidePaneType type) { + SidePaneComponent component = components.get(type); if (component == null) { - return false; + throw new IllegalStateException("Side component " + type + " not registered."); } else { - return visible.contains(component); + return component; } } /** - * If panel is visible it will be hidden and the other way around + * If the given component is visible it will be hidden and the other way around. */ - public synchronized void toggle(Class sidePaneComponent) { - if (isComponentVisible(sidePaneComponent)) { - hide(sidePaneComponent); + public void toggle(SidePaneType type) { + if (isComponentVisible(type)) { + hide(type); } else { - show(sidePaneComponent); + show(type); } } /** - * If panel is hidden it will be shown and focused - * If panel is visible but not focused it will be focused - * If panel is visible and focused it will be hidden + * Makes sure that the given component is visible. */ - public synchronized void toggleThreeWay(Class sidePaneComponent) { - boolean isPanelFocused = Globals.getFocusListener().getFocused() == components.get(sidePaneComponent); - if (isComponentVisible(sidePaneComponent) && isPanelFocused) { - hide(sidePaneComponent); - } else { - show(sidePaneComponent); - } - } - - public synchronized void show(Class sidePaneComponent) { - SidePaneComponent component = components.get(sidePaneComponent); - if (component == null) { - LOGGER.warn("Side pane component '" + sidePaneComponent + "' unknown."); - } else { - show(component); - } - } - - public synchronized void hide(Class sidePaneComponent) { - SidePaneComponent component = components.get(sidePaneComponent); - if (component == null) { - LOGGER.warn("Side pane component '" + sidePaneComponent + "' unknown."); - } else { - hideComponent(component); - if (frame.getCurrentBasePanel() != null) { - MainTable mainTable = frame.getCurrentBasePanel().getMainTable(); - //mainTable.setSelected(mainTable.getSelectedRow()); - mainTable.requestFocus(); - } - } - } - - public synchronized void register(SidePaneComponent comp) { - components.put(comp.getClass(), comp); - } - - private synchronized void show(SidePaneComponent component) { - if (!visible.contains(component)) { - // Put the new component at the top of the group - visible.add(0, component); + public void show(SidePaneType type) { + SidePaneComponent component = getComponent(type); + if (!visibleComponents.contains(component)) { + // Add the new component + visibleComponents.add(component); // Sort the visible components by their preferred position - Collections.sort(visible, new PreferredIndexSort()); + visibleComponents.sort(new PreferredIndexSort()); updateView(); - component.componentOpening(); - } - Globals.getFocusListener().setFocused(component); - component.grabFocus(); - } - - public synchronized SidePaneComponent getComponent(Class sidePaneComponent) { - return components.get(sidePaneComponent); - } - - public synchronized void hideComponent(SidePaneComponent comp) { - if (visible.contains(comp)) { - comp.componentClosing(); - visible.remove(comp); - updateView(); - } - } - public synchronized void hideComponent(Class sidePaneComponent) { - SidePaneComponent component = components.get(sidePaneComponent); - if (component == null) { - return; - } - if (visible.contains(component)) { - component.componentClosing(); - visible.remove(component); - updateView(); + component.afterOpening(); } } - private static Map, Integer> getPreferredPositions() { - Map, Integer> preferredPositions = new HashMap<>(); + /** + * Makes sure that the given component is not visible. + */ + public void hide(SidePaneType type) { + SidePaneComponent component = getComponent(type); + if (visibleComponents.contains(component)) { + component.beforeClosing(); - List componentNames = Globals.prefs.getStringList(JabRefPreferences.SIDE_PANE_COMPONENT_NAMES); - List componentPositions = Globals.prefs - .getStringList(JabRefPreferences.SIDE_PANE_COMPONENT_PREFERRED_POSITIONS); + visibleComponents.remove(component); - for (int i = 0; i < componentNames.size(); ++i) { - String componentName = componentNames.get(i); - try { - Class componentClass = (Class) Class.forName(componentName); - preferredPositions.put(componentClass, Integer.parseInt(componentPositions.get(i))); - } catch (ClassNotFoundException e) { - LOGGER.debug("Following side pane could not be found: " + componentName, e); - } catch (ClassCastException e) { - LOGGER.debug("Following Class is no side pane: '" + componentName, e); - } catch (NumberFormatException e) { - LOGGER.debug("Invalid number format for side pane component '" + componentName + "'.", e); - } + updateView(); } - - return preferredPositions; } + /** + * Stores the current configuration of visible components in the preferences, + * so that we show components at the preferred position next time. + */ private void updatePreferredPositions() { - Map, Integer> preferredPositions = getPreferredPositions(); + Map preferredPositions = preferences.getSidePanePreferredPositions(); - // Update the preferred positions of all visible components + // Use the currently shown positions of all visible components int index = 0; - for (SidePaneComponent comp : visible) { - preferredPositions.put(comp.getClass(), index); + for (SidePaneComponent comp : visibleComponents) { + preferredPositions.put(comp.getType(), index); index++; } - - // Split the map into a pair of parallel String lists suitable for storage - List tmpComponentNames = preferredPositions.keySet().parallelStream() - .map(Class::getName) - .collect(Collectors.toList()); - - List componentPositions = preferredPositions.values().stream().map(Object::toString) - .collect(Collectors.toList()); - - Globals.prefs.putStringList(JabRefPreferences.SIDE_PANE_COMPONENT_NAMES, tmpComponentNames); - Globals.prefs.putStringList(JabRefPreferences.SIDE_PANE_COMPONENT_PREFERRED_POSITIONS, componentPositions); + preferences.storeSidePanePreferredPositions(preferredPositions); } - /** - * Helper class for sorting visible components based on their preferred position + * Moves the given component up. */ - private class PreferredIndexSort implements Comparator { - - private final Map, Integer> preferredPositions; - - - public PreferredIndexSort() { - preferredPositions = getPreferredPositions(); - } - - @Override - public int compare(SidePaneComponent comp1, SidePaneComponent comp2) { - int pos1 = preferredPositions.getOrDefault(comp1.getClass(), 0); - int pos2 = preferredPositions.getOrDefault(comp2.getClass(), 0); - return Integer.valueOf(pos1).compareTo(pos2); - } - } - - public synchronized void moveUp(SidePaneComponent comp) { - if (visible.contains(comp)) { - int currIndex = visible.indexOf(comp); - if (currIndex > 0) { - int newIndex = currIndex - 1; - visible.remove(currIndex); - visible.add(newIndex, comp); + public void moveUp(SidePaneComponent component) { + if (visibleComponents.contains(component)) { + int currentPosition = visibleComponents.indexOf(component); + if (currentPosition > 0) { + int newPosition = currentPosition - 1; + visibleComponents.remove(currentPosition); + visibleComponents.add(newPosition, component); updatePreferredPositions(); updateView(); @@ -233,13 +139,16 @@ public synchronized void moveUp(SidePaneComponent comp) { } } - public synchronized void moveDown(SidePaneComponent comp) { - if (visible.contains(comp)) { - int currIndex = visible.indexOf(comp); - if (currIndex < (visible.size() - 1)) { - int newIndex = currIndex + 1; - visible.remove(currIndex); - visible.add(newIndex, comp); + /** + * Moves the given component down. + */ + public void moveDown(SidePaneComponent comp) { + if (visibleComponents.contains(comp)) { + int currentPosition = visibleComponents.indexOf(comp); + if (currentPosition < (visibleComponents.size() - 1)) { + int newPosition = currentPosition + 1; + visibleComponents.remove(currentPosition); + visibleComponents.add(newPosition, comp); updatePreferredPositions(); updateView(); @@ -247,42 +156,45 @@ public synchronized void moveDown(SidePaneComponent comp) { } } - public synchronized void unregisterComponent(Class sidePaneComponent) { - components.remove(sidePaneComponent); - } - /** - * Update all side pane components to show information from the given - * BasePanel. - * - * @param panel + * Updates the view to reflect changes to visible components. */ - private synchronized void setActiveBasePanel(BasePanel panel) { - for (SidePaneComponent component : components.values()) { - component.setActiveBasePanel(panel); - } - } + private void updateView() { + sidePane.setComponents(visibleComponents); - public synchronized void updateView() { - sidep.setComponents(visible); - /* - if (visible.isEmpty()) { - if (sidep.isVisible()) { - Globals.prefs.putInt(JabRefPreferences.SIDE_PANE_WIDTH, frame.getSplitPane().getDividerLocation()); + if (visibleComponents.isEmpty()) { + if (sidePane.isVisible()) { + preferences.putDouble(JabRefPreferences.SIDE_PANE_WIDTH, sidePane.getWidth()); } - sidep.setVisible(false); + sidePane.setVisible(false); } else { - boolean wasVisible = sidep.isVisible(); - sidep.setVisible(true); + boolean wasVisible = sidePane.isVisible(); + sidePane.setVisible(true); if (!wasVisible) { - int width = Globals.prefs.getInt(JabRefPreferences.SIDE_PANE_WIDTH); + double width = preferences.getDouble(JabRefPreferences.SIDE_PANE_WIDTH); if (width > 0) { - frame.getSplitPane().setDividerLocation(width); - } else { - frame.getSplitPane().setDividerLocation(getPanel().getPreferredSize().width); + sidePane.setPrefWidth(width); } } } - */ + } + + /** + * Helper class for sorting visible components based on their preferred position. + */ + private class PreferredIndexSort implements Comparator { + + private final Map preferredPositions; + + public PreferredIndexSort() { + preferredPositions = Globals.prefs.getSidePanePreferredPositions(); + } + + @Override + public int compare(SidePaneComponent comp1, SidePaneComponent comp2) { + int pos1 = preferredPositions.getOrDefault(comp1.getType(), 0); + int pos2 = preferredPositions.getOrDefault(comp2.getType(), 0); + return Integer.compare(pos1, pos2); + } } } diff --git a/src/main/java/org/jabref/gui/SidePaneType.java b/src/main/java/org/jabref/gui/SidePaneType.java new file mode 100644 index 00000000000..cd60411cf61 --- /dev/null +++ b/src/main/java/org/jabref/gui/SidePaneType.java @@ -0,0 +1,8 @@ +package org.jabref.gui; + +/** + * Definition of all possible components in the side pane. + */ +public enum SidePaneType { + OPEN_OFFICE, WEB_SEARCH, FILE_UPDATE_NOTIFICATION, GROUPS +} diff --git a/src/main/java/org/jabref/gui/actions/ActionsFX.java b/src/main/java/org/jabref/gui/actions/ActionsFX.java index c5b8e1fafe8..e0b75c8e945 100644 --- a/src/main/java/org/jabref/gui/actions/ActionsFX.java +++ b/src/main/java/org/jabref/gui/actions/ActionsFX.java @@ -83,7 +83,10 @@ public enum ActionsFX { sendAsEmail(Localization.lang("Send as email"), IconTheme.JabRefIcons.EMAIL), replaceAll(Localization.menuTitle("Replace string"), KeyBinding.REPLACE_STRING), manageKeywords(Localization.menuTitle("Manage keywords")), - massSetField(Localization.menuTitle("Set/clear/append/rename fields")); + massSetField(Localization.menuTitle("Set/clear/append/rename fields")), + toggleGroups(Localization.lang("Toggle groups interface"), IconTheme.JabRefIcons.TOGGLE_GROUPS, KeyBinding.TOGGLE_GROUPS_INTERFACE), + toggleOpenOffice(Localization.lang("OpenOffice/LibreOffice connection"), IconTheme.JabRefIcons.FILE_OPENOFFICE, KeyBinding.OPEN_OPEN_OFFICE_LIBRE_OFFICE_CONNECTION), + toggleWebSearch(Localization.lang("Web search"), Localization.lang("Toggle web search interface"), IconTheme.JabRefIcons.WWW, KeyBinding.WEB_SEARCH); private final String text; private final String description; diff --git a/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java b/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java index bf73e9b098d..8b4424e870b 100644 --- a/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java +++ b/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java @@ -10,6 +10,7 @@ import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; import org.jabref.gui.SidePaneManager; +import org.jabref.gui.SidePaneType; import org.jabref.logic.util.io.FileBasedLock; import org.jabref.logic.util.io.FileUtil; import org.jabref.model.database.BibDatabaseContext; @@ -82,18 +83,15 @@ public void fileUpdated() { // thread: Runnable t = () -> { - // Check if there is already a notification about external - // changes: + // Check if there is already a notification about external changes: SidePaneManager sidePaneManager = panel.getSidePaneManager(); - boolean hasAlready = sidePaneManager.hasComponent(FileUpdatePanel.class); + boolean hasAlready = sidePaneManager.isComponentVisible(SidePaneType.FILE_UPDATE_NOTIFICATION); if (hasAlready) { - sidePaneManager.hideComponent(FileUpdatePanel.class); - sidePaneManager.unregisterComponent(FileUpdatePanel.class); + sidePaneManager.hide(SidePaneType.FILE_UPDATE_NOTIFICATION); } - FileUpdatePanel pan = new FileUpdatePanel(panel, sidePaneManager, - database.getDatabaseFile().orElse(null), scanner); - sidePaneManager.register(pan); - sidePaneManager.show(FileUpdatePanel.class); + + FileUpdatePanel component = (FileUpdatePanel) sidePaneManager.getComponent(SidePaneType.FILE_UPDATE_NOTIFICATION); + component.showForFile(panel, database.getDatabaseFile().orElse(null), scanner); }; if (scanner.changesFound()) { diff --git a/src/main/java/org/jabref/gui/collab/FileUpdatePanel.java b/src/main/java/org/jabref/gui/collab/FileUpdatePanel.java index 912c203aec6..79a563b599e 100644 --- a/src/main/java/org/jabref/gui/collab/FileUpdatePanel.java +++ b/src/main/java/org/jabref/gui/collab/FileUpdatePanel.java @@ -10,41 +10,39 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; + +import javafx.embed.swing.SwingNode; +import javafx.scene.Node; +import javafx.scene.layout.Priority; import org.jabref.gui.BasePanel; import org.jabref.gui.IconTheme; import org.jabref.gui.SidePaneComponent; import org.jabref.gui.SidePaneManager; +import org.jabref.gui.SidePaneType; +import org.jabref.gui.actions.ActionsFX; import org.jabref.logic.l10n.Localization; public class FileUpdatePanel extends SidePaneComponent implements ActionListener, ChangeScanner.DisplayResultCallback { private final SidePaneManager manager; + private ChangeScanner scanner; + private File file; + private BasePanel panel; - private final ChangeScanner scanner; + public FileUpdatePanel(SidePaneManager manager) { + super(manager, IconTheme.JabRefIcons.SAVE, Localization.lang("File changed")); + this.manager = manager; + } - public FileUpdatePanel(BasePanel panel, SidePaneManager manager, File file, ChangeScanner scanner) { - super(manager, IconTheme.JabRefIcons.SAVE.getIcon(), Localization.lang("File changed")); - close.setEnabled(false); + public void showForFile(BasePanel panel, File file, ChangeScanner scanner) { + this.file = file; this.panel = panel; - this.manager = manager; this.scanner = scanner; - JPanel main = new JPanel(); - main.setLayout(new BorderLayout()); - - JLabel message = new JLabel("
" - + Localization.lang("The file
'%0'
has been modified
externally!", file.getName()) - + "
", SwingConstants.CENTER); - - main.add(message, BorderLayout.CENTER); - JButton test = new JButton(Localization.lang("Review changes")); - main.add(test, BorderLayout.SOUTH); - main.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); - - add(main, BorderLayout.CENTER); - test.addActionListener(this); + this.show(); } /** @@ -56,25 +54,46 @@ public BasePanel getPanel() { return panel; } - /** - * Unregister when this component closes. We need that to avoid showing - * two such external change warnings at the same time, only the latest one. - */ @Override - public void componentClosing() { - manager.unregisterComponent(FileUpdatePanel.class); + public Priority getResizePolicy() { + return Priority.NEVER; } @Override - public int getRescalingWeight() { - return 0; + public ToggleCommand getToggleCommand() { + throw new UnsupportedOperationException(); } @Override - public ToggleAction getToggleAction() { + public ActionsFX getToggleAction() { throw new UnsupportedOperationException(); } + @Override + protected Node createContentPane() { + JPanel main = new JPanel(); + main.setLayout(new BorderLayout()); + + JLabel message = new JLabel("
" + + Localization.lang("The file
'%0'
has been modified
externally!", file.getName()) + + "
", SwingConstants.CENTER); + + main.add(message, BorderLayout.CENTER); + JButton reviewChanges = new JButton(Localization.lang("Review changes")); + reviewChanges.addActionListener(this); + main.add(reviewChanges, BorderLayout.SOUTH); + main.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); + + SwingNode swingNode = new SwingNode(); + SwingUtilities.invokeLater(() -> swingNode.setContent(main)); + return swingNode; + } + + @Override + public SidePaneType getType() { + return SidePaneType.FILE_UPDATE_NOTIFICATION; + } + /** * actionPerformed * @@ -103,7 +122,7 @@ public void actionPerformed(ActionEvent e) { @Override public void scanResultsResolved(boolean resolved) { if (resolved) { - manager.hideComponent(this); + manager.hide(this.getType()); panel.markExternalChangesAsResolved(); } } diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index d3143dd5193..574b73c26a3 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -8,7 +8,6 @@ import javax.swing.JOptionPane; import javax.swing.JTextArea; -import javax.swing.SwingUtilities; import org.jabref.Globals; import org.jabref.JabRefExecutorService; @@ -16,9 +15,9 @@ import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.SidePaneType; import org.jabref.gui.autosaveandbackup.AutosaveUIManager; import org.jabref.gui.collab.ChangeScanner; -import org.jabref.gui.collab.FileUpdatePanel; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.worker.AbstractWorker; @@ -425,8 +424,7 @@ private boolean checkExternalModification() { scanner.displayResult(resolved -> { if (resolved) { panel.markExternalChangesAsResolved(); - SwingUtilities - .invokeLater(() -> panel.getSidePaneManager().hide(FileUpdatePanel.class)); + DefaultTaskExecutor.runInJavaFXThread(() -> panel.getSidePaneManager().hide(SidePaneType.FILE_UPDATE_NOTIFICATION)); } else { canceled = true; } @@ -444,7 +442,7 @@ private boolean checkExternalModification() { canceled = true; } else { panel.markExternalChangesAsResolved(); - panel.getSidePaneManager().hide(FileUpdatePanel.class); + panel.getSidePaneManager().hide(SidePaneType.FILE_UPDATE_NOTIFICATION); } } } diff --git a/src/main/java/org/jabref/gui/groups/GroupSidePane.java b/src/main/java/org/jabref/gui/groups/GroupSidePane.java index dffa6529d2f..d984fac8fe6 100644 --- a/src/main/java/org/jabref/gui/groups/GroupSidePane.java +++ b/src/main/java/org/jabref/gui/groups/GroupSidePane.java @@ -1,92 +1,55 @@ package org.jabref.gui.groups; -import javafx.application.Platform; -import javafx.embed.swing.JFXPanel; -import javafx.scene.Scene; -import javafx.scene.layout.StackPane; +import javafx.scene.Node; +import javafx.scene.layout.Priority; -import org.jabref.Globals; -import org.jabref.gui.BasePanel; import org.jabref.gui.IconTheme; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.SidePaneComponent; import org.jabref.gui.SidePaneManager; -import org.jabref.gui.customjfx.CustomJFXPanel; -import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.gui.SidePaneType; +import org.jabref.gui.actions.ActionsFX; import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; /** * The groups side pane. - * This class is just a Swing wrapper around the JavaFX implementation {@link GroupTreeView}. */ public class GroupSidePane extends SidePaneComponent { - protected final JabRefFrame frame; - private final ToggleAction toggleAction; + private final JabRefPreferences preferences; - /** - * The first element for each group defines which field to use for the quicksearch. The next two define the name and - * regexp for the group. - */ - public GroupSidePane(JabRefFrame frame, SidePaneManager manager) { - super(manager, IconTheme.JabRefIcons.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups")); - - toggleAction = new ToggleAction(Localization.menuTitle("Toggle groups interface"), - Localization.lang("Toggle groups interface"), - Globals.getKeyPrefs().getKey(KeyBinding.TOGGLE_GROUPS_INTERFACE), - IconTheme.JabRefIcons.TOGGLE_GROUPS); - - this.frame = frame; - - JFXPanel groupsPane = CustomJFXPanel.create(); - - add(groupsPane); - // Execute on JavaFX Application Thread - Platform.runLater(() -> { - StackPane root = new StackPane(); - root.getChildren().addAll(new GroupTreeView().getView()); - Scene scene = new Scene(root); - groupsPane.setScene(scene); - }); + public GroupSidePane(SidePaneManager manager, JabRefPreferences preferences) { + super(manager, IconTheme.JabRefIcons.TOGGLE_GROUPS, Localization.lang("Groups")); + this.preferences = preferences; } @Override - public void componentOpening() { - Globals.prefs.putBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE, Boolean.TRUE); + public void afterOpening() { + preferences.putBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE, Boolean.TRUE); } @Override - public int getRescalingWeight() { - return 1; + public Priority getResizePolicy() { + return Priority.ALWAYS; } @Override - public void componentClosing() { - getToggleAction().setSelected(false); - Globals.prefs.putBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE, Boolean.FALSE); + public void beforeClosing() { + preferences.putBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE, Boolean.FALSE); } @Override - public void setActiveBasePanel(BasePanel panel) { - super.setActiveBasePanel(panel); - if (panel == null) { // hide groups - frame.getSidePaneManager().hide(GroupSidePane.class); - return; - } - - synchronized (getTreeLock()) { - validateTree(); - } + public ActionsFX getToggleAction() { + return ActionsFX.toggleGroups; } @Override - public void grabFocus() { - + protected Node createContentPane() { + return new GroupTreeView().getView(); } @Override - public ToggleAction getToggleAction() { - return toggleAction; + public SidePaneType getType() { + return SidePaneType.GROUPS; } } diff --git a/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java b/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java index cc25e205b2e..fed71d15ad0 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java @@ -19,16 +19,21 @@ import javax.swing.JTextField; import javax.swing.SwingUtilities; +import javafx.embed.swing.SwingNode; +import javafx.scene.Node; +import javafx.scene.layout.Priority; + import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.gui.SidePaneComponent; import org.jabref.gui.SidePaneManager; +import org.jabref.gui.SidePaneType; +import org.jabref.gui.actions.ActionsFX; import org.jabref.gui.help.HelpAction; import org.jabref.gui.importer.FetcherPreviewDialog; import org.jabref.gui.importer.ImportInspectionDialog; -import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.OS; import org.jabref.preferences.JabRefPreferences; @@ -41,14 +46,27 @@ public class GeneralFetcher extends SidePaneComponent implements ActionListener private final JPanel optionsPanel = new JPanel(optionsCards); private final JPanel optPanel = new JPanel(new BorderLayout()); - private final ToggleAction action; private final JabRefFrame frame; + private final JabRefPreferences preferences; private EntryFetcher activeFetcher; - - public GeneralFetcher(JabRefFrame frame, SidePaneManager sidePaneManager) { - super(sidePaneManager, IconTheme.JabRefIcons.WWW.getSmallIcon(), Localization.lang("Web search")); + public GeneralFetcher(SidePaneManager sidePaneManager, JabRefPreferences preferences, JabRefFrame frame) { + super(sidePaneManager, IconTheme.JabRefIcons.WWW, Localization.lang("Web search")); this.frame = frame; + this.preferences = preferences; + } + + private JTextField getTextField() { + return tf; + } + + @Override + public ActionsFX getToggleAction() { + return ActionsFX.toggleWebSearch; + } + + @Override + protected Node createContentPane() { List fetchers = new EntryFetchers(Globals.journalAbbreviationLoader).getEntryFetchers(); EntryFetcher[] fetcherArray = fetchers.toArray(new EntryFetcher[fetchers.size()]); Arrays.sort(fetcherArray, new EntryFetcherComparator()); @@ -58,7 +76,7 @@ public GeneralFetcher(JabRefFrame frame, SidePaneManager sidePaneManager) { choices[i] = fetcherArray[i].getTitle(); } JComboBox fetcherChoice = new JComboBox<>(choices); - int defaultFetcher = Globals.prefs.getInt(JabRefPreferences.SELECTED_FETCHER_INDEX); + int defaultFetcher = preferences.getInt(JabRefPreferences.SELECTED_FETCHER_INDEX); if (defaultFetcher >= fetcherArray.length) { defaultFetcher = 0; } @@ -73,7 +91,7 @@ public GeneralFetcher(JabRefFrame frame, SidePaneManager sidePaneManager) { fetcherChoice.addActionListener(actionEvent -> { activeFetcher = fetcherArray[fetcherChoice.getSelectedIndex()]; - Globals.prefs.putInt(JabRefPreferences.SELECTED_FETCHER_INDEX, fetcherChoice.getSelectedIndex()); + preferences.putInt(JabRefPreferences.SELECTED_FETCHER_INDEX, fetcherChoice.getSelectedIndex()); if (activeFetcher.getHelpPage() == null) { helpBut.setEnabled(false); } else { @@ -85,14 +103,8 @@ public GeneralFetcher(JabRefFrame frame, SidePaneManager sidePaneManager) { if (activeFetcher.getOptionsPanel() != null) { optPanel.add(activeFetcher.getOptionsPanel(), BorderLayout.CENTER); } - revalidate(); }); - action = new ToggleAction(Localization.lang("Web search"), - Localization.lang("Toggle web search interface"), - Globals.getKeyPrefs().getKey(KeyBinding.WEB_SEARCH), - IconTheme.JabRefIcons.WWW); - helpBut.setMargin(new Insets(0, 0, 0, 0)); tf.setPreferredSize(new Dimension(1, tf.getPreferredSize().height)); if (OS.OS_X) { @@ -145,18 +157,18 @@ public GeneralFetcher(JabRefFrame frame, SidePaneManager sidePaneManager) { main.add(optPanel); main.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); - add(main, BorderLayout.CENTER); + //add(main, BorderLayout.CENTER); go.addActionListener(this); tf.addActionListener(this); - } - private JTextField getTextField() { - return tf; + SwingNode swingNode = new SwingNode(); + SwingUtilities.invokeLater(() -> swingNode.setContent(main)); + return swingNode; } @Override - public ToggleAction getToggleAction() { - return action; + public SidePaneType getType() { + return SidePaneType.WEB_SEARCH; } @Override @@ -220,26 +232,18 @@ public void actionPerformed(ActionEvent e) { } @Override - public void grabFocus() { - getTextField().grabFocus(); - } - - @Override - public void componentClosing() { - super.componentClosing(); - getToggleAction().setSelected(false); - Globals.prefs.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.FALSE); + public void beforeClosing() { + preferences.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.FALSE); } @Override - public void componentOpening() { - super.componentOpening(); - Globals.prefs.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.TRUE); + public void afterOpening() { + preferences.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.TRUE); } @Override - public int getRescalingWeight() { - return 0; + public Priority getResizePolicy() { + return Priority.NEVER; } private static class EntryFetcherComparator implements Comparator { diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index f58be1651bf..64371ad23a1 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -37,8 +37,6 @@ import org.jabref.gui.FXDialogService; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; -import org.jabref.gui.SidePaneComponent; -import org.jabref.gui.SidePaneManager; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.desktop.os.NativeDesktop; import org.jabref.gui.help.HelpAction; @@ -78,14 +76,37 @@ import org.slf4j.LoggerFactory; /** - * This test panel can be opened by reflection from JabRef, passing the JabRefFrame as an - * argument to the start() method. It displays buttons for testing interaction functions - * between JabRef and OpenOffice. + * Pane to manage the interaction between JabRef and OpenOffice. */ public class OpenOfficePanel extends AbstractWorker { private static final Logger LOGGER = LoggerFactory.getLogger(OpenOfficePanel.class); - private OpenOfficeSidePanel sidePane; + private JPanel content; + + public OpenOfficePanel(JabRefFrame jabRefFrame) { + Icon connectImage = IconTheme.JabRefIcons.CONNECT_OPEN_OFFICE.getSmallIcon(); + + connect = new JButton(connectImage); + manualConnect = new JButton(connectImage); + connect.setToolTipText(Localization.lang("Connect")); + manualConnect.setToolTipText(Localization.lang("Manual connect")); + connect.setPreferredSize(new Dimension(24, 24)); + manualConnect.setPreferredSize(new Dimension(24, 24)); + + selectDocument = new JButton(IconTheme.JabRefIcons.OPEN.getSmallIcon()); + selectDocument.setToolTipText(Localization.lang("Select Writer document")); + selectDocument.setPreferredSize(new Dimension(24, 24)); + update = new JButton(IconTheme.JabRefIcons.REFRESH.getSmallIcon()); + update.setToolTipText(Localization.lang("Sync OpenOffice/LibreOffice bibliography")); + update.setPreferredSize(new Dimension(24, 24)); + preferences = new OpenOfficePreferences(Globals.prefs); + loader = new StyleLoader(preferences, + Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader), + Globals.prefs.getDefaultEncoding()); + + this.frame = jabRefFrame; + initPanel(); + } private JDialog diag; private final JButton connect; private final JButton manualConnect; @@ -111,31 +132,8 @@ public class OpenOfficePanel extends AbstractWorker { private final OpenOfficePreferences preferences; private final StyleLoader loader; - public OpenOfficePanel(JabRefFrame jabRefFrame, SidePaneManager spManager) { - Icon connectImage = IconTheme.JabRefIcons.CONNECT_OPEN_OFFICE.getSmallIcon(); - - connect = new JButton(connectImage); - manualConnect = new JButton(connectImage); - connect.setToolTipText(Localization.lang("Connect")); - manualConnect.setToolTipText(Localization.lang("Manual connect")); - connect.setPreferredSize(new Dimension(24, 24)); - manualConnect.setPreferredSize(new Dimension(24, 24)); - - selectDocument = new JButton(IconTheme.JabRefIcons.OPEN.getSmallIcon()); - selectDocument.setToolTipText(Localization.lang("Select Writer document")); - selectDocument.setPreferredSize(new Dimension(24, 24)); - update = new JButton(IconTheme.JabRefIcons.REFRESH.getSmallIcon()); - update.setToolTipText(Localization.lang("Sync OpenOffice/LibreOffice bibliography")); - update.setPreferredSize(new Dimension(24, 24)); - preferences = new OpenOfficePreferences(Globals.prefs); - loader = new StyleLoader(preferences, - Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader), - Globals.prefs.getDefaultEncoding()); - - this.frame = jabRefFrame; - sidePane = new OpenOfficeSidePanel(spManager, IconTheme.getImage("openoffice"), "OpenOffice/LibreOffice", preferences); - initPanel(); - spManager.register(sidePane); + public JPanel getContent() { + return content; } private void initPanel() { @@ -297,8 +295,7 @@ public void actionPerformed(ActionEvent e) { mainBuilder.add(exportCitations).xy(1, 9); mainBuilder.add(settingsB).xy(1, 10); - JPanel content = new JPanel(); - sidePane.setContentContainer(content); + content = new JPanel(); content.setLayout(new BorderLayout()); content.add(mainBuilder.getPanel(), BorderLayout.CENTER); @@ -747,9 +744,4 @@ private void showSettingsPopup() { menu.add(clearConnectionSettings); menu.show(settingsB, 0, settingsB.getHeight()); } - - public SidePaneComponent.ToggleAction getToggleAction() { - return sidePane.getToggleAction(); - } - } diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficeSidePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficeSidePanel.java index a7dd9257707..644467cf938 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficeSidePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficeSidePanel.java @@ -1,52 +1,59 @@ package org.jabref.gui.openoffice; -import javax.swing.Icon; +import javax.swing.SwingUtilities; -import org.jabref.Globals; +import javafx.embed.swing.SwingNode; +import javafx.scene.Node; +import javafx.scene.layout.Priority; + +import org.jabref.gui.IconTheme; +import org.jabref.gui.JabRefFrame; import org.jabref.gui.SidePaneComponent; import org.jabref.gui.SidePaneManager; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.logic.l10n.Localization; +import org.jabref.gui.SidePaneType; +import org.jabref.gui.actions.ActionsFX; import org.jabref.logic.openoffice.OpenOfficePreferences; public class OpenOfficeSidePanel extends SidePaneComponent { private OpenOfficePreferences preferences; - private final ToggleAction toggleAction; - + private JabRefFrame frame; - public OpenOfficeSidePanel(SidePaneManager sidePaneManager, Icon icon, String title, OpenOfficePreferences preferences) { - super(sidePaneManager, icon, title); + public OpenOfficeSidePanel(SidePaneManager sidePaneManager, OpenOfficePreferences preferences, JabRefFrame frame) { + super(sidePaneManager, IconTheme.JabRefIcons.FILE_OPENOFFICE, "OpenOffice/LibreOffice"); this.preferences = preferences; - sidePaneManager.register(this); - if (preferences.showPanel()) { - manager.show(OpenOfficeSidePanel.class); - } - - toggleAction = new ToggleAction(Localization.lang("OpenOffice/LibreOffice connection"), - Localization.lang("OpenOffice/LibreOffice connection"), - Globals.getKeyPrefs().getKey(KeyBinding.OPEN_OPEN_OFFICE_LIBRE_OFFICE_CONNECTION), - icon); + this.frame = frame; } @Override - public void componentClosing() { + public void beforeClosing() { preferences.setShowPanel(false); } @Override - public void componentOpening() { + public void afterOpening() { preferences.setShowPanel(true); } @Override - public int getRescalingWeight() { - return 0; + public Priority getResizePolicy() { + return Priority.NEVER; } @Override - public ToggleAction getToggleAction() { - return toggleAction; + public ActionsFX getToggleAction() { + return ActionsFX.toggleOpenOffice; } + @Override + protected Node createContentPane() { + SwingNode swingNode = new SwingNode(); + SwingUtilities.invokeLater(() -> swingNode.setContent(new OpenOfficePanel(frame).getContent())); + return swingNode; + } + + @Override + public SidePaneType getType() { + return SidePaneType.OPEN_OFFICE; + } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index d8e4124bb20..59200f931ac 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -35,6 +35,7 @@ import org.jabref.JabRefException; import org.jabref.JabRefMain; +import org.jabref.gui.SidePaneType; import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.desktop.JabRefDesktop; @@ -931,6 +932,27 @@ private static void insertDefaultCleanupPreset(Map storage) { storage.put(CLEANUP_FORMATTERS, convertListToString(preset.getFormatterCleanups().getAsStringList(OS.NEWLINE))); } + public Map getSidePanePreferredPositions() { + Map preferredPositions = new HashMap<>(); + + List componentNames = getStringList(SIDE_PANE_COMPONENT_NAMES); + List componentPositions = getStringList(SIDE_PANE_COMPONENT_PREFERRED_POSITIONS); + + for (int i = 0; i < componentNames.size(); ++i) { + String name = componentNames.get(i); + try { + SidePaneType type = Enum.valueOf(SidePaneType.class, name); + preferredPositions.put(type, Integer.parseInt(componentPositions.get(i))); + } catch (NumberFormatException e) { + LOGGER.debug("Invalid number format for side pane component '" + name + "'", e); + } catch (IllegalArgumentException e) { + LOGGER.debug("Following component is not a side pane: '" + name + "'", e); + } + } + + return preferredPositions; + } + public int getFontSizeFX() { // Decrease font size by 3 since JavaFX has default font size of 9, while Swing uses 12 return getInt(MENU_FONT_SIZE) - 3; @@ -1670,4 +1692,18 @@ public void storeAutoCompletePreferences(AutoCompletePreferences autoCompletePre putBoolean(AUTOCOMPLETER_FIRST_LAST, autoCompletePreferences.getOnlyCompleteFirstLast()); putStringList(AUTOCOMPLETER_COMPLETE_FIELDS, autoCompletePreferences.getCompleteFields()); } + + public void storeSidePanePreferredPositions(Map preferredPositions) { + // Split the map into a pair of parallel String lists suitable for storage + List names = preferredPositions.keySet().stream() + .map(Enum::toString) + .collect(Collectors.toList()); + + List positions = preferredPositions.values().stream() + .map(integer -> Integer.toString(integer)) + .collect(Collectors.toList()); + + putStringList(SIDE_PANE_COMPONENT_NAMES, names); + putStringList(SIDE_PANE_COMPONENT_PREFERRED_POSITIONS, positions); + } } From 284eeab443c06113c1293c5068684446b53d27e4 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 10 Feb 2018 00:24:16 +0100 Subject: [PATCH 055/827] Fix import --- src/main/java/org/jabref/gui/JabRefFrame.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 6ab0ced65f7..d9477508955 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -103,6 +103,7 @@ import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.menus.ChangeEntryTypeMenu; import org.jabref.gui.menus.FileHistoryMenu; +import org.jabref.gui.preftabs.PreferencesDialog; import org.jabref.gui.push.PushToApplicationButton; import org.jabref.gui.push.PushToApplications; import org.jabref.gui.search.GlobalSearchBar; From 7e2c537250a1161fcf2ef0b98191e0fefa6ebab4 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 10 Feb 2018 13:42:21 +0100 Subject: [PATCH 056/827] convert XMP Action and SubDatabase action --- src/main/java/org/jabref/gui/BasePanel.java | 4 +-- src/main/java/org/jabref/gui/JabRefFrame.java | 29 ++++++++------- .../org/jabref/gui/actions/ActionsFX.java | 35 ++++++++++++++----- ...seAction.java => NewSubLibraryAction.java} | 17 +++------ .../gui/actions/NormalSearchAction.java | 12 +++++++ .../jabref/gui/actions/WriteXMPAction.java | 20 +++++++++++ ...PAction.java => WriteXMPActionWorker.java} | 4 +-- .../org/jabref/gui/groups/GroupSidePane.java | 2 +- .../gui/importer/fetcher/GeneralFetcher.java | 2 +- .../gui/openoffice/OpenOfficeSidePanel.java | 2 +- 10 files changed, 85 insertions(+), 42 deletions(-) rename src/main/java/org/jabref/gui/actions/{NewSubDatabaseAction.java => NewSubLibraryAction.java} (68%) create mode 100644 src/main/java/org/jabref/gui/actions/NormalSearchAction.java create mode 100644 src/main/java/org/jabref/gui/actions/WriteXMPAction.java rename src/main/java/org/jabref/gui/externalfiles/{WriteXMPAction.java => WriteXMPActionWorker.java} (98%) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 3b50e57fb08..6e80a7eff32 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -59,7 +59,7 @@ import org.jabref.gui.exporter.SaveDatabaseAction; import org.jabref.gui.externalfiles.FindFullTextAction; import org.jabref.gui.externalfiles.SynchronizeFileField; -import org.jabref.gui.externalfiles.WriteXMPAction; +import org.jabref.gui.externalfiles.WriteXMPActionWorker; import org.jabref.gui.externalfiletype.ExternalFileMenuItem; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; @@ -679,7 +679,7 @@ public void update() { actions.put(Actions.EXPORT_TO_CLIPBOARD, new ExportToClipboardAction(frame)); actions.put(Actions.SEND_AS_EMAIL, new SendAsEMailAction(frame)); - actions.put(Actions.WRITE_XMP, new WriteXMPAction(this)); + actions.put(Actions.WRITE_XMP, new WriteXMPActionWorker(this)); actions.put(Actions.ABBREVIATE_ISO, new AbbreviateAction(this, true)); actions.put(Actions.ABBREVIATE_MEDLINE, new AbbreviateAction(this, false)); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index d9477508955..33dc9e31a12 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -79,13 +79,14 @@ import org.jabref.gui.actions.MnemonicAwareAction; import org.jabref.gui.actions.NewDatabaseAction; import org.jabref.gui.actions.NewEntryAction; -import org.jabref.gui.actions.NewSubDatabaseAction; +import org.jabref.gui.actions.NewSubLibraryAction; import org.jabref.gui.actions.OldDatabaseCommandWrapper; import org.jabref.gui.actions.OpenBrowserAction; import org.jabref.gui.actions.SetupGeneralFieldsAction; import org.jabref.gui.actions.ShowPreferencesAction; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.actions.SortTabsAction; +import org.jabref.gui.actions.WriteXMPAction; import org.jabref.gui.autosaveandbackup.AutosaveUIManager; import org.jabref.gui.bibtexkeypattern.BibtexKeyPatternDialog; import org.jabref.gui.copyfiles.CopyFilesAction; @@ -170,7 +171,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { // BasePanel's runCommand() method to be called with that command. // Note: GeneralAction's constructor automatically gets translations // for the name and message strings. - private final AbstractAction newSubDatabaseAction = new NewSubDatabaseAction(this); private final AbstractAction jabrefWebPageAction = new OpenBrowserAction("https://jabref.org", Localization.menuTitle("Website"), Localization.lang("Opens JabRef's website"), IconTheme.getImage("about"), IconTheme.getImage("about")); @@ -282,10 +282,7 @@ public void actionPerformed(ActionEvent e) { Localization.lang("Autogenerate BibTeX keys"), Globals.getKeyPrefs().getKey(KeyBinding.AUTOGENERATE_BIBTEX_KEYS), IconTheme.JabRefIcons.MAKE_KEY.getIcon()); - private final AbstractAction writeXmpAction = new GeneralAction(Actions.WRITE_XMP, - Localization.menuTitle("Write XMP-metadata to PDFs"), - Localization.lang("Will write XMP-metadata to the PDFs linked from selected entries."), - Globals.getKeyPrefs().getKey(KeyBinding.WRITE_XMP)); + private final AbstractAction openFolder = new GeneralAction(Actions.OPEN_FOLDER, Localization.menuTitle("Open folder"), Localization.lang("Open folder"), Globals.getKeyPrefs().getKey(KeyBinding.OPEN_FOLDER)); @@ -963,8 +960,8 @@ private MenuBar createMenu() { ); edit.getItems().addAll( - factory.createMenuItem(ActionsFX.undo, new OldDatabaseCommandWrapper(Actions.UNDO, this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.redo, new OldDatabaseCommandWrapper(Actions.REDO, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.UNDO, new OldDatabaseCommandWrapper(Actions.UNDO, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.REDO, new OldDatabaseCommandWrapper(Actions.REDO, this, Globals.stateManager)), new SeparatorMenuItem(), @@ -984,7 +981,7 @@ private MenuBar createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(ActionsFX.sendAsEmail, new OldDatabaseCommandWrapper(Actions.SEND_AS_EMAIL, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.SEND_AS_EMAIL, new OldDatabaseCommandWrapper(Actions.SEND_AS_EMAIL, this, Globals.stateManager)), new SeparatorMenuItem() ); @@ -1040,9 +1037,15 @@ private MenuBar createMenu() { //factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), edit.getItems().addAll( - factory.createMenuItem(ActionsFX.manageKeywords, new ManageKeywordsAction(this)), - factory.createMenuItem(ActionsFX.replaceAll, new OldDatabaseCommandWrapper(Actions.REPLACE_ALL, this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.massSetField, new MassSetFieldAction(this)) + factory.createMenuItem(ActionsFX.MANAGE_KEYWORDS, new ManageKeywordsAction(this)), + factory.createMenuItem(ActionsFX.REPLACE_ALL, new OldDatabaseCommandWrapper(Actions.REPLACE_ALL, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.MASS_SET_FIELDS, new MassSetFieldAction(this)) + ); + + tools.getItems().addAll( + factory.createMenuItem(ActionsFX.NEW_SUB_LIBRARY_FROM_AUX, new NewSubLibraryAction(this)), + factory.createMenuItem(ActionsFX.WRITE_XMP, new WriteXMPAction(getCurrentBasePanel())) + ); options.getItems().addAll( @@ -1059,7 +1062,7 @@ private MenuBar createMenu() { /* -factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), + factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), search.add(normalSearch); search.addSeparator(); diff --git a/src/main/java/org/jabref/gui/actions/ActionsFX.java b/src/main/java/org/jabref/gui/actions/ActionsFX.java index af45fa55b36..b029caef566 100644 --- a/src/main/java/org/jabref/gui/actions/ActionsFX.java +++ b/src/main/java/org/jabref/gui/actions/ActionsFX.java @@ -78,15 +78,18 @@ public enum ActionsFX { PULL_CHANGES_FROM_SHARED_DB(Localization.menuTitle("Pull changes from shared database"), IconTheme.JabRefIcons.PULL, KeyBinding.PULL_CHANGES_FROM_SHARED_DATABASE), CLOSE_LIBRARY(Localization.menuTitle("Close library"), Localization.lang("Close the current library"), IconTheme.JabRefIcons.CLOSE, KeyBinding.CLOSE_DATABASE), QUIT(Localization.menuTitle("Quit"), Localization.lang("Quit JabRef"), IconTheme.JabRefIcons.CLOSE_JABREF, KeyBinding.QUIT_JABREF), - undo(Localization.lang("Undo"), IconTheme.JabRefIcons.UNDO, KeyBinding.UNDO), - redo(Localization.lang("Redo"), IconTheme.JabRefIcons.REDO, KeyBinding.REDO), - sendAsEmail(Localization.lang("Send as email"), IconTheme.JabRefIcons.EMAIL), - replaceAll(Localization.menuTitle("Replace string"), KeyBinding.REPLACE_STRING), - manageKeywords(Localization.menuTitle("Manage keywords")), - massSetField(Localization.menuTitle("Set/clear/append/rename fields")), - toggleGroups(Localization.lang("Toggle groups interface"), IconTheme.JabRefIcons.TOGGLE_GROUPS, KeyBinding.TOGGLE_GROUPS_INTERFACE), - toggleOpenOffice(Localization.lang("OpenOffice/LibreOffice connection"), IconTheme.JabRefIcons.FILE_OPENOFFICE, KeyBinding.OPEN_OPEN_OFFICE_LIBRE_OFFICE_CONNECTION), - toggleWebSearch(Localization.lang("Web search"), Localization.lang("Toggle web search interface"), IconTheme.JabRefIcons.WWW, KeyBinding.WEB_SEARCH), + UNDO(Localization.lang("Undo"), IconTheme.JabRefIcons.UNDO, KeyBinding.UNDO), + REDO(Localization.lang("Redo"), IconTheme.JabRefIcons.REDO, KeyBinding.REDO), + REPLACE_ALL(Localization.menuTitle("Replace string"), KeyBinding.REPLACE_STRING), + MANAGE_KEYWORDS(Localization.menuTitle("Manage keywords")), + MASS_SET_FIELDS(Localization.menuTitle("Set/clear/append/rename fields")), + TOGGLE_GROUPS(Localization.lang("Toggle groups interface"), IconTheme.JabRefIcons.TOGGLE_GROUPS, KeyBinding.TOGGLE_GROUPS_INTERFACE), + TOOGLE_OO(Localization.lang("OpenOffice/LibreOffice connection"), IconTheme.JabRefIcons.FILE_OPENOFFICE, KeyBinding.OPEN_OPEN_OFFICE_LIBRE_OFFICE_CONNECTION), + TOGGLE_WEB_SEARCH(Localization.lang("Web search"), Localization.lang("Toggle web search interface"), IconTheme.JabRefIcons.WWW, KeyBinding.WEB_SEARCH), + + NEW_SUB_LIBRARY_FROM_AUX(Localization.menuTitle("New sublibrary based on AUX file") + "...", Localization.lang("New BibTeX sublibrary"), IconTheme.JabRefIcons.NEW), + WRITE_XMP(Localization.menuTitle("Write XMP-metadata to PDFs"), Localization.lang("Will write XMP-metadata to the PDFs linked from selected entries."), KeyBinding.WRITE_XMP), + MANAGE_CUSTOM_EXPORTS(Localization.menuTitle("Manage custom exports")), MANAGE_CUSTOM_IMPORTS(Localization.menuTitle("Manage custom imports")), CUSTOMIZE_ENTRY_TYPES(Localization.menuTitle("Customize entry types")), @@ -123,6 +126,13 @@ public enum ActionsFX { this.keyBinding = Optional.of(keyBinding); } + ActionsFX(String text, String description, IconTheme.JabRefIcons icon) { + this.text = text; + this.description = description; + this.icon = Optional.of(icon); + this.keyBinding = Optional.empty(); + } + ActionsFX(String text, String description, IconTheme.JabRefIcons icon, KeyBinding keyBinding) { this.text = text; this.description = description; @@ -144,6 +154,13 @@ public enum ActionsFX { this.keyBinding = Optional.empty(); } + ActionsFX(String text, String description, KeyBinding keyBinding) { + this.text = text; + this.description = description; + this.icon = Optional.empty(); + this.keyBinding = Optional.of(keyBinding); + } + public Optional getIcon() { return icon; } diff --git a/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java b/src/main/java/org/jabref/gui/actions/NewSubLibraryAction.java similarity index 68% rename from src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java rename to src/main/java/org/jabref/gui/actions/NewSubLibraryAction.java index cf0f9769339..368fe9975ff 100644 --- a/src/main/java/org/jabref/gui/actions/NewSubDatabaseAction.java +++ b/src/main/java/org/jabref/gui/actions/NewSubLibraryAction.java @@ -1,13 +1,8 @@ package org.jabref.gui.actions; -import java.awt.event.ActionEvent; - -import javax.swing.Action; - import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.BasePanelPreferences; -import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; import org.jabref.gui.auximport.FromAuxDialog; import org.jabref.gui.externalfiletype.ExternalFileTypes; @@ -18,21 +13,16 @@ /** * The action concerned with generate a new (sub-)database from latex AUX file. */ -public class NewSubDatabaseAction extends MnemonicAwareAction { +public class NewSubLibraryAction extends SimpleCommand { private final JabRefFrame jabRefFrame; - public NewSubDatabaseAction(JabRefFrame jabRefFrame) { - super(IconTheme.JabRefIcons.NEW.getIcon()); + public NewSubLibraryAction(JabRefFrame jabRefFrame) { this.jabRefFrame = jabRefFrame; - putValue(Action.NAME, Localization.menuTitle("New sublibrary based on AUX file") + "..."); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("New BibTeX sublibrary")); } @Override - public void actionPerformed(ActionEvent e) { - // Create a new, empty, database. - + public void execute() { FromAuxDialog dialog = new FromAuxDialog(jabRefFrame, "", true, jabRefFrame.getTabbedPane()); dialog.setVisible(true); @@ -44,4 +34,5 @@ public void actionPerformed(ActionEvent e) { jabRefFrame.output(Localization.lang("New library created.")); } } + } diff --git a/src/main/java/org/jabref/gui/actions/NormalSearchAction.java b/src/main/java/org/jabref/gui/actions/NormalSearchAction.java new file mode 100644 index 00000000000..af24133fb10 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/NormalSearchAction.java @@ -0,0 +1,12 @@ +package org.jabref.gui.actions; + + +public class NormalSearchAction extends SimpleCommand { + + @Override + public void execute() { + // TODO Auto-generated method stub + + } + +} diff --git a/src/main/java/org/jabref/gui/actions/WriteXMPAction.java b/src/main/java/org/jabref/gui/actions/WriteXMPAction.java new file mode 100644 index 00000000000..8873ea254a7 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/WriteXMPAction.java @@ -0,0 +1,20 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.BasePanel; +import org.jabref.gui.externalfiles.WriteXMPActionWorker; + +public class WriteXMPAction extends SimpleCommand { + + private final BasePanel basePanel; + + public WriteXMPAction(BasePanel basePanel) { + this.basePanel = basePanel; + + } + + @Override + public void execute() { + new WriteXMPActionWorker(basePanel).run(); + } + +} diff --git a/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java b/src/main/java/org/jabref/gui/externalfiles/WriteXMPActionWorker.java similarity index 98% rename from src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java rename to src/main/java/org/jabref/gui/externalfiles/WriteXMPActionWorker.java index 136521971d1..f0cffafbba7 100644 --- a/src/main/java/org/jabref/gui/externalfiles/WriteXMPAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/WriteXMPActionWorker.java @@ -43,7 +43,7 @@ * This action goes through all selected entries in the BasePanel, and attempts * to write the XMP data to the external pdf. */ -public class WriteXMPAction extends AbstractWorker { +public class WriteXMPActionWorker extends AbstractWorker { private final BasePanel panel; private final JabRefFrame frame; @@ -61,7 +61,7 @@ public class WriteXMPAction extends AbstractWorker { private int errors; - public WriteXMPAction(BasePanel panel) { + public WriteXMPActionWorker(BasePanel panel) { this.panel = panel; this.frame = panel.frame(); } diff --git a/src/main/java/org/jabref/gui/groups/GroupSidePane.java b/src/main/java/org/jabref/gui/groups/GroupSidePane.java index d984fac8fe6..bfab0785539 100644 --- a/src/main/java/org/jabref/gui/groups/GroupSidePane.java +++ b/src/main/java/org/jabref/gui/groups/GroupSidePane.java @@ -40,7 +40,7 @@ public void beforeClosing() { @Override public ActionsFX getToggleAction() { - return ActionsFX.toggleGroups; + return ActionsFX.TOGGLE_GROUPS; } @Override diff --git a/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java b/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java index fed71d15ad0..918c49bb836 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/GeneralFetcher.java @@ -62,7 +62,7 @@ private JTextField getTextField() { @Override public ActionsFX getToggleAction() { - return ActionsFX.toggleWebSearch; + return ActionsFX.TOGGLE_WEB_SEARCH; } @Override diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficeSidePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficeSidePanel.java index 644467cf938..60bb27f18e6 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficeSidePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficeSidePanel.java @@ -42,7 +42,7 @@ public Priority getResizePolicy() { @Override public ActionsFX getToggleAction() { - return ActionsFX.toggleOpenOffice; + return ActionsFX.TOOGLE_OO; } @Override From 407a1e43d6826f6538f9e1cfa8972f28fef329eb Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 10 Feb 2018 23:36:33 +0100 Subject: [PATCH 057/827] Add Tools menu --- src/main/java/org/jabref/gui/JabRefFrame.java | 161 +++++++----------- .../org/jabref/gui/actions/ActionsFX.java | 8 +- .../CopyFilesAction.java | 52 +++--- .../jabref/gui/copyfiles/CopyFilesTask.java | 1 + 4 files changed, 95 insertions(+), 127 deletions(-) rename src/main/java/org/jabref/gui/{copyfiles => actions}/CopyFilesAction.java (65%) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 33dc9e31a12..07b861b4576 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -65,11 +65,11 @@ import org.jabref.gui.actions.ActionsFX; import org.jabref.gui.actions.AutoLinkFilesAction; import org.jabref.gui.actions.ConnectToSharedDatabaseCommand; +import org.jabref.gui.actions.CopyFilesAction; import org.jabref.gui.actions.CustomizeKeyBindingAction; import org.jabref.gui.actions.EditExternalFileTypesAction; import org.jabref.gui.actions.ErrorConsoleAction; import org.jabref.gui.actions.IntegrityCheckAction; -import org.jabref.gui.actions.ManageContentSelectorAction; import org.jabref.gui.actions.ManageCustomExportsAction; import org.jabref.gui.actions.ManageCustomImportsAction; import org.jabref.gui.actions.ManageJournalsAction; @@ -86,10 +86,8 @@ import org.jabref.gui.actions.ShowPreferencesAction; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.actions.SortTabsAction; -import org.jabref.gui.actions.WriteXMPAction; import org.jabref.gui.autosaveandbackup.AutosaveUIManager; import org.jabref.gui.bibtexkeypattern.BibtexKeyPatternDialog; -import org.jabref.gui.copyfiles.CopyFilesAction; import org.jabref.gui.documentviewer.ShowDocumentViewerAction; import org.jabref.gui.exporter.ExportCommand; import org.jabref.gui.exporter.SaveAllAction; @@ -145,6 +143,7 @@ * The main window of the application. */ public class JabRefFrame extends BorderPane implements OutputPrinter { + private static final Logger LOGGER = LoggerFactory.getLogger(JabRefFrame.class); // Frame titles. @@ -161,7 +160,8 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { private final JLabel statusLine = new JLabel("", SwingConstants.LEFT); private final JLabel statusLabel = new JLabel( Localization.lang("Status") - + ':', SwingConstants.LEFT); + + ':', + SwingConstants.LEFT); private final JProgressBar progressBar = new JProgressBar(); private final FileHistoryMenu fileHistory = new FileHistoryMenu(prefs, this); @@ -211,11 +211,7 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { Localization.lang("Back"), Globals.getKeyPrefs().getKey(KeyBinding.BACK), IconTheme.JabRefIcons.LEFT.getIcon()); private final AbstractAction deleteEntry = new GeneralAction(Actions.DELETE, Localization.menuTitle("Delete entry"), Localization.lang("Delete entry"), Globals.getKeyPrefs().getKey(KeyBinding.DELETE_ENTRY), IconTheme.JabRefIcons.DELETE_ENTRY.getIcon()); - private final AbstractAction openConsole = new GeneralAction(Actions.OPEN_CONSOLE, - Localization.menuTitle("Open terminal here"), - Localization.lang("Open terminal here"), - Globals.getKeyPrefs().getKey(KeyBinding.OPEN_CONSOLE), - IconTheme.JabRefIcons.CONSOLE.getIcon()); + private final AbstractAction mark = new GeneralAction(Actions.MARK_ENTRIES, Localization.menuTitle("Mark entries"), Localization.lang("Mark entries"), Globals.getKeyPrefs().getKey(KeyBinding.MARK_ENTRIES), IconTheme.JabRefIcons.MARK_ENTRIES.getIcon()); private final JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color")); @@ -241,7 +237,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { private final AbstractAction normalSearch = new GeneralAction(Actions.SEARCH, Localization.menuTitle("Search"), Localization.lang("Search"), Globals.getKeyPrefs().getKey(KeyBinding.SEARCH), IconTheme.JabRefIcons.SEARCH.getIcon()); - private final AbstractAction editPreamble = new GeneralAction(Actions.EDIT_PREAMBLE, Localization.menuTitle("Edit preamble"), Localization.lang("Edit preamble")); @@ -283,41 +278,16 @@ public void actionPerformed(ActionEvent e) { Globals.getKeyPrefs().getKey(KeyBinding.AUTOGENERATE_BIBTEX_KEYS), IconTheme.JabRefIcons.MAKE_KEY.getIcon()); - private final AbstractAction openFolder = new GeneralAction(Actions.OPEN_FOLDER, - Localization.menuTitle("Open folder"), Localization.lang("Open folder"), - Globals.getKeyPrefs().getKey(KeyBinding.OPEN_FOLDER)); - private final AbstractAction openFile = new GeneralAction(Actions.OPEN_EXTERNAL_FILE, - Localization.menuTitle("Open file"), - Localization.lang("Open file"), - Globals.getKeyPrefs().getKey(KeyBinding.OPEN_FILE), - IconTheme.JabRefIcons.FILE.getIcon()); - private final AbstractAction openUrl = new GeneralAction(Actions.OPEN_URL, - Localization.menuTitle("Open URL or DOI"), - Localization.lang("Open URL or DOI"), - Globals.getKeyPrefs().getKey(KeyBinding.OPEN_URL_OR_DOI), - IconTheme.JabRefIcons.WWW.getIcon()); private final AbstractAction dupliCheck = new GeneralAction(Actions.DUPLI_CHECK, Localization.menuTitle("Find duplicates"), IconTheme.JabRefIcons.FIND_DUPLICATES.getIcon()); private final AbstractAction plainTextImport = new GeneralAction(Actions.PLAIN_TEXT_IMPORT, Localization.menuTitle("New entry from plain text") + ELLIPSES, Globals.getKeyPrefs().getKey(KeyBinding.NEW_FROM_PLAIN_TEXT)); - private final AbstractAction autoSetFile = new GeneralAction(Actions.AUTO_SET_FILE, Localization.lang("Synchronize file links") + ELLIPSES, Globals.getKeyPrefs().getKey(KeyBinding.SYNCHRONIZE_FILES)); - private final AbstractAction abbreviateMedline = new GeneralAction(Actions.ABBREVIATE_MEDLINE, - Localization.menuTitle("Abbreviate journal names (MEDLINE)"), - Localization.lang("Abbreviate journal names of the selected entries (MEDLINE abbreviation)")); - private final AbstractAction abbreviateIso = new GeneralAction(Actions.ABBREVIATE_ISO, - Localization.menuTitle("Abbreviate journal names (ISO)"), - Localization.lang("Abbreviate journal names of the selected entries (ISO abbreviation)"), - Globals.getKeyPrefs().getKey(KeyBinding.ABBREVIATE)); - private final AbstractAction unabbreviate = new GeneralAction(Actions.UNABBREVIATE, - Localization.menuTitle("Unabbreviate journal names"), - Localization.lang("Unabbreviate journal names of the selected entries"), - Globals.getKeyPrefs().getKey(KeyBinding.UNABBREVIATE)); - private final AbstractAction exportLinkedFiles = new CopyFilesAction(); + private final AbstractAction bibtexKeyPattern = new BibtexKeyPatternAction(); private final AbstractAction errorConsole = new ErrorConsoleAction(); private final AbstractAction cleanupEntries = new GeneralAction(Actions.CLEANUP, @@ -344,8 +314,7 @@ public void actionPerformed(ActionEvent e) { private final GeneralAction findUnlinkedFiles = new GeneralAction( Actions.findUnlinkedFiles, FindUnlinkedFilesDialog.ACTION_MENU_TITLE, FindUnlinkedFilesDialog.ACTION_SHORT_DESCRIPTION, - Globals.getKeyPrefs().getKey(KeyBinding.FIND_UNLINKED_FILES) - ); + Globals.getKeyPrefs().getKey(KeyBinding.FIND_UNLINKED_FILES)); private final AutoLinkFilesAction autoLinkFile = new AutoLinkFilesAction(); // The action for adding a new entry of unspecified type. private final NewEntryAction newEntryAction = new NewEntryAction(this, Globals.getKeyPrefs().getKey(KeyBinding.NEW_ENTRY)); @@ -513,9 +482,7 @@ private void init() { // Poor-mans binding to global state // We need to invoke this in the JavaFX thread as all the listeners sit there - Platform.runLater(() -> - Globals.stateManager.activeDatabaseProperty().setValue(Optional.of(currentBasePanel.getBibDatabaseContext())) - ); + Platform.runLater(() -> Globals.stateManager.activeDatabaseProperty().setValue(Optional.of(currentBasePanel.getBibDatabaseContext()))); if (new SearchPreferences(Globals.prefs).isGlobalSearch()) { globalSearchBar.performSearch(); } else { @@ -641,7 +608,6 @@ public void about() { // General preferences dialog. The MacAdapter calls this method when "Preferences..." // is selected from the application menu. - public JabRefPreferences prefs() { return prefs; } @@ -711,45 +677,45 @@ public boolean quit() { List filenames = new ArrayList<>(); for (int i = 0; i < tabbedPane.getTabs().size(); i++) { - BibDatabaseContext context = getBasePanelAt(i).getBibDatabaseContext(); + BibDatabaseContext context = getBasePanelAt(i).getBibDatabaseContext(); - if (getBasePanelAt(i).isModified() && (context.getLocation() == DatabaseLocation.LOCAL)) { - tabbedPane.getSelectionModel().select(i); - String filename = context.getDatabaseFile().map(File::getAbsolutePath).orElse(GUIGlobals.UNTITLED_TITLE); - int answer = showSaveDialog(filename); + if (getBasePanelAt(i).isModified() && (context.getLocation() == DatabaseLocation.LOCAL)) { + tabbedPane.getSelectionModel().select(i); + String filename = context.getDatabaseFile().map(File::getAbsolutePath).orElse(GUIGlobals.UNTITLED_TITLE); + int answer = showSaveDialog(filename); - if ((answer == JOptionPane.CANCEL_OPTION) || - (answer == JOptionPane.CLOSED_OPTION)) { - return false; - } - if (answer == JOptionPane.YES_OPTION) { - // The user wants to save. - try { - //getCurrentBasePanel().runCommand("save"); - SaveDatabaseAction saveAction = new SaveDatabaseAction(getCurrentBasePanel()); - saveAction.runCommand(); - if (saveAction.isCanceled() || !saveAction.isSuccess()) { - // The action was either canceled or unsuccessful. - // Break! - output(Localization.lang("Unable to save library")); - close = false; - } - } catch (Throwable ex) { - // Something prevented the file - // from being saved. Break!!! + if ((answer == JOptionPane.CANCEL_OPTION) || + (answer == JOptionPane.CLOSED_OPTION)) { + return false; + } + if (answer == JOptionPane.YES_OPTION) { + // The user wants to save. + try { + //getCurrentBasePanel().runCommand("save"); + SaveDatabaseAction saveAction = new SaveDatabaseAction(getCurrentBasePanel()); + saveAction.runCommand(); + if (saveAction.isCanceled() || !saveAction.isSuccess()) { + // The action was either canceled or unsuccessful. + // Break! + output(Localization.lang("Unable to save library")); close = false; - break; } + } catch (Throwable ex) { + // Something prevented the file + // from being saved. Break!!! + close = false; + break; } - } else if (context.getLocation() == DatabaseLocation.SHARED) { - context.convertToLocalDatabase(); - context.getDBMSSynchronizer().closeSharedDatabase(); - context.clearDBMSSynchronizer(); } - AutosaveManager.shutdown(context); - BackupManager.shutdown(context); - context.getDatabaseFile().map(File::getAbsolutePath).ifPresent(filenames::add); + } else if (context.getLocation() == DatabaseLocation.SHARED) { + context.convertToLocalDatabase(); + context.getDBMSSynchronizer().closeSharedDatabase(); + context.clearDBMSSynchronizer(); } + AutosaveManager.shutdown(context); + BackupManager.shutdown(context); + context.getDatabaseFile().map(File::getAbsolutePath).ifPresent(filenames::add); + } if (close) { for (int i = 0; i < tabbedPane.getTabs().size(); i++) { @@ -941,8 +907,7 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.IMPORT_INTO_NEW_LIBRARY, new ImportCommand(this, false)), factory.createMenuItem(ActionsFX.EXPORT_ALL, new ExportCommand(this, false)), factory.createMenuItem(ActionsFX.EXPORT_SELECTED, new ExportCommand(this, true)), - factory.createMenuItem(ActionsFX.SAVE_SELECTED_AS_PLAIN_BIBTEX, new OldDatabaseCommandWrapper(Actions.SAVE_SELECTED_AS_PLAIN, this, Globals.stateManager)) - ), + factory.createMenuItem(ActionsFX.SAVE_SELECTED_AS_PLAIN_BIBTEX, new OldDatabaseCommandWrapper(Actions.SAVE_SELECTED_AS_PLAIN, this, Globals.stateManager))), new SeparatorMenuItem(), @@ -956,8 +921,7 @@ private MenuBar createMenu() { new SeparatorMenuItem(), factory.createMenuItem(ActionsFX.CLOSE_LIBRARY, new CloseDatabaseAction()), - factory.createMenuItem(ActionsFX.QUIT, new CloseAction()) - ); + factory.createMenuItem(ActionsFX.QUIT, new CloseAction())); edit.getItems().addAll( factory.createMenuItem(ActionsFX.UNDO, new OldDatabaseCommandWrapper(Actions.UNDO, this, Globals.stateManager)), @@ -974,8 +938,7 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.COPY_KEY_AND_TITLE, new OldDatabaseCommandWrapper(Actions.COPY_KEY_AND_TITLE, this, Globals.stateManager)), factory.createMenuItem(ActionsFX.COPY_KEY_AND_LINK, new OldDatabaseCommandWrapper(Actions.COPY_KEY_AND_LINK, this, Globals.stateManager)), factory.createMenuItem(ActionsFX.COPY_CITATION_PREVIEW, new OldDatabaseCommandWrapper(Actions.COPY_CITATION_HTML, this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.EXPORT_SELECTED_TO_CLIPBOARD, new OldDatabaseCommandWrapper(Actions.EXPORT_TO_CLIPBOARD, this, Globals.stateManager)) - ), + factory.createMenuItem(ActionsFX.EXPORT_SELECTED_TO_CLIPBOARD, new OldDatabaseCommandWrapper(Actions.EXPORT_TO_CLIPBOARD, this, Globals.stateManager))), factory.createMenuItem(ActionsFX.PASTE, new EditAction(Actions.PASTE)), @@ -983,8 +946,7 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.SEND_AS_EMAIL, new OldDatabaseCommandWrapper(Actions.SEND_AS_EMAIL, this, Globals.stateManager)), - new SeparatorMenuItem() - ); + new SeparatorMenuItem()); /* edit.add(mark); for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) { @@ -1039,12 +1001,21 @@ private MenuBar createMenu() { edit.getItems().addAll( factory.createMenuItem(ActionsFX.MANAGE_KEYWORDS, new ManageKeywordsAction(this)), factory.createMenuItem(ActionsFX.REPLACE_ALL, new OldDatabaseCommandWrapper(Actions.REPLACE_ALL, this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.MASS_SET_FIELDS, new MassSetFieldAction(this)) - ); + factory.createMenuItem(ActionsFX.MASS_SET_FIELDS, new MassSetFieldAction(this))); tools.getItems().addAll( factory.createMenuItem(ActionsFX.NEW_SUB_LIBRARY_FROM_AUX, new NewSubLibraryAction(this)), - factory.createMenuItem(ActionsFX.WRITE_XMP, new WriteXMPAction(getCurrentBasePanel())) + factory.createMenuItem(ActionsFX.WRITE_XMP, new OldDatabaseCommandWrapper(Actions.WRITE_XMP, this, Globals.stateManager)), + //TODO: Add OpenOffice + //TODO: Push Entries + factory.createMenuItem(ActionsFX.OPEN_FOLDER, new OldDatabaseCommandWrapper(Actions.OPEN_FOLDER, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.OPEN_FILE, new OldDatabaseCommandWrapper(Actions.OPEN_EXTERNAL_FILE, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.OPEN_URL, new OldDatabaseCommandWrapper(Actions.OPEN_URL, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.OPEN_CONSOLE, new OldDatabaseCommandWrapper(Actions.OPEN_CONSOLE, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.COPY_LINKED_FILES, new CopyFilesAction(this)), + factory.createMenuItem(ActionsFX.ABBREVIATE_ISO, new OldDatabaseCommandWrapper(Actions.ABBREVIATE_ISO, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.ABBREVIATE_MEDLINE, new OldDatabaseCommandWrapper(Actions.ABBREVIATE_MEDLINE, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.UNABBREVIATE, new OldDatabaseCommandWrapper(Actions.UNABBREVIATE, this, Globals.stateManager)) ); @@ -1057,9 +1028,7 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.MANAGE_JOURNALS, new ManageJournalsAction()), factory.createMenuItem(ActionsFX.CUSTOMIZE_KEYBINDING, new CustomizeKeyBindingAction()), factory.createMenuItem(ActionsFX.MANAGE_PROTECTED_TERMS, new ManageProtectedTermsAction(this, Globals.protectedTermsLoader)), - factory.createMenuItem(ActionsFX.MANAGE_CONTENT_SELECTORS, new ManageContentSelectorAction(getCurrentBasePanel(), this)) - ); - + factory.createMenuItem(ActionsFX.MANAGE_CONTENT_SELECTORS, new OldDatabaseCommandWrapper(Actions.MANAGE_SELECTORS, this, Globals.stateManager))); /* factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), @@ -1206,8 +1175,7 @@ private MenuBar createMenu() { view, tools, options, - help - ); + help); return menu; } @@ -1528,7 +1496,7 @@ private void trackOpenNewDatabase(BasePanel basePanel) { Map properties = new HashMap<>(); Map measurements = new HashMap<>(); - measurements.put("NumberOfEntries", (double)basePanel.getDatabaseContext().getDatabase().getEntryCount()); + measurements.put("NumberOfEntries", (double) basePanel.getDatabaseContext().getDatabase().getEntryCount()); Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("OpenNewDatabase", properties, measurements)); } @@ -1885,6 +1853,7 @@ public CountingUndoManager getUndoManager() { } private static class MyGlassPane extends JPanel { + public MyGlassPane() { addKeyListener(new KeyAdapter() { // Nothing @@ -1985,14 +1954,12 @@ public void execute() { } } - private class ChangeTabAction extends MnemonicAwareAction { private final boolean next; public ChangeTabAction(boolean next) { - putValue(Action.NAME, next ? Localization.menuTitle("Next tab") : - Localization.menuTitle("Previous tab")); + putValue(Action.NAME, next ? Localization.menuTitle("Next tab") : Localization.menuTitle("Previous tab")); this.next = next; putValue(Action.ACCELERATOR_KEY, next ? Globals.getKeyPrefs().getKey(KeyBinding.NEXT_TAB) : Globals.getKeyPrefs().getKey(KeyBinding.PREVIOUS_TAB)); @@ -2032,12 +1999,6 @@ public void execute() { } } - - - - - - private class BibtexKeyPatternAction extends MnemonicAwareAction { private BibtexKeyPatternDialog bibtexKeyPatternDialog; diff --git a/src/main/java/org/jabref/gui/actions/ActionsFX.java b/src/main/java/org/jabref/gui/actions/ActionsFX.java index b029caef566..41bf5637dbd 100644 --- a/src/main/java/org/jabref/gui/actions/ActionsFX.java +++ b/src/main/java/org/jabref/gui/actions/ActionsFX.java @@ -30,7 +30,6 @@ public enum ActionsFX { CUT(Localization.lang("Cut"), IconTheme.JabRefIcons.CUT, KeyBinding.CUT), DELETE(Localization.lang("Delete"), IconTheme.JabRefIcons.DELETE_ENTRY, KeyBinding.DELETE_ENTRY), SEND_AS_EMAIL(Localization.lang("Send as email"), IconTheme.JabRefIcons.EMAIL), - OPEN_FOLDER(Localization.lang("Open folder"), KeyBinding.OPEN_FOLDER), OPEN_EXTERNAL_FILE(Localization.lang("Open file"), IconTheme.JabRefIcons.FILE, KeyBinding.OPEN_FILE), OPEN_URL(Localization.lang("Open URL or DOI"), IconTheme.JabRefIcons.WWW, KeyBinding.OPEN_URL_OR_DOI), MERGE_WITH_FETCHED_ENTRY(Localization.lang("Get BibTeX data from %0", "DOI/ISBN/...")), @@ -89,6 +88,13 @@ public enum ActionsFX { NEW_SUB_LIBRARY_FROM_AUX(Localization.menuTitle("New sublibrary based on AUX file") + "...", Localization.lang("New BibTeX sublibrary"), IconTheme.JabRefIcons.NEW), WRITE_XMP(Localization.menuTitle("Write XMP-metadata to PDFs"), Localization.lang("Will write XMP-metadata to the PDFs linked from selected entries."), KeyBinding.WRITE_XMP), + OPEN_FOLDER(Localization.menuTitle("Open folder"), Localization.lang("Open folder"), KeyBinding.OPEN_FOLDER), + OPEN_FILE(Localization.menuTitle("Open file"), Localization.lang("Open file"), IconTheme.JabRefIcons.FILE, KeyBinding.OPEN_FILE), + OPEN_CONSOLE(Localization.menuTitle("Open terminal here"), Localization.lang("Open terminal here"), IconTheme.JabRefIcons.CONSOLE, KeyBinding.OPEN_CONSOLE), + COPY_LINKED_FILES(Localization.lang("Copy linked files to folder...")), + ABBREVIATE_ISO(Localization.menuTitle("Abbreviate journal names (ISO)"), Localization.lang("Abbreviate journal names of the selected entries (ISO abbreviation)"), KeyBinding.ABBREVIATE), + ABBREVIATE_MEDLINE(Localization.menuTitle("Abbreviate journal names (MEDLINE)"), Localization.lang("Abbreviate journal names of the selected entries (MEDLINE abbreviation)")), + UNABBREVIATE(Localization.menuTitle("Unabbreviate journal names"), Localization.lang("Unabbreviate journal names of the selected entries"), KeyBinding.UNABBREVIATE), MANAGE_CUSTOM_EXPORTS(Localization.menuTitle("Manage custom exports")), MANAGE_CUSTOM_IMPORTS(Localization.menuTitle("Manage custom imports")), diff --git a/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java b/src/main/java/org/jabref/gui/actions/CopyFilesAction.java similarity index 65% rename from src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java rename to src/main/java/org/jabref/gui/actions/CopyFilesAction.java index ea4ec2d5b33..0b4ca8d758f 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java +++ b/src/main/java/org/jabref/gui/actions/CopyFilesAction.java @@ -1,46 +1,58 @@ -package org.jabref.gui.copyfiles; +package org.jabref.gui.actions; -import java.awt.event.ActionEvent; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.Optional; -import javax.swing.AbstractAction; - import javafx.concurrent.Task; import org.jabref.Globals; import org.jabref.JabRefGUI; import org.jabref.gui.DialogService; import org.jabref.gui.FXDialogService; -import org.jabref.gui.util.DefaultTaskExecutor; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.copyfiles.CopyFilesDialogView; +import org.jabref.gui.copyfiles.CopyFilesResultItemViewModel; +import org.jabref.gui.copyfiles.CopyFilesResultListDependency; +import org.jabref.gui.copyfiles.CopyFilesTask; import org.jabref.gui.util.DirectoryDialogConfiguration; -import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; -public class CopyFilesAction extends AbstractAction { +public class CopyFilesAction extends SimpleCommand { private final DialogService dialogService = new FXDialogService(); private BibDatabaseContext databaseContext; private List entries; + private final JabRefFrame frame; + public CopyFilesAction(JabRefFrame frame) { + this.frame = frame; + } + + + private void startServiceAndshowProgessDialog(Task> exportService) { + + dialogService.showCanceableProgressDialogAndWait(exportService); - public CopyFilesAction() { - super(Localization.lang("Copy linked files to folder...")); + exportService.run(); //Run kinda blocks, so we just show the result dialog wgeb run is ready + showDialog(exportService.getValue()); } - @Override - public void actionPerformed(ActionEvent e) { + private void showDialog(List data) { + CopyFilesDialogView dlg = new CopyFilesDialogView(databaseContext, new CopyFilesResultListDependency(data)); + dlg.show(); + } + @Override + public void execute() { DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() .withInitialDirectory(Paths.get(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY))) .build(); - entries = JabRefGUI.getMainFrame().getCurrentBasePanel().getSelectedEntries(); + entries = frame.getCurrentBasePanel().getSelectedEntries(); - Optional exportPath = DefaultTaskExecutor - .runInJavaFXThread(() -> dialogService.showDirectorySelectionDialog(dirDialogConfiguration)); + Optional exportPath = dialogService.showDirectorySelectionDialog(dirDialogConfiguration); exportPath.ifPresent(path -> { databaseContext = JabRefGUI.getMainFrame().getCurrentBasePanel().getDatabaseContext(); @@ -48,18 +60,6 @@ public void actionPerformed(ActionEvent e) { Task> exportTask = new CopyFilesTask(databaseContext, entries, path); startServiceAndshowProgessDialog(exportTask); }); - } - - private void startServiceAndshowProgessDialog(Task> exportService) { - - DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.showCanceableProgressDialogAndWait(exportService)); - exportService.run(); //Run kinda blocks, so we just show the result dialog wgeb run is ready - DefaultTaskExecutor.runInJavaFXThread(() -> showDialog(exportService.getValue())); - } - - private void showDialog(List data) { - CopyFilesDialogView dlg = new CopyFilesDialogView(databaseContext, new CopyFilesResultListDependency(data)); - dlg.show(); } } \ No newline at end of file diff --git a/src/main/java/org/jabref/gui/copyfiles/CopyFilesTask.java b/src/main/java/org/jabref/gui/copyfiles/CopyFilesTask.java index 1fc7d650a54..2afefe6becc 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopyFilesTask.java +++ b/src/main/java/org/jabref/gui/copyfiles/CopyFilesTask.java @@ -15,6 +15,7 @@ import javafx.concurrent.Task; import org.jabref.Globals; +import org.jabref.gui.actions.CopyFilesAction; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.OS; import org.jabref.logic.util.io.FileUtil; From d3cd8aa4835ca803f3d74393b0d1d0a1ab53ca5a Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 11 Feb 2018 00:15:27 +0100 Subject: [PATCH 058/827] convert help menu --- src/main/java/org/jabref/gui/JabRefFrame.java | 77 ++++++++++++------- .../org/jabref/gui/actions/ActionsFX.java | 20 ++++- .../gui/actions/ErrorConsoleAction.java | 19 +---- .../jabref/gui/actions/OpenBrowserAction.java | 39 ++-------- .../gui/actions/SearchForUpdateAction.java | 13 +--- .../java/org/jabref/gui/help/AboutAction.java | 21 +---- 6 files changed, 81 insertions(+), 108 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 07b861b4576..cf2296ba42f 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -82,6 +82,7 @@ import org.jabref.gui.actions.NewSubLibraryAction; import org.jabref.gui.actions.OldDatabaseCommandWrapper; import org.jabref.gui.actions.OpenBrowserAction; +import org.jabref.gui.actions.SearchForUpdateAction; import org.jabref.gui.actions.SetupGeneralFieldsAction; import org.jabref.gui.actions.ShowPreferencesAction; import org.jabref.gui.actions.SimpleCommand; @@ -171,34 +172,12 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { // BasePanel's runCommand() method to be called with that command. // Note: GeneralAction's constructor automatically gets translations // for the name and message strings. - private final AbstractAction jabrefWebPageAction = new OpenBrowserAction("https://jabref.org", - Localization.menuTitle("Website"), Localization.lang("Opens JabRef's website"), - IconTheme.getImage("about"), IconTheme.getImage("about")); - private final AbstractAction jabrefFacebookAction = new OpenBrowserAction("https://www.facebook.com/JabRef/", - "Facebook", Localization.lang("Opens JabRef's Facebook page"), - IconTheme.JabRefIcons.FACEBOOK.getSmallIcon(), IconTheme.JabRefIcons.FACEBOOK.getIcon()); - private final AbstractAction jabrefTwitterAction = new OpenBrowserAction("https://twitter.com/jabref_org", - "Twitter", Localization.lang("Opens JabRef's Twitter page"), - IconTheme.JabRefIcons.TWITTER.getSmallIcon(), IconTheme.JabRefIcons.TWITTER.getIcon()); - private final AbstractAction jabrefBlogAction = new OpenBrowserAction("https://blog.jabref.org/", - Localization.menuTitle("Blog"), Localization.lang("Opens JabRef's blog"), - IconTheme.JabRefIcons.BLOG.getSmallIcon(), IconTheme.JabRefIcons.BLOG.getIcon()); - private final AbstractAction developmentVersionAction = new OpenBrowserAction("https://builds.jabref.org/master/", - Localization.menuTitle("Development version"), - Localization.lang("Opens a link where the current development version can be downloaded")); - private final AbstractAction changeLogAction = new OpenBrowserAction( - "https://github.com/JabRef/jabref/blob/master/CHANGELOG.md", Localization.menuTitle("View change log"), - Localization.lang("See what has been changed in the JabRef versions")); - private final AbstractAction forkMeOnGitHubAction = new OpenBrowserAction("https://github.com/JabRef/jabref", - Localization.menuTitle("Fork me on GitHub"), Localization.lang("Opens JabRef's GitHub page"), IconTheme.JabRefIcons.GITHUB.getSmallIcon(), IconTheme.JabRefIcons.GITHUB.getIcon()); - private final AbstractAction donationAction = new OpenBrowserAction("https://donations.jabref.org", - Localization.menuTitle("Donate to JabRef"), Localization.lang("Donate to JabRef"), IconTheme.JabRefIcons.DONATE.getSmallIcon(), IconTheme.JabRefIcons.DONATE.getIcon()); - private final AbstractAction openForumAction = new OpenBrowserAction("http://discourse.jabref.org/", - Localization.menuTitle("Online help forum"), Localization.lang("Online help forum"), IconTheme.JabRefIcons.FORUM.getSmallIcon(), IconTheme.JabRefIcons.FORUM.getIcon()); + + + private final AbstractAction help = new HelpAction(Localization.menuTitle("Online help"), Localization.lang("Online help"), HelpFile.CONTENTS, Globals.getKeyPrefs().getKey(KeyBinding.HELP)); - private final AbstractAction about = new AboutAction(Localization.menuTitle("About JabRef"), Localization.lang("About JabRef"), - IconTheme.getImage("about")); + private final AbstractAction editEntry = new GeneralAction(Actions.EDIT, Localization.menuTitle("Edit entry"), Localization.lang("Edit entry"), Globals.getKeyPrefs().getKey(KeyBinding.EDIT_ENTRY), IconTheme.JabRefIcons.EDIT_ENTRY.getIcon()); private final AbstractAction focusTable = new GeneralAction(Actions.FOCUS_TABLE, @@ -289,7 +268,6 @@ public void actionPerformed(ActionEvent e) { Globals.getKeyPrefs().getKey(KeyBinding.SYNCHRONIZE_FILES)); private final AbstractAction bibtexKeyPattern = new BibtexKeyPatternAction(); - private final AbstractAction errorConsole = new ErrorConsoleAction(); private final AbstractAction cleanupEntries = new GeneralAction(Actions.CLEANUP, Localization.menuTitle("Cleanup entries") + ELLIPSES, Localization.lang("Cleanup entries"), @@ -602,7 +580,7 @@ public void openAction(String filePath) { public void about() { // reuse the normal about action // null as parameter is OK as the code of actionPerformed does not rely on the data sent in the event. - about.actionPerformed(null); + // about.actionPerformed(null); } // General preferences dialog. The MacAdapter calls this method when "Preferences..." @@ -1030,6 +1008,49 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.MANAGE_PROTECTED_TERMS, new ManageProtectedTermsAction(this, Globals.protectedTermsLoader)), factory.createMenuItem(ActionsFX.MANAGE_CONTENT_SELECTORS, new OldDatabaseCommandWrapper(Actions.MANAGE_SELECTORS, this, Globals.stateManager))); + help.getItems().addAll( + //TODO: This. helpAction + factory.createMenuItem(ActionsFX.OPEN_FORUM, new OpenBrowserAction("https://discourse.jabref.org/")), + new SeparatorMenuItem(), + factory.createMenuItem(ActionsFX.ERROR_CONSOLE, new ErrorConsoleAction()), + new SeparatorMenuItem(), + factory.createMenuItem(ActionsFX.SEARCH_FOR_UPDATES, new SearchForUpdateAction()), + factory.createSubMenu(ActionsFX.WEB_MENU, + factory.createMenuItem(ActionsFX.OPEN_WEBPAGE, new OpenBrowserAction("https://jabref.org/")), + factory.createMenuItem(ActionsFX.OPEN_BLOG, new OpenBrowserAction("https://blog.jabref.org/")), + factory.createMenuItem(ActionsFX.OPEN_FACEBOOK, new OpenBrowserAction("https://www.facebook.com/JabRef/")), + factory.createMenuItem(ActionsFX.OPEN_TWITTER, new OpenBrowserAction("https://twitter.com/jabref_org")), + new SeparatorMenuItem(), + factory.createMenuItem(ActionsFX.FORK_ME, new OpenBrowserAction("https://github.com/JabRef/jabref")), + factory.createMenuItem(ActionsFX.OPEN_DEV_VERSION_LINK, new OpenBrowserAction("https://builds.jabref.org/master/")), + factory.createMenuItem(ActionsFX.OPEN_CHANGELOG, new OpenBrowserAction("https://github.com/JabRef/jabref/blob/master/CHANGELOG.md")), + new SeparatorMenuItem(), + factory.createMenuItem(ActionsFX.DONATE, new OpenBrowserAction("https://donations.jabref.org"))), + factory.createMenuItem(ActionsFX.ABOUT, new AboutAction())); + + /* + + help.add(this.help); + help.add(openForumAction); + help.addSeparator(); + help.add(errorConsole); + help.addSeparator(); + help.add(new SearchForUpdateAction()); + JMenu webMenu = JabRefFrame.subMenu(Localization.menuTitle("JabRef resources")); + webMenu.add(jabrefWebPageAction); + webMenu.add(jabrefBlogAction); + webMenu.add(jabrefFacebookAction); + webMenu.add(jabrefTwitterAction); + webMenu.addSeparator(); + webMenu.add(forkMeOnGitHubAction); + webMenu.add(developmentVersionAction); + webMenu.add(changeLogAction); + webMenu.addSeparator(); + webMenu.add(donationAction); + help.add(webMenu); + help.add(about); + */ + /* factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), diff --git a/src/main/java/org/jabref/gui/actions/ActionsFX.java b/src/main/java/org/jabref/gui/actions/ActionsFX.java index 41bf5637dbd..c09551adfcf 100644 --- a/src/main/java/org/jabref/gui/actions/ActionsFX.java +++ b/src/main/java/org/jabref/gui/actions/ActionsFX.java @@ -103,11 +103,27 @@ public enum ActionsFX { MANAGE_EXTERNAL_FILETYPES(Localization.menuTitle("Manage external file types")), MANAGE_PROTECTED_TERMS(Localization.menuTitle("Manage protected terms")), LIBRARY_PROPERTIES(Localization.menuTitle("Library properties")), - BIBTEX_KEY_PATTERN( Localization.lang("BibTeX key patterns")), + BIBTEX_KEY_PATTERN(Localization.lang("BibTeX key patterns")), SHOW_PREFS(Localization.menuTitle("Preferences")), MANAGE_JOURNALS(Localization.menuTitle("Manage journal abbreviations")), CUSTOMIZE_KEYBINDING(Localization.lang("Customize key bindings"), IconTheme.JabRefIcons.KEY_BINDINGS), - MANAGE_CONTENT_SELECTORS(Localization.menuTitle("Manage content selectors"), IconTheme.JabRefIcons.PREFERENCES); + MANAGE_CONTENT_SELECTORS(Localization.menuTitle("Manage content selectors"), IconTheme.JabRefIcons.PREFERENCES), + + WEB_MENU(Localization.menuTitle("JabRef resources")), + OPEN_WEBPAGE(Localization.menuTitle("Website"), Localization.lang("Opens JabRef's website")), + OPEN_FACEBOOK("Facebook", Localization.lang("Opens JabRef's Facebook page"), IconTheme.JabRefIcons.FACEBOOK), + OPEN_TWITTER("Twitter", Localization.lang("Opens JabRef's Twitter page"), IconTheme.JabRefIcons.TWITTER), + OPEN_BLOG(Localization.menuTitle("Blog"), Localization.lang("Opens JabRef's blog"), IconTheme.JabRefIcons.BLOG), + OPEN_DEV_VERSION_LINK(Localization.menuTitle("Development version"), Localization.lang("Opens a link where the current development version can be downloaded")), + OPEN_CHANGELOG(Localization.menuTitle("View change log"), Localization.lang("See what has been changed in the JabRef versions")), + FORK_ME(Localization.menuTitle("Fork me on GitHub"), Localization.lang("Opens JabRef's GitHub page"), IconTheme.JabRefIcons.GITHUB), + DONATE(Localization.menuTitle("Donate to JabRef"), Localization.lang("Donate to JabRef"), IconTheme.JabRefIcons.DONATE), + OPEN_FORUM(Localization.menuTitle("Online help forum"), Localization.lang("Online help forum"), IconTheme.JabRefIcons.FORUM), + HELP(Localization.menuTitle("Online help"), Localization.lang("Online help"), KeyBinding.HELP), + ERROR_CONSOLE(Localization.menuTitle("View event log"), Localization.lang("Display all error messages")), + SEARCH_FOR_UPDATES(Localization.lang("Check for updates")), + ABOUT(Localization.menuTitle("About JabRef"), Localization.lang("About JabRef")); + private final String text; private final String description; diff --git a/src/main/java/org/jabref/gui/actions/ErrorConsoleAction.java b/src/main/java/org/jabref/gui/actions/ErrorConsoleAction.java index f81b8ce5bae..2ac2dbf6623 100644 --- a/src/main/java/org/jabref/gui/actions/ErrorConsoleAction.java +++ b/src/main/java/org/jabref/gui/actions/ErrorConsoleAction.java @@ -1,14 +1,6 @@ package org.jabref.gui.actions; -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; -import javax.swing.Action; - -import javafx.application.Platform; - import org.jabref.gui.errorconsole.ErrorConsoleView; -import org.jabref.logic.l10n.Localization; /** * Such an error console can be @@ -17,16 +9,11 @@ *

* It offers a separate tab for the log output. */ -public class ErrorConsoleAction extends AbstractAction { - - public ErrorConsoleAction() { - super(Localization.menuTitle("View event log")); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Display all error messages")); - } +public class ErrorConsoleAction extends SimpleCommand { @Override - public void actionPerformed(ActionEvent e) { - Platform.runLater(() -> new ErrorConsoleView().show()); + public void execute() { + new ErrorConsoleView().show(); } } diff --git a/src/main/java/org/jabref/gui/actions/OpenBrowserAction.java b/src/main/java/org/jabref/gui/actions/OpenBrowserAction.java index 56457b4c3d5..992077ef39a 100644 --- a/src/main/java/org/jabref/gui/actions/OpenBrowserAction.java +++ b/src/main/java/org/jabref/gui/actions/OpenBrowserAction.java @@ -1,49 +1,20 @@ package org.jabref.gui.actions; -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.Icon; - import org.jabref.gui.desktop.JabRefDesktop; -public class OpenBrowserAction extends AbstractAction { +public class OpenBrowserAction extends SimpleCommand { private final String urlToOpen; - /** - * OpenBrowserAction without icons - only to be used for menus - * - * @param urlToOpen URL string of an URL to be shown in the default web browser - * @param menuTitle title of the menu entry; should already be localized - * @param description description shown in a tooltip hovering over the menu/icon bar entry; should already be localized - */ - public OpenBrowserAction(String urlToOpen, String menuTitle, String description) { - super(menuTitle); + public OpenBrowserAction(String urlToOpen) { this.urlToOpen = urlToOpen; - putValue(Action.SHORT_DESCRIPTION, description); - } - - /** - * OpenBrowserAction with icons - * - * @param urlToOpen URL string of an URL to be shown in the default web browser - * @param menuTitle title of the menu entry; should already be localized - * @param description description shown in a tooltip hovering over the menu/icon bar entry; should already be localized - * @param smallIcon smallIcon to be shown in the menus - * @param largeIcon larger icon to be shown in the icon bar - */ - public OpenBrowserAction(String urlToOpen, String menuTitle, String description, Icon smallIcon, Icon largeIcon) { - super(menuTitle, smallIcon); - this.urlToOpen = urlToOpen; - putValue(Action.SHORT_DESCRIPTION, description); - putValue(Action.LARGE_ICON_KEY, largeIcon); } @Override - public void actionPerformed(ActionEvent e) { + public void execute() { JabRefDesktop.openBrowserShowPopup(urlToOpen); + } + } diff --git a/src/main/java/org/jabref/gui/actions/SearchForUpdateAction.java b/src/main/java/org/jabref/gui/actions/SearchForUpdateAction.java index acf9807c849..5a8dc415b74 100644 --- a/src/main/java/org/jabref/gui/actions/SearchForUpdateAction.java +++ b/src/main/java/org/jabref/gui/actions/SearchForUpdateAction.java @@ -1,20 +1,11 @@ package org.jabref.gui.actions; -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; - import org.jabref.JabRefGUI; -import org.jabref.logic.l10n.Localization; -public class SearchForUpdateAction extends AbstractAction { - - public SearchForUpdateAction() { - super(Localization.lang("Check for updates")); - } +public class SearchForUpdateAction extends SimpleCommand { @Override - public void actionPerformed(ActionEvent e) { + public void execute() { JabRefGUI.checkForNewVersion(true); } } diff --git a/src/main/java/org/jabref/gui/help/AboutAction.java b/src/main/java/org/jabref/gui/help/AboutAction.java index 3a7eefccac7..ec0e82077a5 100644 --- a/src/main/java/org/jabref/gui/help/AboutAction.java +++ b/src/main/java/org/jabref/gui/help/AboutAction.java @@ -1,24 +1,11 @@ package org.jabref.gui.help; -import java.awt.event.ActionEvent; +import org.jabref.gui.actions.SimpleCommand; -import javax.swing.Action; -import javax.swing.Icon; - -import javafx.application.Platform; - -import org.jabref.gui.actions.MnemonicAwareAction; - -public class AboutAction extends MnemonicAwareAction { - - public AboutAction(String title, String tooltip, Icon iconFile) { - super(iconFile); - putValue(Action.NAME, title); - putValue(Action.SHORT_DESCRIPTION, tooltip); - } +public class AboutAction extends SimpleCommand { @Override - public void actionPerformed(ActionEvent e) { - Platform.runLater(() -> new AboutDialogView().show()); + public void execute() { + new AboutDialogView().show(); } } From 952b39ce5546ff4b8f4542ac275b4204d30f64d1 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sun, 11 Feb 2018 13:08:11 +0100 Subject: [PATCH 059/827] Migrate view menu --- src/main/java/org/jabref/gui/BasePanel.java | 80 +----- src/main/java/org/jabref/gui/GUIGlobals.java | 1 - src/main/java/org/jabref/gui/JabRefFrame.java | 260 ++++++------------ .../java/org/jabref/gui/actions/Actions.java | 3 - .../org/jabref/gui/actions/ActionsFX.java | 7 + .../gui/actions/ShowDocumentViewerAction.java | 12 + .../jabref/gui/actions/SortTabsAction.java | 34 --- .../ShowDocumentViewerAction.java | 32 --- .../org/jabref/gui/keyboard/KeyBinding.java | 6 +- 9 files changed, 112 insertions(+), 323 deletions(-) create mode 100644 src/main/java/org/jabref/gui/actions/ShowDocumentViewerAction.java delete mode 100644 src/main/java/org/jabref/gui/actions/SortTabsAction.java delete mode 100644 src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 6e80a7eff32..91bb712d756 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -158,8 +158,6 @@ public class BasePanel extends StackPane implements ClipboardOwner { private final UndoAction undoAction = new UndoAction(); private final RedoAction redoAction = new RedoAction(); private final CountingUndoManager undoManager; - private final List previousEntries = new ArrayList<>(); - private final List nextEntries = new ArrayList<>(); // Keeps track of the string dialog if it is open. private final Map actions = new HashMap<>(); private final SidePaneManager sidePaneManager; @@ -181,9 +179,7 @@ public class BasePanel extends StackPane implements ClipboardOwner { // Used to track whether the base has changed since last save. private MainTable mainTable; private BibEntry showing; - // Variable to prevent erroneous update of back/forward histories at the time - // when a Back or Forward operation is being processed: - private boolean backOrForwardInProgress; + // in switching between entries. private PreambleEditor preambleEditor; // Keeps track of the preamble dialog if it is open. @@ -337,10 +333,6 @@ private void setupActions() { actions.put(Actions.UNDO, undoAction); actions.put(Actions.REDO, redoAction); - actions.put(Actions.FOCUS_TABLE, (BaseAction) () -> { - mainTable.requestFocus(); - }); - // The action for opening an entry editor. actions.put(Actions.EDIT, (BaseAction) this::showAndEdit); @@ -686,9 +678,6 @@ public void update() { actions.put(Actions.UNABBREVIATE, new UnabbreviateAction(this)); actions.put(Actions.AUTO_SET_FILE, new SynchronizeFileField(this)); - actions.put(Actions.BACK, (BaseAction) BasePanel.this::back); - actions.put(Actions.FORWARD, (BaseAction) BasePanel.this::forward); - actions.put(Actions.RESOLVE_DUPLICATE_KEYS, new SearchFixDuplicateLabels(this)); actions.put(Actions.ADD_TO_GROUP, new GroupAddRemoveDialog(this, true, false)); @@ -1422,7 +1411,7 @@ public void showAndEdit(BibEntry entry) { if (entry != getShowing()) { entryEditor.setEntry(entry); - newEntryShowing(entry); + showing = entry; } entryEditor.requestFocus(); @@ -1804,71 +1793,6 @@ private BibEntry getShowing() { return showing; } - /** - * Update the pointer to the currently shown entry in all cases where the user has moved to a new entry, except when - * using Back and Forward commands. Also updates history for Back command, and clears history for Forward command. - * - * @param entry The entry that is now to be shown. - */ - private void newEntryShowing(BibEntry entry) { - - // If this call is the result of a Back or Forward operation, we must take - // care not to make any history changes, since the necessary changes will - // already have been done in the back() or forward() method: - if (backOrForwardInProgress) { - showing = entry; - backOrForwardInProgress = false; - setBackAndForwardEnabledState(); - return; - } - nextEntries.clear(); - if (!Objects.equals(entry, showing)) { - // Add the entry we are leaving to the history: - if (showing != null) { - previousEntries.add(showing); - if (previousEntries.size() > GUIGlobals.MAX_BACK_HISTORY_SIZE) { - previousEntries.remove(0); - } - } - showing = entry; - setBackAndForwardEnabledState(); - } - } - - /** - * Go back (if there is any recorded history) and update the histories for the Back and Forward commands. - */ - private void back() { - if (!previousEntries.isEmpty()) { - BibEntry toShow = previousEntries.get(previousEntries.size() - 1); - previousEntries.remove(previousEntries.size() - 1); - // Add the entry we are going back from to the Forward history: - if (showing != null) { - nextEntries.add(showing); - } - backOrForwardInProgress = true; // to avoid the history getting updated erroneously - clearAndSelect(toShow); - } - } - - private void forward() { - if (!nextEntries.isEmpty()) { - BibEntry toShow = nextEntries.get(nextEntries.size() - 1); - nextEntries.remove(nextEntries.size() - 1); - // Add the entry we are going forward from to the Back history: - if (showing != null) { - previousEntries.add(showing); - } - backOrForwardInProgress = true; // to avoid the history getting updated erroneously - clearAndSelect(toShow); - } - } - - public void setBackAndForwardEnabledState() { - frame.getBackAction().setEnabled(!previousEntries.isEmpty()); - frame.getForwardAction().setEnabled(!nextEntries.isEmpty()); - } - private String formatOutputMessage(String start, int count) { return String.format("%s %d %s.", start, count, (count > 1 ? Localization.lang("entries") : Localization.lang("entry"))); diff --git a/src/main/java/org/jabref/gui/GUIGlobals.java b/src/main/java/org/jabref/gui/GUIGlobals.java index c5f7eba8a79..8c1e6696abc 100644 --- a/src/main/java/org/jabref/gui/GUIGlobals.java +++ b/src/main/java/org/jabref/gui/GUIGlobals.java @@ -30,7 +30,6 @@ public class GUIGlobals { public static final int WIDTH_ICON_COL_RANKING = 5 * JabRefPreferences.getInstance().getInt(JabRefPreferences.ICON_SIZE_SMALL); // Width of Ranking Icon Column public static final String UNTITLED_TITLE = Localization.lang("untitled"); - public static final int MAX_BACK_HISTORY_SIZE = 10; // The maximum number of "Back" operations stored. // Colors. public static final Color ENTRY_EDITOR_LABEL_COLOR = new Color(100, 100, 150); // Empty field, blue. diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index cf2296ba42f..d404fcab9b4 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -55,6 +55,7 @@ import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.control.Tooltip; +import javafx.scene.input.KeyEvent; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; @@ -84,12 +85,11 @@ import org.jabref.gui.actions.OpenBrowserAction; import org.jabref.gui.actions.SearchForUpdateAction; import org.jabref.gui.actions.SetupGeneralFieldsAction; +import org.jabref.gui.actions.ShowDocumentViewerAction; import org.jabref.gui.actions.ShowPreferencesAction; import org.jabref.gui.actions.SimpleCommand; -import org.jabref.gui.actions.SortTabsAction; import org.jabref.gui.autosaveandbackup.AutosaveUIManager; import org.jabref.gui.bibtexkeypattern.BibtexKeyPatternDialog; -import org.jabref.gui.documentviewer.ShowDocumentViewerAction; import org.jabref.gui.exporter.ExportCommand; import org.jabref.gui.exporter.SaveAllAction; import org.jabref.gui.exporter.SaveDatabaseAction; @@ -150,8 +150,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { // Frame titles. public static final String FRAME_TITLE = "JabRef"; private static final String ELLIPSES = "..."; - public final AbstractAction nextTab = new ChangeTabAction(true); - public final AbstractAction prevTab = new ChangeTabAction(false); private final SplitPane splitPane = new SplitPane(); private final JabRefPreferences prefs = Globals.prefs; private final Insets marg = new Insets(1, 0, 2, 0); @@ -178,16 +176,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { private final AbstractAction help = new HelpAction(Localization.menuTitle("Online help"), Localization.lang("Online help"), HelpFile.CONTENTS, Globals.getKeyPrefs().getKey(KeyBinding.HELP)); - private final AbstractAction editEntry = new GeneralAction(Actions.EDIT, Localization.menuTitle("Edit entry"), - Localization.lang("Edit entry"), Globals.getKeyPrefs().getKey(KeyBinding.EDIT_ENTRY), IconTheme.JabRefIcons.EDIT_ENTRY.getIcon()); - private final AbstractAction focusTable = new GeneralAction(Actions.FOCUS_TABLE, - Localization.menuTitle("Focus entry table"), - Localization.lang("Move the keyboard focus to the entry table"), Globals.getKeyPrefs().getKey(KeyBinding.FOCUS_ENTRY_TABLE)); - private final AbstractAction sortTabs = new SortTabsAction(this); - private final AbstractAction forward = new GeneralAction(Actions.FORWARD, Localization.menuTitle("Forward"), - Localization.lang("Forward"), Globals.getKeyPrefs().getKey(KeyBinding.FORWARD), IconTheme.JabRefIcons.RIGHT.getIcon()); - private final AbstractAction back = new GeneralAction(Actions.BACK, Localization.menuTitle("Back"), - Localization.lang("Back"), Globals.getKeyPrefs().getKey(KeyBinding.BACK), IconTheme.JabRefIcons.LEFT.getIcon()); private final AbstractAction deleteEntry = new GeneralAction(Actions.DELETE, Localization.menuTitle("Delete entry"), Localization.lang("Delete entry"), Globals.getKeyPrefs().getKey(KeyBinding.DELETE_ENTRY), IconTheme.JabRefIcons.DELETE_ENTRY.getIcon()); @@ -224,33 +212,11 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { Localization.lang("Edit strings"), Globals.getKeyPrefs().getKey(KeyBinding.EDIT_STRINGS), IconTheme.JabRefIcons.EDIT_STRINGS.getIcon()); - private final Action toggleToolbar = enableToggle(new AbstractAction(Localization.menuTitle("Hide/show toolbar")) { - - { - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Hide/show toolbar")); - } - - @Override - public void actionPerformed(ActionEvent e) { - tlb.setVisible(!tlb.isVisible()); - } - }); - private final AbstractAction showPdvViewer = new ShowDocumentViewerAction(); private final AbstractAction addToGroup = new GeneralAction(Actions.ADD_TO_GROUP, Localization.lang("Add to group") + ELLIPSES); private final AbstractAction removeFromGroup = new GeneralAction(Actions.REMOVE_FROM_GROUP, Localization.lang("Remove from group") + ELLIPSES); private final AbstractAction moveToGroup = new GeneralAction(Actions.MOVE_TO_GROUP, Localization.lang("Move to group") + ELLIPSES); - private final Action togglePreview = enableToggle(new GeneralAction(Actions.TOGGLE_PREVIEW, - Localization.menuTitle("Toggle entry preview"), - Localization.lang("Toggle entry preview"), - Globals.getKeyPrefs().getKey(KeyBinding.TOGGLE_ENTRY_PREVIEW), - IconTheme.JabRefIcons.TOGGLE_ENTRY_PREVIEW.getIcon())); - private final AbstractAction nextPreviewStyle = new GeneralAction(Actions.NEXT_PREVIEW_STYLE, - Localization.menuTitle("Next preview layout"), - Globals.getKeyPrefs().getKey(KeyBinding.NEXT_PREVIEW_LAYOUT)); - private final AbstractAction previousPreviewStyle = new GeneralAction(Actions.PREVIOUS_PREVIEW_STYLE, - Localization.menuTitle("Previous preview layout"), - Globals.getKeyPrefs().getKey(KeyBinding.PREVIOUS_PREVIEW_LAYOUT)); + private final AbstractAction makeKeyAction = new GeneralAction(Actions.MAKE_KEY, Localization.menuTitle("Autogenerate BibTeX keys"), Localization.lang("Autogenerate BibTeX keys"), @@ -280,9 +246,6 @@ public void actionPerformed(ActionEvent e) { private final AbstractAction downloadFullText = new GeneralAction(Actions.DOWNLOAD_FULL_TEXT, Localization.menuTitle("Look up full text documents"), Globals.getKeyPrefs().getKey(KeyBinding.DOWNLOAD_FULL_TEXT)); - private final AbstractAction increaseFontSize = new IncreaseTableFontSizeAction(); - private final AbstractAction defaultFontSize = new DefaultTableFontSizeAction(); - private final AbstractAction decreseFontSize = new DecreaseTableFontSizeAction(); private final AbstractAction resolveDuplicateKeys = new GeneralAction(Actions.RESOLVE_DUPLICATE_KEYS, Localization.menuTitle("Resolve duplicate BibTeX keys"), Localization.lang("Find and remove duplicate BibTeX keys"), @@ -431,6 +394,8 @@ private void init() { initActions(); + initKeyBindings(); + // Show the toolbar if it was visible at last shutdown: tlb.setVisible(Globals.prefs.getBoolean(JabRefPreferences.TOOLBAR_VISIBLE)); @@ -483,8 +448,7 @@ private void init() { setWindowTitle(); // Update search autocompleter with information for the correct database: currentBasePanel.updateSearchManager(); - // Set correct enabled state for Back and Forward actions: - currentBasePanel.setBackAndForwardEnabledState(); + currentBasePanel.getUndoManager().postUndoRedoEvent(); currentBasePanel.getMainTable().requestFocus(); }); @@ -504,6 +468,41 @@ private void init() { } + private void initKeyBindings() { + addEventFilter(KeyEvent.KEY_PRESSED, event -> { + Optional keyBinding = Globals.getKeyPrefs().mapToKeyBinding(event); + if (keyBinding.isPresent()) { + switch (keyBinding.get()) { + case FOCUS_ENTRY_TABLE: + getCurrentBasePanel().getMainTable().requestFocus(); + event.consume(); + break; + case NEXT_LIBRARY: + tabbedPane.getSelectionModel().selectNext(); + event.consume(); + break; + case PREVIOUS_LIBRARY: + tabbedPane.getSelectionModel().selectPrevious(); + event.consume(); + break; + case INCREASE_TABLE_FONT_SIZE: + increaseTableFontSize(); + event.consume(); + break; + case DECREASE_TABLE_FONT_SIZE: + decreaseTableFontSize(); + event.consume(); + break; + case DEFAULT_TABLE_FONT_SIZE: + setDefaultTableFontSize(); + event.consume(); + break; + default: + } + } + }); + } + private void initShowTrackingNotification() { if (!Globals.prefs.shouldAskToCollectTelemetry()) { JabRefExecutorService.INSTANCE.submit(new TimerTask() { @@ -885,7 +884,8 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.IMPORT_INTO_NEW_LIBRARY, new ImportCommand(this, false)), factory.createMenuItem(ActionsFX.EXPORT_ALL, new ExportCommand(this, false)), factory.createMenuItem(ActionsFX.EXPORT_SELECTED, new ExportCommand(this, true)), - factory.createMenuItem(ActionsFX.SAVE_SELECTED_AS_PLAIN_BIBTEX, new OldDatabaseCommandWrapper(Actions.SAVE_SELECTED_AS_PLAIN, this, Globals.stateManager))), + factory.createMenuItem(ActionsFX.SAVE_SELECTED_AS_PLAIN_BIBTEX, new OldDatabaseCommandWrapper(Actions.SAVE_SELECTED_AS_PLAIN, this, Globals.stateManager)) + ), new SeparatorMenuItem(), @@ -899,7 +899,8 @@ private MenuBar createMenu() { new SeparatorMenuItem(), factory.createMenuItem(ActionsFX.CLOSE_LIBRARY, new CloseDatabaseAction()), - factory.createMenuItem(ActionsFX.QUIT, new CloseAction())); + factory.createMenuItem(ActionsFX.QUIT, new CloseAction()) + ); edit.getItems().addAll( factory.createMenuItem(ActionsFX.UNDO, new OldDatabaseCommandWrapper(Actions.UNDO, this, Globals.stateManager)), @@ -916,7 +917,8 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.COPY_KEY_AND_TITLE, new OldDatabaseCommandWrapper(Actions.COPY_KEY_AND_TITLE, this, Globals.stateManager)), factory.createMenuItem(ActionsFX.COPY_KEY_AND_LINK, new OldDatabaseCommandWrapper(Actions.COPY_KEY_AND_LINK, this, Globals.stateManager)), factory.createMenuItem(ActionsFX.COPY_CITATION_PREVIEW, new OldDatabaseCommandWrapper(Actions.COPY_CITATION_HTML, this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.EXPORT_SELECTED_TO_CLIPBOARD, new OldDatabaseCommandWrapper(Actions.EXPORT_TO_CLIPBOARD, this, Globals.stateManager))), + factory.createMenuItem(ActionsFX.EXPORT_SELECTED_TO_CLIPBOARD, new OldDatabaseCommandWrapper(Actions.EXPORT_TO_CLIPBOARD, this, Globals.stateManager)) + ), factory.createMenuItem(ActionsFX.PASTE, new EditAction(Actions.PASTE)), @@ -924,7 +926,8 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.SEND_AS_EMAIL, new OldDatabaseCommandWrapper(Actions.SEND_AS_EMAIL, this, Globals.stateManager)), - new SeparatorMenuItem()); + new SeparatorMenuItem() + ); /* edit.add(mark); for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) { @@ -974,12 +977,30 @@ private MenuBar createMenu() { } */ - //factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), - edit.getItems().addAll( factory.createMenuItem(ActionsFX.MANAGE_KEYWORDS, new ManageKeywordsAction(this)), factory.createMenuItem(ActionsFX.REPLACE_ALL, new OldDatabaseCommandWrapper(Actions.REPLACE_ALL, this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.MASS_SET_FIELDS, new MassSetFieldAction(this))); + factory.createMenuItem(ActionsFX.MASS_SET_FIELDS, new MassSetFieldAction(this)) + ); + + SidePaneComponent webSearch = sidePaneManager.getComponent(SidePaneType.WEB_SEARCH); + SidePaneComponent groups = sidePaneManager.getComponent(SidePaneType.GROUPS); + view.getItems().addAll( + factory.createMenuItem(webSearch.getToggleAction(), webSearch.getToggleCommand()), + factory.createMenuItem(groups.getToggleAction(), groups.getToggleCommand()), + factory.createMenuItem(ActionsFX.TOGGLE_PREVIEW, new OldDatabaseCommandWrapper(Actions.TOGGLE_PREVIEW, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.EDIT_ENTRY, new OldDatabaseCommandWrapper(Actions.EDIT, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.SHOW_PDV_VIEWER, new ShowDocumentViewerAction()), + + new SeparatorMenuItem(), + + factory.createMenuItem(ActionsFX.SELECT_ALL, new OldDatabaseCommandWrapper(Actions.SELECT_ALL, this, Globals.stateManager)), + + new SeparatorMenuItem(), + + factory.createMenuItem(ActionsFX.NEXT_PREVIEW_STYLE, new OldDatabaseCommandWrapper(Actions.NEXT_PREVIEW_STYLE, this, Globals.stateManager)), + factory.createMenuItem(ActionsFX.PREVIOUS_PREVIEW_STYLE, new OldDatabaseCommandWrapper(Actions.PREVIOUS_PREVIEW_STYLE, this, Globals.stateManager)) + ); tools.getItems().addAll( factory.createMenuItem(ActionsFX.NEW_SUB_LIBRARY_FROM_AUX, new NewSubLibraryAction(this)), @@ -994,7 +1015,6 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.ABBREVIATE_ISO, new OldDatabaseCommandWrapper(Actions.ABBREVIATE_ISO, this, Globals.stateManager)), factory.createMenuItem(ActionsFX.ABBREVIATE_MEDLINE, new OldDatabaseCommandWrapper(Actions.ABBREVIATE_MEDLINE, this, Globals.stateManager)), factory.createMenuItem(ActionsFX.UNABBREVIATE, new OldDatabaseCommandWrapper(Actions.UNABBREVIATE, this, Globals.stateManager)) - ); options.getItems().addAll( @@ -1006,50 +1026,41 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.MANAGE_JOURNALS, new ManageJournalsAction()), factory.createMenuItem(ActionsFX.CUSTOMIZE_KEYBINDING, new CustomizeKeyBindingAction()), factory.createMenuItem(ActionsFX.MANAGE_PROTECTED_TERMS, new ManageProtectedTermsAction(this, Globals.protectedTermsLoader)), - factory.createMenuItem(ActionsFX.MANAGE_CONTENT_SELECTORS, new OldDatabaseCommandWrapper(Actions.MANAGE_SELECTORS, this, Globals.stateManager))); + factory.createMenuItem(ActionsFX.MANAGE_CONTENT_SELECTORS, new OldDatabaseCommandWrapper(Actions.MANAGE_SELECTORS, this, Globals.stateManager)) + ); help.getItems().addAll( //TODO: This. helpAction factory.createMenuItem(ActionsFX.OPEN_FORUM, new OpenBrowserAction("https://discourse.jabref.org/")), + new SeparatorMenuItem(), + factory.createMenuItem(ActionsFX.ERROR_CONSOLE, new ErrorConsoleAction()), + new SeparatorMenuItem(), + factory.createMenuItem(ActionsFX.SEARCH_FOR_UPDATES, new SearchForUpdateAction()), factory.createSubMenu(ActionsFX.WEB_MENU, factory.createMenuItem(ActionsFX.OPEN_WEBPAGE, new OpenBrowserAction("https://jabref.org/")), factory.createMenuItem(ActionsFX.OPEN_BLOG, new OpenBrowserAction("https://blog.jabref.org/")), factory.createMenuItem(ActionsFX.OPEN_FACEBOOK, new OpenBrowserAction("https://www.facebook.com/JabRef/")), factory.createMenuItem(ActionsFX.OPEN_TWITTER, new OpenBrowserAction("https://twitter.com/jabref_org")), + new SeparatorMenuItem(), + factory.createMenuItem(ActionsFX.FORK_ME, new OpenBrowserAction("https://github.com/JabRef/jabref")), factory.createMenuItem(ActionsFX.OPEN_DEV_VERSION_LINK, new OpenBrowserAction("https://builds.jabref.org/master/")), factory.createMenuItem(ActionsFX.OPEN_CHANGELOG, new OpenBrowserAction("https://github.com/JabRef/jabref/blob/master/CHANGELOG.md")), + new SeparatorMenuItem(), - factory.createMenuItem(ActionsFX.DONATE, new OpenBrowserAction("https://donations.jabref.org"))), - factory.createMenuItem(ActionsFX.ABOUT, new AboutAction())); - /* + factory.createMenuItem(ActionsFX.DONATE, new OpenBrowserAction("https://donations.jabref.org")) + ), + factory.createMenuItem(ActionsFX.ABOUT, new AboutAction()) + ); + + - help.add(this.help); - help.add(openForumAction); - help.addSeparator(); - help.add(errorConsole); - help.addSeparator(); - help.add(new SearchForUpdateAction()); - JMenu webMenu = JabRefFrame.subMenu(Localization.menuTitle("JabRef resources")); - webMenu.add(jabrefWebPageAction); - webMenu.add(jabrefBlogAction); - webMenu.add(jabrefFacebookAction); - webMenu.add(jabrefTwitterAction); - webMenu.addSeparator(); - webMenu.add(forkMeOnGitHubAction); - webMenu.add(developmentVersionAction); - webMenu.add(changeLogAction); - webMenu.addSeparator(); - webMenu.add(donationAction); - help.add(webMenu); - help.add(about); - */ /* factory.createMenuItem(ActionsFX., new OldDatabaseCommandWrapper(Actions., this, Globals.stateManager)), @@ -1071,24 +1082,7 @@ private MenuBar createMenu() { groups.add(moveToGroup); mb.add(groups); - view.add(getBackAction()); - view.add(getForwardAction()); - view.add(focusTable); - view.add(nextTab); - view.add(prevTab); - view.add(sortTabs); - view.addSeparator(); - view.add(increaseFontSize); - view.add(decreseFontSize); - view.add(defaultFontSize); - view.addSeparator(); - view.add(new JCheckBoxMenuItem(toggleToolbar)); - view.add(new JCheckBoxMenuItem(enableToggle(generalFetcher.getToggleCommand()))); - view.add(new JCheckBoxMenuItem(groupSidePane.getToggleCommand())); - view.add(new JCheckBoxMenuItem(togglePreview)); - view.add(showPdvViewer); - view.add(getNextPreviewStyleAction()); - view.add(getPreviousPreviewStyleAction()); + mb.add(view); @@ -1101,7 +1095,6 @@ private MenuBar createMenu() { library.add(plainTextImport); library.addSeparator(); - library.add(editEntry); library.add(editPreamble); library.add(editStrings); library.addSeparator(); @@ -1386,8 +1379,6 @@ public void updateEnabledState(ListChangeListener.Change change) setEnabled(severalDatabasesOnlyActions, tabCount > 1); } if (tabCount == 0) { - getBackAction().setEnabled(false); - getForwardAction().setEnabled(false); setEnabled(openAndSavedDatabasesOnlyActions, false); setEnabled(sharedDatabaseOnlyActions, false); setEnabled(oneEntryOnlyActions, false); @@ -1569,15 +1560,6 @@ public void createDisabledIconsForButtons(Container container) { } } - public void sortTabs() { - // We are going to be crude: remove all tabs and re-add them in a sorted way - // This is ugly, but otherwise we run into issues: https://stackoverflow.com/questions/37328760/javafx-tabpane-sorting-tabs-creates-havoc - List tabs = new ArrayList<>(tabbedPane.getTabs()); - tabs.sort((o1, o2) -> o2.getText().compareTo(o1.getText())); - tabbedPane.getTabs().clear(); - tabbedPane.getTabs().setAll(tabs); - } - /** * This method does the job of adding imported entries into the active * database, or into a new one. It shows the ImportInspectionDialog if @@ -1833,22 +1815,6 @@ public String getStatusLineText() { return statusLine.getText(); } - public AbstractAction getForwardAction() { - return forward; - } - - public AbstractAction getBackAction() { - return back; - } - - public AbstractAction getNextPreviewStyleAction() { - return nextPreviewStyle; - } - - public AbstractAction getPreviousPreviewStyleAction() { - return previousPreviewStyle; - } - public SplitPane getSplitPane() { return splitPane; } @@ -1975,27 +1941,6 @@ public void execute() { } } - private class ChangeTabAction extends MnemonicAwareAction { - - private final boolean next; - - public ChangeTabAction(boolean next) { - putValue(Action.NAME, next ? Localization.menuTitle("Next tab") : Localization.menuTitle("Previous tab")); - this.next = next; - putValue(Action.ACCELERATOR_KEY, - next ? Globals.getKeyPrefs().getKey(KeyBinding.NEXT_TAB) : Globals.getKeyPrefs().getKey(KeyBinding.PREVIOUS_TAB)); - } - - @Override - public void actionPerformed(ActionEvent e) { - if (next) { - tabbedPane.getSelectionModel().selectNext(); - } else { - tabbedPane.getSelectionModel().selectPrevious(); - } - } - } - /** * Class for handling general actions; cut, copy and paste. The focused component is * kept track of by Globals.focusListener, and we call the action stored under the @@ -2044,49 +1989,23 @@ public void actionPerformed(ActionEvent e) { } - private class DefaultTableFontSizeAction extends MnemonicAwareAction { - - public DefaultTableFontSizeAction() { - putValue(Action.NAME, Localization.menuTitle("Default table font size")); - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.DEFAULT_TABLE_FONT_SIZE)); - } - - @Override - public void actionPerformed(ActionEvent event) { + private void setDefaultTableFontSize() { GUIGlobals.setFont(Globals.prefs.getIntDefault(JabRefPreferences.FONT_SIZE)); for (BasePanel basePanel : getBasePanelList()) { basePanel.updateTableFont(); } setStatus(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize()))); } - } - - private class IncreaseTableFontSizeAction extends MnemonicAwareAction { - - public IncreaseTableFontSizeAction() { - putValue(Action.NAME, Localization.menuTitle("Increase table font size")); - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.INCREASE_TABLE_FONT_SIZE)); - } - @Override - public void actionPerformed(ActionEvent event) { + private void increaseTableFontSize() { GUIGlobals.setFont(GUIGlobals.currentFont.getSize() + 1); for (BasePanel basePanel : getBasePanelList()) { basePanel.updateTableFont(); } setStatus(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize()))); } - } - - private class DecreaseTableFontSizeAction extends MnemonicAwareAction { - - public DecreaseTableFontSizeAction() { - putValue(Action.NAME, Localization.menuTitle("Decrease table font size")); - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.DECREASE_TABLE_FONT_SIZE)); - } - @Override - public void actionPerformed(ActionEvent event) { + private void decreaseTableFontSize() { int currentSize = GUIGlobals.currentFont.getSize(); if (currentSize < 2) { return; @@ -2097,7 +2016,6 @@ public void actionPerformed(ActionEvent event) { } setStatus(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize()))); } - } private class CloseDatabaseAction extends SimpleCommand { diff --git a/src/main/java/org/jabref/gui/actions/Actions.java b/src/main/java/org/jabref/gui/actions/Actions.java index db244f3911c..6c4ea110cca 100644 --- a/src/main/java/org/jabref/gui/actions/Actions.java +++ b/src/main/java/org/jabref/gui/actions/Actions.java @@ -10,7 +10,6 @@ public enum Actions { ADD_FILE_LINK, ADD_TO_GROUP, AUTO_SET_FILE, - BACK, CLEANUP, COPY, COPY_CITATION_ASCII_DOC, @@ -31,8 +30,6 @@ public enum Actions { EDIT_PREAMBLE, EDIT_STRINGS, EXPORT_TO_CLIPBOARD, - FOCUS_TABLE, - FORWARD, MAKE_KEY, MANAGE_SELECTORS, MARK_ENTRIES, diff --git a/src/main/java/org/jabref/gui/actions/ActionsFX.java b/src/main/java/org/jabref/gui/actions/ActionsFX.java index c09551adfcf..6ab22ddfb65 100644 --- a/src/main/java/org/jabref/gui/actions/ActionsFX.java +++ b/src/main/java/org/jabref/gui/actions/ActionsFX.java @@ -109,6 +109,13 @@ public enum ActionsFX { CUSTOMIZE_KEYBINDING(Localization.lang("Customize key bindings"), IconTheme.JabRefIcons.KEY_BINDINGS), MANAGE_CONTENT_SELECTORS(Localization.menuTitle("Manage content selectors"), IconTheme.JabRefIcons.PREFERENCES), + TOGGLE_PREVIEW(Localization.lang("Toggle entry preview"), IconTheme.JabRefIcons.TOGGLE_ENTRY_PREVIEW, KeyBinding.TOGGLE_ENTRY_PREVIEW), + EDIT_ENTRY(Localization.lang("Edit entry"), IconTheme.JabRefIcons.EDIT_ENTRY, KeyBinding.EDIT_ENTRY), + SHOW_PDV_VIEWER(Localization.lang("Show document viewer"), IconTheme.JabRefIcons.PDF_FILE), + NEXT_PREVIEW_STYLE(Localization.menuTitle("Next preview layout"), KeyBinding.NEXT_PREVIEW_LAYOUT), + PREVIOUS_PREVIEW_STYLE(Localization.menuTitle("Previous preview layout"), KeyBinding.PREVIOUS_PREVIEW_LAYOUT), + SELECT_ALL(Localization.menuTitle("Select all"), KeyBinding.SELECT_ALL), + WEB_MENU(Localization.menuTitle("JabRef resources")), OPEN_WEBPAGE(Localization.menuTitle("Website"), Localization.lang("Opens JabRef's website")), OPEN_FACEBOOK("Facebook", Localization.lang("Opens JabRef's Facebook page"), IconTheme.JabRefIcons.FACEBOOK), diff --git a/src/main/java/org/jabref/gui/actions/ShowDocumentViewerAction.java b/src/main/java/org/jabref/gui/actions/ShowDocumentViewerAction.java new file mode 100644 index 00000000000..7c15ae6d119 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/ShowDocumentViewerAction.java @@ -0,0 +1,12 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.documentviewer.DocumentViewerView; + +public class ShowDocumentViewerAction extends SimpleCommand { + + @Override + public void execute() { + new DocumentViewerView().show(); + } + +} diff --git a/src/main/java/org/jabref/gui/actions/SortTabsAction.java b/src/main/java/org/jabref/gui/actions/SortTabsAction.java deleted file mode 100644 index 952ad7ca64c..00000000000 --- a/src/main/java/org/jabref/gui/actions/SortTabsAction.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.jabref.gui.actions; - -import java.awt.event.ActionEvent; -import java.util.Comparator; -import java.util.Locale; - -import javax.swing.Action; - -import org.jabref.gui.JabRefFrame; -import org.jabref.logic.l10n.Localization; - -/** - * This action rearranges all tabs in the main tabbed pane of the given JabRefFrame - * in alphabetical order. - */ -public class SortTabsAction extends MnemonicAwareAction implements Comparator { - private final JabRefFrame frame; - - public SortTabsAction(JabRefFrame frame) { - putValue(Action.NAME, Localization.menuTitle("Sort tabs")); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Rearrange tabs alphabetically by title")); - this.frame = frame; - } - - @Override - public void actionPerformed(ActionEvent e) { - frame.sortTabs(); - } - - @Override - public int compare(String o1, String o2) { - return o1.toLowerCase(Locale.ROOT).compareTo(o2.toLowerCase(Locale.ROOT)); - } -} diff --git a/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java b/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java deleted file mode 100644 index 6735edaf1cc..00000000000 --- a/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.jabref.gui.documentviewer; - -import java.awt.event.ActionEvent; - -import javax.swing.Action; -import javax.swing.Icon; - -import javafx.application.Platform; - -import org.jabref.gui.IconTheme; -import org.jabref.gui.actions.MnemonicAwareAction; -import org.jabref.logic.l10n.Localization; - -public class ShowDocumentViewerAction extends MnemonicAwareAction { - - public ShowDocumentViewerAction(String title, String tooltip, Icon iconFile) { - super(iconFile); - putValue(Action.NAME, title); - putValue(Action.SHORT_DESCRIPTION, tooltip); - } - - public ShowDocumentViewerAction() { - this(Localization.menuTitle("Show document viewer"), Localization.lang("Show document viewer"), - IconTheme.JabRefIcons.PDF_FILE.getIcon()); - } - - @Override - public void actionPerformed(ActionEvent e) { - Platform.runLater(() -> new DocumentViewerView().show()); - } - -} diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java index 6138ae09dd2..db4b228bdb2 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java @@ -8,7 +8,6 @@ public enum KeyBinding { AUTOGENERATE_BIBTEX_KEYS("Autogenerate BibTeX keys", Localization.lang("Autogenerate BibTeX keys"), "ctrl+G", KeyBindingCategory.QUALITY), ACCEPT("Accept", Localization.lang("Accept"), "ctrl+ENTER", KeyBindingCategory.EDIT), AUTOMATICALLY_LINK_FILES("Automatically link files", Localization.lang("Automatically set file links"), "F7", KeyBindingCategory.QUALITY), - BACK("Back", Localization.lang("Back"), "alt+LEFT", KeyBindingCategory.VIEW), CHECK_INTEGRITY("Check integrity", Localization.menuTitle("Check integrity"), "ctrl+F8", KeyBindingCategory.QUALITY), CLEANUP("Cleanup", Localization.lang("Cleanup entries"), "alt+F8", KeyBindingCategory.QUALITY), CLOSE_DATABASE("Close library", Localization.lang("Close library"), "ctrl+W", KeyBindingCategory.FILE), @@ -38,7 +37,6 @@ public enum KeyBinding { FILE_LIST_EDITOR_MOVE_ENTRY_UP("File list editor, move entry up", Localization.lang("File list editor, move entry up"), "ctrl+UP", KeyBindingCategory.VIEW), FIND_UNLINKED_FILES("Find unlinked files", Localization.lang("Find unlinked files"), "shift+F7", KeyBindingCategory.QUALITY), FOCUS_ENTRY_TABLE("Focus entry table", Localization.lang("Focus entry table"), "alt+1", KeyBindingCategory.VIEW), - FORWARD("Forward", Localization.lang("Forward"), "alt+RIGHT", KeyBindingCategory.VIEW), GLOBAL_SEARCH("Search globally", Localization.lang("Search globally"), "ctrl+shift+F", KeyBindingCategory.SEARCH), HELP("Help", Localization.lang("Help"), "F1", KeyBindingCategory.FILE), IMPORT_INTO_CURRENT_DATABASE("Import into current library", Localization.lang("Import into current library"), "ctrl+I", KeyBindingCategory.FILE), @@ -57,7 +55,7 @@ public enum KeyBinding { NEW_UNPUBLISHED("New unpublished", Localization.lang("New unpublished"), "ctrl+shift+U", KeyBindingCategory.BIBTEX), NEW_TECHREPORT("New technical report", Localization.lang("New technical report"), "ctrl+shift+R", KeyBindingCategory.BIBTEX), NEXT_PREVIEW_LAYOUT("Next preview layout", Localization.lang("Next preview layout"), "F9", KeyBindingCategory.VIEW), - NEXT_TAB("Next tab", Localization.lang("Next tab"), "ctrl+PAGE_DOWN", KeyBindingCategory.VIEW), + NEXT_LIBRARY("Next library", Localization.lang("Next library"), "ctrl+PAGE_DOWN", KeyBindingCategory.VIEW), OPEN_CONSOLE("Open terminal here", Localization.lang("Open terminal here"), "ctrl+shift+L", KeyBindingCategory.TOOLS), OPEN_DATABASE("Open library", Localization.lang("Open library"), "ctrl+O", KeyBindingCategory.FILE), OPEN_FILE("Open file", Localization.lang("Open file"), "F4", KeyBindingCategory.TOOLS), @@ -68,7 +66,7 @@ public enum KeyBinding { PULL_CHANGES_FROM_SHARED_DATABASE("Pull changes from shared database", Localization.lang("Pull changes from shared database"), "ctrl+shift+R", KeyBindingCategory.FILE), PREAMBLE_EDITOR_STORE_CHANGES("Preamble editor, store changes", Localization.lang("Preamble editor, store changes"), "alt+S", KeyBindingCategory.FILE), PREVIOUS_PREVIEW_LAYOUT("Previous preview layout", Localization.lang("Previous preview layout"), "shift+F9", KeyBindingCategory.VIEW), - PREVIOUS_TAB("Previous tab", Localization.lang("Previous tab"), "ctrl+PAGE_UP", KeyBindingCategory.VIEW), + PREVIOUS_LIBRARY("Previous library", Localization.lang("Previous library"), "ctrl+PAGE_UP", KeyBindingCategory.VIEW), PUSH_TO_APPLICATION("Push to application", Localization.lang("Push to application"), "ctrl+L", KeyBindingCategory.TOOLS), QUIT_JABREF("Quit JabRef", Localization.lang("Quit JabRef"), "ctrl+Q", KeyBindingCategory.FILE), REDO("Redo", Localization.lang("Redo"), "ctrl+Y", KeyBindingCategory.EDIT), From 249dc8a783f9e099b948f7c33d4ee0174642430f Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sun, 11 Feb 2018 13:43:56 +0100 Subject: [PATCH 060/827] reduce new FXDialogService --- src/main/java/org/jabref/gui/BasePanel.java | 13 +++++-------- .../java/org/jabref/gui/FXDialogService.java | 7 +++++++ .../org/jabref/gui/FindUnlinkedFilesDialog.java | 2 +- src/main/java/org/jabref/gui/JabRefFrame.java | 7 ++++++- src/main/java/org/jabref/gui/PreviewPanel.java | 7 ++++--- .../org/jabref/gui/actions/CopyFilesAction.java | 6 +++--- .../org/jabref/gui/auximport/FromAuxDialog.java | 5 +---- .../ResolveDuplicateLabelDialog.java | 3 ++- .../gui/collab/EntryAddChangeViewModel.java | 3 ++- .../gui/collab/EntryDeleteChangeViewModel.java | 3 ++- .../gui/entryeditor/DeprecatedFieldsTab.java | 5 +++-- .../org/jabref/gui/entryeditor/EntryEditor.java | 17 ++++++++++------- .../jabref/gui/entryeditor/FieldsEditorTab.java | 8 +++++--- .../gui/entryeditor/OptionalFields2Tab.java | 5 +++-- .../gui/entryeditor/OptionalFieldsTab.java | 5 +++-- .../jabref/gui/entryeditor/OtherFieldsTab.java | 5 +++-- .../gui/entryeditor/RequiredFieldsTab.java | 5 +++-- .../gui/entryeditor/UserDefinedFieldsTab.java | 5 +++-- .../jabref/gui/exporter/CustomExportDialog.java | 7 ++----- .../org/jabref/gui/exporter/ExportCommand.java | 3 +-- .../jabref/gui/exporter/SaveDatabaseAction.java | 3 +-- .../gui/fieldeditors/LinkedFileViewModel.java | 6 +++--- .../LinkedFilesEditorViewModel.java | 14 +++++++------- .../gui/filelist/FileListEntryEditor.java | 7 ++----- .../org/jabref/gui/importer/ImportCommand.java | 3 +-- .../gui/importer/ImportCustomizationDialog.java | 5 ++--- .../gui/importer/ImportInspectionDialog.java | 2 +- .../org/jabref/gui/importer/ImportMenuItem.java | 3 +-- .../importer/actions/AppendDatabaseAction.java | 3 +-- .../importer/actions/OpenDatabaseAction.java | 3 +-- .../org/jabref/gui/maintable/MainTable.java | 2 +- .../gui/maintable/MainTableColumnFactory.java | 9 ++++++--- .../jabref/gui/mergeentries/MergeEntries.java | 3 ++- .../jabref/gui/openoffice/OpenOfficePanel.java | 16 +++++++--------- .../gui/openoffice/StyleSelectDialog.java | 7 ++----- .../gui/plaintextimport/TextInputDialog.java | 3 +-- .../java/org/jabref/gui/preftabs/FileTab.java | 7 ++----- .../jabref/gui/preftabs/PreferencesDialog.java | 5 ++--- .../jabref/gui/preftabs/PreviewPrefsTab.java | 3 ++- .../protectedterms/ProtectedTermsDialog.java | 3 +-- .../jabref/gui/search/SearchResultFrame.java | 2 +- .../shared/ConnectToSharedDatabaseDialog.java | 3 +-- .../org/jabref/gui/worker/VersionWorker.java | 3 ++- 43 files changed, 119 insertions(+), 117 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 91bb712d756..7cf7ac4bfbd 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -192,6 +192,7 @@ public class BasePanel extends StackPane implements ClipboardOwner { private Optional currentSearchQuery = Optional.empty(); private Optional changeMonitor = Optional.empty(); + private final DialogService dialogService; public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabaseContext bibDatabaseContext, ExternalFileTypes externalFileTypes) { this.preferences = Objects.requireNonNull(preferences); @@ -199,6 +200,7 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext); this.externalFileTypes = Objects.requireNonNull(externalFileTypes); this.undoManager = frame.getUndoManager(); + this.dialogService = frame.getDialogService(); bibDatabaseContext.getDatabase().registerListener(this); bibDatabaseContext.getMetaData().registerListener(this); @@ -236,9 +238,9 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas this.getDatabase().registerListener(new UpdateTimestampListener(Globals.prefs)); - this.entryEditor = new EntryEditor(this, preferences.getEntryEditorPreferences(), Globals.getFileUpdateMonitor()); + this.entryEditor = new EntryEditor(this, preferences.getEntryEditorPreferences(), Globals.getFileUpdateMonitor(), dialogService); - this.preview = new PreviewPanel(this, getBibDatabaseContext(), preferences.getKeyBindings(), preferences.getPreviewPreferences()); + this.preview = new PreviewPanel(this, getBibDatabaseContext(), preferences.getKeyBindings(), preferences.getPreviewPreferences(), dialogService); DefaultTaskExecutor.runInJavaFXThread(() -> frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview)); } @@ -1638,7 +1640,6 @@ private void changeType(List entries, String newType) { } if (entries.size() > 1) { - DialogService dialogService = new FXDialogService(); boolean proceed = dialogService.showConfirmationDialogAndWait(Localization.lang("Change entry type"), Localization.lang("Multiple entries selected. Do you want to change the type of all these to '%0'?")); if (!proceed) { return; @@ -2103,11 +2104,7 @@ public void action() throws SaveException { .addExtensionFilter(FileType.BIBTEX_DB) .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); - DialogService ds = new FXDialogService(); - - Optional chosenFile = DefaultTaskExecutor - .runInJavaFXThread(() -> ds.showFileSaveDialog(fileDialogConfiguration)); - + Optional chosenFile = dialogService.showFileSaveDialog(fileDialogConfiguration); if (chosenFile.isPresent()) { Path path = chosenFile.get(); saveDatabase(path.toFile(), true, Globals.prefs.getDefaultEncoding(), saveType); diff --git a/src/main/java/org/jabref/gui/FXDialogService.java b/src/main/java/org/jabref/gui/FXDialogService.java index a42523f17bf..cc84c24758d 100644 --- a/src/main/java/org/jabref/gui/FXDialogService.java +++ b/src/main/java/org/jabref/gui/FXDialogService.java @@ -38,6 +38,13 @@ */ public class FXDialogService implements DialogService { + /** + * @deprecated try not to initialize a new dialog service but reuse the one constructed in {@link org.jabref.JabRefMain}. + */ + @Deprecated + public FXDialogService() { + } + private static FXDialog createDialog(AlertType type, String title, String content) { FXDialog alert = new FXDialog(type, title, true); alert.setHeaderText(null); diff --git a/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java b/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java index 01c4d16faa0..c57daebeff1 100644 --- a/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java +++ b/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java @@ -585,7 +585,7 @@ private void setupActions() { DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder() .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); - DialogService ds = new FXDialogService(); + DialogService ds = frame.getDialogService(); /** * Stores the selected directory. */ diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index d404fcab9b4..dbe0966f310 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -288,9 +288,11 @@ public class JabRefFrame extends BorderPane implements OutputPrinter { private PushToApplications pushApplications; private JMenu newSpec; private final CountingUndoManager undoManager = new CountingUndoManager(); + private final DialogService dialogService; public JabRefFrame(Stage mainStage) { this.mainStage = mainStage; + this.dialogService = new FXDialogService(); init(); } @@ -519,7 +521,6 @@ public void run() { private Void showTrackingNotification() { if (!Globals.prefs.shouldCollectTelemetry()) { - DialogService dialogService = new FXDialogService(); boolean shouldCollect = dialogService.showConfirmationDialogAndWait( Localization.lang("Telemetry: Help make JabRef better"), Localization.lang("To improve the user experience, we would like to collect anonymous statistics on the features you use. We will only record what features you access and how often you do it. We will neither collect any personal data nor the content of bibliographic items. If you choose to allow data collection, you can later disable it via Options -> Preferences -> General."), @@ -1839,6 +1840,10 @@ public CountingUndoManager getUndoManager() { return undoManager; } + public DialogService getDialogService() { + return dialogService; + } + private static class MyGlassPane extends JPanel { public MyGlassPane() { diff --git a/src/main/java/org/jabref/gui/PreviewPanel.java b/src/main/java/org/jabref/gui/PreviewPanel.java index 1307ffb01bd..201ae8398e8 100644 --- a/src/main/java/org/jabref/gui/PreviewPanel.java +++ b/src/main/java/org/jabref/gui/PreviewPanel.java @@ -67,15 +67,16 @@ public class PreviewPanel extends ScrollPane implements SearchQueryHighlightList private Optional> citationStyleFuture = Optional.empty(); /** - * @param preferences * @param panel (may be null) Only set this if the preview is associated to the main window. * @param databaseContext (may be null) Used for resolving pdf directories for links. + * @param preferences + * @param dialogService */ - public PreviewPanel(BasePanel panel, BibDatabaseContext databaseContext, KeyBindingRepository keyBindingRepository, PreviewPreferences preferences) { + public PreviewPanel(BasePanel panel, BibDatabaseContext databaseContext, KeyBindingRepository keyBindingRepository, PreviewPreferences preferences, DialogService dialogService) { this.databaseContext = Optional.ofNullable(databaseContext); this.basePanel = Optional.ofNullable(panel); + this.dialogService = dialogService; this.clipBoardManager = new ClipBoardManager(); - this.dialogService = new FXDialogService(); this.keyBindingRepository = keyBindingRepository; // Set up scroll pane for preview pane diff --git a/src/main/java/org/jabref/gui/actions/CopyFilesAction.java b/src/main/java/org/jabref/gui/actions/CopyFilesAction.java index 0b4ca8d758f..57ced255727 100644 --- a/src/main/java/org/jabref/gui/actions/CopyFilesAction.java +++ b/src/main/java/org/jabref/gui/actions/CopyFilesAction.java @@ -10,7 +10,6 @@ import org.jabref.Globals; import org.jabref.JabRefGUI; import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; import org.jabref.gui.JabRefFrame; import org.jabref.gui.copyfiles.CopyFilesDialogView; import org.jabref.gui.copyfiles.CopyFilesResultItemViewModel; @@ -23,12 +22,13 @@ public class CopyFilesAction extends SimpleCommand { - private final DialogService dialogService = new FXDialogService(); + private final DialogService dialogService; private BibDatabaseContext databaseContext; private List entries; private final JabRefFrame frame; public CopyFilesAction(JabRefFrame frame) { this.frame = frame; + this.dialogService = frame.getDialogService(); } @@ -62,4 +62,4 @@ public void execute() { }); } -} \ No newline at end of file +} diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index 9b2950e11df..7e879d1a36f 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -25,8 +25,6 @@ import org.jabref.Globals; import org.jabref.gui.BasePanel; -import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; import org.jabref.gui.JabRefDialog; import org.jabref.gui.JabRefFrame; import org.jabref.gui.keyboard.KeyBinding; @@ -166,11 +164,10 @@ private void initPanels() { .addExtensionFilter(FileType.AUX) .withDefaultExtension(FileType.AUX) .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); - DialogService ds = new FXDialogService(); browseAuxFileButton.addActionListener(e -> { Optional file = DefaultTaskExecutor - .runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration)); + .runInJavaFXThread(() -> parentFrame.getDialogService().showFileOpenDialog(fileDialogConfiguration)); file.ifPresent(f -> auxFileField.setText(f.toAbsolutePath().toString())); }); diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java b/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java index 7692696e14a..3a36c4f686e 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java @@ -22,6 +22,7 @@ import org.jabref.Globals; import org.jabref.gui.BasePanel; +import org.jabref.gui.FXDialogService; import org.jabref.gui.PreviewPanel; import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.keyboard.KeyBinding; @@ -57,7 +58,7 @@ public ResolveDuplicateLabelDialog(BasePanel panel, String key, List e JCheckBox cb = new JCheckBox(Localization.lang("Generate BibTeX key"), !first); b.appendRows("1dlu, p"); b.add(cb).xy(1, row); - PreviewPanel previewPanel = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); + PreviewPanel previewPanel = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), new FXDialogService()); previewPanel.setEntry(entry); JFXPanel container = CustomJFXPanel.wrap(new Scene(previewPanel)); container.setPreferredSize(new Dimension(800, 90)); diff --git a/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java b/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java index d0cdf431ea7..66cba9d420e 100644 --- a/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java @@ -7,6 +7,7 @@ import org.jabref.Globals; import org.jabref.gui.BasePanel; +import org.jabref.gui.FXDialogService; import org.jabref.gui.PreviewPanel; import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.undo.NamedCompound; @@ -26,7 +27,7 @@ public EntryAddChangeViewModel(BibEntry diskEntry) { super(Localization.lang("Added entry")); this.diskEntry = diskEntry; - PreviewPanel previewPanel = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); + PreviewPanel previewPanel = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), new FXDialogService()); previewPanel.setEntry(diskEntry); container = CustomJFXPanel.wrap(new Scene(previewPanel)); } diff --git a/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java b/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java index fd1e6c5311a..a36990be7eb 100644 --- a/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java @@ -7,6 +7,7 @@ import org.jabref.Globals; import org.jabref.gui.BasePanel; +import org.jabref.gui.FXDialogService; import org.jabref.gui.PreviewPanel; import org.jabref.gui.customjfx.CustomJFXPanel; import org.jabref.gui.undo.NamedCompound; @@ -43,7 +44,7 @@ public EntryDeleteChangeViewModel(BibEntry memEntry, BibEntry tmpEntry) { LOGGER.debug("Modified entry: " + memEntry.getCiteKeyOptional().orElse("") + "\n Modified locally: " + isModifiedLocally); - PreviewPanel previewPanel = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences()); + PreviewPanel previewPanel = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), new FXDialogService()); previewPanel.setEntry(memEntry); container = CustomJFXPanel.wrap(new Scene(previewPanel)); } diff --git a/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java b/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java index f52edafa728..4e8fcef722f 100644 --- a/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java @@ -6,6 +6,7 @@ import javafx.scene.control.Tooltip; +import org.jabref.gui.DialogService; import org.jabref.gui.IconTheme; import org.jabref.gui.autocompleter.SuggestionProviders; import org.jabref.logic.l10n.Localization; @@ -14,8 +15,8 @@ import org.jabref.model.entry.EntryType; public class DeprecatedFieldsTab extends FieldsEditorTab { - public DeprecatedFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager) { - super(false, databaseContext, suggestionProviders, undoManager); + public DeprecatedFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService) { + super(false, databaseContext, suggestionProviders, undoManager, dialogService); setText(Localization.lang("Deprecated fields")); setTooltip(new Tooltip(Localization.lang("Show deprecated BibTeX fields"))); diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index e3d93d09940..d664bdd107f 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -20,6 +20,7 @@ import javafx.scene.layout.BorderPane; import org.jabref.gui.BasePanel; +import org.jabref.gui.DialogService; import org.jabref.gui.GUIGlobals; import org.jabref.gui.entryeditor.fileannotationtab.FileAnnotationTab; import org.jabref.gui.help.HelpAction; @@ -68,13 +69,15 @@ public class EntryEditor extends BorderPane { private SourceTab sourceTab; @FXML private Label typeLabel; private final EntryEditorPreferences preferences; + private final DialogService dialogService; - public EntryEditor(BasePanel panel, EntryEditorPreferences preferences, FileUpdateMonitor fileMonitor) { + public EntryEditor(BasePanel panel, EntryEditorPreferences preferences, FileUpdateMonitor fileMonitor, DialogService dialogService) { this.panel = panel; this.bibDatabaseContext = panel.getBibDatabaseContext(); this.undoManager = panel.getUndoManager(); this.preferences = Objects.requireNonNull(preferences); this.fileMonitor = fileMonitor; + this.dialogService = dialogService; ControlHelper.loadFXMLForControl(this); @@ -155,19 +158,19 @@ private List createTabs() { List tabs = new LinkedList<>(); // Required fields - tabs.add(new RequiredFieldsTab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager)); + tabs.add(new RequiredFieldsTab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager, dialogService)); // Optional fields - tabs.add(new OptionalFieldsTab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager)); - tabs.add(new OptionalFields2Tab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager)); - tabs.add(new DeprecatedFieldsTab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager)); + tabs.add(new OptionalFieldsTab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager, dialogService)); + tabs.add(new OptionalFields2Tab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager, dialogService)); + tabs.add(new DeprecatedFieldsTab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager, dialogService)); // Other fields - tabs.add(new OtherFieldsTab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager, preferences.getCustomTabFieldNames())); + tabs.add(new OtherFieldsTab(panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager, preferences.getCustomTabFieldNames(), dialogService)); // General fields from preferences for (Map.Entry> tab : preferences.getEntryEditorTabList().entrySet()) { - tabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager)); + tabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), panel.getDatabaseContext(), panel.getSuggestionProviders(), undoManager, dialogService)); } // Special tabs diff --git a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java index 80b64831e19..dacc6c23212 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java @@ -22,7 +22,7 @@ import javafx.scene.layout.RowConstraints; import org.jabref.Globals; -import org.jabref.gui.FXDialogService; +import org.jabref.gui.DialogService; import org.jabref.gui.autocompleter.SuggestionProviders; import org.jabref.gui.fieldeditors.FieldEditorFX; import org.jabref.gui.fieldeditors.FieldEditors; @@ -49,12 +49,14 @@ abstract class FieldsEditorTab extends EntryEditorTab { private final BibDatabaseContext databaseContext; private UndoManager undoManager; private Collection fields; + private final DialogService dialogService; - public FieldsEditorTab(boolean compressed, BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager) { + public FieldsEditorTab(boolean compressed, BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService) { this.isCompressed = compressed; this.databaseContext = databaseContext; this.suggestionProviders = suggestionProviders; this.undoManager = undoManager; + this.dialogService = dialogService; } private static void addColumn(GridPane gridPane, int columnIndex, List