diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherMenu.java b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherMenu.java index 31900d9..f695ef3 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherMenu.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherMenu.java @@ -57,78 +57,18 @@ public class ServerLauncherMenu implements ActionListener { public void initialize() { JMenu mnOptions = new JMenu("Options"); menuBar.add(mnOptions); - - runInBackgroundCheckBoxMenuItem = new JCheckBoxMenuItem("Run in background on exit"); - mnOptions.add(runInBackgroundCheckBoxMenuItem); - runInBackgroundCheckBoxMenuItem.addActionListener(this); - - delayStartupCheckBoxMenuItem = new JCheckBoxMenuItem("Delay Startup"); - mnOptions.add(delayStartupCheckBoxMenuItem); - delayStartupCheckBoxMenuItem.addActionListener(this); - - downloadJarsCheckBoxMenuItem = new JCheckBoxMenuItem("Download jars"); - mnOptions.add(downloadJarsCheckBoxMenuItem); - downloadJarsCheckBoxMenuItem.addActionListener(this); - - javaCommandMenuItem = new JMenuItem("Java command"); - mnOptions.add(javaCommandMenuItem); - javaCommandMenuItem.addActionListener(this); - - oldJavaCommandMenuItem = new JMenuItem("Old Java command"); - mnOptions.add(oldJavaCommandMenuItem); - oldJavaCommandMenuItem.addActionListener(this); + generateOptionsMenuItems(mnOptions); JMenu mnHelp = new JMenu("Help"); menuBar.add(mnHelp); - errorsMenuItem = new JMenuItem("Errors"); - mnHelp.add(errorsMenuItem); - errorsMenuItem.addActionListener(this); - - setupMenuItem = new JMenuItem("Setup"); - mnHelp.add(setupMenuItem); - setupMenuItem.addActionListener(this); - - manualUpdateMenuItem = new JMenuItem("Manual update"); - mnHelp.add(manualUpdateMenuItem); - manualUpdateMenuItem.addActionListener(this); + errorsMenuItem = createMenuItem("Errors", mnHelp); + setupMenuItem = createMenuItem("Setup", mnHelp); + manualUpdateMenuItem = createMenuItem("Manual update", mnHelp); JMenu mnInfo = new JMenu("Info"); menuBar.add(mnInfo); - - JMenu mnOptionsInfo = new JMenu("Options"); - mnInfo.add(mnOptionsInfo); - - runInBackgroundMenuItem = new JMenuItem("Run in background on exit"); - mnOptionsInfo.add(runInBackgroundMenuItem); - runInBackgroundMenuItem.addActionListener(this); - - delayStartupMenuItem = new JMenuItem("Delay Startup"); - mnOptionsInfo.add(delayStartupMenuItem); - delayStartupMenuItem.addActionListener(this); - - downloadJarsMenuItem = new JMenuItem("Download jars"); - mnOptionsInfo.add(downloadJarsMenuItem); - downloadJarsMenuItem.addActionListener(this); - - javaCommandInfoMenuItem = new JMenuItem("Java command"); - mnOptionsInfo.add(javaCommandInfoMenuItem); - javaCommandInfoMenuItem.addActionListener(this); - - oldJavaCommandInfoMenuItem = new JMenuItem("Old Java command"); - mnOptionsInfo.add(oldJavaCommandInfoMenuItem); - oldJavaCommandInfoMenuItem.addActionListener(this); - - JMenu mnAbout = new JMenu("About"); - mnInfo.add(mnAbout); - - aboutMenuItem = new JMenuItem("About"); - mnAbout.add(aboutMenuItem); - aboutMenuItem.addActionListener(this); - - storyMenuItem = new JMenuItem("Story"); - mnAbout.add(storyMenuItem); - storyMenuItem.addActionListener(this); + generateInfoMenuItems(mnInfo); } /** @@ -176,6 +116,69 @@ public class ServerLauncherMenu implements ActionListener { } } + /** + * Generates the children of the options menu + * + * @param mnOptions

A reference to the options menu

+ */ + private void generateOptionsMenuItems(JMenu mnOptions) { + runInBackgroundCheckBoxMenuItem = createCheckBoxMenuItem("Run in background on exit", mnOptions); + delayStartupCheckBoxMenuItem = createCheckBoxMenuItem("Delay Startup", mnOptions); + downloadJarsCheckBoxMenuItem = createCheckBoxMenuItem("Download jars", mnOptions); + javaCommandMenuItem = createMenuItem("Java command", mnOptions); + oldJavaCommandMenuItem = createMenuItem("Old Java command", mnOptions); + } + + /** + * Generates the children of the info menu + * + * @param mnInfo

A reference to the info menu

+ */ + private void generateInfoMenuItems(JMenu mnInfo) { + JMenu mnOptionsInfo = new JMenu("Options"); + mnInfo.add(mnOptionsInfo); + + runInBackgroundMenuItem = createMenuItem("Run in background on exit", mnOptionsInfo); + delayStartupMenuItem = createMenuItem("Delay Startup", mnOptionsInfo); + downloadJarsMenuItem = createMenuItem("Download jars", mnOptionsInfo); + javaCommandInfoMenuItem = createMenuItem("Java command", mnOptionsInfo); + oldJavaCommandInfoMenuItem = createMenuItem("Old Java command", mnOptionsInfo); + + JMenu mnAbout = new JMenu("About"); + mnInfo.add(mnAbout); + + aboutMenuItem = createMenuItem("About", mnAbout); + storyMenuItem = createMenuItem("Story", mnAbout); + } + + /** + * Creates a checkbox menu item + * + * @param itemName

The name of the new checkbox item

+ * @param parent

The parent menu the item belongs to

+ * @return

The created checkbox menu item

+ */ + private JCheckBoxMenuItem createCheckBoxMenuItem(String itemName, JMenu parent) { + JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(itemName); + parent.add(menuItem); + menuItem.addActionListener(this); + return menuItem; + } + + /** + * Creates a menu item + * + * @param itemName

The name of the new item

+ * @param parent

The parent menu the item belongs to

+ * @return

The created menu item

+ */ + private JMenuItem createMenuItem(String itemName, JMenu parent) { + JMenuItem menuItem = new JMenuItem(itemName); + parent.add(menuItem); + menuItem.addActionListener(this); + return menuItem; + } + /** * Asks the user for the new Java path * @param old

Whether asking for the path to the old java version

diff --git a/src/main/resources/menumsg.csv b/src/main/resources/menumsg.csv index 946efdb..0c37914 100644 --- a/src/main/resources/menumsg.csv +++ b/src/main/resources/menumsg.csv @@ -6,5 +6,5 @@ aboutText=This software was created to start and manage several servers simultan infoURL=https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncherInfo/ manualUpdateURL=https://git.knarcraft.net/KnarCraft/Minecraft-Server-Launcher/releases storyURL=https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncherStory/ -javaCommandText=This option allows you to set a custom command/path to the Java executable used for Minecraft 1.17 and above. If "java" is currently pointing to Java 8, you can use this to set a custom one for running new Minecraft servers and BuildTools. -oldJavaCommandText=This option allows you to set a custom command/path to the Java executable used for Minecraft 1.16 and below. If "java" is currently pointing to Java 16, you can use this to set a custom one for running old Minecraft servers. \ No newline at end of file +javaCommandText=This option allows you to set a custom command/path to the Java executable used for Minecraft 1.17 and above._BREAK_If "java" is currently pointing to Java 8, you can use this to set a custom one for running new Minecraft servers and BuildTools. +oldJavaCommandText=This option allows you to set a custom command/path to the Java executable used for Minecraft 1.16 and below._BREAK_If "java" is currently pointing to Java 16, you can use this to set a custom one for running old Minecraft servers. \ No newline at end of file