Example #1
0
 /**
  * Returns the 0 based index of the column at {@code pt}. The code can handle re-ordered columns.
  * The index refers to the original ordering (as used by SWT API).
  *
  * <p>Will return -1 if no column could be computed -- this is the case when all columns are
  * resized to have width 0.
  */
 private int findColumn(final Grid grid, final Point pt) {
   int width = 0;
   final int[] colOrder = grid.getColumnOrder();
   // compute the current column ordering
   final GridColumn[] columns = new GridColumn[colOrder.length];
   for (int i = 0; i < colOrder.length; i++) {
     final int idx = colOrder[i];
     columns[i] = grid.getColumn(idx);
   }
   // find the column under Point pt\
   for (final GridColumn col : columns) {
     final int colWidth = col.getWidth();
     if (width < pt.x && pt.x < width + colWidth) {
       return grid.indexOf(col);
     }
     width += colWidth;
   }
   return -1;
 }