Browse Source

REPORT-55694 【组件背景分离】组件复用-组件/控件锁定时,通过右侧设置面板先增加宽度时,高度不变;但减小宽度时,高度会1单位1单位减小,最后组件变成一条横线

【问题原因】
1. 直接编辑宽度和高度,互相联动,存在小数舍入的问题,比如20.75,只取20,导致越来越小
2. 在锁定比例功能从未启动到启动时,需要保存尺寸比例,并持久化,否则再次打开模版后,原有的比例数据
就消失了
【改动思路】
1. WidgetBoundPane.java中widthSpinner和heightSpinner互相关联时,
使用Math.round取整,而不是直接取整数部分
2. 在启用比例锁定时,保存当前的aspectRatioBackup,除非关闭比例锁定,否则不更新改值
3. 高度或宽度为0时,取消比例锁定,避免出现除0问题
4. 绝对布局内组件移入移出时,重新计算锁定的尺寸比例
final/10.0
Starryi 3 years ago
parent
commit
4145aa26f3
  1. 7
      designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  2. 18
      designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java
  3. 13
      designer-form/src/main/java/com/fr/design/designer/ui/PopupControlPanel.java
  4. 7
      designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java
  5. 68
      designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java

7
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());

18
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);
}

13
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);
}
});

7
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();

68
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

Loading…
Cancel
Save