Improves some comments and structure for the Controller
This commit is contained in:
parent
d60e16b4a5
commit
e71e95df7f
@ -16,7 +16,7 @@ import java.util.Scanner;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class controls
|
* This class handles profiles, GUI creation and session restoration
|
||||||
*/
|
*/
|
||||||
public class Controller {
|
public class Controller {
|
||||||
|
|
||||||
@ -30,6 +30,9 @@ public class Controller {
|
|||||||
private boolean downloadAllJars;
|
private boolean downloadAllJars;
|
||||||
private static Controller controller;
|
private static Controller controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new controller
|
||||||
|
*/
|
||||||
private Controller() {
|
private Controller() {
|
||||||
this.profileList = new ArrayList<>();
|
this.profileList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
@ -123,9 +126,9 @@ public class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a profile if the name is valid and unique.
|
* Adds a profile if the name is valid and unique
|
||||||
*
|
*
|
||||||
* @param name The name of the new profile.
|
* @param name <p>The name of the new profile</p>
|
||||||
*/
|
*/
|
||||||
public void addProfile(String name) {
|
public void addProfile(String name) {
|
||||||
if (!CommonFunctions.nameIsValid(name)) {
|
if (!CommonFunctions.nameIsValid(name)) {
|
||||||
@ -148,7 +151,7 @@ public class Controller {
|
|||||||
/**
|
/**
|
||||||
* Removes a profile with the given name from the list of profiles, if such a profile exists
|
* Removes a profile with the given name from the list of profiles, if such a profile exists
|
||||||
*
|
*
|
||||||
* @param name <p>The name of the profile to rempve</p>
|
* @param name <p>The name of the profile to remove</p>
|
||||||
*/
|
*/
|
||||||
public void removeProfile(String name) {
|
public void removeProfile(String name) {
|
||||||
if (profileList.size() > 1) {
|
if (profileList.size() > 1) {
|
||||||
@ -182,7 +185,7 @@ public class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads profiles and servers from a text file.
|
* Reads profiles and servers from a text file
|
||||||
*/
|
*/
|
||||||
public void loadState() throws ConfigurationException, IOException {
|
public void loadState() throws ConfigurationException, IOException {
|
||||||
//Loads data regarding this controller
|
//Loads data regarding this controller
|
||||||
@ -193,7 +196,19 @@ public class Controller {
|
|||||||
} else {
|
} else {
|
||||||
this.serverLauncherGUI = new ServerLauncherGUI();
|
this.serverLauncherGUI = new ServerLauncherGUI();
|
||||||
}
|
}
|
||||||
|
//Loads all saved profiles
|
||||||
|
loadProfiles(currentProfile);
|
||||||
|
//Makes the GUI show the loaded data
|
||||||
|
executeGUILoadingTasks();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads all saved profiles
|
||||||
|
*
|
||||||
|
* @param currentProfile <p>The profile saved as the current profile</p>
|
||||||
|
* @throws ConfigurationException <p>If unable to load a profile</p>
|
||||||
|
*/
|
||||||
|
private void loadProfiles(String currentProfile) throws ConfigurationException {
|
||||||
try (Scanner in = new Scanner(new File(profilesFile))) {
|
try (Scanner in = new Scanner(new File(profilesFile))) {
|
||||||
while (in.hasNextLine()) {
|
while (in.hasNextLine()) {
|
||||||
String profileData = in.nextLine();
|
String profileData = in.nextLine();
|
||||||
@ -208,7 +223,12 @@ public class Controller {
|
|||||||
if (this.currentProfile == null) {
|
if (this.currentProfile == null) {
|
||||||
this.currentProfile = this.profileList.get(0);
|
this.currentProfile = this.profileList.get(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the GUI as necessary to display loaded data
|
||||||
|
*/
|
||||||
|
private void executeGUILoadingTasks() {
|
||||||
this.serverLauncherGUI.updateProfiles();
|
this.serverLauncherGUI.updateProfiles();
|
||||||
this.serverLauncherGUI.update();
|
this.serverLauncherGUI.update();
|
||||||
this.currentProfile.updateConsoles();
|
this.currentProfile.updateConsoles();
|
||||||
@ -286,7 +306,7 @@ public class Controller {
|
|||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
serverLauncherGUI.showError("Invalid server version for " + server.getName());
|
serverLauncherGUI.showError("Invalid server version for " + server.getName());
|
||||||
}
|
}
|
||||||
server.setEnabled(serverTab.enabled());
|
server.setEnabled(serverTab.isEnabled());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user