From 4145aa26f3b1c367cfb12e426747a9b409cf7269 Mon Sep 17 00:00:00 2001 From: Starryi Date: Thu, 22 Jul 2021 20:03:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-55694=20=E3=80=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=88=86=E7=A6=BB=E3=80=91=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=A4=8D=E7=94=A8-=E7=BB=84=E4=BB=B6/=E6=8E=A7=E4=BB=B6?= =?UTF-8?q?=E9=94=81=E5=AE=9A=E6=97=B6=EF=BC=8C=E9=80=9A=E8=BF=87=E5=8F=B3?= =?UTF-8?q?=E4=BE=A7=E8=AE=BE=E7=BD=AE=E9=9D=A2=E6=9D=BF=E5=85=88=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AE=BD=E5=BA=A6=E6=97=B6=EF=BC=8C=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E4=B8=8D=E5=8F=98=EF=BC=9B=E4=BD=86=E5=87=8F=E5=B0=8F=E5=AE=BD?= =?UTF-8?q?=E5=BA=A6=E6=97=B6=EF=BC=8C=E9=AB=98=E5=BA=A6=E4=BC=9A1?= =?UTF-8?q?=E5=8D=95=E4=BD=8D1=E5=8D=95=E4=BD=8D=E5=87=8F=E5=B0=8F?= =?UTF-8?q?=EF=BC=8C=E6=9C=80=E5=90=8E=E7=BB=84=E4=BB=B6=E5=8F=98=E6=88=90?= =?UTF-8?q?=E4=B8=80=E6=9D=A1=E6=A8=AA=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 1. 直接编辑宽度和高度,互相联动,存在小数舍入的问题,比如20.75,只取20,导致越来越小 2. 在锁定比例功能从未启动到启动时,需要保存尺寸比例,并持久化,否则再次打开模版后,原有的比例数据 就消失了 【改动思路】 1. WidgetBoundPane.java中widthSpinner和heightSpinner互相关联时, 使用Math.round取整,而不是直接取整数部分 2. 在启用比例锁定时,保存当前的aspectRatioBackup,除非关闭比例锁定,否则不更新改值 3. 高度或宽度为0时,取消比例锁定,避免出现除0问题 4. 绝对布局内组件移入移出时,重新计算锁定的尺寸比例 --- .../layout/FRAbsoluteLayoutAdapter.java | 7 ++ .../designer/creator/XWAbsoluteLayout.java | 18 ++++- .../design/designer/ui/PopupControlPanel.java | 13 +++- .../mainframe/FormCreatorDropTarget.java | 7 +- .../designer/component/WidgetBoundPane.java | 68 ++++++++++++------- 5 files changed, 87 insertions(+), 26 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java index 4b3147c0a..e4426f61a 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java @@ -9,6 +9,7 @@ import com.fr.design.designer.properties.BoundsGroupModel; import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel; import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.gui.LayoutUtils; +import com.fr.form.ui.Widget; import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; @@ -295,6 +296,12 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { */ @Override public void fix(XCreator creator) { + Widget widget = creator.toData(); + Rectangle bounds = creator.getBounds(); + if (widget != null && widget.isAspectRatioLocked() && (bounds.width == 0 || bounds.height == 0)) { + widget.setAspectRatioLocked(false); + widget.setAspectRatioBackup(-1.0); + } WAbsoluteLayout wabs = (WAbsoluteLayout)container.toData(); fix(creator,creator.getX(),creator.getY()); wabs.setBounds(creator.toData(),creator.getBounds()); diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java index fdd62d1b0..44d1588df 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java @@ -386,7 +386,18 @@ public class XWAbsoluteLayout extends XLayoutContainer { if (!creator.acceptType(XWFitLayout.class)) { creator.setDirections(Direction.ALL); } - wabs.addWidget(new BoundsWidget(creator.toData(), creator.getBounds())); + Widget wgt = creator.toData(); + if (wgt != null && wgt.isAspectRatioLocked() && wgt.getAspectRatioBackup() <= 0) { + // 将比例锁定的组件重新移会绝对布局内时(如body修改绝对布局),尺寸比例可能失效,需要重新计算 + Rectangle bounds = creator.getBounds(); + if (bounds.width > 0 && bounds.height > 0) { + wgt.setAspectRatioBackup(1.0 * bounds.width / bounds.height); + } else { + wgt.setAspectRatioLocked(false); + wgt.setAspectRatioBackup(-1); + } + } + wabs.addWidget(new BoundsWidget(wgt, creator.getBounds())); } /** @@ -402,6 +413,11 @@ public class XWAbsoluteLayout extends XLayoutContainer { WAbsoluteLayout wlayout = this.toData(); XWidgetCreator xwc = ((XWidgetCreator) e.getChild()); Widget wgt = xwc.toData(); + + // 将比例锁定的组件重新移出绝对布局时(如body修改为自适应布局),锁定的尺寸比例失效 + if (wgt != null) { + wgt.setAspectRatioBackup(-1.0); + } BoundsWidget bw = new BoundsWidget(wgt, xwc.getBounds()); wlayout.removeWidget(bw); } diff --git a/designer-form/src/main/java/com/fr/design/designer/ui/PopupControlPanel.java b/designer-form/src/main/java/com/fr/design/designer/ui/PopupControlPanel.java index ad003ff69..f806a72c0 100644 --- a/designer-form/src/main/java/com/fr/design/designer/ui/PopupControlPanel.java +++ b/designer-form/src/main/java/com/fr/design/designer/ui/PopupControlPanel.java @@ -13,6 +13,7 @@ import com.fr.design.layout.VerticalFlowLayout; import com.fr.design.mainframe.CoverReportPane; import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.FormDesigner; +import com.fr.form.ui.Widget; import com.fr.general.IOUtils; import com.fr.stable.ArrayUtils; @@ -94,7 +95,17 @@ public class PopupControlPanel extends JPanel { JToggleButton toggleBtn = (JToggleButton) e.getSource(); String toolTipText = toggleBtn.isSelected() ? Toolkit.i18nText("Fine-Design_Form_Lock_Widget_Ratio") : Toolkit.i18nText("Fine-Design_Form_UnLock_Widget_Ratio"); toggleBtn.setToolTipText(toolTipText); - creator.toData().setAspectRatioLocked(toggleBtn.isSelected()); + Widget widget = creator.toData(); + if (widget != null) { + Rectangle bounds = new Rectangle(creator.getBounds()); + if (toggleBtn.isSelected() && bounds.width > 0 && bounds.height > 0) { + widget.setAspectRatioLocked(true); + widget.setAspectRatioBackup(1.0 * bounds.width / bounds.height); + } else { + widget.setAspectRatioLocked(false); + widget.setAspectRatioBackup(-1.0); + } + } designer.getEditListenerTable().fireCreatorModified(creator, DesignerEvent.CREATOR_RESIZED); } }); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java b/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java index 11fa1dc3b..d1aa9fc56 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java @@ -112,7 +112,12 @@ public class FormCreatorDropTarget extends DropTarget { if (addingXCreator.isShared()) { if (container.acceptType(XWAbsoluteLayout.class)) { // 绝对布局中新添加的共享组件默认锁定尺寸比例 - addingXCreator.toData().setAspectRatioLocked(true); + Rectangle bounds = new Rectangle(addingXCreator.getBounds()); + Widget addingWidget = addingXCreator.toData(); + if (addingWidget != null && bounds.width > 0 && bounds.height > 0) { + addingXCreator.toData().setAspectRatioLocked(true); + addingXCreator.toData().setAspectRatioBackup(1.0 * bounds.width / bounds.height); + } } String shareId = addingXCreator.getShareId(); diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java index d046a6a9e..2fdec31e1 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java @@ -103,14 +103,11 @@ public class WidgetBoundPane extends BasicPane { } public void populate() { - Rectangle bounds = new Rectangle(creator.getBounds()); - if (ratioLockedButton != null) { - // 临时禁止尺寸比例锁定,关掉widthSpinner/heightSpinner之间的数值关联,以更新其高度和宽度值 - ratioLockedButton.setLocked(false); - } - width.setValue(bounds.width); - height.setValue(bounds.height); - if (ratioLockedButton != null) { + if (ratioLockedButton == null) { + Rectangle bounds = new Rectangle(creator.getBounds()); + width.setValue(bounds.width); + height.setValue(bounds.height); + } else { ratioLockedButton.populate(creator); } } @@ -213,8 +210,7 @@ public class WidgetBoundPane extends BasicPane { private final UISpinner mWidthSpinner; private final UISpinner mHeightSpinner; - protected double width4Backup = 0; - protected double height4Backup = 0; + protected double aspectRatioBackup = 0; public AspectRatioLockedButton(UISpinner widthSpinner, UISpinner heightSpinner) { setUI(new BasicButtonUI()); @@ -229,12 +225,16 @@ public class WidgetBoundPane extends BasicPane { addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - // 改变图标icon - setLocked(!isLocked()); - - if (isLocked() && isLockEnabled()) { - width4Backup = mWidthSpinner.getValue(); - height4Backup = mHeightSpinner.getValue(); + double width = mWidthSpinner.getValue(); + double height = mHeightSpinner.getValue(); + boolean nextLocked = !isLocked(); + + if (nextLocked && width > 0 && height > 0) { + setLocked(true); + aspectRatioBackup = width / height; + } else { + setLocked(false); + aspectRatioBackup = -1; } if (globalNameListener != null) { @@ -250,16 +250,26 @@ public class WidgetBoundPane extends BasicPane { mWidthSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { - if (isLockEnabled() && isLocked() && width4Backup > 0 && height4Backup > 0) { - mHeightSpinner.setValue(mWidthSpinner.getValue() * height4Backup / width4Backup, false); + if (isLockEnabled() && isLocked()) { + if (mWidthSpinner.getValue() == 0) { + setLocked(false); + aspectRatioBackup = -1; + } else if (aspectRatioBackup > 0) { + double value = mWidthSpinner.getValue() / aspectRatioBackup; + mHeightSpinner.setValue(Math.round(value), false); + } } } }); mHeightSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { - if (isLockEnabled() && isLocked() && width4Backup > 0 && height4Backup > 0) { - mWidthSpinner.setValue(mHeightSpinner.getValue() * width4Backup / height4Backup, false); + if (isLockEnabled() && isLocked()) { + setLocked(false); + aspectRatioBackup = -1; + } else if (aspectRatioBackup > 0) { + double value = mHeightSpinner.getValue() * aspectRatioBackup; + mWidthSpinner.setValue(Math.round(value), false); } } }); @@ -301,14 +311,26 @@ public class WidgetBoundPane extends BasicPane { public void populate(XCreator creator) { Rectangle bounds = new Rectangle(creator.getBounds()); - width4Backup = bounds.width; - height4Backup = bounds.height; Widget widget = creator.toData(); + + aspectRatioBackup = widget.getAspectRatioBackup(); setLocked(widget.isAspectRatioLocked()); + + mWidthSpinner.setValue(bounds.width, false); + mHeightSpinner.setValue(bounds.height, false); } public void update(XCreator creator) { - creator.toData().setAspectRatioLocked(this.isLocked()); + Widget widget = creator.toData(); + if (widget != null) { + if (this.isLocked()) { + widget.setAspectRatioLocked(true); + widget.setAspectRatioBackup(this.aspectRatioBackup); + } else { + widget.setAspectRatioLocked(false); + widget.setAspectRatioBackup(-1.0); + } + } } @Override From ada963198322026d313a8ba21bfef5576b7ffd7d Mon Sep 17 00:00:00 2001 From: Starryi Date: Fri, 23 Jul 2021 01:50:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-55491=20=E3=80=90=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E9=AA=8C=E6=94=B6=E3=80=91=E3=80=90=E7=BB=84=E4=BB=B6=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E5=88=86=E7=A6=BB=E3=80=91=E5=9C=A8=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E4=B8=8B=E7=9A=84=E3=80=8C=E4=B8=BB=E4=BD=93?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E3=80=8D=E8=AE=BE=E7=BD=AE=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=95=8C=E9=9D=A2=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=EF=BC=8C=E7=9C=8B=E4=B8=8D=E5=88=B0=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 1. 绘制图表块时,填充了白色背景,导致组件样式背景被覆盖 2. 图表进入编辑模式下,ChartComponent被绘制两次,差 了一个像素,又因为ChartComponent支持半透明,导致出现了 重影 【改动思路】 1. 表单布局面板上预览报表块时,不使用白色背景填充,保持透明 2. DesignerEditor绘制Editor时,补充下差了的一个 像素(默认灰色边框) --- .../java/com/fr/design/chart/gui/ChartComponent.java | 12 +++++++----- .../design/designer/beans/events/DesignerEditor.java | 2 +- .../com/fr/design/designer/creator/XChartEditor.java | 3 +++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/designer-chart/src/main/java/com/fr/design/chart/gui/ChartComponent.java b/designer-chart/src/main/java/com/fr/design/chart/gui/ChartComponent.java index 1a5088a27..1ce2fbffd 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/gui/ChartComponent.java +++ b/designer-chart/src/main/java/com/fr/design/chart/gui/ChartComponent.java @@ -43,6 +43,7 @@ public class ChartComponent extends MiddleChartComponent implements MouseListene public ChartComponent() { super(); + setOpaque(true); addMouseListener(this); addMouseMotionListener(this); } @@ -148,11 +149,12 @@ public class ChartComponent extends MiddleChartComponent implements MouseListene chartCollection4Design.setPredefinedStyleName(getGlobalPredefinedStyleName(), false); Graphics2D g2d = (Graphics2D) g; - Paint oldPaint = g2d.getPaint(); - - g2d.setPaint(Color.WHITE); - g2d.fillRect(0, 0, this.getBounds().width, this.getBounds().height); - g2d.setPaint(oldPaint); + if (this.isOpaque()) { + Paint oldPaint = g2d.getPaint(); + g2d.setPaint(Color.WHITE); + g2d.fillRect(0, 0, this.getBounds().width, this.getBounds().height); + g2d.setPaint(oldPaint); + } g2d.translate(ChartConstants.PREGAP4BOUNDS/2, ChartConstants.PREGAP4BOUNDS/2); 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 f53f66d31..58f58c075 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 @@ -93,7 +93,7 @@ public class DesignerEditor implements PropertyChangeListe comp.setSize(new Dimension(width, height)); LayoutUtils.layoutContainer(comp); - comp.setBounds(comp.getX() + x, comp.getY() + y, width, height); + comp.setBounds(comp.getX() + x - 1, comp.getY() + y - 1, width, height); Graphics clipg = g.create(x, y, width, height); this.comp.paint(clipg); } 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 8633c0bd5..ad328b85e 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 @@ -231,7 +231,9 @@ public class XChartEditor extends XBorderStyleWidgetCreator { public void paintForeground(Graphics2D g) { Dimension size = getSize(); PaddingMargin margin = toData().getMargin(); + designerEditor.paintEditor(g, size, margin); + if (coverPanel != null) { int horizonMargin = margin != null ? margin.getLeft() + margin.getRight() : 0; int verticalMargin = margin != null ? margin.getTop() + margin.getBottom() : 0; @@ -289,6 +291,7 @@ public class XChartEditor extends XBorderStyleWidgetCreator { final MiddleChartComponent chartComponent = DesignModuleFactory.getChartComponent(((BaseChartEditor) data).getChartCollection()); if (chartComponent != null) { JComponent jChart = chartComponent; + chartComponent.setOpaque(false); jChart.setBorder(BorderFactory.createLineBorder(Color.lightGray)); designerEditor = new DesignerEditor(jChart); chartComponent.addStopEditingListener(designerEditor);