Browse Source

Pull request #7104: KERNEL-9636 设计器渲染表单去除分辨率的差异

Merge in DESIGN/design from ~KERRY/design_10.0:feature/x to feature/x

* commit 'e972e7ef1cc5323bf4127d966262c5733d20dac6':
  去除新老转换时,调整表单组件尺寸的逻辑
  代码修改
  代码修改
  KERNEL-9636  设计器渲染表单去除分辨率的差异
feature/x
kerry 3 years ago
parent
commit
854ff33129
  1. 109
      designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java
  2. 100
      designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java
  3. 4
      designer-form/src/main/java/com/fr/design/designer/properties/FRFitLayoutConstraints.java
  4. 63
      designer-form/src/main/java/com/fr/design/fit/NewJForm.java
  5. 5
      designer-form/src/main/java/com/fr/design/fit/common/AdaptiveSwitchUtil.java
  6. 15
      designer-form/src/main/java/com/fr/design/fit/common/LayoutTool.java
  7. 62
      designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java
  8. 137
      designer-form/src/main/java/com/fr/design/mainframe/FormArea.java
  9. 9
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java
  10. 3
      designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java
  11. 3
      designer-form/src/main/java/com/fr/design/mainframe/FormSelectionUtils.java
  12. 3
      designer-form/src/main/java/com/fr/design/mainframe/share/select/ComponentTransformerImpl.java
  13. 4
      designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java

109
designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java

