147 lines
5.8 KiB
Java
Raw Normal View History

2018-01-26 20:26:16 +01:00
package net.knarcraft.serverlauncher.userinterface;
2018-01-26 23:15:19 +01:00
import javax.imageio.ImageIO;
2018-01-26 20:26:16 +01:00
import javax.swing.*;
import javax.swing.border.EmptyBorder;
2018-01-26 20:26:16 +01:00
import java.awt.*;
2018-01-26 23:15:19 +01:00
import java.io.IOException;
2018-01-26 20:26:16 +01:00
/**
* A class for creating the gui.
*
* @author Kristian Knarvik <kristian.knarvik@knett.no>
* @version 0.0.0.1
* @since 0.0.0.1
*/
public class GUI {
public GUI() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
2018-01-26 23:15:19 +01:00
} catch (ClassNotFoundException | UnsupportedLookAndFeelException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
2018-01-26 20:26:16 +01:00
JFrame frame = new JFrame("Minecraft server launcher");
2018-01-26 23:15:19 +01:00
ImageIcon img;
try {
img = new ImageIcon(ImageIO.read(GUI.class.getResourceAsStream("/files/GUIIcon.png")));
} catch (IOException | IllegalArgumentException e) {
img = new ImageIcon("files/GUIIcon.png");
}
2018-01-26 20:26:16 +01:00
frame.setIconImage(img.getImage());
frame.setLocation(0,0);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menu = new JMenuBar();
// A menu containing a user's options
JMenu optionsMenu = new JMenu("Options");
JCheckBoxMenuItem backgroundMode = new JCheckBoxMenuItem("Run in background on exit");
JCheckBoxMenuItem delayStartup = new JCheckBoxMenuItem("Delay startup");
JCheckBoxMenuItem downloadJars = new JCheckBoxMenuItem("Download Jars");
// A menu containing helpful information
JMenu helpMenu = new JMenu("Help");
JMenuItem errors = new JMenuItem("Errors");
JMenuItem setup = new JMenuItem("Setup");
JMenuItem warning = new JMenuItem("Warning");
JMenuItem manualUpdate = new JMenuItem("Manual update");
// A menu containing various information
JMenu infoMenu = new JMenu("Info");
JMenu options = new JMenu("Options");
JMenu about = new JMenu("About");
JMenuItem backgroundModeInfo = new JMenuItem("Run in background on exit");
JMenuItem delayStartupInfo = new JMenuItem("Delay Startup");
JMenuItem downloadJarsInfo = new JMenuItem("Download jars");
JMenuItem aboutAbout = new JMenuItem("About");
JMenuItem aboutStory = new JMenuItem("Story");
// Connects menu items to each other
optionsMenu.add(backgroundMode);
optionsMenu.add(delayStartup);
optionsMenu.add(downloadJars);
menu.add(optionsMenu);
helpMenu.add(errors);
helpMenu.add(setup);
helpMenu.add(warning);
helpMenu.add(manualUpdate);
menu.add(helpMenu);
options.add(backgroundModeInfo);
options.add(delayStartupInfo);
options.add(downloadJarsInfo);
infoMenu.add(options);
about.add(aboutAbout);
about.add(aboutStory);
infoMenu.add(about);
menu.add(infoMenu);
frame.setJMenuBar(menu);
JTabbedPane tabs = new JTabbedPane(SwingConstants.TOP);
//First tab
JPanel controlPanel = new JPanel();
controlPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
GroupLayout controlLayout = new GroupLayout(controlPanel);
controlPanel.setLayout(controlLayout);
JLabel basicControls = customLabel("Basic controls");
JButton sendStart = customButton("Start servers");
JButton sendStop = customButton("Stop servers");
JButton backup = customButton("Backup");
JButton viewConsole = customButton("View server consoles");
JLabel profile = customLabel("Profile");
controlLayout.setVerticalGroup(
controlLayout.createSequentialGroup()
.addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(basicControls))
.addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(sendStart)
.addComponent(sendStop)
.addComponent(backup)
.addComponent(viewConsole))
.addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(profile)));
controlLayout.setHorizontalGroup(
controlLayout.createSequentialGroup()
.addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(basicControls)
.addComponent(profile)
.addComponent(sendStart))
.addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(sendStop))
.addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(backup))
.addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(viewConsole)));
tabs.addTab("Control panel", null, controlPanel, "Basic server controls");
JPanel serversPanel = new JPanel();
tabs.addTab("Control servers", null, serversPanel, "Easy server commands");
2018-01-26 20:26:16 +01:00
frame.add(tabs);
// TODO: Finish gui
frame.setVisible(true);
Insets insets = frame.getInsets();
frame.setSize(450 + 2 * insets.left, 170 + insets.top + insets.bottom);
}
private JButton customButton(String text) {
JButton button = new JButton(text);
button.setMargin(new Insets(3,5,3,5));
return button;
}
private JLabel customLabel(String text) {
JLabel label = new JLabel(text);
label.setBorder(new EmptyBorder(1, 2, 1, 0));
return label;
}
2018-01-26 20:26:16 +01:00
}