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 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 {
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 <p>The new path of the server tab</p>
* @param isEnabled <p>Whether to mark the server as enabled</p>
* @param typeName <p>The name of the selected server type</p>
* @param serverVersion <p>The version of the server</p>
* @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.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 <p>The JPanel containing the server tab's elements</p>
*/
public JPanel getPanel() {
return this.panel;
}
/**
* Gets the file path selected by the user
*
* @return <p>The file path selected by the user</p>
*/
public String getPath() {
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() {
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 <p>The server type selected by the user</p>
*/
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 <p>The server version selected by the user</p>
*/
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 <p>True if this server is enabled</p>
*/
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);
}
}
}