Пример #1
0
  /**
   * This gets the actual range of a paste from a corner point. This is actually a helper method for
   * paste
   *
   * @param corner the upper left corner coordinate
   * @return the actual cell range; null if it's beyond the table range
   * @param model the SharpTableModel you are using
   */
  public CellRange getRange(SpreadsheetTableModelClipboardInterface model, CellPoint corner) {
    // limit to paste region
    int rowLimit = model.getRowCount() - 1;
    int colLimit = model.getColumnCount() - 1;

    // calculate dimensions of clipboard
    int rowMax = (corner.getRow() + source.getHeight()) - 1;
    int colMax = (corner.getCol() + source.getWidth()) - 1;

    // cannot paste to nonexistent cells
    if ((corner.getRow() < 0) || (corner.getCol() < 0)) {
      return null;
    } else {
      // paste as much as you can
      return new CellRange(
          corner, new CellPoint(Math.min(rowMax, rowLimit), Math.min(colMax, colLimit)));
    }
  }