diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherGUI.java b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherGUI.java index 69f8849..76fdc0b 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherGUI.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherGUI.java @@ -18,9 +18,7 @@ import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.*; -import java.util.ArrayList; -import java.util.Objects; -import java.util.Scanner; +import java.util.*; import java.util.concurrent.Executors; import static java.awt.Frame.NORMAL; @@ -39,31 +37,53 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, private final JLabel lblStatuslabel = new JLabel("Servers are stopped"); private final ArrayList globalPlayers; + private Controller controller; + private Map textStrings; + private JFrame frame; private JTabbedPane tabbedPane; private JTabbedPane serversPane; - //Menu - private JCheckBoxMenuItem chckbxmntmRunInBackground, chckbxmntmDelayStartup, chckbxmntmDownloadJars; //Options - private JMenuItem mntmErrors, mntmSetup, mntmManualUpdate; //Help - private JMenuItem mntmRunInBackground, mntmDelayStartup, mntmDownloadJars; //Info/options - private JMenuItem mntmAbout, mntmStory; //Info/about + /******* + * Menu + ********/ + //Options + private JCheckBoxMenuItem runInBackgroundCheckBoxMenuItem; + private JCheckBoxMenuItem delayStartupCheckBoxMenuItem; + private JCheckBoxMenuItem downloadJarsCheckBoxMenuItem; + //Help + private JMenuItem errorsMenuItem; + private JMenuItem setupMenuItem; + private JMenuItem manualUpdateMenuItem; + //Info/options + private JMenuItem runInBackgroundMenuItem; + private JMenuItem delayStartupMenuItem; + private JMenuItem downloadJarsMenuItem; + //Info/about + private JMenuItem aboutMenuItem; + private JMenuItem storyMenuItem; //Basic controls - private JButton btnStartServer, btnStopServer, addServer, backup, addProfile, delProfile; + private JButton startServerButton; + private JButton stopServerButton; + private JButton addServerButton; + private JButton backupButton; + private JButton addProfileButton; + private JButton deleteProfileButton; private JComboBox profiles; //Server controls - private JComboBox targetServer; - private JComboBox targetPlayer; - private JButton btnKick, btnBan, btnOp, btnDeop, btnCustomCommand, btnSaveserver, btnReload, btnServerConsoles; - private JTextField customCommand; - //Text - private String setupText; - private String runInBackgroundText; - private String delayStartupText; - private String downloadJarsText; - private String aboutText; + private JComboBox targetServerCombo; + private JComboBox targetPlayerCombo; + private JButton kickButton; + private JButton banButton; + private JButton opButton; + private JButton deopButton; + private JButton customCommandButton; + private JButton saveServerButton; + private JButton reloadButton; + private JButton showConsolesButton; + private JTextField customCommandTextField; + //Tray private SystemTray tray; private TrayIcon trayIcon; - private Controller controller; /** * Creates the application window @@ -93,7 +113,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, /** * Gets the pane used for server configurations * - * @return A JTabbedPane + * @return

The pane used for server configurations

