Browse Source

REPORT-55211【组件背景分离】组件复用-图表块取消勾选标题可见,设置的主体背景(颜色/渐变色/图片),在设计界面里会遮盖住图表,可见图。web效果正常

子功能: 设计器组件样式主体背景预览
【问题原因】
图表重写了paint方法,导致super.paint中的背景绘制在了图表图片上方
【改动思路】
将XBorderStyleWidgetCreator中的paint方法分成若干部分:
clipByRoundedBorder: 圆角裁剪
paintBackground: 绘制背景
paintForeground: 绘制前景内容(在背景上方的组件内容)

图表可通过重写paintForeground方法实现之前的逻辑,同时保证内容不被背景遮盖
【review建议】
zheng-1641779399395
Starryi 4 years ago
parent
commit
c1e56841e1
  1. 8
      designer-form/src/main/java/com/fr/design/designer/creator/XAutoChartCreator.java
  2. 13
      designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java
  3. 11
      designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java

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

@ -18,8 +18,7 @@ import com.fr.stable.bridge.StableFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
@ -102,7 +101,8 @@ public class XAutoChartCreator extends XChartEditor {
}
public void paint(Graphics g) {
@Override
public void paintForeground(Graphics2D g) {
BufferedImage bufferedImage = IOUtils.readImage("com/fr/design/form/images/auto_chart_preview.png");
GraphHelper.paintImage(
g, this.getWidth(), this.getHeight(), bufferedImage,
@ -110,7 +110,7 @@ public class XAutoChartCreator extends XChartEditor {
0,
0, -1, -1
);
super.paint(g);
super.paintForeground(g);
}
private void initChart(BaseChartCollection chartCollection) {

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

@ -222,24 +222,23 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
}
// 设计器预览界面中绘制组件背景效果
private void paintBackground(Graphics2D g2d) {
public void paintBackground(Graphics2D g2d) {
Background background4Painting = getBackground4Painting();
if (background4Painting != null) {
background4Painting.paint(g2d, new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
}
}
@Override
protected void paintComponent(Graphics g) {
this.paintBackground((Graphics2D) g);
super.paintComponent(g);
public void paintForeground(Graphics2D g2d) {
super.paint(g2d);
super.paintBorder(g2d);
}
@Override
public void paint(Graphics g) {
this.clipByRoundedBorder((Graphics2D) g);
super.paint(g);
paintBorder(g);
this.paintBackground((Graphics2D) g);
this.paintForeground((Graphics2D) g);
}
@Override

11
designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java

@ -29,12 +29,8 @@ import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.*;
import java.beans.IntrospectionException;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
/**
@ -228,7 +224,8 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
/**
* 渲染Painter
*/
public void paint(Graphics g) {
@Override
public void paintForeground(Graphics2D g) {
Dimension size = getSize();
PaddingMargin margin = toData().getMargin();
designerEditor.paintEditor(g, size, margin);
@ -237,7 +234,7 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
int verticalMargin = margin != null ? margin.getTop() + margin.getBottom() : 0;
coverPanel.setSize(size.width - horizonMargin, size.height - verticalMargin);
}
super.paint(g);
super.paintForeground(g);
if (isEditing) {
g.setColor(INNER_BORDER_COLOR);
GraphHelper.draw(g, new Rectangle(0, 0, getWidth(), getHeight()), Constants.LINE_MEDIUM);

Loading…
Cancel
Save