Skip to content

Commit

Permalink
fix: Retrieve focus and font size so it actually has an effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Sep 16, 2023
1 parent 268f415 commit 4a0c066
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import javax.swing.plaf.FontUIResource
*/
@Suppress("unused", "RedundantSuppression")
class GuiProps(private val apiProperties: ApiProperties) {

@Suppress("MemberVisibilityCanBePrivate")
val smallSize = 18

Expand Down Expand Up @@ -387,35 +388,42 @@ class GuiProps(private val apiProperties: ApiProperties) {
FlatAnimatedLafChange.hideSnapshotWithAnimation()
storeGuiProperty("theme", field.javaClass.name)
}
var startFocusEnabled: Boolean
var startFocusEnabled: Boolean = getGuiProperty("focus.start", "false").toBoolean()
get() {
val prop = getGuiProperty("focus.start", "false")
return prop == "true"
field = prop == "true"
return field
}
set(value) {
field = value
storeGuiProperty("focus.start",value.toString())
}
var generationFocusEnabled: Boolean
var generationFocusEnabled: Boolean = getGuiProperty("focus.generation", "false").toBoolean()
get() {
val prop = getGuiProperty("focus.generation", "false")
return prop == "true"
field = prop == "true"
return field
}
set(value) {
field = value
storeGuiProperty("focus.generation",value.toString())
}
var fontSize: Int
var fontSize: Int = getGuiProperty("font.size","12")!!.toInt()
get() {
val prop = getGuiProperty("font.size","12")
return if (prop != null) {
field = if (prop != null) {
return prop.toInt()
} else {
12
}
return field
}
set(value) {
field = value
storeGuiProperty("font.size",value.toString())
val currentFont = UIManager.get("defaultFont") as Font
UIManager.put("defaultFont",FontUIResource(currentFont.fontName, currentFont.style, value))
FlatLaf.updateUI()
}

/**
Expand Down Expand Up @@ -452,4 +460,11 @@ class GuiProps(private val apiProperties: ApiProperties) {
fun storeGuiProperty(key: String, value: String) {
apiProperties.storeCustomProperty("$guiPropertyPrefix$key", value)
}

fun initFont() {
val value = getGuiProperty("font.size","12")!!.toInt()
val currentFont = UIManager.get("defaultFont") as Font
UIManager.put("defaultFont",FontUIResource(currentFont.fontName, currentFont.style, value))
FlatLaf.updateUI()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@ class MainWindow(
UIManager.setLookAndFeel(instance)
FlatLaf.updateUI()

val frame = MainFrame(
MainFrame(
guiProps,
apiWrapper,
updateChecker,
migrationManager
)
splashScreen.close()
if (guiProps.startFocusEnabled) {
frame.toFront()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,14 @@ class MainFrame(
frame.isAutoRequestFocus = true
frame.preferredSize = Dimension(1100, 860)
frame.pack()
guiProps.initFont()
frame.isVisible = true
guiProps.larsonScanner.loadConfig(guiProps.idleConfig)
guiProps.larsonScanner.play()
KeyComboManager(guiProps,apiWrapper,updateChecker,updateDialogs,migrationManager,frame,mainPanel,menu)
/*Toolkit.getDefaultToolkit().addAWTEventListener({ e: AWTEvent ->
val event = e as KeyEvent
if (event.id == KeyEvent.KEY_RELEASED) {
val currentFont = UIManager.get("defaultFont") as Font
when {
event.keyCode == KeyEvent.VK_UP && event.isControlDown && event.isShiftDown -> {
UIManager.put(
"defaultFont",
FontUIResource(currentFont.fontName, currentFont.style, currentFont.size + 1)
)
FlatLaf.updateUI()
}
event.keyCode == KeyEvent.VK_DOWN && event.isControlDown && event.isShiftDown -> {
UIManager.put(
"defaultFont",
FontUIResource(currentFont.fontName, currentFont.style, currentFont.size - 1)
)
FlatLaf.updateUI()
}
}
}
}, AWTEvent.KEY_EVENT_MASK)*/
if (guiProps.startFocusEnabled) {
toFront()
}
}

fun toFront() {
Expand Down

0 comments on commit 4a0c066

Please sign in to comment.