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 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 | ||
41 | 0 | private final String USED_SPACE = "Used Space: "; |
42 | 0 | |
43 | 0 | private final String DECLARED_AVAILABLE_SPACE = "Declared Available Space: "; |
44 | 0 | |
45 | 0 | private final String HOSTED_ARTIFACT_COUNT = "Hosted Artifacts: "; |
46 | ||
47 | 0 | private final String AVERAGE_ARTIFACT_SIZE_COUNT = "Average Artifact Size: "; |
48 | ||
49 | private JLabel usedSpaceLabel; | |
50 | ||
51 | 0 | private JLabel declaredAvailableSpaceLabel; |
52 | 0 | |
53 | 0 | private JLabel hostedArtifactCountLabel; |
54 | 0 | |
55 | private JLabel averageArtifactSizeLabel; | |
56 | ||
57 | 0 | public RepositoryStatisticPanel() { |
58 | 0 | initialize(); |
59 | 0 | ConfigurationManager.getInstance().getRepository().addObserver(this); |
60 | 0 | } |
61 | 0 | |
62 | 0 | protected void initialize() { |
63 | 0 | this.setBorder(new TitledBorder("Utilizzation Statistics")); |
64 | 0 | this.setLayout(new GridLayout(2, 2)); |
65 | 0 | this.add(this.getUsedSpaceLabel()); |
66 | 0 | this.add(this.getDeclaredAvailableSpaceLabel()); |
67 | 0 | this.add(this.getHostedArtifactCountLabel()); |
68 | 0 | this.add(this.getAverageArtifactSizeLabel()); |
69 | 0 | } |
70 | 0 | |
71 | public void update(Observable arg0, Object arg1) { | |
72 | 0 | this.getUsedSpaceLabel().setText( |
73 | 0 | USED_SPACE |
74 | 0 | + FileUtil.fileSizeInMB(ConfigurationManager |
75 | 0 | .getInstance().getRepository().getLocation()) |
76 | + " Mb"); | |
77 | 0 | this.getDeclaredAvailableSpaceLabel().setText( |
78 | 0 | DECLARED_AVAILABLE_SPACE |
79 | + (ConfigurationManager.getInstance().getRepository() | |
80 | .getDeclaredAvailableSpace() - FileUtil | |
81 | 0 | .fileSizeInMB(ConfigurationManager |
82 | .getInstance().getRepository() | |
83 | .getLocation())) + " Mb"); | |
84 | 0 | this.getHostedArtifactCountLabel().setText( |
85 | 0 | HOSTED_ARTIFACT_COUNT |
86 | 0 | + ConfigurationManager.getInstance().getRepository() |
87 | .getBackupDescriptor().length); | |
88 | 0 | String labelText = AVERAGE_ARTIFACT_SIZE_COUNT; |
89 | 0 | if (ConfigurationManager.getInstance().getRepository() |
90 | 0 | .getBackupDescriptor().length > 0) { |
91 | 0 | long size = 0; |
92 | 0 | for (int i = 0; i < ConfigurationManager.getInstance() |
93 | 0 | .getRepository().getBackupDescriptor().length; i++) |
94 | 0 | size += FileUtil.fileSizeInKB(ConfigurationManager |
95 | 0 | .getInstance().getRepository().getBackupDescriptor()[i] |
96 | .getBackupFile()); | |
97 | 0 | labelText += (size / ConfigurationManager.getInstance() |
98 | 0 | .getRepository().getBackupDescriptor().length) |
99 | 0 | + " Kb"; |
100 | } | |
101 | 0 | this.getAverageArtifactSizeLabel().setText(labelText); |
102 | 0 | } |
103 | 0 | |
104 | /** | |
105 | 0 | * @return Returns the averageArtifactSizeLabel. |
106 | 0 | */ |
107 | 0 | protected JLabel getAverageArtifactSizeLabel() { |
108 | 0 | if (this.averageArtifactSizeLabel == null) { |
109 | 0 | String labelText = AVERAGE_ARTIFACT_SIZE_COUNT; |
110 | 0 | if (ConfigurationManager.getInstance().getRepository() |
111 | 0 | .getBackupDescriptor().length > 0) { |
112 | 0 | long size = 0; |
113 | 0 | for (int i = 0; i < ConfigurationManager.getInstance() |
114 | 0 | .getRepository().getBackupDescriptor().length; i++) |
115 | 0 | size += FileUtil.fileSizeInKB(ConfigurationManager |
116 | .getInstance().getRepository() | |
117 | .getBackupDescriptor()[i].getBackupFile()); | |
118 | 0 | labelText += (size / ConfigurationManager.getInstance() |
119 | 0 | .getRepository().getBackupDescriptor().length) |
120 | + " Kb"; | |
121 | 0 | } |
122 | 0 | this.averageArtifactSizeLabel = new JLabel(labelText); |
123 | 0 | } |
124 | 0 | return averageArtifactSizeLabel; |
125 | 0 | } |
126 | ||
127 | /** | |
128 | 0 | * @return Returns the declaredAvailableSpaceLabel. |
129 | 0 | */ |
130 | protected JLabel getDeclaredAvailableSpaceLabel() { | |
131 | 0 | if (this.declaredAvailableSpaceLabel == null) { |
132 | 0 | this.declaredAvailableSpaceLabel = new JLabel( |
133 | DECLARED_AVAILABLE_SPACE | |
134 | + (ConfigurationManager.getInstance() | |
135 | .getRepository() | |
136 | .getDeclaredAvailableSpace() - FileUtil | |
137 | .fileSizeInMB(ConfigurationManager | |
138 | 0 | .getInstance().getRepository() |
139 | .getLocation())) + " Mb"); | |
140 | } | |
141 | 0 | return declaredAvailableSpaceLabel; |
142 | } | |
143 | ||
144 | /** | |
145 | 0 | * @return Returns the hostedArtifactCountLabel. |
146 | 0 | */ |
147 | protected JLabel getHostedArtifactCountLabel() { | |
148 | 0 | if (this.hostedArtifactCountLabel == null) { |
149 | 0 | this.hostedArtifactCountLabel = new JLabel(HOSTED_ARTIFACT_COUNT |
150 | 0 | + ConfigurationManager.getInstance().getRepository() |
151 | .getBackupDescriptor().length); | |
152 | } | |
153 | 0 | return hostedArtifactCountLabel; |
154 | } | |
155 | ||
156 | /** | |
157 | 0 | * @return Returns the usedSpaceLabel. |
158 | 0 | */ |
159 | protected JLabel getUsedSpaceLabel() { | |
160 | 0 | if (this.usedSpaceLabel == null) { |
161 | 0 | this.usedSpaceLabel = new JLabel(USED_SPACE |
162 | 0 | + FileUtil.fileSizeInMB(ConfigurationManager.getInstance() |
163 | .getRepository().getLocation()) + " Mb"); | |
164 | } | |
165 | 0 | return usedSpaceLabel; |
166 | } | |
167 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |