View Javadoc
1 /*** 2 * StatisticView.java 3 * 4 * Project: Dependency Tool 5 * 6 * WHEN WHO WHAT 7 * 06.06.2003 pko initial public release 8 * 22.01.2002 ctr modification 9 * 08.01.2002 ctr creation 10 * 11 * Copyright 2003 ELCA Informatique SA 12 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland 13 * www.elca.ch 14 * 15 * This library is free software; you can redistribute it and/or 16 * modify it under the terms of the GNU Lesser General Public License 17 * as published by the Free Software Foundation; either version 2.1 of 18 * the License, or (at your option) any later version. 19 * 20 * This library is distributed in the hope that it will be useful, but 21 * WITHOUT ANY WARRANTY; without even the implied warranty of 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 * Lesser General Public License for more details. 24 * 25 * You should have received a copy of the GNU Lesser General Public 26 * License along with this library; if not, write to the Free Software 27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 28 * USA 29 */ 30 31 package ch.elca.dependency.view; 32 33 import ch.elca.dependency.core.DependencyModel; 34 import ch.elca.dependency.core.Statistic; 35 36 import java.awt.*; 37 import java.util.ArrayList; 38 import java.util.ListIterator; 39 import javax.swing.*; 40 import javax.swing.border.*; 41 42 import info.clearthought.layout.TableLayout; 43 44 /*** 45 * A view class for diplaying the statistic data representation of the 46 * analyzed project. The display method of the <code>View</code> 47 * superclass is impemented in this specific view. This method is 48 * responsible for getting the needed data from the model and then 49 * show this actual data to the user.<br> All the user interaction 50 * which concerns only this view is also managed by this class. 51 * 52 * @see ch.elca.dependency.view.View 53 * 54 * @author Christoph Trutmann 55 * @version 1.0-beta 56 */ 57 public class StatisticView extends View { 58 59 60 private final static String FRAME_TITLE = "Statistics View"; 61 62 /*** 63 * Project '#classes' label for adjusting the text. 64 */ 65 private JLabel m_projClasses; 66 67 /*** 68 * Project '#packages' label for adjusting the text. 69 */ 70 private JLabel m_projPackages; 71 72 /*** 73 * Project '#library packages' label for adjusting the text. 74 */ 75 private JLabel m_projLibPack; 76 77 /*** 78 * Project 'biggest package' label for adjusting the text. 79 */ 80 private JLabel m_biggestProjPackage; 81 82 /*** 83 * Project 'average # of classes' label for adjusting the text. 84 */ 85 private JLabel m_averageProjClasses; 86 87 /*** 88 * Analyzed '#classes' label for adjusting the text. 89 */ 90 private JLabel m_analyzedClasses; 91 92 /*** 93 * Analyzed '#packages' label for adjusting the text. 94 */ 95 private JLabel m_analyzedPackages; 96 97 /*** 98 * Analyzed '#library packages' label for adjusting the text. 99 */ 100 private JLabel m_analyzedLibPack; 101 102 /*** 103 * Analyzed 'biggest package' label for adjusting the text. 104 */ 105 private JLabel m_biggestAnalyzedPackage; 106 107 /*** 108 * Analyzed 'average # of classes' label for adjusting the text. 109 */ 110 private JLabel m_averageAnalyzedClasses; 111 112 /*** 113 * 'uses' label for adjusting the text. 114 */ 115 private JLabel m_usesDependencies; 116 117 /*** 118 * Default Font for displaying the statistic data. 119 */ 120 private Font m_statFont = new Font("SansSerif", Font.PLAIN, 12); 121 122 123 124 /*** 125 * Constructor - Makes a <code>JInternalFrame</code> with the specified 126 * parameters. 127 */ 128 public StatisticView(DependencyModel dependencyModel) { 129 super(dependencyModel, FRAME_TITLE); 130 setDefaultBounds(new Rectangle(665, 4, 547, 429)); 131 recallConfig(); 132 133 int border = 10; 134 double fill = TableLayout.FILL; 135 double pref = TableLayout.PREFERRED; 136 double size[][] = 137 {{fill}, // Columns 138 {pref, pref}}; // Rows 139 140 // create the edged border type for the whole dialog 141 Border compound = BorderFactory. 142 createCompoundBorder(BorderFactory.createEmptyBorder(border,border, 143 border, border), 144 BorderFactory.createEtchedBorder()); 145 146 getContentPane().setLayout(new TableLayout(size)); 147 148 // make the project panel 149 ArrayList projectList = new ArrayList(); 150 m_projClasses = new JLabel(); 151 projectList.add(createStatEntry( 152 "#classes of project:", m_projClasses)); 153 m_projPackages = new JLabel(); 154 projectList.add(createStatEntry( 155 "#packages of project", m_projPackages)); 156 m_biggestProjPackage = new JLabel(); 157 projectList.add(createStatEntry("biggest package (max # classes)", 158 m_biggestProjPackage)); 159 m_averageProjClasses = new JLabel(); 160 projectList.add(createStatEntry("average classes per package", 161 m_averageProjClasses)); 162 163 JPanel projPanel 164 = createStatPanel(" Total in Project ", projectList, compound); 165 166 this.getContentPane().add(projPanel, "0, 0, F, F"); 167 168 // make the analyzed panel 169 ArrayList analyzedList = new ArrayList(); 170 m_analyzedClasses = new JLabel(); 171 analyzedList.add(createStatEntry( 172 "#classes of project:", m_analyzedClasses)); 173 m_analyzedPackages = new JLabel(); 174 analyzedList.add(createStatEntry( 175 "#packages of project", m_analyzedPackages)); 176 m_analyzedLibPack = new JLabel(); 177 analyzedList.add(createStatEntry( 178 "#library packages", m_analyzedLibPack)); 179 180 181 m_biggestAnalyzedPackage = new JLabel(); 182 analyzedList.add(createStatEntry("biggest package (max # classes)", 183 m_biggestAnalyzedPackage)); 184 m_averageAnalyzedClasses = new JLabel(); 185 analyzedList.add(createStatEntry("average classes per package", 186 m_averageAnalyzedClasses)); 187 m_usesDependencies = new JLabel(); 188 analyzedList.add(createStatEntry( 189 "# 'uses' dependencies (libraries included)", m_usesDependencies)); 190 191 JPanel analyzedPanel 192 = createStatPanel(" Displayed in Views " 193 , analyzedList, compound); 194 195 this.getContentPane().add(analyzedPanel, "0, 1, F, F"); 196 197 this.setBackground(analyzedPanel.getBackground()); 198 199 // set the parameters of the internal frame 200 this.setSize(this.getPreferredSize()); 201 this.setMinimumSize(this.getPreferredSize()); 202 this.validate(); 203 this.setVisible(true); 204 } 205 206 /*** 207 * This is the implementation of the superclass' abstract 208 * method. This class doesn't need any functionality to be 209 * implemented here. 210 */ 211 protected void internalInitData() { 212 // 213 // deliberately left empty 214 // 215 } 216 217 /*** 218 * This is the implementation of the superclass' abstract 219 * method. This class doesn't need any functionality to be 220 * implemented here. 221 */ 222 protected void initView() { 223 // 224 // deliberately left empty 225 // 226 } 227 228 /*** 229 * Displays the <code>StatisticView</code> after the data has changed. 230 * This mehtod is individually implemented in each view. 231 */ 232 public void display() { 233 // get the statistic data from the model 234 Statistic statistic = m_dependencyModel.getFilteredStatistic(); 235 236 // update the text of the project statistic labels 237 m_projClasses.setText(String.valueOf(statistic.getProjClasses())); 238 m_projPackages.setText(String.valueOf(statistic.getProjPackages())); 239 m_biggestProjPackage.setText(String.valueOf( 240 statistic.getBiggestProjPackage())); 241 m_averageProjClasses.setText(String.valueOf( 242 statistic.getAverageProjClassesPerPackage())); 243 244 // update the text of the analyse statistc labels 245 m_analyzedClasses.setText(String.valueOf( 246 statistic.getAnalyzedClasses())); 247 m_analyzedPackages.setText(String.valueOf( 248 statistic.getAnalyzedPackages())); 249 m_analyzedLibPack.setText(String.valueOf( 250 statistic.getAnalyzedLibPackages())); 251 m_biggestAnalyzedPackage.setText(String.valueOf( 252 statistic.getBiggestAnalyzedPackage())); 253 m_averageAnalyzedClasses.setText(String.valueOf( 254 statistic.getAverageAnalyzedClassesPerPackage())); 255 m_usesDependencies.setText(String.valueOf( 256 statistic.getNumberOfUsesDep())); 257 } 258 259 /*** 260 * Selects all the packages in the specified list for all the views 261 * implementing the <code>Observer</code> interface. 262 * 263 * @param selectList List containing all the selected packages. 264 */ 265 public void select(ArrayList selectList){ 266 // 267 // deliberately left empty 268 // 269 } 270 271 /*** 272 * Clears all the selections in all the views. 273 */ 274 public void clearSelection() { 275 // 276 // deliberately left empty 277 // 278 } 279 280 /*** 281 * Helper method for creating a bordered JPanel with the statistic content 282 * and the specified title. 283 */ 284 private JPanel createStatPanel(String title, ArrayList contentList, 285 Border border){ 286 287 // create a border with aditional space inside 288 CompoundBorder compBorder = BorderFactory.createCompoundBorder( 289 border, 290 BorderFactory.createEmptyBorder(0, 10, 10, 10)); 291 292 // get the iterator over all the content elements 293 ListIterator contentIter = contentList.listIterator(); 294 int rows = contentList.size(); 295 296 // layout for the panels 297 GridLayout panelLayout = new GridLayout( rows, // rows 298 2, // cols 299 15, // hgap 300 15); //vgap 301 302 // create the custom border for this panel 303 TitledBorder titBorder 304 = BorderFactory.createTitledBorder(compBorder, title); 305 titBorder.setTitleJustification(TitledBorder.LEFT); 306 titBorder.setTitlePosition(TitledBorder.DEFAULT_POSITION); 307 308 // make the panel for the analyzed artifacts panel 309 JPanel panel = new JPanel(); 310 panel.setBorder(titBorder); 311 panel.setLayout(panelLayout); 312 313 // fill in the entries of that panel 314 while ( contentIter.hasNext() ) { 315 JLabel[] entry = (JLabel[])contentIter.next(); 316 317 panel.add(entry[0]); 318 panel.add(entry[1]); 319 } 320 return panel; 321 } 322 323 /*** 324 * Helper method for creating a row in a statistic panel. 325 */ 326 private JLabel[] createStatEntry(String desc, JLabel textLabel){ 327 328 JLabel[] row = new JLabel[2]; 329 row[0] = new JLabel(desc); 330 row[0].setFont(m_statFont); 331 row[1] = textLabel; 332 row[1].setFont(m_statFont); 333 334 return row; 335 } 336 }

This page was automatically generated by Maven