From 0e02afd3d9ba1719c03e78b5a6e6e2da3b5d6626 Mon Sep 17 00:00:00 2001 From: Starryi Date: Mon, 27 Sep 2021 18:13:11 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-59897=20=E5=86=85=E8=BE=B9=E8=B7=9D?= =?UTF-8?q?=E8=8C=83=E5=9B=B4=E8=B0=83=E6=95=B4-=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 1. 内边距需要对标题文本也生效,当文本对齐方式为左对齐/右对齐时, 不应该再顶格放置了。即内边距从过去的对主体区域生效,改为对组件 外沿生效。有标题时,原主体区域上方的间距,现在就没了。 2. 边框需要从内边框变为正边框,即去掉原来1px的位移。 【改动思路】 同上 --- .../designer/beans/events/DesignerEditor.java | 10 ++--- .../creator/XBorderStyleWidgetCreator.java | 31 +++++++++++--- .../design/designer/creator/XChartEditor.java | 8 ++-- .../designer/creator/XCreatorUtils.java | 2 +- .../designer/creator/XWTitleLayout.java | 42 ++++++++++++++----- .../fr/design/form/layout/FRTitleLayout.java | 12 ++++-- 6 files changed, 76 insertions(+), 29 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/events/DesignerEditor.java b/designer-form/src/main/java/com/fr/design/designer/beans/events/DesignerEditor.java index 58f58c075..e023e1f4d 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/events/DesignerEditor.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/events/DesignerEditor.java @@ -77,12 +77,12 @@ public class DesignerEditor 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; diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java b/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java index 0ff99f3a9..60434f2cb 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java +++ b/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); - } - return new Insets(padding.getTop(), padding.getLeft(), padding.getBottom(), padding.getRight()); + Container parent = this.getParent(); + if (parent instanceof XWTitleLayout && parent.getComponentCount() > 1) { + setPaddingInsets4Painting(null); + } else { + setPaddingInsets4Painting(toData().getMargin()); + } + return getPaddingInsets4Painting(); } /** diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java b/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java index 020dac063..1ab6d1a31 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java +++ b/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); diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java b/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java index 02ac912c3..408723152 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java +++ b/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!"); diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java index b2ef84edc..7655095b1 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java +++ b/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,12 +200,15 @@ 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); - titleBackground4Painting.paint(g2d, shape); + Shape shape = new Rectangle2D.Double(0, 0, getWidth(), height + paddingInsets.top); + titleBackground4Painting.paint(g2d, shape); - g2d.setComposite(oldComposite); + g2d.setComposite(oldComposite); + } } } @@ -201,14 +217,18 @@ public class XWTitleLayout extends DedicateLayoutContainer { 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); + XCreator bodyCreator = getBodyCreator(); + + if (bodyCreator != null) { + int y = bodyCreator.getY(); + int height = bodyCreator.getHeight(); + Insets paddingInsets = getInsets(); - g2d.setComposite(oldComposite); + Shape shape = new Rectangle2D.Double(0, y, getWidth(), height + paddingInsets.bottom); + bodyBackground4Painting.paint(g2d, shape); + + g2d.setComposite(oldComposite); + } } } diff --git a/designer-form/src/main/java/com/fr/design/form/layout/FRTitleLayout.java b/designer-form/src/main/java/com/fr/design/form/layout/FRTitleLayout.java index 3f0d2826f..2be67555a 100644 --- a/designer-form/src/main/java/com/fr/design/form/layout/FRTitleLayout.java +++ b/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); } } }