Skip to content

Commit

Permalink
Work towards Settings. Add Webservice settings elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Sep 11, 2023
1 parent 2266e3b commit b9f316d
Show file tree
Hide file tree
Showing 11 changed files with 382 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@ actual class ApiProperties(
val fallbackServerPackCleanupEnabled = true
val fallbackMinecraftPreReleasesAvailabilityEnabled = false
val fallbackAutoExcludingModsEnabled = true
val fallbackArtemisQueueMaxDiskUsage = 90
val fallbackCleanupSchedule = "0 0 0 * * *"
val fallbackVersionSchedule = "0 0 0 * * *"
val fallbackDatabaseCleanupSchedule = "0 0 0 * * *"
private val serverPackCreatorProperties = "serverpackcreator.properties"
private val checkedJavas = hashMapOf<String, Boolean>()

Expand Down Expand Up @@ -1089,7 +1093,7 @@ actual class ApiProperties(
/**
* Maximum disk usage in percent until Artemis stops accepting new entries.
*/
var queueMaxDiskUsage = 90
var artemisQueueMaxDiskUsage = 90
get() {
val usage = getIntProperty(pSpringArtemisQueueMaxDiskUsage, 90)
field = if (usage in 0..100) {
Expand All @@ -1110,6 +1114,38 @@ actual class ApiProperties(
}
}

var webserviceCleanupSchedule: String
get() {
return internalProps.getProperty("de.griefed.serverpackcreator.spring.schedules.database.cleanup")
}
set(value) {
internalProps.setProperty("de.griefed.serverpackcreator.spring.schedules.database.cleanup",value)
}

var webserviceVersionSchedule: String
get() {
return internalProps.getProperty("de.griefed.serverpackcreator.spring.schedules.versions.refresh")
}
set(value) {
internalProps.setProperty("de.griefed.serverpackcreator.spring.schedules.versions.refresh",value)
}

var webserviceDatabaseCleanupSchedule: String
get() {
return internalProps.getProperty("de.griefed.serverpackcreator.spring.schedules.files.cleanup")
}
set(value) {
internalProps.setProperty("de.griefed.serverpackcreator.spring.schedules.files.cleanup",value)
}

fun defaultWebserviceDatabase(): File {
return File(userHome,"serverpackcreator.db")
}

fun defaultArtemisDataDirectory(): File {
return File(workDirectory, "artemis")
}

/**
* Default home-directory for ServerPackCreator. If there's no user-home, then the directory containing the
* ServerPackCreator JAR will be used as the home-directory for ServerPackCreator.
Expand Down Expand Up @@ -1193,6 +1229,10 @@ actual class ApiProperties(
log.info("Set Tomcat base-directory to: $field")
}

fun defaultTomcatBaseDirectory(): File {
return homeDirectory.absoluteFile
}

fun defaultServerPacksDirectory(): File {
return File(homeDirectory, "server-packs").absoluteFile
}
Expand Down Expand Up @@ -1237,7 +1277,7 @@ actual class ApiProperties(
@Suppress("MemberVisibilityCanBePrivate")
var tomcatLogsDirectory: File = logsDirectory
get() {
val default = File("${homeDirectory}${File.separator}logs").absolutePath
val default = File(homeDirectory,"logs").absolutePath
val dir = internalProps.getProperty(pTomcatLogsDirectory, default)
field = File(dir).absoluteFile
return field
Expand All @@ -1248,6 +1288,10 @@ actual class ApiProperties(
log.info("Set Tomcat logs-directory to: $field")
}

fun defaultTomcatLogsDirectory(): File {
return File(homeDirectory,"logs").absoluteFile
}

/**
* Directory to which default/fallback manifests are copied to during the startup of
* ServerPackCreator.
Expand Down Expand Up @@ -2066,7 +2110,7 @@ actual class ApiProperties(
log.info("Checking for pre-releases set to: $isCheckingForPreReleasesEnabled")
log.info("Zip-file exclusion enabled set to: $isZipFileExclusionEnabled")
log.info("HasteBin documents endpoint set to: $hasteBinServerUrl")
log.info("Queue max disk usage set to: $queueMaxDiskUsage")
log.info("Queue max disk usage set to: $artemisQueueMaxDiskUsage")
log.info("Directories which must always be included set to: $directoriesToInclude")
log.info("Directories which must always be excluded set to: $directoriesToExclude")
log.info("Cleanup of already existing server packs set to: $isServerPackCleanupEnabled")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class ApiPropertiesTest internal constructor() {
Assertions.assertNotNull(apiProperties.serverPacksDirectory)
Assertions.assertNotNull(apiProperties.directoriesToExclude)
Assertions.assertFalse(apiProperties.isCheckingForPreReleasesEnabled)
Assertions.assertEquals(90, apiProperties.queueMaxDiskUsage)
Assertions.assertEquals(90, apiProperties.artemisQueueMaxDiskUsage)
Assertions.assertEquals("dev", apiProperties.apiVersion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class GlobalSettings(guiProps: GuiProps, apiProperties: ApiProperties, component
val homeReset = BalloonTipButton(null,guiProps.resetIcon,"Reset to default value",guiProps) { homeSetting.file = apiProperties.defaultHomeDirectory() }

Check notice on line 42 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'homeReset' could be private
val homeChoose = BalloonTipButton(null,guiProps.folderIcon,"Select directory",guiProps) {

Check notice on line 43 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'homeChoose' could be private
val homeChooser = HomeDirChooser(apiProperties,"Home Directory Chooser")
if (homeChooser.showSaveDialog(mainFrame.frame) == JFileChooser.APPROVE_OPTION) {
if (homeChooser.showSaveDialog(mainFrame.frame) == JFileChooser.SAVE_DIALOG) {
homeSetting.file = homeChooser.selectedFile.absoluteFile
}
}
Expand All @@ -54,7 +54,7 @@ class GlobalSettings(guiProps: GuiProps, apiProperties: ApiProperties, component
val javaReset = BalloonTipButton(null,guiProps.resetIcon,"Reset to default value",guiProps) { javaSetting.file = File(apiProperties.acquireJavaPath()).absoluteFile }

Check notice on line 54 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'javaReset' could be private
val javaChoose = BalloonTipButton(null,guiProps.folderIcon,"Select executable",guiProps) {

Check notice on line 55 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'javaChoose' could be private
val javaChooser = JavaChooser(apiProperties,"Java Executable Chooser")
if (javaChooser.showSaveDialog(mainFrame.frame) == JFileChooser.APPROVE_OPTION) {
if (javaChooser.showSaveDialog(mainFrame.frame) == JFileChooser.SAVE_DIALOG) {
javaSetting.file = javaChooser.selectedFile.absoluteFile
}
}
Expand All @@ -66,7 +66,7 @@ class GlobalSettings(guiProps: GuiProps, apiProperties: ApiProperties, component
val serverPacksReset = BalloonTipButton(null,guiProps.resetIcon,"Reset to default value",guiProps) { serverPacksSetting.file = apiProperties.defaultServerPacksDirectory() }

Check notice on line 66 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'serverPacksReset' could be private
val serverPacksChoose = BalloonTipButton(null,guiProps.folderIcon,"Select directory",guiProps) {

Check notice on line 67 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'serverPacksChoose' could be private
val serverPackDirChooser = ServerPackDirChooser(apiProperties,"Server Pack Directory Chooser")
if (serverPackDirChooser.showSaveDialog(mainFrame.frame) == JFileChooser.APPROVE_OPTION) {
if (serverPackDirChooser.showSaveDialog(mainFrame.frame) == JFileChooser.SAVE_DIALOG) {
serverPacksSetting.file = serverPackDirChooser.selectedFile.absoluteFile
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ class GlobalSettings(guiProps: GuiProps, apiProperties: ApiProperties, component
val scriptReset = BalloonTipButton(null,guiProps.resetIcon,"Reset to default value",guiProps) { scriptSetting.text = apiProperties.defaultScriptTemplates().joinToString(", ") }

Check notice on line 96 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'scriptReset' could be private
val scriptChoose = BalloonTipButton(null,guiProps.folderIcon,"Select directory",guiProps) {

Check notice on line 97 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'scriptChoose' could be private
val scriptChooser = ScriptTemplatesChooser(apiProperties,"Script Template Chooser")
if (scriptChooser.showSaveDialog(mainFrame.frame) == JFileChooser.APPROVE_OPTION) {
if (scriptChooser.showSaveDialog(mainFrame.frame) == JFileChooser.SAVE_DIALOG) {
scriptSetting.text = scriptChooser.selectedFiles.joinToString(", ") { it.absolutePath }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,69 +24,67 @@ import de.griefed.serverpackcreator.gui.components.BalloonTipButton
import de.griefed.serverpackcreator.gui.components.ElementLabel
import de.griefed.serverpackcreator.gui.components.StatusIcon
import de.griefed.serverpackcreator.gui.window.settings.components.Editor
import java.awt.Font
import javax.swing.JCheckBox
import javax.swing.JSlider
import javax.swing.UIManager

class GuiSettings(guiProps: GuiProps) : Editor("Gui", guiProps) {

val fontSizeIcon = StatusIcon(guiProps,"Size of fonts in ServerPackCreators GUI.")

Check notice on line 32 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'fontSizeIcon' could be private
val fontSizeLabel = ElementLabel("Font Size")

Check notice on line 33 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'fontSizeLabel' could be private
val fontSizeSlider = JSlider(8,76,guiProps.fontSize)
val fontSizeSetting = JSlider(8,76,guiProps.fontSize)

Check notice on line 34 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'fontSizeSetting' could be private
val fontSizeRevert = BalloonTipButton(null,guiProps.revertIcon,"Revert changes", guiProps) {

Check notice on line 35 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'fontSizeRevert' could be private
fontSizeSlider.value = guiProps.fontSize
fontSizeSetting.value = guiProps.fontSize
}
val fontSizeReset = BalloonTipButton(null,guiProps.resetIcon,"Reset to default value",guiProps) {

Check notice on line 38 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'fontSizeReset' could be private
fontSizeSlider.value = 12
fontSizeSetting.value = 12
}

val startFocusIcon = StatusIcon(guiProps,"Whether ServerPackCreator should be focused after starting.")

Check notice on line 42 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'startFocusIcon' could be private
val startFocusLabel = ElementLabel("Focus On Start")

Check notice on line 43 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'startFocusLabel' could be private
val startFocusEnabled = JCheckBox()
val startFocusSetting = JCheckBox()

Check notice on line 44 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'startFocusSetting' could be private
val startFocusRevert = BalloonTipButton(null,guiProps.revertIcon,"Revert changes",guiProps) {

Check notice on line 45 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'startFocusRevert' could be private
startFocusEnabled.isSelected = guiProps.startFocusEnabled
startFocusSetting.isSelected = guiProps.startFocusEnabled
}
val startFocusReset = BalloonTipButton(null,guiProps.resetIcon,"Reset to default value",guiProps) {

Check notice on line 48 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'startFocusReset' could be private
startFocusEnabled.isSelected = false
startFocusSetting.isSelected = false
}

val generationFocusIcon = StatusIcon(guiProps,"Whether ServerPackCreator should be focused after a server pack has been generated.")

Check notice on line 52 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'generationFocusIcon' could be private
val generationFocusLabel = ElementLabel("Focus After Generation")

Check notice on line 53 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'generationFocusLabel' could be private
val generationFocusEnabled = JCheckBox()
val generationFocusSetting = JCheckBox()

Check notice on line 54 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'generationFocusSetting' could be private
val generationFocusRevert = BalloonTipButton(null,guiProps.revertIcon,"Revert changes",guiProps) {

Check notice on line 55 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'generationFocusRevert' could be private
generationFocusEnabled.isSelected = guiProps.generationFocusEnabled
generationFocusSetting.isSelected = guiProps.generationFocusEnabled
}
val generationFocusReset = BalloonTipButton(null,guiProps.resetIcon,"Reset to default value",guiProps) {

Check notice on line 58 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'generationFocusReset' could be private
generationFocusEnabled.isSelected = false
generationFocusSetting.isSelected = false
}

init {
startFocusEnabled.isSelected = guiProps.startFocusEnabled
generationFocusEnabled.isSelected = guiProps.generationFocusEnabled
fontSizeSlider.paintTicks = true
fontSizeSlider.paintLabels = true
fontSizeSlider.majorTickSpacing = 4
fontSizeSlider.minorTickSpacing = 2
startFocusSetting.isSelected = guiProps.startFocusEnabled
generationFocusSetting.isSelected = guiProps.generationFocusEnabled
fontSizeSetting.paintTicks = true
fontSizeSetting.paintLabels = true
fontSizeSetting.majorTickSpacing = 4
fontSizeSetting.minorTickSpacing = 2

var y = 0
panel.add(fontSizeIcon, "cell 0 $y")

Check notice on line 71 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Constant conditions

Value of 'y' is always zero
panel.add(fontSizeLabel, "cell 1 $y")

Check notice on line 72 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Constant conditions

Value of 'y' is always zero
panel.add(fontSizeSlider, "cell 2 $y, grow")
panel.add(fontSizeSetting, "cell 2 $y, grow")

Check notice on line 73 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Constant conditions

Value of 'y' is always zero
panel.add(fontSizeRevert, "cell 3 $y")

Check notice on line 74 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Constant conditions

Value of 'y' is always zero
panel.add(fontSizeReset, "cell 4 $y")

Check notice on line 75 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GuiSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Constant conditions

Value of 'y' is always zero

y++
panel.add(startFocusIcon, "cell 0 $y")
panel.add(startFocusLabel, "cell 1 $y")
panel.add(startFocusEnabled, "cell 2 $y, grow")
panel.add(startFocusSetting, "cell 2 $y, grow")
panel.add(startFocusRevert, "cell 3 $y")
panel.add(startFocusReset, "cell 4 $y")

y++
panel.add(generationFocusIcon, "cell 0 $y")
panel.add(generationFocusLabel, "cell 1 $y")
panel.add(generationFocusEnabled, "cell 2 $y, grow")
panel.add(generationFocusSetting, "cell 2 $y, grow")
panel.add(generationFocusRevert, "cell 3 $y")
panel.add(generationFocusReset, "cell 4 $y")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SettingsEditorsTab(guiProps: GuiProps, apiProperties: ApiProperties, mainF

private val componentResizer = ComponentResizer()
val global = GlobalSettings(guiProps, apiProperties, componentResizer, mainFrame)
val webservice = WebserviceSettings(guiProps)
val webservice = WebserviceSettings(guiProps, apiProperties,mainFrame)
val gui = GuiSettings(guiProps)

init {
Expand Down
Loading

0 comments on commit b9f316d

Please sign in to comment.