| Line | Hits | Source |
|---|---|---|
| 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 | */ | |
| 39 | 0 | @SuppressWarnings("serial") |
| 40 | public class FileStatisticPanel extends JPanel implements Observer { | |
| 41 | 0 | |
| 42 | 0 | private static final transient Logger logger = Logger |
| 43 | 0 | .getLogger(FileStatisticPanel.class.getName()); |
| 44 | 0 | |
| 45 | 0 | private final String TOTAL_FILE_COUNT = "Total Files: "; |
| 46 | ||
| 47 | 0 | private final String TOTAL_FILE_SIZE = "Total Size: "; |
| 48 | ||
| 49 | 0 | private final String AVG_FILE_SIZE = "Average File Size: "; |
| 50 | ||
| 51 | private JLabel totalFileLabel; | |
| 52 | ||
| 53 | 0 | private JLabel totalFileSizeLabel; |
| 54 | 0 | |
| 55 | 0 | private JLabel avgFileSizeLabel; |
| 56 | 0 | |
| 57 | 0 | private final Backup backup; |
| 58 | ||
| 59 | 0 | public FileStatisticPanel(Backup backup) { |
| 60 | 0 | this.backup = backup; |
| 61 | 0 | this.backup.addObserver(this); |
| 62 | 0 | initialize(); |
| 63 | 0 | } |
| 64 | 0 | |
| 65 | 0 | protected void initialize() { |
| 66 | 0 | this.setBorder(new TitledBorder("File Statistics")); |
| 67 | 0 | this.setLayout(new GridLayout(1, 3)); |
| 68 | 0 | this.add(this.getTotalFileLabel()); |
| 69 | 0 | this.add(this.getTotalFileSizeLabel()); |
| 70 | 0 | this.add(this.getAvgFileSizeLabel()); |
| 71 | 0 | } |
| 72 | 0 | |
| 73 | 0 | public void update(Observable arg0, Object arg1) { |
| 74 | 0 | if (backup.getFileDescriptor().length > 0) { |
| 75 | 0 | long totalSize = 0; |
| 76 | 0 | for (int i = 0; i < backup.getFileDescriptor().length; i++) |
| 77 | 0 | totalSize += backup.getFileDescriptor()[i].getSize(); |
| 78 | 0 | this.getTotalFileLabel().setText( |
| 79 | TOTAL_FILE_COUNT + backup.getFileDescriptor().length); | |
| 80 | 0 | this.getTotalFileSizeLabel().setText( |
| 81 | TOTAL_FILE_SIZE + totalSize + " Kb"); | |
| 82 | 0 | this.getAvgFileSizeLabel().setText( |
| 83 | 0 | AVG_FILE_SIZE |
| 84 | 0 | + (totalSize / backup.getFileDescriptor().length) |
| 85 | 0 | + " Kb"); |
| 86 | 0 | } |
| 87 | 0 | } |
| 88 | 0 | |
| 89 | /** | |
| 90 | 0 | * @return Returns the avgFileSizeLabel. |
| 91 | */ | |
| 92 | protected JLabel getAvgFileSizeLabel() { | |
| 93 | 0 | if (this.avgFileSizeLabel == null) { |
| 94 | 0 | long totalSize = 0; |
| 95 | 0 | for (int i = 0; i < backup.getFileDescriptor().length; i++) |
| 96 | 0 | totalSize += backup.getFileDescriptor()[i].getSize(); |
| 97 | 0 | String labelText = AVG_FILE_SIZE; |
| 98 | 0 | if (backup.getFileDescriptor().length > 0) |
| 99 | 0 | labelText += (totalSize / backup.getFileDescriptor().length) |
| 100 | 0 | + " Kb"; |
| 101 | 0 | |
| 102 | 0 | this.avgFileSizeLabel = new JLabel(labelText); |
| 103 | 0 | |
| 104 | } | |
| 105 | 0 | return avgFileSizeLabel; |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * @return Returns the totalFileLabel. | |
| 110 | 0 | */ |
| 111 | 0 | protected JLabel getTotalFileLabel() { |
| 112 | 0 | if (this.totalFileLabel == null) { |
| 113 | 0 | this.totalFileLabel = new JLabel(TOTAL_FILE_COUNT |
| 114 | 0 | + backup.getFileDescriptor().length); |
| 115 | } | |
| 116 | 0 | return totalFileLabel; |
| 117 | } | |
| 118 | ||
| 119 | /** | |
| 120 | * @return Returns the totalFileSizeLabel. | |
| 121 | */ | |
| 122 | protected JLabel getTotalFileSizeLabel() { | |
| 123 | 0 | if (this.totalFileSizeLabel == null) { |
| 124 | 0 | long totalSize = 0; |
| 125 | 0 | for (int i = 0; i < backup.getFileDescriptor().length; i++) |
| 126 | 0 | totalSize += backup.getFileDescriptor()[i].getSize(); |
| 127 | 0 | this.totalFileSizeLabel = new JLabel(TOTAL_FILE_SIZE + totalSize |
| 128 | + " Kb"); | |
| 129 | } | |
| 130 | 0 | return totalFileSizeLabel; |
| 131 | } | |
| 132 | ||
| 133 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |