From 0a4d5aad4ef856f9f980f49b397bcd0d121b0020 Mon Sep 17 00:00:00 2001 From: "Leo.Qin" Date: Wed, 27 Dec 2023 20:01:15 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-107973=20=E4=BF=AE=E6=94=B9=E6=B8=90?= =?UTF-8?q?=E5=8F=98=E8=89=B2=E6=BB=91=E5=9D=97UI=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../theme/light/ui/FineGradientBarUI.java | 35 +++++++++++++------ .../gradient/AbstractComponentPopBox.java | 13 +++---- .../background/gradient/GradientBar.java | 2 -- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FineGradientBarUI.java b/designer-base/src/main/java/com/fine/theme/light/ui/FineGradientBarUI.java index fdf4a7f601..a57f40c8bb 100644 --- a/designer-base/src/main/java/com/fine/theme/light/ui/FineGradientBarUI.java +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineGradientBarUI.java @@ -1,6 +1,7 @@ package com.fine.theme.light.ui; import com.fine.theme.utils.FineUIUtils; +import com.formdev.flatlaf.ui.FlatPanelUI; import com.fr.design.style.background.gradient.GradientBar; import com.fr.design.style.background.gradient.SelectColorPointBtn; import com.fr.stable.AssistUtils; @@ -31,7 +32,7 @@ import java.util.List; * @since 11.0 * Created on 2023/12/19 */ -public class FineGradientBarUI extends ComponentUI { +public class FineGradientBarUI extends FlatPanelUI { private int directionalShapeSize; private int recHeight; @@ -54,6 +55,10 @@ public class FineGradientBarUI extends ComponentUI { boolean[] hoverStatus; + protected FineGradientBarUI(boolean shared) { + super(shared); + } + /** * 创建UI @@ -62,7 +67,7 @@ public class FineGradientBarUI extends ComponentUI { * @return UI */ public static ComponentUI createUI(JComponent c) { - return new FineGradientBarUI(); + return new FineGradientBarUI(false); } @Override @@ -71,10 +76,6 @@ public class FineGradientBarUI extends ComponentUI { installDefaults(c); gradientBar = (GradientBar) c; - list = gradientBar.getList(); - p1 = gradientBar.getSelectColorPointBtnP1(); - p2 = gradientBar.getSelectColorPointBtnP2(); - hoverStatus = new boolean[list.size()]; mouseMotionListener = new TrackMotionListener(); mouseListener = new TrackMouseListener(); gradientBar.addMouseMotionListener(mouseMotionListener); @@ -143,7 +144,6 @@ public class FineGradientBarUI extends ComponentUI { int halfSize = directionalShapeSize / 2; boolean x = e.getX() <= gradientBar.getWidth() - halfSize && e.getX() >= halfSize; if (x) { - list.get(index).setX(e.getX()); list.get(index).setStartPosition((double) (e.getX() - halfSize) / (gradientBar.getWidth() - directionalShapeSize)); gradientBar.repaint(); } @@ -201,6 +201,15 @@ public class FineGradientBarUI extends ComponentUI { public void paint(Graphics g, JComponent c) { Graphics2D g2 = (Graphics2D) g; + + gradientBar = (GradientBar) c; + list = gradientBar.getList(); + p1 = gradientBar.getSelectColorPointBtnP1(); + p2 = gradientBar.getSelectColorPointBtnP2(); + if (hoverStatus == null) { + hoverStatus = new boolean[list.size()]; + } + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); @@ -232,6 +241,13 @@ public class FineGradientBarUI extends ComponentUI { colors[i] = btnList.get(i).getColorInner(); } + float[] dist = getColorFloats(c, btnList); + LinearGradientPaint paint = new LinearGradientPaint(start, end, dist, colors); + g2d.setPaint(paint); + g2d.fillRect(halfSize + borderWidth, borderWidth, c.getWidth() - directionalShapeSize - borderWidth * 2, recHeight - borderWidth * 2); + } + + private float[] getColorFloats(GradientBar c, List btnList) { float[] dist = new float[btnList.size()]; for (int i = 0; i < btnList.size(); i++) { if (btnList.get(i).getStartPosition() < 0) { @@ -243,6 +259,7 @@ public class FineGradientBarUI extends ComponentUI { } btnList.get(i).setX(dist[i] * (c.getWidth() - directionalShapeSize) + (double) directionalShapeSize / 2); + btnList.get(i).setY(recHeight); } float dist1 = dist[btnList.size() - 1]; @@ -250,9 +267,7 @@ public class FineGradientBarUI extends ComponentUI { if (AssistUtils.equals(dist1, dist2)) { dist[btnList.size() - 1] = (float) (dist2 + offset); } - LinearGradientPaint paint = new LinearGradientPaint(start, end, dist, colors); - g2d.setPaint(paint); - g2d.fillRect(halfSize + borderWidth, borderWidth, c.getWidth() - directionalShapeSize - borderWidth * 2, recHeight - borderWidth * 2); + return dist; } private void paintBorder(Graphics2D g2d, GradientBar c) { diff --git a/designer-base/src/main/java/com/fr/design/style/background/gradient/AbstractComponentPopBox.java b/designer-base/src/main/java/com/fr/design/style/background/gradient/AbstractComponentPopBox.java index ef647f2bde..2adfc85ef7 100644 --- a/designer-base/src/main/java/com/fr/design/style/background/gradient/AbstractComponentPopBox.java +++ b/designer-base/src/main/java/com/fr/design/style/background/gradient/AbstractComponentPopBox.java @@ -4,14 +4,11 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.style.background.BackgroundJComponent; import com.fr.general.Background; -import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JWindow; import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import java.util.ArrayList; -import java.util.List; import java.awt.AWTEvent; import java.awt.Dimension; import java.awt.Point; @@ -21,13 +18,17 @@ import java.awt.Window; import java.awt.event.AWTEventListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.List; /** + * 渐变色弹出窗口 + * * @author Bjorn - * @version 10.0 - * Created by Bjorn on 2021-08-24 + * @since 10.0 + * Created on 2021-08-24 */ -public abstract class AbstractComponentPopBox extends JComponent { +public abstract class AbstractComponentPopBox extends JPanel { protected BackgroundJComponent displayComponent; 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 1540191df3..7954387448 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 @@ -1,6 +1,5 @@ package com.fr.design.style.background.gradient; -import com.fine.theme.light.ui.FineGradientBarUI; import com.fine.theme.utils.FineUIUtils; import com.fr.base.background.ColorBackground; import com.fr.design.event.UIObserver; @@ -86,7 +85,6 @@ public class GradientBar extends AbstractComponentPopBox implements UIObserver, p2.setStartPosition(1); addMouseClickListener(); iniListener(); - setUI(new FineGradientBarUI()); } public List getList() {