-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadsTableModel.java
More file actions
66 lines (51 loc) · 1.6 KB
/
Copy pathDownloadsTableModel.java
File metadata and controls
66 lines (51 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
class DownloadsTableModel extends AbstractTableModel implements Observer {
private static final String[] columnNames = {"URL", "Size", "Progress", "Status"};
private static final Class[] columnClasses = {String.class, String.class, JProgressBar.class, String.class};
private ArrayList<Download> downloadList = new ArrayList<Download>();
public void addDownload(Download download) {
download.addObserver(this);
downloadList.add(download);
fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
}
public Download getDownload(int row) {
return downloadList.get(row);
}
public void clearDownload(int row) {
downloadList.remove(row);
fireTableRowsDeleted(row, row);
}
public int getColumnCount() {
return columnNames.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Class getColumnClass(int col) {
return columnClasses[col];
}
public int getRowCount() {
return downloadList.size();
}
public Object getValueAt(int row, int col) {
Download download = downloadList.get(row);
switch(col) {
case 0:
return download.getUrl();
case 1:
int size = download.getSize();
return (size == -1) ? "" : Integer.toString(size);
case 2:
return new Float(download.getProgress());
case 3:
return Download.STATUSES[download.getStatus()];
}
return "";
}
public void update(Observable o, Object arg) {
int index = downloadList.indexOf(o);
fireTableRowsUpdated(index, index);
}
}