|
|
|
@ -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 |
|
|
|
|