Improves readability of the server launcher menu code

This commit is contained in:
Kristian Knarvik 2021-08-03 10:40:12 +02:00
parent 33795a90a9
commit 429b1fcec0
2 changed files with 70 additions and 67 deletions

View File

@ -57,78 +57,18 @@ public class ServerLauncherMenu implements ActionListener {
public void initialize() { public void initialize() {
JMenu mnOptions = new JMenu("Options"); JMenu mnOptions = new JMenu("Options");
menuBar.add(mnOptions); menuBar.add(mnOptions);
generateOptionsMenuItems(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);
JMenu mnHelp = new JMenu("Help"); JMenu mnHelp = new JMenu("Help");
menuBar.add(mnHelp); menuBar.add(mnHelp);
errorsMenuItem = new JMenuItem("Errors"); errorsMenuItem = createMenuItem("Errors", mnHelp);
mnHelp.add(errorsMenuItem); setupMenuItem = createMenuItem("Setup", mnHelp);
errorsMenuItem.addActionListener(this); manualUpdateMenuItem = createMenuItem("Manual update", mnHelp);
setupMenuItem = new JMenuItem("Setup");
mnHelp.add(setupMenuItem);
setupMenuItem.addActionListener(this);
manualUpdateMenuItem = new JMenuItem("Manual update");
mnHelp.add(manualUpdateMenuItem);
manualUpdateMenuItem.addActionListener(this);
JMenu mnInfo = new JMenu("Info"); JMenu mnInfo = new JMenu("Info");
menuBar.add(mnInfo); menuBar.add(mnInfo);
generateInfoMenuItems(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);
} }
/** /**
@ -176,6 +116,69 @@ public class ServerLauncherMenu implements ActionListener {
} }
} }
/**
* Generates the children of the options menu
*
* @param mnOptions <p>A reference to the options menu</p>
*/
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 <p>A reference to the info menu</p>
*/
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 <p>The name of the new checkbox item</p>
* @param parent <p>The parent menu the item belongs to</p>
* @return <p>The created checkbox menu item</p>
*/
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 <p>The name of the new item</p>
* @param parent <p>The parent menu the item belongs to</p>
* @return <p>The created menu item</p>
*/
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 * Asks the user for the new Java path
* @param old <p>Whether asking for the path to the old java version</p> * @param old <p>Whether asking for the path to the old java version</p>

View File

@ -6,5 +6,5 @@ aboutText=This software was created to start and manage several servers simultan
infoURL=https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncherInfo/ infoURL=https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncherInfo/
manualUpdateURL=https://git.knarcraft.net/KnarCraft/Minecraft-Server-Launcher/releases manualUpdateURL=https://git.knarcraft.net/KnarCraft/Minecraft-Server-Launcher/releases
storyURL=https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncherStory/ 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. 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. If "java" is currently pointing to Java 16, you can use this to set a custom one for running old Minecraft servers. 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.
Can't render this file because it contains an unexpected character in line 9 and column 130.