From e71e95df7ff9c4f258bbc04f57af2b3d830db65a Mon Sep 17 00:00:00 2001 From: Kristian Knarvik Date: Mon, 17 Aug 2020 23:09:37 +0200 Subject: [PATCH] Improves some comments and structure for the Controller --- .../profile/Controller.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/profile/Controller.java b/src/main/java/net/knarcraft/minecraftserverlauncher/profile/Controller.java index 49b86b6..b9e6aa4 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/profile/Controller.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/profile/Controller.java @@ -16,7 +16,7 @@ import java.util.Scanner; import java.util.concurrent.Executors; /** - * This class controls + * This class handles profiles, GUI creation and session restoration */ public class Controller { @@ -30,6 +30,9 @@ public class Controller { private boolean downloadAllJars; private static Controller controller; + /** + * Instantiates a new controller + */ private Controller() { 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

The name of the new profile

*/ public void addProfile(String 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 * - * @param name

The name of the profile to rempve

+ * @param name

The name of the profile to remove

*/ public void removeProfile(String name) { 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 { //Loads data regarding this controller @@ -193,7 +196,19 @@ public class Controller { } else { this.serverLauncherGUI = new ServerLauncherGUI(); } + //Loads all saved profiles + loadProfiles(currentProfile); + //Makes the GUI show the loaded data + executeGUILoadingTasks(); + } + /** + * Loads all saved profiles + * + * @param currentProfile

The profile saved as the current profile

+ * @throws ConfigurationException

If unable to load a profile

+ */ + private void loadProfiles(String currentProfile) throws ConfigurationException { try (Scanner in = new Scanner(new File(profilesFile))) { while (in.hasNextLine()) { String profileData = in.nextLine(); @@ -208,7 +223,12 @@ public class Controller { if (this.currentProfile == null) { this.currentProfile = this.profileList.get(0); } + } + /** + * Updates the GUI as necessary to display loaded data + */ + private void executeGUILoadingTasks() { this.serverLauncherGUI.updateProfiles(); this.serverLauncherGUI.update(); this.currentProfile.updateConsoles(); @@ -286,7 +306,7 @@ public class Controller { } catch (IllegalArgumentException e) { serverLauncherGUI.showError("Invalid server version for " + server.getName()); } - server.setEnabled(serverTab.enabled()); + server.setEnabled(serverTab.isEnabled()); } }