Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fixdragandrop
Browse files Browse the repository at this point in the history
* upstream/master: (22 commits)
  fix failing architecture test by making test class public again migrate architecture test to junit jupiter
  Fix build... (#4128)
  fix checkstyle after merge
  Migrate Review field in entry preview to comment (#4100)
  [WIP] Split push to applications in logic and gui (#4110)
  Fix checkstyle
  Fix #4115: Don't report journal name as abbreviated when full name = abbreviated name (#4116)
  Use <kbd>in changelog
  Groups right click (#4061)
  Fix open thread prevents shutdown (#4111)
  Extract v4.x changelog (#4125)
  Saves and reloads window state on close and on open (#4124)
  Fix convert to bibtex moves contents of the file field (#4123)
  Opens the directory of the currently edited file when opening a new file (#4106)
  Don't run on Swing thread
  Properly shutdown telemetry client
  Code cleanup
  Remove Swing stuff (L&F, font customization)
  Properly shutdown JabRef (not with System.exit)
  Replace swing clipboard with JavaFX one
  ...

# Conflicts:
#	src/main/java/org/jabref/gui/BasePanel.java
#	src/main/java/org/jabref/gui/JabRefFrame.java
#	src/main/java/org/jabref/gui/maintable/MainTable.java
#	src/main/java/org/jabref/gui/search/SearchResultFrame.java
#	src/main/java/org/jabref/preferences/JabRefPreferences.java
  • Loading branch information
Siedlerchr committed Jun 15, 2018
2 parents 6b15e31 + f47b740 commit 95d0957
Show file tree
Hide file tree
Showing 72 changed files with 1,011 additions and 1,984 deletions.
382 changes: 25 additions & 357 deletions CHANGELOG.md

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.jabref;

import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.util.Optional;
import java.util.UUID;

import javafx.stage.Screen;

import org.jabref.gui.ClipBoardManager;
import org.jabref.gui.GlobalFocusListener;
import org.jabref.gui.StateManager;
Expand All @@ -25,6 +26,7 @@
import com.google.common.base.StandardSystemProperty;
import com.microsoft.applicationinsights.TelemetryClient;
import com.microsoft.applicationinsights.TelemetryConfiguration;
import com.microsoft.applicationinsights.internal.shutdown.SDKShutdownActivity;
import com.microsoft.applicationinsights.telemetry.SessionState;

public class Globals {
Expand Down Expand Up @@ -90,10 +92,13 @@ public static void startBackgroundTasks() {
}

private static void stopTelemetryClient() {
if (Globals.prefs.shouldCollectTelemetry()) {
getTelemetryClient().ifPresent(client -> client.trackSessionState(SessionState.End));
getTelemetryClient().ifPresent(client -> client.flush());
}
getTelemetryClient().ifPresent(client -> {
client.trackSessionState(SessionState.End);
client.flush();

//FIXME: Workaround for bug https://github.com/Microsoft/ApplicationInsights-Java/issues/662
SDKShutdownActivity.INSTANCE.stopAll();
});
}

private static void startTelemetryClient() {
Expand All @@ -107,8 +112,7 @@ private static void startTelemetryClient() {
telemetryClient.getContext().getSession().setId(UUID.randomUUID().toString());
telemetryClient.getContext().getDevice().setOperatingSystem(StandardSystemProperty.OS_NAME.value());
telemetryClient.getContext().getDevice().setOperatingSystemVersion(StandardSystemProperty.OS_VERSION.value());
telemetryClient.getContext().getDevice().setScreenResolution(
Toolkit.getDefaultToolkit().getScreenSize().toString());
telemetryClient.getContext().getDevice().setScreenResolution(Screen.getPrimary().getVisualBounds().toString());

telemetryClient.trackSessionState(SessionState.Start);
}
Expand Down
70 changes: 20 additions & 50 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package org.jabref;

import java.awt.Font;
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.UIDefaults;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.FontUIResource;

import javafx.scene.Scene;
import javafx.stage.Stage;

Expand All @@ -34,7 +26,6 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.logic.shared.exception.NotASharedDatabaseException;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.Version;
import org.jabref.model.database.shared.DatabaseNotSupportedException;
import org.jabref.preferences.JabRefPreferences;
Expand All @@ -46,7 +37,7 @@ public class JabRefGUI {

private static final String NIMBUS_LOOK_AND_FEEL = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
private static final String WINDOWS_LOOK_AND_FEEL = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
private static final String OSX_AQUA_LOOk_AND_FEEL = "apple.laf.AquaLookAndFeel";
private static final String OSX_AQUA_LOOK_AND_FEEL = "apple.laf.AquaLookAndFeel";

private static final Logger LOGGER = LoggerFactory.getLogger(JabRefGUI.class);

Expand Down Expand Up @@ -155,6 +146,11 @@ private void openWindow(Stage mainStage) {
// do it here:
if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) {
mainStage.setMaximized(true);
} else {
mainStage.setX(Globals.prefs.getDouble(JabRefPreferences.POS_X));
mainStage.setY(Globals.prefs.getDouble(JabRefPreferences.POS_Y));
mainStage.setWidth(Globals.prefs.getDouble(JabRefPreferences.SIZE_X));
mainStage.setHeight(Globals.prefs.getDouble(JabRefPreferences.SIZE_Y));
}

Scene scene = new Scene(JabRefGUI.mainFrame, 800, 800);
Expand All @@ -165,6 +161,7 @@ private void openWindow(Stage mainStage) {
mainStage.show();

mainStage.setOnCloseRequest(event -> {
saveWindowState(mainStage);
boolean reallyQuit = mainFrame.quit();
if (!reallyQuit) {
event.consume();
Expand Down Expand Up @@ -203,6 +200,14 @@ private void openWindow(Stage mainStage) {
LOGGER.debug("Finished adding panels");
}

private void saveWindowState(Stage mainStage) {
Globals.prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, mainStage.isMaximized());
Globals.prefs.putDouble(JabRefPreferences.POS_X, mainStage.getX());
Globals.prefs.putDouble(JabRefPreferences.POS_Y, mainStage.getY());
Globals.prefs.putDouble(JabRefPreferences.SIZE_X, mainStage.getWidth());
Globals.prefs.putDouble(JabRefPreferences.SIZE_Y, mainStage.getHeight());
}

private void openLastEditedDatabases() {
if (Globals.prefs.get(JabRefPreferences.LAST_EDITED) == null) {
return;
Expand Down Expand Up @@ -242,46 +247,11 @@ private boolean isLoaded(File fileToOpen) {
}

private void setLookAndFeel() {
try {

if (OS.WINDOWS) {
UIManager.setLookAndFeel(WINDOWS_LOOK_AND_FEEL);
}
if (OS.OS_X) {
UIManager.setLookAndFeel(OSX_AQUA_LOOk_AND_FEEL);
} else {
UIManager.setLookAndFeel(NIMBUS_LOOK_AND_FEEL);
}
// On Linux, Java FX fonts look blurry per default. This can be improved by using a non-default rendering
// setting. See https://github.com/woky/javafx-hates-linux
if (Globals.prefs.getBoolean(JabRefPreferences.FX_FONT_RENDERING_TWEAK)) {
System.setProperty("prism.text", "t2k");
System.setProperty("prism.lcdtext", "true");
}
} catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
try {
LOGGER.warn("Setting Look and Feel to Nimbus", e);

UIManager.setLookAndFeel(NIMBUS_LOOK_AND_FEEL);
} catch (Exception ex) {
LOGGER.warn("Look and feel could not be set", e);
}

}

// In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms
boolean overrideDefaultFonts = Globals.prefs.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONTS);
if (overrideDefaultFonts) {
int fontSize = Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE);
UIDefaults defaults = UIManager.getDefaults();
Enumeration<Object> keys = defaults.keys();
for (Object key : Collections.list(keys)) {
if ((key instanceof String) && ((String) key).endsWith(".font")) {
Font font = (Font) UIManager.get(key);
font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
defaults.put(key, font);
}
}
// On Linux, Java FX fonts look blurry per default. This can be improved by using a non-default rendering
// setting. See https://github.com/woky/javafx-hates-linux
if (Globals.prefs.getBoolean(JabRefPreferences.FX_FONT_RENDERING_TWEAK)) {
System.setProperty("prism.text", "t2k");
System.setProperty("prism.lcdtext", "true");
}
}

Expand Down
64 changes: 31 additions & 33 deletions src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* JabRef MainClass
*/
public class JabRefMain extends Application {

private static final Logger LOGGER = LoggerFactory.getLogger(JabRefMain.class);

private static String[] arguments;
Expand All @@ -46,41 +47,45 @@ public static void main(String[] args) {

@Override
public void start(Stage mainStage) throws Exception {
// Fail on unsupported Java versions
ensureCorrectJavaVersion();
FallbackExceptionHandler.installExceptionHandler();
try {
// Fail on unsupported Java versions
ensureCorrectJavaVersion();
FallbackExceptionHandler.installExceptionHandler();

// Init preferences
final JabRefPreferences preferences = JabRefPreferences.getInstance();
Globals.prefs = preferences;
// Perform migrations
PreferencesMigrations.runMigrations();
// Init preferences
final JabRefPreferences preferences = JabRefPreferences.getInstance();
Globals.prefs = preferences;
// Perform migrations
PreferencesMigrations.runMigrations();

configureProxy(preferences.getProxyPreferences());
configureProxy(preferences.getProxyPreferences());

Globals.startBackgroundTasks();
Globals.startBackgroundTasks();

applyPreferences(preferences);
applyPreferences(preferences);

// Process arguments
ArgumentProcessor argumentProcessor = new ArgumentProcessor(arguments, ArgumentProcessor.Mode.INITIAL_START);
// Process arguments
ArgumentProcessor argumentProcessor = new ArgumentProcessor(arguments, ArgumentProcessor.Mode.INITIAL_START);

// Check for running JabRef
if (!handleMultipleAppInstances(arguments) || argumentProcessor.shouldShutDown()) {
shutdownCurrentInstance();
return;
}
// Check for running JabRef
if (!handleMultipleAppInstances(arguments) || argumentProcessor.shouldShutDown()) {
Platform.exit();
return;
}

// If not, start GUI
new JabRefGUI(mainStage, argumentProcessor.getParserResults(), argumentProcessor.isBlank());
// If not, start GUI
new JabRefGUI(mainStage, argumentProcessor.getParserResults(), argumentProcessor.isBlank());
} catch (Exception ex) {
LOGGER.error("Unexpected exception", ex);
}
}

@Override
public void stop() {
Platform.exit();
System.exit(0);
Globals.stopBackgroundTasks();
Globals.shutdownThreadPools();
}

/**
* 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 <code>gradle.build</code>. It is possible to
Expand Down Expand Up @@ -145,13 +150,6 @@ private static boolean handleMultipleAppInstances(String[] args) {
return true;
}

private static void shutdownCurrentInstance() {
Globals.stopBackgroundTasks();
Globals.shutdownThreadPools();
Platform.exit();
System.exit(0);
}

private static void applyPreferences(JabRefPreferences preferences) {
// Update handling of special fields based on preferences
InternalBibtexFields.updateSpecialFields(Globals.prefs.getBoolean(JabRefPreferences.SERIALIZESPECIALFIELDS));
Expand All @@ -165,9 +163,9 @@ private static void applyPreferences(JabRefPreferences preferences) {

/* Build list of Import and Export formats */
Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(),
Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor());
Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor());
EntryTypes.loadCustomEntryTypes(preferences.loadCustomEntryTypes(BibDatabaseMode.BIBTEX),
preferences.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX));
preferences.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX));
Globals.exportFactory = Globals.prefs.getExporterFactory(Globals.journalAbbreviationLoader);

// Initialize protected terms loader
Expand Down
40 changes: 6 additions & 34 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,7 @@ private void copyTitle() {
output(Localization.lang("None of the selected entries have titles."));
return;
}
String titlesToCopy = String.join("\n", titles);
Globals.clipboardManager.setClipboardContent(titlesToCopy);
Globals.clipboardManager.setContent(String.join("\n", titles));

if (titles.size() == selectedBibEntries.size()) {
// All entries had titles.
Expand Down Expand Up @@ -674,8 +673,7 @@ private void copyCiteKey() {
String citeCommand = Optional.ofNullable(Globals.prefs.get(JabRefPreferences.CITE_COMMAND))
.filter(cite -> cite.contains("\\")) // must contain \
.orElse("\\cite");
String keysToCopy = citeCommand + "{" + sb + '}';
Globals.clipboardManager.setClipboardContent(keysToCopy);
Globals.clipboardManager.setContent(citeCommand + "{" + sb + '}');

if (keys.size() == bes.size()) {
// All entries had keys.
Expand All @@ -699,8 +697,7 @@ private void copyKey() {
return;
}

String keyToCopy = String.join(",", keys);
Globals.clipboardManager.setClipboardContent(keyToCopy);
Globals.clipboardManager.setContent(String.join(",", keys));

if (keys.size() == bes.size()) {
// All entries had keys.
Expand Down Expand Up @@ -741,8 +738,7 @@ private void copyKeyAndTitle() {
return;
}

String keyAndTitleToCopy = sb.toString();
Globals.clipboardManager.setClipboardContent(keyAndTitleToCopy);
Globals.clipboardManager.setContent(sb.toString());

if (copied == bes.size()) {
// All entries had keys.
Expand Down Expand Up @@ -1246,36 +1242,12 @@ public void clearAndSelect(final BibEntry bibEntry) {
mainTable.clearAndSelect(bibEntry);
}

/**
* 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
*/
@Deprecated
private void clearAndSelect(int pos) {
if ((pos >= 0) && (pos < mainTable.getItems().size())) {
mainTable.getSelectionModel().clearAndSelect(pos);
}
}

public void selectPreviousEntry() {
mainTable.getSelectionModel().clearSelection();
mainTable.getSelectionModel().selectPrevious();
mainTable.getSelectionModel().clearAndSelect(mainTable.getSelectionModel().getSelectedIndex() - 1);
}

public void selectNextEntry() {
mainTable.getSelectionModel().clearSelection();
mainTable.getSelectionModel().selectNext();
}

public void selectFirstEntry() {
clearAndSelect(0);
}

public void selectLastEntry() {
mainTable.getSelectionModel().clearSelection();
mainTable.getSelectionModel().selectLast();
mainTable.getSelectionModel().clearAndSelect(mainTable.getSelectionModel().getSelectedIndex() + 1);
}

/**
Expand Down
Loading

0 comments on commit 95d0957

Please sign in to comment.