Clover coverage report - brownies library - 1.0-beta-1
Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00
file stats: LOC: 234   Methods: 22
NCLOC: 133   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ListViewTable.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * Created on 2004/05/27
 3   
  */
 4   
 package org.asyrinx.brownie.swing.table;
 5   
 
 6   
 import java.awt.Component;
 7   
 import java.awt.event.MouseAdapter;
 8   
 import java.awt.event.MouseEvent;
 9   
 import java.util.List;
 10   
 
 11   
 import javax.swing.JScrollPane;
 12   
 import javax.swing.JTable;
 13   
 import javax.swing.table.DefaultTableModel;
 14   
 import javax.swing.table.JTableHeader;
 15   
 import javax.swing.table.TableColumn;
 16   
 import javax.swing.table.TableColumnModel;
 17   
 
 18   
 /**
 19   
  * @author akima
 20   
  */
 21   
 public class ListViewTable extends JScrollPane {
 22   
     private javax.swing.JTable table = null;
 23   
 
 24   
     /**
 25   
      *  
 26   
      */
 27  0
     public ListViewTable() {
 28  0
         super();
 29  0
         initialize();
 30  0
         this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
 31  0
         this
 32   
                 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
 33   
     }
 34   
 
 35   
     /**
 36   
      * @param vsbPolicy
 37   
      * @param hsbPolicy
 38   
      */
 39  0
     public ListViewTable(int vsbPolicy, int hsbPolicy) {
 40  0
         super(vsbPolicy, hsbPolicy);
 41  0
         initialize();
 42   
     }
 43   
 
 44   
     /**
 45   
      * @param view
 46   
      */
 47  0
     public ListViewTable(Component view) {
 48  0
         super(view);
 49  0
         initialize();
 50  0
         this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
 51  0
         this
 52   
                 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
 53   
     }
 54   
 
 55   
     /**
 56   
      * @param view
 57   
      * @param vsbPolicy
 58   
      * @param hsbPolicy
 59   
      */
 60  0
     public ListViewTable(Component view, int vsbPolicy, int hsbPolicy) {
 61  0
         super(view, vsbPolicy, hsbPolicy);
 62  0
         initialize();
 63   
     }
 64   
 
 65   
     /**
 66   
      * This method initializes this
 67   
      * 
 68   
      * @return void
 69   
      */
 70  0
     protected void initialize() {
 71  0
         this.setViewportView(getTable());
 72  0
         this.setSize(252, 217);
 73   
     }
 74   
 
 75   
     private DefaultTableModel model = null;
 76   
 
 77   
     /**
 78   
      * @return Returns the model.
 79   
      */
 80  0
     public DefaultTableModel getModel() {
 81  0
         return model;
 82   
     }
 83   
 
 84   
     private SortableTableModel sortableModel = null;
 85   
 
 86  0
     public SortableTableModel getSortableModel() {
 87  0
         return sortableModel;
 88   
     }
 89   
 
 90   
     private InvisibleColumnTableModel invisibleColumnModel = null;
 91   
 
 92   
     /**
 93   
      * @return Returns the invisibleColumnModel.
 94   
      */
 95  0
     public InvisibleColumnTableModel getInvisibleColumnModel() {
 96  0
         return invisibleColumnModel;
 97   
     }
 98   
 
 99   
     /**
 100   
      * This method initializes jTable
 101   
      * 
 102   
      * @return javax.swing.JTable
 103   
      */
 104  0
     public javax.swing.JTable getTable() {
 105  0
         if (table == null) {
 106  0
             table = new javax.swing.JTable();
 107  0
             initTable(table);
 108   
         }
 109  0
         return table;
 110   
     }
 111   
 
 112   
     /**
 113   
      *  
 114   
      */
 115  0
     protected void initTable(JTable target) {
 116  0
         table.getTableHeader().addMouseListener(new MouseAdapter() {
 117  0
             public void mouseClicked(MouseEvent e) {
 118  0
                 if (e.getButton() != MouseEvent.BUTTON1)
 119  0
                     return;
 120  0
                 final JTableHeader header = getTable().getTableHeader();
 121  0
                 final int viewColIndex = header.columnAtPoint(e.getPoint());
 122  0
                 final boolean reverse = (e.getClickCount() % 2) == 0;
 123  0
                 sortByViewColIndex(viewColIndex, reverse);
 124   
             }
 125   
         });
 126   
         //table.setBackground(new java.awt.Color(225, 225, 225));
 127  0
         model = new DefaultTableModel();
 128  0
         initColumns();
 129  0
         model.setRowCount(0);
 130   
         //sortableModelはオリジナルのモデルのフィルタです
 131  0
         sortableModel = TableUtils.toSortableModel(model);
 132   
         //invisibleColumnModelは比較的ビューに近いフィルタなのでsortableModelの後です
 133  0
         invisibleColumnModel = TableUtils.toInvisibleColumnModel(sortableModel,
 134   
                 getInvisibleColumnIndex(), getInvisibleColumnCount());
 135  0
         target.setModel(TableUtils.toUneditableModel(invisibleColumnModel));
 136  0
         target.setCellEditor(null);
 137  0
         target.setEditingColumn(0);
 138  0
         target.setColumnSelectionAllowed(false);
 139  0
         target.setRowSelectionAllowed(true);
 140  0
         target.setFocusable(true);
 141  0
         target
 142   
                 .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
 143  0
         target.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
 144  0
         initColumnWidth(target);
 145   
         //
 146  0
         initRowData();
 147   
     }
 148   
 
 149   
     /**
 150   
      * @param target
 151   
      */
 152  0
     protected void initRowData() {
 153   
         //do nothing
 154   
     }
 155   
 
 156  0
     private void initColumnWidth(JTable target) {
 157  0
         final int colCount = target.getTableHeader().getColumnModel()
 158   
                 .getColumnCount();
 159  0
         final TableColumnModel columnModel = target.getTableHeader()
 160   
                 .getColumnModel();
 161  0
         for (int i = 0; i < colCount; i++) {
 162  0
             final TableColumn column = columnModel.getColumn(i);
 163  0
             column.setPreferredWidth(getDefaultPreferredColumnWidth());
 164   
         }
 165   
     }
 166   
 
 167   
     private int defaultPreferredColumnWidth = 150;
 168   
 
 169  0
     protected int getInvisibleColumnIndex() {
 170  0
         return -1;
 171   
     }
 172   
 
 173  0
     protected int getInvisibleColumnCount() {
 174  0
         return 0;
 175   
     }
 176   
 
 177  0
     protected void initColumns() {
 178   
         //do nothing
 179   
     }
 180   
 
 181   
     /**
 182   
      * スクリーン上に表示されている列のインデックスを元にソートを行います
 183   
      * 
 184   
      * @param viewColIndex
 185   
      */
 186  0
     public void sortByViewColIndex(int viewColIndex, boolean reverse) {
 187  0
         final int visibleModelColIndex = getTable().getTableHeader()
 188   
                 .getColumnModel().getColumn(viewColIndex).getModelIndex();
 189  0
         sortByVisibleModelColIndex(visibleModelColIndex, reverse);
 190   
     }
 191   
 
 192   
     /**
 193   
      * tableのモデルのインデックスを元にソートを行います。 これはgetModelで得られるモデルのインデックスとは異なるかもしれません。
 194   
      * 
 195   
      * @param viewColIndex
 196   
      */
 197  0
     public void sortByVisibleModelColIndex(int visibleModelColIndex,
 198   
             boolean reverse) {
 199  0
         final int originalColIndex = getInvisibleColumnModel()
 200   
                 .getOriginalColumnIndex(visibleModelColIndex);
 201  0
         sortByOriginalModelColIndex(originalColIndex, reverse);
 202   
     }
 203   
 
 204   
     /**
 205   
      * オリジナルのモデル(に近いsortableModel)をソートします
 206   
      * 
 207   
      * @param originalColIndex
 208   
      */
 209  0
     public void sortByOriginalModelColIndex(int originalColIndex,
 210   
             boolean reverse) {
 211  0
         getSortableModel().sort(originalColIndex, reverse);
 212  0
         getTable().revalidate();
 213   
     }
 214   
 
 215  0
     public void load(List entities) {
 216   
         //do nothing
 217   
     }
 218   
 
 219   
     /**
 220   
      * @return
 221   
      */
 222  0
     public int getDefaultPreferredColumnWidth() {
 223  0
         return defaultPreferredColumnWidth;
 224   
     }
 225   
 
 226   
     /**
 227   
      * @param i
 228   
      */
 229  0
     public void setDefaultPreferredColumnWidth(int i) {
 230  0
         defaultPreferredColumnWidth = i;
 231   
     }
 232   
 
 233   
 } //  @jve:visual-info decl-index=0 visual-constraint="10,10"
 234