Adds missing comments, simplifies proxy distinction, moves updating to own class and fixes formatting
This commit is contained in:
@ -17,9 +17,9 @@ import static javax.swing.text.DefaultCaret.ALWAYS_UPDATE;
|
||||
* Acts as a single writable/readable tab
|
||||
* Has a box for user input, and a textArea for server output.
|
||||
*
|
||||
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class Console implements ActionListener, KeyListener {
|
||||
private final JTextField textInput;
|
||||
@ -55,7 +55,7 @@ public class Console implements ActionListener, KeyListener {
|
||||
/**
|
||||
* Prints a string to the textArea.
|
||||
*
|
||||
* @param text The text to print
|
||||
* @param text The text to print
|
||||
*/
|
||||
public void output(String text) {
|
||||
this.textOutput.setText(this.textOutput.getText() + "\n" + text);
|
||||
|
@ -15,7 +15,7 @@ public interface GUI {
|
||||
/**
|
||||
* Displays an error to the user as an independent box
|
||||
*
|
||||
* @param title <p>The title of the error message</p>
|
||||
* @param title <p>The title of the error message</p>
|
||||
* @param message <p>The error message contents</p>
|
||||
*/
|
||||
void showError(String title, String message);
|
||||
@ -30,7 +30,7 @@ public interface GUI {
|
||||
/**
|
||||
* Displays a message to the user as an independent box
|
||||
*
|
||||
* @param title <p>The title of the message</p>
|
||||
* @param title <p>The title of the message</p>
|
||||
* @param message <p>The message contents</p>
|
||||
*/
|
||||
void showMessage(String title, String message);
|
||||
|
@ -46,8 +46,8 @@ public abstract class MessageHandler implements GUI {
|
||||
/**
|
||||
* Shows a JOptionPane
|
||||
*
|
||||
* @param title <p>The title of the pane</p>
|
||||
* @param message <p>The message of the pane</p>
|
||||
* @param title <p>The title of the pane</p>
|
||||
* @param message <p>The message of the pane</p>
|
||||
* @param paneType <p>The type of the pane</p>
|
||||
*/
|
||||
private void showJOptionPane(String title, String message, int paneType) {
|
||||
|
@ -1,17 +1,16 @@
|
||||
package net.knarcraft.minecraftserverlauncher.userinterface;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JTabbedPane;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* A parent window for server consoles.
|
||||
* Should be toggled with the "View server consoles" button.
|
||||
* Keeps track of all consoles.
|
||||
*
|
||||
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class ServerConsoles {
|
||||
private static JFrame frame;
|
||||
@ -30,6 +29,7 @@ public class ServerConsoles {
|
||||
|
||||
/**
|
||||
* Adds a new console tab
|
||||
*
|
||||
* @param name <p>The name of the consoles tab</p>
|
||||
* @return <p>A new console element with the new tabbed pane</p>
|
||||
*/
|
||||
@ -46,6 +46,7 @@ public class ServerConsoles {
|
||||
|
||||
/**
|
||||
* Returns the tabbed pane containing the server consoles
|
||||
*
|
||||
* @return <p>A tabbed pane</p>
|
||||
*/
|
||||
public static JTabbedPane getTabbedPane() {
|
||||
|
@ -1,17 +1,26 @@
|
||||
package net.knarcraft.minecraftserverlauncher.userinterface;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
||||
import net.knarcraft.minecraftserverlauncher.Main;
|
||||
import net.knarcraft.minecraftserverlauncher.server.Server;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Profile;
|
||||
import net.knarcraft.minecraftserverlauncher.server.Server;
|
||||
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Scanner;
|
||||
@ -25,12 +34,14 @@ import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.getR
|
||||
/**
|
||||
* Generates a ServerLauncherGUI.
|
||||
*
|
||||
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class ServerLauncherGUI extends MessageHandler implements ActionListener, GUI {
|
||||
|
||||
private final JLabel lblStatuslabel = new JLabel("Servers are stopped");
|
||||
private final ArrayList<String> globalPlayers;
|
||||
private JFrame frame;
|
||||
private JTabbedPane tabbedPane;
|
||||
private JTabbedPane serversPane;
|
||||
@ -42,7 +53,6 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
//Basic controls
|
||||
private JButton btnStartServer, btnStopServer, addServer, backup, addProfile, delProfile;
|
||||
private JComboBox<String> profiles;
|
||||
private final JLabel lblStatuslabel = new JLabel("Servers are stopped");
|
||||
//Server controls
|
||||
private JComboBox<String> targetServer;
|
||||
private JComboBox<String> targetPlayer;
|
||||
@ -54,8 +64,6 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
private String delayStartupText;
|
||||
private String downloadJarsText;
|
||||
private String aboutText;
|
||||
|
||||
private final ArrayList<String> globalPlayers;
|
||||
private SystemTray tray;
|
||||
private TrayIcon trayIcon;
|
||||
|
||||
@ -71,7 +79,8 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
|
||||
/**
|
||||
* Creates the application window with a preferred width and height
|
||||
* @param width <p>The preferred width</p>
|
||||
*
|
||||
* @param width <p>The preferred width</p>
|
||||
* @param height <p>The preferred height</p>
|
||||
*/
|
||||
public ServerLauncherGUI(int width, int height) throws IOException {
|
||||
@ -84,7 +93,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
/**
|
||||
* Gets the pane used for server configurations
|
||||
*
|
||||
* @return A JTabbedPane
|
||||
* @return A JTabbedPane
|
||||
*/
|
||||
public JTabbedPane getPane() {
|
||||
return this.serversPane;
|
||||
@ -95,7 +104,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
this.lblStatuslabel.setText(text);
|
||||
try (PrintWriter file = new PrintWriter(new FileWriter(Main.getApplicationWorkDirectory() + File.separator + "latestrun.log", true))) {
|
||||
file.println(text);
|
||||
} catch (IOException e ) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -103,7 +112,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
/**
|
||||
* Adds a player to the global playerlist, 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);
|
||||
@ -113,7 +122,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
/**
|
||||
* 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));
|
||||
@ -133,7 +142,7 @@ 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 frame
|
||||
*/
|
||||
public Dimension getSize() {
|
||||
return frame.getContentPane().getSize();
|
||||
@ -439,7 +448,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
PopupMenu popup = new PopupMenu();
|
||||
trayIcon = new TrayIcon(trayImage, "Minecraft Server Launcher", popup);
|
||||
trayIcon.setImageAutoSize(true);
|
||||
ActionListener exitListener= e -> {
|
||||
ActionListener exitListener = e -> {
|
||||
stop();
|
||||
try {
|
||||
Profile.getCurrent().save();
|
||||
@ -491,7 +500,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
trayIcon.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if(e.getClickCount() >= 1 && e.getButton() == MouseEvent.BUTTON1){
|
||||
if (e.getClickCount() >= 1 && e.getButton() == MouseEvent.BUTTON1) {
|
||||
frame.setExtendedState(NORMAL);
|
||||
tray.remove(trayIcon);
|
||||
frame.setVisible(true);
|
||||
@ -560,12 +569,12 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
} else if (e.getSource() == mntmStory) {
|
||||
CommonFunctions.goToURL("https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncherStory/");
|
||||
} else if (e.getSource() == btnStartServer) {
|
||||
try {
|
||||
Profile.getCurrent().save();
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
Executors.newSingleThreadExecutor().execute(Server::startServers);
|
||||
try {
|
||||
Profile.getCurrent().save();
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
Executors.newSingleThreadExecutor().execute(Server::startServers);
|
||||
} else if (e.getSource() == btnStopServer) {
|
||||
stop();
|
||||
} else if (e.getSource() == addServer) {
|
||||
@ -589,11 +598,11 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
updateProfiles();
|
||||
}
|
||||
} else if (e.getSource() == profiles) {
|
||||
try {
|
||||
changeProfile();
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
changeProfile();
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} else if (e.getSource() == btnKick) {
|
||||
if (selectedServerValue != null && selectedPlayerValue != null) {
|
||||
Profile.getCurrent().sendCommand(selectedServerValue, "kick " + selectedPlayerValue);
|
||||
@ -633,7 +642,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
/**
|
||||
* Updates the ServerLauncherGUI components to block a user from doing illegal actions.
|
||||
*
|
||||
* @param running Are the servers currently running?
|
||||
* @param running Are the servers currently running?
|
||||
*/
|
||||
public void updateRunning(boolean running) {
|
||||
boolean stopped = !running; //Most gui is only enabled when the server is stopped rather than running.
|
||||
|
@ -2,8 +2,8 @@ package net.knarcraft.minecraftserverlauncher.userinterface;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Profile;
|
||||
import net.knarcraft.minecraftserverlauncher.server.Server;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
|
||||
import net.knarcraft.minecraftserverlauncher.server.ServerTypeHandler;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.swing.*;
|
||||
@ -14,9 +14,9 @@ import java.awt.event.ActionListener;
|
||||
* Contains all buttons for configuring a server.
|
||||
* Does some visual stuff by itself, but otherwise reads user inputs.
|
||||
*
|
||||
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class ServerTab implements ActionListener {
|
||||
private final JComboBox<String> serverTypes, serverVersions, maxRam;
|
||||
@ -26,24 +26,6 @@ public class ServerTab implements ActionListener {
|
||||
private final JPanel panel;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public void setData(String path, boolean enabled, String typeName, String serverVersion, String maxRam) throws ConfigurationException {
|
||||
this.directory.setText(path);
|
||||
this.chckbxEnabled.setSelected(enabled);
|
||||
this.serverTypes.setSelectedItem(typeName);
|
||||
this.serverTypes();
|
||||
this.serverVersions.setSelectedItem(serverVersion);
|
||||
this.maxRam.setSelectedItem(maxRam);
|
||||
}
|
||||
|
||||
public ServerTab(String name) throws ConfigurationException {
|
||||
this.name = name;
|
||||
panel = new JPanel();
|
||||
@ -129,6 +111,24 @@ public class ServerTab implements ActionListener {
|
||||
btnBrowse.addActionListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public void setData(String path, boolean enabled, String typeName, String serverVersion, String maxRam) throws ConfigurationException {
|
||||
this.directory.setText(path);
|
||||
this.chckbxEnabled.setSelected(enabled);
|
||||
this.serverTypes.setSelectedItem(typeName);
|
||||
this.serverTypes();
|
||||
this.serverVersions.setSelectedItem(serverVersion);
|
||||
this.maxRam.setSelectedItem(maxRam);
|
||||
}
|
||||
|
||||
public JPanel getPanel() {
|
||||
return this.panel;
|
||||
}
|
||||
@ -158,7 +158,7 @@ public class ServerTab implements ActionListener {
|
||||
/**
|
||||
* Gets the selected version from the serverVersion combo
|
||||
*
|
||||
* @return The combo value, or defaults to "Latest" on null
|
||||
* @return The combo value, or defaults to "Latest" on null
|
||||
*/
|
||||
public String getVersion() {
|
||||
Object selected = this.serverVersions.getSelectedItem();
|
||||
@ -172,7 +172,7 @@ public class ServerTab implements ActionListener {
|
||||
/**
|
||||
* Checks if the server is enabled
|
||||
*
|
||||
* @return True if the checkbox is checked. False otherwise.
|
||||
* @return True if the checkbox is checked. False otherwise.
|
||||
*/
|
||||
public boolean enabled() {
|
||||
return this.chckbxEnabled.isSelected();
|
||||
|
Reference in New Issue
Block a user