More gui buttons work in theory
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package net.knarcraft.serverlauncher.userinterface;
|
||||
|
||||
import net.knarcraft.serverlauncher.server.Server;
|
||||
import net.knarcraft.serverlauncher.server.ServerType;
|
||||
import net.knarcraft.serverlauncher.profile.Profile;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -25,6 +24,8 @@ import java.util.Scanner;
|
||||
*/
|
||||
public class GUI implements ActionListener {
|
||||
|
||||
private static GUI gui;
|
||||
|
||||
private JFrame frame;
|
||||
|
||||
//Menu
|
||||
@ -50,7 +51,7 @@ public class GUI implements ActionListener {
|
||||
|
||||
private JTabbedPane serversPane;
|
||||
|
||||
private ArrayList<ServerTab> serverTabs = new ArrayList<>();
|
||||
private final ArrayList<ServerTab> serverTabs = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Create the application.
|
||||
@ -58,7 +59,7 @@ public class GUI implements ActionListener {
|
||||
public GUI() {
|
||||
initialize();
|
||||
loadMessages();
|
||||
Server.setGui(this);
|
||||
gui = this;
|
||||
}
|
||||
|
||||
public JFrame getFrame() {
|
||||
@ -89,6 +90,10 @@ public class GUI implements ActionListener {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static GUI getGUI() {
|
||||
return gui;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a server's tab, removes it from the list of tabs, and removes the server from Profile.java
|
||||
*
|
||||
@ -377,6 +382,16 @@ public class GUI implements ActionListener {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String selectedServerValue = null, selectedPlayerValue = null;
|
||||
Object selectedServer = targetServer.getSelectedItem();
|
||||
if (selectedServer != null) {
|
||||
selectedServerValue = selectedServer.toString();
|
||||
}
|
||||
Object selectedPlayer = targetPlayer.getSelectedItem();
|
||||
if (selectedPlayer != null) {
|
||||
selectedPlayerValue = selectedPlayer.toString();
|
||||
}
|
||||
|
||||
if (e.getSource() == chckbxmntmRunInBackground) {
|
||||
background();
|
||||
} else if (e.getSource() == chckbxmntmDelayStartup) {
|
||||
@ -406,7 +421,11 @@ public class GUI implements ActionListener {
|
||||
stop();
|
||||
} else if (e.getSource() == addServer) {
|
||||
String serverName = JOptionPane.showInputDialog("Name of server: ");
|
||||
new Server(serverName, this);
|
||||
if (!serverName.equals("") && !currentProfile().serverExists(serverName)) {
|
||||
new Server(serverName, this);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "A servername must my unique and not empty.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} else if (e.getSource() == backup) {
|
||||
backup();
|
||||
} else if (e.getSource() == addProfile) {
|
||||
@ -416,13 +435,37 @@ public class GUI implements ActionListener {
|
||||
if (selected != null) {
|
||||
Profile.deleteProfile(selected.toString());
|
||||
}
|
||||
} else if (e.getSource() == btnKick) {
|
||||
if (selectedServerValue != null && selectedPlayerValue != null) {
|
||||
currentProfile().sendCommand(selectedServerValue, "kick " + selectedPlayerValue);
|
||||
}
|
||||
} else if (e.getSource() == btnBan) {
|
||||
if (selectedServerValue != null && selectedPlayerValue != null) {
|
||||
currentProfile().sendCommand(selectedServerValue, "ban " + selectedPlayerValue);
|
||||
}
|
||||
} else if (e.getSource() == btnOp) {
|
||||
if (selectedServerValue != null && selectedPlayerValue != null) {
|
||||
currentProfile().sendCommand(selectedServerValue, "op " + selectedPlayerValue);
|
||||
}
|
||||
} else if (e.getSource() == btnDeop) {
|
||||
if (selectedServerValue != null && selectedPlayerValue != null) {
|
||||
currentProfile().sendCommand(selectedServerValue, "deop " + selectedPlayerValue);
|
||||
}
|
||||
} else if (e.getSource() == btnCustomCommand) {
|
||||
if (selectedServerValue != null) {
|
||||
currentProfile().sendCommand(selectedServerValue, customCommand.getSelectedText());
|
||||
}
|
||||
} else if (e.getSource() == btnSaveserver) {
|
||||
if (selectedServerValue != null) {
|
||||
currentProfile().sendCommand(selectedServerValue, "save-all");
|
||||
}
|
||||
} else if (e.getSource() == btnReload) {
|
||||
if (selectedServerValue != null) {
|
||||
currentProfile().sendCommand(selectedServerValue, "reload");
|
||||
}
|
||||
} else if (e.getSource() == btnServerConsoles) {
|
||||
//TODO: Make server consoles window, and toggle visibility on this action.
|
||||
}
|
||||
/*
|
||||
//Server controls
|
||||
private JComboBox targetServer, targetPlayer;
|
||||
private JButton btnKick, btnBan, btnOp, btnDeop, btnCustomCommand, btnSaveserver, btnReload, btnServerConsoles;
|
||||
private JTextField customCommand;*/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -441,7 +484,7 @@ public class GUI implements ActionListener {
|
||||
Server.stop();
|
||||
setStatus("Servers are stopped");
|
||||
} catch (IOException e1) {
|
||||
JOptionPane.showMessageDialog(null, "Could not stop server", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
JOptionPane.showMessageDialog(null, "Could not stop server.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,16 +7,19 @@ import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class ServerTab implements ActionListener {
|
||||
private JComboBox<String> serverTypes, serverVersions, maxRam;
|
||||
private JCheckBox chckbxEnabled;
|
||||
private JButton btnRemoveServer, btnBrowse;
|
||||
private JTextField directory;
|
||||
class ServerTab implements ActionListener {
|
||||
private final JComboBox<String> serverTypes;
|
||||
private final JComboBox<String> serverVersions;
|
||||
private final JComboBox<String> maxRam;
|
||||
private final JCheckBox chckbxEnabled;
|
||||
private final JButton btnRemoveServer;
|
||||
private final JButton btnBrowse;
|
||||
private final JTextField directory;
|
||||
|
||||
|
||||
public ServerTab(String name) {
|
||||
JPanel panel = new JPanel();
|
||||
Server.getGUI().getPane().addTab(name, null, panel, null);
|
||||
GUI.getGUI().getPane().addTab(name, null, panel, null);
|
||||
SpringLayout sl_panel_3 = new SpringLayout();
|
||||
panel.setLayout(sl_panel_3);
|
||||
|
||||
@ -100,9 +103,16 @@ public class ServerTab implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getSource() == btnRemoveServer) {
|
||||
Server.getGUI().removeServer(this);
|
||||
GUI.getGUI().removeServer(this);
|
||||
} else if (e.getSource() == btnBrowse) {
|
||||
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setCurrentDirectory(new java.io.File("/"));
|
||||
chooser.setDialogTitle("Backup folder");
|
||||
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
chooser.setAcceptAllFileFilterUsed(false);
|
||||
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
directory.setText(chooser.getSelectedFile().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user