From dbe5e9c71ab160824d3227837b1d6e6c99c2e516 Mon Sep 17 00:00:00 2001 From: Starryi Date: Tue, 13 Jul 2021 18:30:18 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-55211=E3=80=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=88=86=E7=A6=BB=E3=80=91=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=A4=8D=E7=94=A8-=E5=9B=BE=E8=A1=A8=E5=9D=97=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E5=8B=BE=E9=80=89=E6=A0=87=E9=A2=98=E5=8F=AF=E8=A7=81?= =?UTF-8?q?=EF=BC=8C=E8=AE=BE=E7=BD=AE=E7=9A=84=E4=B8=BB=E4=BD=93=E8=83=8C?= =?UTF-8?q?=E6=99=AF=EF=BC=88=E9=A2=9C=E8=89=B2/=E6=B8=90=E5=8F=98?= =?UTF-8?q?=E8=89=B2/=E5=9B=BE=E7=89=87=EF=BC=89=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E7=95=8C=E9=9D=A2=E9=87=8C=E4=BC=9A=E9=81=AE?= =?UTF-8?q?=E7=9B=96=E4=BD=8F=E5=9B=BE=E8=A1=A8=EF=BC=8C=E5=8F=AF=E8=A7=81?= =?UTF-8?q?=E5=9B=BE=E3=80=82web=E6=95=88=E6=9E=9C=E6=AD=A3=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 子功能: 设计器组件样式主体背景预览 【问题原因】 图表重写了paint方法,导致super.paint中的背景绘制在了图表图片上方 【改动思路】 将XBorderStyleWidgetCreator中的paint方法分成若干部分: clipByRoundedBorder: 圆角裁剪 paintBackground: 绘制背景 paintForeground: 绘制前景内容(在背景上方的组件内容) 图表可通过重写paintForeground方法实现之前的逻辑,同时保证内容不被背景遮盖 【review建议】 --- .../design/designer/creator/XAutoChartCreator.java | 8 ++++---- .../designer/creator/XBorderStyleWidgetCreator.java | 13 ++++++------- .../fr/design/designer/creator/XChartEditor.java | 11 ++++------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XAutoChartCreator.java b/designer-form/src/main/java/com/fr/design/designer/creator/XAutoChartCreator.java index ec132a206..4c5b669b4 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XAutoChartCreator.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XAutoChartCreator.java @@ -18,8 +18,7 @@ import com.fr.stable.bridge.StableFactory; import javax.swing.JComponent; import javax.swing.JPanel; -import java.awt.Dimension; -import java.awt.Graphics; +import java.awt.*; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; @@ -102,7 +101,8 @@ public class XAutoChartCreator extends XChartEditor { } - public void paint(Graphics g) { + @Override + public void paintForeground(Graphics2D g) { BufferedImage bufferedImage = IOUtils.readImage("com/fr/design/form/images/auto_chart_preview.png"); GraphHelper.paintImage( g, this.getWidth(), this.getHeight(), bufferedImage, @@ -110,7 +110,7 @@ public class XAutoChartCreator extends XChartEditor { 0, 0, -1, -1 ); - super.paint(g); + super.paintForeground(g); } private void initChart(BaseChartCollection chartCollection) { diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java b/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java index fc40b1d12..754638783 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java @@ -222,24 +222,23 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ } // 设计器预览界面中绘制组件背景效果 - private void paintBackground(Graphics2D g2d) { + public void paintBackground(Graphics2D g2d) { Background background4Painting = getBackground4Painting(); if (background4Painting != null) { background4Painting.paint(g2d, new Rectangle2D.Double(0, 0, getWidth(), getHeight())); } } - @Override - protected void paintComponent(Graphics g) { - this.paintBackground((Graphics2D) g); - super.paintComponent(g); + public void paintForeground(Graphics2D g2d) { + super.paint(g2d); + super.paintBorder(g2d); } @Override public void paint(Graphics g) { this.clipByRoundedBorder((Graphics2D) g); - super.paint(g); - paintBorder(g); + this.paintBackground((Graphics2D) g); + this.paintForeground((Graphics2D) g); } @Override diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java b/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java index 2e9b3e23a..531a94ec6 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java @@ -29,12 +29,8 @@ import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.SwingUtilities; +import java.awt.*; import java.beans.IntrospectionException; -import java.awt.Color; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Rectangle; import java.awt.event.MouseEvent; /** @@ -228,7 +224,8 @@ public class XChartEditor extends XBorderStyleWidgetCreator { /** * 渲染Painter */ - public void paint(Graphics g) { + @Override + public void paintForeground(Graphics2D g) { Dimension size = getSize(); PaddingMargin margin = toData().getMargin(); designerEditor.paintEditor(g, size, margin); @@ -237,7 +234,7 @@ public class XChartEditor extends XBorderStyleWidgetCreator { int verticalMargin = margin != null ? margin.getTop() + margin.getBottom() : 0; coverPanel.setSize(size.width - horizonMargin, size.height - verticalMargin); } - super.paint(g); + super.paintForeground(g); if (isEditing) { g.setColor(INNER_BORDER_COLOR); GraphHelper.draw(g, new Rectangle(0, 0, getWidth(), getHeight()), Constants.LINE_MEDIUM);