gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / zipviewer / ZipTableModel.java @ 2937
History | View | Annotate | Download (2.06 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.tools.swing.impl.zipviewer; |
7 |
|
8 |
import java.util.Date; |
9 |
import java.util.List; |
10 |
import java.util.zip.ZipEntry; |
11 |
import javax.swing.table.AbstractTableModel; |
12 |
|
13 |
/**
|
14 |
*
|
15 |
* @author jjdelcerro
|
16 |
*/
|
17 |
public class ZipTableModel extends AbstractTableModel { |
18 |
|
19 |
public static final int NAME = 0; |
20 |
|
21 |
public static final int SIZE = 1; |
22 |
|
23 |
public static final int COMP_SIZE = 2; |
24 |
|
25 |
public static final int TYPE = 3; |
26 |
|
27 |
public static final int LAST_MODI = 4; |
28 |
|
29 |
public String[] m_colNames = {"File Name", "Size", "Compressed Size", "Type", "Last Modified"}; |
30 |
|
31 |
private List m_zipEntries; |
32 |
|
33 |
public ZipTableModel(List zipEntries) { |
34 |
super();
|
35 |
m_zipEntries = zipEntries; |
36 |
} |
37 |
|
38 |
public int getColumnCount() { |
39 |
return m_colNames.length;
|
40 |
} |
41 |
|
42 |
public int getRowCount() { |
43 |
|
44 |
return m_zipEntries.size();
|
45 |
} |
46 |
|
47 |
public String getColumnName(int col) { |
48 |
return m_colNames[col];
|
49 |
} |
50 |
|
51 |
public Object getValueAt(int row, int col) { |
52 |
ZipEntry zipEntry = (ZipEntry) (m_zipEntries.get(row)); |
53 |
switch (col) {
|
54 |
case NAME:
|
55 |
return zipEntry.getName();
|
56 |
case SIZE:
|
57 |
if (zipEntry.isDirectory()) {
|
58 |
return ""; |
59 |
} else {
|
60 |
return String.valueOf(zipEntry.getSize() / 1000) + " KB"; |
61 |
} |
62 |
case COMP_SIZE:
|
63 |
if (zipEntry.isDirectory()) {
|
64 |
return ""; |
65 |
} else {
|
66 |
return String.valueOf(zipEntry.getCompressedSize() / 1000) + " KB"; |
67 |
} |
68 |
case TYPE:
|
69 |
if (zipEntry.isDirectory()) {
|
70 |
return "Directory"; |
71 |
} else {
|
72 |
return "File"; |
73 |
} |
74 |
case LAST_MODI:
|
75 |
return String.valueOf(new Date(zipEntry.getTime())); |
76 |
} |
77 |
return new String(); |
78 |
} |
79 |
} |