From bdad7f09e27485894ce414b1444d6a7eab1dbf56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E7=A3=8A?= <294531121@qq.com> Date: Tue, 13 Jul 2021 20:15:42 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-54998=20=E8=BF=9B=E4=B8=80=E6=AD=A5?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E5=85=B7=E4=BD=93=E7=9A=84=E6=96=B9=E5=90=91=E5=88=A4=E6=96=AD?= =?UTF-8?q?=EF=BC=8C=E5=8F=AA=E7=95=99=E6=B0=B4=E5=B9=B3=E6=88=96=E8=80=85?= =?UTF-8?q?=E5=9E=82=E7=9B=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/grid/GridMouseAdapter.java | 44 +++++-------------- 1 file changed, 11 insertions(+), 33 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 b0f8fff467..0a6ba50421 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java +++ b/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java @@ -463,52 +463,30 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous } int xDistance = evtX - this.oldEvtX; int yDistance = evtY - this.oldEvtY; - int dragDirection = calculateDragDirection(xDistance, yDistance); - Rectangle endRec = calculateEndRec(currentMouseCell, startRec, dragDirection); + boolean isHorizontal = isHorizontal(xDistance, yDistance); + Rectangle endRec = calculateEndRec(currentMouseCell, startRec, isHorizontal); grid.getDragRectangle().setBounds(calculateDragRectangle(startRec, endRec)); reportPane.ensureColumnRowVisible(currentMouseCell.getColumn() + 1, currentMouseCell.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 boolean isHorizontal(int xDistance, int yDistance) { + return Math.abs(yDistance) <= Math.abs(xDistance); } /** * 计算拖拽的结尾矩形 * @param currentMouseCell 当前鼠标所在的格子 * @param startRec 起始格子 - * @param direction 拖拽方向 + * @param isHorizontal 拖拽方向 水平or垂直 * @return 计算拖拽的结尾矩形 */ - private Rectangle calculateEndRec(ColumnRow currentMouseCell, Rectangle startRec, int direction) { - Rectangle rec; - switch(direction) { - case DIRECTION_DOWN: - case DIRECTION_UP: - rec = new Rectangle(startRec.x, currentMouseCell.row, 1, 1); - break; - case DIRECTION_RIGHT: - case DIRECTION_LEFT: - rec = new Rectangle(currentMouseCell.column, startRec.y, 1, 1); - break; - default: - rec = new Rectangle(); - break; - } - return rec; + private Rectangle calculateEndRec(ColumnRow currentMouseCell, Rectangle startRec, boolean isHorizontal) { + if (isHorizontal) { + return new Rectangle(currentMouseCell.column, startRec.y, 1, 1); + } else { + return new Rectangle(startRec.x, currentMouseCell.row, 1, 1); + } } /**