Browse Source

去除新老转换时,调整表单组件尺寸的逻辑

feature/x
kerry 3 years ago
parent
commit
e972e7ef1c
  1. 63
      designer-form/src/main/java/com/fr/design/fit/NewJForm.java
  2. 5
      designer-form/src/main/java/com/fr/design/fit/common/AdaptiveSwitchUtil.java
  3. 15
      designer-form/src/main/java/com/fr/design/fit/common/LayoutTool.java
  4. 62
      designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java
  5. 17
      designer-form/src/main/java/com/fr/design/mainframe/FormArea.java

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

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

@ -24,7 +24,6 @@ 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;
@ -335,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();
@ -362,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(
@ -375,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();

Loading…
Cancel
Save