Coverage details for base.jdbs.ui.panel.FileStatisticPanel

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.panel;
22  
23 import java.awt.GridLayout;
24 import java.util.Observable;
25 import java.util.Observer;
26  
27 import javax.swing.JLabel;
28 import javax.swing.JPanel;
29 import javax.swing.border.TitledBorder;
30  
31 import org.apache.log4j.Logger;
32  
33 import base.jdbs.Backup;
34  
35 /**
36  * @author skunk
37  *
38  */
390@SuppressWarnings("serial")
40 public class FileStatisticPanel extends JPanel implements Observer {
410 
420    private static final transient Logger logger = Logger
430            .getLogger(FileStatisticPanel.class.getName());
440 
450    private final String TOTAL_FILE_COUNT = "Total Files: ";
46  
470    private final String TOTAL_FILE_SIZE = "Total Size: ";
48  
490    private final String AVG_FILE_SIZE = "Average File Size: ";
50  
51     private JLabel totalFileLabel;
52  
530    private JLabel totalFileSizeLabel;
540 
550    private JLabel avgFileSizeLabel;
560 
570    private final Backup backup;
58  
590    public FileStatisticPanel(Backup backup) {
600        this.backup = backup;
610        this.backup.addObserver(this);
620        initialize();
630    }
640 
650    protected void initialize() {
660        this.setBorder(new TitledBorder("File Statistics"));
670        this.setLayout(new GridLayout(1, 3));
680        this.add(this.getTotalFileLabel());
690        this.add(this.getTotalFileSizeLabel());
700        this.add(this.getAvgFileSizeLabel());
710    }
720 
730    public void update(Observable arg0, Object arg1) {
740        if (backup.getFileDescriptor().length > 0) {
750            long totalSize = 0;
760            for (int i = 0; i < backup.getFileDescriptor().length; i++)
770                totalSize += backup.getFileDescriptor()[i].getSize();
780            this.getTotalFileLabel().setText(
79                     TOTAL_FILE_COUNT + backup.getFileDescriptor().length);
800            this.getTotalFileSizeLabel().setText(
81                     TOTAL_FILE_SIZE + totalSize + " Kb");
820            this.getAvgFileSizeLabel().setText(
830                    AVG_FILE_SIZE
840                            + (totalSize / backup.getFileDescriptor().length)
850                            + " Kb");
860        }
870    }
880 
89     /**
900     * @return Returns the avgFileSizeLabel.
91      */
92     protected JLabel getAvgFileSizeLabel() {
930        if (this.avgFileSizeLabel == null) {
940            long totalSize = 0;
950            for (int i = 0; i < backup.getFileDescriptor().length; i++)
960                totalSize += backup.getFileDescriptor()[i].getSize();
970            String labelText = AVG_FILE_SIZE;
980            if (backup.getFileDescriptor().length > 0)
990                labelText += (totalSize / backup.getFileDescriptor().length)
1000                        + " Kb";
1010 
1020            this.avgFileSizeLabel = new JLabel(labelText);
1030 
104         }
1050        return avgFileSizeLabel;
106     }
107  
108     /**
109      * @return Returns the totalFileLabel.
1100     */
1110    protected JLabel getTotalFileLabel() {
1120        if (this.totalFileLabel == null) {
1130            this.totalFileLabel = new JLabel(TOTAL_FILE_COUNT
1140                    + backup.getFileDescriptor().length);
115         }
1160        return totalFileLabel;
117     }
118  
119     /**
120      * @return Returns the totalFileSizeLabel.
121      */
122     protected JLabel getTotalFileSizeLabel() {
1230        if (this.totalFileSizeLabel == null) {
1240            long totalSize = 0;
1250            for (int i = 0; i < backup.getFileDescriptor().length; i++)
1260                totalSize += backup.getFileDescriptor()[i].getSize();
1270            this.totalFileSizeLabel = new JLabel(TOTAL_FILE_SIZE + totalSize
128                     + " Kb");
129         }
1300        return totalFileSizeLabel;
131     }
132  
133 }

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.