2018-01-29 20:14:17 +01:00
|
|
|
package net.knarcraft.serverlauncher.userinterface;
|
|
|
|
|
|
|
|
import net.knarcraft.serverlauncher.server.Server;
|
|
|
|
import net.knarcraft.serverlauncher.server.ServerType;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
2018-01-30 19:46:14 +01:00
|
|
|
/**
|
|
|
|
* Contains all buttons for configuring a server
|
|
|
|
* Does some visual stuff by itself, but otherwise reads boxes and stuff
|
|
|
|
*
|
|
|
|
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
|
|
|
* @version 0.0.0.1
|
|
|
|
* @since 0.0.0.1
|
|
|
|
*/
|
2018-01-30 17:14:29 +01:00
|
|
|
public class ServerTab implements ActionListener {
|
2018-01-30 19:46:14 +01:00
|
|
|
private final JComboBox<String> serverTypes, serverVersions, maxRam;
|
2018-01-30 00:44:03 +01:00
|
|
|
private final JCheckBox chckbxEnabled;
|
2018-01-30 19:46:14 +01:00
|
|
|
private final JButton btnRemoveServer, btnBrowse;
|
2018-01-30 00:44:03 +01:00
|
|
|
private final JTextField directory;
|
2018-01-29 20:14:17 +01:00
|
|
|
|
|
|
|
public ServerTab(String name) {
|
|
|
|
JPanel panel = new JPanel();
|
2018-01-30 00:44:03 +01:00
|
|
|
GUI.getGUI().getPane().addTab(name, null, panel, null);
|
2018-01-29 20:14:17 +01:00
|
|
|
SpringLayout sl_panel_3 = new SpringLayout();
|
|
|
|
panel.setLayout(sl_panel_3);
|
|
|
|
|
|
|
|
JLabel lblServerType = new JLabel("Server type");
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.NORTH, lblServerType, 10, SpringLayout.NORTH, panel);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.WEST, lblServerType, 10, SpringLayout.WEST, panel);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.SOUTH, lblServerType, 30, SpringLayout.NORTH, panel);
|
|
|
|
panel.add(lblServerType);
|
|
|
|
|
|
|
|
JLabel lblServerVersion = new JLabel("Server version");
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.NORTH, lblServerVersion, 6, SpringLayout.SOUTH, lblServerType);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.WEST, lblServerVersion, 10, SpringLayout.WEST, panel);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.SOUTH, lblServerVersion, 26, SpringLayout.SOUTH, lblServerType);
|
|
|
|
panel.add(lblServerVersion);
|
|
|
|
|
2018-01-30 23:34:25 +01:00
|
|
|
serverTypes = new JComboBox<>(ServerType.getTypeNames());
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.NORTH, serverTypes, 10, SpringLayout.NORTH, panel);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.WEST, serverTypes, 5, SpringLayout.EAST, lblServerVersion);
|
|
|
|
panel.add(serverTypes);
|
|
|
|
serverTypes.addActionListener(this);
|
|
|
|
|
2018-01-29 20:14:17 +01:00
|
|
|
serverVersions = new JComboBox<>(ServerType.getServerTypes().get(0).getVersions());
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.NORTH, serverVersions, 6, SpringLayout.SOUTH, serverTypes);
|
2018-01-30 23:34:25 +01:00
|
|
|
sl_panel_3.putConstraint(SpringLayout.EAST, serverVersions, 0, SpringLayout.EAST, serverTypes);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.WEST, serverVersions, 6, SpringLayout.EAST, lblServerVersion);
|
2018-01-29 20:14:17 +01:00
|
|
|
panel.add(serverVersions);
|
|
|
|
serverVersions.addActionListener(this);
|
|
|
|
|
|
|
|
JLabel lblMaxRam = new JLabel("Max ram");
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.EAST, serverTypes, -13, SpringLayout.WEST, lblMaxRam);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.NORTH, lblMaxRam, 10, SpringLayout.NORTH, panel);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.SOUTH, lblMaxRam, -92, SpringLayout.SOUTH, panel);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.EAST, lblMaxRam, -111, SpringLayout.EAST, panel);
|
|
|
|
panel.add(lblMaxRam);
|
|
|
|
|
|
|
|
maxRam = new JComboBox<>(Server.getRamList());
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.NORTH, maxRam, 10, SpringLayout.NORTH, panel);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.WEST, maxRam, 6, SpringLayout.EAST, lblMaxRam);
|
2018-01-30 23:34:25 +01:00
|
|
|
sl_panel_3.putConstraint(SpringLayout.EAST, maxRam, -10, SpringLayout.EAST, panel);
|
2018-01-29 20:14:17 +01:00
|
|
|
panel.add(maxRam);
|
|
|
|
maxRam.addActionListener(this);
|
|
|
|
|
|
|
|
chckbxEnabled = new JCheckBox("Enabled");
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.NORTH, chckbxEnabled, 6, SpringLayout.SOUTH, lblServerVersion);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.EAST, chckbxEnabled, 0, SpringLayout.EAST, lblServerType);
|
|
|
|
panel.add(chckbxEnabled);
|
|
|
|
chckbxEnabled.addActionListener(this);
|
|
|
|
|
|
|
|
btnRemoveServer = new JButton("Remove server");
|
2018-01-30 23:34:25 +01:00
|
|
|
sl_panel_3.putConstraint(SpringLayout.NORTH, btnRemoveServer, 0, SpringLayout.NORTH, serverVersions);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.SOUTH, btnRemoveServer, 0, SpringLayout.SOUTH, serverVersions);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.WEST, btnRemoveServer, 6, SpringLayout.EAST, serverVersions);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.EAST, btnRemoveServer, -10, SpringLayout.EAST, panel);
|
2018-01-29 20:14:17 +01:00
|
|
|
panel.add(btnRemoveServer);
|
|
|
|
btnRemoveServer.addActionListener(this);
|
|
|
|
|
|
|
|
JLabel lblDirectory = new JLabel("Directory");
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.NORTH, lblDirectory, 1, SpringLayout.NORTH, chckbxEnabled);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.SOUTH, lblDirectory, 0, SpringLayout.SOUTH, chckbxEnabled);
|
2018-01-30 23:34:25 +01:00
|
|
|
sl_panel_3.putConstraint(SpringLayout.WEST, lblDirectory, 6, SpringLayout.EAST, chckbxEnabled);
|
2018-01-29 20:14:17 +01:00
|
|
|
panel.add(lblDirectory);
|
|
|
|
|
|
|
|
directory = new JTextField();
|
2018-01-30 23:34:25 +01:00
|
|
|
sl_panel_3.putConstraint(SpringLayout.WEST, directory, 6, SpringLayout.EAST, lblDirectory);
|
2018-01-29 20:14:17 +01:00
|
|
|
panel.add(directory);
|
|
|
|
directory.setColumns(10);
|
|
|
|
directory.addActionListener(this);
|
|
|
|
|
|
|
|
btnBrowse = new JButton("Browse");
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.EAST, directory, -6, SpringLayout.WEST, btnBrowse);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.NORTH, btnBrowse, 3, SpringLayout.SOUTH, btnRemoveServer);
|
2018-01-30 23:34:25 +01:00
|
|
|
sl_panel_3.putConstraint(SpringLayout.EAST, btnBrowse, -10, SpringLayout.EAST, panel);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.SOUTH, directory, 0, SpringLayout.SOUTH, btnBrowse);
|
|
|
|
sl_panel_3.putConstraint(SpringLayout.NORTH, directory, 0, SpringLayout.NORTH, btnBrowse);
|
2018-01-29 20:14:17 +01:00
|
|
|
panel.add(btnBrowse);
|
|
|
|
btnBrowse.addActionListener(this);
|
|
|
|
}
|
|
|
|
|
2018-01-30 17:14:29 +01:00
|
|
|
public String getPath() {
|
|
|
|
return this.directory.getText();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getMaxRam() {
|
|
|
|
Object selected = this.maxRam.getSelectedItem();
|
|
|
|
if (selected != null) {
|
|
|
|
return selected.toString();
|
|
|
|
} else {
|
|
|
|
return "512M";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getType() {
|
|
|
|
Object selected = this.serverTypes.getSelectedItem();
|
|
|
|
if (selected != null) {
|
|
|
|
return selected.toString();
|
|
|
|
} else {
|
|
|
|
return "Vanilla";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getVersion() {
|
|
|
|
Object selected = this.serverVersions.getSelectedItem();
|
|
|
|
if (selected != null) {
|
|
|
|
return selected.toString();
|
|
|
|
} else {
|
|
|
|
return "Vanilla";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean enabled() {
|
|
|
|
return this.chckbxEnabled.isSelected();
|
|
|
|
}
|
|
|
|
|
2018-01-29 20:14:17 +01:00
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
if (e.getSource() == btnRemoveServer) {
|
2018-01-30 00:44:03 +01:00
|
|
|
GUI.getGUI().removeServer(this);
|
2018-01-29 20:14:17 +01:00
|
|
|
} else if (e.getSource() == btnBrowse) {
|
2018-01-30 00:44:03 +01:00
|
|
|
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());
|
|
|
|
}
|
2018-01-30 13:39:09 +01:00
|
|
|
} else if (e.getSource() == serverTypes) {
|
|
|
|
serverVersions.removeAllItems();
|
|
|
|
String selectedserverTypes = null;
|
|
|
|
Object selectedType = serverTypes.getSelectedItem();
|
|
|
|
if (selectedType != null) {
|
|
|
|
selectedserverTypes = selectedType.toString();
|
|
|
|
}
|
|
|
|
if (selectedserverTypes != null) {
|
|
|
|
if (selectedserverTypes.equals("Custom")) {
|
|
|
|
serverVersions.setEditable(true);
|
|
|
|
} else {
|
|
|
|
serverVersions.setEditable(false);
|
|
|
|
ServerType current = null;
|
|
|
|
for (ServerType servertype : ServerType.getServerTypes()) {
|
|
|
|
if (servertype.getName().equals(selectedserverTypes)) {
|
|
|
|
current = servertype;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (current != null) {
|
|
|
|
for (String version : current.getVersions()) {
|
|
|
|
serverVersions.addItem(version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-29 20:14:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|