source: AE/installer2/src/net/oni2/aeinstaller/gui/downloadwindow/Downloader.java@ 611

Last change on this file since 611 was 606, checked in by alloc, 12 years ago

AEI2:

  • Table columns "Type" and "Platform" removed
  • Column "Install" moved to front
  • Added Type+Platform to the description pane for now
  • Order of level-installation: now in alphabetical order (0, 10...19, 1...9)
  • Oni launched with WorkDir set to the Edition folder instead of AEI folder
File size: 3.0 KB
Line 
1package net.oni2.aeinstaller.gui.downloadwindow;
2
3import java.util.ResourceBundle;
4import java.util.TreeSet;
5
6import javax.swing.JDialog;
7import javax.swing.JLabel;
8import javax.swing.JOptionPane;
9import javax.swing.JProgressBar;
10
11import net.oni2.aeinstaller.backend.SizeFormatter;
12import net.oni2.aeinstaller.backend.mods.Mod;
13import net.oni2.aeinstaller.backend.mods.download.ModDownloader;
14import net.oni2.aeinstaller.backend.mods.download.ModDownloader.State;
15import net.oni2.aeinstaller.backend.mods.download.ModDownloaderListener;
16
17import org.javabuilders.BuildResult;
18import org.javabuilders.swing.SwingJavaBuilder;
19
20/**
21 * @author Christian Illy
22 */
23public class Downloader extends JDialog implements ModDownloaderListener {
24 private static final long serialVersionUID = 9097967828001263776L;
25
26 private ResourceBundle bundle = ResourceBundle.getBundle(getClass()
27 .getName());
28 @SuppressWarnings("unused")
29 private BuildResult result = SwingJavaBuilder.build(this, bundle);
30
31 private JLabel lblElapsedVal;
32 private JLabel lblRemainingVal;
33 private JLabel lblDownloadedVal;
34 private JLabel lblTotalVal;
35 private JLabel lblRateVal;
36 private JProgressBar progress;
37
38 private ModDownloader downloader;
39
40 /**
41 * @param mods
42 * Mods to download
43 */
44 public Downloader(TreeSet<Mod> mods) {
45 super();
46
47 setResizable(false);
48 setSize(500, (int) getSize().getHeight());
49
50 downloader = new ModDownloader(mods, this);
51 progress.setMaximum(downloader.getTotalSize());
52 progress.setStringPainted(true);
53 progress.setToolTipText(String.format("%d / %d files downloaded", 0,
54 mods.size()));
55
56 lblDownloadedVal.setText(SizeFormatter.format(0, 3));
57 lblTotalVal.setText(SizeFormatter.format(downloader.getTotalSize(), 3));
58 }
59
60 private void close() {
61 if (!downloader.isFinished())
62 downloader.abort();
63 setVisible(false);
64 }
65
66 @SuppressWarnings("unused")
67 private boolean confirm() {
68 int res = JOptionPane.showConfirmDialog(this,
69 bundle.getString("abort.text"),
70 bundle.getString("abort.title"), JOptionPane.YES_NO_OPTION,
71 JOptionPane.WARNING_MESSAGE);
72 return res == JOptionPane.YES_OPTION;
73 }
74
75 private String formatTime(int sec) {
76 int min = sec / 60;
77 sec = sec % 60;
78 return String.format("%02d:%02d", min, sec);
79 }
80
81 @Override
82 public void updateStatus(ModDownloader source, State state, int filesDown,
83 int filesTotal, int bytesDown, int bytesTotal, int duration,
84 int remaining, int speed) {
85 if (state == ModDownloader.State.FINISHED) {
86 close();
87 } else {
88 progress.setValue(bytesDown);
89 progress.setToolTipText(String.format("%d / %d files downloaded",
90 filesDown, filesTotal));
91
92 lblElapsedVal.setText(formatTime(duration));
93 lblRemainingVal.setText(formatTime(remaining));
94
95 lblDownloadedVal.setText(SizeFormatter.format(bytesDown, 3));
96
97 lblRateVal.setText(SizeFormatter.format(speed, 3) + "/s");
98 }
99 }
100
101 /**
102 * @return were all downloads finished?
103 */
104 public boolean isFinished() {
105 return downloader.isFinished();
106 }
107
108}
Note: See TracBrowser for help on using the repository browser.