Coverage Report - org.argouml.cognitive.critics.ui.TableCritics
 
Classes in this File Line Coverage Branch Coverage Complexity
TableCritics
74%
29/39
75%
3/4
1.5
 
 1  
 /* $Id: TableCritics.java 17817 2010-01-12 18:34:59Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    penyaskito
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2007 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies. This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason. IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.cognitive.critics.ui;
 40  
 
 41  
 import java.awt.Dimension;
 42  
 
 43  
 import javax.swing.JTable;
 44  
 import javax.swing.ListSelectionModel;
 45  
 import javax.swing.event.ListSelectionListener;
 46  
 import javax.swing.event.TableModelEvent;
 47  
 import javax.swing.event.TableModelListener;
 48  
 import javax.swing.table.TableColumn;
 49  
 import javax.swing.table.TableModel;
 50  
 
 51  
 import org.argouml.cognitive.Critic;
 52  
 
 53  
 /**
 54  
  * This class represents the table shown in the Critics Browser dialog. <p>
 55  
  * 
 56  
  * This is a seperate class so that 
 57  
  * the CriticsBrowser does not need to know 
 58  
  * what the table contains, i.e. how many columns it has, etc. 
 59  
  *
 60  
  * @author Michiel
 61  
  */
 62  
 class TableCritics extends JTable {
 63  
 
 64  
     private boolean initialised;
 65  
     private static final String DESC_WIDTH_TEXT =
 66  
         "This is Sample Text for determining Column Width";
 67  
 
 68  
     public TableCritics(TableModel model, 
 69  
             ListSelectionListener lsl, TableModelListener tml) {
 70  20
         super(model);
 71  20
         setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 72  20
         setShowVerticalLines(false);
 73  20
         getSelectionModel().addListSelectionListener(lsl);
 74  20
         getModel().addTableModelListener(tml);
 75  20
         setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
 76  
 
 77  20
         initialised = true;
 78  20
         setColumnWidths();
 79  20
     }
 80  
 
 81  
     private void setColumnWidths() {
 82  40
         if (!initialised) {
 83  20
             return;
 84  
         }
 85  20
         TableColumn checkCol = getColumnModel().getColumn(0);
 86  20
         TableColumn descCol = getColumnModel().getColumn(1);
 87  20
         TableColumn actCol = getColumnModel().getColumn(2);
 88  20
         checkCol.setMinWidth(35);
 89  20
         checkCol.setMaxWidth(35);
 90  20
         checkCol.setWidth(30);
 91  20
         int descWidth = getFontMetrics(getFont())
 92  
                 .stringWidth(DESC_WIDTH_TEXT);
 93  20
         descCol.setMinWidth(descWidth);
 94  20
         descCol.setWidth(descWidth); // no maximum set, so it will stretch...
 95  20
         actCol.setMinWidth(50);
 96  20
         actCol.setMaxWidth(55);
 97  20
         actCol.setWidth(55);
 98  
         /* and for advanced mode: */
 99  20
         if (getColumnModel().getColumnCount() > 3) {
 100  0
             descCol.setMinWidth(descWidth / 2);
 101  0
             TableColumn prioCol = getColumnModel().getColumn(3);
 102  0
             prioCol.setMinWidth(45);
 103  0
             prioCol.setMaxWidth(50);
 104  0
             prioCol.setWidth(50);
 105  
         }
 106  20
     }
 107  
     
 108  
     public Critic getCriticAtRow(int row) {
 109  0
         TableModelCritics model = (TableModelCritics) getModel();
 110  0
         return model.getCriticAtRow(row);
 111  
     }
 112  
 
 113  
     public Dimension getInitialSize() {
 114  20
         return new Dimension(getColumnModel().getTotalColumnWidth() + 20, 0);
 115  
     }
 116  
     
 117  
     public void setAdvanced(boolean mode) {
 118  0
         TableModelCritics model = (TableModelCritics) getModel();
 119  0
         model.setAdvanced(mode);
 120  0
     }
 121  
 
 122  
     /**
 123  
      * @see javax.swing.JTable#tableChanged(javax.swing.event.TableModelEvent)
 124  
      */
 125  
     @Override
 126  
     public void tableChanged(TableModelEvent e) {
 127  20
         super.tableChanged(e);
 128  
         /* This changes the complete structure of the table, 
 129  
          * so we need to set the column widths again. */
 130  20
         setColumnWidths();
 131  20
     }
 132  
 
 133  
     
 134  
 }