Coverage details for base.jdbs.ui.FileTableModel

LineHitsSource
1 /*******************************************************************************
2  *InternetCafe is a software solution that helps the management of Cybercafes
3  * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4  * Copyright (C) 2006 Guido Angelo Ingenito
5  
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *******************************************************************************/
20  
21 package base.jdbs.ui;
22  
23 import java.util.Observable;
24 import java.util.Observer;
25  
26 import javax.swing.table.AbstractTableModel;
27  
28 import org.apache.log4j.Logger;
29  
30 import base.jdbs.Backup;
31  
32 @SuppressWarnings("serial")
330public class FileTableModel extends AbstractTableModel implements Observer {
34     
350    private static final transient Logger logger = Logger.getLogger(AbstractTableModel.class.getName());
36  
370    private String[] columnNames = {"Absolute Path","File Name","Type","Size (Kb)"};
38  
39     public static final int FILE_ABSOLUTE_PATH_COLUMN = 0;
40  
41     public static final int FILE_NAME_COLUMN = 1;
42  
43     public static final int FILE_TYPE_COLUMN = 2;
44  
45     public static final int FILE_SIZE_COLUMN = 3;
46  
47     private final Backup backup;
48     
49  
500    public FileTableModel(Backup backup) {
510        this.backup = backup;
520        this.backup.addObserver(this);
530    }
54  
55     public int getColumnCount() {
560        return columnNames.length;
57     }
58  
59     public int getRowCount() {
600        return backup.getFileDescriptor().length;
61     }
62  
63     public String getColumnName(int column) {
640        return columnNames[column];
65     }
66  
67     public Object getValueAt(int row, int column) {
680        if (row < 0 || column < 0)
690            return null;
700        Object result = null;
710        switch (column) {
72         case FILE_ABSOLUTE_PATH_COLUMN:
730            result = backup.getFileDescriptor()[row].getFile().getAbsolutePath();
740            break;
75         case FILE_NAME_COLUMN:
760            result = backup.getFileDescriptor()[row].getFile().getName();
770            break;
78         case FILE_TYPE_COLUMN:
790            String name = backup.getFileDescriptor()[row].getFile().getName();
800            if(name.lastIndexOf(".") > 0)
810                result = name.substring(name.lastIndexOf("."),name.length()).toUpperCase();
820            else result = "";
830            break;
84         case FILE_SIZE_COLUMN:
850            result = backup.getFileDescriptor()[row].getSize();
86             break;
87         }
880        return result;
89     }
90  
91     @SuppressWarnings("unchecked")
92     public Class getColumnClass(int column) {
930        Class result = null;
940        switch (column) {
95         case FILE_ABSOLUTE_PATH_COLUMN:
960            result = String.class;
970            break;
98         case FILE_NAME_COLUMN:
990            result = String.class;
1000            break;
101         case FILE_TYPE_COLUMN:
1020            result = String.class;
1030            break;
104         case FILE_SIZE_COLUMN:
1050            result = Long.class;
106             break;
107         }
1080        return result;
109     }
110  
111     public void update(Observable arg0, Object arg1) {
1120        this.fireTableDataChanged();
1130    }
114  
115 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.