01: package snow.files;
02:
03: import snow.utils.storage.FileUtils;
04: import snow.utils.DateUtils;
05: import snow.sortabletable.*;
06: import java.util.*;
07:
08: public class JFilesTableModel extends FineGrainTableModel {
09: final List<JFile> hits;
10:
11: public JFilesTableModel(List<JFile> hits) {
12: this .hits = hits;
13: }
14:
15: public JFile getHitAt(int row) {
16: return hits.get(row);
17: }
18:
19: public Object getValueAt(int row, int col) {
20: if (col == 0)
21: return hits.get(row).relName;
22: if (col == 1) {
23: return DateUtils.formatTimeDifference(System
24: .currentTimeMillis()
25: - hits.get(row).lastModified);
26: }
27: return FileUtils.formatSize(hits.get(row).length);
28: }
29:
30: public int getRowCount() {
31: return hits.size();
32: }
33:
34: public int getColumnCount() {
35: return 3;
36: }
37:
38: @Override
39: public String getColumnName(int c) {
40: if (c == 0)
41: return "File";
42: if (c == 1)
43: return "Age";
44: return "Size";
45: }
46:
47: @Override
48: public int getPreferredColumnWidth(int column) {
49: if (column == 1)
50: return 4;
51: if (column == 2)
52: return 4;
53: return 25;
54: }
55:
56: @Override
57: public int compareForColumnSort(int pos1, int pos2, int col) {
58: if (col == 1) {
59: long a1 = System.currentTimeMillis()
60: - hits.get(pos1).lastModified;
61: long a2 = System.currentTimeMillis()
62: - hits.get(pos2).lastModified;
63: return Long.valueOf(a1).compareTo(a2);
64: }
65:
66: if (col == 2) {
67: long s1 = hits.get(pos1).length;
68: long s2 = hits.get(pos2).length;
69: return Long.valueOf(s1).compareTo(s2);
70: }
71: return super.compareForColumnSort(pos1, pos2, col);
72: }
73:
74: }
|