From bbc701f0816bfd9bbe754bb69e741d0823294593 Mon Sep 17 00:00:00 2001 From: zack Date: Thu, 17 Apr 2025 17:28:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../icontainer/UIEastResizableContainer.java | 31 +++++++++++++++++++ .../mainframe/EastRegionContainerPane.java | 4 ++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/icontainer/UIEastResizableContainer.java b/designer-base/src/main/java/com/fr/design/gui/icontainer/UIEastResizableContainer.java index af7bfc9672..acdec476ec 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icontainer/UIEastResizableContainer.java +++ b/designer-base/src/main/java/com/fr/design/gui/icontainer/UIEastResizableContainer.java @@ -359,9 +359,21 @@ public class UIEastResizableContainer extends JPanel { } } + /** + * This inner class handles mouse events for resizing the container + * by dragging the left edge of the right pane. + */ public class ResizeListener extends MouseAdapter implements MouseMotionListener { + + // Stores the point where the mouse was initially pressed private Point mouseDownCompCoords; + /** + * This method is called when the mouse is moved within the component. + * It changes the cursor to indicate that resizing is possible. + * + * @param e The MouseEvent. + */ @Override public void mouseMoved(MouseEvent e) { if (e.getX() <= RESIZE_RANGE) { @@ -371,6 +383,12 @@ public class UIEastResizableContainer extends JPanel { } } + /** + * This method is called when the mouse is pressed near the left edge. + * If within the resize area, the mouse position is stored for dragging. + * + * @param e The MouseEvent. + */ @Override public void mousePressed(MouseEvent e) { if (e.getX() <= RESIZE_RANGE) { @@ -378,11 +396,18 @@ public class UIEastResizableContainer extends JPanel { } } + /** + * This method is called when the mouse is dragged after being pressed + * near the left edge. It adjusts the container width based on drag distance. + * + * @param e The MouseEvent. + */ @Override public void mouseDragged(MouseEvent e) { if (mouseDownCompCoords != null && getCursor().equals(westResizeCursor)) { Point currCoords = e.getLocationOnScreen(); int newWidth = containerWidth - (currCoords.x - mouseDownCompCoords.x); + // Update container width within allowed range if (newWidth >= MIN_CONTAINER_WIDTH && newWidth <= MAX_CONTAINER_WIDTH) { containerWidth = newWidth; mouseDownCompCoords = currCoords; @@ -391,6 +416,12 @@ public class UIEastResizableContainer extends JPanel { } } + /** + * This method is called when the mouse button is released. + * It clears the stored starting point for dragging. + * + * @param e The MouseEvent. + */ @Override public void mouseReleased(MouseEvent e) { mouseDownCompCoords = null; diff --git a/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java b/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java index 26d2f9c061..90840c1bd3 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java @@ -1424,7 +1424,9 @@ public class EastRegionContainerPane extends UIEastResizableContainer { addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { - if (mouseDownCompCoords == null) return; + if (mouseDownCompCoords == null) { + return; + } Rectangle bounds = getBounds(); Point currCoords = e.getLocationOnScreen();