Coverage Report - org.pdfsam.guiclient.commons.business.listeners.adapters.PdfSelectionMouseHeaderAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
PdfSelectionMouseHeaderAdapter
20%
3/15
0%
0/12
4
 
 1  
 /*
 2  
  * Created on 21-Dec-2007
 3  
  * Copyright (C) 2006 by Andrea Vacondio.
 4  
  *
 5  
  * This program is free software; you can redistribute it and/or modify it under the terms of the 
 6  
  * GNU General Public License as published by the Free Software Foundation; 
 7  
  * either version 2 of the License.
 8  
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 9  
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 10  
  * See the GNU General Public License for more details.
 11  
  * You should have received a copy of the GNU General Public License along with this program; 
 12  
  * if not, write to the Free Software Foundation, Inc., 
 13  
  *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 14  
  */
 15  
 package org.pdfsam.guiclient.commons.business.listeners.adapters;
 16  
 
 17  
 import java.awt.event.MouseAdapter;
 18  
 import java.awt.event.MouseEvent;
 19  
 
 20  
 import javax.swing.table.JTableHeader;
 21  
 import javax.swing.table.TableColumnModel;
 22  
 
 23  
 import org.pdfsam.guiclient.commons.models.AbstractPdfSelectionTableModel;
 24  
 import org.pdfsam.guiclient.commons.models.SortablePdfSelectionTableModel;
 25  
 /**
 26  
  * Listener for the mouse clicks on the table header
 27  
  * @author Andrea Vacondio
 28  
  *
 29  
  */
 30  
 public class PdfSelectionMouseHeaderAdapter extends MouseAdapter {
 31  
         
 32  
         private AbstractPdfSelectionTableModel tableModel;
 33  
         
 34  20589
         public PdfSelectionMouseHeaderAdapter(AbstractPdfSelectionTableModel tableModel){
 35  20589
                 this.tableModel = tableModel;
 36  20589
         }
 37  
         
 38  
         public void mouseClicked(MouseEvent e) {
 39  0
                 if(tableModel.isSortable()){
 40  0
                 JTableHeader h = (JTableHeader) e.getSource();
 41  0
                 TableColumnModel columnModel = h.getColumnModel();
 42  0
                 int viewColumn = columnModel.getColumnIndexAtX(e.getX());
 43  0
                 int column = columnModel.getColumn(viewColumn).getModelIndex();
 44  0
                 if (column != -1 && column != SortablePdfSelectionTableModel.PASSWORD && column != SortablePdfSelectionTableModel.ROW_NUM) {
 45  0
                     int sortType = (tableModel.getSortingState().getCol() == column)?tableModel.getSortingState().getSortType(): SortablePdfSelectionTableModel.NOT_SORTED;
 46  
                   
 47  
                     // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or 
 48  
                     // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed. 
 49  0
                     sortType = sortType + (e.isShiftDown() ? -1 : 1);
 50  0
                     sortType = (sortType + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
 51  0
                     tableModel.setSortingState(tableModel.new SortingState(column, sortType));
 52  0
                     h.repaint();
 53  
                 }
 54  
         }
 55  0
     }
 56  
 }