View Javadoc

1   // %1126721046073:hoplugins.commons.ui.sorter%
2   /*
3    * Created on 7-apr-2005
4    *
5    * To change the template for this generated file go to
6    * Window>Preferences>Java>Code Generation>Code and Comments
7    */
8   package hoplugins.commons.ui.sorter;
9   
10  import javax.swing.table.JTableHeader;
11  import javax.swing.table.TableColumnModel;
12  
13  import java.awt.event.MouseAdapter;
14  import java.awt.event.MouseEvent;
15  
16  /***
17   * DOCUMENT ME!
18   *
19   * @author
20   */
21  class MouseHandler extends MouseAdapter {
22      /*** TODO Missing Parameter Documentation */
23      private final AbstractTableSorter sorter;
24  
25      /***
26       * Creates a new MouseHandler object.
27       *
28       * @param sorter
29       */
30      MouseHandler(AbstractTableSorter sorter) {
31          this.sorter = sorter;
32  
33          // 
34      }
35  
36      /***
37       * DOCUMENT ME!
38       *
39       * @param e
40       */
41      public void mouseClicked(MouseEvent e) {
42          JTableHeader h = (JTableHeader) e.getSource();
43          TableColumnModel columnModel = h.getColumnModel();
44          int viewColumn = columnModel.getColumnIndexAtX(e.getX());
45          int column = columnModel.getColumn(viewColumn).getModelIndex();
46  
47          //skip unwanted columns            
48          if (column < this.sorter.minSortableColumn()) {
49              column = -1;
50          }
51  
52          if (column != -1) {
53              int status = this.sorter.getSortingStatus(column);
54  
55              if (!e.isControlDown()) {
56                  this.sorter.cancelSorting();
57              }
58  
59              // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or 
60              // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed. 
61              status = status + (e.isShiftDown() ? (-1) : 1);
62              status = ((status + 4) % 3) - 1; // signed mod, returning {-1, 0, 1}
63              this.sorter.setSortingStatus(column, status);
64          }
65      }
66  }