From 52edf38baaaf0d8e00b7fd9ac10aa633f43c082d Mon Sep 17 00:00:00 2001 From: Starryi Date: Thu, 22 Jul 2021 16:01:55 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-55491=20=E3=80=90=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E9=AA=8C=E6=94=B6=E3=80=91=E3=80=90=E7=BB=84=E4=BB=B6=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E5=88=86=E7=A6=BB=E3=80=91=E5=9C=A8=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E4=B8=8B=E7=9A=84=E3=80=8C=E4=B8=BB=E4=BD=93?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E3=80=8D=E8=AE=BE=E7=BD=AE=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=95=8C=E9=9D=A2=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=EF=BC=8C=E7=9C=8B=E4=B8=8D=E5=88=B0=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 1. 绘制报表块缩略图时,填充了白色背景,导致组件样式背景被覆盖 2. 优化报表块缩略图时,即在ElementCaseImage中截取部分缩略图时,丢弃了Alpha通道 3. 表单布局预览绘制表格缩略图时使用了默认的白色纸张背景(表单报表块的表格没有纸张背景的概念) 【改动思路】 1. 绘制报表块缩略图时,不要使用白色背景填充,保持透明 2. 优化报表块缩略图时,使用subImage完成截取功能,保留Alpha通道 3. 表单布局预览绘制表格缩略图时,忽略纸张背景 4. 替换默认的报表块预览图(此图用于将报表块拖拽到面板中时显示作为 报表块的缩略图使用),因此也要支持半透明 --- .../design/designer/creator/XElementCase.java | 8 +++--- .../form/FormElementCaseDesigner.java | 26 +++++++++++-------- .../src/main/java/com/fr/grid/Grid.java | 11 ++++++++ .../src/main/java/com/fr/grid/GridUI.java | 6 +++-- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java b/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java index 7ed22c52d..b5cc813ae 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java @@ -41,7 +41,7 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme static { try { - DEFAULT_BACKGROUND = BaseUtils.readImageWithCache("com/fr/base/images/report/elementcase.png"); + DEFAULT_BACKGROUND = BaseUtils.readImageWithCache("com/fr/base/images/report/elementcase_translucent.png"); } catch (Throwable e) { //IBM jdk 1.5.0_22 并发下读取图片有时会异常(EOFException), 这个图片反正只有设计器用到, 捕获住 DEFAULT_BACKGROUND = CoreGraphHelper.createBufferedImage(0, 0); @@ -183,7 +183,8 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme if (editor == null) { setBorder(DEFALUTBORDER); editor = new JPanel(); - editor.setBackground(null); + editor.setOpaque(false); + editor.setBackground(new Color(0, 0, 0, 0)); editor.setLayout(null); imageLable = initImageBackground(); @@ -218,7 +219,8 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme private void setLabelBackground(Image image, UILabel imageLable) { ImageIcon icon = new ImageIcon(image); imageLable.setIcon(icon); - imageLable.setOpaque(true); + imageLable.setOpaque(false); + imageLable.setBackground(new Color(0, 0, 0, 0)); imageLable.setLayout(null); imageLable.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight()); } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java index 7af39737d..b2892e722 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java @@ -43,9 +43,9 @@ import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JScrollBar; import java.awt.BorderLayout; -import java.awt.Color; import java.awt.Dimension; -import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Transparency; import java.awt.image.BufferedImage; /** @@ -129,19 +129,23 @@ public class FormElementCaseDesigner public BufferedImage getElementCaseImage(Dimension size) { BufferedImage image = null; try { - image = new java.awt.image.BufferedImage(size.width, size.height, - java.awt.image.BufferedImage.TYPE_INT_RGB); - Graphics g = image.getGraphics(); + int width = size.width; + int height = size.height; - //填充白色背景, 不然有黑框 - Color oldColor = g.getColor(); - g.setColor(Color.WHITE); - g.fillRect(0, 0, size.width, size.height); - g.setColor(oldColor); + image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2d = image.createGraphics(); + // 创建一个支持透明背景的buffer image + image = g2d.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); + g2d.dispose(); + g2d = image.createGraphics(); Grid grid = this.elementCasePane != null ? this.elementCasePane.getGrid() : null; if (grid != null) { - grid.paintAll(g); + boolean oldTranslucent = grid.isTranslucent(); + // 截缩图图时grid需支持半透明,不能用默认白色填充画布,否则会遮挡组件样式背景 + grid.setTranslucent(true); + grid.paint(g2d); + grid.setTranslucent(oldTranslucent); } } catch (Exception e) { diff --git a/designer-realize/src/main/java/com/fr/grid/Grid.java b/designer-realize/src/main/java/com/fr/grid/Grid.java index abbd60928..b55f60bb5 100644 --- a/designer-realize/src/main/java/com/fr/grid/Grid.java +++ b/designer-realize/src/main/java/com/fr/grid/Grid.java @@ -134,6 +134,9 @@ public class Grid extends BaseGridComponent { private boolean needRequestFocus = true; + // 截取缩略图时需透明(不能用默认白色填充),否则会遮挡组件样式的背景,其余情况的绘制可以用白色等默认颜色填充 + private boolean isTranslucent = false; + public Grid(int resolution) { this.resolution = resolution; // 能触发processEvent,不管是否给component增加listener @@ -1458,4 +1461,12 @@ public class Grid extends BaseGridComponent { this.paginateLineShowType = paginateLineShowType; this.getElementCasePane().repaint(); } + + public boolean isTranslucent() { + return isTranslucent; + } + + public void setTranslucent(boolean translucent) { + isTranslucent = translucent; + } } diff --git a/designer-realize/src/main/java/com/fr/grid/GridUI.java b/designer-realize/src/main/java/com/fr/grid/GridUI.java index 711ecee83..10934a7cc 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridUI.java +++ b/designer-realize/src/main/java/com/fr/grid/GridUI.java @@ -1128,8 +1128,10 @@ public class GridUI extends ComponentUI { double realWidth = gridSize.getWidth();// 宽度 double realHeight = gridSize.getHeight();// 高度 - // 画背景 - this.paintBackground(g2d, grid, elementCase, resolution); + if (!grid.isTranslucent()) { + // 画背景 + this.paintBackground(g2d, grid, elementCase, resolution); + } // 画Grid Line this.paintGridLine(g2d, grid, elementCase, realWidth, realHeight, resolution);