Skip to content

Commit

Permalink
refactor: Reorganize classes and functions to better fit their purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Oct 1, 2023
1 parent b94eccb commit 87f2714
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,25 @@ class MainWindow(
UIManager.setLookAndFeel(instance)
FlatLaf.updateUI()

MainFrame(
val main = MainFrame(
guiProps,
apiWrapper,
updateChecker,
migrationManager
)
splashScreen.close()
guiProps.font = guiProps.font
if (guiProps.startFocusEnabled) {
main.toFront()
} else {
main.show()
}
if (!apiWrapper.apiProperties.preRelease) {
main.displayMigrationMessages()
}
if (guiProps.showTipOnStartup) {
main.showTip()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
*/
package de.griefed.serverpackcreator.gui.window.tips
package de.griefed.serverpackcreator.gui.tips

import tokyo.northside.swing.tips.DefaultTip
import javax.swing.ImageIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
*/
package de.griefed.serverpackcreator.gui.window.tips
package de.griefed.serverpackcreator.gui.tips

import Gui
import de.griefed.serverpackcreator.gui.GuiProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
*/
package de.griefed.serverpackcreator.gui.window.tips
package de.griefed.serverpackcreator.gui.tips

import Gui
import de.griefed.serverpackcreator.gui.GuiProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ import Gui
import de.griefed.serverpackcreator.api.ApiWrapper
import de.griefed.serverpackcreator.gui.GuiProps
import de.griefed.serverpackcreator.gui.window.menu.MainMenuBar
import de.griefed.serverpackcreator.gui.window.tips.TipOfTheDayManager
import de.griefed.serverpackcreator.updater.MigrationManager
import de.griefed.serverpackcreator.updater.UpdateChecker
import java.awt.Dimension
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import javax.swing.JFrame
import javax.swing.WindowConstants
import javax.swing.event.HyperlinkEvent
import javax.swing.event.HyperlinkListener

/**
* Main Frame of ServerPackCreator, housing [MainPanel], [MainMenuBar].
Expand All @@ -47,50 +44,63 @@ class MainFrame(
) {
val frame: JFrame = JFrame(Gui.createserverpack_gui_createandshowgui.toString())
val mainPanel = MainPanel(guiProps, apiWrapper, guiProps.larsonScanner,this)
private val updateDialogs : UpdateDialogs
private val menuBar: MainMenuBar

init {
val closeAndExit = object : WindowAdapter() {
override fun windowClosing(event: WindowEvent) {
mainPanel.closeAndExit()
}
}
val updateDialogs = UpdateDialogs(
updateDialogs = UpdateDialogs(
guiProps, apiWrapper.utilities!!.webUtilities,
apiWrapper.apiProperties, updateChecker, frame
)
val menu = MainMenuBar(
menuBar = MainMenuBar(
guiProps, apiWrapper, updateDialogs,
this, migrationManager
)
frame.jMenuBar = menu.menuBar
frame.jMenuBar = menuBar.menuBar
frame.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
frame.addWindowListener(closeAndExit)
frame.addWindowListener(object : WindowAdapter() {
override fun windowClosing(event: WindowEvent) {
mainPanel.closeAndExit()
}
})
frame.iconImage = guiProps.appIcon
frame.contentPane = mainPanel.panel
frame.isLocationByPlatform = true
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)
if (guiProps.startFocusEnabled) {
toFront()
}
if (!apiWrapper.apiProperties.preRelease) {
menu.displayMigrationMessages()
}
if (guiProps.showTipOnStartup) {
menu.showTip()
}
KeyComboManager(guiProps,apiWrapper,updateChecker,updateDialogs,migrationManager,frame,mainPanel,menuBar)
}

/**
* @author Griefed
*/
fun show() {
frame.isVisible = true
}

/**
* @author Griefed
*/
fun displayMigrationMessages() {
menuBar.displayMigrationMessages()
}

/**
* @author Griefed
*/
fun showTip() {
menuBar.showTip()
}

/**
* @author Griefed
*/
fun toFront() {
frame.isAutoRequestFocus = true
show()
frame.toFront()
frame.requestFocus()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package de.griefed.serverpackcreator.gui.window.menu.about

import de.griefed.serverpackcreator.gui.GuiProps
import de.griefed.serverpackcreator.gui.window.MainFrame
import de.griefed.serverpackcreator.gui.window.tips.TipOfTheDayManager
import de.griefed.serverpackcreator.gui.tips.TipOfTheDayManager
import javax.swing.JMenuItem

/**
Expand Down

0 comments on commit 87f2714

Please sign in to comment.