mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-04-19 21:16:30 +02:00
Add new GUI code from windowbuilder, fix a thing
This commit is contained in:
parent
87b00f316a
commit
452ab15cc7
@ -0,0 +1,201 @@
|
|||||||
|
package link.infra.packwiz.installer.ui;
|
||||||
|
|
||||||
|
import link.infra.packwiz.installer.ui.IExceptionDetails.ExceptionListResult;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.event.ListSelectionEvent;
|
||||||
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class ExceptionListWindow extends JDialog {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private final JPanel contentPanel = new JPanel();
|
||||||
|
private final JTextArea lblExceptionStacktrace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the dialog.
|
||||||
|
*/
|
||||||
|
public ExceptionListWindow(List<IExceptionDetails> eList, CompletableFuture<ExceptionListResult> future, int numTotal, JFrame parentWindow) {
|
||||||
|
super(parentWindow, "Failed file downloads", true);
|
||||||
|
|
||||||
|
setBounds(100, 100, 540, 340);
|
||||||
|
setLocationRelativeTo(parentWindow);
|
||||||
|
getContentPane().setLayout(new BorderLayout());
|
||||||
|
{
|
||||||
|
JPanel errorPanel = new JPanel();
|
||||||
|
getContentPane().add(errorPanel, BorderLayout.NORTH);
|
||||||
|
{
|
||||||
|
JLabel lblWarning = new JLabel("One or more errors were encountered while installing the modpack!");
|
||||||
|
lblWarning.setIcon(UIManager.getIcon("OptionPane.warningIcon"));
|
||||||
|
errorPanel.add(lblWarning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||||
|
contentPanel.setLayout(new BorderLayout(0, 0));
|
||||||
|
{
|
||||||
|
JSplitPane splitPane = new JSplitPane();
|
||||||
|
splitPane.setResizeWeight(0.3);
|
||||||
|
contentPanel.add(splitPane);
|
||||||
|
{
|
||||||
|
lblExceptionStacktrace = new JTextArea("Select a file");
|
||||||
|
lblExceptionStacktrace.setBackground(UIManager.getColor("List.background"));
|
||||||
|
lblExceptionStacktrace.setOpaque(true);
|
||||||
|
lblExceptionStacktrace.setWrapStyleWord(true);
|
||||||
|
lblExceptionStacktrace.setLineWrap(true);
|
||||||
|
lblExceptionStacktrace.setEditable(false);
|
||||||
|
lblExceptionStacktrace.setFocusable(true);
|
||||||
|
lblExceptionStacktrace.setFont(UIManager.getFont("Label.font"));
|
||||||
|
lblExceptionStacktrace.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
JScrollPane scrollPane = new JScrollPane(lblExceptionStacktrace);
|
||||||
|
scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||||
|
splitPane.setRightComponent(scrollPane);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JList<String> list = new JList<String>();
|
||||||
|
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
list.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
ExceptionListModel listModel = new ExceptionListModel(eList);
|
||||||
|
list.setModel(listModel);
|
||||||
|
list.addListSelectionListener(new ListSelectionListener() {
|
||||||
|
@Override
|
||||||
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
|
int i = list.getSelectedIndex();
|
||||||
|
if (i > -1) {
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
listModel.getExceptionAt(i).printStackTrace(new PrintWriter(sw));
|
||||||
|
lblExceptionStacktrace.setText(sw.toString());
|
||||||
|
// Scroll to the top
|
||||||
|
lblExceptionStacktrace.setCaretPosition(0);
|
||||||
|
} else {
|
||||||
|
lblExceptionStacktrace.setText("Select a file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JScrollPane scrollPane = new JScrollPane(list);
|
||||||
|
scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||||
|
splitPane.setLeftComponent(scrollPane);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JPanel buttonPane = new JPanel();
|
||||||
|
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||||
|
buttonPane.setLayout(new BorderLayout(0, 0));
|
||||||
|
{
|
||||||
|
JPanel rightButtons = new JPanel();
|
||||||
|
buttonPane.add(rightButtons, BorderLayout.EAST);
|
||||||
|
{
|
||||||
|
JButton btnContinue = new JButton("Continue");
|
||||||
|
btnContinue.setToolTipText("Attempt to continue installing, excluding the failed downloads");
|
||||||
|
btnContinue.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
future.complete(ExceptionListResult.CONTINUE);
|
||||||
|
ExceptionListWindow.this.dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rightButtons.add(btnContinue);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JButton btnCancelLaunch = new JButton("Cancel launch");
|
||||||
|
btnCancelLaunch.setToolTipText("Stop launching the game");
|
||||||
|
btnCancelLaunch.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
future.complete(ExceptionListResult.CANCEL);
|
||||||
|
ExceptionListWindow.this.dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rightButtons.add(btnCancelLaunch);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JButton btnIgnoreUpdate = new JButton("Ignore update");
|
||||||
|
btnIgnoreUpdate.setToolTipText("Start the game without attempting to update");
|
||||||
|
btnIgnoreUpdate.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
future.complete(ExceptionListResult.IGNORE);
|
||||||
|
ExceptionListWindow.this.dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rightButtons.add(btnIgnoreUpdate);
|
||||||
|
{
|
||||||
|
JLabel lblErrored = new JLabel(eList.size() + "/" + numTotal + " errored");
|
||||||
|
lblErrored.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
buttonPane.add(lblErrored, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JPanel leftButtons = new JPanel();
|
||||||
|
buttonPane.add(leftButtons, BorderLayout.WEST);
|
||||||
|
{
|
||||||
|
JButton btnReportIssue = new JButton("Report issue");
|
||||||
|
boolean supported = Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE);
|
||||||
|
btnReportIssue.setEnabled(supported);
|
||||||
|
if (supported) {
|
||||||
|
btnReportIssue.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
Desktop.getDesktop().browse(new URI("https://github.com/comp500/packwiz-installer/issues/new"));
|
||||||
|
} catch (IOException | URISyntaxException e1) {
|
||||||
|
// lol the button just won't work i guess
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
leftButtons.add(btnReportIssue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
future.complete(ExceptionListResult.CANCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowClosed(WindowEvent e) {
|
||||||
|
// Just in case closing didn't get triggered - if something else called dispose() the
|
||||||
|
// future will have already completed
|
||||||
|
future.complete(ExceptionListResult.CANCEL);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ExceptionListModel extends AbstractListModel<String> {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private final List<IExceptionDetails> details;
|
||||||
|
|
||||||
|
public ExceptionListModel(List<IExceptionDetails> details) {
|
||||||
|
this.details = details;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return details.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getElementAt(int index) {
|
||||||
|
return details.get(index).getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Exception getExceptionAt(int index) {
|
||||||
|
return details.get(index).getException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package link.infra.packwiz.installer.ui;
|
||||||
|
|
||||||
|
public interface IExceptionDetails {
|
||||||
|
Exception getException();
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
enum ExceptionListResult {
|
||||||
|
CONTINUE, CANCEL, IGNORE
|
||||||
|
}
|
||||||
|
}
|
@ -77,7 +77,6 @@ public class OptionsSelectWindow extends JDialog implements ActionListener {
|
|||||||
lblOptionDescription.setOpaque(true);
|
lblOptionDescription.setOpaque(true);
|
||||||
lblOptionDescription.setWrapStyleWord(true);
|
lblOptionDescription.setWrapStyleWord(true);
|
||||||
lblOptionDescription.setLineWrap(true);
|
lblOptionDescription.setLineWrap(true);
|
||||||
lblOptionDescription.setOpaque(true);
|
|
||||||
lblOptionDescription.setEditable(false);
|
lblOptionDescription.setEditable(false);
|
||||||
lblOptionDescription.setFocusable(false);
|
lblOptionDescription.setFocusable(false);
|
||||||
lblOptionDescription.setFont(UIManager.getFont("Label.font"));
|
lblOptionDescription.setFont(UIManager.getFont("Label.font"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user