Improves some comments and variable names for ServerTab

This commit is contained in:
Kristian Knarvik 2020-08-17 22:55:09 +02:00
parent cc0a5a1659
commit d60e16b4a5

View File

@ -27,6 +27,12 @@ public class ServerTab implements ActionListener {
private final JPanel panel; private final JPanel panel;
private final String name; private final String name;
/**
* Initializes a new server tab with the given name
*
* @param name <p>The name of the new server tab</p>
* @throws ConfigurationException <p>If unable to create the new tab</p>
*/
public ServerTab(String name) throws ConfigurationException { public ServerTab(String name) throws ConfigurationException {
this.name = name; this.name = name;
panel = new JPanel(); panel = new JPanel();
@ -115,29 +121,44 @@ public class ServerTab implements ActionListener {
/** /**
* Updates the server tab components according to the received parameters. * Updates the server tab components according to the received parameters.
* *
* @param path The new path * @param path <p>The new path of the server tab</p>
* @param enabled The enabled status of the server * @param isEnabled <p>Whether to mark the server as enabled</p>
* @param typeName The name of the selected server type * @param typeName <p>The name of the selected server type</p>
* @param serverVersion The version of the server * @param serverVersion <p>The version of the server</p>
* @param maxRam The max usable ram for the server * @param maxRam <p>The maximum usable ram for the server</p>
*/ */
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.directory.setText(path);
this.chckbxEnabled.setSelected(enabled); this.chckbxEnabled.setSelected(isEnabled);
this.serverTypes.setSelectedItem(typeName); this.serverTypes.setSelectedItem(typeName);
this.serverTypes(); this.updateServerVersion();
this.serverVersions.setSelectedItem(serverVersion); this.serverVersions.setSelectedItem(serverVersion);
this.maxRam.setSelectedItem(maxRam); this.maxRam.setSelectedItem(maxRam);
} }
/**
* Gets the JPanel containing the server tab's elements
*
* @return <p>The JPanel containing the server tab's elements</p>
*/
public JPanel getPanel() { public JPanel getPanel() {
return this.panel; return this.panel;
} }
/**
* Gets the file path selected by the user
*
* @return <p>The file path selected by the user</p>
*/
public String getPath() { public String getPath() {
return this.directory.getText(); return this.directory.getText();
} }
/**
* Gets the maximum RAM selected by the user
*
* @return <p>The maximum RAM selected by the user</p>
*/
public String getMaxRam() { public String getMaxRam() {
Object selected = this.maxRam.getSelectedItem(); Object selected = this.maxRam.getSelectedItem();
if (selected != null) { if (selected != null) {
@ -147,6 +168,11 @@ public class ServerTab implements ActionListener {
} }
} }
/**
* Gets the server type selected by the user
*
* @return <p>The server type selected by the user</p>
*/
public String getType() { public String getType() {
Object selected = this.serverTypes.getSelectedItem(); Object selected = this.serverTypes.getSelectedItem();
if (selected != null) { 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 <p>The server version selected by the user</p>
*/ */
public String getVersion() { public String getVersion() {
Object selected = this.serverVersions.getSelectedItem(); 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 <p>True if this server is enabled</p>
*/ */
public boolean enabled() { public boolean isEnabled() {
return this.chckbxEnabled.isSelected(); return this.chckbxEnabled.isSelected();
} }
@ -187,7 +213,7 @@ public class ServerTab implements ActionListener {
browse(); browse();
} else if (e.getSource() == serverTypes) { } else if (e.getSource() == serverTypes) {
try { try {
serverTypes(); updateServerVersion();
} catch (ConfigurationException e1) { } catch (ConfigurationException e1) {
e1.printStackTrace(); 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() { private void remove() {
Main.getController().getCurrentProfile().removeCollection(this.name); Main.getController().getCurrentProfile().removeCollection(this.name);
@ -204,8 +230,7 @@ public class ServerTab implements ActionListener {
} }
/** /**
* Asks the user for the server folder. * Asks the user for server location and updates the GUI if given a valid value
* Sets the directory input's value if successful.
*/ */
private void browse() { private void browse() {
File chosenFolder = Main.getController().getGUI().askForDirectory("Server folder"); 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(); serverVersions.removeAllItems();
String selectedserverTypes = null; String selectedServerTypes = null;
Object selectedType = serverTypes.getSelectedItem(); Object selectedType = serverTypes.getSelectedItem();
if (selectedType != null) { if (selectedType != null) {
selectedserverTypes = selectedType.toString(); selectedServerTypes = selectedType.toString();
} }
if (selectedserverTypes != null) { if (selectedServerTypes == null) {
if (selectedserverTypes.equals("Custom")) { return;
serverVersions.setEditable(true); }
} else { if (selectedServerTypes.equals("Custom")) {
serverVersions.setEditable(false); serverVersions.setEditable(true);
ServerType current = null; } else {
for (ServerType servertype : ServerTypeHandler.getServerTypes()) { serverVersions.setEditable(false);
if (servertype.getName().equals(selectedserverTypes)) { ServerType current = null;
current = servertype; for (ServerType servertype : ServerTypeHandler.getServerTypes()) {
} if (servertype.getName().equals(selectedServerTypes)) {
current = servertype;
} }
if (current != null) { }
for (String version : current.getVersions()) { if (current != null) {
serverVersions.addItem(version); for (String version : current.getVersions()) {
} serverVersions.addItem(version);
} }
} }
} }