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

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 base.jdbs.ConfigurationManager;
32 import base.util.FileUtil;
33  
34 /**
35  * @author skunk
36  *
37  */
38 @SuppressWarnings("serial")
39 public class RepositoryStatisticPanel extends JPanel implements Observer {
40  
410    private final String USED_SPACE = "Used Space: ";
420 
430    private final String DECLARED_AVAILABLE_SPACE = "Declared Available Space: ";
440 
450    private final String HOSTED_ARTIFACT_COUNT = "Hosted Artifacts: ";
46  
470    private final String AVERAGE_ARTIFACT_SIZE_COUNT = "Average Artifact Size: ";
48  
49     private JLabel usedSpaceLabel;
50  
510    private JLabel declaredAvailableSpaceLabel;
520 
530    private JLabel hostedArtifactCountLabel;
540 
55     private JLabel averageArtifactSizeLabel;
56  
570    public RepositoryStatisticPanel() {
580        initialize();
590        ConfigurationManager.getInstance().getRepository().addObserver(this);
600    }
610 
620    protected void initialize() {
630        this.setBorder(new TitledBorder("Utilizzation Statistics"));
640        this.setLayout(new GridLayout(2, 2));
650        this.add(this.getUsedSpaceLabel());
660        this.add(this.getDeclaredAvailableSpaceLabel());
670        this.add(this.getHostedArtifactCountLabel());
680        this.add(this.getAverageArtifactSizeLabel());
690    }
700 
71     public void update(Observable arg0, Object arg1) {
720        this.getUsedSpaceLabel().setText(
730                USED_SPACE
740                        + FileUtil.fileSizeInMB(ConfigurationManager
750                                .getInstance().getRepository().getLocation())
76                         + " Mb");
770        this.getDeclaredAvailableSpaceLabel().setText(
780                DECLARED_AVAILABLE_SPACE
79                         + (ConfigurationManager.getInstance().getRepository()
80                                 .getDeclaredAvailableSpace() - FileUtil
810                                .fileSizeInMB(ConfigurationManager
82                                         .getInstance().getRepository()
83                                         .getLocation())) + " Mb");
840        this.getHostedArtifactCountLabel().setText(
850                HOSTED_ARTIFACT_COUNT
860                        + ConfigurationManager.getInstance().getRepository()
87                                 .getBackupDescriptor().length);
880        String labelText = AVERAGE_ARTIFACT_SIZE_COUNT;
890        if (ConfigurationManager.getInstance().getRepository()
900                .getBackupDescriptor().length > 0) {
910            long size = 0;
920            for (int i = 0; i < ConfigurationManager.getInstance()
930                    .getRepository().getBackupDescriptor().length; i++)
940                size += FileUtil.fileSizeInKB(ConfigurationManager
950                        .getInstance().getRepository().getBackupDescriptor()[i]
96                         .getBackupFile());
970            labelText += (size / ConfigurationManager.getInstance()
980                    .getRepository().getBackupDescriptor().length)
990                    + " Kb";
100         }
1010        this.getAverageArtifactSizeLabel().setText(labelText);
1020    }
1030 
104     /**
1050     * @return Returns the averageArtifactSizeLabel.
1060     */
1070    protected JLabel getAverageArtifactSizeLabel() {
1080        if (this.averageArtifactSizeLabel == null) {
1090            String labelText = AVERAGE_ARTIFACT_SIZE_COUNT;
1100            if (ConfigurationManager.getInstance().getRepository()
1110                    .getBackupDescriptor().length > 0) {
1120                long size = 0;
1130                for (int i = 0; i < ConfigurationManager.getInstance()
1140                        .getRepository().getBackupDescriptor().length; i++)
1150                    size += FileUtil.fileSizeInKB(ConfigurationManager
116                             .getInstance().getRepository()
117                             .getBackupDescriptor()[i].getBackupFile());
1180                labelText += (size / ConfigurationManager.getInstance()
1190                        .getRepository().getBackupDescriptor().length)
120                         + " Kb";
1210            }
1220            this.averageArtifactSizeLabel = new JLabel(labelText);
1230        }
1240        return averageArtifactSizeLabel;
1250    }
126  
127     /**
1280     * @return Returns the declaredAvailableSpaceLabel.
1290     */
130     protected JLabel getDeclaredAvailableSpaceLabel() {
1310        if (this.declaredAvailableSpaceLabel == null) {
1320            this.declaredAvailableSpaceLabel = new JLabel(
133                     DECLARED_AVAILABLE_SPACE
134                             + (ConfigurationManager.getInstance()
135                                     .getRepository()
136                                     .getDeclaredAvailableSpace() - FileUtil
137                                     .fileSizeInMB(ConfigurationManager
1380                                            .getInstance().getRepository()
139                                             .getLocation())) + " Mb");
140         }
1410        return declaredAvailableSpaceLabel;
142     }
143  
144     /**
1450     * @return Returns the hostedArtifactCountLabel.
1460     */
147     protected JLabel getHostedArtifactCountLabel() {
1480        if (this.hostedArtifactCountLabel == null) {
1490            this.hostedArtifactCountLabel = new JLabel(HOSTED_ARTIFACT_COUNT
1500                    + ConfigurationManager.getInstance().getRepository()
151                             .getBackupDescriptor().length);
152         }
1530        return hostedArtifactCountLabel;
154     }
155  
156     /**
1570     * @return Returns the usedSpaceLabel.
1580     */
159     protected JLabel getUsedSpaceLabel() {
1600        if (this.usedSpaceLabel == null) {
1610            this.usedSpaceLabel = new JLabel(USED_SPACE
1620                    + FileUtil.fileSizeInMB(ConfigurationManager.getInstance()
163                             .getRepository().getLocation()) + " Mb");
164         }
1650        return usedSpaceLabel;
166     }
167 }

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.