Skip to content

Commit

Permalink
Added cancel button to pack download dialog; cancel or closing dialog…
Browse files Browse the repository at this point in the history
… aborts download
  • Loading branch information
FyberOptic committed Dec 13, 2014
1 parent a6d92de commit 8612734
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/ftb/gui/LaunchFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ private boolean initializeMods () {
} catch (InterruptedException ignored) {
}
}
if (ModManager.erroneous) {
if (ModManager.erroneous || ModManager.worker.isCancelled()) {
return false;
}
try {
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/net/ftb/tools/ModManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.google.common.net.HttpHeaders.CONTENT_MD5;
import static net.ftb.download.Locations.MODPACKS;
import static net.ftb.download.Locations.PRIVATEPACKS;

import net.ftb.data.ModPack;
import net.ftb.data.Settings;
import net.ftb.gui.LaunchFrame;
Expand All @@ -33,6 +32,8 @@
import net.ftb.util.OSUtils;
import net.ftb.util.TrackerUtils;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedInputStream;
Expand Down Expand Up @@ -313,8 +314,9 @@ public ModManager (JFrame owner, Boolean model) {
super(owner, model);
setResizable(false);
setTitle("Downloading...");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds(100, 100, 313, 138);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

This comment has been minimized.

Copy link
@jikuja

jikuja Dec 14, 2014

Collaborator

DISPOSE_ON_CLOSE is probably correct one. Launcher creates always new JDialog.
Otherwise looking good but we probably need check if mopack is always left state which launcher can detect and start reinstalling at next launch. I can do testing later and try to find bad cases.

This comment has been minimized.

Copy link
@FyberOptic

FyberOptic Dec 14, 2014

Author Contributor

I wasn't sure how the ModManagerWorker process would be dealt with in the case of a DISPOSE_ON_CLOSE, since the SwingWorker documentation doesn't specifically say if it's set to "cancelled" when destroyed, so I took the manual approach to ensure it's forced to cancel when you close the dialog, so that I can check for isCancelled().

setBounds(100, 100, 313, 165);
setLocationRelativeTo(null);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
Expand All @@ -332,8 +334,26 @@ public ModManager (JFrame owner, Boolean model) {
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setBounds(0, 42, 313, 14);
contentPane.add(label);

JButton cancelButton = new JButton();
cancelButton.setText("Cancel");
cancelButton.setBounds(50, 100, 200, 30);
final ModManager thisManager = this;
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
thisManager.dispatchEvent(new WindowEvent(thisManager, WindowEvent.WINDOW_CLOSING));
}
});
contentPane.add(cancelButton);

addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
worker.cancel(true);
super.windowClosing(e);
}

@Override
public void windowOpened (WindowEvent arg0) {
worker = new ModManagerWorker() {
Expand Down

0 comments on commit 8612734

Please sign in to comment.