Browse Source

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

Merge in DESIGN/design from ~STARRYI/design:final/10.0 to final/10.0

* commit '796c285d8269a6074f190419ebaba3225a4c72c8':
  EPORT-55747 【组件背景分离】组件复用-设计器画布效果,标题背景遮挡边框图片
final/10.0
Kara 3 years ago
parent
commit
8fe556280c
  1. 119
      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

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

@ -52,33 +52,26 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
return this.background4Painting; return this.background4Painting;
} }
public void setBackground4Painting(Background background4Painting) {
this.background4Painting = background4Painting;
this.repaint();
}
public double getBackgroundOpacity4Painting() { public double getBackgroundOpacity4Painting() {
return backgroundOpacity4Painting; return backgroundOpacity4Painting;
} }
public void setBackgroundOpacity4Painting(double backgroundOpacity4Painting) { public void setBackground4Painting(Background background, double opacity) {
this.backgroundOpacity4Painting = backgroundOpacity4Painting; this.background4Painting = background;
this.backgroundOpacity4Painting = opacity;
} }
public Background getBorderImage4Painting() { public Background getBorderImage4Painting() {
return borderImage4Painting; return borderImage4Painting;
} }
public void setBorderImage4Painting(Background borderImage4Painting) {
this.borderImage4Painting = borderImage4Painting;
}
public double getBorderImageOpacity4Painting() { public double getBorderImageOpacity4Painting() {
return borderImageOpacity4Painting; return borderImageOpacity4Painting;
} }
public void setBorderImageOpacity4Painting(double borderImageOpacity4Painting) { public void setBorderImage4Painting(Background borderImage, double opacity) {
this.borderImageOpacity4Painting = borderImageOpacity4Painting; this.borderImage4Painting = borderImage;
this.borderImageOpacity4Painting = opacity;
} }
/** /**
@ -129,11 +122,13 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
} }
this.setBorder(border); this.setBorder(border);
this.setBorderImage4Painting(style != null ? style.getBorderImage() : null); if (style != null) {
this.setBorderImageOpacity4Painting(style != null ? style.getBorderImageOpacity() : 0.0); this.setBorderImage4Painting(style.getBorderImage(), style.getBorderImageOpacity());
this.setBackground4Painting(style.getBackground(), style.getAlpha());
this.setBackground4Painting(style != null ? style.getBackground() : null); } else {
this.setBackgroundOpacity4Painting(style != null ? style.getAlpha() : 0.0); this.setBorderImage4Painting(null, 0.0);
this.setBackground4Painting(null, 0.0);
}
} }
private void clearTitleWidget() { private void clearTitleWidget() {
@ -213,42 +208,56 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
XCreator titleCreator = titleParent.getTitleCreator(); XCreator titleCreator = titleParent.getTitleCreator();
XCreator bodyXCreator = titleParent.getBodyCreator(); XCreator bodyXCreator = titleParent.getBodyCreator();
Border border = bodyXCreator.getBorder(); reshuffleBorderPaintingEffectIfTitleExists(titleParent, titleCreator, bodyXCreator);
reshuffleBackgroundPaintingEffectIfTitleExists(titleParent, titleCreator, bodyXCreator);
titleParent.setBorder(border); // 容器绘制完整边框
bodyXCreator.setBorder(BorderFactory.createEmptyBorder()); // body不绘制边框
titleCreator.setBorder(BorderFactory.createEmptyBorder()); // title绘制底部边框
if (border instanceof LineBorder) {
Color color = ((LineBorder) border).getLineColor();
int thickness = ((LineBorder) border).getThickness();
titleCreator.setBorder(new BottomLineBorder(color, thickness));
}
if (bodyXCreator instanceof XBorderStyleWidgetCreator) {
XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyXCreator;
Background borderImage4Painting = styledBodyXCreator.getBorderImage4Painting();
double opacity = styledBodyXCreator.getBorderImageOpacity4Painting();
styledBodyXCreator.setBorderImage4Painting(null); // body不绘制图片边框
styledBodyXCreator.setBorderImageOpacity4Painting(0.0);
titleParent.setBorderImage4Painting(borderImage4Painting); // 容器绘制完整图片边框
titleParent.setBorderImageOpacity4Painting(opacity);
}
if (bodyXCreator instanceof XBorderStyleWidgetCreator) {
XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyXCreator;
Background background4Painting = styledBodyXCreator.getBackground4Painting();
double opacity = styledBodyXCreator.getBackgroundOpacity4Painting();
styledBodyXCreator.setBackground4Painting(null); // body不绘制背景
styledBodyXCreator.setBackgroundOpacity4Painting(0.0);
titleParent.setBackground4Painting(background4Painting); // 容器绘制完整背景
titleParent.setBackgroundOpacity4Painting(opacity);
}
} }
} }
} }
private void reshuffleBorderPaintingEffectIfTitleExists(XWTitleLayout parentCreator, XCreator titleCreator, XCreator bodyCreator) {
Border border = bodyCreator.getBorder();
parentCreator.setBorder(border); // 容器绘制完整边框
bodyCreator.setBorder(BorderFactory.createEmptyBorder()); // body不绘制边框
titleCreator.setBorder(BorderFactory.createEmptyBorder()); // title绘制底部边框
if (border instanceof LineBorder) {
Color color = ((LineBorder) border).getLineColor();
int thickness = ((LineBorder) border).getThickness();
titleCreator.setBorder(new BottomLineBorder(color, thickness));
}
if (bodyCreator instanceof XBorderStyleWidgetCreator) {
XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyCreator;
Background borderImage= styledBodyXCreator.getBorderImage4Painting();
double opacity = styledBodyXCreator.getBorderImageOpacity4Painting();
styledBodyXCreator.setBorderImage4Painting(null, 0.0); // body不绘制图片边框
parentCreator.setBorderImage4Painting(borderImage, opacity); // 容器绘制完整图片边框
}
}
private void reshuffleBackgroundPaintingEffectIfTitleExists(XWTitleLayout parentCreator, XCreator titleCreator, XCreator bodyCreator) {
if (titleCreator instanceof XLabel) {
XLabel labelCreator = (XLabel) titleCreator;
Label titleLabel = labelCreator.toData();
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); // 容器绘制完整背景
}
}
// 根据当前组件边框裁剪内容,如果当前组件存在圆角,则应当按圆角裁剪内容 // 根据当前组件边框裁剪内容,如果当前组件存在圆角,则应当按圆角裁剪内容
private void clipByRoundedBorder(Graphics2D g2d) { private void clipByRoundedBorder(Graphics2D g2d) {
@ -273,16 +282,6 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) backgroundOpacity4Painting)); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) backgroundOpacity4Painting));
Shape shape = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); 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); background4Painting.paint(g2d, shape);
g2d.setComposite(oldComposite); 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.form.ui.container.WParameterLayout;
import com.fr.general.Background; import com.fr.general.Background;
import com.fr.general.act.BorderPacker;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import com.fr.stable.core.PropertyChangeAdapter; import com.fr.stable.core.PropertyChangeAdapter;
@ -36,11 +35,16 @@ import java.beans.IntrospectionException;
public class XLabel extends XWidgetCreator { public class XLabel extends XWidgetCreator {
private int cornerSize = 15; private int cornerSize = 15;
private boolean enabledBackgroundPainting = true;
public XLabel(Label widget, Dimension initSize) { public XLabel(Label widget, Dimension initSize) {
super(widget, initSize); super(widget, initSize);
} }
public void setEnabledBackgroundPainting(boolean enable) {
this.enabledBackgroundPainting = enable;
}
/** /**
* 生成creator对应的控件widget * 生成creator对应的控件widget
* *
@ -93,7 +97,7 @@ public class XLabel extends XWidgetCreator {
Dimension size = this.getSize(); Dimension size = this.getSize();
//先画背景,再画标题 //先画背景,再画标题
Background background = label.getBackground(); Background background = label.getBackground();
if (background != null) { if (background != null && enabledBackgroundPainting) {
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, label.getBackgroundOpacity())); 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.WidgetTitle;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import com.fr.form.ui.container.WTitleLayout; import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.Background;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import java.awt.*; import java.awt.*;
import java.awt.event.ContainerEvent; 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; private static final int INDEX = 0;
protected Background titleBackground4Painting; // 设计器预览界面中绘制title背景图
protected double titleBackgroundOpacity4Painting;
protected Background bodyBackground4Painting; // 设计器预览界面中绘制body背景图
protected double bodyBackgroundOpacity4Painting;
public XWTitleLayout() { public XWTitleLayout() {
super(new WTitleLayout("titlePane"), new Dimension()); super(new WTitleLayout("titlePane"), new Dimension());
} }
@ -45,6 +52,16 @@ public class XWTitleLayout extends DedicateLayoutContainer {
super(widget, initSize); 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 @Override
protected void initXCreatorProperties() { protected void initXCreatorProperties() {
super.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 * 将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.FormElementCase;
import com.fr.report.worksheet.WorkSheet; import com.fr.report.worksheet.WorkSheet;
import javax.imageio.ImageIO;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollBar; import javax.swing.JScrollBar;
@ -49,7 +48,6 @@ import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Transparency; import java.awt.Transparency;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File;
/** /**
* 表单中的ElementCase编辑面板 * 表单中的ElementCase编辑面板
@ -160,8 +158,6 @@ public class FormElementCaseDesigner
grid.setTranslucent(oldTranslucent); grid.setTranslucent(oldTranslucent);
} }
ImageIO.write(image, "png", new File("/Users/Starryi/test.png"));
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }

Loading…
Cancel
Save