Skip to content

Commit

Permalink
extension fn for checkbox matching preference
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Mar 8, 2024
1 parent 0265bfa commit 49e4af6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package dartzee.screen.preference

import dartzee.core.util.setFontSize
import dartzee.preferences.Preference
import dartzee.screen.ScreenCache
import dartzee.utils.InjectedThings.preferenceService
import dartzee.utils.resetCachedDartboardValues
import java.awt.BorderLayout
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import javax.swing.JButton
import javax.swing.JCheckBox
import javax.swing.JPanel

abstract class AbstractPreferencesPanel : JPanel() {
Expand Down Expand Up @@ -39,6 +42,9 @@ abstract class AbstractPreferencesPanel : JPanel() {
btnApply.isEnabled = hasOutstandingChanges()
}

protected fun JCheckBox.matchesPreference(preference: Preference<Boolean>) =
isSelected == preferenceService.get(preference)

inner class PreferencesPanelListener : ActionListener {
override fun actionPerformed(e: ActionEvent?) {
when (e?.source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ class PreferencesPanelMisc :
override fun hasOutstandingChanges() =
slider.value != preferenceService.get(Preferences.aiSpeed) ||
nfLeaderboardSize.value != preferenceService.get(Preferences.leaderboardSize) ||
chckbxAiAutomaticallyFinish.isSelected !=
preferenceService.get(Preferences.aiAutoContinue) ||
chckbxCheckForUpdates.isSelected !=
preferenceService.get(Preferences.checkForUpdates) ||
chckbxShowAnimations.isSelected != preferenceService.get(Preferences.showAnimations)
!chckbxAiAutomaticallyFinish.matchesPreference(Preferences.aiAutoContinue) ||
!chckbxCheckForUpdates.matchesPreference(Preferences.checkForUpdates) ||
!chckbxShowAnimations.matchesPreference(Preferences.showAnimations)

override fun stateChanged(e: ChangeEvent?) = stateChanged()

Expand Down

0 comments on commit 49e4af6

Please sign in to comment.