ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/java/installer2/src/net/oni2/aeinstaller/gui/downloadwindow/Downloader.java
Revision: 605
Committed: Sun Jan 13 19:11:07 2013 UTC (12 years, 9 months ago) by alloc
Content type: text/x-java
Original Path: AE/installer2/src/net/oni2/aeinstaller/gui/downloadwindow/Downloader.java
File size: 3185 byte(s)
Log Message:
AEI2:
- Added mod download prior to installation
- Dependency checking (needs verification)
- Conflicts checking basis (not implemented)
- Run Oni through AEI

File Contents

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