|
|
|
package com.fr.design.fit;
|
|
|
|
|
|
|
|
import com.fr.base.DynamicUnitList;
|
|
|
|
import com.fr.base.Parameter;
|
|
|
|
import com.fr.base.TRL;
|
|
|
|
import com.fr.design.designer.beans.AdapterBus;
|
|
|
|
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.XComponent;
|
|
|
|
import com.fr.design.designer.creator.XCreator;
|
|
|
|
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.fit.toolbar.SwitchAction;
|
|
|
|
import com.fr.design.fun.PreviewProvider;
|
|
|
|
import com.fr.design.gui.ibutton.UIButton;
|
|
|
|
import com.fr.design.mainframe.DesignerUIModeConfig;
|
|
|
|
import com.fr.design.mainframe.FormDesigner;
|
|
|
|
import com.fr.design.mainframe.JForm;
|
|
|
|
import com.fr.design.mainframe.WidgetPropertyPane;
|
|
|
|
import com.fr.design.preview.DeveloperPreview;
|
|
|
|
import com.fr.design.preview.FormAdaptivePreview;
|
|
|
|
import com.fr.design.preview.FormPreview;
|
|
|
|
import com.fr.design.preview.MobilePreview;
|
|
|
|
import com.fr.design.utils.ComponentUtils;
|
|
|
|
import com.fr.file.FILE;
|
|
|
|
import com.fr.form.FormElementCaseProvider;
|
|
|
|
import com.fr.form.fit.NewFormMarkAttr;
|
|
|
|
import com.fr.form.main.Form;
|
|
|
|
import com.fr.form.ui.ElementCaseEditor;
|
|
|
|
import com.fr.general.ComparatorUtils;
|
|
|
|
import com.fr.stable.ArrayUtils;
|
|
|
|
|
|
|
|
import javax.swing.JComponent;
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.Rectangle;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by kerry on 2020-05-31
|
|
|
|
*/
|
|
|
|
public class NewJForm extends JForm {
|
|
|
|
private static final int FUZZY_EDGE = 10;
|
|
|
|
private static final int TITLE_HEIGHT = 36;
|
|
|
|
private JFormType jFormType;
|
|
|
|
|
|
|
|
public NewJForm() {
|
|
|
|
super();
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public NewJForm(Form form) {
|
|
|
|
super(form);
|
|
|
|
//新建的模板都要加上新表单标志attr
|
|
|
|
getTarget().addAttrMark(NewFormMarkAttr.createNewFormAttr());
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public NewJForm(Form form, FILE file, Parameter[] parameters) {
|
|
|
|
this(form, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
public NewJForm(Form form, FILE file) {
|
|
|
|
super(form, file);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public JFormType getJFormType() {
|
|
|
|
return this.jFormType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setJFormType(JFormType jFormType) {
|
|
|
|
this.jFormType = jFormType;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
this.getFormDesign().addDesignerEditListener(new DesignerEditListener() {
|
|
|
|
private Rectangle oldRec;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fireCreatorModified(DesignerEvent evt) {
|
|
|
|
if (evt.getAffectedCreator() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_RESIZED) {
|
|
|
|
XComponent affectedCreator = evt.getAffectedCreator();
|
|
|
|
if (isElementCase((JComponent) affectedCreator)) {
|
|
|
|
processAbsorbingEffect((XWTitleLayout) affectedCreator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
|
|
|
|
XComponent affectedCreator = evt.getAffectedCreator();
|
|
|
|
oldRec = new Rectangle(affectedCreator.getBounds());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isElementCase(JComponent component) {
|
|
|
|
return component.getComponents().length > 0 && component.getComponent(0) instanceof XElementCase;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processAbsorbingEffect(XWTitleLayout xwTitleLayout) {
|
|
|
|
NewJForm.this.getFormDesign().repaint();
|
|
|
|
Dimension bound = new Dimension(xwTitleLayout.getSize());
|
|
|
|
ElementCaseEditor elementCaseEditor = (ElementCaseEditor) xwTitleLayout.toData().getBodyBoundsWidget().getWidget();
|
|
|
|
FormElementCaseProvider elementCase = elementCaseEditor.getElementCase();
|
|
|
|
if (oldRec.width != bound.width) {
|
|
|
|
processColumnAbsorbingEffect(xwTitleLayout, elementCase.getColumnWidthList_DEC(), bound);
|
|
|
|
oldRec.width = bound.width;
|
|
|
|
}
|
|
|
|
if (oldRec.height != bound.height) {
|
|
|
|
processRowAbsorbingEffect(xwTitleLayout, elementCase.getRowHeightList_DEC(), bound);
|
|
|
|
oldRec.height = bound.height;
|
|
|
|
}
|
|
|
|
NewJForm.this.getFormDesign().refreshDesignerUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean hasTitle(XWTitleLayout xwTitleLayout) {
|
|
|
|
return xwTitleLayout.getComponentCount() > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processColumnAbsorbingEffect(XWTitleLayout xwTitleLayout, DynamicUnitList columnUnitList, Dimension bound) {
|
|
|
|
int temp = 0;
|
|
|
|
int resolution = DesignerUIModeConfig.getInstance().getScreenResolution();
|
|
|
|
int difference = 0;
|
|
|
|
int i = 0;
|
|
|
|
while (true) {
|
|
|
|
if (i < columnUnitList.size()) {
|
|
|
|
temp += columnUnitList.get(i++).toPixI(resolution);
|
|
|
|
} else {
|
|
|
|
//在处理吸附效果时,columnUnitList数组长度可能比实际显示的列数少,所以用默认值来补充
|
|
|
|
temp += columnUnitList.getDefaultUnit().toPixI(resolution);
|
|
|
|
}
|
|
|
|
if (bound.width - temp < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bound.width - temp < FUZZY_EDGE) {
|
|
|
|
difference = bound.width - temp;
|
|
|
|
bound.width = temp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fixLayout(xwTitleLayout, bound, difference, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processRowAbsorbingEffect(XWTitleLayout xwTitleLayout, DynamicUnitList rowUnitList, Dimension bound) {
|
|
|
|
int temp = hasTitle(xwTitleLayout) ? TITLE_HEIGHT : 0;
|
|
|
|
int resolution = DesignerUIModeConfig.getInstance().getScreenResolution();
|
|
|
|
int difference = 0;
|
|
|
|
int i = 0;
|
|
|
|
while (true) {
|
|
|
|
if (i < rowUnitList.size()) {
|
|
|
|
temp += rowUnitList.get(i++).toPixI(resolution);
|
|
|
|
} else {
|
|
|
|
//在处理吸附效果时,rowUnitList数组长度可能比实际显示的行数少,所以用默认值来补充
|
|
|
|
temp += rowUnitList.getDefaultUnit().toPixI(resolution);
|
|
|
|
}
|
|
|
|
if (bound.height - temp < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bound.height - temp < FUZZY_EDGE) {
|
|
|
|
difference = bound.height - temp;
|
|
|
|
bound.height = temp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fixLayout(xwTitleLayout, bound, difference, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void fixLayout(XWTitleLayout xwTitleLayout, Dimension bound, int difference, int row) {
|
|
|
|
Rectangle backupBounds = getBound(xwTitleLayout);
|
|
|
|
xwTitleLayout.setSize(bound);
|
|
|
|
FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner();
|
|
|
|
LayoutAdapter adapter = AdapterBus.searchLayoutAdapter(formDesigner, xwTitleLayout);
|
|
|
|
if (adapter instanceof FRFitLayoutAdapter) {
|
|
|
|
FRFitLayoutAdapter layoutAdapter = (FRFitLayoutAdapter) adapter;
|
|
|
|
layoutAdapter.setEdit(true);
|
|
|
|
layoutAdapter.calculateBounds(backupBounds, xwTitleLayout.getBounds(), xwTitleLayout, row, difference);
|
|
|
|
} else {
|
|
|
|
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(xwTitleLayout);
|
|
|
|
if (parent != null && parent.toData() != null) {
|
|
|
|
parent.toData().setBounds(xwTitleLayout.toData(), xwTitleLayout.getBounds());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Form form = this.getTarget();
|
|
|
|
NewFormMarkAttr newFormMarkAttr = form.getAttrMark(NewFormMarkAttr.XML_TAG);
|
|
|
|
if (newFormMarkAttr == null) {
|
|
|
|
newFormMarkAttr = new NewFormMarkAttr();
|
|
|
|
}
|
|
|
|
this.setJFormType(JFormType.parseFormType(newFormMarkAttr.getType()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Rectangle getBound(XWTitleLayout creator) {
|
|
|
|
Rectangle bounds = new Rectangle(creator.getBounds());
|
|
|
|
if (creator.getParent() == null) {
|
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
Rectangle rec = ComponentUtils.getRelativeBounds(creator.getParent());
|
|
|
|
bounds.x += rec.x;
|
|
|
|
bounds.y += rec.y;
|
|
|
|
return bounds;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PreviewProvider[] supportPreview() {
|
|
|
|
if (isNewJFrom()) {
|
|
|
|
return new PreviewProvider[]{new FormAdaptivePreview(), new DeveloperPreview(), new MobilePreview()};
|
|
|
|
}
|
|
|
|
return new PreviewProvider[]{new FormPreview(), new MobilePreview()};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public UIButton[] createExtraButtons() {
|
|
|
|
UIButton[] extraButtons = super.createExtraButtons();
|
|
|
|
return addAdaptiveSwitchButton(extraButtons);
|
|
|
|
}
|
|
|
|
|
|
|
|
private UIButton[] addAdaptiveSwitchButton(UIButton[] extraButtons) {
|
|
|
|
SwitchAction switchAction = new SwitchAction(this);
|
|
|
|
return ArrayUtils.addAll(extraButtons, switchAction.getToolBarButton());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isNewJFrom() {
|
|
|
|
return jFormType == null || jFormType.isNewType();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void navigate(TRL trl) {
|
|
|
|
String blockName = trl.unescapeNext();
|
|
|
|
JForm.traversalXCreator(formDesign.getRootComponent(), xCreator -> {
|
|
|
|
if (!ComparatorUtils.equals(xCreator.toData().getWidgetName(), blockName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (xCreator instanceof XElementCase) {
|
|
|
|
getFormDesign().getSelectionModel().selectACreator4ITLocation(xCreator);
|
|
|
|
xCreator.startEditing();
|
|
|
|
if (getElementCaseDesign() != null) {
|
|
|
|
getElementCaseDesign().navigate(trl);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tabChanged(FORM_TAB);
|
|
|
|
getFormDesign().getSelectionModel().reset();
|
|
|
|
getFormDesign().getSelectionModel().selectACreator4ITLocation(xCreator);
|
|
|
|
}
|
|
|
|
}, XCreator.class);
|
|
|
|
}
|
|
|
|
}
|