*/ public JTabbedPane getPane() { return this.serversPane; @@ -125,9 +145,9 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, } /** - * Adds a player to the global playerlist, and updates the players combo. + * Adds a player to the global player list, and updates the players combo * - * @param name The name of the player to add + * @param name

The name of the player to add

*/ public void addPlayer(String name) { this.globalPlayers.add(name); @@ -135,9 +155,9 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, } /** - * Removes a player from the global list of players. + * Removes a player from the global list of players * - * @param name The name of the player to remove. + * @param name

The name of the player to remove

*/ public void removePlayer(String name) { globalPlayers.removeIf(playerName -> playerName.equals(name)); @@ -145,7 +165,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, } /** - * Updates the profiles combo. + * Updates the profiles combo */ public void updateProfiles() { String selectedProfile = Main.getController().getCurrentProfile().getName(); @@ -159,31 +179,31 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, /** * Gets the size of the main JFrame * - * @return The Dimension of the frame + * @return

The Dimension of the main JFrame

*/ public Dimension getSize() { return frame.getContentPane().getSize(); } /** - * Updates ServerLauncherGUI according to current profile settings. + * Updates ServerLauncherGUI according to current profile settings */ public void update() { Controller controller = Main.getController(); serversPane.removeAll(); - chckbxmntmRunInBackground.setState(controller.getRunInBackground()); - chckbxmntmDelayStartup.setState(controller.getDelayStartup() > 0); - chckbxmntmDownloadJars.setState(controller.getDownloadAllJars()); - this.targetServer.removeAllItems(); - this.targetServer.addItem("All"); + runInBackgroundCheckBoxMenuItem.setState(controller.getRunInBackground()); + delayStartupCheckBoxMenuItem.setState(controller.getDelayStartup() > 0); + downloadJarsCheckBoxMenuItem.setState(controller.getDownloadAllJars()); + this.targetServerCombo.removeAllItems(); + this.targetServerCombo.addItem("All"); for (Collection collection : controller.getCurrentProfile().getCollections()) { serversPane.addTab(collection.getName(), collection.getServerTab().getPanel()); - this.targetServer.addItem(collection.getName()); + this.targetServerCombo.addItem(collection.getName()); } } /** - * Creates the ServerLauncherGUI, + * Creates the ServerLauncherGUI */ private void initialize(int width, int height) throws IOException { try { @@ -210,32 +230,32 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, JMenu mnOptions = new JMenu("Options"); menuBar.add(mnOptions); - chckbxmntmRunInBackground = new JCheckBoxMenuItem("Run in background on exit"); - mnOptions.add(chckbxmntmRunInBackground); - chckbxmntmRunInBackground.addActionListener(this); + runInBackgroundCheckBoxMenuItem = new JCheckBoxMenuItem("Run in background on exit"); + mnOptions.add(runInBackgroundCheckBoxMenuItem); + runInBackgroundCheckBoxMenuItem.addActionListener(this); - chckbxmntmDelayStartup = new JCheckBoxMenuItem("Delay Startup"); - mnOptions.add(chckbxmntmDelayStartup); - chckbxmntmDelayStartup.addActionListener(this); + delayStartupCheckBoxMenuItem = new JCheckBoxMenuItem("Delay Startup"); + mnOptions.add(delayStartupCheckBoxMenuItem); + delayStartupCheckBoxMenuItem.addActionListener(this); - chckbxmntmDownloadJars = new JCheckBoxMenuItem("Download jars"); - mnOptions.add(chckbxmntmDownloadJars); - chckbxmntmDownloadJars.addActionListener(this); + downloadJarsCheckBoxMenuItem = new JCheckBoxMenuItem("Download jars"); + mnOptions.add(downloadJarsCheckBoxMenuItem); + downloadJarsCheckBoxMenuItem.addActionListener(this); JMenu mnHelp = new JMenu("Help"); menuBar.add(mnHelp); - mntmErrors = new JMenuItem("Errors"); - mnHelp.add(mntmErrors); - mntmErrors.addActionListener(this); + errorsMenuItem = new JMenuItem("Errors"); + mnHelp.add(errorsMenuItem); + errorsMenuItem.addActionListener(this); - mntmSetup = new JMenuItem("Setup"); - mnHelp.add(mntmSetup); - mntmSetup.addActionListener(this); + setupMenuItem = new JMenuItem("Setup"); + mnHelp.add(setupMenuItem); + setupMenuItem.addActionListener(this); - mntmManualUpdate = new JMenuItem("Manual update"); - mnHelp.add(mntmManualUpdate); - mntmManualUpdate.addActionListener(this); + manualUpdateMenuItem = new JMenuItem("Manual update"); + mnHelp.add(manualUpdateMenuItem); + manualUpdateMenuItem.addActionListener(this); JMenu mnInfo = new JMenu("Info"); menuBar.add(mnInfo); @@ -243,28 +263,28 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, JMenu mnOptionsInfo = new JMenu("Options"); mnInfo.add(mnOptionsInfo); - mntmRunInBackground = new JMenuItem("Run in background on exit"); - mnOptionsInfo.add(mntmRunInBackground); - mntmRunInBackground.addActionListener(this); + runInBackgroundMenuItem = new JMenuItem("Run in background on exit"); + mnOptionsInfo.add(runInBackgroundMenuItem); + runInBackgroundMenuItem.addActionListener(this); - mntmDelayStartup = new JMenuItem("Delay Startup"); - mnOptionsInfo.add(mntmDelayStartup); - mntmDelayStartup.addActionListener(this); + delayStartupMenuItem = new JMenuItem("Delay Startup"); + mnOptionsInfo.add(delayStartupMenuItem); + delayStartupMenuItem.addActionListener(this); - mntmDownloadJars = new JMenuItem("Download jars"); - mnOptionsInfo.add(mntmDownloadJars); - mntmDownloadJars.addActionListener(this); + downloadJarsMenuItem = new JMenuItem("Download jars"); + mnOptionsInfo.add(downloadJarsMenuItem); + downloadJarsMenuItem.addActionListener(this); JMenu mnAbout = new JMenu("About"); mnInfo.add(mnAbout); - mntmAbout = new JMenuItem("About"); - mnAbout.add(mntmAbout); - mntmAbout.addActionListener(this); + aboutMenuItem = new JMenuItem("About"); + mnAbout.add(aboutMenuItem); + aboutMenuItem.addActionListener(this); - mntmStory = new JMenuItem("Story"); - mnAbout.add(mntmStory); - mntmStory.addActionListener(this); + storyMenuItem = new JMenuItem("Story"); + mnAbout.add(storyMenuItem); + storyMenuItem.addActionListener(this); tabbedPane = new JTabbedPane(JTabbedPane.TOP); frame.getContentPane().add(tabbedPane); @@ -278,159 +298,159 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, sl_panel.putConstraint(SpringLayout.NORTH, lblBasicControls, 10, SpringLayout.NORTH, panelBasic); panelBasic.add(lblBasicControls); - btnStartServer = new JButton("Start servers"); - sl_panel.putConstraint(SpringLayout.WEST, lblBasicControls, 0, SpringLayout.WEST, btnStartServer); - sl_panel.putConstraint(SpringLayout.NORTH, btnStartServer, 6, SpringLayout.SOUTH, lblBasicControls); - sl_panel.putConstraint(SpringLayout.WEST, btnStartServer, 10, SpringLayout.WEST, panelBasic); - panelBasic.add(btnStartServer); - btnStartServer.addActionListener(this); + startServerButton = new JButton("Start servers"); + sl_panel.putConstraint(SpringLayout.WEST, lblBasicControls, 0, SpringLayout.WEST, startServerButton); + sl_panel.putConstraint(SpringLayout.NORTH, startServerButton, 6, SpringLayout.SOUTH, lblBasicControls); + sl_panel.putConstraint(SpringLayout.WEST, startServerButton, 10, SpringLayout.WEST, panelBasic); + panelBasic.add(startServerButton); + startServerButton.addActionListener(this); - btnStopServer = new JButton("Stop servers"); - sl_panel.putConstraint(SpringLayout.NORTH, btnStopServer, 0, SpringLayout.NORTH, btnStartServer); - sl_panel.putConstraint(SpringLayout.WEST, btnStopServer, 6, SpringLayout.EAST, btnStartServer); - panelBasic.add(btnStopServer); - btnStopServer.addActionListener(this); + stopServerButton = new JButton("Stop servers"); + sl_panel.putConstraint(SpringLayout.NORTH, stopServerButton, 0, SpringLayout.NORTH, startServerButton); + sl_panel.putConstraint(SpringLayout.WEST, stopServerButton, 6, SpringLayout.EAST, startServerButton); + panelBasic.add(stopServerButton); + stopServerButton.addActionListener(this); JLabel lblProfile = new JLabel("Profile"); - sl_panel.putConstraint(SpringLayout.NORTH, lblProfile, 6, SpringLayout.SOUTH, btnStartServer); + sl_panel.putConstraint(SpringLayout.NORTH, lblProfile, 6, SpringLayout.SOUTH, startServerButton); sl_panel.putConstraint(SpringLayout.WEST, lblProfile, 10, SpringLayout.WEST, panelBasic); panelBasic.add(lblProfile); - addProfile = new JButton("+"); - sl_panel.putConstraint(SpringLayout.NORTH, addProfile, 6, SpringLayout.SOUTH, lblProfile); - sl_panel.putConstraint(SpringLayout.WEST, addProfile, 10, SpringLayout.WEST, panelBasic); - panelBasic.add(addProfile); - addProfile.addActionListener(this); + addProfileButton = new JButton("+"); + sl_panel.putConstraint(SpringLayout.NORTH, addProfileButton, 6, SpringLayout.SOUTH, lblProfile); + sl_panel.putConstraint(SpringLayout.WEST, addProfileButton, 10, SpringLayout.WEST, panelBasic); + panelBasic.add(addProfileButton); + addProfileButton.addActionListener(this); - delProfile = new JButton("-"); - sl_panel.putConstraint(SpringLayout.NORTH, delProfile, 0, SpringLayout.NORTH, addProfile); - sl_panel.putConstraint(SpringLayout.WEST, delProfile, 6, SpringLayout.EAST, addProfile); - panelBasic.add(delProfile); - delProfile.addActionListener(this); + deleteProfileButton = new JButton("-"); + sl_panel.putConstraint(SpringLayout.NORTH, deleteProfileButton, 0, SpringLayout.NORTH, addProfileButton); + sl_panel.putConstraint(SpringLayout.WEST, deleteProfileButton, 6, SpringLayout.EAST, addProfileButton); + panelBasic.add(deleteProfileButton); + deleteProfileButton.addActionListener(this); profiles = new JComboBox<>(); - sl_panel.putConstraint(SpringLayout.NORTH, profiles, 0, SpringLayout.NORTH, addProfile); - sl_panel.putConstraint(SpringLayout.WEST, profiles, 6, SpringLayout.EAST, delProfile); - sl_panel.putConstraint(SpringLayout.EAST, profiles, 124, SpringLayout.EAST, delProfile); + sl_panel.putConstraint(SpringLayout.NORTH, profiles, 0, SpringLayout.NORTH, addProfileButton); + sl_panel.putConstraint(SpringLayout.WEST, profiles, 6, SpringLayout.EAST, deleteProfileButton); + sl_panel.putConstraint(SpringLayout.EAST, profiles, 124, SpringLayout.EAST, deleteProfileButton); panelBasic.add(profiles); profiles.addActionListener(this); - sl_panel.putConstraint(SpringLayout.NORTH, lblStatuslabel, 6, SpringLayout.SOUTH, addProfile); + sl_panel.putConstraint(SpringLayout.NORTH, lblStatuslabel, 6, SpringLayout.SOUTH, addProfileButton); sl_panel.putConstraint(SpringLayout.SOUTH, lblStatuslabel, -10, SpringLayout.SOUTH, panelBasic); sl_panel.putConstraint(SpringLayout.WEST, lblStatuslabel, 10, SpringLayout.WEST, panelBasic); sl_panel.putConstraint(SpringLayout.EAST, lblStatuslabel, -10, SpringLayout.EAST, panelBasic); panelBasic.add(lblStatuslabel); - addServer = new JButton("Add server"); - sl_panel.putConstraint(SpringLayout.NORTH, addServer, 0, SpringLayout.NORTH, btnStartServer); - sl_panel.putConstraint(SpringLayout.WEST, addServer, 6, SpringLayout.EAST, btnStopServer); - panelBasic.add(addServer); - addServer.addActionListener(this); + addServerButton = new JButton("Add server"); + sl_panel.putConstraint(SpringLayout.NORTH, addServerButton, 0, SpringLayout.NORTH, startServerButton); + sl_panel.putConstraint(SpringLayout.WEST, addServerButton, 6, SpringLayout.EAST, stopServerButton); + panelBasic.add(addServerButton); + addServerButton.addActionListener(this); - backup = new JButton("Backup"); - sl_panel.putConstraint(SpringLayout.NORTH, backup, 0, SpringLayout.NORTH, btnStartServer); - sl_panel.putConstraint(SpringLayout.WEST, backup, 6, SpringLayout.EAST, addServer); - panelBasic.add(backup); - backup.addActionListener(this); + backupButton = new JButton("Backup"); + sl_panel.putConstraint(SpringLayout.NORTH, backupButton, 0, SpringLayout.NORTH, startServerButton); + sl_panel.putConstraint(SpringLayout.WEST, backupButton, 6, SpringLayout.EAST, addServerButton); + panelBasic.add(backupButton); + backupButton.addActionListener(this); JPanel controlServers = new JPanel(); tabbedPane.addTab("Control servers", null, controlServers, null); SpringLayout sl_panel_1 = new SpringLayout(); controlServers.setLayout(sl_panel_1); - targetServer = new JComboBox<>(); - sl_panel_1.putConstraint(SpringLayout.NORTH, targetServer, 10, SpringLayout.NORTH, controlServers); - controlServers.add(targetServer); - targetServer.addActionListener(this); + targetServerCombo = new JComboBox<>(); + sl_panel_1.putConstraint(SpringLayout.NORTH, targetServerCombo, 10, SpringLayout.NORTH, controlServers); + controlServers.add(targetServerCombo); + targetServerCombo.addActionListener(this); - targetPlayer = new JComboBox<>(); - sl_panel_1.putConstraint(SpringLayout.NORTH, targetPlayer, 6, SpringLayout.SOUTH, targetServer); - targetPlayer.setEditable(true); - controlServers.add(targetPlayer); + targetPlayerCombo = new JComboBox<>(); + sl_panel_1.putConstraint(SpringLayout.NORTH, targetPlayerCombo, 6, SpringLayout.SOUTH, targetServerCombo); + targetPlayerCombo.setEditable(true); + controlServers.add(targetPlayerCombo); - btnKick = new JButton("Kick"); - sl_panel_1.putConstraint(SpringLayout.NORTH, btnKick, 10, SpringLayout.NORTH, controlServers); - sl_panel_1.putConstraint(SpringLayout.WEST, btnKick, 6, SpringLayout.EAST, targetServer); - sl_panel_1.putConstraint(SpringLayout.EAST, btnKick, 104, SpringLayout.WEST, btnKick); - sl_panel_1.putConstraint(SpringLayout.SOUTH, targetServer, 0, SpringLayout.SOUTH, btnKick); - controlServers.add(btnKick); - btnKick.addActionListener(this); + kickButton = new JButton("Kick"); + sl_panel_1.putConstraint(SpringLayout.NORTH, kickButton, 10, SpringLayout.NORTH, controlServers); + sl_panel_1.putConstraint(SpringLayout.WEST, kickButton, 6, SpringLayout.EAST, targetServerCombo); + sl_panel_1.putConstraint(SpringLayout.EAST, kickButton, 104, SpringLayout.WEST, kickButton); + sl_panel_1.putConstraint(SpringLayout.SOUTH, targetServerCombo, 0, SpringLayout.SOUTH, kickButton); + controlServers.add(kickButton); + kickButton.addActionListener(this); - btnBan = new JButton("Ban"); - sl_panel_1.putConstraint(SpringLayout.NORTH, btnBan, 6, SpringLayout.SOUTH, btnKick); - sl_panel_1.putConstraint(SpringLayout.WEST, btnBan, 6, SpringLayout.EAST, targetPlayer); - sl_panel_1.putConstraint(SpringLayout.EAST, btnBan, 104, SpringLayout.WEST, btnBan); - sl_panel_1.putConstraint(SpringLayout.SOUTH, targetPlayer, 0, SpringLayout.SOUTH, btnBan); - controlServers.add(btnBan); - btnBan.addActionListener(this); + banButton = new JButton("Ban"); + sl_panel_1.putConstraint(SpringLayout.NORTH, banButton, 6, SpringLayout.SOUTH, kickButton); + sl_panel_1.putConstraint(SpringLayout.WEST, banButton, 6, SpringLayout.EAST, targetPlayerCombo); + sl_panel_1.putConstraint(SpringLayout.EAST, banButton, 104, SpringLayout.WEST, banButton); + sl_panel_1.putConstraint(SpringLayout.SOUTH, targetPlayerCombo, 0, SpringLayout.SOUTH, banButton); + controlServers.add(banButton); + banButton.addActionListener(this); - btnOp = new JButton("OP"); - sl_panel_1.putConstraint(SpringLayout.NORTH, btnOp, 10, SpringLayout.NORTH, controlServers); - sl_panel_1.putConstraint(SpringLayout.WEST, btnOp, 6, SpringLayout.EAST, btnKick); - sl_panel_1.putConstraint(SpringLayout.EAST, btnOp, -10, SpringLayout.EAST, controlServers); - controlServers.add(btnOp); - btnOp.addActionListener(this); + opButton = new JButton("OP"); + sl_panel_1.putConstraint(SpringLayout.NORTH, opButton, 10, SpringLayout.NORTH, controlServers); + sl_panel_1.putConstraint(SpringLayout.WEST, opButton, 6, SpringLayout.EAST, kickButton); + sl_panel_1.putConstraint(SpringLayout.EAST, opButton, -10, SpringLayout.EAST, controlServers); + controlServers.add(opButton); + opButton.addActionListener(this); - btnDeop = new JButton("DEOP"); - sl_panel_1.putConstraint(SpringLayout.WEST, btnDeop, 6, SpringLayout.EAST, btnBan); - sl_panel_1.putConstraint(SpringLayout.NORTH, btnDeop, 5, SpringLayout.SOUTH, btnOp); - sl_panel_1.putConstraint(SpringLayout.EAST, btnDeop, -10, SpringLayout.EAST, controlServers); - controlServers.add(btnDeop); - btnDeop.addActionListener(this); + deopButton = new JButton("DEOP"); + sl_panel_1.putConstraint(SpringLayout.WEST, deopButton, 6, SpringLayout.EAST, banButton); + sl_panel_1.putConstraint(SpringLayout.NORTH, deopButton, 5, SpringLayout.SOUTH, opButton); + sl_panel_1.putConstraint(SpringLayout.EAST, deopButton, -10, SpringLayout.EAST, controlServers); + controlServers.add(deopButton); + deopButton.addActionListener(this); JLabel lblTargetServer = new JLabel("Target server"); - sl_panel_1.putConstraint(SpringLayout.WEST, targetServer, 6, SpringLayout.EAST, lblTargetServer); - sl_panel_1.putConstraint(SpringLayout.EAST, targetServer, 121, SpringLayout.EAST, lblTargetServer); + sl_panel_1.putConstraint(SpringLayout.WEST, targetServerCombo, 6, SpringLayout.EAST, lblTargetServer); + sl_panel_1.putConstraint(SpringLayout.EAST, targetServerCombo, 121, SpringLayout.EAST, lblTargetServer); sl_panel_1.putConstraint(SpringLayout.NORTH, lblTargetServer, 10, SpringLayout.NORTH, controlServers); - sl_panel_1.putConstraint(SpringLayout.SOUTH, lblTargetServer, 0, SpringLayout.SOUTH, targetServer); + sl_panel_1.putConstraint(SpringLayout.SOUTH, lblTargetServer, 0, SpringLayout.SOUTH, targetServerCombo); sl_panel_1.putConstraint(SpringLayout.WEST, lblTargetServer, 10, SpringLayout.WEST, controlServers); controlServers.add(lblTargetServer); JLabel lblTargetPlayer = new JLabel("Target player"); - sl_panel_1.putConstraint(SpringLayout.WEST, targetPlayer, 7, SpringLayout.EAST, lblTargetPlayer); - sl_panel_1.putConstraint(SpringLayout.EAST, targetPlayer, 122, SpringLayout.EAST, lblTargetPlayer); + sl_panel_1.putConstraint(SpringLayout.WEST, targetPlayerCombo, 7, SpringLayout.EAST, lblTargetPlayer); + sl_panel_1.putConstraint(SpringLayout.EAST, targetPlayerCombo, 122, SpringLayout.EAST, lblTargetPlayer); sl_panel_1.putConstraint(SpringLayout.NORTH, lblTargetPlayer, 6, SpringLayout.SOUTH, lblTargetServer); - sl_panel_1.putConstraint(SpringLayout.SOUTH, lblTargetPlayer, 0, SpringLayout.SOUTH, targetPlayer); + sl_panel_1.putConstraint(SpringLayout.SOUTH, lblTargetPlayer, 0, SpringLayout.SOUTH, targetPlayerCombo); sl_panel_1.putConstraint(SpringLayout.WEST, lblTargetPlayer, 0, SpringLayout.WEST, lblTargetServer); controlServers.add(lblTargetPlayer); - btnCustomCommand = new JButton("Custom command"); - sl_panel_1.putConstraint(SpringLayout.WEST, btnCustomCommand, 250, SpringLayout.WEST, controlServers); - sl_panel_1.putConstraint(SpringLayout.EAST, btnCustomCommand, 0, SpringLayout.EAST, btnOp); - controlServers.add(btnCustomCommand); - btnCustomCommand.addActionListener(this); - frame.getRootPane().setDefaultButton(btnCustomCommand); + customCommandButton = new JButton("Custom command"); + sl_panel_1.putConstraint(SpringLayout.WEST, customCommandButton, 250, SpringLayout.WEST, controlServers); + sl_panel_1.putConstraint(SpringLayout.EAST, customCommandButton, 0, SpringLayout.EAST, opButton); + controlServers.add(customCommandButton); + customCommandButton.addActionListener(this); + frame.getRootPane().setDefaultButton(customCommandButton); - customCommand = new JTextField(); - sl_panel_1.putConstraint(SpringLayout.WEST, customCommand, 10, SpringLayout.WEST, controlServers); - sl_panel_1.putConstraint(SpringLayout.EAST, customCommand, -6, SpringLayout.WEST, btnCustomCommand); - sl_panel_1.putConstraint(SpringLayout.NORTH, btnCustomCommand, 0, SpringLayout.NORTH, customCommand); - sl_panel_1.putConstraint(SpringLayout.SOUTH, customCommand, 0, SpringLayout.SOUTH, btnCustomCommand); - controlServers.add(customCommand); - customCommand.setColumns(10); + customCommandTextField = new JTextField(); + sl_panel_1.putConstraint(SpringLayout.WEST, customCommandTextField, 10, SpringLayout.WEST, controlServers); + sl_panel_1.putConstraint(SpringLayout.EAST, customCommandTextField, -6, SpringLayout.WEST, customCommandButton); + sl_panel_1.putConstraint(SpringLayout.NORTH, customCommandButton, 0, SpringLayout.NORTH, customCommandTextField); + sl_panel_1.putConstraint(SpringLayout.SOUTH, customCommandTextField, 0, SpringLayout.SOUTH, customCommandButton); + controlServers.add(customCommandTextField); + customCommandTextField.setColumns(10); - btnSaveserver = new JButton("Save server"); - sl_panel_1.putConstraint(SpringLayout.NORTH, customCommand, 6, SpringLayout.SOUTH, btnSaveserver); - sl_panel_1.putConstraint(SpringLayout.NORTH, btnSaveserver, 6, SpringLayout.SOUTH, btnBan); - sl_panel_1.putConstraint(SpringLayout.WEST, btnSaveserver, 0, SpringLayout.WEST, btnKick); - sl_panel_1.putConstraint(SpringLayout.EAST, btnSaveserver, 104, SpringLayout.WEST, btnKick); - sl_panel_1.putConstraint(SpringLayout.EAST, btnSaveserver, 104, SpringLayout.WEST, btnKick); - controlServers.add(btnSaveserver); - btnSaveserver.addActionListener(this); + saveServerButton = new JButton("Save server"); + sl_panel_1.putConstraint(SpringLayout.NORTH, customCommandTextField, 6, SpringLayout.SOUTH, saveServerButton); + sl_panel_1.putConstraint(SpringLayout.NORTH, saveServerButton, 6, SpringLayout.SOUTH, banButton); + sl_panel_1.putConstraint(SpringLayout.WEST, saveServerButton, 0, SpringLayout.WEST, kickButton); + sl_panel_1.putConstraint(SpringLayout.EAST, saveServerButton, 104, SpringLayout.WEST, kickButton); + sl_panel_1.putConstraint(SpringLayout.EAST, saveServerButton, 104, SpringLayout.WEST, kickButton); + controlServers.add(saveServerButton); + saveServerButton.addActionListener(this); - btnReload = new JButton("Reload"); - sl_panel_1.putConstraint(SpringLayout.NORTH, btnReload, 6, SpringLayout.SOUTH, btnDeop); - sl_panel_1.putConstraint(SpringLayout.WEST, btnReload, 0, SpringLayout.WEST, btnDeop); - sl_panel_1.putConstraint(SpringLayout.EAST, btnReload, 0, SpringLayout.EAST, btnOp); - controlServers.add(btnReload); - btnReload.addActionListener(this); + reloadButton = new JButton("Reload"); + sl_panel_1.putConstraint(SpringLayout.NORTH, reloadButton, 6, SpringLayout.SOUTH, deopButton); + sl_panel_1.putConstraint(SpringLayout.WEST, reloadButton, 0, SpringLayout.WEST, deopButton); + sl_panel_1.putConstraint(SpringLayout.EAST, reloadButton, 0, SpringLayout.EAST, opButton); + controlServers.add(reloadButton); + reloadButton.addActionListener(this); - btnServerConsoles = new JButton("View server consoles"); - sl_panel_1.putConstraint(SpringLayout.NORTH, btnServerConsoles, 0, SpringLayout.NORTH, btnSaveserver); - sl_panel_1.putConstraint(SpringLayout.WEST, btnServerConsoles, 0, SpringLayout.WEST, lblTargetServer); - sl_panel_1.putConstraint(SpringLayout.EAST, btnServerConsoles, 0, SpringLayout.EAST, targetServer); - controlServers.add(btnServerConsoles); - btnServerConsoles.addActionListener(this); + showConsolesButton = new JButton("View server consoles"); + sl_panel_1.putConstraint(SpringLayout.NORTH, showConsolesButton, 0, SpringLayout.NORTH, saveServerButton); + sl_panel_1.putConstraint(SpringLayout.WEST, showConsolesButton, 0, SpringLayout.WEST, lblTargetServer); + sl_panel_1.putConstraint(SpringLayout.EAST, showConsolesButton, 0, SpringLayout.EAST, targetServerCombo); + controlServers.add(showConsolesButton); + showConsolesButton.addActionListener(this); JPanel panel_2 = new JPanel(); tabbedPane.addTab("Servers", null, panel_2, null); @@ -455,7 +475,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, } /** - * Prepares the system tray if available. + * Prepares the system tray if available */ private void tray() { if (SystemTray.isSupported()) { @@ -535,7 +555,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, } /** - * Hides the gui to the tray, + * Hides the gui to the tray */ public void hide() { frame.setVisible(false); @@ -549,42 +569,42 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, @Override public void actionPerformed(ActionEvent e) { String selectedServerValue = null, selectedPlayerValue = null; - Object selectedServer = targetServer.getSelectedItem(); + Object selectedServer = targetServerCombo.getSelectedItem(); if (selectedServer != null) { selectedServerValue = selectedServer.toString(); } - Object selectedPlayer = targetPlayer.getSelectedItem(); + Object selectedPlayer = targetPlayerCombo.getSelectedItem(); if (selectedPlayer != null) { selectedPlayerValue = selectedPlayer.toString(); } - if (e.getSource() == chckbxmntmRunInBackground) { + if (e.getSource() == runInBackgroundCheckBoxMenuItem) { background(); - } else if (e.getSource() == chckbxmntmDelayStartup) { + } else if (e.getSource() == delayStartupCheckBoxMenuItem) { delay(); - } else if (e.getSource() == chckbxmntmDownloadJars) { + } else if (e.getSource() == downloadJarsCheckBoxMenuItem) { downloadJars(); - } else if (e.getSource() == mntmErrors) { - CommonFunctions.goToURL("https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncherInfo/"); - } else if (e.getSource() == mntmSetup) { - showMessage("Setup", setupText); - } else if (e.getSource() == mntmManualUpdate) { - CommonFunctions.goToURL("https://git.knarcraft.net/KnarCraft/Minecraft-Server-Launcher/releases"); - } else if (e.getSource() == mntmRunInBackground) { - showMessage("Run in background", runInBackgroundText); - } else if (e.getSource() == mntmDelayStartup) { - showMessage("Delay startup", delayStartupText); - } else if (e.getSource() == mntmDownloadJars) { - showMessage("Download jars", downloadJarsText); - } else if (e.getSource() == mntmAbout) { - showMessage("About", aboutText); - } else if (e.getSource() == mntmStory) { - CommonFunctions.goToURL("https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncherStory/"); - } else if (e.getSource() == btnStartServer) { + } else if (e.getSource() == errorsMenuItem) { + CommonFunctions.goToURL(textStrings.get("infoURL")); + } else if (e.getSource() == setupMenuItem) { + showMessage("Setup", textStrings.get("setupText")); + } else if (e.getSource() == manualUpdateMenuItem) { + CommonFunctions.goToURL(textStrings.get("manualUpdateURL")); + } else if (e.getSource() == runInBackgroundMenuItem) { + showMessage("Run in background", textStrings.get("runInBackgroundText")); + } else if (e.getSource() == delayStartupMenuItem) { + showMessage("Delay startup", textStrings.get("delayStartupText")); + } else if (e.getSource() == downloadJarsMenuItem) { + showMessage("Download jars", textStrings.get("downloadJarsText")); + } else if (e.getSource() == aboutMenuItem) { + showMessage("About", textStrings.get("aboutText")); + } else if (e.getSource() == storyMenuItem) { + CommonFunctions.goToURL(textStrings.get("storyURL")); + } else if (e.getSource() == startServerButton) { controller.saveState(); Executors.newSingleThreadExecutor().execute(Server::startServers); - } else if (e.getSource() == btnStopServer) { + } else if (e.getSource() == stopServerButton) { stop(); - } else if (e.getSource() == addServer) { + } else if (e.getSource() == addServerButton) { String serverName = JOptionPane.showInputDialog("Name of server: "); try { controller.getCurrentProfile().addCollection(serverName); @@ -593,12 +613,12 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, } this.update(); controller.getCurrentProfile().updateConsoles(); - } else if (e.getSource() == backup) { + } else if (e.getSource() == backupButton) { CommonFunctions.backup(this); - } else if (e.getSource() == addProfile) { + } else if (e.getSource() == addProfileButton) { controller.addProfile(JOptionPane.showInputDialog("Profile name: ")); updateProfiles(); - } else if (e.getSource() == delProfile) { + } else if (e.getSource() == deleteProfileButton) { Object selected = profiles.getSelectedItem(); if (selected != null) { controller.removeProfile(selected.toString()); @@ -606,60 +626,60 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, } } else if (e.getSource() == profiles) { changeProfile(); - } else if (e.getSource() == btnKick) { + } else if (e.getSource() == kickButton) { if (selectedServerValue != null && selectedPlayerValue != null) { controller.getCurrentProfile().sendCommand(selectedServerValue, "kick " + selectedPlayerValue); } - } else if (e.getSource() == btnBan) { + } else if (e.getSource() == banButton) { if (selectedServerValue != null && selectedPlayerValue != null) { controller.getCurrentProfile().sendCommand(selectedServerValue, "ban " + selectedPlayerValue); } - } else if (e.getSource() == btnOp) { + } else if (e.getSource() == opButton) { if (selectedServerValue != null && selectedPlayerValue != null) { controller.getCurrentProfile().sendCommand(selectedServerValue, "op " + selectedPlayerValue); } - } else if (e.getSource() == btnDeop) { + } else if (e.getSource() == deopButton) { if (selectedServerValue != null && selectedPlayerValue != null) { controller.getCurrentProfile().sendCommand(selectedServerValue, "deop " + selectedPlayerValue); } - } else if (e.getSource() == btnCustomCommand) { + } else if (e.getSource() == customCommandButton) { if (selectedServerValue != null) { - controller.getCurrentProfile().sendCommand(selectedServerValue, customCommand.getText()); - customCommand.setText(""); + controller.getCurrentProfile().sendCommand(selectedServerValue, customCommandTextField.getText()); + customCommandTextField.setText(""); } - } else if (e.getSource() == btnSaveserver) { + } else if (e.getSource() == saveServerButton) { if (selectedServerValue != null) { controller.getCurrentProfile().sendCommand(selectedServerValue, "save-all"); } - } else if (e.getSource() == btnReload) { + } else if (e.getSource() == reloadButton) { if (selectedServerValue != null) { controller.getCurrentProfile().sendCommand(selectedServerValue, "reload"); } - } else if (e.getSource() == btnServerConsoles) { + } else if (e.getSource() == showConsolesButton) { ServerConsoles.setAsVisible(); - } else if (e.getSource() == targetServer) { + } else if (e.getSource() == targetServerCombo) { updatePlayers(); } } /** - * Updates the ServerLauncherGUI components to block a user from doing illegal actions. + * Updates the ServerLauncherGUI components to block a user from doing illegal actions * - * @param running Are the servers currently running? + * @param running

Whether the servers are currently running

*/ public void updateRunning(boolean running) { boolean stopped = !running; //Most gui is only enabled when the server is stopped rather than running. profiles.setEnabled(stopped); - addProfile.setEnabled(stopped); - delProfile.setEnabled(stopped); - btnStartServer.setEnabled(stopped); - addServer.setEnabled(stopped); + addProfileButton.setEnabled(stopped); + deleteProfileButton.setEnabled(stopped); + startServerButton.setEnabled(stopped); + addServerButton.setEnabled(stopped); tabbedPane.setEnabledAt(2, stopped); - btnStopServer.setEnabled(running); + stopServerButton.setEnabled(running); } /** - * Saves the previous profile and loads data from the new profile. + * Saves the previous profile and loads data from the new profile */ private void changeProfile() { controller.saveState(); @@ -685,16 +705,16 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, } /** - * Asks the user for a delay if checked, and sets the value to the current profile. + * Asks the user for a delay if checked, and sets the value to the current profile */ private void delay() { Object selected = profiles.getSelectedItem(); if (selected != null) { Profile profile = controller.getProfileByName(selected.toString()); - if (chckbxmntmDelayStartup.isSelected()) { + if (delayStartupCheckBoxMenuItem.isSelected()) { String response = JOptionPane.showInputDialog("Seconds to delay: "); if (response == null) { - chckbxmntmDelayStartup.setState(false); + delayStartupCheckBoxMenuItem.setState(false); return; } int parsed = Integer.parseInt(response); @@ -708,76 +728,62 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener, } /** - * Saves the runInBackground setting to the current profile. + * Saves the runInBackground setting to the current profile */ private void background() { Object selected = profiles.getSelectedItem(); if (selected != null) { Profile profile = controller.getProfileByName(selected.toString()); - Objects.requireNonNull(profile).setRunInBackground(chckbxmntmRunInBackground.isSelected()); + Objects.requireNonNull(profile).setRunInBackground(runInBackgroundCheckBoxMenuItem.isSelected()); } else { showError("No profile selected"); } } /** - * Saves the downloadJars setting to the current profile. + * Saves the downloadJars setting to the current profile */ private void downloadJars() { Object selected = profiles.getSelectedItem(); if (selected != null) { - controller.setDownloadAllJars(chckbxmntmDownloadJars.isSelected()); + controller.setDownloadAllJars(downloadJarsCheckBoxMenuItem.isSelected()); } else { showError("No profile selected"); } } /** - * Updates the list of players currently online on the selected server, + * Updates the list of players currently online on the selected server */ private void updatePlayers() { String selectedServerValue; - Object selectedServer = targetServer.getSelectedItem(); + Object selectedServer = targetServerCombo.getSelectedItem(); if (selectedServer != null) { - targetPlayer.removeAllItems(); + targetPlayerCombo.removeAllItems(); selectedServerValue = selectedServer.toString(); if (selectedServerValue.equals("All")) { for (String player : this.globalPlayers) { - targetPlayer.addItem(player); + targetPlayerCombo.addItem(player); } } else { for (String player : controller.getCurrentProfile().getCollection(selectedServerValue).getServer().getPlayers()) { - targetPlayer.addItem(player); + targetPlayerCombo.addItem(player); } } } } /** - * Loads popup messages from a text file. + * Loads popup messages from a text file */ private void loadMessages() throws FileNotFoundException { + textStrings = new HashMap<>(); Scanner file = getResourceAsScanner("menumsg.csv"); while (file.hasNextLine()) { String nextLine = file.nextLine(); String[] line = nextLine.split("="); String content = line[1].replaceAll("_BREAK_", System.getProperty("line.separator")); - switch (line[0]) { - case "setup": - setupText = content; - break; - case "runinbk": - runInBackgroundText = content; - break; - case "delaystartup": - delayStartupText = content; - break; - case "downloadjars": - downloadJarsText = content; - break; - case "about": - aboutText = content; - } + textStrings.put(line[0], content); } } } diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/utility/CommonFunctions.java b/src/main/java/net/knarcraft/minecraftserverlauncher/utility/CommonFunctions.java index 824efd3..bccd556 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/utility/CommonFunctions.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/utility/CommonFunctions.java @@ -4,6 +4,7 @@ import net.knarcraft.minecraftserverlauncher.Main; import net.knarcraft.minecraftserverlauncher.profile.Collection; import net.knarcraft.minecraftserverlauncher.server.Server; import net.knarcraft.minecraftserverlauncher.userinterface.GUI; +import net.knarcraft.minecraftserverlauncher.userinterface.WebBrowser; import java.io.*; import java.net.URI; @@ -181,8 +182,8 @@ public final class CommonFunctions { java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); try { desktop.browse(new URI(url)); - } catch (URISyntaxException | IOException e1) { - e1.printStackTrace(); + } catch (URISyntaxException | IOException | UnsupportedOperationException e1) { + WebBrowser.displayPage(url); } }