Browse Source

REPORT-59897 内边距范围调整-设计器内

【问题原因】
1. 内边距需要对标题文本也生效,当文本对齐方式为左对齐/右对齐时,
不应该再顶格放置了。即内边距从过去的对主体区域生效,改为对组件
外沿生效。有标题时,原主体区域上方的间距,现在就没了。

2. 边框需要从内边框变为正边框,即去掉原来1px的位移。

【改动思路】
同上
research/11.0
Starryi 3 years ago
parent
commit
0e02afd3d9
  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. 12
      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) {
int marginLeft = margin != null ? margin.getLeft() : 0;
int marginTop = margin != null ? margin.getTop() : 0;
int marginRight = margin != null ? margin.getRight() : 0;
int marginBottom = margin != null ? margin.getBottom() : 0;
int marginLeft = margin.left;
int marginTop = margin.top;
int marginRight = margin.right;
int marginBottom = margin.bottom;
int horizonMargin = marginLeft + marginRight;
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 Background borderImage4Painting; // 设计器预览界面中绘制边框图片
protected double borderImageOpacity4Painting;
protected Insets paddingInsets4Painting;
public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) {
super(widget, initSize);
@ -87,6 +88,24 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
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
* @return 同上
@ -371,11 +390,13 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
*/
@Override
public Insets getInsets() {
PaddingMargin padding = toData().getMargin();
if (padding == null) {
return new Insets(0, 0, 0, 0);
Container parent = this.getParent();
if (parent instanceof XWTitleLayout && parent.getComponentCount() > 1) {
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
public void paintForeground(Graphics2D g) {
Dimension size = getSize();
PaddingMargin margin = toData().getMargin();
Insets paddingInsets = getInsets();
if (!isEditing) {
// CHART-20568 & CHART-20627
@ -238,12 +238,12 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
// 同时这里又在下层绘制了一遍ChartComponent,导致图表进入编辑状态,会出现两个重叠的ChartComponent。
// 考虑到编辑中,FormDesigner中的ChartComponent位于上层,下层的ChartComponent实际上没什么用,所以可以不用绘制
// 下层的ChartComponent
designerEditor.paintEditor(g, size, margin);
designerEditor.paintEditor(g, size, paddingInsets);
}
if (coverPanel != null) {
int horizonMargin = margin != null ? margin.getLeft() + margin.getRight() : 0;
int verticalMargin = margin != null ? margin.getTop() + margin.getBottom() : 0;
int horizonMargin = paddingInsets.left + paddingInsets.right;
int verticalMargin = paddingInsets.top + paddingInsets.bottom;
coverPanel.setSize(size.width - horizonMargin, size.height - verticalMargin);
}
super.paintForeground(g);

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

@ -275,7 +275,7 @@ public class XCreatorUtils {
try {
creator = Reflect.on(clazz).create(widget, d).get();
} catch (Exception ignore) {
FineLoggerFactory.getLogger().error(ignore.getMessage(), ignore);
}
if (creator == null) {
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);
}
@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
protected void initXCreatorProperties() {
super.initXCreatorProperties();
@ -187,30 +200,37 @@ public class XWTitleLayout extends DedicateLayoutContainer {
Composite oldComposite = g2d.getComposite();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) this.titleBackgroundOpacity4Painting));
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);
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);
XCreator bodyCreator = getBodyCreator();
if (bodyCreator != null) {
int y = bodyCreator.getY();
int height = bodyCreator.getHeight();
Insets paddingInsets = getInsets();
Shape shape = new Rectangle2D.Double(0, y, getWidth(), height + paddingInsets.bottom);
bodyBackground4Painting.paint(g2d, shape);
g2d.setComposite(oldComposite);
}
}
}
/**
* 将WLayout转换为XLayoutContainer

12
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.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import com.fr.form.ui.container.WLayout;
@ -123,15 +124,20 @@ public class FRTitleLayout implements FRLayoutManager, LayoutManager{
synchronized (target.getTreeLock()) {
int width = target.getWidth();
int height = target.getHeight();
int titleH = title==null ? 0 : WTitleLayout.TITLE_HEIGHT;
Insets insets = target.getInsets();
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++) {
Component comp = target.getComponent(i);
if (comp != null) {
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) {
int y = titleH + gap;
comp.setBounds(0, y, width, height-y);
comp.setBounds(insets.left, y + insets.top, width, height - y);
}
}
}

Loading…
Cancel
Save