From 08a39eee5c279f91787f5ce3a310c63a1fd68b5e Mon Sep 17 00:00:00 2001 From: kerry Date: Tue, 14 Dec 2021 11:54:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?KERNEL-9636=20=E6=96=B0=E8=87=AA=E9=80=82?= =?UTF-8?q?=E5=BA=94=E4=B8=AD=E8=AE=BE=E8=AE=A1=E5=99=A8=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=92=8C=E4=B8=BB=20jar=20=E4=B8=AD=E7=9A=84=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe}/DesignerUIModeConfig.java | 46 ++-- .../com/fr/design/mainframe/JTemplate.java | 4 + .../java/com/fr/design/mainframe}/PX.java | 2 +- .../design/mainframe}/PXReportLengthUNIT.java | 2 +- .../actions/NewFormMobileAttrAction.java | 115 ---------- .../java/com/fr/design/fit/JFormType.java | 109 ++-------- .../main/java/com/fr/design/fit/NewJForm.java | 38 ++-- .../design/fit/common/AdaptiveSwitchUtil.java | 142 ++++++------- .../fr/design/fit/common/TemplateTool.java | 42 ++-- .../fr/design/fit/toolbar/SwitchAction.java | 26 +-- .../com/fr/design/mainframe/FormDesigner.java | 1 - .../java/com/fr/design/mainframe/JForm.java | 4 + .../parameter/RootDesignDefinePane.java | 4 +- .../layout/ElementEditorDefinePane.java | 10 +- .../FRAbsoluteBodyLayoutDefinePane.java | 6 +- .../layout/FRAbsoluteLayoutDefinePane.java | 4 +- .../layout/FRFitLayoutDefinePane.java | 8 +- .../fr/design/fit/FormUIModeConfigTest.java | 11 +- .../fr/design/fit/PXReportLengthUNITTest.java | 1 + .../test/java/com/fr/design/fit/PXTest.java | 1 + .../columnrow/ColumnRowSizingAction.java | 2 +- .../java/com/fr/design/condition/WHPane.java | 2 +- .../grid/GridHeaderWithBoundMouseHandler.java | 70 ------ .../fit/grid/GridLimitColumnMouseHandler.java | 194 ----------------- .../fit/grid/GridLimitRowMouseHandler.java | 190 ----------------- .../fit/grid/NewFormDesignerGridUI.java | 201 ------------------ .../fr/design/mainframe/ElementCasePane.java | 11 +- .../form/FormElementCaseDesigner.java | 1 - .../form/FormElementCasePaneDelegate.java | 46 +++- .../form/FormReportComponentComposite.java | 5 +- .../grid/AbstractGridHeaderMouseHandler.java | 42 +++- .../com/fr/grid/DefaultGridUIProcessor.java | 10 +- .../src/main/java/com/fr/grid/Grid.java | 35 ++- .../src/main/java/com/fr/grid/GridColumn.java | 77 +++---- .../com/fr/grid/GridColumnMouseHandler.java | 33 ++- .../main/java/com/fr/grid/GridColumnUI.java | 2 +- .../src/main/java/com/fr/grid/GridCorner.java | 4 +- .../java/com/fr/grid/GridMouseAdapter.java | 73 ++++++- .../src/main/java/com/fr/grid/GridRow.java | 105 +++++---- .../java/com/fr/grid/GridRowMouseHandler.java | 27 +++ .../src/main/java/com/fr/grid/GridRowUI.java | 2 +- .../src/main/java/com/fr/grid/GridUI.java | 30 +++ .../src/main/java/com/fr/grid/GridUtils.java | 2 +- 43 files changed, 534 insertions(+), 1206 deletions(-) rename {designer-form/src/main/java/com/fr/design/fit => designer-base/src/main/java/com/fr/design/mainframe}/DesignerUIModeConfig.java (65%) rename {designer-form/src/main/java/com/fr/design/fit => designer-base/src/main/java/com/fr/design/mainframe}/PX.java (94%) rename {designer-form/src/main/java/com/fr/design/fit => designer-base/src/main/java/com/fr/design/mainframe}/PXReportLengthUNIT.java (95%) delete mode 100644 designer-form/src/main/java/com/fr/design/actions/NewFormMobileAttrAction.java delete mode 100644 designer-realize/src/main/java/com/fr/design/fit/grid/GridHeaderWithBoundMouseHandler.java delete mode 100644 designer-realize/src/main/java/com/fr/design/fit/grid/GridLimitColumnMouseHandler.java delete mode 100644 designer-realize/src/main/java/com/fr/design/fit/grid/GridLimitRowMouseHandler.java delete mode 100644 designer-realize/src/main/java/com/fr/design/fit/grid/NewFormDesignerGridUI.java diff --git a/designer-form/src/main/java/com/fr/design/fit/DesignerUIModeConfig.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerUIModeConfig.java similarity index 65% rename from designer-form/src/main/java/com/fr/design/fit/DesignerUIModeConfig.java rename to designer-base/src/main/java/com/fr/design/mainframe/DesignerUIModeConfig.java index 5e743d383e..1e072d956a 100644 --- a/designer-form/src/main/java/com/fr/design/fit/DesignerUIModeConfig.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerUIModeConfig.java @@ -1,19 +1,16 @@ -package com.fr.design.fit; +package com.fr.design.mainframe; import com.fr.base.ScreenResolution; import com.fr.design.fun.ReportLengthUNITProvider; import com.fr.design.unit.UnitConvertUtil; import com.fr.general.ComparatorUtils; -import com.fr.general.FRScreen; import com.fr.stable.Constants; -import java.awt.Dimension; - /** * Created by kerry on 2020-06-05 */ public class DesignerUIModeConfig { - private DesignerUIMode mode = DesignerUIMode.NEW_UI_MODE; + private DesignerUIMode mode = DesignerUIMode.ABSOLUTE_MEASURE_UI_MODE; private static class DesignerUIModeConfigHolder { private static final DesignerUIModeConfig designerUIModeConfig = new DesignerUIModeConfig(); @@ -33,22 +30,22 @@ public class DesignerUIModeConfig { * * @return boolean */ - public boolean newUIMode() { - return ComparatorUtils.equals(DesignerUIMode.NEW_UI_MODE, mode); + public boolean simulateWebUIMode() { + return ComparatorUtils.equals(DesignerUIMode.SIMULATE_WEB_UI_MODE, mode); } /** * 设置新ui模式 */ - public void setNewUIMode() { - this.mode = DesignerUIMode.NEW_UI_MODE; + public void setSimulateWebUIMode() { + this.mode = DesignerUIMode.SIMULATE_WEB_UI_MODE; } /** * 设置老ui模式 */ - public void setOldUIMode() { - this.mode = DesignerUIMode.OLD_UI_MODE; + public void setAbsoluteMeasureUIMode() { + this.mode = DesignerUIMode.ABSOLUTE_MEASURE_UI_MODE; } /** @@ -70,55 +67,38 @@ public class DesignerUIModeConfig { return mode.getScreenResolution(); } - /** - * 根据屏幕尺寸获取设计时的FRScreen - * - * @param screen 屏幕尺寸 - * @return FRScreen - */ - public FRScreen getDesignScreenByDimension(Dimension screen) { - return mode.getDesignScreenByDimension(screen); - } private enum DesignerUIMode { - OLD_UI_MODE { + ABSOLUTE_MEASURE_UI_MODE { @Override protected ReportLengthUNITProvider parseLengthUNIT(int unitType) { return UnitConvertUtil.parseLengthUNIT(unitType); } - @Override - protected FRScreen getDesignScreenByDimension(Dimension screen) { - return FRScreen.getDesignScreenByDimension(screen); - } - @Override protected int getScreenResolution() { return ScreenResolution.getScreenResolution(); } + }, - NEW_UI_MODE { + SIMULATE_WEB_UI_MODE { @Override protected ReportLengthUNITProvider parseLengthUNIT(int unitType) { return new PXReportLengthUNIT(); } - @Override - protected FRScreen getDesignScreenByDimension(Dimension screen) { - return FRScreen.p1440; - } - @Override protected int getScreenResolution() { return Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION; } + }; protected abstract ReportLengthUNITProvider parseLengthUNIT(int unitType); - protected abstract FRScreen getDesignScreenByDimension(Dimension screen); protected abstract int getScreenResolution(); + } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index a08febe685..26a2f64bca 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -1869,4 +1869,8 @@ public abstract class JTemplate> } + public void setDesignerUIMode(){ + DesignerUIModeConfig.getInstance().setAbsoluteMeasureUIMode(); + } + } \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/fit/PX.java b/designer-base/src/main/java/com/fr/design/mainframe/PX.java similarity index 94% rename from designer-form/src/main/java/com/fr/design/fit/PX.java rename to designer-base/src/main/java/com/fr/design/mainframe/PX.java index 720268ea6a..8fd9ac0edc 100644 --- a/designer-form/src/main/java/com/fr/design/fit/PX.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/PX.java @@ -1,4 +1,4 @@ -package com.fr.design.fit; +package com.fr.design.mainframe; import com.fr.stable.Constants; import com.fr.stable.unit.LEN_UNIT; diff --git a/designer-form/src/main/java/com/fr/design/fit/PXReportLengthUNIT.java b/designer-base/src/main/java/com/fr/design/mainframe/PXReportLengthUNIT.java similarity index 95% rename from designer-form/src/main/java/com/fr/design/fit/PXReportLengthUNIT.java rename to designer-base/src/main/java/com/fr/design/mainframe/PXReportLengthUNIT.java index 8d8f1de167..69d46480e9 100644 --- a/designer-form/src/main/java/com/fr/design/fit/PXReportLengthUNIT.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/PXReportLengthUNIT.java @@ -1,4 +1,4 @@ -package com.fr.design.fit; +package com.fr.design.mainframe; import com.fr.design.fun.impl.AbstractReportLengthUNITProvider; import com.fr.stable.unit.UNIT; diff --git a/designer-form/src/main/java/com/fr/design/actions/NewFormMobileAttrAction.java b/designer-form/src/main/java/com/fr/design/actions/NewFormMobileAttrAction.java deleted file mode 100644 index 17ec76b837..0000000000 --- a/designer-form/src/main/java/com/fr/design/actions/NewFormMobileAttrAction.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.fr.design.actions; - - -import com.fr.base.iofile.attr.MobileOnlyTemplateAttrMark; -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.dialog.BasicDialog; -import com.fr.design.dialog.DialogActionAdapter; -import com.fr.design.fit.NewJForm; -import com.fr.design.fit.common.AdaptiveSwitchUtil; -import com.fr.design.fit.common.TemplateTool; -import com.fr.design.form.mobile.FormMobileAttrPane; -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.WidgetPropertyPane; -import com.fr.file.FILE; -import com.fr.form.main.Form; -import com.fr.form.main.mobile.FormMobileAttr; -import com.fr.record.analyzer.EnableMetrics; -import com.fr.stable.StringUtils; - -import java.awt.event.ActionEvent; - -/** - * Created by fanglei on 2016/11/14. - */ -@EnableMetrics -public class NewFormMobileAttrAction extends FormMobileAttrAction { - - public NewFormMobileAttrAction(JForm jf) { - super(jf); - } - - /** - * 执行动作 - * - * @return 是否执行成功 - */ - @Override - public void actionPerformed(ActionEvent e) { - final JForm jf = getEditingComponent(); - if (jf == null) { - return; - } - final Form formTpl = jf.getTarget(); - FormMobileAttr mobileAttr = formTpl.getFormMobileAttr(); - - final FormMobileAttrPane mobileAttrPane = new FormMobileAttrPane(); - mobileAttrPane.populateBean(mobileAttr); - - final boolean oldMobileOnly = mobileAttr.isMobileOnly(); - final boolean oldAdaptive = mobileAttr.isAdaptivePropertyAutoMatch(); - BasicDialog dialog = mobileAttrPane.showWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { - @Override - public void doOk() { - FormMobileAttr formMobileAttr = mobileAttrPane.updateBean(); - if (formMobileAttr.isMobileOnly() && jf.getTarget().getAttrMark(MobileOnlyTemplateAttrMark.XML_TAG) == null) { - // 如果是老模板,选择手机专属之后需要另存为 - FILE editingFILE = jf.getEditingFILE(); - if (editingFILE != null && editingFILE.exists()) { - String fileName = editingFILE.getName().substring(0, editingFILE.getName().length() - jf.suffix().length()) + "_mobile"; - if (!jf.saveAsTemplate(true, fileName)) { - return; - } - } - // 放到后面。如果提前 return 了,则仍然处于未设置状态,不要添加 - jf.getTarget().addAttrMark(new MobileOnlyTemplateAttrMark()); - } - // 设置移动端属性并刷新界面 - formTpl.setFormMobileAttr(formMobileAttr); // 会调整 body 的自适应布局,放到最后 - boolean changeSize = (!oldMobileOnly && formMobileAttr.isMobileOnly()) || (oldMobileOnly && !formMobileAttr.isMobileOnly()); - if (changeSize) { - ((FormArea)jf.getFormDesign().getParent()).onMobileAttrModified(); - } - //改变布局为自适应布局,只在移动端属性设置保存后改变一次 - boolean changeLayout = !oldAdaptive && formMobileAttr.isAdaptivePropertyAutoMatch(); - if (changeLayout) { - jf.getFormDesign().getSelectionModel().setSelectedCreator(jf.getFormDesign().getRootComponent()); - doChangeBodyLayout(); - WidgetPropertyPane.getInstance().refreshDockingView(); - } - jf.fireTargetModified(); - FILE editingFILE = jf.getEditingFILE(); - if(editingFILE != null && editingFILE.exists()){ - JForm jForm = getEditingComponent(); - TemplateTool.saveForm(jForm); - if (jForm instanceof NewJForm) { - AdaptiveSwitchUtil.switch2OldUI(); - } - }else { - AdaptiveSwitchUtil.switch2OldUIMode(); - NewJForm mobileJForm = new NewJForm(jf.getTarget(), jf.getEditingFILE()); - //设置临时的id,和新建的模板区分 - mobileJForm.getTarget().setTemplateID(StringUtils.EMPTY); - TemplateTool.resetTabPaneEditingTemplate(mobileJForm); - TemplateTool.activeAndResizeTemplate(mobileJForm); - } - } - }); - dialog.setVisible(true); - } - - private void doChangeBodyLayout(){ - FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); - XLayoutContainer rootLayout = formDesigner.getRootComponent(); - if (rootLayout.getComponentCount() == 1 && rootLayout.getXCreator(0).acceptType(XWAbsoluteBodyLayout.class)) { - rootLayout = (XWAbsoluteBodyLayout) rootLayout.getXCreator(0); - } - ((XWFitLayout)formDesigner.getRootComponent()).switch2FitBodyLayout(rootLayout); - } -} - diff --git a/designer-form/src/main/java/com/fr/design/fit/JFormType.java b/designer-form/src/main/java/com/fr/design/fit/JFormType.java index f2d1c4ad90..52c8f728cb 100644 --- a/designer-form/src/main/java/com/fr/design/fit/JFormType.java +++ b/designer-form/src/main/java/com/fr/design/fit/JFormType.java @@ -1,30 +1,10 @@ package com.fr.design.fit; -import com.fr.design.beans.BasicBeanPane; -import com.fr.design.fit.common.AdaptiveSwitchUtil; -import com.fr.form.fit.NewFormMarkAttr; import com.fr.form.fit.config.FormFitConfig; -import com.fr.design.fit.menupane.FormFitAttrPane; -import com.fr.design.fun.PreviewProvider; -import com.fr.design.mainframe.JTemplate; -import com.fr.design.preview.FormAdaptivePreview; -import com.fr.design.preview.FormPreview; -import com.fr.design.report.fit.menupane.ReportFitAttrPane; -import com.fr.form.main.Form; import com.fr.report.fit.ReportFitAttr; public enum JFormType { - OLD_TYPE(0, new FormPreview()) { - @Override - public void switchUI() { - AdaptiveSwitchUtil.switch2OldUI(); - } - - @Override - public void switchUIMode() { - AdaptiveSwitchUtil.switch2OldUIMode(); - } - + OLD_TYPE(0) { @Override public ReportFitAttr obtainFitAttr() { return FormFitConfig.getInstance().getOldFitAttr(); @@ -35,23 +15,9 @@ public enum JFormType { FormFitConfig.getInstance().setOldFitAttr(attr); } - @Override - public BasicBeanPane obtainAttrPane(NewJForm newJForm) { - return new ReportFitAttrPane(); - } }, - NEW_TYPE(1, new FormAdaptivePreview()) { - @Override - public void switchUI() { - AdaptiveSwitchUtil.switch2NewUI(); - } - - @Override - public void switchUIMode() { - AdaptiveSwitchUtil.switch2NewUIMode(); - } - + NEW_TYPE(1) { @Override public ReportFitAttr obtainFitAttr() { return FormFitConfig.getInstance().getNewFitAttr(); @@ -62,80 +28,35 @@ public enum JFormType { FormFitConfig.getInstance().setNewFitAttr(attr); } - @Override - public BasicBeanPane obtainAttrPane(NewJForm newJForm) { - return new FormFitAttrPane(newJForm); - } }; - private int type; - private boolean newType; - private PreviewProvider defaultPreviewType; + private final int type; + private final boolean newType; - JFormType(int type, PreviewProvider defaultPreviewType) { + JFormType(int type) { this.type = type; this.newType = (type == 1); - this.defaultPreviewType = defaultPreviewType; } public int getType() { return type; } - public boolean isNewType() { - return newType; - } - public PreviewProvider getDefaultPreviewType() { - return defaultPreviewType; + public static JFormType parseFormType(int type) { + for (JFormType formType : values()) { + if (formType.getType() == type) { + return formType; + } + } + return JFormType.OLD_TYPE; } - public abstract void switchUI(); - - public abstract void switchUIMode(); + public boolean isNewType() { + return newType; + } public abstract ReportFitAttr obtainFitAttr(); public abstract void updateFitAttr(ReportFitAttr attr); - public abstract BasicBeanPane obtainAttrPane(NewJForm newJForm); - - /** - * @Description: 更新模板的标志位 - * @param jTemplate - * @return: - * @Author: Henry.Wang - * @date: 2020/12/17 16:17 - */ - public void updateJFromTemplateType(JTemplate jTemplate) { - if (jTemplate instanceof NewJForm) { - NewJForm newJForm = (NewJForm) jTemplate; - Form form = newJForm.getTarget(); - NewFormMarkAttr newFormMarkAttr = form.getAttrMark(NewFormMarkAttr.XML_TAG); - if (newFormMarkAttr == null) { - newFormMarkAttr = new NewFormMarkAttr(this.getType()); - form.addAttrMark(newFormMarkAttr); - } - newFormMarkAttr.setType(this.getType()); - newJForm.setJFormType(this); - } - } - - /** - * @Description: 更新预览方式 - * @param jTemplate - * @return: - * @Author: Henry.Wang - * @date: 2020/12/17 16:17 - */ - public void updatePreviewType(JTemplate jTemplate) { - if (jTemplate.getPreviewType() != null) { - PreviewProvider[] previewProviders = jTemplate.supportPreview(); - for (PreviewProvider previewProvider : previewProviders) { - if (previewProvider.getClass() == jTemplate.getPreviewType().getClass()) { - return; - } - } - } - jTemplate.setPreviewType(this.getDefaultPreviewType()); - } } diff --git a/designer-form/src/main/java/com/fr/design/fit/NewJForm.java b/designer-form/src/main/java/com/fr/design/fit/NewJForm.java index 2445b45e51..034834f411 100644 --- a/designer-form/src/main/java/com/fr/design/fit/NewJForm.java +++ b/designer-form/src/main/java/com/fr/design/fit/NewJForm.java @@ -2,19 +2,18 @@ package com.fr.design.fit; import com.fr.base.DynamicUnitList; import com.fr.base.Parameter; -import com.fr.design.actions.TemplateParameterAction; 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.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.mainframe.DesignerUIModeConfig; import com.fr.design.preview.DeveloperPreview; import com.fr.design.preview.FormAdaptivePreview; import com.fr.design.fit.toolbar.SwitchAction; @@ -22,12 +21,12 @@ import com.fr.design.fun.PreviewProvider; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.JForm; import com.fr.design.mainframe.WidgetPropertyPane; -import com.fr.design.menu.ShortCut; 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.stable.ArrayUtils; @@ -61,9 +60,7 @@ public class NewJForm extends JForm { public NewJForm(Form form, FILE file) { super(form, file); - if (DesignerUIModeConfig.getInstance().newUIMode()) { - init(); - } + init(); } public JFormType getJFormType() { @@ -74,22 +71,6 @@ public class NewJForm extends JForm { this.jFormType = jFormType; } - - /** - * 模板菜单 - * - * @return 返回菜单 - */ - @Override - public ShortCut[] shortcut4TemplateMenu() { - if (this.index == FORM_TAB) { - return ArrayUtils.addAll(new ShortCut[]{new TemplateParameterAction(this), new NewFormMobileAttrAction(this), getReportFitAttrAction()}, new ShortCut[0]); - } else { - return ArrayUtils.addAll(new ShortCut[]{new TemplateParameterAction(this), new NewFormMobileAttrAction(this), getReportFitAttrAction()}, this.getElementCaseDesign().shortcut4TemplateMenu()); - } - } - - private void init() { this.getFormDesign().addDesignerEditListener(new DesignerEditListener() { private Rectangle oldRec; @@ -202,6 +183,13 @@ public class NewJForm extends JForm { } }); + + Form form = this.getTarget(); + NewFormMarkAttr newFormMarkAttr = form.getAttrMark(NewFormMarkAttr.XML_TAG); + if (newFormMarkAttr == null) { + newFormMarkAttr = new NewFormMarkAttr(); + } + this.setJFormType(JFormType.parseFormType(newFormMarkAttr.getType())); } @@ -225,16 +213,14 @@ public class NewJForm extends JForm { return new PreviewProvider[]{new FormPreview(), new MobilePreview()}; } - private SwitchAction switchAction; - public UIButton[] createExtraButtons() { UIButton[] extraButtons = super.createExtraButtons(); return addAdaptiveSwitchButton(extraButtons); } private UIButton[] addAdaptiveSwitchButton(UIButton[] extraButtons) { - switchAction = new SwitchAction(); - return ArrayUtils.addAll(extraButtons, new UIButton[]{switchAction.getToolBarButton()}); + SwitchAction switchAction = new SwitchAction(this); + return ArrayUtils.addAll(extraButtons, switchAction.getToolBarButton()); } public boolean isNewJFrom() { diff --git a/designer-form/src/main/java/com/fr/design/fit/common/AdaptiveSwitchUtil.java b/designer-form/src/main/java/com/fr/design/fit/common/AdaptiveSwitchUtil.java index 3d090d8f18..031d698498 100644 --- a/designer-form/src/main/java/com/fr/design/fit/common/AdaptiveSwitchUtil.java +++ b/designer-form/src/main/java/com/fr/design/fit/common/AdaptiveSwitchUtil.java @@ -1,15 +1,14 @@ package com.fr.design.fit.common; import com.fr.design.data.DesignTableDataManager; -import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.fit.NewJForm; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.JForm; import com.fr.design.mainframe.JTemplate; import com.fr.design.preview.FormAdaptivePreview; import com.fr.design.preview.FormPreview; import com.fr.file.FILE; import com.fr.file.MemFILE; +import com.fr.form.fit.NewFormMarkAttr; import com.fr.form.main.Form; import com.fr.form.main.WidgetGather; import com.fr.form.ui.Widget; @@ -33,25 +32,10 @@ public class AdaptiveSwitchUtil { } - public static void switch2NewUI() { - switch2NewUIMode(); - reload(); - } - - public static void switch2NewUIMode() { - DesignerUIModeConfig.getInstance().setNewUIMode(); - } - - public static void switch2OldUI() { - switch2OldUIMode(); - reload(); - } - - public static void switch2OldUIMode() { - DesignerUIModeConfig.getInstance().setOldUIMode(); - } - - public static void reload() { + /** + * 新老表单转换的方法 + */ + public static void switchReload() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -61,15 +45,15 @@ public class AdaptiveSwitchUtil { return; } JTemplate old = TemplateTool.getCurrentEditingTemplate(); - if (!(old instanceof JForm)) { + if (!(old instanceof NewJForm)) { return; } - JTemplate template = createNewJTemplate(old); + JTemplate template = createNewJTemplate((NewJForm) old); if (template != null) { DesignTableDataManager.closeTemplate(old); TemplateTool.resetTabPaneEditingTemplate(template); TemplateTool.activeAndResizeTemplate(template); - setPreviewType(); + setPreviewType(template); } } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage()); @@ -83,14 +67,12 @@ public class AdaptiveSwitchUtil { /** * @Description: 设置预览方式 - * @return: 新创建的模板 * @Author: Henry.Wang * @date: 2020/10/13 14:08 */ - private static void setPreviewType() { - JTemplate jTemplate = TemplateTool.getCurrentEditingTemplate(); + private static void setPreviewType(JTemplate jTemplate) { if (jTemplate != null) { - if (DesignerUIModeConfig.getInstance().newUIMode()) { + if (TemplateTool.isNewJForm(jTemplate)) { jTemplate.setPreviewType(new FormAdaptivePreview()); } else { jTemplate.setPreviewType(new FormPreview()); @@ -99,29 +81,30 @@ public class AdaptiveSwitchUtil { } /** + * @param oldForm 以前的模板 * @Description: 创建模板 - * @param old 以前的模板 * @return: 新创建的模板 * @Author: Henry.Wang * @date: 2020/9/6 14:08 */ - public static JTemplate createNewJTemplate(JTemplate old) { - JTemplate template; - template = createNewJTemplateInternal(old); - if (template instanceof NewJForm) { - NewJForm jForm = ((NewJForm) template); - //如果是从旧的设计模板转化为新的设计模式,并且不是全局配置的模板。则更新新模板的Pc端自适应属性 - if (DesignerUIModeConfig.getInstance().newUIMode() && jForm.getTarget().getReportFitAttr() != null && isSwitchJFromIng()) { - jForm.getTarget().setReportFitAttr(shiftReportFitAttr(old, jForm.getTarget().getReportFitAttr().isFitFont())); - } - processAbsoluteLayoutCompatible(jForm.getTarget()); - TemplateTool.saveForm(jForm); + public static JTemplate createNewJTemplate(NewJForm oldForm) { + NewJForm newJForm = createNewJTemplateInternal(oldForm); + if (newJForm == null) { + return null; + } + //如果是从旧的设计模板转化为新的设计模式,并且不是全局配置的模板。则更新新模板的Pc端自适应属性 + if (newJForm.getTarget().getReportFitAttr() != null && newJForm.isNewJFrom()) { + //修改自适应属性 + newJForm.getTarget().setReportFitAttr(shiftReportFitAttr(oldForm, newJForm.getTarget().getReportFitAttr().isFitFont())); + //修改绝对布局中的缩放属性 + processAbsoluteLayoutCompatible(newJForm.getTarget()); } - return template; + TemplateTool.saveForm(newJForm); + return newJForm; } - private static void processAbsoluteLayoutCompatible(Form form){ + private static void processAbsoluteLayoutCompatible(Form form) { Form.traversalWidget(form.getContainer(), new WidgetGather() { @Override public void dealWith(Widget widget) { @@ -141,22 +124,28 @@ public class AdaptiveSwitchUtil { } - /** - * @Description: 创建模板核心方法 * @param old 以前的方法 + * @Description: 创建模板核心方法 * @return: 新创建的模板 * @Author: Henry.Wang * @date: 2020/9/6 14:09 */ - private static JTemplate createNewJTemplateInternal(JTemplate old) { + private static NewJForm createNewJTemplateInternal(JTemplate old) { FILE file = old.getEditingFILE(); if ((file instanceof MemFILE) || !old.isSaved()) { TemplateTool.saveForm(old); } if (old.getTarget() instanceof Form) { try { - return new NewJForm((Form) (old.getTarget()).clone(), old.getEditingFILE()); + //这边进行数据模型中的标志位切换 + Form form = (Form) old.getTarget().clone(); + NewFormMarkAttr oldFormAttr = form.getAttrMark(NewFormMarkAttr.XML_TAG); + if (oldFormAttr == null) { + oldFormAttr = new NewFormMarkAttr(); + } + form.addAttrMark(oldFormAttr.switchAttr()); + return new NewJForm(form, old.getEditingFILE()); } catch (Exception e) { FineLoggerFactory.getLogger().error(e, e.getMessage()); return null; @@ -167,46 +156,43 @@ public class AdaptiveSwitchUtil { } /** - * @Description: 老模板切换到新模板的属性配置转换( - * 1、绝对布局-适应区域--》双向自适应 - * 2、自适应布局-双向自适应--》双向自适应 - * 3、自适应布局-横向自适应--》横向自适应 - * 4、绝对布局-固定大小--》不自适应 - * ) * @param old * @param fitFont 字体是否自适应 + * @Description: 老模板切换到新模板的属性配置转换( + * 1、绝对布局-适应区域--》双向自适应 + * 2、自适应布局-双向自适应--》双向自适应 + * 3、自适应布局-横向自适应--》横向自适应 + * 4、绝对布局-固定大小--》不自适应 + * ) * @return: * @Author: Henry.Wang * @date: 2020/9/6 14:01 */ - private static ReportFitAttr shiftReportFitAttr(JTemplate old, boolean fitFont) { - if (old instanceof JForm && DesignerUIModeConfig.getInstance().newUIMode()) { - JForm jForm = (JForm) old; - try { - int layoutType = LayoutTool.getFormLayoutType(jForm); - int compState = -1; - //自适应布局 - if (layoutType == 0) { - compState = ((WFitLayout) jForm.getFormDesign().getRootComponent().toData()).getCompState(); - if (compState == WFitLayout.STATE_FULL) { - return new ReportFitAttr(2, fitFont); - } else if (compState == WFitLayout.STATE_ORIGIN) { - return new ReportFitAttr(1, fitFont); - } - } else if (layoutType == 1) {//绝对布局 - Widget widget = ((CRBoundsWidget) jForm.getFormDesign().getRootComponent().toData().getWidget(0)).getWidget(); - if (widget instanceof WAbsoluteLayout) { - compState = ((WAbsoluteLayout) widget).getCompState(); - } - if (compState == WAbsoluteLayout.STATE_FIT) { - return new ReportFitAttr(2, fitFont); - } else if (compState == WAbsoluteLayout.STATE_FIXED) { - return new ReportFitAttr(3, fitFont); - } + private static ReportFitAttr shiftReportFitAttr(NewJForm old, boolean fitFont) { + try { + int layoutType = LayoutTool.getFormLayoutType(old); + int compState = -1; + //自适应布局 + if (layoutType == 0) { + compState = ((WFitLayout) old.getFormDesign().getRootComponent().toData()).getCompState(); + if (compState == WFitLayout.STATE_FULL) { + return new ReportFitAttr(2, fitFont); + } else if (compState == WFitLayout.STATE_ORIGIN) { + return new ReportFitAttr(1, fitFont); + } + } else if (layoutType == 1) {//绝对布局 + Widget widget = ((CRBoundsWidget) old.getFormDesign().getRootComponent().toData().getWidget(0)).getWidget(); + if (widget instanceof WAbsoluteLayout) { + compState = ((WAbsoluteLayout) widget).getCompState(); + } + if (compState == WAbsoluteLayout.STATE_FIT) { + return new ReportFitAttr(2, fitFont); + } else if (compState == WAbsoluteLayout.STATE_FIXED) { + return new ReportFitAttr(3, fitFont); } - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); } return null; } diff --git a/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java b/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java index f763fbf3a4..47512348f4 100644 --- a/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java +++ b/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java @@ -1,13 +1,9 @@ package com.fr.design.fit.common; - 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.JForm; import com.fr.design.mainframe.JTemplate; import com.fr.event.Event; import com.fr.event.Listener; @@ -23,31 +19,20 @@ import java.util.List; * @create: 2020/09/03 14:19 */ public class TemplateTool { - //和转换有关的所有代码都在这个监听器中 - //在判断新老模式时,统一使用FormUIModeConfig.getInstance().newUIMode()进行判断 - private static Listener switchListener = new Listener() { + private static final Listener switchListener = new Listener() { @Override public void on(Event event, JTemplate jTemplate) { - if (!(jTemplate instanceof JForm)) { - JFormType.OLD_TYPE.switchUIMode(); - return; - } - JFormType currentType = JFormType.OLD_TYPE; - if (AdaptiveSwitchUtil.isSwitchJFromIng()) { - currentType = DesignerUIModeConfig.getInstance().newUIMode() ? JFormType.NEW_TYPE : JFormType.OLD_TYPE; - } else if (isNewJForm(jTemplate)) { - currentType = JFormType.NEW_TYPE; - } - //UI转换 - currentType.switchUIMode(); - //标志位转换 - currentType.updateJFromTemplateType(jTemplate); - //预览方式转换 - currentType.updatePreviewType(jTemplate); + jTemplate.setDesignerUIMode(); } }; - private static boolean isNewJForm(JTemplate jTemplate) { + + public static Listener getSwitchListener() { + return switchListener; + } + + + public static boolean isNewJForm(JTemplate jTemplate) { if (jTemplate instanceof NewJForm) { NewJForm newJForm = (NewJForm) jTemplate; if (LightTool.containNewFormFlag(newJForm.getTarget()) || newJForm.getTarget().getTemplateID() == null) { @@ -57,8 +42,8 @@ public class TemplateTool { return false; } - public static Listener getSwitchListener() { - return switchListener; + public static boolean isCurrentEditingNewJForm(){ + return isNewJForm(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()); } /** @@ -69,8 +54,7 @@ public class TemplateTool { * @date: 2020/9/6 14:17 */ public static JTemplate getCurrentEditingTemplate() { - JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - return jTemplate; + return HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); } /** @@ -159,4 +143,6 @@ public class TemplateTool { } + + } diff --git a/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java b/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java index e14d39a68f..5e45e97ace 100644 --- a/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java +++ b/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java @@ -3,7 +3,6 @@ package com.fr.design.fit.toolbar; import com.fr.design.actions.UpdateAction; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.file.TemplateTreePane; -import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.fit.NewJForm; import com.fr.design.fit.common.AdaptiveSwitchUtil; import com.fr.design.fit.common.TemplateTool; @@ -11,6 +10,7 @@ import com.fr.design.gui.ibutton.UIButton; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.BaseJForm; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JForm; import com.fr.design.mainframe.JTemplate; import com.fr.design.menu.MenuKeySet; import com.fr.file.FILE; @@ -64,11 +64,11 @@ public class SwitchAction extends UpdateAction { } }; - public SwitchAction() { - initMenuStyle(); + public SwitchAction(JForm jForm) { + initMenuStyle(jForm); } - private void initMenuStyle() { + private void initMenuStyle(JForm jForm) { this.setMenuKeySet(SWITCH_ATTR); this.setName(getMenuKeySet().getMenuKeySetName()); this.setMnemonic(getMenuKeySet().getMnemonic()); @@ -80,7 +80,7 @@ public class SwitchAction extends UpdateAction { Font oldFont = switchBtn.getFont(); switchBtn.setFont(new Font(oldFont.getName(),oldFont.getStyle(),12)); switchBtn.setForeground(new Color(0x33, 0x33, 0x34)); - freshSwitchButton(); + freshSwitchButton(jForm); } @Override @@ -92,11 +92,7 @@ public class SwitchAction extends UpdateAction { if (confirmSwitchDialog() && backUpOldModeJTemplate()) { AdaptiveSwitchUtil.setSwitchJFromIng(1); showLoadingJPanel(); - if (DesignerUIModeConfig.getInstance().newUIMode()) { - AdaptiveSwitchUtil.switch2OldUI(); - } else { - AdaptiveSwitchUtil.switch2NewUI(); - } + AdaptiveSwitchUtil.switchReload(); } } @@ -175,7 +171,7 @@ public class SwitchAction extends UpdateAction { */ private boolean backUpOldModeJTemplate() { JTemplate jTemplate = TemplateTool.getCurrentEditingTemplate(); - if (jTemplate != null && !DesignerUIModeConfig.getInstance().newUIMode()) { + if (jTemplate != null && !(jTemplate instanceof NewJForm)) { FILE editingFILE = jTemplate.getEditingFILE(); if (editingFILE != null && editingFILE.exists()) { try { @@ -237,7 +233,7 @@ public class SwitchAction extends UpdateAction { * @date: 2020/9/18 11:20 */ private boolean confirmSwitchDialog() { - Object message = DesignerUIModeConfig.getInstance().newUIMode() ? Toolkit.i18nText("Fine-Designer_Fit_Confirm_New_Old_Switch") : Toolkit.i18nText("Fine-Designer_Fit_Confirm_Old_New_Switch"); + Object message = TemplateTool.isCurrentEditingNewJForm() ? Toolkit.i18nText("Fine-Designer_Fit_Confirm_New_Old_Switch") : Toolkit.i18nText("Fine-Designer_Fit_Confirm_Old_New_Switch"); int returnVal = FineJOptionPane.showConfirmDialog( DesignerContext.getDesignerFrame(), message, @@ -269,8 +265,8 @@ public class SwitchAction extends UpdateAction { * @Author: Henry.Wang * @date: 2020/8/31 16:39 */ - public UIButton freshSwitchButton() { - if (DesignerUIModeConfig.getInstance().newUIMode()) { + public UIButton freshSwitchButton(JForm jForm) { + if (TemplateTool.isNewJForm(jForm)) { switchBtn.setToolTipText(Toolkit.i18nText("Fine-Designer_Fit_Switch_To_Old_UI")); switchBtn.setText(Toolkit.i18nText("Fine-Designer_Fit_Switch_To_Old_Version")); } else { @@ -281,7 +277,7 @@ public class SwitchAction extends UpdateAction { } public UIButton getToolBarButton() { - return freshSwitchButton(); + return switchBtn; } } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java index 845c270b73..adc59581ac 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java @@ -43,7 +43,6 @@ import com.fr.design.designer.properties.FormWidgetAuthorityEditPane; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.event.DesignerOpenedListener; import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.form.util.XCreatorConstants; import com.fr.design.fun.RightSelectionHandlerProvider; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; diff --git a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java index d61cd59028..8d2748eb39 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java @@ -1235,4 +1235,8 @@ public class JForm extends JTemplate implements BaseJForm { public RootDesignDefinePane(XCreator xCreator) { super(xCreator); - newForm = TemplateTool.getCurrentEditingNewJForm() != null && DesignerUIModeConfig.getInstance().newUIMode(); + newForm = TemplateTool.getCurrentEditingNewJForm() != null && DesignerUIModeConfig.getInstance().simulateWebUIMode(); this.root = (XWParameterLayout) xCreator; initComponent(); } diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/ElementEditorDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/ElementEditorDefinePane.java index 9507248df3..3eb947488e 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/ElementEditorDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/ElementEditorDefinePane.java @@ -5,7 +5,7 @@ import com.fr.base.theme.TemplateTheme; import com.fr.base.theme.settings.ThemedComponentStyle; import com.fr.design.designer.IntervalConstants; import com.fr.design.designer.creator.*; -import com.fr.design.fit.DesignerUIModeConfig; +import com.fr.design.fit.common.TemplateTool; import com.fr.design.fit.attrpane.PcFitExpandablePane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.style.FollowingThemePane; @@ -76,7 +76,7 @@ public class ElementEditorDefinePane extends WTitleLayoutDefinePane list = new ArrayList(); @@ -102,7 +102,7 @@ public class ElementEditorDefinePane extends WTitleLayoutDefinePane selectedColumns[selectedColumns.length - 1]) { - resetGridSelectionBySelect(selectedCellPoint.getColumn(), ePane); - } - } - - - protected int doChooseFrom() { - return CellSelection.CHOOSE_COLUMN; - } - - @Override - protected Rectangle resetSelectedBoundsByShift(Rectangle editRectangle, ColumnRow selectedCellPoint, ElementCasePane reportPane) { - int tempOldSelectedCellX = editRectangle.x;// editRectangle.x; - - // adjust them to got the correct selected bounds. - if (selectedCellPoint.getColumn() >= editRectangle.x) { - selectedCellPoint = ColumnRow.valueOf(selectedCellPoint.getColumn() + 1, selectedCellPoint.getRow()); - } else { - tempOldSelectedCellX++; - } - - int lastRow = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getRow(); - return new Rectangle(Math.min(tempOldSelectedCellX, selectedCellPoint.getColumn()), 0, Math.max(editRectangle.width, Math.abs(tempOldSelectedCellX - - selectedCellPoint.getColumn())), lastRow); - } - - @Override - protected int[] getGridSelectionIndices(CellSelection cs) { - return cs.getSelectedColumns(); - } - - @Override - protected int getScrollValue(ElementCasePane casePane) { - return casePane.getGrid().getHorizontalValue(); - } - - @Override - protected int getScrollExtent(ElementCasePane casePane) { - return casePane.getGrid().getHorizontalExtent(); - } - - @Override - protected int getBeginValue(ElementCasePane casePane) { - return casePane.getGrid().getHorizontalBeginValue(); - } - - @Override - protected int getColumnOrRowByGridHeader(ColumnRow selectedCellPoint) { - return selectedCellPoint.getColumn(); - } - - - /** - * Checks whether is on zero separator line. - */ - @Override - protected boolean isOnSeparatorLineIncludeZero(MouseEvent evt, double tmpWidth2, double tmpIncreaseWidth) { - return tmpIncreaseWidth <= 1 && (evt.getX() >= tmpWidth2 + 2 && (evt.getX() <= tmpWidth2 + SEPARATOR_GAP)); - } - - @Override - protected boolean between(MouseEvent evt, double from, double to) { - return evt.getX() > from && evt.getX() <= to; - } - - /** - * Checks whether is on normal separator line. - */ - @Override - protected boolean isOnNormalSeparatorLine(MouseEvent evt, double tmpWidth2) { - return (evt.getX() >= tmpWidth2 - 2) && (evt.getX() <= tmpWidth2 + 2); - } - - @Override - protected int evtOffset(MouseEvent evt, int offset) { - return evt.getX() - offset; - } - - @Override - protected DynamicUnitList getSizeList(ElementCase elementCase) { - return ReportHelper.getColumnWidthList(elementCase); - } - - @Override - protected String methodName() { - return "setColumnWidth"; - } - - @Override - protected String getSelectedHeaderTooltip(int selectedColumnCount) { - return selectedColumnCount + "C"; - } - - @Override - protected Point getTipLocationByMouseEvent(MouseEvent evt, GridHeader gHeader, Dimension tipPreferredSize) { - Point convertPoint = new Point(evt.getX(), 0); - SwingUtilities.convertPointToScreen(convertPoint, gHeader); - - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - convertPoint.x = Math.max(0, Math.min(convertPoint.x - tipPreferredSize.width / 2, screenSize.width - tipPreferredSize.width)); - convertPoint.y = convertPoint.y - tipPreferredSize.height - 2; - - return convertPoint; - } - - @Override - protected void resetGridSelectionBySelect(int column, ElementCasePane ePane) { - int lastRow = GridUtils.getAdjustLastColumnRowOfReportPane(ePane).getRow(); - CellSelection cellSelection = new CellSelection(column, 0, 1, lastRow); - cellSelection.setSelectedType(CellSelection.CHOOSE_COLUMN); - ePane.setSelection(cellSelection); - } - - @Override - protected String nameOfMoveCursorGIF() { - return "cursor_hmove"; - } - - @Override - protected String nameOfSelectCursorGIF() { - return "cursor_hselect"; - } - - @Override - protected String nameOfSplitCursorGIF() { - return "cursor_hsplit"; - } - - @Override - protected UIPopupMenu createPopupMenu(ElementCasePane reportPane, - MouseEvent evt, int columnIndex) { - return ElementCasePaneUtil.createColumnPopupMenu(reportPane, evt, columnIndex); - } - - @Override - protected void resetGridSelectionByDrag(CellSelection gridSelection, ElementCasePane reportPane, - int startMultiSelectIndex, int endMultiSelectIndex) { - int lastRow = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getRow(); - gridSelection.setLastRectangleBounds(Math.min(endMultiSelectIndex, startMultiSelectIndex), 0, Math.abs(startMultiSelectIndex - endMultiSelectIndex) + 1, lastRow); - } - - @Override - public void mouseReleased(MouseEvent e) { - super.mouseReleased(e); - int resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); - int dragIndex = getDragIndex(e); - if (Math.abs(e.getX() - getLimit()) < FUZZY_EDGE && dragIndex >= 0) { - UNIT oldValue = this.getEditingElementCase().getColumnWidth(dragIndex); - this.getEditingElementCase().setColumnWidth(dragIndex, FU.valueOfPix(oldValue.toPixI(resolution) + getLimit() - e.getX(), resolution)); - } - this.getElementCasePane().repaint(); - } - -} diff --git a/designer-realize/src/main/java/com/fr/design/fit/grid/GridLimitRowMouseHandler.java b/designer-realize/src/main/java/com/fr/design/fit/grid/GridLimitRowMouseHandler.java deleted file mode 100644 index ac4a70eab1..0000000000 --- a/designer-realize/src/main/java/com/fr/design/fit/grid/GridLimitRowMouseHandler.java +++ /dev/null @@ -1,190 +0,0 @@ -package com.fr.design.fit.grid; - -import com.fr.base.DynamicUnitList; -import com.fr.design.fit.DesignerUIModeConfig; -import com.fr.design.gui.imenu.UIPopupMenu; -import com.fr.design.mainframe.ElementCasePane; -import com.fr.grid.GridHeader; -import com.fr.grid.GridRow; -import com.fr.grid.GridUtils; -import com.fr.grid.selection.CellSelection; -import com.fr.grid.selection.Selection; -import com.fr.report.ReportHelper; -import com.fr.report.elementcase.ElementCase; -import com.fr.stable.ColumnRow; -import com.fr.stable.unit.FU; -import com.fr.stable.unit.UNIT; - -import javax.swing.SwingUtilities; -import java.awt.Dimension; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.MouseEvent; - -/** - * peter:处理对GridRow的Mouse事件. - */ -public class GridLimitRowMouseHandler extends GridHeaderWithBoundMouseHandler { - - public GridLimitRowMouseHandler(GridRow gridRow, int limit) { - super(gridRow, limit); - } - - @Override - protected void resetSelectionByRightButton(ColumnRow selectedCellPoint, Selection cs, ElementCasePane ePane) { - int[] selectedRows = cs.getSelectedRows(); - if (selectedRows.length == 0 - || selectedCellPoint.getRow() < selectedRows[0] - || selectedCellPoint.getRow() > selectedRows[selectedRows.length - 1]) { - resetGridSelectionBySelect(selectedCellPoint.getRow(), ePane); - } - } - - - protected int doChooseFrom() { - return CellSelection.CHOOSE_ROW; - } - - @Override - protected int getScrollValue(ElementCasePane casePane) { - return casePane.getGrid().getVerticalValue(); - } - - @Override - protected int getScrollExtent(ElementCasePane casePane) { - return casePane.getGrid().getVerticalExtent(); - } - - @Override - protected int getBeginValue(ElementCasePane casePane) { - return casePane.getGrid().getVerticalBeginValue(); - } - - @Override - protected Rectangle resetSelectedBoundsByShift(Rectangle editRectangle, ColumnRow selectedCellPoint, ElementCasePane reportPane) { - int tempOldSelectedCellY = editRectangle.y;// editRectangle.x; - - // ajust them to got the correct selected bounds. - if (selectedCellPoint.getRow() >= editRectangle.y) { - selectedCellPoint = ColumnRow.valueOf(selectedCellPoint.getColumn(), selectedCellPoint.getRow() + 1); - } else { - tempOldSelectedCellY++; - } - - int lastColumn = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getColumn(); - return new Rectangle(0, Math.min(tempOldSelectedCellY, selectedCellPoint.getRow()), - lastColumn, Math.max(editRectangle.height, Math.abs(tempOldSelectedCellY - selectedCellPoint.getRow()))); - } - - @Override - protected int[] getGridSelectionIndices(CellSelection cs) { - return cs.getSelectedRows(); - } - - @Override - protected int getColumnOrRowByGridHeader(ColumnRow selectedCellPoint) { - return selectedCellPoint.getRow(); - } - - - @Override - protected void resetGridSelectionBySelect(int row, ElementCasePane ePane) { - int lastColumn = GridUtils.getAdjustLastColumnRowOfReportPane(ePane).getColumn(); - CellSelection cellSelection = new CellSelection(0, row, lastColumn, 1); - cellSelection.setSelectedType(CellSelection.CHOOSE_ROW); - ePane.setSelection(cellSelection); - } - - /** - * Checks whether is on zero separator line. - */ - @Override - protected boolean isOnSeparatorLineIncludeZero(MouseEvent evt, double tmpHeight2, double tmpIncreaseHeight) { - return tmpIncreaseHeight <= 1 && (evt.getY() >= tmpHeight2 + 2 && evt.getY() <= tmpHeight2 + SEPARATOR_GAP); - } - - @Override - protected boolean between(MouseEvent evt, double from, double to) { - return evt.getY() > from && evt.getY() <= to; - } - - @Override - protected DynamicUnitList getSizeList(ElementCase elementCase) { - return ReportHelper.getRowHeightList(elementCase); - } - - @Override - protected String methodName() { - return "setRowHeight"; - } - - /** - * Checks whether is on normal separator line. - */ - @Override - protected boolean isOnNormalSeparatorLine(MouseEvent evt, double tmpHeight2) { - return (evt.getY() >= tmpHeight2 - 2) && (evt.getY() <= tmpHeight2 + 2); - } - - @Override - protected int evtOffset(MouseEvent evt, int offset) { - return evt.getY() - offset; - } - - @Override - protected String getSelectedHeaderTooltip(int rowSelectedCount) { - return rowSelectedCount + "R"; - } - - @Override - protected Point getTipLocationByMouseEvent(MouseEvent evt, GridHeader gHeader, Dimension tipPreferredSize) { - Point convertPoint = new Point(0, evt.getY()); - SwingUtilities.convertPointToScreen(convertPoint, gHeader); - - convertPoint.x = convertPoint.x + gHeader.getSize().width + 2; - convertPoint.y = convertPoint.y - tipPreferredSize.height / 2; - - return convertPoint; - } - - @Override - protected String nameOfMoveCursorGIF() { - return "cursor_vmove"; - } - - @Override - protected String nameOfSelectCursorGIF() { - return "cursor_vselect"; - } - - @Override - protected String nameOfSplitCursorGIF() { - return "cursor_vsplit"; - } - - @Override - protected UIPopupMenu createPopupMenu(ElementCasePane reportPane, - MouseEvent evt, int rowIndex) { - return ElementCasePaneUtil.createRowPopupMenu(reportPane, evt, rowIndex); - } - - @Override - protected void resetGridSelectionByDrag(CellSelection gridSelection, ElementCasePane reportPane, - int startMultiSelectIndex, int endMultiSelectIndex) { - int lastColumn = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getColumn(); - gridSelection.setLastRectangleBounds(0, Math.min(endMultiSelectIndex, startMultiSelectIndex), lastColumn, Math.abs(startMultiSelectIndex - endMultiSelectIndex) + 1); - - } - - @Override - public void mouseReleased(MouseEvent e) { - super.mouseReleased(e); - int resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); - int dragIndex = getDragIndex(e); - if (Math.abs(e.getY() - getLimit()) < FUZZY_EDGE && dragIndex >= 0) { - UNIT oldValue = this.getEditingElementCase().getRowHeight(dragIndex); - this.getEditingElementCase().setRowHeight(dragIndex, FU.valueOfPix(oldValue.toPixI(resolution) + getLimit() - e.getY(), resolution)); - } - this.getElementCasePane().repaint(); - } -} diff --git a/designer-realize/src/main/java/com/fr/design/fit/grid/NewFormDesignerGridUI.java b/designer-realize/src/main/java/com/fr/design/fit/grid/NewFormDesignerGridUI.java deleted file mode 100644 index 9a2601aee2..0000000000 --- a/designer-realize/src/main/java/com/fr/design/fit/grid/NewFormDesignerGridUI.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.fr.design.fit.grid; - -import com.fr.design.designer.creator.XElementCase; -import com.fr.design.fit.AdaptiveCellElementPainter; -import com.fr.design.fit.DesignerUIModeConfig; -import com.fr.design.fit.common.FormDesignerUtil; -import com.fr.design.mainframe.ElementCasePane; -import com.fr.design.mainframe.FormDesigner; -import com.fr.grid.CellElementPainter; -import com.fr.grid.Grid; -import com.fr.grid.GridColumn; -import com.fr.grid.GridRow; -import com.fr.grid.GridUI; -import com.fr.report.elementcase.TemplateElementCase; -import com.fr.report.worksheet.FormElementCase; -import com.fr.stable.Constants; -import com.fr.stable.GraphDrawHelper; - -import javax.swing.JComponent; -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelListener; - - -/** - * Created by kerry on 2020-04-14 - */ -public class NewFormDesignerGridUI extends GridUI { - private GridLimitColumnMouseHandler gridColumnMouseHandler; - private GridLimitRowMouseHandler gridRowMouseHandler; - private AdaptiveGridListener adaptiveGridListener; - private FormDesigner designer; - - public NewFormDesignerGridUI(FormDesigner designer, int resolution) { - super(resolution); - this.designer = designer; - this.setCellElementPainter(new AdaptiveCellElementPainter()); - } - - public void setCellElementPainter(CellElementPainter elementPainter) { - this.painter = elementPainter; - } - - public void paint(Graphics g, JComponent c) { - Graphics2D g2d = (Graphics2D) g; - Grid grid = (Grid) c; - // 取得ElementCasePane.ElementCase - ElementCasePane elementCasePane = grid.getElementCasePane(); - final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); - - super.paint(g, c); - - if (!(elementCase instanceof FormElementCase)) { - return; - } - final Rectangle rectangle = getBoundsLineRect(elementCase, grid); - int width = getScaleWidth(rectangle.width) - columnWidthList.getRangeValue(0, horizontalValue).toPixI(resolution); - int height = getScaleHeight(rectangle.height) - rowHeightList.getRangeValue(0, verticalValue).toPixI(resolution); - drawBoundsLine(g2d, width, height); - addListener(grid, elementCasePane, width, height, rectangle.width, rectangle.height); - } - - private int getScaleWidth(int width) { - return width * resolution / DesignerUIModeConfig.getInstance().getScreenResolution(); - - } - - private int getScaleHeight(int height) { - return height * resolution / DesignerUIModeConfig.getInstance().getScreenResolution(); - } - - - /** - * 获取需要画线的矩形大小 - */ - private Rectangle getBoundsLineRect(TemplateElementCase elementCase, Grid grid) { - final Rectangle rectangle = new Rectangle(); - XElementCase xElementCase = FormDesignerUtil.getXelementCase(designer.getRootComponent(), (FormElementCase) elementCase); - if (xElementCase != null) { - rectangle.setBounds(xElementCase.getBounds()); - - //减去内边距的宽和高 - Insets insets = xElementCase.getInsets(); - rectangle.width -= insets.left + insets.right; - rectangle.height -= insets.top + insets.bottom; - - } - return rectangle; - } - - - private void addListener(Grid grid, ElementCasePane elementCasePane, int width, int height, int actualWidth, int actualHeight) { - addGridColumnListener(elementCasePane.getGridColumn(), width); - addGridRowListener(elementCasePane.getGridRow(), height); - addMouseListener(grid, width, height, actualWidth, actualHeight); - } - - - private void drawBoundsLine(Graphics2D g2d, int width, int height) { - g2d.setPaint(Color.black); - g2d.setStroke(GraphDrawHelper.getStroke(Constants.LINE_DASH_DOT)); - g2d.drawLine(0, height, width, height); - g2d.drawLine(width, 0, width, height); - } - - private void removeGridColumnListener(GridColumn column) { - MouseMotionListener[] mouseMotionListeners = column.getMouseMotionListeners(); - for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { - if (mouseMotionListener instanceof com.fr.grid.GridColumnMouseHandler || mouseMotionListener instanceof GridLimitColumnMouseHandler) { - column.removeMouseMotionListener(mouseMotionListener); - } - } - MouseListener[] mouseListeners = column.getMouseListeners(); - for (MouseListener motionListener : mouseListeners) { - if (motionListener instanceof com.fr.grid.GridColumnMouseHandler || motionListener instanceof GridLimitColumnMouseHandler) { - column.removeMouseListener(motionListener); - } - } - } - - private void removeGridRowListener(GridRow row) { - MouseMotionListener[] mouseMotionListeners = row.getMouseMotionListeners(); - for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { - if (mouseMotionListener instanceof com.fr.grid.GridRowMouseHandler || mouseMotionListener instanceof GridLimitRowMouseHandler) { - row.removeMouseMotionListener(mouseMotionListener); - } - } - MouseListener[] mouseListeners = row.getMouseListeners(); - for (MouseListener motionListener : mouseListeners) { - if (motionListener instanceof com.fr.grid.GridRowMouseHandler || motionListener instanceof GridLimitRowMouseHandler) { - row.removeMouseListener(motionListener); - } - } - } - - private void removeGridListener(Grid grid) { - MouseMotionListener[] mouseMotionListeners = grid.getMouseMotionListeners(); - for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { - if (mouseMotionListener instanceof AdaptiveGridListener) { - grid.removeMouseMotionListener(mouseMotionListener); - break; - } - } - MouseListener[] mouseListeners = grid.getMouseListeners(); - for (MouseListener motionListener : mouseListeners) { - if (motionListener instanceof AdaptiveGridListener) { - grid.removeMouseListener(motionListener); - break; - } - } - MouseWheelListener[] mouseWheelListeners = grid.getMouseWheelListeners(); - for (MouseWheelListener mouseWheelListener : mouseWheelListeners) { - if (mouseWheelListener instanceof AdaptiveGridListener) { - grid.removeMouseWheelListener(mouseWheelListener); - break; - } - } - } - - private void addGridColumnListener(GridColumn column, int width) { - if (gridColumnMouseHandler != null) { - gridColumnMouseHandler.setLimit(width); - return; - } - removeGridColumnListener(column); - gridColumnMouseHandler = new GridLimitColumnMouseHandler(column, width); - column.addMouseListener(gridColumnMouseHandler); - column.addMouseMotionListener(gridColumnMouseHandler); - } - - - private void addGridRowListener(GridRow row, int height) { - if (gridRowMouseHandler != null) { - gridRowMouseHandler.setLimit(height); - return; - } - removeGridRowListener(row); - gridRowMouseHandler = new GridLimitRowMouseHandler(row, height); - row.addMouseMotionListener(gridRowMouseHandler); - row.addMouseListener(gridRowMouseHandler); - } - - - private void addMouseListener(Grid grid, int width, int height, int actualWidth, int actualHeight) { - if (adaptiveGridListener != null) { - adaptiveGridListener.resetBoundInfo(width, height, actualWidth, actualHeight); - return; - } - removeGridListener(grid); - adaptiveGridListener = new AdaptiveGridListener(grid, width, height, actualWidth, actualHeight); - grid.addMouseMotionListener(adaptiveGridListener); - grid.addMouseListener(adaptiveGridListener); - grid.addMouseWheelListener(adaptiveGridListener); - } - -} diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java b/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java index dbc4269d6a..c8c5848b9c 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java @@ -6,7 +6,6 @@ package com.fr.design.mainframe; import com.fr.base.BaseFormula; import com.fr.base.DynamicUnitList; import com.fr.base.Formula; -import com.fr.base.ScreenResolution; import com.fr.base.Style; import com.fr.base.vcs.DesignerMode; import com.fr.design.DesignState; @@ -67,7 +66,6 @@ import com.fr.design.constants.UIConstants; import com.fr.design.designer.EditingState; import com.fr.design.designer.TargetComponent; import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.fun.ElementUIProvider; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.imenu.UIPopupMenu; @@ -157,10 +155,10 @@ public abstract class ElementCasePane extends Tar // alex: private boolean supportDefaultParentCalculate = false; // GUI. - private Grid grid; - private GridRow gridRow; - private GridColumn gridColumn; - private GridCorner gridCorner; + protected Grid grid; + protected GridRow gridRow; + protected GridColumn gridColumn; + protected GridCorner gridCorner; private JScrollBar verScrollBar; private JScrollBar horScrollBar; // Visible @@ -365,7 +363,6 @@ public abstract class ElementCasePane extends Tar } } - public void setResolution(int resolution) { this.resolution = resolution; } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java index 43c66d8c8c..5be6362a4d 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java @@ -13,7 +13,6 @@ import com.fr.design.designer.EditingState; import com.fr.design.designer.TargetComponent; import com.fr.design.event.TargetModifiedEvent; import com.fr.design.event.TargetModifiedListener; -import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.gui.frpane.HyperlinkGroupPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.AuthorityEditPane; diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCasePaneDelegate.java b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCasePaneDelegate.java index 55d11fe7de..750422bc38 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCasePaneDelegate.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCasePaneDelegate.java @@ -6,8 +6,10 @@ import com.fr.design.actions.core.ActionFactory; import com.fr.design.actions.form.FormECBackgroundAction; import com.fr.design.actions.form.FormECColumnsAction; import com.fr.design.actions.form.FormECFrozenAction; +import com.fr.design.designer.creator.XElementCase; import com.fr.design.event.TargetModifiedEvent; import com.fr.design.event.TargetModifiedListener; +import com.fr.design.fit.common.FormDesignerUtil; import com.fr.design.gui.frpane.HyperlinkGroupPane; import com.fr.design.mainframe.*; import com.fr.design.mainframe.cell.QuickEditorRegion; @@ -18,21 +20,27 @@ import com.fr.design.menu.ToolBarDef; import com.fr.design.present.ConditionAttributesGroupPane; import com.fr.form.main.Form; import com.fr.grid.Grid; +import com.fr.grid.GridColumn; +import com.fr.grid.GridCorner; +import com.fr.grid.GridRow; import com.fr.page.ReportSettingsProvider; +import com.fr.report.elementcase.TemplateElementCase; import com.fr.report.worksheet.FormElementCase; import com.fr.design.selection.SelectionEvent; import com.fr.design.selection.SelectionListener; import javax.swing.JComponent; import javax.swing.JPanel; +import java.awt.Insets; +import java.awt.Rectangle; /** */ public class FormElementCasePaneDelegate extends ElementCasePane{ + public FormElementCasePaneDelegate(FormElementCase sheet, Form form) { super(sheet); - this.getGrid().setPaginateLineShowType(form.getFormMobileAttr().isMobileOnly() ? Grid.SINGLE_HORIZONTAL_PAGINATE_LINE : Grid.NO_PAGINATE_LINE); @@ -55,6 +63,42 @@ public class FormElementCasePaneDelegate extends ElementCasePane { - private GridColumnMouseHandler gridColumnMouseHandler; + private GridColumnMouseHandler gridColumnMouseHandler; + private int adsorbWidth; - public GridColumn(int resolution) { - super(resolution); - } + public GridColumn(int resolution) { + this(resolution, 0); + } - @Override - protected void initByConstructor() { - gridColumnMouseHandler = new GridColumnMouseHandler(this); - this.addMouseListener(gridColumnMouseHandler); - this.addMouseMotionListener(gridColumnMouseHandler); - this.updateUI(); - } + public GridColumn(int resolution, int adsorbWidth) { + super(resolution); + this.adsorbWidth = adsorbWidth; + } + @Override + protected void initByConstructor() { + this.updateUI(); + } + @Override + public String getDisplay(int index) { + return StableUtils.convertIntToABC(index + 1); + } - @Override - public String getDisplay(int index) { - return StableUtils.convertIntToABC(index + 1); - } + @Override + public void updateUI() { + this.removeMouseListener(gridColumnMouseHandler); + this.removeMouseMotionListener(gridColumnMouseHandler); + gridColumnMouseHandler = new GridColumnMouseHandler(this, adsorbWidth); + this.addMouseListener(gridColumnMouseHandler); + this.addMouseMotionListener(gridColumnMouseHandler); + this.setUI(new GridColumnUI(resolution)); + } - @Override - public void updateUI() { - this.removeMouseListener(gridColumnMouseHandler); - this.removeMouseMotionListener(gridColumnMouseHandler); - gridColumnMouseHandler = new GridColumnMouseHandler(this); - this.addMouseListener(gridColumnMouseHandler); - this.addMouseMotionListener(gridColumnMouseHandler); - this.setUI(new GridColumnUI(resolution)); - } + /** + * Gets the preferred size. + */ + @Override + public Dimension getPreferredSize() { + ElementCasePane reportPane = this.getElementCasePane(); + float time = (float) reportPane.getResolution() / DesignerUIModeConfig.getInstance().getScreenResolution(); + if (!reportPane.isColumnHeaderVisible()) { + return new Dimension(0, 0); + } - /** - * Gets the preferred size. - */ - @Override - public Dimension getPreferredSize() { - ElementCasePane reportPane = this.getElementCasePane(); - float time = (float)reportPane.getResolution()/ DesignerUIModeConfig.getInstance().getScreenResolution(); - if (!reportPane.isColumnHeaderVisible()) { - return new Dimension(0, 0); - } - - return new Dimension(super.getPreferredSize().width, (int) (GraphHelper.getFontMetrics(this.getFont()).getHeight() * time + SIZE_ADJUST)); - } + return new Dimension(super.getPreferredSize().width, (int) (GraphHelper.getFontMetrics(this.getFont()).getHeight() * time + SIZE_ADJUST)); + } } diff --git a/designer-realize/src/main/java/com/fr/grid/GridColumnMouseHandler.java b/designer-realize/src/main/java/com/fr/grid/GridColumnMouseHandler.java index bc5b54c903..a6b38dc81c 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridColumnMouseHandler.java +++ b/designer-realize/src/main/java/com/fr/grid/GridColumnMouseHandler.java @@ -9,23 +9,34 @@ import java.awt.event.MouseEvent; import javax.swing.SwingUtilities; import com.fr.base.DynamicUnitList; import com.fr.design.gui.imenu.UIPopupMenu; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.mainframe.ElementCasePane; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.Selection; import com.fr.report.ReportHelper; import com.fr.report.elementcase.ElementCase; +import com.fr.report.elementcase.TemplateElementCase; import com.fr.stable.ColumnRow; +import com.fr.stable.unit.FU; +import com.fr.stable.unit.UNIT; /** * peter:处理对GridColumn的Mouse事件. */ public class GridColumnMouseHandler extends AbstractGridHeaderMouseHandler { + private final int adsorbWidth; + public GridColumnMouseHandler(GridColumn gridColumn) { - super(gridColumn); - this.resolution = gridColumn.resolution; + this(gridColumn, 0); } + public GridColumnMouseHandler(GridColumn gridColumn, int adsorbWidth) { + super(gridColumn); + this.adsorbWidth = adsorbWidth; + this.resolution = gridColumn.resolution; + } + public void setResolution(int resolution){ this.resolution = resolution; } @@ -40,6 +51,24 @@ public class GridColumnMouseHandler extends AbstractGridHeaderMouseHandler { } } + @Override + public void mouseReleased(MouseEvent e) { + super.mouseReleased(e); + if (this.adsorbWidth <= 0) { + return; + } + ElementCasePane elementCasePane = this.gHeader.getElementCasePane(); + TemplateElementCase editingElementCase = elementCasePane.getEditingElementCase(); + double adsorbWidthWithResolution = this.adsorbWidth * (resolution * 1D / DesignerUIModeConfig.getInstance().getScreenResolution()); + + int dragIndex = getDragIndex(e); + if (Math.abs(e.getX() - adsorbWidthWithResolution) < FUZZY_EDGE && dragIndex >= 0) { + UNIT oldValue = editingElementCase.getColumnWidth(dragIndex); + editingElementCase.setColumnWidth(dragIndex, oldValue.add(FU.valueOfPix((int) (adsorbWidthWithResolution- e.getX()), resolution))); + } + elementCasePane.repaint(); + } + protected int doChooseFrom() { return CellSelection.CHOOSE_COLUMN; diff --git a/designer-realize/src/main/java/com/fr/grid/GridColumnUI.java b/designer-realize/src/main/java/com/fr/grid/GridColumnUI.java index 088c8f220c..6c401e925b 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridColumnUI.java +++ b/designer-realize/src/main/java/com/fr/grid/GridColumnUI.java @@ -16,7 +16,7 @@ import com.fr.base.ScreenResolution; import com.fr.base.vcs.DesignerMode; import com.fr.cache.list.IntList; import com.fr.design.constants.UIConstants; -import com.fr.design.fit.DesignerUIModeConfig; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.mainframe.ElementCasePane; import com.fr.design.roleAuthority.ReportAndFSManagePane; import com.fr.grid.selection.Selection; diff --git a/designer-realize/src/main/java/com/fr/grid/GridCorner.java b/designer-realize/src/main/java/com/fr/grid/GridCorner.java index 4d1d393b7f..2bbe3d9df0 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridCorner.java +++ b/designer-realize/src/main/java/com/fr/grid/GridCorner.java @@ -4,9 +4,9 @@ package com.fr.grid; import com.fr.base.GraphHelper; -import com.fr.base.ScreenResolution; + import com.fr.design.constants.UIConstants; -import com.fr.design.fit.DesignerUIModeConfig; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.mainframe.ElementCasePane; import javax.swing.event.MouseInputListener; diff --git a/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java b/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java index c2c1861147..45f7748234 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java +++ b/designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java @@ -2,11 +2,10 @@ package com.fr.grid; import com.fr.base.BaseUtils; import com.fr.base.DynamicUnitList; -import com.fr.base.ScreenResolution; import com.fr.base.vcs.DesignerMode; import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.constants.UIConstants; -import com.fr.design.fit.DesignerUIModeConfig; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.EastRegionContainerPane; import com.fr.design.mainframe.ElementCasePane; @@ -78,8 +77,18 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous private int[] resizingBackupBounds = null; - protected GridMouseAdapter(Grid grid) { + private double adsorbWidth = 0D; + + private double adsorbHeight = 0D; + + private JWindow tipWindow = null; + private JToolTip tip = null; + + + protected GridMouseAdapter(Grid grid, double adsorbWidth, double adsorbHeight) { this.grid = grid; + this.adsorbWidth = adsorbWidth; + this.adsorbHeight = adsorbHeight; } /** @@ -330,8 +339,63 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous } lastMouseMoveTime = systemCurrentTime;// 记录最后一次的时间. mouseMoveOnGrid(evt.getX(), evt.getY()); + dealAdsorb(evt); } + private void dealAdsorb(final MouseEvent e) { + if (adsorbWidth <= 0 || adsorbHeight <= 0) { + return; + } + int verticalValue = grid.getVerticalValue(); + int horizontalValue = grid.getHorizontalValue(); + ElementCasePane reportPane = grid.getElementCasePane(); + TemplateElementCase report = reportPane.getEditingElementCase(); + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + double width = adsorbWidth * (resolution * 1.0D / DesignerUIModeConfig.getInstance().getScreenResolution()) + - columnWidthList.getRangeValue(0, horizontalValue).toPixI(this.grid.getResolution()); + double height = adsorbHeight * (resolution * 1.0D / DesignerUIModeConfig.getInstance().getScreenResolution()) + - rowHeightList.getRangeValue(0, verticalValue).toPixI(this.grid.getResolution()); + if (Math.abs(e.getX() - width) < 5 && e.getY() >= 0 && e.getY() < height) { + Point convertPoint = new Point((int) width, 0); + SwingUtilities.convertPointToScreen(convertPoint, grid); + showToolTip(grid, e, adsorbWidth + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Px"), convertPoint); + return; + } else { + hideToolTip(); + } + if (Math.abs(e.getY() - height) < 5 && e.getX() >= 0 && e.getX() < width) { + Point convertPoint = new Point(0, (int) height); + SwingUtilities.convertPointToScreen(convertPoint, grid); + showToolTip(grid, e, adsorbHeight + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Px"), convertPoint); + } else { + hideToolTip(); + } + } + + private void showToolTip(Grid grid, MouseEvent evt, String text, Point tipLocation) { + if (tipWindow == null) { + tipWindow = new JWindow(); + + + tip = grid.createToolTip(); + tip.setBorder(BorderFactory.createEmptyBorder()); + tipWindow.getContentPane().add(tip, BorderLayout.CENTER); + } + tip.setTipText(text); + tip.setForeground(Color.decode("#88ACC6")); + tipWindow.setLocation(tipLocation.x, tipLocation.y); + tipWindow.pack(); + tipWindow.setVisible(true); + } + + private void hideToolTip() { + if (tipWindow != null) { + tipWindow.setVisible(false); + } + } + + /** * @param evt */ @@ -879,7 +943,7 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous * @param e */ public void mouseWheelMoved(MouseWheelEvent e) { - + hideToolTip(); } /** @@ -898,5 +962,6 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous * @param e */ public void mouseExited(MouseEvent e) { + hideToolTip(); } } diff --git a/designer-realize/src/main/java/com/fr/grid/GridRow.java b/designer-realize/src/main/java/com/fr/grid/GridRow.java index a85c3c3989..0ec5fdab2e 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridRow.java +++ b/designer-realize/src/main/java/com/fr/grid/GridRow.java @@ -6,75 +6,74 @@ package com.fr.grid; import java.awt.Dimension; import com.fr.base.GraphHelper; -import com.fr.base.ScreenResolution; -import com.fr.design.ExtraDesignClassManager; -import com.fr.design.fit.DesignerUIModeConfig; -import com.fr.design.fun.GridUIProcessor; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.mainframe.ElementCasePane; -import javax.swing.plaf.ComponentUI; - /** * GridRow used to paint and edit grid row. - * + * * @editor zhou * @since 2012-3-22下午6:12:03 */ public class GridRow extends GridHeader { - private static final int MAX = 4; - private GridRowMouseHandler gridRowMouseHandler; + private static final int MAX = 4; + private int adsorbHeight; + private GridRowMouseHandler gridRowMouseHandler; + + public GridRow(int resolution) { + this(resolution, 0); + } + + public GridRow(int resolution, int adsorbHeight) { + super(resolution); + this.adsorbHeight = adsorbHeight; + } - public GridRow(int resolution) { - super(resolution); - } - @Override - protected void initByConstructor() { - gridRowMouseHandler = new GridRowMouseHandler(this); - this.addMouseListener(gridRowMouseHandler); - this.addMouseMotionListener(gridRowMouseHandler); - this.updateUI(); - } + @Override + protected void initByConstructor() { + this.updateUI(); + } - @Override - public Integer getDisplay(int index) { - return new Integer(index + 1); - } + @Override + public Integer getDisplay(int index) { + return new Integer(index + 1); + } - @Override - public void updateUI() { - this.removeMouseListener(gridRowMouseHandler); - this.removeMouseMotionListener(gridRowMouseHandler); - gridRowMouseHandler = new GridRowMouseHandler(this); - this.addMouseListener(gridRowMouseHandler); - this.addMouseMotionListener(gridRowMouseHandler); - this.setUI(new GridRowUI(resolution)); - } + @Override + public void updateUI() { + this.removeMouseListener(gridRowMouseHandler); + this.removeMouseMotionListener(gridRowMouseHandler); + gridRowMouseHandler = new GridRowMouseHandler(this, adsorbHeight); + this.addMouseListener(gridRowMouseHandler); + this.addMouseMotionListener(gridRowMouseHandler); + this.setUI(new GridRowUI(resolution)); + } - /** - * Gets the preferred size. - */ - @Override - public Dimension getPreferredSize() { - ElementCasePane reportPane = this.getElementCasePane(); - float time = (float)reportPane.getResolution()/ DesignerUIModeConfig.getInstance().getScreenResolution(); - if (!(reportPane.isRowHeaderVisible())) { - return new Dimension(0, 0); - } + /** + * Gets the preferred size. + */ + @Override + public Dimension getPreferredSize() { + ElementCasePane reportPane = this.getElementCasePane(); + float time = (float) reportPane.getResolution() / DesignerUIModeConfig.getInstance().getScreenResolution(); + if (!(reportPane.isRowHeaderVisible())) { + return new Dimension(0, 0); + } - int maxCharNumber = this.caculateMaxCharNumber(reportPane); - return new Dimension((int) (maxCharNumber * GraphHelper.getFontMetrics(this.getFont()).charWidth('M') * time), super.getPreferredSize().height); - } + int maxCharNumber = this.caculateMaxCharNumber(reportPane); + return new Dimension((int) (maxCharNumber * GraphHelper.getFontMetrics(this.getFont()).charWidth('M') * time), super.getPreferredSize().height); + } - /** - * Calculates max char number. - */ - private int caculateMaxCharNumber(ElementCasePane reportPane) { - int maxCharNumber = MAX; - maxCharNumber = Math.max(maxCharNumber, ("" + (reportPane.getGrid().getVerticalValue() + reportPane.getGrid().getVerticalExtent())).length() + 1); + /** + * Calculates max char number. + */ + private int caculateMaxCharNumber(ElementCasePane reportPane) { + int maxCharNumber = MAX; + maxCharNumber = Math.max(maxCharNumber, ("" + (reportPane.getGrid().getVerticalValue() + reportPane.getGrid().getVerticalExtent())).length() + 1); - return maxCharNumber; - } + return maxCharNumber; + } } \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/grid/GridRowMouseHandler.java b/designer-realize/src/main/java/com/fr/grid/GridRowMouseHandler.java index b6e2292471..e828c2a4a3 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridRowMouseHandler.java +++ b/designer-realize/src/main/java/com/fr/grid/GridRowMouseHandler.java @@ -9,20 +9,30 @@ import javax.swing.SwingUtilities; import com.fr.base.DynamicUnitList; import com.fr.design.gui.imenu.UIPopupMenu; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.mainframe.ElementCasePane; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.Selection; import com.fr.report.ReportHelper; import com.fr.report.elementcase.ElementCase; +import com.fr.report.elementcase.TemplateElementCase; import com.fr.stable.ColumnRow; +import com.fr.stable.unit.FU; +import com.fr.stable.unit.UNIT; /** * peter:处理对GridRow的Mouse事件. */ public class GridRowMouseHandler extends AbstractGridHeaderMouseHandler { + private final int adsorbHeight; public GridRowMouseHandler(GridRow gridRow) { + this(gridRow, 0); + } + + public GridRowMouseHandler(GridRow gridRow, int adsorbHeight) { super(gridRow); + this.adsorbHeight = adsorbHeight; } @Override @@ -36,6 +46,23 @@ public class GridRowMouseHandler extends AbstractGridHeaderMouseHandler { } + @Override + public void mouseReleased(MouseEvent e) { + super.mouseReleased(e); + if (this.adsorbHeight <= 0) { + return; + } + ElementCasePane elementCasePane = this.gHeader.getElementCasePane(); + TemplateElementCase editingElementCase = elementCasePane.getEditingElementCase(); + double adsorbHeightWithResolution = this.adsorbHeight * (resolution * 1D / DesignerUIModeConfig.getInstance().getScreenResolution()); + int dragIndex = getDragIndex(e); + if (Math.abs(e.getY() - adsorbHeightWithResolution) < FUZZY_EDGE && dragIndex >= 0) { + UNIT oldValue = editingElementCase.getRowHeight(dragIndex); + editingElementCase.setRowHeight(dragIndex, oldValue.add(FU.valueOfPix((int) (adsorbHeightWithResolution - e.getY()), resolution))); + } + elementCasePane.repaint(); + } + protected int doChooseFrom() { return CellSelection.CHOOSE_ROW; } diff --git a/designer-realize/src/main/java/com/fr/grid/GridRowUI.java b/designer-realize/src/main/java/com/fr/grid/GridRowUI.java index 6c2fed6d0c..19f4d76df5 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridRowUI.java +++ b/designer-realize/src/main/java/com/fr/grid/GridRowUI.java @@ -8,7 +8,7 @@ import javax.swing.JComponent; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; -import com.fr.design.fit.DesignerUIModeConfig; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.stable.AssistUtils; import com.fr.base.BaseUtils; import com.fr.base.DynamicUnitList; diff --git a/designer-realize/src/main/java/com/fr/grid/GridUI.java b/designer-realize/src/main/java/com/fr/grid/GridUI.java index 431c6de1ee..39e52df54d 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridUI.java +++ b/designer-realize/src/main/java/com/fr/grid/GridUI.java @@ -14,6 +14,7 @@ import com.fr.design.base.mode.DesignModeContext; import com.fr.design.constants.UIConstants; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.mainframe.ElementCasePane; import com.fr.design.mainframe.JTemplate; import com.fr.design.roleAuthority.ReportAndFSManagePane; @@ -48,6 +49,7 @@ import com.fr.report.worksheet.WorkSheet; import com.fr.stable.AssistUtils; import com.fr.stable.ColumnRow; import com.fr.stable.Constants; +import com.fr.stable.GraphDrawHelper; import com.fr.stable.script.CalculatorUtils; import com.fr.stable.unit.FU; import com.fr.stable.unit.UNIT; @@ -1191,9 +1193,37 @@ public class GridUI extends ComponentUI { paintWatermark(g2d, ((WorkSheet) elementCase).getBook()); } + //绘制吸附辅助线 + paintAdsorbLines(g2d, grid); + grid.ajustEditorComponentBounds(); // refresh size } + //绘制吸附辅助线 + private void paintAdsorbLines(Graphics2D g2d, Grid grid) { + int verticalValue = grid.getVerticalValue(); + int horizontalValue = grid.getHorizontalValue(); + if (grid.getAdsorbWidth() <= 0 || grid.getAdsorbHeight() <= 0) { + return; + } + int width = (int) (grid.getAdsorbWidth() * (resolution * 1.0D / DesignerUIModeConfig.getInstance().getScreenResolution()) + - columnWidthList.getRangeValue(0, horizontalValue).toPixI(resolution)); + int height = (int) (grid.getAdsorbHeight() * (resolution * 1.0D / DesignerUIModeConfig.getInstance().getScreenResolution()) + - rowHeightList.getRangeValue(0, verticalValue).toPixI(resolution)); + drawBoundsLine(g2d, width, height); + } + + private void drawBoundsLine(Graphics2D g2d, int width, int height) { + Paint oldPaint = g2d.getPaint(); + Stroke oldStroke = g2d.getStroke(); + g2d.setPaint(Color.black); + g2d.setStroke(GraphDrawHelper.getStroke(Constants.LINE_DASH_DOT)); + g2d.drawLine( 0, height, width, height); + g2d.drawLine( width, 0, width, height); + g2d.setPaint(oldPaint); + g2d.setStroke(oldStroke); + } + // 绘制水印 private void paintWatermark(Graphics2D g2d, FineBook book) { WatermarkAttr watermark = ReportUtils.getWatermarkAttrFromTemplateAndGlobal(book); diff --git a/designer-realize/src/main/java/com/fr/grid/GridUtils.java b/designer-realize/src/main/java/com/fr/grid/GridUtils.java index 31ceacd7a0..21b032265f 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridUtils.java +++ b/designer-realize/src/main/java/com/fr/grid/GridUtils.java @@ -5,7 +5,7 @@ import com.fr.base.ScreenResolution; import com.fr.design.cell.clipboard.CellElementsClip; import com.fr.design.cell.clipboard.ElementsTransferable; import com.fr.design.cell.clipboard.FloatElementsClip; -import com.fr.design.fit.DesignerUIModeConfig; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.mainframe.ElementCasePane; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; From 5aa637b87fb210038e02790ef76c5866bac459c1 Mon Sep 17 00:00:00 2001 From: kerry Date: Tue, 14 Dec 2021 16:18:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- designer-form/src/main/java/com/fr/design/fit/NewJForm.java | 2 ++ .../src/main/java/com/fr/design/fit/toolbar/SwitchAction.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/designer-form/src/main/java/com/fr/design/fit/NewJForm.java b/designer-form/src/main/java/com/fr/design/fit/NewJForm.java index 034834f411..9df0806de3 100644 --- a/designer-form/src/main/java/com/fr/design/fit/NewJForm.java +++ b/designer-form/src/main/java/com/fr/design/fit/NewJForm.java @@ -52,6 +52,8 @@ public class NewJForm extends JForm { public NewJForm(Form form) { super(form); init(); + //新建的模板都要加上新表单标志attr + form.addAttrMark(NewFormMarkAttr.createNewFormAttr()); } public NewJForm(Form form, FILE file, Parameter[] parameters) { diff --git a/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java b/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java index 5e45e97ace..bf490a7200 100644 --- a/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java +++ b/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java @@ -171,7 +171,7 @@ public class SwitchAction extends UpdateAction { */ private boolean backUpOldModeJTemplate() { JTemplate jTemplate = TemplateTool.getCurrentEditingTemplate(); - if (jTemplate != null && !(jTemplate instanceof NewJForm)) { + if (jTemplate != null && !TemplateTool.isNewJForm(jTemplate)) { FILE editingFILE = jTemplate.getEditingFILE(); if (editingFILE != null && editingFILE.exists()) { try {