From 274edcc599bfc0ecc0d93335c56bca4bf6fa6f3b Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 3 Jun 2020 02:03:44 +0100 Subject: [PATCH] preserve initial font+size+style accross restarts --- gui/griffon-app/lifecycle/Initialize.groovy | 20 ++++++++++--------- .../groovy/com/muwire/gui/UISettings.groovy | 6 +++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/gui/griffon-app/lifecycle/Initialize.groovy b/gui/griffon-app/lifecycle/Initialize.groovy index a21173c8..e9c5b60c 100644 --- a/gui/griffon-app/lifecycle/Initialize.groovy +++ b/gui/griffon-app/lifecycle/Initialize.groovy @@ -124,7 +124,7 @@ class Initialize extends AbstractLifecycleHandler { uiSettings.lnf = lnf.getID() } - if (uiSettings.font != null || uiSettings.autoFontSize || uiSettings.fontSize > 0) { + if (uiSettings.font != null || uiSettings.autoFontSize || uiSettings.fontSize > 0 ) { FontUIResource defaultFont = lnf.getDefaults().getFont("Label.font") @@ -142,7 +142,7 @@ class Initialize extends AbstractLifecycleHandler { fontSize = uiSettings.fontSize } rowHeight = fontSize + 3 - FontUIResource font = new FontUIResource(fontName, Font.PLAIN, fontSize) + FontUIResource font = new FontUIResource(fontName, uiSettings.fontStyle, fontSize) def keys = lnf.getDefaults().keys() while(keys.hasMoreElements()) { @@ -158,21 +158,23 @@ class Initialize extends AbstractLifecycleHandler { Properties props = new Properties() uiSettings = new UISettings(props) log.info "will try default lnfs" + LookAndFeel chosen if (isMacOSX()) { - if (SystemVersion.isJava9()) { uiSettings.lnf = "metal" - lookAndFeel("metal") - } else { - uiSettings.lnf = "nimbus" - lookAndFeel('nimbus') // otherwise the file chooser doesn't open??? - } + chosen = lookAndFeel("metal") } else { - LookAndFeel chosen = lookAndFeel('system', 'gtk') + chosen = lookAndFeel('system', 'gtk') if (chosen == null) chosen = lookAndFeel('metal') uiSettings.lnf = chosen.getID() log.info("ended up applying $chosen.name") } + + FontUIResource defaultFont = chosen.getDefaults().getFont("Label.font") + uiSettings.font = defaultFont.getName() + uiSettings.fontSize = defaultFont.getSize() + uiSettings.fontStyle = defaultFont.getStyle() + rowHeight = uiSettings.fontSize + 3 } application.context.put("row-height", rowHeight) diff --git a/gui/src/main/groovy/com/muwire/gui/UISettings.groovy b/gui/src/main/groovy/com/muwire/gui/UISettings.groovy index 2691e028..7ecede81 100644 --- a/gui/src/main/groovy/com/muwire/gui/UISettings.groovy +++ b/gui/src/main/groovy/com/muwire/gui/UISettings.groovy @@ -2,13 +2,15 @@ package com.muwire.gui import com.muwire.core.util.DataUtil +import java.awt.Font + class UISettings { String lnf boolean showMonitor String font boolean autoFontSize - int fontSize + int fontSize, fontStyle boolean clearCancelledDownloads boolean clearFinishedDownloads boolean excludeLocalResult @@ -33,6 +35,7 @@ class UISettings { showSearchHashes = Boolean.parseBoolean(props.getProperty("showSearchHashes","true")) autoFontSize = Boolean.parseBoolean(props.getProperty("autoFontSize","false")) fontSize = Integer.parseInt(props.getProperty("fontSize","12")) + fontStyle = Integer.parseInt(props.getProperty("fontStyle", String.valueOf(Font.PLAIN))) closeWarning = Boolean.parseBoolean(props.getProperty("closeWarning","true")) certificateWarning = Boolean.parseBoolean(props.getProperty("certificateWarning","true")) exitOnClose = Boolean.parseBoolean(props.getProperty("exitOnClose","false")) @@ -62,6 +65,7 @@ class UISettings { props.setProperty("storeSearchHistory", String.valueOf(storeSearchHistory)) props.setProperty("groupByFile", String.valueOf(groupByFile)) props.setProperty("maxChatLines", String.valueOf(maxChatLines)) + props.setProperty("fontStyle", String.valueOf(fontStyle)) if (font != null) props.setProperty("font", font)