preserve initial font+size+style accross restarts

This commit is contained in:
Zlatin Balevsky
2020-06-03 02:03:44 +01:00
parent af218a369c
commit 274edcc599
2 changed files with 16 additions and 10 deletions

View File

@ -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)

View File

@ -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)