Esempio n. 1
0
  /**
   * Paint cells.
   *
   * @param context DOCUMENT ME!
   * @param g DOCUMENT ME!
   * @param rMin DOCUMENT ME!
   * @param rMax DOCUMENT ME!
   * @param cMin DOCUMENT ME!
   * @param cMax DOCUMENT ME!
   */
  private void paintCells(
      SeaGlassContext context, Graphics g, int rMin, int rMax, int cMin, int cMax) {
    JTableHeader header = table.getTableHeader();
    TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();

    TableColumnModel cm = table.getColumnModel();
    int columnMargin = cm.getColumnMargin();

    Rectangle cellRect;
    TableColumn aColumn;
    int columnWidth;

    if (table.getComponentOrientation().isLeftToRight()) {
      for (int row = rMin; row <= rMax; row++) {
        cellRect = table.getCellRect(row, cMin, false);
        for (int column = cMin; column <= cMax; column++) {
          aColumn = cm.getColumn(column);
          columnWidth = aColumn.getWidth();
          cellRect.width = columnWidth - columnMargin;
          if (aColumn != draggedColumn) {
            paintCell(context, g, cellRect, row, column);
          }

          cellRect.x += columnWidth;
        }
      }
    } else {
      for (int row = rMin; row <= rMax; row++) {
        cellRect = table.getCellRect(row, cMin, false);
        aColumn = cm.getColumn(cMin);
        if (aColumn != draggedColumn) {
          columnWidth = aColumn.getWidth();
          cellRect.width = columnWidth - columnMargin;
          paintCell(context, g, cellRect, row, cMin);
        }

        for (int column = cMin + 1; column <= cMax; column++) {
          aColumn = cm.getColumn(column);
          columnWidth = aColumn.getWidth();
          cellRect.width = columnWidth - columnMargin;
          cellRect.x -= columnWidth;
          if (aColumn != draggedColumn) {
            paintCell(context, g, cellRect, row, column);
          }
        }
      }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
      paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
    }

    // Remove any renderers that may be left in the rendererPane.
    rendererPane.removeAll();
  }
 /**
  * Implemented to pass the event to the original only if the mouseX doesn't lead to dragging the
  * column over the first.
  */
 @Override
 public void mouseDragged(MouseEvent e) {
   TableColumn dragged = header.getDraggedColumn();
   // int index = getViewIndexForColumn(header.getColumnModel(), dragged);
   // dragged column is at second position, allow only drags to the right
   int indexColumn = header.getColumnModel().getColumnIndex(columnName);
   if (indexColumn == 1) {
     if (e.getX() < maxX) return;
   }
   mouseMotionDelegate.mouseDragged(e);
 }
 /**
  * Implemented to do some tweaks/bookkeeping before/after passing the event to the original
  *
  * <p>- temporarily disallow reordering if hit on first column - calculate the max mouseX that's
  * allowable in dragging to the left
  */
 @Override
 public void mousePressed(MouseEvent e) {
   int index = header.columnAtPoint(e.getPoint());
   boolean reorderingAllowed = header.getReorderingAllowed();
   if (index == 0) {
     // temporarily disable re-ordering
     header.setReorderingAllowed(false);
   }
   mouseDelegate.mousePressed(e);
   header.setReorderingAllowed(reorderingAllowed);
   if (header.getDraggedColumn() != null) {
     Rectangle r = header.getHeaderRect(index);
     maxX = header.getColumnModel().getColumn(0).getWidth() + e.getX() - r.x - 1;
   }
 }