diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerTab.java b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerTab.java index b210f57..d9b2a2d 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerTab.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerTab.java @@ -27,6 +27,12 @@ public class ServerTab implements ActionListener { private final JPanel panel; private final String name; + /** + * Initializes a new server tab with the given name + * + * @param name

The name of the new server tab

+ * @throws ConfigurationException

If unable to create the new tab

+ */ public ServerTab(String name) throws ConfigurationException { this.name = name; panel = new JPanel(); @@ -115,29 +121,44 @@ public class ServerTab implements ActionListener { /** * Updates the server tab components according to the received parameters. * - * @param path The new path - * @param enabled The enabled status of the server - * @param typeName The name of the selected server type - * @param serverVersion The version of the server - * @param maxRam The max usable ram for the server + * @param path

The new path of the server tab

+ * @param isEnabled

Whether to mark the server as enabled

+ * @param typeName

The name of the selected server type

+ * @param serverVersion

The version of the server

+ * @param maxRam

The maximum usable ram for the server

*/ - public void setData(String path, boolean enabled, String typeName, String serverVersion, String maxRam) throws ConfigurationException { + public void setData(String path, boolean isEnabled, String typeName, String serverVersion, String maxRam) throws ConfigurationException { this.directory.setText(path); - this.chckbxEnabled.setSelected(enabled); + this.chckbxEnabled.setSelected(isEnabled); this.serverTypes.setSelectedItem(typeName); - this.serverTypes(); + this.updateServerVersion(); this.serverVersions.setSelectedItem(serverVersion); this.maxRam.setSelectedItem(maxRam); } + /** + * Gets the JPanel containing the server tab's elements + * + * @return

The JPanel containing the server tab's elements

+ */ public JPanel getPanel() { return this.panel; } + /** + * Gets the file path selected by the user + * + * @return

The file path selected by the user

+ */ public String getPath() { return this.directory.getText(); } + /** + * Gets the maximum RAM selected by the user + * + * @return

The maximum RAM selected by the user

+ */ public String getMaxRam() { Object selected = this.maxRam.getSelectedItem(); if (selected != null) { @@ -147,6 +168,11 @@ public class ServerTab implements ActionListener { } } + /** + * Gets the server type selected by the user + * + * @return

The server type selected by the user

+ */ public String getType() { Object selected = this.serverTypes.getSelectedItem(); if (selected != null) { @@ -157,9 +183,9 @@ public class ServerTab implements ActionListener { } /** - * Gets the selected version from the serverVersion combo + * Gets the server version selected by the user * - * @return The combo value, or defaults to "Latest" on null + * @return

The server version selected by the user

*/ public String getVersion() { Object selected = this.serverVersions.getSelectedItem(); @@ -171,11 +197,11 @@ public class ServerTab implements ActionListener { } /** - * Checks if the server is enabled + * Checks whether this server is enabled * - * @return True if the checkbox is checked. False otherwise. + * @return

True if this server is enabled

*/ - public boolean enabled() { + public boolean isEnabled() { return this.chckbxEnabled.isSelected(); } @@ -187,7 +213,7 @@ public class ServerTab implements ActionListener { browse(); } else if (e.getSource() == serverTypes) { try { - serverTypes(); + updateServerVersion(); } catch (ConfigurationException e1) { e1.printStackTrace(); } @@ -195,7 +221,7 @@ public class ServerTab implements ActionListener { } /** - * Removes the collection containing this ServerTab, and updates everything necessary. + * Removes the collection containing this ServerTab, and updates everything necessary */ private void remove() { Main.getController().getCurrentProfile().removeCollection(this.name); @@ -204,8 +230,7 @@ public class ServerTab implements ActionListener { } /** - * Asks the user for the server folder. - * Sets the directory input's value if successful. + * Asks the user for server location and updates the GUI if given a valid value */ private void browse() { File chosenFolder = Main.getController().getGUI().askForDirectory("Server folder"); @@ -215,30 +240,31 @@ public class ServerTab implements ActionListener { } /** - * Updates the versions combo according to the value of the server type combo. + * Updates server version choices according to the server type */ - private void serverTypes() throws ConfigurationException { + private void updateServerVersion() throws ConfigurationException { serverVersions.removeAllItems(); - String selectedserverTypes = null; + String selectedServerTypes = null; Object selectedType = serverTypes.getSelectedItem(); if (selectedType != null) { - selectedserverTypes = selectedType.toString(); + selectedServerTypes = selectedType.toString(); } - if (selectedserverTypes != null) { - if (selectedserverTypes.equals("Custom")) { - serverVersions.setEditable(true); - } else { - serverVersions.setEditable(false); - ServerType current = null; - for (ServerType servertype : ServerTypeHandler.getServerTypes()) { - if (servertype.getName().equals(selectedserverTypes)) { - current = servertype; - } + if (selectedServerTypes == null) { + return; + } + if (selectedServerTypes.equals("Custom")) { + serverVersions.setEditable(true); + } else { + serverVersions.setEditable(false); + ServerType current = null; + for (ServerType servertype : ServerTypeHandler.getServerTypes()) { + if (servertype.getName().equals(selectedServerTypes)) { + current = servertype; } - if (current != null) { - for (String version : current.getVersions()) { - serverVersions.addItem(version); - } + } + if (current != null) { + for (String version : current.getVersions()) { + serverVersions.addItem(version); } } }