this.tableModel = tableModel;
}
public void mouseClicked(MouseEvent e) {
if(tableModel.isSortable()){
JTableHeader h = (JTableHeader) e.getSource();
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1 && column != SortablePdfSelectionTableModel.PASSWORD && column != SortablePdfSelectionTableModel.ROW_NUM) {
int sortType = (tableModel.getSortingState().getCol() == column)?tableModel.getSortingState().getSortType(): SortablePdfSelectionTableModel.NOT_SORTED;
// Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
sortType = sortType + (e.isShiftDown() ? -1 : 1);
sortType = (sortType + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
tableModel.setSortingState(tableModel.new SortingState(column, sortType));
h.repaint();
}
}
}