All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
Additionally fixes some formatting mistakes Updates version to 1.4.1
107 lines
3.3 KiB
Java
107 lines
3.3 KiB
Java
package net.knarcraft.minecraftserverlauncher.userinterface;
|
|
|
|
import net.knarcraft.minecraftserverlauncher.utility.BackupUtil;
|
|
|
|
import javax.imageio.ImageIO;
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.io.IOException;
|
|
|
|
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.getResourceAsStream;
|
|
|
|
/**
|
|
* The Backup GUI is used to display backup progress
|
|
*/
|
|
public class BackupGUI implements ActionListener {
|
|
private static JFrame frame;
|
|
private static JTextArea progressTextArea;
|
|
private static JProgressBar progressBar;
|
|
private static JButton cancelButton;
|
|
|
|
/**
|
|
* Instantiates a new GUI
|
|
*/
|
|
public BackupGUI() {
|
|
instantiate();
|
|
}
|
|
|
|
/**
|
|
* Initializes the server consoles frame
|
|
*/
|
|
public void instantiate() {
|
|
if (frame != null) {
|
|
return;
|
|
}
|
|
frame = new JFrame("Running backup...");
|
|
frame.setBounds(100, 100, 500, 140);
|
|
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
|
ImageIcon img;
|
|
try {
|
|
img = new ImageIcon(ImageIO.read(getResourceAsStream("GUIIcon.png")));
|
|
frame.setIconImage(img.getImage());
|
|
} catch (IOException ignored) {
|
|
}
|
|
|
|
progressTextArea = new JTextArea();
|
|
progressTextArea.setEditable(false);
|
|
progressBar = new JProgressBar();
|
|
cancelButton = new JButton("Cancel");
|
|
JPanel panel = new JPanel();
|
|
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
|
|
panel.add(progressTextArea);
|
|
panel.add(Box.createRigidArea(new Dimension(0, 5)));
|
|
panel.add(progressBar);
|
|
|
|
JPanel buttonPane = new JPanel();
|
|
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
|
|
buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
|
|
buttonPane.add(Box.createHorizontalGlue());
|
|
buttonPane.add(cancelButton);
|
|
cancelButton.addActionListener(BackupGUI.this);
|
|
|
|
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
|
Container contentPane = frame.getContentPane();
|
|
contentPane.add(panel, BorderLayout.CENTER);
|
|
contentPane.add(buttonPane, BorderLayout.PAGE_END);
|
|
frame.setVisible(true);
|
|
}
|
|
|
|
/**
|
|
* Updates information about the backup progress
|
|
*
|
|
* @param infoText <p>The text to display</p>
|
|
* @param progressPercent <p>The new percent of the progress bar</p>
|
|
*/
|
|
public static void updateProgress(String infoText, int progressPercent) {
|
|
if (progressTextArea != null) {
|
|
progressTextArea.setText(infoText);
|
|
}
|
|
if (progressBar != null) {
|
|
progressBar.setValue(progressPercent);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Destroys the backup GUI
|
|
*/
|
|
public static void destroy() {
|
|
if (frame != null) {
|
|
frame.dispose();
|
|
frame = null;
|
|
progressBar = null;
|
|
progressTextArea = null;
|
|
cancelButton = null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void actionPerformed(ActionEvent actionEvent) {
|
|
if (actionEvent.getSource() == cancelButton) {
|
|
BackupUtil.abortBackup();
|
|
destroy();
|
|
}
|
|
}
|
|
}
|