From 43f9b6f31235ea9f06fe91b40e3e84f5987e2476 Mon Sep 17 00:00:00 2001 From: renekton Date: Tue, 10 Sep 2024 20:20:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=8F=90=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../background/gradient/GradientBar.java | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/style/background/gradient/GradientBar.java b/designer-base/src/main/java/com/fr/design/style/background/gradient/GradientBar.java index 25467b02ba..74afec7efd 100644 --- a/designer-base/src/main/java/com/fr/design/style/background/gradient/GradientBar.java +++ b/designer-base/src/main/java/com/fr/design/style/background/gradient/GradientBar.java @@ -134,28 +134,7 @@ public class GradientBar extends AbstractComponentPopBox implements UIObserver, protected void addMouseDragListener() { this.addMouseMotionListener(new MouseAdapter() { public void mouseDragged(MouseEvent e) { - int oldIndex = index; - for (int i = 0; i < list.size(); i++) { - if (list.get(i).contains(e.getX(), e.getY())) { - index = i; - break; - } - } - if (OperatingSystem.isLinux() && AssistUtils.equals(oldIndex, index)) { - if (Math.abs(p1.getX() - e.getX()) > Math.abs(p2.getX() - e.getX())) { - index = 1; - } else { - index = 0; - } - } - boolean x = e.getX() <= max && e.getX() >= min; - if (x && e.getY() < MAX_VERTICAL) { - list.get(index).setX(e.getX()); - } - - GradientBar.this.repaint(); - startLabel.setText(Double.toString(p1.getX())); - endLabel.setText(Double.toString(p2.getX())); + dragAction(e); } }); } @@ -336,4 +315,29 @@ public class GradientBar extends AbstractComponentPopBox implements UIObserver, public void setDraggable(boolean draggable) { this.draggable = draggable; } + + private void dragAction(MouseEvent e) { + int oldIndex = index; + for (int i = 0; i < list.size(); i++) { + if (list.get(i).contains(e.getX(), e.getY())) { + index = i; + break; + } + } + if (OperatingSystem.isLinux() && AssistUtils.equals(oldIndex, index)) { + if (Math.abs(p1.getX() - e.getX()) > Math.abs(p2.getX() - e.getX())) { + index = 1; + } else { + index = 0; + } + } + boolean x = e.getX() <= max && e.getX() >= min; + if (x && e.getY() < MAX_VERTICAL) { + list.get(index).setX(e.getX()); + } + + GradientBar.this.repaint(); + startLabel.setText(Double.toString(p1.getX())); + endLabel.setText(Double.toString(p2.getX())); + } } \ No newline at end of file