1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.transfer;
21
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24
25 import org.apache.log4j.Logger;
26
27 /***
28 * This class acts as data container for {@link Download} objects.
29 *
30 * <p>The class makes use of the singleton pattern.</p>
31 */
32 public class DownloadManager extends AbstractTransferManager
33 implements PropertyChangeListener
34 {
35
36
37
38
39
40 private static DownloadManager singleton = new DownloadManager();
41
42
43
44 private DownloadManager()
45 {
46 logger = Logger.getLogger(DownloadManager.class);
47
48 prefs.addPropertyChangeListener("limitDownloads", this);
49 prefs.addPropertyChangeListener("maxDownloads", this);
50 prefs.addPropertyChangeListener("autoClearTransfers", this);
51 prefs.addPropertyChangeListener("autoClearTransfersInterval", this);
52
53 updateLimit();
54 }
55
56
57
58 public static DownloadManager getInstance()
59 {
60 return singleton;
61 }
62
63 public synchronized void add(Download d)
64 {
65 super.add(d);
66 }
67
68 public void propertyChange(PropertyChangeEvent e)
69 {
70 updateLimit();
71 }
72
73 public synchronized void remove(Download d)
74 {
75 super.remove(d);
76 }
77
78 private void updateLimit()
79 {
80 getQueue().setMaxSlots(prefs.getLimitDownloads()
81 ? prefs.getMaxDownloads()
82 : Integer.MAX_VALUE);
83 setAutoClearInterval(prefs.getAutoClearTransfers()
84 ? prefs.getAutoClearTransfersInterval()
85 : -1);
86 }
87
88 }