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 d278d130f8..09373189e8 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 @@ -46,7 +46,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); + CellStylePreviewPane pane = new CellStylePreviewPane(false, false); TemplateCellElement cellElement = DefaultThemedTemplateCellElementCase.createInstance(c, r); int flags = CellBorderSourceFlag.INVALID_BORDER_SOURCE; if (supportInnerBorder) { 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 66a873d4d1..dc888b1c10 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 @@ -30,13 +30,20 @@ import java.util.List; public class CellStylePreviewPane extends JPanel { public static final int MINIMUM_HEIGHT = 40; + private static final BufferedImage transparentBackgroundImage = IOUtils.readImage("/com/fr/design/images/transparent_background.png"); + private final float transparentBackgroundWidth; + private final float transparentBackgroundHeight; private String paintText = "Report"; private Style style = Style.DEFAULT_STYLE; private final boolean autoClearCanvas; + private final boolean paintingMosaic; - public CellStylePreviewPane(boolean autoClearCanvas) { + public CellStylePreviewPane(boolean autoClearCanvas, boolean paintingMosaic) { this.autoClearCanvas = autoClearCanvas; + this.paintingMosaic = paintingMosaic; + transparentBackgroundWidth = transparentBackgroundImage.getWidth(null); + transparentBackgroundHeight = transparentBackgroundImage.getHeight(null); setPreferredSize(new Dimension(0, 0)); } @@ -64,12 +71,52 @@ public class CellStylePreviewPane extends JPanel { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + if (paintingMosaic) { + paintTransparentBackground(g2d, style); + } + paintCellStyle(g2d, style); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } + private void paintTransparentBackground(Graphics2D g2d, Style style) { + float alpha = computeTransparentBackgroundAlpha(style); + + float scaleWidth = 1.0F * getWidth() / transparentBackgroundWidth; + float scaleHeight = 1.0F * getHeight() / transparentBackgroundHeight; + float maxScale = Math.max(scaleWidth, scaleHeight); + + if (maxScale <= 1) { + scaleWidth = scaleHeight = 1; + } else { + scaleHeight = scaleWidth = maxScale; + } + + Composite oldComposite = g2d.getComposite(); + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha)); + g2d.drawImage(transparentBackgroundImage, 0, 0, (int) (transparentBackgroundWidth * scaleWidth), (int) (transparentBackgroundHeight * scaleHeight), null); + g2d.setComposite(oldComposite); + } + + private float computeTextColorBrightness(Style style) { + Color fontColor = style.getFRFont().getForeground(); + return fontColor.getRed() * 0.299F + fontColor.getGreen() * 0.587F + fontColor.getBlue() * 0.114F; + } + + private float computeTransparentBackgroundAlpha(Style style) { + float textBrightness = computeTextColorBrightness(style); + + float alpha = 1.0F; + if (textBrightness < 50) { + alpha = 0.2F; + } else if (textBrightness < 160){ + alpha = 0.5F; + } + return alpha; + } + private void paintCellStyle(Graphics2D g2d, Style style) { int resolution = ScreenResolution.getScreenResolution(); @@ -86,9 +133,7 @@ public class CellStylePreviewPane extends JPanel { Style.paintContent(g2d, paintText, style, width, height, resolution); - Style.paintBorder(g2d, style, - width - GraphHelper.getLineStyleSize(style.getBorderRight()) / 2F, - height - GraphHelper.getLineStyleSize(style.getBorderBottom()) / 2F); + Style.paintBorder(g2d, style, width, height); } @Override diff --git a/designer-base/src/main/resources/com/fr/design/images/transparent_background.png b/designer-base/src/main/resources/com/fr/design/images/transparent_background.png index 61557d0a80..3db1fd14f2 100644 Binary files a/designer-base/src/main/resources/com/fr/design/images/transparent_background.png and b/designer-base/src/main/resources/com/fr/design/images/transparent_background.png differ 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 a5295ad7ec..24d8a7f4c1 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); + previewArea = new CellStylePreviewPane(true, true); followingThemeButtonGroup = new UIButtonGroup<>(FOLLOWING_THEME_STRING_ARRAYS); followingThemeButtonGroup.setAutoFireStateChanged(false); customStylePane = new CustomFloatStyleSettingPane();