Using pack() for scaling

This commit is contained in:
2018-01-31 17:40:28 +01:00
parent 749af701a8
commit 30263d7753
9 changed files with 114 additions and 75 deletions

View File

@ -11,7 +11,7 @@ import java.awt.*;
* @version 0.0.0.1
* @since 0.0.0.1
*/
class Console {
public class Console {
private final JTextField textInput;
private final JTextArea textOutput;
@ -19,7 +19,7 @@ class Console {
this.textOutput.setText(text);
}
Console(JTabbedPane tab, String name) {
public Console(JTabbedPane tab, String name) {
JPanel panel = new JPanel();
tab.addTab(name, null, panel, null);
panel.setLayout(new BorderLayout(0, 0));

View File

@ -1,10 +1,12 @@
package net.knarcraft.serverlauncher.userinterface;
import net.knarcraft.serverlauncher.profile.Collection;
import net.knarcraft.serverlauncher.server.Server;
import net.knarcraft.serverlauncher.profile.Profile;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
@ -107,7 +109,7 @@ public class GUI implements ActionListener {
for (int i = 0; i < this.serverTabs.size(); i++) {
if(this.serverTabs.get(i) == tab) {
serversPane.remove(i);
currentProfile().removeServer(i);
currentProfile().removeCollection(i);
this.serverTabs.remove(i);
i = serverTabs.size();
}
@ -119,14 +121,13 @@ public class GUI implements ActionListener {
* Initialize the contents of the frame.
*/
private void initialize() {
try {
/*try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | UnsupportedLookAndFeelException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}*/
frame = new JFrame("Minecraft server launcher");
frame.setBounds(100, 100, 470, 219);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setResizable(false);
ImageIcon img;
@ -204,7 +205,6 @@ public class GUI implements ActionListener {
mntmStory = new JMenuItem("Story");
mnAbout.add(mntmStory);
frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.X_AXIS));
mntmStory.addActionListener(this);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
@ -221,8 +221,7 @@ public class GUI implements ActionListener {
btnStartServer = new JButton("Start servers");
sl_panel.putConstraint(SpringLayout.WEST, lblBasicControls, 0, SpringLayout.WEST, btnStartServer);
sl_panel.putConstraint(SpringLayout.SOUTH, lblBasicControls, -6, SpringLayout.NORTH, btnStartServer);
sl_panel.putConstraint(SpringLayout.NORTH, btnStartServer, 30, SpringLayout.NORTH, panelBasic);
sl_panel.putConstraint(SpringLayout.NORTH, btnStartServer, 6, SpringLayout.SOUTH, lblBasicControls);
sl_panel.putConstraint(SpringLayout.WEST, btnStartServer, 10, SpringLayout.WEST, panelBasic);
panelBasic.add(btnStartServer);
btnStartServer.addActionListener(this);
@ -251,15 +250,16 @@ public class GUI implements ActionListener {
delProfile.addActionListener(this);
profiles = new JComboBox<>();
sl_panel.putConstraint(SpringLayout.NORTH, profiles, 1, SpringLayout.NORTH, addProfile);
sl_panel.putConstraint(SpringLayout.NORTH, profiles, 0, SpringLayout.NORTH, addProfile);
sl_panel.putConstraint(SpringLayout.WEST, profiles, 6, SpringLayout.EAST, delProfile);
sl_panel.putConstraint(SpringLayout.EAST, profiles, 124, SpringLayout.EAST, delProfile);
panelBasic.add(profiles);
profiles.addActionListener(this);
sl_panel.putConstraint(SpringLayout.NORTH, lblStatuslabel, 8, SpringLayout.SOUTH, addProfile);
sl_panel.putConstraint(SpringLayout.NORTH, lblStatuslabel, 6, SpringLayout.SOUTH, addProfile);
sl_panel.putConstraint(SpringLayout.SOUTH, lblStatuslabel, -10, SpringLayout.SOUTH, panelBasic);
sl_panel.putConstraint(SpringLayout.WEST, lblStatuslabel, 10, SpringLayout.WEST, panelBasic);
sl_panel.putConstraint(SpringLayout.EAST, lblStatuslabel, 386, SpringLayout.WEST, panelBasic);
sl_panel.putConstraint(SpringLayout.EAST, lblStatuslabel, -10, SpringLayout.EAST, panelBasic);
panelBasic.add(lblStatuslabel);
addServer = new JButton("Add server");
@ -291,15 +291,15 @@ public class GUI implements ActionListener {
btnKick = new JButton("Kick");
sl_panel_1.putConstraint(SpringLayout.NORTH, btnKick, 10, SpringLayout.NORTH, controlServers);
sl_panel_1.putConstraint(SpringLayout.WEST, btnKick, 6, SpringLayout.EAST, targetServer);
sl_panel_1.putConstraint(SpringLayout.EAST, btnKick, 124, SpringLayout.WEST, btnKick);
sl_panel_1.putConstraint(SpringLayout.EAST, btnKick, 104, SpringLayout.WEST, btnKick);
sl_panel_1.putConstraint(SpringLayout.SOUTH, targetServer, 0, SpringLayout.SOUTH, btnKick);
controlServers.add(btnKick);
btnKick.addActionListener(this);
btnBan = new JButton("Ban");
sl_panel_1.putConstraint(SpringLayout.NORTH, btnBan, 5, SpringLayout.SOUTH, btnKick);
sl_panel_1.putConstraint(SpringLayout.NORTH, btnBan, 6, SpringLayout.SOUTH, btnKick);
sl_panel_1.putConstraint(SpringLayout.WEST, btnBan, 6, SpringLayout.EAST, targetPlayer);
sl_panel_1.putConstraint(SpringLayout.EAST, btnBan, 124, SpringLayout.WEST, btnBan);
sl_panel_1.putConstraint(SpringLayout.EAST, btnBan, 104, SpringLayout.WEST, btnBan);
sl_panel_1.putConstraint(SpringLayout.SOUTH, targetPlayer, 0, SpringLayout.SOUTH, btnBan);
controlServers.add(btnBan);
btnBan.addActionListener(this);
@ -307,7 +307,6 @@ public class GUI implements ActionListener {
btnOp = new JButton("OP");
sl_panel_1.putConstraint(SpringLayout.NORTH, btnOp, 10, SpringLayout.NORTH, controlServers);
sl_panel_1.putConstraint(SpringLayout.WEST, btnOp, 6, SpringLayout.EAST, btnKick);
//sl_panel_1.putConstraint(SpringLayout.SOUTH, btnOp, 32, SpringLayout.NORTH, controlServers);
sl_panel_1.putConstraint(SpringLayout.EAST, btnOp, -10, SpringLayout.EAST, controlServers);
controlServers.add(btnOp);
btnOp.addActionListener(this);
@ -353,7 +352,8 @@ public class GUI implements ActionListener {
sl_panel_1.putConstraint(SpringLayout.NORTH, customCommand, 6, SpringLayout.SOUTH, btnSaveserver);
sl_panel_1.putConstraint(SpringLayout.NORTH, btnSaveserver, 6, SpringLayout.SOUTH, btnBan);
sl_panel_1.putConstraint(SpringLayout.WEST, btnSaveserver, 0, SpringLayout.WEST, btnKick);
sl_panel_1.putConstraint(SpringLayout.EAST, btnSaveserver, 120, SpringLayout.WEST, btnKick);
sl_panel_1.putConstraint(SpringLayout.EAST, btnSaveserver, 104, SpringLayout.WEST, btnKick);
sl_panel_1.putConstraint(SpringLayout.EAST, btnSaveserver, 104, SpringLayout.WEST, btnKick);
controlServers.add(btnSaveserver);
btnSaveserver.addActionListener(this);
@ -386,13 +386,14 @@ public class GUI implements ActionListener {
this.serversPane = tabbedPane_1;
tabbedPane_1.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
frame.setPreferredSize(frame.getPreferredSize());
frame.getContentPane().setPreferredSize(new Dimension(440, 170));
frame.validate();
frame.pack();
frame.setVisible(true);
}
public void addServer(String name) {
serverTabs.add(new ServerTab(name));
public void addServer(ServerTab serverTab) {
serverTabs.add(serverTab);
}
@Override
@ -421,11 +422,11 @@ public class GUI implements ActionListener {
} else if (e.getSource() == mntmRunInBackground) {
JOptionPane.showMessageDialog(null, runInBackgroundText, "Run in background", JOptionPane.INFORMATION_MESSAGE);
} else if (e.getSource() == mntmDelayStartup) {
JOptionPane.showMessageDialog(null, delayStartupText, "Run in background", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, delayStartupText, "Delay startup", JOptionPane.INFORMATION_MESSAGE);
} else if (e.getSource() == mntmDownloadJars) {
JOptionPane.showMessageDialog(null, downloadJarsText, "Run in background", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, downloadJarsText, "Download jars", JOptionPane.INFORMATION_MESSAGE);
} else if (e.getSource() == mntmAbout) {
JOptionPane.showMessageDialog(null, aboutText, "Run in background", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, aboutText, "About", JOptionPane.INFORMATION_MESSAGE);
} else if (e.getSource() == mntmStory) {
goToURL("https://knarcraft.net/Bungeeminecraftserverlauncher/Story/");
} else if (e.getSource() == btnStartServer) {
@ -435,11 +436,7 @@ public class GUI implements ActionListener {
stop();
} else if (e.getSource() == addServer) {
String serverName = JOptionPane.showInputDialog("Name of server: ");
if (!serverName.equals("") && !currentProfile().serverExists(serverName)) {
new Server(serverName, this);
} else {
JOptionPane.showMessageDialog(null, "A server name must my unique and not empty.", "Error", JOptionPane.ERROR_MESSAGE);
}
this.currentProfile().addCollection(serverName);
} else if (e.getSource() == backup) {
backup();
} else if (e.getSource() == addProfile) {
@ -479,6 +476,7 @@ public class GUI implements ActionListener {
}
} else if (e.getSource() == btnServerConsoles) {
//TODO: Make server consoles window, and toggle visibility on this action.
ServerConsoles.getGUI().show();
}
}
@ -486,7 +484,7 @@ public class GUI implements ActionListener {
* Reads all combo boxes, updates variables and saves to disk
*/
private void save() {
currentProfile().save(serverTabs);
currentProfile().save();
}
/**
@ -562,10 +560,10 @@ public class GUI implements ActionListener {
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
File path = chooser.getSelectedFile();
for (Server server : currentProfile().getServers()) {
if (!server.getPath().equals("") && server.isEnabled()) {
String name = server.getName();
File srcFolder = new File(server.getPath());
for (Collection collection : currentProfile().getCollections()) {
if (!collection.getServer().getPath().equals("") && collection.getServer().isEnabled()) {
String name = collection.getServer().getName();
File srcFolder = new File(collection.getServer().getPath());
File destFolder = new File(path, name);
if (!destFolder.exists()) {
if (destFolder.mkdirs()) {

View File

@ -16,7 +16,6 @@ import java.util.ArrayList;
*/
public class ServerConsoles {
private static ServerConsoles serverConsoles;
private static ArrayList<Console> consoles = new ArrayList<>();
private final JFrame frame;
private final JTabbedPane consolesTab;
@ -28,7 +27,6 @@ public class ServerConsoles {
consolesTab = new JTabbedPane(JTabbedPane.TOP);
frame.getContentPane().add(consolesTab, BorderLayout.CENTER);
serverConsoles = this;
frame.setVisible(true);
}
public static ServerConsoles getGUI() {
@ -39,8 +37,8 @@ public class ServerConsoles {
frame.setVisible(true);
}
public void addTab(String name) {
new Console(consolesTab, name);
public Console addTab(String name) {
return new Console(consolesTab, name);
}
}

View File

@ -58,7 +58,6 @@ public class ServerTab implements ActionListener {
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.EAST, lblMaxRam, 50, SpringLayout.WEST, lblMaxRam);
sl_panel_3.putConstraint(SpringLayout.WEST, lblMaxRam, 6, SpringLayout.EAST, serverTypes);
panel.add(lblMaxRam);