From 869aff12f345f6bb7d864c7b8ed13c46c0c7bc0d Mon Sep 17 00:00:00 2001 From: Starryi Date: Mon, 5 Jul 2021 23:17:51 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-53175=E3=80=9010.0.18=E3=80=91=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E8=83=8C=E6=99=AF=E5=88=86=E7=A6=BB=E4=B8=BA=E6=A0=87?= =?UTF-8?q?=E9=A2=98/=E8=83=8C=E6=99=AF/=E8=BE=B9=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 子功能: 设计器绝对布局内可锁定组件宽高比例 修复尺寸比例锁定按钮不能保存锁定状态的问题 1. 尺寸比例锁定按钮不应该保存XCreator对象(点击按钮时不能直接通过保存的XCreator, 改变widget锁定状态) 2. 尺寸比例锁定按钮需要实现GlobalNameObserver接口才能成功使得update被调用, 从而更新XCreator中widget的锁定状态 弹出提示显示逻辑 仅选中绝对布局内组件且该组件未勾选比例锁定按钮时,显示Shift键锁定组件尺寸比例功能 提示信息 --- .../beans/location/AccessDirection.java | 5 +- .../designer/beans/models/StateModel.java | 7 +- .../fr/design/mainframe/FormSelection.java | 10 +++ .../component/WidgetAbsoluteBoundPane.java | 3 +- .../designer/component/WidgetBoundPane.java | 74 ++++++++++++++----- 5 files changed, 76 insertions(+), 23 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java b/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java index be44eae81..adb0c6017 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java @@ -195,8 +195,11 @@ public abstract class AccessDirection implements Direction { if (type != formEditor.getCursor().getType()) { // 设置当前形状 formEditor.setCursor(Cursor.getPredefinedCursor(type)); + + FormSelection selection = formEditor.getSelectionModel().getSelection(); + boolean canLockAspectRatioOnlyByShift = !selection.isCreatorAspectRatioLockedInAbsLayout(formEditor) && selection.isCreatorInAbsLayout(formEditor); ServerPreferenceConfig config = ServerPreferenceConfig.getInstance(); - if (!config.isHasShownLockedAspectRatioResizingToolTip()) { + if (canLockAspectRatioOnlyByShift && !config.isHasShownLockedAspectRatioResizingToolTip()) { formEditor.setToolTipText(getTooltip()); config.setHasShownLockedAspectRatioResizingToolTip(true); } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/StateModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/StateModel.java index 34b03bc52..3b676921b 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/StateModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/StateModel.java @@ -15,6 +15,7 @@ import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XWAbsoluteBodyLayout; import com.fr.design.designer.creator.XWAbsoluteLayout; import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.FormSelection; import com.fr.design.mainframe.FormSelectionUtils; import com.fr.design.utils.ComponentUtils; @@ -486,12 +487,14 @@ public class StateModel { public void dragging(MouseEvent e) { //进入dragging状态时备份组件大小和位置 if (!dragging) { - this.aspectRatioLocked = this.selectionModel.getSelection().isCreatorAspectRatioLockedInAbsLayout(designer); selectedPositionBackup = selectionModel.getSelection().getRelativeBounds(); } checkAddable(e); setDependLinePainter(e); - this.aspectRatioLocked = this.aspectRatioLocked || e.isShiftDown(); + + FormSelection selection = this.selectionModel.getSelection(); + this.aspectRatioLocked = selection.isCreatorAspectRatioLockedInAbsLayout(designer) || + (this.selectionModel.getSelection().isCreatorInAbsLayout(designer) && e.isShiftDown()); driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer); this.dragging = true; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java b/designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java index 956e1cb66..54ab34a4f 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java @@ -300,6 +300,16 @@ public class FormSelection { return false; } + public boolean isCreatorInAbsLayout(FormDesigner designer) { + for (XCreator creator : selection) { + LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator); + if (layoutAdapter instanceof FRAbsoluteLayoutAdapter) { + return true; + } + } + return false; + } + /** * @Description 重置报表块缩略图 * @param: creator diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetAbsoluteBoundPane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetAbsoluteBoundPane.java index 30c90b326..e8aeb994d 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetAbsoluteBoundPane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetAbsoluteBoundPane.java @@ -29,11 +29,12 @@ public class WidgetAbsoluteBoundPane extends WidgetBoundPane { y = new UIBoundSpinner(0, Integer.MAX_VALUE, 1, 0d); width = new UIBoundSpinner(0, Integer.MAX_VALUE, 1, 0d); height = new UIBoundSpinner(0, Integer.MAX_VALUE, 1, 0d); - ratioLockedButton = new AspectRatioLockedButton(width, height, creator); + ratioLockedButton = new AspectRatioLockedButton(width, height); x.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size")); y.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size")); width.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size")); height.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size")); + ratioLockedButton.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size")); this.add(WidgetBoundsPaneFactory.createAbsoluteBoundsPane(x, y, width, height, ratioLockedButton, WidgetBoundsPaneFactory.NameAttribute.WIDGET)); } 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 5e1c8dee7..e963bf713 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 @@ -11,8 +11,11 @@ import com.fr.design.designer.creator.cardlayout.XWCardLayout; import com.fr.design.designer.creator.cardlayout.XWCardTagLayout; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.event.GlobalNameListener; +import com.fr.design.event.GlobalNameObserver; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.FormDesigner; @@ -81,7 +84,8 @@ public class WidgetBoundPane extends BasicPane { JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); if (jTemplate.isJWorkBook() || !((JForm)jTemplate).isSelectRootPane()) { - ratioLockedButton = new AspectRatioLockedButton(width, height, creator); + ratioLockedButton = new AspectRatioLockedButton(width, height); + ratioLockedButton.setGlobalName(i18nText("Fine-Design_Form_Coords_And_Size")); ratioLockedButton.setLockEnabled(false); } @@ -121,7 +125,7 @@ public class WidgetBoundPane extends BasicPane { limitHeight(wabs, h, bounds, rec); } if (ratioLockedButton != null) { - ratioLockedButton.setLocked(creator.toData().isAspectRatioLocked()); + ratioLockedButton.update(creator); } } @@ -191,21 +195,24 @@ public class WidgetBoundPane extends BasicPane { } - protected static class AspectRatioLockedButton extends UIButton { + protected static class AspectRatioLockedButton extends JButton implements UIObserver, GlobalNameObserver { private final Icon enabledLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_lock_enabled.png"); private final Icon disabledLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_lock_disabled.png"); private final Icon enabledUnLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_unlock_enabled.png"); private final Icon disabledUnLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_unlock_disabled.png"); - private UISpinner mWidthSpinner; - private UISpinner mHeightSpinner; - private XCreator mCreator; + private UIObserverListener uiObserverListener; + private GlobalNameListener globalNameListener; + private String globalName = null; + + private final UISpinner mWidthSpinner; + private final UISpinner mHeightSpinner; protected double width4Backup = 0; protected double height4Backup = 0; - public AspectRatioLockedButton(UISpinner widthSpinner, UISpinner heightSpinner, XCreator creator) { + public AspectRatioLockedButton(UISpinner widthSpinner, UISpinner heightSpinner) { setUI(new BasicButtonUI()); setBorderPainted(false); setBorder(null); @@ -214,25 +221,25 @@ public class WidgetBoundPane extends BasicPane { this.mWidthSpinner = widthSpinner; this.mHeightSpinner = heightSpinner; - this.mCreator = creator; addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - setSelected(!isSelected()); - } - }); - addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - mCreator.toData().setAspectRatioLocked(isLocked()); - - setToolTipText(isLockEnabled() ? null : i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Button_ToolTip")); + // 改变图标icon + setLocked(!isLocked()); if (isLocked() && isLockEnabled()) { width4Backup = mWidthSpinner.getValue(); height4Backup = mHeightSpinner.getValue(); } + + if (globalNameListener != null) { + globalNameListener.setGlobalName(globalName); + } + + if (uiObserverListener != null) { + uiObserverListener.doChange(); + } } }); @@ -285,15 +292,44 @@ public class WidgetBoundPane extends BasicPane { public void setLockEnabled(boolean enabled) { this.setEnabled(enabled); + setToolTipText(isLockEnabled() ? null : i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Button_ToolTip")); } public void populate(XCreator creator) { Rectangle bounds = new Rectangle(creator.getBounds()); - mCreator = creator; width4Backup = bounds.width; height4Backup = bounds.height; Widget widget = creator.toData(); setLocked(widget.isAspectRatioLocked()); } + + public void update(XCreator creator) { + creator.toData().setAspectRatioLocked(this.isLocked()); + } + + @Override + public void registerChangeListener(UIObserverListener listener) { + uiObserverListener = listener; + } + + @Override + public boolean shouldResponseChangeListener() { + return true; + } + + @Override + public void registerNameListener(GlobalNameListener listener) { + this.globalNameListener = listener; + } + + @Override + public boolean shouldResponseNameListener() { + return true; + } + + @Override + public void setGlobalName(String name) { + this.globalName = name; + } } }