From 906eddd5710e6ab6df32fecacd9a345b222346dc Mon Sep 17 00:00:00 2001 From: Starryi Date: Thu, 30 Dec 2021 11:25:15 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-65170=E3=80=90=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E8=BE=B9=E6=A1=86=E3=80=91=E6=82=AC=E6=B5=AE=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E7=9A=84=E9=A2=84=E8=A7=88=E5=9B=BE=EF=BC=8C=E5=8F=B3=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E8=BE=B9=E6=A1=86=E7=BA=BF=E7=9C=8B=E4=B8=8D=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 换个方式实现主题单元格内边框样式的预览效果,之前使用setClip(null)的 问题较大,会将边框绘制到父组件的其他区域 【改动思路】 根据预览时Cell的位置计算边框的位置,使得边框可以在Cell区域内完整展示 出来,而不至于被裁剪 --- .../cell/CellRectangleStylePreviewPane.java | 8 +++- .../fr/design/cell/CellStylePreviewPane.java | 39 +++++++++++++++++-- .../com/fr/design/report/ReportStylePane.java | 2 +- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java b/designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java index 09373189e8..c0b6a0bc85 100644 --- a/designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java @@ -15,6 +15,7 @@ import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; +import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.image.BufferedImage; @@ -46,7 +47,7 @@ public class CellRectangleStylePreviewPane extends JPanel { for (int r = 0; r < ROW_COUNT; r++) { for (int c = 0; c < COLUMN_COUNT; c++) { - CellStylePreviewPane pane = new CellStylePreviewPane(false, false); + CellStylePreviewPane pane = new CellStylePreviewPane(c, r, COLUMN_COUNT, ROW_COUNT, false, false); TemplateCellElement cellElement = DefaultThemedTemplateCellElementCase.createInstance(c, r); int flags = CellBorderSourceFlag.INVALID_BORDER_SOURCE; if (supportInnerBorder) { @@ -136,6 +137,11 @@ public class CellRectangleStylePreviewPane extends JPanel { super.paint(g); } + @Override + public Rectangle getBounds() { + return super.getBounds(); + } + private void paintTransparentBackground(Graphics2D g2d, Style style) { float alpha = computeTransparentBackgroundAlpha(style); diff --git a/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java b/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java index f90c78d87f..899c04cb17 100644 --- a/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java @@ -18,7 +18,9 @@ import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Rectangle; import java.awt.RenderingHints; +import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.util.List; @@ -36,10 +38,19 @@ public class CellStylePreviewPane extends JPanel { private String paintText = "Report"; private Style style = Style.DEFAULT_STYLE; + private final int column; + private final int row; + private final int columnSpan; + private final int rowSpan; + private final boolean autoClearCanvas; private final boolean paintingMosaic; - public CellStylePreviewPane(boolean autoClearCanvas, boolean paintingMosaic) { + public CellStylePreviewPane(int column, int row, int columnSpan, int rowSpan, boolean autoClearCanvas, boolean paintingMosaic) { + this.column = column; + this.row = row; + this.columnSpan = columnSpan; + this.rowSpan = rowSpan; this.autoClearCanvas = autoClearCanvas; this.paintingMosaic = paintingMosaic; transparentBackgroundWidth = transparentBackgroundImage.getWidth(null); @@ -133,8 +144,30 @@ public class CellStylePreviewPane extends JPanel { Style.paintContent(g2d, paintText, style, width, height, resolution); - g2d.setClip(null); - Style.paintBorder(g2d, style, width, height); + paintCellBorder(g2d, style); + } + + protected void paintCellBorder(Graphics2D g2d, Style style) { + float adjustLeft = 0; + float adjustTop = 0; + float adjustRight = 0; + float adjustBottom = 0; + if (column == 0) { + adjustLeft = GraphHelper.getLineStyleSize(style.getBorderLeft()) / 2.0F; + } + if (row == 0) { + adjustTop = GraphHelper.getLineStyleSize(style.getBorderTop()) / 2.0F; + } + if (column == columnSpan - 1) { + adjustRight = -GraphHelper.getLineStyleSize(style.getBorderRight()) / 2.0F; + } + if (row == rowSpan - 1) { + adjustBottom = -GraphHelper.getLineStyleSize(style.getBorderBottom()) / 2.0F; + } + + g2d.translate(adjustLeft, adjustTop); + Style.paintBorder(g2d, style, getWidth() - adjustLeft + adjustRight, getHeight() - adjustTop + adjustBottom); + g2d.translate(-adjustLeft, -adjustTop); } @Override diff --git a/designer-realize/src/main/java/com/fr/design/report/ReportStylePane.java b/designer-realize/src/main/java/com/fr/design/report/ReportStylePane.java index 24d8a7f4c1..4777d01727 100644 --- a/designer-realize/src/main/java/com/fr/design/report/ReportStylePane.java +++ b/designer-realize/src/main/java/com/fr/design/report/ReportStylePane.java @@ -79,7 +79,7 @@ public class ReportStylePane extends BasicPane { setLayout(FRGUIPaneFactory.createBorderLayout()); setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); - previewArea = new CellStylePreviewPane(true, true); + previewArea = new CellStylePreviewPane(0, 0, 1,1, true, true); followingThemeButtonGroup = new UIButtonGroup<>(FOLLOWING_THEME_STRING_ARRAYS); followingThemeButtonGroup.setAutoFireStateChanged(false); customStylePane = new CustomFloatStyleSettingPane();