From 907cca3f83130780511bdb731c89592097a51a52 Mon Sep 17 00:00:00 2001 From: Starryi Date: Thu, 22 Jul 2021 16:57:50 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-55672=20=E6=82=AC=E6=B5=AE=E5=85=83?= =?UTF-8?q?=E7=B4=A0-=E6=96=B0=E5=BB=BA=E6=A8=A1=E6=9D=BF=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E6=B7=BB=E5=8A=A0=E7=9A=84=E6=82=AC=E6=B5=AE?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E4=B8=8D=E8=83=BD=E7=A7=BB=E5=8A=A8=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 resizingBackupBounds仅在拖拽改变尺寸,光标改变时初始化,所以导致拖拽移动时,出现NPE 【改动思路】 resizingBackupBounds只在等比例尺寸缩放拖拽改变尺寸时需要 --- .../java/com/fr/grid/GridMouseAdapter.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 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 0ae21bf4d5..1cb3e6242a 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java +++ b/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java @@ -408,11 +408,11 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous int currentWidth = currentRight - currentLeft; int currentHeight = currentBottom - currentTop; - int backupWidth= resizingBackupBounds[2]; - int backupHeight= resizingBackupBounds[3]; - if (cursorType == Cursor.NW_RESIZE_CURSOR || cursorType == Cursor.NE_RESIZE_CURSOR || cursorType == Cursor.SE_RESIZE_CURSOR || cursorType == Cursor.SW_RESIZE_CURSOR) { - if (aspectRatio) { + if (aspectRatio && resizingBackupBounds != null) { + int backupWidth= resizingBackupBounds[2]; + int backupHeight= resizingBackupBounds[3]; + double currentDiagonal = Math.pow(currentWidth, 2) + Math.pow(currentHeight, 2); double backupDiagonal = Math.pow(backupWidth, 2) + Math.pow(backupHeight, 2); @@ -452,7 +452,10 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous floatElement.setTopDistance(topDistance); floatElement.setHeight(FU.valueOfPix(currentBottom, resolution).subtract(floatY1_fu)); - if (aspectRatio) { + if (aspectRatio && resizingBackupBounds != null) { + int backupWidth= resizingBackupBounds[2]; + int backupHeight= resizingBackupBounds[3]; + currentWidth = backupWidth * currentHeight / backupHeight; currentRight = currentLeft + currentWidth; FU floatX1_fu = FU.valueOfPix(currentLeft, resolution); @@ -465,7 +468,10 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous floatElement.setLeftDistance(leftDistance); floatElement.setWidth(FU.valueOfPix(currentRight, resolution).subtract(floatX1_fu)); - if (aspectRatio) { + if (aspectRatio && resizingBackupBounds != null) { + int backupWidth= resizingBackupBounds[2]; + int backupHeight= resizingBackupBounds[3]; + currentHeight = backupHeight * currentWidth / backupWidth; currentBottom = currentTop + currentHeight; FU floatY1_fu = FU.valueOfPix(currentTop, resolution);