From e4fe8267847615ecd0549f4b1691ce9a35c0db55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E7=A3=8A?= <294531121@qq.com> Date: Mon, 12 Jul 2021 18:06:54 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-54998=20=E5=AE=8C=E5=96=84=E4=B8=80?= =?UTF-8?q?=E4=B8=8B=E8=BF=99=E8=BE=B9=E7=9A=84=E5=88=A4=E6=96=AD=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BD=BF=E5=85=B6=E6=9B=B4=E5=8A=A0=E6=B8=85?= =?UTF-8?q?=E6=99=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/grid/GridMouseAdapter.java | 153 ++++++++++++++---- 1 file changed, 118 insertions(+), 35 deletions(-) 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 55bbcfed30..da2f6f1743 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java +++ b/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java @@ -46,6 +46,10 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous private static final int TOOLTIP_X_Y_FIX = 4; private static final double COPY_CROSS_INNER_DISTANCE = 1.5; private static final double COPY_CROSS_OUTER_DISTANCE = 2.5; + private static final int DIRECTION_UP = 1; + private static final int DIRECTION_DOWN = 2; + private static final int DIRECTION_LEFT = 3; + private static final int DIRECTION_RIGHT = 4; /** * 拖拽时候刷新时间间隔 */ @@ -457,48 +461,127 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous if (cellRectangle.contains(selectedCellPoint.getColumn(), selectedCellPoint.getRow())) { grid.getDragRectangle().setBounds(cellRectangle); } else { + if (isOutECBlockPane(evtX, evtY)) { + return; + } int xDistance = evtX - this.oldEvtX; int yDistance = evtY - this.oldEvtY; - if (Math.abs(yDistance) > Math.abs(xDistance)) { - grid.getDragRectangle().x = cellRectangle.x; - grid.getDragRectangle().width = cellRectangle.width; - if (yDistance >= 0) { - // 聚合报表要求拖拽的时候要在本块的内部进行 不能无限往下拖 - if (reportPane instanceof ECBlockPane && evtY > reportPane.getBounds().height - ECBlockGap) { - return; - } - grid.getDragRectangle().y = cellRectangle.y; - grid.getDragRectangle().height = selectedCellPoint.getRow() - cellRectangle.y + 1; + int dragDirection = calculateDragDirection(xDistance, yDistance); + grid.getDragRectangle().x = calculateDragRectangleX(selectedCellPoint, cellRectangle, dragDirection); + grid.getDragRectangle().y = calculateDragRectangleY(selectedCellPoint, cellRectangle, dragDirection); + grid.getDragRectangle().width = calculateDragRectangleWidth(selectedCellPoint, cellRectangle, dragDirection); + grid.getDragRectangle().height = calculateDragRectangleHeight(selectedCellPoint, cellRectangle, dragDirection); + } + reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn() + 1, selectedCellPoint.getRow() + 1); + } + + private int calculateDragDirection(int xDistance, int yDistance) { + if (Math.abs(yDistance) > Math.abs(xDistance)) { + if (yDistance >= 0) { + return DIRECTION_DOWN; + } else { + return DIRECTION_UP; + } + } else { + if (xDistance >= 0) { + return DIRECTION_RIGHT; + } else { + return DIRECTION_LEFT; + } + } + } + + private int calculateDragRectangleX(ColumnRow currentMouseCell, Rectangle startRec, int direction) { + int result = 0; + switch(direction) { + case DIRECTION_DOWN: + case DIRECTION_UP: + case DIRECTION_RIGHT: + result = startRec.x; + break; + case DIRECTION_LEFT: + if (isInsideSelectedCell(currentMouseCell, startRec, direction)) { + result = startRec.x; } else { - if (selectedCellPoint.getRow() >= cellRectangle.y && selectedCellPoint.getRow() < cellRectangle.y + cellRectangle.height) { - grid.getDragRectangle().y = cellRectangle.y; - grid.getDragRectangle().height = cellRectangle.height; - } else { - grid.getDragRectangle().y = selectedCellPoint.getRow(); - grid.getDragRectangle().height = cellRectangle.y - selectedCellPoint.getRow() + cellRectangle.height; - } + result = currentMouseCell.getColumn(); } - } else { - grid.getDragRectangle().y = cellRectangle.y; - grid.getDragRectangle().height = cellRectangle.height; - if (xDistance >= 0) { - if (reportPane instanceof ECBlockPane && evtX > reportPane.getBounds().width - ECBlockGap) { - return; - } - grid.getDragRectangle().x = cellRectangle.x; - grid.getDragRectangle().width = selectedCellPoint.getColumn() - cellRectangle.x + 1; + break; + } + return result; + } + + private int calculateDragRectangleY(ColumnRow currentMouseCell, Rectangle startRec, int direction) { + int result = 0; + switch(direction) { + case DIRECTION_RIGHT: + case DIRECTION_LEFT: + case DIRECTION_DOWN: + result = startRec.y; + break; + case DIRECTION_UP: + if (isInsideSelectedCell(currentMouseCell, startRec, direction)) { + result = startRec.y; } else { - if (selectedCellPoint.getColumn() >= cellRectangle.x && selectedCellPoint.getColumn() < cellRectangle.x + cellRectangle.width) { - grid.getDragRectangle().x = cellRectangle.x; - grid.getDragRectangle().width = cellRectangle.width; - } else { - grid.getDragRectangle().x = selectedCellPoint.getColumn(); - grid.getDragRectangle().width = cellRectangle.x - selectedCellPoint.getColumn() + cellRectangle.width; - } + result = currentMouseCell.getRow(); } - } + break; } - reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn() + 1, selectedCellPoint.getRow() + 1); + return result; + } + + private int calculateDragRectangleWidth(ColumnRow currentMouseCell, Rectangle startRec, int direction) { + int result = 0; + switch(direction) { + case DIRECTION_DOWN: + case DIRECTION_UP: + result = startRec.width; + break; + case DIRECTION_RIGHT: + result = currentMouseCell.getColumn() - startRec.x + 1; + break; + case DIRECTION_LEFT: + if (isInsideSelectedCell(currentMouseCell, startRec, direction)) { + result = startRec.width; + } else { + result = startRec.x - currentMouseCell.getColumn() + startRec.width; + } + break; + } + return result; + } + + private int calculateDragRectangleHeight(ColumnRow currentMouseCell, Rectangle startRec, int direction) { + int result = 0; + switch(direction) { + case DIRECTION_DOWN: + result = currentMouseCell.getRow() - startRec.y + 1; + break; + case DIRECTION_UP: + if (isInsideSelectedCell(currentMouseCell, startRec, direction)) { + result = startRec.y - currentMouseCell.getRow() + startRec.height; + } else { + result = startRec.height; + } + break; + case DIRECTION_RIGHT: + case DIRECTION_LEFT: + result = startRec.height; + break; + } + return result; + } + + private boolean isOutECBlockPane(int evtX, int evtY) { + ElementCasePane reportPane = grid.getElementCasePane(); + if (reportPane instanceof ECBlockPane) { + return (evtY > reportPane.getBounds().height - ECBlockGap) || (evtX > reportPane.getBounds().width - ECBlockGap); + } + return true; + } + + private boolean isInsideSelectedCell(ColumnRow currentMouseCell, Rectangle startRec, int direction) { + return (direction == DIRECTION_UP && currentMouseCell.getRow() >= startRec.y && currentMouseCell.getRow() < startRec.y + startRec.height) || + (direction == DIRECTION_LEFT && currentMouseCell.getColumn() >= startRec.x && currentMouseCell.getColumn() < startRec.x + startRec.width); } private void doShiftSelectCell(double evtX, double evtY) {