Skip to content

Commit d650b26

Browse files
authored
Fix Look and Feel related issues (#4002)
* 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
1 parent 920ac0a commit d650b26

File tree

4 files changed

+86
-74
lines changed

4 files changed

+86
-74
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
1616

1717
### Fixed
1818
We fixed an issue where the export to clipboard functionality could not be invoked [#3994](https://github.com/JabRef/jabref/issues/3994)
19-
19+
We fixed an issue with the migration of invalid Look and Feels [#3995, comment](https://github.com/JabRef/jabref/issues/3995#issuecomment-385649448)
20+
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)
2021
### Removed
21-
22-
22+
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)
23+
The GTK Look and Feel is now replaced with the "Nimbus" style as default.
2324

2425

2526

src/main/java/org/jabref/JabRefGUI.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jabref;
22

3+
import java.awt.Font;
34
import java.awt.Frame;
45
import java.io.File;
56
import java.sql.SQLException;
@@ -39,7 +40,10 @@
3940

4041
public class JabRefGUI {
4142

43+
private static final String NIMBUS_LOOK_AND_FEEL = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
4244
private static final Logger LOGGER = LoggerFactory.getLogger(JabRefGUI.class);
45+
private static final String GTK_LF_CLASSNAME = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
46+
4347
private static JabRefFrame mainFrame;
4448

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

5660
// passed file (we take the first one) should be focused
57-
focusedFile = argsDatabases.stream().findFirst().flatMap(ParserResult::getFile).map(File::getAbsolutePath)
61+
focusedFile = argsDatabases.stream()
62+
.findFirst()
63+
.flatMap(ParserResult::getFile)
64+
.map(File::getAbsolutePath)
5865
.orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED));
5966

