Skip to content

Commit

Permalink
Fix Look and Feel related issues (#4002)
Browse files Browse the repository at this point in the history
* list l&fs

* enable style choose for mac
remove gtk l&f from style selection

* fix empty lines

* Fix preference migration for obsolete look and feels

* Fix class cast exception in awt.Font

* reset gtk l and f to nimbus on migration
add changelog

* default system look and feel may return GTK on Linux

* simplify condition
  • Loading branch information
Siedlerchr authored May 4, 2018
1 parent 920ac0a commit d650b26
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 74 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#

### Fixed
We fixed an issue where the export to clipboard functionality could not be invoked [#3994](https://github.com/JabRef/jabref/issues/3994)

We fixed an issue with the migration of invalid Look and Feels [#3995, comment](https://github.com/JabRef/jabref/issues/3995#issuecomment-385649448)
We fixed an issue where JabRef would no longer start, when the option "Override default font settings" was activated [#3986](https://github.com/JabRef/jabref/issues/3986)
### Removed


We removed the GTK Look and Feel from the Options, as it leads to freezes in JabRef on MacOSX and Linux [#3995](https://github.com/JabRef/jabref/issues/3995)
The GTK Look and Feel is now replaced with the "Nimbus" style as default.



Expand Down
30 changes: 16 additions & 14 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref;

import java.awt.Font;
import java.awt.Frame;
import java.io.File;
import java.sql.SQLException;
Expand Down Expand Up @@ -39,7 +40,10 @@

public class JabRefGUI {

private static final String NIMBUS_LOOK_AND_FEEL = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
private static final Logger LOGGER = LoggerFactory.getLogger(JabRefGUI.class);
private static final String GTK_LF_CLASSNAME = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";

private static JabRefFrame mainFrame;

private final List<ParserResult> bibDatabases;
Expand All @@ -54,7 +58,10 @@ public JabRefGUI(List<ParserResult> argsDatabases, boolean isBlank) {
this.isBlank = isBlank;

// passed file (we take the first one) should be focused
focusedFile = argsDatabases.stream().findFirst().flatMap(ParserResult::getFile).map(File::getAbsolutePath)
focusedFile = argsDatabases.stream()
.findFirst()
.flatMap(ParserResult::getFile)
.map(File::getAbsolutePath)
.orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED));

openWindow();
Expand Down Expand Up @@ -230,25 +237,20 @@ private void setLookAndFeel() {
String systemLookFeel = UIManager.getSystemLookAndFeelClassName();

if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) {
// FIXME: Problems with OpenJDK and GTK L&F
// See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638
if (System.getProperty("java.runtime.name").contains("OpenJDK")) {
// Metal L&F
lookFeel = UIManager.getCrossPlatformLookAndFeelClassName();
LOGGER.warn(
"There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution.");
// FIXME: Problems with GTK L&F on Linux and Mac. Needs reevaluation for Java9
if (GTK_LF_CLASSNAME.equals(systemLookFeel)) {
lookFeel = NIMBUS_LOOK_AND_FEEL;
LOGGER.warn("There seems to be problems with GTK Look&Feel. Using Nimbus L&F instead. Change to another L&F with caution.");
} else {
lookFeel = systemLookFeel;
}
} else {
lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
}

// FIXME: Open JDK problem
if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel)
&& !System.getProperty("java.runtime.name").contains("OpenJDK")) {
// try to avoid ending up with the ugly Metal L&F
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
//Prevent metal l&f
if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel)) {
UIManager.setLookAndFeel(NIMBUS_LOOK_AND_FEEL);
} else {
try {
UIManager.setLookAndFeel(lookFeel);
Expand Down Expand Up @@ -285,7 +287,7 @@ private void setLookAndFeel() {
Enumeration<Object> keys = defaults.keys();
for (Object key : Collections.list(keys)) {
if ((key instanceof String) && ((String) key).endsWith(".font")) {
FontUIResource font = (FontUIResource) UIManager.get(key);
Font font = (Font) UIManager.get(key);
font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
defaults.put(key, font);
}
Expand Down
81 changes: 42 additions & 39 deletions src/main/java/org/jabref/gui/preftabs/AppearancePrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.jabref.gui.GUIGlobals;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.preferences.JabRefPreferences;

import com.jgoodies.forms.builder.DefaultFormBuilder;
Expand All @@ -32,6 +31,7 @@
class AppearancePrefsTab extends JPanel implements PrefsTab {

private static final Logger LOGGER = LoggerFactory.getLogger(AppearancePrefsTab.class);
private static final String GTK_LF_CLASSNAME = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";

private final JabRefPreferences prefs;

Expand Down Expand Up @@ -59,7 +59,10 @@ class AppearancePrefsTab extends JPanel implements PrefsTab {
static class LookAndFeel {

public static Set<String> getAvailableLookAndFeels() {
return Arrays.stream(UIManager.getInstalledLookAndFeels()).map(LookAndFeelInfo::getClassName).collect(Collectors.toSet());
return Arrays.stream(UIManager.getInstalledLookAndFeels())
.map(LookAndFeelInfo::getClassName)
.filter(style -> !GTK_LF_CLASSNAME.equals(style))
.collect(Collectors.toSet());
}
}

Expand Down Expand Up @@ -98,46 +101,46 @@ public AppearancePrefsTab(JabRefPreferences prefs) {
fxFontTweaksLAF = new JCheckBox(Localization.lang("Tweak font rendering for entry editor on Linux"));
// Only list L&F which are available
Set<String> lookAndFeels = LookAndFeel.getAvailableLookAndFeels();

classNamesLAF = new JComboBox<>(lookAndFeels.toArray(new String[lookAndFeels.size()]));
classNamesLAF.setEditable(true);
customLAF.addChangeListener(e -> classNamesLAF.setEnabled(((JCheckBox) e.getSource()).isSelected()));

colorPanel = new ColorSetupPanel(colorCodes, resolvedColorCodes, showGrid);

// only the default L&F shows the OSX specific first drop-down menu
if (!OS.OS_X) {
JPanel pan = new JPanel();
builder.appendSeparator(Localization.lang("Look and feel"));
JLabel lab = new JLabel(
Localization.lang("Default look and feel") + ": " + UIManager.getSystemLookAndFeelClassName());
builder.nextLine();
builder.append(pan);
builder.append(lab);
builder.nextLine();
builder.append(pan);
builder.append(customLAF);
builder.nextLine();
builder.append(pan);
JPanel pan2 = new JPanel();
lab = new JLabel(Localization.lang("Class name") + ':');
pan2.add(lab);
pan2.add(classNamesLAF);
builder.append(pan2);
builder.nextLine();
builder.append(pan);
lab = new JLabel(Localization
.lang("Note that you must specify the fully qualified class name for the look and feel,"));
builder.append(lab);
builder.nextLine();
builder.append(pan);
lab = new JLabel(
Localization.lang("and the class must be available in your classpath next time you start JabRef."));
builder.append(lab);
builder.nextLine();
builder.append(pan);
builder.append(fxFontTweaksLAF);
builder.nextLine();
}

JPanel pan = new JPanel();
builder.appendSeparator(Localization.lang("Look and feel"));
JLabel lab = new JLabel(
Localization.lang("Default look and feel") + ": " + UIManager.getSystemLookAndFeelClassName());
builder.nextLine();
builder.append(pan);
builder.append(lab);
builder.nextLine();
builder.append(pan);
builder.append(customLAF);
builder.nextLine();
builder.append(pan);
JPanel pan2 = new JPanel();
lab = new JLabel(Localization.lang("Class name") + ':');
pan2.add(lab);
pan2.add(classNamesLAF);
builder.append(pan2);
builder.nextLine();
builder.append(pan);
lab = new JLabel(Localization
.lang("Note that you must specify the fully qualified class name for the look and feel,"));
builder.append(lab);
builder.nextLine();
builder.append(pan);
lab = new JLabel(
Localization.lang("and the class must be available in your classpath next time you start JabRef."));
builder.append(lab);
builder.nextLine();
builder.append(pan);
builder.append(fxFontTweaksLAF);
builder.nextLine();


builder.leadingColumnOffset(2);

Expand Down Expand Up @@ -197,9 +200,9 @@ public AppearancePrefsTab(JabRefPreferences prefs) {
fontButton.addActionListener(
e -> new FontSelectorDialog(null, usedFont).getSelectedFont().ifPresent(x -> usedFont = x));

JPanel pan = builder.getPanel();
pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
add(pan, BorderLayout.CENTER);
JPanel panel = builder.getPanel();
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
add(panel, BorderLayout.CENTER);
}

@Override
Expand Down
42 changes: 24 additions & 18 deletions src/main/java/org/jabref/migrations/PreferencesMigrations.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.function.UnaryOperator;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import java.util.stream.Stream;

import org.jabref.Globals;
import org.jabref.JabRefMain;
Expand Down Expand Up @@ -201,22 +202,22 @@ private static void migrateFileImportPattern(String oldStylePattern, String newS
JabRefPreferences prefs, Preferences mainPrefsNode) {
String preferenceFileNamePattern = mainPrefsNode.get(JabRefPreferences.IMPORT_FILENAMEPATTERN, null);

if (preferenceFileNamePattern != null &&
oldStylePattern.equals(preferenceFileNamePattern)) {
if ((preferenceFileNamePattern != null) &&
oldStylePattern.equals(preferenceFileNamePattern)) {
// Upgrade the old-style File Name pattern to new one:
mainPrefsNode.put(JabRefPreferences.IMPORT_FILENAMEPATTERN, newStylePattern);
LOGGER.info("migrated old style " + JabRefPreferences.IMPORT_FILENAMEPATTERN +
" value \"" + oldStylePattern + "\" to new value \"" +
newStylePattern + "\" in the preference file");
" value \"" + oldStylePattern + "\" to new value \"" +
newStylePattern + "\" in the preference file");

if (prefs.hasKey(JabRefPreferences.IMPORT_FILENAMEPATTERN)) {
// Update also the key in the current application settings, if necessary:
String fileNamePattern = prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN);
if (oldStylePattern.equals(fileNamePattern)) {
prefs.put(JabRefPreferences.IMPORT_FILENAMEPATTERN, newStylePattern);
LOGGER.info("migrated old style " + JabRefPreferences.IMPORT_FILENAMEPATTERN +
" value \"" + oldStylePattern + "\" to new value \"" +
newStylePattern + "\" in the running application");
" value \"" + oldStylePattern + "\" to new value \"" +
newStylePattern + "\" in the running application");
}
}
}
Expand Down Expand Up @@ -285,18 +286,23 @@ private static void migrateTypedKeyPrefs(JabRefPreferences prefs, Preferences ol
public static void upgradeObsoleteLookAndFeels() {
JabRefPreferences prefs = Globals.prefs;
String currentLandF = prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
if ("com.jgoodies.looks.windows.WindowsLookAndFeel".equals(currentLandF) ||
"com.jgoodies.plaf.plastic.Plastic3DLookAndFeel".equals(currentLandF) ) {
if (OS.WINDOWS) {
String windowsLandF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, windowsLandF);
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + windowsLandF);
} else {
String nimbusLandF = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, nimbusLandF);
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + nimbusLandF);
}
}

Stream.of("com.jgoodies.looks.windows.WindowsLookAndFeel", "com.jgoodies.looks.plastic.PlasticLookAndFeel",
"com.jgoodies.looks.plastic.Plastic3DLookAndFeel", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel",
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel")
.filter(style -> style.equals(currentLandF))
.findAny()
.ifPresent(loolAndFeel -> {
if (OS.WINDOWS) {
String windowsLandF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, windowsLandF);
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + windowsLandF);
} else {
String nimbusLandF = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, nimbusLandF);
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + nimbusLandF);
}
});
}

}

0 comments on commit d650b26

Please sign in to comment.