Browse Source

EPORT-55747 【组件背景分离】组件复用-设计器画布效果,标题背景遮挡边框图片

【问题原因】
边框图片被标题背景遮挡。
标题背景由XLabel绘制,边框图片由XWTitleLayout绘制导致的
【改动思路】
1. 标题背景/主体背景/边框图片均由XWTitleLayout绘制
2. 整理下背景/边框绘制相关的接口
final/10.0
Starryi 3 years ago
parent
commit
796c285d82
  1. 93
      designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java
  2. 8
      designer-form/src/main/java/com/fr/design/designer/creator/XLabel.java
  3. 54
      designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java
  4. 4
      designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java

93
designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java

@ -52,33 +52,26 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
return this.background4Painting;
}
public void setBackground4Painting(Background background4Painting) {
this.background4Painting = background4Painting;
this.repaint();
}
public double getBackgroundOpacity4Painting() {
return backgroundOpacity4Painting;
}
public void setBackgroundOpacity4Painting(double backgroundOpacity4Painting) {
this.backgroundOpacity4Painting = backgroundOpacity4Painting;
public void setBackground4Painting(Background background, double opacity) {
this.background4Painting = background;
this.backgroundOpacity4Painting = opacity;
}
public Background getBorderImage4Painting() {
return borderImage4Painting;
}
public void setBorderImage4Painting(Background borderImage4Painting) {
this.borderImage4Painting = borderImage4Painting;
}
public double getBorderImageOpacity4Painting() {
return borderImageOpacity4Painting;
}
public void setBorderImageOpacity4Painting(double borderImageOpacity4Painting) {
this.borderImageOpacity4Painting = borderImageOpacity4Painting;
public void setBorderImage4Painting(Background borderImage, double opacity) {
this.borderImage4Painting = borderImage;
this.borderImageOpacity4Painting = opacity;
}
/**
@ -129,11 +122,13 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
}
this.setBorder(border);
this.setBorderImage4Painting(style != null ? style.getBorderImage() : null);
this.setBorderImageOpacity4Painting(style != null ? style.getBorderImageOpacity() : 0.0);
this.setBackground4Painting(style != null ? style.getBackground() : null);
this.setBackgroundOpacity4Painting(style != null ? style.getAlpha() : 0.0);
if (style != null) {
this.setBorderImage4Painting(style.getBorderImage(), style.getBorderImageOpacity());
this.setBackground4Painting(style.getBackground(), style.getAlpha());
} else {
this.setBorderImage4Painting(null, 0.0);
this.setBackground4Painting(null, 0.0);
}
}
private void clearTitleWidget() {
@ -213,10 +208,17 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
XCreator titleCreator = titleParent.getTitleCreator();
XCreator bodyXCreator = titleParent.getBodyCreator();
Border border = bodyXCreator.getBorder();
reshuffleBorderPaintingEffectIfTitleExists(titleParent, titleCreator, bodyXCreator);
reshuffleBackgroundPaintingEffectIfTitleExists(titleParent, titleCreator, bodyXCreator);
}
}
}
private void reshuffleBorderPaintingEffectIfTitleExists(XWTitleLayout parentCreator, XCreator titleCreator, XCreator bodyCreator) {
Border border = bodyCreator.getBorder();
titleParent.setBorder(border); // 容器绘制完整边框
bodyXCreator.setBorder(BorderFactory.createEmptyBorder()); // body不绘制边框
parentCreator.setBorder(border); // 容器绘制完整边框
bodyCreator.setBorder(BorderFactory.createEmptyBorder()); // body不绘制边框
titleCreator.setBorder(BorderFactory.createEmptyBorder()); // title绘制底部边框
if (border instanceof LineBorder) {
Color color = ((LineBorder) border).getLineColor();
@ -224,28 +226,35 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
titleCreator.setBorder(new BottomLineBorder(color, thickness));
}
if (bodyXCreator instanceof XBorderStyleWidgetCreator) {
XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyXCreator;
Background borderImage4Painting = styledBodyXCreator.getBorderImage4Painting();
if (bodyCreator instanceof XBorderStyleWidgetCreator) {
XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyCreator;
Background borderImage= styledBodyXCreator.getBorderImage4Painting();
double opacity = styledBodyXCreator.getBorderImageOpacity4Painting();
styledBodyXCreator.setBorderImage4Painting(null); // body不绘制图片边框
styledBodyXCreator.setBorderImageOpacity4Painting(0.0);
titleParent.setBorderImage4Painting(borderImage4Painting); // 容器绘制完整图片边框
titleParent.setBorderImageOpacity4Painting(opacity);
styledBodyXCreator.setBorderImage4Painting(null, 0.0); // body不绘制图片边框
parentCreator.setBorderImage4Painting(borderImage, opacity); // 容器绘制完整图片边框
}
}
if (bodyXCreator instanceof XBorderStyleWidgetCreator) {
XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyXCreator;
Background background4Painting = styledBodyXCreator.getBackground4Painting();
double opacity = styledBodyXCreator.getBackgroundOpacity4Painting();
private void reshuffleBackgroundPaintingEffectIfTitleExists(XWTitleLayout parentCreator, XCreator titleCreator, XCreator bodyCreator) {
if (titleCreator instanceof XLabel) {
XLabel labelCreator = (XLabel) titleCreator;
Label titleLabel = labelCreator.toData();
styledBodyXCreator.setBackground4Painting(null); // body不绘制背景
styledBodyXCreator.setBackgroundOpacity4Painting(0.0);
titleParent.setBackground4Painting(background4Painting); // 容器绘制完整背景
titleParent.setBackgroundOpacity4Painting(opacity);
}
Background background = titleLabel.getBackground();
double opacity = titleLabel.getBackgroundOpacity();
labelCreator.setEnabledBackgroundPainting(false); // 标题不绘制背景
parentCreator.setTitleBackground4Painting(background, opacity); // 容器绘制完整背景
}
if (bodyCreator instanceof XBorderStyleWidgetCreator) {
XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyCreator;
Background background = styledBodyXCreator.getBackground4Painting();
double opacity = styledBodyXCreator.getBackgroundOpacity4Painting();
styledBodyXCreator.setBackground4Painting(null, 0.0); // body不绘制背景
parentCreator.setBodyBackground4Painting(background, opacity); // 容器绘制完整背景
}
}
@ -273,16 +282,6 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) backgroundOpacity4Painting));
Shape shape = new Rectangle2D.Double(0, 0, getWidth(), getHeight());
if (this instanceof XWTitleLayout) {
// 兼容性考虑,组件样式背景不作用在标题范围内,只作用在控件整体,但同时不能遮挡作用于整体的边框图片
// 所以考虑样式背景与边框图片都由XWTitleLayout绘制,但样式背景要向下偏移标题栏的高度
XWTitleLayout titleParent = (XWTitleLayout) this;
if (getComponentCount() > 1) {
XCreator titleCreator = titleParent.getTitleCreator();
int titleHeight = titleCreator != null ? titleCreator.getHeight() : 0;
shape = new Rectangle2D.Double(0, titleHeight, getWidth(), getHeight() - titleHeight);
}
}
background4Painting.paint(g2d, shape);
g2d.setComposite(oldComposite);

8
designer-form/src/main/java/com/fr/design/designer/creator/XLabel.java

@ -19,7 +19,6 @@ import com.fr.form.ui.Label;
import com.fr.form.ui.container.WParameterLayout;
import com.fr.general.Background;
import com.fr.general.act.BorderPacker;
import com.fr.stable.ArrayUtils;
import com.fr.stable.Constants;
import com.fr.stable.core.PropertyChangeAdapter;
@ -36,11 +35,16 @@ import java.beans.IntrospectionException;
public class XLabel extends XWidgetCreator {
private int cornerSize = 15;
private boolean enabledBackgroundPainting = true;
public XLabel(Label widget, Dimension initSize) {
super(widget, initSize);
}
public void setEnabledBackgroundPainting(boolean enable) {
this.enabledBackgroundPainting = enable;
}
/**
* 生成creator对应的控件widget
*
@ -93,7 +97,7 @@ public class XLabel extends XWidgetCreator {
Dimension size = this.getSize();
//先画背景,再画标题
Background background = label.getBackground();
if (background != null) {
if (background != null && enabledBackgroundPainting) {
Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, label.getBackgroundOpacity()));

54
designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java

@ -12,10 +12,12 @@ import com.fr.form.ui.Widget;
import com.fr.form.ui.WidgetTitle;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.Background;
import com.fr.general.ComparatorUtils;
import java.awt.*;
import java.awt.event.ContainerEvent;
import java.awt.geom.Rectangle2D;
/**
* 一些控件 如图表报表块有标题设置且标题的高度字体等不变
@ -31,6 +33,11 @@ public class XWTitleLayout extends DedicateLayoutContainer {
private static final int INDEX = 0;
protected Background titleBackground4Painting; // 设计器预览界面中绘制title背景图
protected double titleBackgroundOpacity4Painting;
protected Background bodyBackground4Painting; // 设计器预览界面中绘制body背景图
protected double bodyBackgroundOpacity4Painting;
public XWTitleLayout() {
super(new WTitleLayout("titlePane"), new Dimension());
}
@ -45,6 +52,16 @@ public class XWTitleLayout extends DedicateLayoutContainer {
super(widget, initSize);
}
public void setTitleBackground4Painting(Background background, double opacity) {
this.titleBackground4Painting = background;
this.titleBackgroundOpacity4Painting = opacity;
}
public void setBodyBackground4Painting(Background background, double opacity) {
this.bodyBackground4Painting = background;
this.bodyBackgroundOpacity4Painting = opacity;
}
@Override
protected void initXCreatorProperties() {
super.initXCreatorProperties();
@ -150,6 +167,43 @@ public class XWTitleLayout extends DedicateLayoutContainer {
}
@Override
public void paintBackground(Graphics2D g2d) {
if (getComponentCount() > 1) {
paintTitleBackground(g2d);
paintBodyBackground(g2d);
}
}
private void paintTitleBackground(Graphics2D g2d) {
if (titleBackground4Painting != null) {
Composite oldComposite = g2d.getComposite();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) this.titleBackgroundOpacity4Painting));
XCreator titleCreator = getTitleCreator();
int titleHeight = titleCreator != null ? titleCreator.getHeight() : 0;
Shape shape = new Rectangle2D.Double(0, 0, getWidth(), titleHeight);
titleBackground4Painting.paint(g2d, shape);
g2d.setComposite(oldComposite);
}
}
private void paintBodyBackground(Graphics2D g2d) {
if (bodyBackground4Painting != null) {
Composite oldComposite = g2d.getComposite();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) this.bodyBackgroundOpacity4Painting));
XCreator titleCreator = getTitleCreator();
int titleHeight = titleCreator != null ? titleCreator.getHeight() : 0;
// 兼容性考虑,组件样式背景不作用在标题范围内,只作用在控件整体,但同时不能遮挡作用于整体的边框图片
// 所以考虑样式背景与边框图片都由XWTitleLayout绘制,但样式背景要向下偏移标题栏的高度
Shape shape = new Rectangle2D.Double(0, titleHeight, getWidth(), getHeight() - titleHeight);
bodyBackground4Painting.paint(g2d, shape);
g2d.setComposite(oldComposite);
}
}
/**
* 将WLayout转换为XLayoutContainer

4
designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java

@ -39,7 +39,6 @@ import com.fr.report.elementcase.TemplateElementCase;
import com.fr.report.worksheet.FormElementCase;
import com.fr.report.worksheet.WorkSheet;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
@ -49,7 +48,6 @@ import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.File;
/**
* 表单中的ElementCase编辑面板
@ -160,8 +158,6 @@ public class FormElementCaseDesigner
grid.setTranslucent(oldTranslucent);
}
ImageIO.write(image, "png", new File("/Users/Starryi/test.png"));
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}

Loading…
Cancel
Save