6067
openWindow();
@@ -230,25 +237,20 @@ private void setLookAndFeel() {
230237
String systemLookFeel = UIManager.getSystemLookAndFeelClassName();
231238

232239
if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) {
233-
// FIXME: Problems with OpenJDK and GTK L&F
234-
// See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638
235-
if (System.getProperty("java.runtime.name").contains("OpenJDK")) {
236-
// Metal L&F
237-
lookFeel = UIManager.getCrossPlatformLookAndFeelClassName();
238-
LOGGER.warn(
239-
"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.");
240+
// FIXME: Problems with GTK L&F on Linux and Mac. Needs reevaluation for Java9
241+
if (GTK_LF_CLASSNAME.equals(systemLookFeel)) {
242+
lookFeel = NIMBUS_LOOK_AND_FEEL;
243+
LOGGER.warn("There seems to be problems with GTK Look&Feel. Using Nimbus L&F instead. Change to another L&F with caution.");
240244
} else {
241245
lookFeel = systemLookFeel;
242246
}
243247
} else {
244248
lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
245249
}
246250

247-
// FIXME: Open JDK problem
248-
if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel)
249-
&& !System.getProperty("java.runtime.name").contains("OpenJDK")) {
250-
// try to avoid ending up with the ugly Metal L&F
251-
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
251+
//Prevent metal l&f
252+
if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel)) {
253+
UIManager.setLookAndFeel(NIMBUS_LOOK_AND_FEEL);
252254
} else {
253255
try {
254256
UIManager.setLookAndFeel(lookFeel);
@@ -285,7 +287,7 @@ private void setLookAndFeel() {
285287
Enumeration<Object> keys = defaults.keys();
286288
for (Object key : Collections.list(keys)) {
287289
if ((key instanceof String) && ((String) key).endsWith(".font")) {
288-
FontUIResource font = (FontUIResource) UIManager.get(key);
290+
Font font = (Font) UIManager.get(key);
289291
font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
290292
defaults.put(key, font);
291293
}

src/main/java/org/jabref/gui/preftabs/AppearancePrefsTab.java

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import org.jabref.gui.GUIGlobals;
2222
import org.jabref.logic.l10n.Localization;
23-
import org.jabref.logic.util.OS;
2423
import org.jabref.preferences.JabRefPreferences;
2524

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

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

3636
private final JabRefPreferences prefs;
3737

@@ -59,7 +59,10 @@ class AppearancePrefsTab extends JPanel implements PrefsTab {
5959
static class LookAndFeel {
6060

6161
public static Set<String> getAvailableLookAndFeels() {
62-
return Arrays.stream(UIManager.getInstalledLookAndFeels()).map(LookAndFeelInfo::getClassName).collect(Collectors.toSet());
62+
return Arrays.stream(UIManager.getInstalledLookAndFeels())
63+
.map(LookAndFeelInfo::getClassName)
64+
.filter(style -> !GTK_LF_CLASSNAME.equals(style))
65+
.collect(Collectors.toSet());
6366
}
6467
}
6568

@@ -98,46 +101,46 @@ public AppearancePrefsTab(JabRefPreferences prefs) {
98101
fxFontTweaksLAF = new JCheckBox(Localization.lang("Tweak font rendering for entry editor on Linux"));
99102
// Only list L&F which are available
100103
Set<String> lookAndFeels = LookAndFeel.getAvailableLookAndFeels();
104+
101105
classNamesLAF = new JComboBox<>(lookAndFeels.toArray(new String[lookAndFeels.size()]));
102106
classNamesLAF.setEditable(true);
103107
customLAF.addChangeListener(e -> classNamesLAF.setEnabled(((JCheckBox) e.getSource()).isSelected()));
104108

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

107-
// only the default L&F shows the OSX specific first drop-down menu
108-
if (!OS.OS_X) {
109-
JPanel pan = new JPanel();
110-
builder.appendSeparator(Localization.lang("Look and feel"));
111-
JLabel lab = new JLabel(
112-
Localization.lang("Default look and feel") + ": " + UIManager.getSystemLookAndFeelClassName());
113-
builder.nextLine();
114-
builder.append(pan);
115-
builder.append(lab);
116-
builder.nextLine();
117-
builder.append(pan);
118-
builder.append(customLAF);
119-
builder.nextLine();
120-
builder.append(pan);
121-
JPanel pan2 = new JPanel();
122-
lab = new JLabel(Localization.lang("Class name") + ':');
123-
pan2.add(lab);
124-
pan2.add(classNamesLAF);
125-
builder.append(pan2);
126-
builder.nextLine();
127-
builder.append(pan);
128-
lab = new JLabel(Localization
129-
.lang("Note that you must specify the fully qualified class name for the look and feel,"));
130-
builder.append(lab);
131-
builder.nextLine();
132-
builder.append(pan);
133-
lab = new JLabel(
134-
Localization.lang("and the class must be available in your classpath next time you start JabRef."));
135-
builder.append(lab);
136-
builder.nextLine();
137-
builder.append(pan);
138-
builder.append(fxFontTweaksLAF);
139-
builder.nextLine();
140-
}
111+
112+
JPanel pan = new JPanel();
113+
builder.appendSeparator(Localization.lang("Look and feel"));
114+
JLabel lab = new JLabel(
115+
Localization.lang("Default look and feel") + ": " + UIManager.getSystemLookAndFeelClassName());
116+
builder.nextLine();
117+
builder.append(pan);
118+
builder.append(lab);
119+
builder.nextLine();
120+
builder.append(pan);
121+
builder.append(customLAF);
122+
builder.nextLine();
123+
builder.append(pan);
124+
JPanel pan2 = new JPanel();
125+
lab = new JLabel(Localization.lang("Class name") + ':');
126+
pan2.add(lab);
127+
pan2.add(classNamesLAF);
128+
builder.append(pan2);
129+
builder.nextLine();
130+
builder.append(pan);
131+
lab = new JLabel(Localization
132+
.lang("Note that you must specify the fully qualified class name for the look and feel,"));
133+
builder.append(lab);
134+
builder.nextLine();
135+
builder.append(pan);
136+
lab = new JLabel(
137+
Localization.lang("and the class must be available in your classpath next time you start JabRef."));
138+
builder.append(lab);
139+
builder.nextLine();
140+
builder.append(pan);
141+
builder.append(fxFontTweaksLAF);
142+
builder.nextLine();
143+
141144

142145
builder.leadingColumnOffset(2);
143146

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

200-
JPanel pan = builder.getPanel();
201-
pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
202-
add(pan, BorderLayout.CENTER);
203+
JPanel panel = builder.getPanel();
204+
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
205+
add(panel, BorderLayout.CENTER);
203206
}
204207

205208
@Override

src/main/java/org/jabref/migrations/PreferencesMigrations.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.function.UnaryOperator;
1010
import java.util.prefs.BackingStoreException;
1111
import java.util.prefs.Preferences;
12+
import java.util.stream.Stream;
1213

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

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

212213
if (prefs.hasKey(JabRefPreferences.IMPORT_FILENAMEPATTERN)) {
213214
// Update also the key in the current application settings, if necessary:
214215
String fileNamePattern = prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN);
215216
if (oldStylePattern.equals(fileNamePattern)) {
216217
prefs.put(JabRefPreferences.IMPORT_FILENAMEPATTERN, newStylePattern);
217218
LOGGER.info("migrated old style " + JabRefPreferences.IMPORT_FILENAMEPATTERN +
218-
" value \"" + oldStylePattern + "\" to new value \"" +
219-
newStylePattern + "\" in the running application");
219+
" value \"" + oldStylePattern + "\" to new value \"" +
220+
newStylePattern + "\" in the running application");
220221
}
221222
}
222223
}
@@ -285,18 +286,23 @@ private static void migrateTypedKeyPrefs(JabRefPreferences prefs, Preferences ol
285286
public static void upgradeObsoleteLookAndFeels() {
286287
JabRefPreferences prefs = Globals.prefs;
287288
String currentLandF = prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
288-
if ("com.jgoodies.looks.windows.WindowsLookAndFeel".equals(currentLandF) ||
289-
"com.jgoodies.plaf.plastic.Plastic3DLookAndFeel".equals(currentLandF) ) {
290-
if (OS.WINDOWS) {
291-
String windowsLandF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
292-
prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, windowsLandF);
293-
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + windowsLandF);
294-
} else {
295-
String nimbusLandF = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
296-
prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, nimbusLandF);
297-
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + nimbusLandF);
298-
}
299-
}
289+
290+
Stream.of("com.jgoodies.looks.windows.WindowsLookAndFeel", "com.jgoodies.looks.plastic.PlasticLookAndFeel",
291+
"com.jgoodies.looks.plastic.Plastic3DLookAndFeel", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel",
292+
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel")
293+
.filter(style -> style.equals(currentLandF))
294+
.findAny()
295+
.ifPresent(loolAndFeel -> {
296+
if (OS.WINDOWS) {
297+
String windowsLandF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
298+
prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, windowsLandF);
299+
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + windowsLandF);
300+
} else {
301+
String nimbusLandF = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
302+
prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, nimbusLandF);
303+
LOGGER.info("Switched from obsolete look and feel " + currentLandF + " to " + nimbusLandF);
304+
}
305+
});
300306
}
301307

302308
}

0 commit comments

Comments
 (0)