Makes the project into a Maven project
Some checks failed
KnarCraft/Minecraft-Server-Launcher/master There was a failure building this commit

Moves stuff around
Adds Jenkinsfile
Changes some package names
Replaces library with Maven dependency
This commit is contained in:
2020-02-12 21:30:36 +01:00
parent 4901ea0627
commit 194686b9d8
17 changed files with 96 additions and 69 deletions

View File

@ -0,0 +1,243 @@
package net.knarcraft.minecraftserverlauncher.userinterface;
import net.knarcraft.minecraftserverlauncher.profile.Profile;
import net.knarcraft.minecraftserverlauncher.server.Server;
import net.knarcraft.minecraftserverlauncher.server.ServerType;
import javax.swing.*;
import java.awt.event.ActionEvent;
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
*/
public class ServerTab implements ActionListener {
private final JComboBox<String> serverTypes, serverVersions, maxRam;
private final JCheckBox chckbxEnabled;
private final JButton btnRemoveServer, btnBrowse;
private final JTextField directory;
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);
this.serverTypes.setSelectedItem(typeName);
this.serverTypes();
this.serverVersions.setSelectedItem(serverVersion);
this.maxRam.setSelectedItem(maxRam);
}
public ServerTab(String name) {
this.name = name;
panel = new JPanel();
Profile.getGUI().getPane().addTab(name, null, panel, null);
SpringLayout sl_panel_3 = new SpringLayout();
panel.setLayout(sl_panel_3);
JLabel lblServerType = new JLabel("Server type");
sl_panel_3.putConstraint(SpringLayout.WEST, lblServerType, 10, SpringLayout.WEST, 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);
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);
sl_panel_3.putConstraint(SpringLayout.EAST, serverTypes, 154, SpringLayout.WEST, serverTypes);
sl_panel_3.putConstraint(SpringLayout.NORTH, lblServerType, 0, SpringLayout.NORTH, serverTypes);
sl_panel_3.putConstraint(SpringLayout.SOUTH, lblServerType, 0, SpringLayout.SOUTH, serverTypes);
panel.add(serverTypes);
serverTypes.addActionListener(this);
serverVersions = new JComboBox<>(ServerType.getServerTypes().get(0).getVersions());
sl_panel_3.putConstraint(SpringLayout.NORTH, serverVersions, 6, SpringLayout.SOUTH, serverTypes);
sl_panel_3.putConstraint(SpringLayout.EAST, serverVersions, 0, SpringLayout.EAST, serverTypes);
sl_panel_3.putConstraint(SpringLayout.WEST, serverVersions, 6, SpringLayout.EAST, lblServerVersion);
sl_panel_3.putConstraint(SpringLayout.NORTH, lblServerVersion, 0, SpringLayout.NORTH, serverVersions);
sl_panel_3.putConstraint(SpringLayout.SOUTH, lblServerVersion, 0, SpringLayout.SOUTH, serverVersions);
panel.add(serverVersions);
serverVersions.addActionListener(this);
JLabel lblMaxRam = new JLabel("Max ram");
sl_panel_3.putConstraint(SpringLayout.NORTH, lblMaxRam, 0, SpringLayout.NORTH, serverTypes);
sl_panel_3.putConstraint(SpringLayout.SOUTH, lblMaxRam, 0, SpringLayout.SOUTH, serverTypes);
sl_panel_3.putConstraint(SpringLayout.WEST, lblMaxRam, 6, SpringLayout.EAST, serverTypes);
panel.add(lblMaxRam);
maxRam = new JComboBox<>(Server.getRamList());
sl_panel_3.putConstraint(SpringLayout.NORTH, maxRam, 0, SpringLayout.NORTH, serverTypes);
sl_panel_3.putConstraint(SpringLayout.WEST, maxRam, 6, SpringLayout.EAST, lblMaxRam);
sl_panel_3.putConstraint(SpringLayout.EAST, maxRam, -10, SpringLayout.EAST, panel);
panel.add(maxRam);
maxRam.addActionListener(this);
chckbxEnabled = new JCheckBox("Enabled");
sl_panel_3.putConstraint(SpringLayout.WEST, chckbxEnabled, 10, SpringLayout.WEST, panel);
panel.add(chckbxEnabled);
chckbxEnabled.addActionListener(this);
btnRemoveServer = new JButton("Remove server");
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);
panel.add(btnRemoveServer);
btnRemoveServer.addActionListener(this);
JLabel lblDirectory = new JLabel("Directory");
sl_panel_3.putConstraint(SpringLayout.WEST, lblDirectory, 6, SpringLayout.EAST, chckbxEnabled);
panel.add(lblDirectory);
directory = new JTextField();
sl_panel_3.putConstraint(SpringLayout.WEST, directory, 6, SpringLayout.EAST, lblDirectory);
sl_panel_3.putConstraint(SpringLayout.SOUTH, lblDirectory, 0, SpringLayout.SOUTH, directory);
sl_panel_3.putConstraint(SpringLayout.NORTH, lblDirectory, 0, SpringLayout.NORTH, directory);
sl_panel_3.putConstraint(SpringLayout.NORTH, chckbxEnabled, 0, SpringLayout.NORTH, directory);
sl_panel_3.putConstraint(SpringLayout.SOUTH, chckbxEnabled, 0, SpringLayout.SOUTH, directory);
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);
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);
panel.add(btnBrowse);
btnBrowse.addActionListener(this);
}
public JPanel getPanel() {
return this.panel;
}
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";
}
}
/**
* 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) {
return selected.toString();
} else {
return "Latest";
}
}
/**
* Checks if the server is enabled
*
* @return True if the checkbox is checked. False otherwise.
*/
public boolean enabled() {
return this.chckbxEnabled.isSelected();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnRemoveServer) {
remove();
} else if (e.getSource() == btnBrowse) {
browse();
} else if (e.getSource() == serverTypes) {
serverTypes();
}
}
/**
* Removes the collection containing this ServerTab, and updates everything necessary.
*/
private void remove() {
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("/"));
chooser.setDialogTitle("Server folder");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
directory.setText(chooser.getSelectedFile().toString());
}
}
/**
* Updates the versions combo according to the value of the server type combo.
*/
private void 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);
}
}
}
}
}
}