@ -4,15 +4,11 @@
package com.fr.design.designer.creator;
import com.fr.base.GraphHelper;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.FRAbsoluteLayoutAdapter;
import com.fr.design.designer.beans.location.Direction;
import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.designer.properties.mobile.MobileBooKMarkUsePropertyUI;
import com.fr.design.fit.DesignerUIModeConfig;
import com.fr.design.form.layout.FRAbsoluteLayout;
import com.fr.design.form.util.FormDesignerUtils;
import com.fr.design.fun.WidgetPropertyUIProvider;
@ -26,6 +22,7 @@ import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import com.fr.form.ui.container.WLayout;
import com.fr.general.FRScreen;
import com.fr.stable.AssistUtils;
import com.fr.stable.Constants;
@ -34,7 +31,6 @@ import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ContainerEvent;
import java.awt.event.MouseEvent;
import java.beans.IntrospectionException;
@ -51,9 +47,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
private int minHeight = WLayout.MIN_HEIGHT;
private static final Color OUTER_BORDER_COLOR = new Color(65, 155, 249, 30);
private static final Color INNER_BORDER_COLOR = new Color(65, 155, 249);
//由于屏幕分辨率不同,界面上的容器大小可能不是默认的100%,此时拖入组件时,保存的大小按照100%时的计算
protected double containerPercent = 1.0;
private static final double DEFAULT_CONTAINER_PERCENT = 1.0D;
private HashMap<Connector, XConnector> xConnectorMap;
@ -73,8 +67,6 @@ public class XWAbsoluteLayout extends XLayoutContainer {
connector = widget.getConnectorIndex(i);
xConnectorMap.put(connector, new XConnector(connector, this));
}
initPercent(widget);
}
/**
@ -87,36 +79,6 @@ public class XWAbsoluteLayout extends XLayoutContainer {
return new Dimension(500, 300);
}
//根据屏幕大小来确定显示的百分比, 1440*900默认100%, 1366*768缩放90%
private void initPercent(WAbsoluteLayout widget) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension scrnsize = toolkit.getScreenSize();
double screenValue = DesignerUIModeConfig.getInstance().getDesignScreenByDimension(scrnsize).getValue();
if (!AssistUtils.equals(screenValue, FormArea.DEFAULT_SLIDER)) {
this.setContainerPercent(screenValue / FormArea.DEFAULT_SLIDER);
}
}
/**
* 返回容器大小的百分比
*
* @return the containerPercent
*/
public double getContainerPercent() {
return containerPercent;
}
/**
* 设置容器大小的百分比
*
* @param containerPercent the containerPercent to set
*/
public void setContainerPercent(double containerPercent) {
this.containerPercent = containerPercent;
minWidth = (int) (XWAbsoluteLayout.MIN_WIDTH * containerPercent);
minHeight = (int) (XWAbsoluteLayout.MIN_HEIGHT * containerPercent);
}
/**
* 返回界面处根据百分比调整后的最小宽度
*
@ -142,30 +104,14 @@ public class XWAbsoluteLayout extends XLayoutContainer {
*/
public int getAcualInterval() {
// adapter那边交叉三等分、删除都要判断是否对齐,所以间隔转为偶数
int interval = (int) (toData().getCompInterval() * containerPercent);
int interval = (int) (toData().getCompInterval() );
int val = interval / 2;
return val * 2;
}
/**
* 界面容器大小不是默认的时处理控件的BoundsWidget且避免出现空隙
*/
private Rectangle dealWidgetBound(Rectangle rec) {
if (AssistUtils.equals(1.0, containerPercent)) {
return rec;
}
rec.x = (int) (rec.x / containerPercent);
rec.y = (int) (rec.y / containerPercent);
rec.width = (int) (rec.width / containerPercent);
rec.height = (int) (rec.height / containerPercent);
return rec;
}
/**
* 新增删除拉伸后单个组件的BoundsWidget
*/
public void updateBoundsWidget(XCreator xCreator) {
WAbsoluteLayout layout = this.toData();
if (xCreator.hasTitleStyle()) {
xCreator = (XLayoutContainer) xCreator.getParent();
}
@ -223,32 +169,33 @@ public class XWAbsoluteLayout extends XLayoutContainer {
}
}
/**
* 更新子组件的Bound
* 这边主要用于绝对布局子组件在适应区域选项时
* 涉及到的不同分辨率下缩放
*
* @param minHeight 最小高度
*/
@Override
public void updateChildBound(int minHeight) {
double prevContainerPercent = DesignerUIModeConfig.getInstance().getDesignScreenByDimension(toData().getDesigningResolution()).getValue() / FormArea.DEFAULT_SLIDER;
if (toData().getCompState() == 0 && !AssistUtils.equals(containerPercent, prevContainerPercent)) {
for (int i = 0; i < this.getComponentCount(); i++) {
XCreator creator = getXCreator(i);
Rectangle rec = new Rectangle(creator.getBounds());
rec.x = (int)Math.round (rec.x / prevContainerPercent * containerPercent);
rec.y = (int)Math.round (rec.y / prevContainerPercent * containerPercent);
rec.height = (int)Math.round (rec.height / prevContainerPercent * containerPercent);
rec.width = (int)Math.round (rec.width / prevContainerPercent * containerPercent);
BoundsWidget wgt = (BoundsWidget) toData().getBoundsWidget(creator.toData());
wgt.setBounds(rec);
creator.setBounds(rec);
creator.updateChildBound(minHeight);
/**
* 更新子组件的Bound
* 这边主要用于绝对布局子组件在适应区域选项时
* 涉及到的不同分辨率下缩放
* 兼容方法老的模板中绝对布局带有分辨率参数的兼容处理
*
* @param minHeight 最小高度
*/
@Override
public void updateChildBound(int minHeight) {
double prevContainerPercent = FRScreen.getFRScreenByDimension(toData().getDesigningResolution()).getValue() / FormArea.DEFAULT_SLIDER;
if (!AssistUtils.equals(DEFAULT_CONTAINER_PERCENT, prevContainerPercent)) {
for (int i = 0; i < this.getComponentCount(); i++) {
XCreator creator = getXCreator(i);
Rectangle rec = new Rectangle(creator.getBounds());
rec.x = (int) Math.round(rec.x / prevContainerPercent);
rec.y = (int) Math.round(rec.y / prevContainerPercent);
rec.height = (int) Math.round(rec.height / prevContainerPercent);
rec.width = (int) Math.round(rec.width / prevContainerPercent);
BoundsWidget wgt = (BoundsWidget) toData().getBoundsWidget(creator.toData());
wgt.setBounds(rec);
creator.setBounds(rec);
creator.updateChildBound(minHeight);
}
}
toData().setDesigningResolution(FRScreen.p1440.getDimension());
}
toData().setDesigningResolution(Toolkit.getDefaultToolkit().getScreenSize());
}
/**
* 增加对齐线

100
designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java

@ -3,15 +3,12 @@ package com.fr.design.designer.creator;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.FRFitLayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.FRFixLayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.FRNoFixLayoutAdapter;
import com.fr.design.designer.beans.location.Direction;
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.designer.properties.mobile.BodyMobilePropertyUI;
import com.fr.design.fit.DesignerUIModeConfig;
import com.fr.design.form.layout.FRFitLayout;
import com.fr.design.fun.WidgetPropertyUIProvider;
import com.fr.design.mainframe.FormArea;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.design.utils.gui.LayoutUtils;
@ -24,12 +21,10 @@ import com.fr.form.ui.container.WLayout;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.stable.ArrayUtils;
import com.fr.stable.AssistUtils;
import javax.swing.JOptionPane;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ContainerEvent;
import java.util.ArrayList;
import java.util.Arrays;
@ -46,9 +41,6 @@ public class XWFitLayout extends XLayoutContainer {
private static final long serialVersionUID = 8112908607102660176L;
private static final int EACH_ROW_COUNT = 4;
//由于屏幕分辨率不同,界面上的容器大小可能不是默认的100%,此时拖入组件时,保存的大小按照100%时的计算
protected double containerPercent = 1.0;
// 布局缩小的时候,考虑最小宽高,若挨着右侧或底侧边框的控件缩小后达到最小宽或高,此时容器大小微调下
private int needAddWidth = 0;
private int needAddHeight = 0;
@ -64,20 +56,6 @@ public class XWFitLayout extends XLayoutContainer {
public XWFitLayout(WFitLayout widget, Dimension initSize) {
super(widget, initSize);
initPercent();
widget.setResolutionScaling(containerPercent);
}
//根据屏幕大小来确定显示的百分比, 1440*900默认100%, 1366*768缩放90%
private void initPercent(){
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension scrnsize = toolkit.getScreenSize();
double screenValue = DesignerUIModeConfig.getInstance().getDesignScreenByDimension(scrnsize).getValue();
if (!AssistUtils.equals(FormArea.DEFAULT_SLIDER, screenValue)) {
this.setContainerPercent(screenValue / FormArea.DEFAULT_SLIDER);
}
}
@Override
@ -252,19 +230,16 @@ public class XWFitLayout extends XLayoutContainer {
* @return int[] 横坐标数组
*/
public int[] getHors(boolean isActualSize) {
double perc = isActualSize ? containerPercent : 1.0;
List<Integer> posX = new ArrayList<Integer>();
// 保存实际大小时,组件大小已经去除内边距,此处也判断下
PaddingMargin margin = isActualSize ? new PaddingMargin(0,0,0,0) : toData().getMargin();
PaddingMargin margin = isActualSize ? new PaddingMargin(0, 0, 0, 0) : toData().getMargin();
posX.add(margin.getLeft());
int width = this.getWidth() - margin.getLeft() - margin.getRight();
int containW = (int) (width / perc);
posX.add(containW + margin.getLeft());
for (int i=0, len=this.getComponentCount(); i < len; i++) {
posX.add(width + margin.getLeft());
for (int i = 0, len = this.getComponentCount(); i < len; i++) {
int x = this.getComponent(i).getX();
int finalX = (int) (x / perc);
if (!posX.contains(finalX)) {
posX.add(finalX);
if (!posX.contains(x)) {
posX.add(x);
}
}
Collections.sort(posX);
@ -278,19 +253,16 @@ public class XWFitLayout extends XLayoutContainer {
*
*/
public int[] getVeris(boolean isActualSize) {
double perc = isActualSize ? containerPercent : 1.0;
List<Integer> posY = new ArrayList<Integer>();
// 保存实际大小时,组件大小已经去除内边距,此处也判断下
PaddingMargin margin = isActualSize ? new PaddingMargin(0,0,0,0) : toData().getMargin();
posY.add(margin.getTop());
int height = this.getHeight() - margin.getTop() - margin.getBottom();
int containH = (int) (height / perc);
posY.add(containH + margin.getTop());
posY.add(height + margin.getTop());
for (int i=0, len=this.getComponentCount(); i < len; i++) {
int y = this.getComponent(i).getY();
int finalY = (int) (y / perc);
if (!posY.contains(finalY)) {
posY.add(finalY);
if (!posY.contains(y)) {
posY.add(y);
}
}
Collections.sort(posY);
@ -721,34 +693,6 @@ public class XWFitLayout extends XLayoutContainer {
creator.setBackupParent(this);
}
/**
* 界面容器大小不是默认的时处理控件的BoundsWidget且避免出现空隙
*/
private Rectangle dealWidgetBound(Rectangle rec) {
if (AssistUtils.equals(1.0, containerPercent)) {
return rec;
}
rec.x = (int) (rec.x/containerPercent);
rec.y = (int) (rec.y/containerPercent);
rec.width = (int) (rec.width/containerPercent);
rec.height = (int) (rec.height/containerPercent);
return rec;
}
/**
* 界面容器大小不是默认的时恢复组件实际大小
*/
private Rectangle dealWgtBound(Rectangle rec) {
if (AssistUtils.equals(1.0, containerPercent)) {
return rec;
}
rec.x = (int) (rec.x * containerPercent);
rec.y = (int) (rec.y * containerPercent);
rec.width = (int) (rec.width * containerPercent);
rec.height = (int) (rec.height * containerPercent);
return rec;
}
/**
* 新增删除拉伸后更新每个组件的BoundsWidget
*/
@ -774,7 +718,7 @@ public class XWFitLayout extends XLayoutContainer {
XCreator creator = (XCreator) this.getComponent(index);
BoundsWidget wgt = (BoundsWidget) layout.getBoundsWidget(creator.toData());
// 用当前的显示大小计算后调正具体位置
Rectangle wgtBound = dealWidgetBound(creator.getBounds());
Rectangle wgtBound = creator.getBounds();
Rectangle rec = recalculateWidgetBounds(wgtBound, hors, veris);
wgt.setBounds(rec);
creator.toData().updateChildBounds(rec);
@ -814,7 +758,7 @@ public class XWFitLayout extends XLayoutContainer {
//更新的时候一定要带上backupBound
if (creator.getBackupBound() == null && wgt.getBeforeScaleBounds() != null) {
creator.setBackupBound(dealWgtBound(wgt.getBeforeScaleBounds()));
creator.setBackupBound(wgt.getBeforeScaleBounds());
}
((XWAbsoluteLayout) creator).updateBoundsWidget();
creator.setBackupBound(creator.getBounds());
@ -1170,24 +1114,6 @@ public class XWFitLayout extends XLayoutContainer {
return this.getComponentAt(x+w-default_Length, y+h+default_Length+val);
}
/**
* 返回容器大小的百分比
* @return the containerPercent
*/
public double getContainerPercent() {
return containerPercent;
}
/**
* 设置容器大小的百分比
* @param containerPercent the containerPercent to set
*/
public void setContainerPercent(double containerPercent) {
this.containerPercent = containerPercent;
minWidth = (int) (XWFitLayout.MIN_WIDTH*containerPercent);
minHeight = (int) (XWFitLayout.MIN_HEIGHT*containerPercent);
}
/**
* 该组件是否可以拖拽(表单中参数面板和自适应布局不可以拖拽)
* @return 是则返回true
@ -1218,9 +1144,9 @@ public class XWFitLayout extends XLayoutContainer {
*/
public int getAcualInterval() {
// adapter那边交叉三等分、删除都要判断是否对齐,所以间隔转为偶数
int interval = (int) (toData().getCompInterval()*containerPercent);
int val = interval/2;
return val*2;
int interval = toData().getCompInterval();
int val = interval / 2;
return val * 2;
}
/**

4
designer-form/src/main/java/com/fr/design/designer/properties/FRFitLayoutConstraints.java

@ -92,8 +92,8 @@ public class FRFitLayoutConstraints implements ConstraintsGroupModel {
Rectangle bounds = getBounds();
Rectangle rec = ComponentUtils.getRelativeBounds(parent);
WFitLayout wFitLayout = parent.toData();
int minHeight = (int)(MINHEIGHT * wFitLayout.getResolutionScaling());
int minWidth = (int)(MINWIDTH * wFitLayout.getResolutionScaling());
int minHeight = MINHEIGHT;
int minWidth = MINWIDTH;
PaddingMargin margin= wFitLayout.getMargin();
switch (row) {
case 0:

63
designer-form/src/main/java/com/fr/design/fit/NewJForm.java

@ -8,12 +8,12 @@ import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.FRFitLayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEditListener;
import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.*;
import com.fr.design.fit.common.AdaptiveSwitchUtil;
import com.fr.design.fit.common.LayoutTool;
import com.fr.form.fit.NewFormMarkAttr;
import com.fr.design.fit.common.TemplateTool;
import com.fr.design.actions.NewFormMobileAttrAction;
import com.fr.design.designer.creator.XComponent;
import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XElementCase;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWTitleLayout;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.preview.DeveloperPreview;
import com.fr.design.preview.FormAdaptivePreview;
@ -29,7 +29,6 @@ import com.fr.design.utils.ComponentUtils;
import com.fr.file.FILE;
import com.fr.form.FormElementCaseProvider;
import com.fr.form.main.Form;
import com.fr.form.main.mobile.FormMobileAttr;
import com.fr.form.ui.ElementCaseEditor;
import com.fr.stable.ArrayUtils;
@ -49,13 +48,11 @@ public class NewJForm extends JForm {
public NewJForm() {
super();
init();
changePaneSize();
}
public NewJForm(Form form) {
super(form);
init();
changePaneSize();
}
public NewJForm(Form form, FILE file, Parameter[] parameters) {
@ -67,48 +64,6 @@ public class NewJForm extends JForm {
if (DesignerUIModeConfig.getInstance().newUIMode()) {
init();
}
changePaneSize();
}
/**
* @Description:改变body的大小主要针对新模式下打开老模板出现截断的情况
* @param
* @return:
* @Author: Henry.Wang
* @date: 2020/9/13 23:23
*/
private void changePaneSize() {
NewFormMarkAttr newFormMarkAttr = this.getTarget().getAttrMark(NewFormMarkAttr.XML_TAG);
if (newFormMarkAttr.isNotSetOriginSize()) {
newFormMarkAttr.setBodyHeight(LayoutTool.getBodyHeight(this));
newFormMarkAttr.setBodyWidth(LayoutTool.getBodyWidth(this));
return;
}
//这种是针对body为绝对布局时,可能出现截断的情况
if (LayoutTool.absoluteLayoutForm(this)) {
int bodyHeight = newFormMarkAttr.getBodyHeight();
int bodyWidth = newFormMarkAttr.getBodyWidth();
Rectangle rectangle = LayoutTool.getAbsoluteBodySize(this);
if (!isNewJFrom() && (rectangle.width != bodyWidth || rectangle.height != bodyHeight)) {
TemplateTool.onlyChangeAbsoluteBodySize(bodyHeight, bodyWidth, this);
} else if (isNewJFrom()) {
if (rectangle.width > bodyWidth && rectangle.height > bodyHeight) {
TemplateTool.onlyChangeAbsoluteBodySize(rectangle.height, rectangle.width, this);
} else if (rectangle.width > bodyWidth) {
TemplateTool.onlyChangeAbsoluteBodySize(bodyHeight, rectangle.width, this);
} else if (rectangle.height > bodyHeight) {
TemplateTool.onlyChangeAbsoluteBodySize(rectangle.height, bodyWidth, this);
}
}
} else if (AdaptiveSwitchUtil.isSwitchJFromIng()) {
//这种是针对body中有绝对画布块,导致截断的情况
double scale = LayoutTool.getContainerPercent();
if (isNewJFrom()) {
LayoutTool.scaleAbsoluteBlockComponentsBounds(this.getFormDesign().getRootComponent(), 1 / scale);
} else {
LayoutTool.scaleAbsoluteBlockComponentsBounds(this.getFormDesign().getRootComponent(), scale);
}
}
}
public JFormType getJFormType() {
@ -270,14 +225,6 @@ public class NewJForm extends JForm {
return new PreviewProvider[]{new FormPreview(), new MobilePreview()};
}
public boolean mobileForm() {
FormMobileAttr mobileAttr = this.getTarget().getFormMobileAttr();
if (mobileAttr.isMobileOnly() && mobileAttr.isAdaptivePropertyAutoMatch()) {
return true;
}
return false;
}
private SwitchAction switchAction;
public UIButton[] createExtraButtons() {

5
designer-form/src/main/java/com/fr/design/fit/common/AdaptiveSwitchUtil.java

@ -61,7 +61,7 @@ public class AdaptiveSwitchUtil {
return;
}
JTemplate<?, ?> old = TemplateTool.getCurrentEditingTemplate();
if (old == null || !(old instanceof JForm)) {
if (!(old instanceof JForm)) {
return;
}
JTemplate<?, ?> template = createNewJTemplate(old);
@ -152,9 +152,6 @@ public class AdaptiveSwitchUtil {
private static JTemplate<?, ?> createNewJTemplateInternal(JTemplate<?, ?> old) {
FILE file = old.getEditingFILE();
if ((file instanceof MemFILE) || !old.isSaved()) {
if (old instanceof NewJForm) {
TemplateTool.resetAbsoluteBodySize((NewJForm) old);
}
TemplateTool.saveForm(old);
}
if (old.getTarget() instanceof Form) {

15
designer-form/src/main/java/com/fr/design/fit/common/LayoutTool.java

@ -7,20 +7,16 @@ import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.design.designer.creator.cardlayout.XWCardLayout;
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
import com.fr.design.fit.NewJForm;
import com.fr.design.mainframe.FormArea;
import com.fr.design.mainframe.JForm;
import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.container.WAbsoluteBodyLayout;
import com.fr.form.ui.container.WFitLayout;
import com.fr.form.ui.container.WLayout;
import com.fr.form.ui.widget.CRBoundsWidget;
import com.fr.general.FRScreen;
import com.fr.log.FineLoggerFactory;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
/**
* @description:布局工具类
@ -163,15 +159,4 @@ public class LayoutTool {
}
}
/**
* @Description: 获取老预览时的缩放比例
* @return:
* @Author: Henry.Wang
* @date: 2020/10/26 20:39
*/
public static double getContainerPercent(){
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
double screenValue = FRScreen.getFRScreenByDimension(screen).getValue();
return screenValue / FormArea.DEFAULT_SLIDER;
}
}

62
designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java

@ -1,17 +1,12 @@
package com.fr.design.fit.common;
import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWAbsoluteBodyLayout;
import com.fr.design.designer.creator.XWFitLayout;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.MutilTempalteTabPane;
import com.fr.design.fit.DesignerUIModeConfig;
import com.fr.design.fit.JFormType;
import com.fr.design.fit.NewJForm;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.FormArea;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.JForm;
import com.fr.design.mainframe.JTemplate;
import com.fr.event.Event;
@ -19,12 +14,7 @@ import com.fr.event.Listener;
import com.fr.file.MemFILE;
import com.fr.file.StashedFILE;
import com.fr.form.fit.common.LightTool;
import com.fr.form.fit.NewFormMarkAttr;
import com.fr.form.ui.Widget;
import com.fr.form.ui.widget.CRBoundsWidget;
import com.fr.general.ComparatorUtils;
import java.awt.Rectangle;
import java.util.List;
/**
@ -168,55 +158,5 @@ public class TemplateTool {
jTemplate.requestFocus();
}
/**
* @param height
* @param width
* @param newJForm
* @Description: 只改变绝对布局body的尺寸
* @return:
* @Author: Henry.Wang
* @date: 2020/9/11 15:14
*/
public static void onlyChangeAbsoluteBodySize(int height, int width, NewJForm newJForm) {
FormDesigner formDesigner = newJForm.getFormDesign();
FormArea formArea = formDesigner.getArea();
XLayoutContainer root = formDesigner.getRootComponent();
XWAbsoluteBodyLayout xwAbsoluteBodyLayout = LayoutTool.getXWAbsoluteBodyLayout(newJForm);
if (root.acceptType(XWFitLayout.class) && xwAbsoluteBodyLayout != null) {
XWFitLayout layout = (XWFitLayout) root;
if (height == layout.toData().getContainerHeight() && width == layout.toData().getContainerWidth())
return;
formArea.setWidthPaneValue(width);
formArea.setHeightPaneValue(height);
layout.setSize(width, height);
xwAbsoluteBodyLayout.setSize(width, height);
Widget widget = layout.toData().getWidget(0);
if (widget instanceof CRBoundsWidget) {
((CRBoundsWidget) widget).setBounds(new Rectangle(0, 0, width, height));
}
layout.toData().setContainerWidth(width);
layout.toData().setContainerHeight(height);
formArea.doReCalculateRoot(width, height, layout);
}
formDesigner.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_EDITED);
}
/**
* @param newJForm
* @Description: 因为新老模板切换有截断的问题所以body的尺寸会在调用onlyChangeAbsoluteBodySize之后发生改变为了使模板文件中的尺寸不发生要在模板保存时调用此函数
* @return:
* @Author: Henry.Wang
* @date: 2020/9/11 15:20
*/
public static void resetAbsoluteBodySize(NewJForm newJForm) {
if (LayoutTool.absoluteLayoutForm(newJForm)) {
NewFormMarkAttr newFormMarkAttr = newJForm.getTarget().getAttrMark(NewFormMarkAttr.XML_TAG);
XLayoutContainer root = newJForm.getFormDesign().getRootComponent();
if (newFormMarkAttr != null && root instanceof XWFitLayout) {
((XWFitLayout) root).toData().setContainerWidth(newFormMarkAttr.getBodyWidth());
((XWFitLayout) root).toData().setContainerHeight(newFormMarkAttr.getBodyHeight());
}
}
}
}

137
designer-form/src/main/java/com/fr/design/mainframe/FormArea.java

@ -7,7 +7,6 @@ import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWBorderLayout;
import com.fr.design.designer.creator.XWFitLayout;
import com.fr.design.fit.DesignerUIModeConfig;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIButtonUI;
import com.fr.design.gui.ilable.UILabel;
@ -25,11 +24,11 @@ import com.fr.design.scrollruler.VerticalRuler;
import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.GUIPaintUtils;
import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.fit.NewFormMarkAttr;
import com.fr.form.main.mobile.FormMobileAttr;
import com.fr.form.ui.container.WBodyLayoutType;
import com.fr.form.ui.container.WBorderLayout;
import com.fr.form.ui.container.WFitLayout;
import com.fr.general.FRScreen;
import com.fr.general.IOUtils;
import com.fr.stable.AssistUtils;
@ -66,12 +65,10 @@ import java.awt.event.MouseWheelEvent;
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER;
public class FormArea extends JComponent implements ScrollRulerComponent {
private static final double SLIDER_FLOAT = 400.0;
private static final double SLIDER_MIN = 10.0;
private static final String SCALE_PLUS_COMMAND = "scale_plus";
private static final String SCALE_MINUS_COMMAND = "scale_minus";
public static final String FIX_LAYOUT_SWITCH_BUTTON = "fix_layout_switch_button";
public static final double DEFAULT_SLIDER = 100.0;
public static final double DEFAULT_SLIDER = 100.0D;
private static final int ROTATIONS = 50;
public static final int SHOWVALMAX = 400;
public static final int SHOWVALMIN = 10;
@ -90,21 +87,9 @@ public class FormArea extends JComponent implements ScrollRulerComponent {
private UINumberField heightPane;
private JFormSliderPane slidePane;
private boolean isValid = true;
// 初始时滑块值为100,托动后的值设为START_VALUE;
private double START_VALUE = DEFAULT_SLIDER;
private double screenValue;
private UIButton fixLayoutSwitchButton;
private boolean isFixLayoutEditState;
public FormScrollBar getHorScrollBar() {
return horScrollBar;
}
public void setHorScrollBar(FormScrollBar horScrollBar) {
this.horScrollBar = horScrollBar;
}
public FormArea(FormDesigner designer) {
this(designer, true);
}
@ -243,7 +228,6 @@ public class FormArea extends JComponent implements ScrollRulerComponent {
heightPane.setPreferredSize(new Dimension(60, 0));
slidePane = JFormSliderPane.getInstance();
JPanel resizePane = TableLayoutHelper.createCommonTableLayoutPane(
new JComponent[][]{{tipsPane, layoutSwitchPane, widthPane,
new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Indent_Pixel")),
@ -258,6 +242,7 @@ public class FormArea extends JComponent implements ScrollRulerComponent {
slidePane.setVisible(true);
initCalculateSize();
slidePane.addValueChangeListener(showValSpinnerChangeListener);
slidePane.setShowValue(FRScreen.getFRScreenByDimension(Toolkit.getDefaultToolkit().getScreenSize()).getValue().intValue());
}
public void undoFixLayoutState(boolean isFixLayout) {
@ -309,41 +294,10 @@ public class FormArea extends JComponent implements ScrollRulerComponent {
this.designer.repaint();
}
/**
* 返回当前的屏幕分辨率对应的百分比值
*
* @return 缩放的百分比值
*/
public double getScreenValue() {
return screenValue;
}
/**
* 设置屏幕分辨率对应的百分比值
*
* @param screenValue 百分比值
*/
public void setScreenValue(double screenValue) {
this.screenValue = screenValue;
}
private void initCalculateSize() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension scrnsize = toolkit.getScreenSize();
this.screenValue = DesignerUIModeConfig.getInstance().getDesignScreenByDimension(scrnsize).getValue();
XLayoutContainer root = FormArea.this.designer.getRootComponent();
// 7.1.1不放缩放滑块,但表单大小仍按屏幕分辨率调整
// slidePane.populateBean(screenValue);
if (root.acceptType(XWFitLayout.class)) {
XWFitLayout layout = (XWFitLayout) root;
if ( !AssistUtils.equals(screenValue, DEFAULT_SLIDER) ) {
reCalculateRoot(screenValue, true);
} else {
// 组件间隔啊
// REPORT-2585 原有的逻辑导致嵌套的tab中的间隔加不上去,会在后续拖动的过程中出问题
reCalculateDefaultRoot(screenValue, true);
}
reCalculateDefaultRoot();
}
LayoutUtils.layoutContainer(root);
updateCreatorsBackupBound(root);
@ -380,18 +334,10 @@ public class FormArea extends JComponent implements ScrollRulerComponent {
// 失去焦点时,可以认为输入结束
int width = (int) ((UINumberField) e.getSource()).getValue();
changeWidthPaneValue(width);
changeFormMarkAttrWidth(width);
}
});
}
private void changeFormMarkAttrWidth(int width) {
NewFormMarkAttr newFormMarkAttr = designer.getTarget().getAttrMark(NewFormMarkAttr.XML_TAG);
if (newFormMarkAttr != null) {
newFormMarkAttr.setBodyWidth(width);
}
}
private void changeWidthPaneValue(int width) {
XWFitLayout layout = (XWFitLayout) designer.getRootComponent();
@ -407,7 +353,6 @@ public class FormArea extends JComponent implements ScrollRulerComponent {
public void actionPerformed(ActionEvent evt) {
int height = (int) ((UINumberField) evt.getSource()).getValue();
changeHeightPaneValue(height);
changeFormMarkAttrHeight(height);
}
});
heightPane.addFocusListener(
@ -420,13 +365,6 @@ public class FormArea extends JComponent implements ScrollRulerComponent {
});
}
private void changeFormMarkAttrHeight(int height){
NewFormMarkAttr newFormMarkAttr = designer.getTarget().getAttrMark(NewFormMarkAttr.XML_TAG);
if (newFormMarkAttr != null) {
newFormMarkAttr.setBodyHeight(height);
}
}
private void changeHeightPaneValue(int height) {
XWFitLayout layout = (XWFitLayout) designer.getRootComponent();
@ -497,78 +435,26 @@ public class FormArea extends JComponent implements ScrollRulerComponent {
* 修改大小后再根据屏幕分辨率调整下
*/
public void doReCalculateRoot(int width, int height, XWFitLayout layout) {
// double value = slidePane.updateBean();
//重置滑块的值为默认值100
START_VALUE = DEFAULT_SLIDER;
if ( AssistUtils.equals(screenValue, DEFAULT_SLIDER) ) {
layout.getParent().setSize(width, height + designer.getParaHeight());
FormArea.this.validate();
} else {
layout.setBackupGap(screenValue / DEFAULT_SLIDER);
reCalculateRoot(screenValue, false);
}
}
/**
* 按照界面大小的百分比值调整root大小
*
* @param needCalculateParaHeight 是否需要调整参数界面高度
* @param value
*/
private void reCalculateRoot(double value, boolean needCalculateParaHeight) {
if ( AssistUtils.equals(value, START_VALUE) ) {
return;
}
double percent = (value - START_VALUE) / START_VALUE;
XLayoutContainer root = FormArea.this.designer.getRootComponent();
if (root.acceptType(XWFitLayout.class)) {
XWFitLayout layout = (XWFitLayout) root;
layout.setContainerPercent(value / DEFAULT_SLIDER);
traverAndAdjust(layout, percent);
layout.adjustCreatorsWhileSlide(percent);
// 拖动滑块,先将内部组件百分比大小计算,再计算容器大小
Dimension d = new Dimension(layout.getWidth(), layout.getHeight());
// 自适应布局的父层是border
if (layout.getParent() != null) {
int paraHeight = designer.getParaHeight();
if (needCalculateParaHeight && paraHeight > 0) {
designer.setParaHeight(paraHeight);
XWBorderLayout parent = (XWBorderLayout) layout.getParent();
parent.toData().setNorthSize(paraHeight);
parent.removeAll();
parent.add(designer.getParaComponent(), WBorderLayout.NORTH);
parent.add(designer.getRootComponent(), WBorderLayout.CENTER);
}
layout.getParent().setSize(d.width, d.height + paraHeight);
// 调整自适应布局大小后,同步调整参数界面和border大小,此时刷新下formArea
FormArea.this.validate();
}
START_VALUE = value;
}
layout.getParent().setSize(width, height + designer.getParaHeight());
FormArea.this.validate();
}
/**
* 按照界面大小的百分比值调整root大小
*
* @param needCalculateParaHeight 是否需要调整参数界面高度
* @param value
*/
private void reCalculateDefaultRoot(double value, boolean needCalculateParaHeight) {
private void reCalculateDefaultRoot() {
XLayoutContainer root = FormArea.this.designer.getRootComponent();
if (root.acceptType(XWFitLayout.class)) {
XWFitLayout layout = (XWFitLayout) root;
layout.setContainerPercent(1.0);
traverAndAdjust(layout, 0.0);
layout.adjustCreatorsWhileSlide(0.0);
// 拖动滑块,先将内部组件百分比大小计算,再计算容器大小
Dimension d = new Dimension(layout.getWidth(), layout.getHeight());
// 自适应布局的父层是border
if (layout.getParent() != null) {
int paraHeight = designer.getParaHeight();
if (needCalculateParaHeight && paraHeight > 0) {
if (paraHeight > 0) {
designer.setParaHeight(paraHeight);
XWBorderLayout parent = (XWBorderLayout) layout.getParent();
parent.toData().setNorthSize(paraHeight);
@ -885,16 +771,11 @@ public class FormArea extends JComponent implements ScrollRulerComponent {
heightPane.setValue(height);
reCalculateHeight((int) height);
}
if (designer.getRootComponent().acceptType(XWFitLayout.class) && AssistUtils.equals(screenValue, DEFAULT_SLIDER) ) {
if (designer.getRootComponent().acceptType(XWFitLayout.class) ) {
XWFitLayout layout = (XWFitLayout) designer.getRootComponent();
// 撤销时先refreshRoot了,此处去掉内边距再增加间隔
layout.moveContainerMargin();
layout.addCompInterval(layout.getAcualInterval());
} else if (designer.getRootComponent().acceptType(XWFitLayout.class)) {
START_VALUE = DEFAULT_SLIDER;
reCalculateRoot(screenValue, true);
// slidePane.populateBean(slide);
}
this.slidePane.setShowValue((int) slide);
}

9
designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java

@ -151,7 +151,6 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
// 存储被选择组件和剪切板的model
private transient SelectionModel selectionModel;
private int resolution = DesignerUIModeConfig.getInstance().getScreenResolution();
// 编辑状态的事件表
private CreatorEventListenerTable edit;
protected List<UpdateAction> designerActions;
@ -1801,14 +1800,6 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
}
public void setResolution(int resolution) {
this.resolution = resolution;
}
public int getResolution() {
return this.resolution;
}
public double getScale() {
return scale;
}

3
designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java

@ -1,6 +1,7 @@
package com.fr.design.mainframe;
import com.fr.base.GraphHelper;
import com.fr.base.ScreenResolution;
import com.fr.base.Utils;
import com.fr.base.iofile.attr.WatermarkAttr;
import com.fr.base.vcs.DesignerMode;
@ -132,7 +133,7 @@ public class FormDesignerUI extends ComponentUI {
return;
}
WatermarkAttr watermark = ReportUtils.getWatermarkAttrFromTemplateAndGlobal(designer.getTarget());
WatermarkPainter painter = WatermarkPainter.createPainter(watermark, designer.getResolution());
WatermarkPainter painter = WatermarkPainter.createPainter(watermark, ScreenResolution.getScreenResolution());
painter.paint(g, 0, 0, designer.getArea().getBounds());
}

3
designer-form/src/main/java/com/fr/design/mainframe/FormSelectionUtils.java

@ -182,11 +182,10 @@ public class FormSelectionUtils {
if (!childrenList.isEmpty()) {
for (Object aChildrenList : childrenList) {
XWTabFitLayout tabLayout = (XWTabFitLayout) aChildrenList;
double percent = tabLayout.getContainerPercent();
Component[] components = tabLayout.getComponents();
for (Component component : components) {
Rectangle show = component.getBounds();
component.setBounds(new Rectangle((int) (show.x * percent), (int) (show.y * percent), (int) (show.width * percent), (int) (show.height * percent)));
component.setBounds(new Rectangle(show.x, show.y, show.width, show.height));
}
}
}

3
designer-form/src/main/java/com/fr/design/mainframe/share/select/ComponentTransformerImpl.java

@ -30,7 +30,6 @@ import org.jetbrains.annotations.Nullable;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
@ -88,8 +87,6 @@ public class ComponentTransformerImpl implements ComponentTransformer {
FRContext.getLogger().error(e1.getMessage(), e1);
}
}
wAbsoluteLayout.setDesigningResolution(Toolkit.getDefaultToolkit().getScreenSize());
selectedCreator = new XWAbsoluteLayout(wAbsoluteLayout, new Dimension(selectedTriple.width, selectedTriple.height));
selectedWidget = selectedCreator.toData();

4
designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java

@ -150,7 +150,7 @@ public class WidgetBoundPane extends BasicPane {
public void limitWidth(WLayout wabs, int w, Rectangle bounds, Rectangle rec) {
int difference = 0;
int minWidth = (int) (MINWIDTH * ((WFitLayout) wabs).getResolutionScaling());
int minWidth = MINWIDTH;
PaddingMargin margin = wabs.getMargin();
if (bounds.width != w) {
if (bounds.width == rec.width - margin.getLeft() - margin.getRight()) {
@ -172,7 +172,7 @@ public class WidgetBoundPane extends BasicPane {
public void limitHeight(WLayout wabs, int h, Rectangle bounds, Rectangle rec) {
int difference = 0;
PaddingMargin margin = wabs.getMargin();
int minHeight = (int) (MINHEIGHT * ((WFitLayout) wabs).getResolutionScaling());
int minHeight = MINHEIGHT;
if (bounds.height != h) {
if (bounds.height == rec.height - margin.getTop() - margin.getBottom()) {
FineJOptionPane.showMessageDialog(null, i18nText("Fine-Design_Form_Beyond_Bounds"));

Loading…
Cancel
Save