Browse Source

Pull request #6127: REPORT-59897 内边距范围调整-设计器内

Merge in DESIGN/design from ~STARRYI/design:REPORT-59897 to feature/x

* commit '0e02afd3d9ba1719c03e78b5a6e6e2da3b5d6626':
  REPORT-59897 内边距范围调整-设计器内
research/11.0
starryi 3 years ago
parent
commit
9345a2eb99
  1. 10
      designer-form/src/main/java/com/fr/design/designer/beans/events/DesignerEditor.java
  2. 29
      designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java
  3. 8
      designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java
  4. 2
      designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java
  5. 34
      designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java
  6. 10
      designer-form/src/main/java/com/fr/design/form/layout/FRTitleLayout.java

10
designer-form/src/main/java/com/fr/design/designer/beans/events/DesignerEditor.java

@ -77,12 +77,12 @@ public class DesignerEditor<T extends JComponent> implements PropertyChangeListe
} }
} }
public void paintEditor(Graphics g, Dimension size, PaddingMargin margin) { public void paintEditor(Graphics g, Dimension size, Insets margin) {
if (this.comp != null) { if (this.comp != null) {
int marginLeft = margin != null ? margin.getLeft() : 0; int marginLeft = margin.left;
int marginTop = margin != null ? margin.getTop() : 0; int marginTop = margin.top;
int marginRight = margin != null ? margin.getRight() : 0; int marginRight = margin.right;
int marginBottom = margin != null ? margin.getBottom() : 0; int marginBottom = margin.bottom;
int horizonMargin = marginLeft + marginRight; int horizonMargin = marginLeft + marginRight;
int verticalMargin = marginTop + marginBottom; int verticalMargin = marginTop + marginBottom;

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

@ -40,6 +40,7 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
protected double backgroundOpacity4Painting; // 设计器预览界面中绘制组件背景图 protected double backgroundOpacity4Painting; // 设计器预览界面中绘制组件背景图
protected Background borderImage4Painting; // 设计器预览界面中绘制边框图片 protected Background borderImage4Painting; // 设计器预览界面中绘制边框图片
protected double borderImageOpacity4Painting; protected double borderImageOpacity4Painting;
protected Insets paddingInsets4Painting;
public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) { public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) {
super(widget, initSize); super(widget, initSize);
@ -87,6 +88,24 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
this.borderImageOpacity4Painting = opacity; this.borderImageOpacity4Painting = opacity;
} }
public void setPaddingInsets4Painting(PaddingMargin margin) {
if (this.paddingInsets4Painting == null) {
this.paddingInsets4Painting = new Insets(0, 0, 0, 0);
}
if (margin == null) {
this.paddingInsets4Painting.set(0, 0, 0, 0);
} else {
this.paddingInsets4Painting.set(margin.getTop(), margin.getLeft(), margin.getBottom(), margin.getRight());
}
}
protected Insets getPaddingInsets4Painting() {
if (this.paddingInsets4Painting == null) {
this.paddingInsets4Painting = new Insets(0, 0, 0, 0);
}
return this.paddingInsets4Painting;
}
/** /**
* 返回容器对应的widget * 返回容器对应的widget
* @return 同上 * @return 同上
@ -371,11 +390,13 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
*/ */
@Override @Override
public Insets getInsets() { public Insets getInsets() {
PaddingMargin padding = toData().getMargin(); Container parent = this.getParent();
if (padding == null) { if (parent instanceof XWTitleLayout && parent.getComponentCount() > 1) {
return new Insets(0, 0, 0, 0); setPaddingInsets4Painting(null);
} else {
setPaddingInsets4Painting(toData().getMargin());
} }
return new Insets(padding.getTop(), padding.getLeft(), padding.getBottom(), padding.getRight()); return getPaddingInsets4Painting();
} }
/** /**

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

@ -230,7 +230,7 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
@Override @Override
public void paintForeground(Graphics2D g) { public void paintForeground(Graphics2D g) {
Dimension size = getSize(); Dimension size = getSize();
PaddingMargin margin = toData().getMargin(); Insets paddingInsets = getInsets();
if (!isEditing) { if (!isEditing) {
// CHART-20568 & CHART-20627 // CHART-20568 & CHART-20627
@ -238,12 +238,12 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
// 同时这里又在下层绘制了一遍ChartComponent,导致图表进入编辑状态,会出现两个重叠的ChartComponent。 // 同时这里又在下层绘制了一遍ChartComponent,导致图表进入编辑状态,会出现两个重叠的ChartComponent。
// 考虑到编辑中,FormDesigner中的ChartComponent位于上层,下层的ChartComponent实际上没什么用,所以可以不用绘制 // 考虑到编辑中,FormDesigner中的ChartComponent位于上层,下层的ChartComponent实际上没什么用,所以可以不用绘制
// 下层的ChartComponent // 下层的ChartComponent
designerEditor.paintEditor(g, size, margin); designerEditor.paintEditor(g, size, paddingInsets);
} }
if (coverPanel != null) { if (coverPanel != null) {
int horizonMargin = margin != null ? margin.getLeft() + margin.getRight() : 0; int horizonMargin = paddingInsets.left + paddingInsets.right;
int verticalMargin = margin != null ? margin.getTop() + margin.getBottom() : 0; int verticalMargin = paddingInsets.top + paddingInsets.bottom;
coverPanel.setSize(size.width - horizonMargin, size.height - verticalMargin); coverPanel.setSize(size.width - horizonMargin, size.height - verticalMargin);
} }
super.paintForeground(g); super.paintForeground(g);

2
designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java

@ -275,7 +275,7 @@ public class XCreatorUtils {
try { try {
creator = Reflect.on(clazz).create(widget, d).get(); creator = Reflect.on(clazz).create(widget, d).get();
} catch (Exception ignore) { } catch (Exception ignore) {
FineLoggerFactory.getLogger().error(ignore.getMessage(), ignore);
} }
if (creator == null) { if (creator == null) {
FineLoggerFactory.getLogger().error("Error to create xcreator!"); FineLoggerFactory.getLogger().error("Error to create xcreator!");

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

@ -69,6 +69,19 @@ public class XWTitleLayout extends DedicateLayoutContainer {
setBackground4Painting(null, 0.0); setBackground4Painting(null, 0.0);
} }
@Override
public Insets getInsets() {
if (getComponentCount() > 1) {
XCreator bodyCreator = getBodyCreator();
if (bodyCreator instanceof XBorderStyleWidgetCreator) {
XBorderStyleWidgetCreator styleBodyCreator = (XBorderStyleWidgetCreator) bodyCreator;
setPaddingInsets4Painting(styleBodyCreator.toData().getMargin());
return getPaddingInsets4Painting();
}
}
return super.getInsets();
}
@Override @Override
protected void initXCreatorProperties() { protected void initXCreatorProperties() {
super.initXCreatorProperties(); super.initXCreatorProperties();
@ -187,30 +200,37 @@ public class XWTitleLayout extends DedicateLayoutContainer {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) this.titleBackgroundOpacity4Painting)); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) this.titleBackgroundOpacity4Painting));
XCreator titleCreator = getTitleCreator(); XCreator titleCreator = getTitleCreator();
int titleHeight = titleCreator != null ? titleCreator.getHeight() : 0; if (titleCreator != null) {
int height = titleCreator.getHeight();
Insets paddingInsets = getInsets();
Shape shape = new Rectangle2D.Double(0, 0, getWidth(), titleHeight); Shape shape = new Rectangle2D.Double(0, 0, getWidth(), height + paddingInsets.top);
titleBackground4Painting.paint(g2d, shape); titleBackground4Painting.paint(g2d, shape);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
} }
}
private void paintBodyBackground(Graphics2D g2d) { private void paintBodyBackground(Graphics2D g2d) {
if (bodyBackground4Painting != null) { if (bodyBackground4Painting != null) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) this.bodyBackgroundOpacity4Painting)); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) this.bodyBackgroundOpacity4Painting));
XCreator titleCreator = getTitleCreator(); XCreator bodyCreator = getBodyCreator();
int titleHeight = titleCreator != null ? titleCreator.getHeight() : 0;
// 兼容性考虑,组件样式背景不作用在标题范围内,只作用在控件整体,但同时不能遮挡作用于整体的边框图片 if (bodyCreator != null) {
// 所以考虑样式背景与边框图片都由XWTitleLayout绘制,但样式背景要向下偏移标题栏的高度 int y = bodyCreator.getY();
Shape shape = new Rectangle2D.Double(0, titleHeight, getWidth(), getHeight() - titleHeight); int height = bodyCreator.getHeight();
Insets paddingInsets = getInsets();
Shape shape = new Rectangle2D.Double(0, y, getWidth(), height + paddingInsets.bottom);
bodyBackground4Painting.paint(g2d, shape); bodyBackground4Painting.paint(g2d, shape);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
} }
}
/** /**
* 将WLayout转换为XLayoutContainer * 将WLayout转换为XLayoutContainer

10
designer-form/src/main/java/com/fr/design/form/layout/FRTitleLayout.java

@ -6,6 +6,7 @@ package com.fr.design.form.layout;
import java.awt.Component; import java.awt.Component;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager; import java.awt.LayoutManager;
import com.fr.form.ui.container.WLayout; import com.fr.form.ui.container.WLayout;
@ -123,15 +124,20 @@ public class FRTitleLayout implements FRLayoutManager, LayoutManager{
synchronized (target.getTreeLock()) { synchronized (target.getTreeLock()) {
int width = target.getWidth(); int width = target.getWidth();
int height = target.getHeight(); int height = target.getHeight();
Insets insets = target.getInsets();
int titleH = title == null ? 0 : WTitleLayout.TITLE_HEIGHT; int titleH = title == null ? 0 : WTitleLayout.TITLE_HEIGHT;
insets = title == null ? new Insets(0, 0, 0, 0) : insets;
width = Math.max(0, width - insets.left - insets.right);
height = Math.max(0, height - insets.top - insets.bottom);
for (int i=0; i< target.getComponentCount(); i++) { for (int i=0; i< target.getComponentCount(); i++) {
Component comp = target.getComponent(i); Component comp = target.getComponent(i);
if (comp != null) { if (comp != null) {
if (comp == title) { if (comp == title) {
comp.setBounds(0, 0, width, WTitleLayout.TITLE_HEIGHT); comp.setBounds(insets.left, insets.top, width, WTitleLayout.TITLE_HEIGHT);
} else if (comp == body) { } else if (comp == body) {
int y = titleH + gap; int y = titleH + gap;
comp.setBounds(0, y, width, height-y); comp.setBounds(insets.left, y + insets.top, width, height - y);
} }
} }
} }

Loading…
Cancel
Save