-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtableModel.java
More file actions
88 lines (76 loc) · 2.5 KB
/
tableModel.java
File metadata and controls
88 lines (76 loc) · 2.5 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package FileSystem;
import javax.swing.table.AbstractTableModel;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ArrayList;
/**
* Created by hongjiayong on 16/6/7.
*/
public class tableModel extends AbstractTableModel {
/**
*
*/
private static final long serialVersionUID = 1L;
private ArrayList<Object> content = null;
private String[] title_name = { "文件名", "文件地址", "文件类型", "文件大小/KB", "最近修改时间"};
public tableModel(){
content = new ArrayList<Object>();
}
public void addRow(MyFile myFile){
ArrayList<Object> v = new ArrayList<Object>();
DecimalFormat format=new DecimalFormat("#0.00");
v.add(0, myFile.getFileName());
v.add(1,myFile.getFilePath());
if (myFile.getMyFile().isFile()){
v.add(2, "File");
v.add(3, format.format(myFile.getCapacity()));
}else {
v.add(2, "Directory");
v.add(3, "-");
}
long time = myFile.getMyFile().lastModified();
String ctime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date(time));
v.add(4, ctime);
content.add(v);
}
@SuppressWarnings("unchecked")
public void removeRow(String name) {
for (int i = 0; i < content.size(); i++){
if (((ArrayList<Object>) content.get(i)).get(1).equals(name)){
content.remove(i);
break;
}
}
}
public void removeRows(int row, int count){
for (int i = row+count-1; i >= row; i--){
content.remove(i);
}
}
@Override
public void setValueAt(Object value, int rowIndex, int colIndex){
((ArrayList<Object>) content.get(rowIndex)).remove(colIndex);
((ArrayList<Object>) content.get(rowIndex)).add(colIndex, value);
this.fireTableCellUpdated(rowIndex, colIndex);
}
public String getColumnName(int col) {
return title_name[col];
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex){
return false;
}
@Override
public int getRowCount() {
return content.size();
}
@Override
public int getColumnCount() {
return title_name.length;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return ((ArrayList<Object>) content.get(rowIndex)).get(columnIndex);
}
}