diff --git a/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java b/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java index 7fb4af3293..b0f8fff467 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java +++ b/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java @@ -464,8 +464,8 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous int xDistance = evtX - this.oldEvtX; int yDistance = evtY - this.oldEvtY; int dragDirection = calculateDragDirection(xDistance, yDistance); - ColumnRow realCell = calculateRealCell(currentMouseCell, startRec, dragDirection); - grid.getDragRectangle().setBounds(calculateDragRectangle(realCell, startRec, dragDirection)); + Rectangle endRec = calculateEndRec(currentMouseCell, startRec, dragDirection); + grid.getDragRectangle().setBounds(calculateDragRectangle(startRec, endRec)); reportPane.ensureColumnRowVisible(currentMouseCell.getColumn() + 1, currentMouseCell.getRow() + 1); } @@ -487,86 +487,46 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous } /** - * 计算当前十字标所在格子对应的真正参与计算拖拽边框的格子 + * 计算拖拽的结尾矩形 * @param currentMouseCell 当前鼠标所在的格子 * @param startRec 起始格子 * @param direction 拖拽方向 - * @return 当前十字标所在格子对应的真正参与计算拖拽边框的格子 + * @return 计算拖拽的结尾矩形 */ - private ColumnRow calculateRealCell(ColumnRow currentMouseCell, Rectangle startRec, int direction) { - ColumnRow realCell; + private Rectangle calculateEndRec(ColumnRow currentMouseCell, Rectangle startRec, int direction) { + Rectangle rec; switch(direction) { case DIRECTION_DOWN: case DIRECTION_UP: - realCell = ColumnRow.valueOf(startRec.x, currentMouseCell.row); + rec = new Rectangle(startRec.x, currentMouseCell.row, 1, 1); break; case DIRECTION_RIGHT: case DIRECTION_LEFT: - realCell = ColumnRow.valueOf(currentMouseCell.column, startRec.y); + rec = new Rectangle(currentMouseCell.column, startRec.y, 1, 1); break; default: - realCell = currentMouseCell; + rec = new Rectangle(); break; } - return realCell; + return rec; } /** - * 计算拖拽的边框 - * @param realCell 当前十字标所在格子对应的真正参与计算拖拽边框的格子 - * @param startRec 起始格子 - * @param direction 拖拽方向 + * 计算拖拽的边框,传俩矩形确认出一个大矩形,就是所要的结果 + * @param startRec 起始格子矩形 + * @param endRec 结尾格子矩形 * @return 拖拽的边框 */ - private Rectangle calculateDragRectangle(ColumnRow realCell, Rectangle startRec, int direction) { + private Rectangle calculateDragRectangle(Rectangle startRec, Rectangle endRec) { Rectangle rectangle = new Rectangle(); - if (startRec.contains(realCell.column, realCell.row)) { - rectangle.setBounds(startRec); - } else { - boolean clockWise = isClockWise(direction); - int x, y, width, height; - if (clockWise) { - x = startRec.x; - y = startRec.y; - width = Math.abs(realCell.column - startRec.x) + 1; // 加一是因为计算顺时针边框宽度或者高度的时候,没把realCell自身高度算进去 - height = Math.abs(realCell.row - startRec.y) + 1; - } else { - x = realCell.column; - y = realCell.row; - width = Math.abs(realCell.column - startRec.x) + startRec.width; - height = Math.abs(realCell.row - startRec.y) + startRec.height; - } - - // 上面的只计算了顺时针和逆时针的width,height,但是还要顺时针里面还要区分从左往右和从上往下,这里是用于修正 - boolean isHorizontal = isHorizontal(direction); - if (isHorizontal) { - height = startRec.height; // 水平方向,绘制的边框肯定就等于起始格子的高度 - } else { - width = startRec.width; // 垂直方向,绘制的边框肯定就等于起始给子的宽度 - } - rectangle.setBounds(x, y, width, height); - } + int x = Math.min(startRec.x, endRec.x); + int y = Math.min(startRec.y, endRec.y); + int rightBottomX = Math.max(startRec.x + startRec.width, endRec.x + endRec.width); + int rightBottomY = Math.max(startRec.y + startRec.height, endRec.y + endRec.height); + rectangle.setBounds(x, y, rightBottomX - x, rightBottomY - y); return rectangle; } - /** - * 判断拖拽方向是否是顺时针 从左往右,从上往下为顺时针,从右往左,从下往上为逆时针 - * @param direction 方向 - * @return 是否是顺时针 - */ - private boolean isClockWise(int direction) { - return direction == DIRECTION_DOWN || direction == DIRECTION_RIGHT; - } - - /** - * 判断拖拽方向是否为水平还是垂直 - * @param direction 方向 - * @return 是否为水平 - */ - private boolean isHorizontal(int direction) { - return direction == DIRECTION_RIGHT || direction == DIRECTION_LEFT; - } - private boolean isOutECBlockPane(int evtX, int evtY) { ElementCasePane reportPane = grid.getElementCasePane(); return reportPane instanceof ECBlockPane && ((evtY > reportPane.getBounds().height - ECBlockGap) || (evtX > reportPane.getBounds().width - ECBlockGap));