Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smooth shutdown #4109

Merged
merged 7 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 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 Down Expand Up @@ -107,8 +108,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
54 changes: 5 additions & 49 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 Down Expand Up @@ -242,46 +233,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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a Linux switch anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is turned on by default only on Linux: defaults.put(FX_FONT_RENDERING_TWEAK, OS.LINUX);

System.setProperty("prism.text", "t2k");
System.setProperty("prism.lcdtext", "true");
}
}

Expand Down
13 changes: 3 additions & 10 deletions src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void start(Stage mainStage) throws Exception {

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

Expand All @@ -77,8 +77,8 @@ public void start(Stage mainStage) throws Exception {

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

/**
Expand Down Expand Up @@ -145,13 +145,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 Down
14 changes: 4 additions & 10 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.jabref.gui;

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.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -648,8 +646,7 @@ private void copyTitle() {
output(Localization.lang("None of the selected entries have titles."));
return;
}
StringSelection ss = new StringSelection(String.join("\n", titles));
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
Globals.clipboardManager.setContent(String.join("\n", titles));

if (titles.size() == selectedBibEntries.size()) {
// All entries had titles.
Expand Down Expand Up @@ -677,8 +674,7 @@ private void copyCiteKey() {
String citeCommand = Optional.ofNullable(Globals.prefs.get(JabRefPreferences.CITE_COMMAND))
.filter(cite -> cite.contains("\\")) // must contain \
.orElse("\\cite");
StringSelection ss = new StringSelection(citeCommand + "{" + sb + '}');
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
Globals.clipboardManager.setContent(citeCommand + "{" + sb + '}');

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

StringSelection ss = new StringSelection(String.join(",", keys));
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
Globals.clipboardManager.setContent(String.join(",", keys));

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

final StringSelection ss = new StringSelection(sb.toString());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
Globals.clipboardManager.setContent(sb.toString());

if (copied == bes.size()) {
// All entries had keys.
Expand Down
Loading