Better code and comments
This commit is contained in:
@ -52,6 +52,11 @@ public class Console implements ActionListener, KeyListener {
|
||||
return this.panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a string to the textArea.
|
||||
*
|
||||
* @param text The text to print
|
||||
*/
|
||||
public void output(String text) {
|
||||
this.textOutput.setText(this.textOutput.getText() + "\n" + text);
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
|
||||
public class GUI implements ActionListener {
|
||||
|
||||
private JFrame frame;
|
||||
private JTabbedPane tabbedPane;
|
||||
private JTabbedPane serversPane;
|
||||
//Menu
|
||||
private JCheckBoxMenuItem chckbxmntmRunInBackground, chckbxmntmDelayStartup, chckbxmntmDownloadJars; //Options
|
||||
private JMenuItem mntmErrors, mntmSetup, mntmManualUpdate; //Help
|
||||
@ -51,13 +53,9 @@ public class GUI implements ActionListener {
|
||||
private String aboutText;
|
||||
|
||||
private final ArrayList<String> globalPlayers;
|
||||
|
||||
private JTabbedPane serversPane;
|
||||
|
||||
private SystemTray tray;
|
||||
private TrayIcon trayIcon;
|
||||
|
||||
|
||||
/**
|
||||
* Create the application window.
|
||||
*/
|
||||
@ -67,25 +65,51 @@ public class GUI implements ActionListener {
|
||||
this.globalPlayers = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the application window with a preferred width and height.
|
||||
*
|
||||
* @param width The preferred width
|
||||
* @param height The preferred height
|
||||
*/
|
||||
public GUI(int width, int height) {
|
||||
initialize(width, height);
|
||||
loadMessages();
|
||||
this.globalPlayers = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pane used for server configurations
|
||||
*
|
||||
* @return A JTabbedPane
|
||||
*/
|
||||
public JTabbedPane getPane() {
|
||||
return this.serversPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text of the status label.
|
||||
*
|
||||
* @param text The new text
|
||||
*/
|
||||
public void setStatus(String text) {
|
||||
this.lblStatuslabel.setText(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to the global playerlist, and updates the players combo.
|
||||
*
|
||||
* @param name The name of the player to add
|
||||
*/
|
||||
public void addPlayer(String name) {
|
||||
this.globalPlayers.add(name);
|
||||
this.updatePlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from the global list of players.
|
||||
*
|
||||
* @param name The name of the player to remove.
|
||||
*/
|
||||
public void removePlayer(String name) {
|
||||
for (int i = 0; i < this.globalPlayers.size(); i++) {
|
||||
if (this.globalPlayers.get(i).equals(name)) {
|
||||
@ -95,6 +119,9 @@ public class GUI implements ActionListener {
|
||||
this.updatePlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the profiles combo.
|
||||
*/
|
||||
public void updateProfiles() {
|
||||
this.profiles.removeAllItems();
|
||||
for (Profile profile : Profile.getProfiles()) {
|
||||
@ -102,12 +129,17 @@ public class GUI implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the main JFrame
|
||||
*
|
||||
* @return The Dimension of the frame
|
||||
*/
|
||||
public Dimension getSize() {
|
||||
return frame.getContentPane().getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates GUI according to current settings.
|
||||
* Updates GUI according to current profile settings.
|
||||
*/
|
||||
public void update() {
|
||||
serversPane.removeAll();
|
||||
@ -211,7 +243,7 @@ public class GUI implements ActionListener {
|
||||
mnAbout.add(mntmStory);
|
||||
mntmStory.addActionListener(this);
|
||||
|
||||
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
frame.getContentPane().add(tabbedPane);
|
||||
|
||||
JPanel panelBasic = new JPanel();
|
||||
@ -396,6 +428,7 @@ public class GUI implements ActionListener {
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
tray();
|
||||
updateRunning(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -620,18 +653,20 @@ public class GUI implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void running() {
|
||||
profiles.setEnabled(false);
|
||||
addProfile.setEnabled(false);
|
||||
delProfile.setEnabled(false);
|
||||
btnStartServer.setEnabled(false);
|
||||
}
|
||||
|
||||
public void stopped() {
|
||||
profiles.setEnabled(true);
|
||||
addProfile.setEnabled(true);
|
||||
delProfile.setEnabled(true);
|
||||
btnStartServer.setEnabled(true);
|
||||
/**
|
||||
* Updates the GUI components to block a user from doing illegal actions.
|
||||
*
|
||||
* @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.
|
||||
profiles.setEnabled(stopped);
|
||||
addProfile.setEnabled(stopped);
|
||||
delProfile.setEnabled(stopped);
|
||||
btnStartServer.setEnabled(stopped);
|
||||
addServer.setEnabled(stopped);
|
||||
tabbedPane.setEnabledAt(2, stopped);
|
||||
btnStopServer.setEnabled(running);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -652,9 +687,8 @@ public class GUI implements ActionListener {
|
||||
*/
|
||||
private void stop() {
|
||||
try {
|
||||
setStatus("Servers are stopping");
|
||||
setStatus("Servers are stopping...");
|
||||
Server.stop();
|
||||
setStatus("Servers are stopped");
|
||||
} catch (IOException e1) {
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
@ -758,6 +792,7 @@ public class GUI implements ActionListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setStatus("Backup finished");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -845,11 +880,11 @@ public class GUI implements ActionListener {
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
this.setStatus("File copied from " + src + " to " + dest);
|
||||
this.setStatus("Copied file " + src);
|
||||
} else {
|
||||
if(!dest.exists()){
|
||||
if (dest.mkdir()) {
|
||||
this.setStatus("Directory copied from " + src + " to " + dest);
|
||||
this.setStatus("Copied directory " + src);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ public class ServerConsoles {
|
||||
frame = new JFrame();
|
||||
frame.setBounds(100, 100, 450, 300);
|
||||
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
|
||||
consolesTab = new JTabbedPane(JTabbedPane.TOP);
|
||||
frame.getContentPane().add(consolesTab, BorderLayout.CENTER);
|
||||
}
|
||||
|
@ -24,6 +24,15 @@ 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) {
|
||||
this.directory.setText(path);
|
||||
this.chckbxEnabled.setSelected(enabled);
|
||||
@ -144,6 +153,11 @@ public class ServerTab implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the selected version from the serverVersion combo
|
||||
*
|
||||
* @return The combo value, or defaults to "Latest" on null
|
||||
*/
|
||||
public String getVersion() {
|
||||
Object selected = this.serverVersions.getSelectedItem();
|
||||
if (selected != null) {
|
||||
@ -153,6 +167,11 @@ public class ServerTab implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the server is enabled
|
||||
*
|
||||
* @return True if the checkbox is checked. False otherwise.
|
||||
*/
|
||||
public boolean enabled() {
|
||||
return this.chckbxEnabled.isSelected();
|
||||
}
|
||||
@ -168,12 +187,19 @@ public class ServerTab implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the collection containing this ServerTab, and updates everything necessary.
|
||||
*/
|
||||
private void remove() {
|
||||
Profile.getCurrent().removeCollection(name);
|
||||
Profile.getCurrent().removeCollection(this.name);
|
||||
Profile.getGUI().update();
|
||||
Profile.getCurrent().updateConsoles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks the user for the server folder.
|
||||
* Sets the directory input's value if successful.
|
||||
*/
|
||||
private void browse() {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setCurrentDirectory(new java.io.File("/"));
|
||||
@ -185,6 +211,9 @@ public class ServerTab implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the versions combo according to the value of the server type combo.
|
||||
*/
|
||||
private void serverTypes() {
|
||||
serverVersions.removeAllItems();
|
||||
String selectedserverTypes = null;
|
||||
|
Reference in New Issue
Block a user