From e537b799f3951a7dd55517c75ff9362ca345254f Mon Sep 17 00:00:00 2001 From: zhouping Date: Wed, 9 Nov 2016 15:11:03 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-750=20=E8=A1=A8=E5=8D=95=E5=85=B1?= =?UTF-8?q?=E5=88=9B=E5=86=85=E6=B5=8B=E9=97=AE=E9=A2=98=20bugfix4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../layout/FRAbsoluteLayoutAdapter.java | 10 +- ...bsoluteBodyLayoutPropertiesGroupModel.java | 94 +++++++++++-------- .../FRFitLayoutPropertiesGroupModel.java | 53 ++++++----- 3 files changed, 89 insertions(+), 68 deletions(-) diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java index c49ecf0f3..3ab61eb38 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java @@ -308,19 +308,23 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { * @param y 坐标y */ public void fix(XCreator creator ,int x, int y) { + int height = creator.getHeight(); + int width = creator.getWidth(); if (x < 0) { + width += x; x = 0; } else if (x + creator.getWidth() > container.getWidth()) { - x = container.getWidth() - creator.getWidth(); + width = container.getWidth() - x; } if (y < 0) { + height += y; y = 0; } else if (y + creator.getHeight() > container.getHeight()) { - y = container.getHeight() - creator.getHeight(); + height = container.getHeight() - y; } - creator.setLocation(x, y); + creator.setBounds(x, y, width, height); } @Override diff --git a/designer_form/src/com/fr/design/designer/properties/FRAbsoluteBodyLayoutPropertiesGroupModel.java b/designer_form/src/com/fr/design/designer/properties/FRAbsoluteBodyLayoutPropertiesGroupModel.java index 6b29a172e..b290bcccf 100644 --- a/designer_form/src/com/fr/design/designer/properties/FRAbsoluteBodyLayoutPropertiesGroupModel.java +++ b/designer_form/src/com/fr/design/designer/properties/FRAbsoluteBodyLayoutPropertiesGroupModel.java @@ -9,6 +9,7 @@ import com.fr.design.mainframe.widget.editors.LayoutTypeEditor; import com.fr.design.utils.gui.LayoutUtils; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WBodyLayoutType; +import com.fr.general.FRLogger; import com.fr.general.FRScreen; import com.fr.general.Inter; @@ -92,46 +93,7 @@ public class FRAbsoluteBodyLayoutPropertiesGroupModel extends FRAbsoluteLayoutPr } else { if (row == 0) { if (state == WBodyLayoutType.FIT.getTypeValue()) { - XWFitLayout xfl = (XWFitLayout) xwAbsoluteLayout.getBackupParent(); - //备份一下组件间隔 - int compInterval = xfl.toData().getCompInterval(); - Component[] components = xwAbsoluteLayout.getComponents(); - - Arrays.sort(components, new ComparatorComponentLocation()); - - xfl.getLayoutAdapter().removeBean(xwAbsoluteLayout, xwAbsoluteLayout.getWidth(), xwAbsoluteLayout.getHeight()); - xfl.remove(xwAbsoluteLayout); - - for (Component comp : components) { - XCreator xCreator = (XCreator)comp; - if (xCreator.shouldScaleCreator()){ - XLayoutContainer parentPanel = xCreator.initCreatorWrapper(xCreator.getHeight()); - xfl.add(parentPanel, xCreator.toData().getWidgetName()); - parentPanel.updateChildBound(xfl.getActualMinHeight()); - continue; - } - xfl.add(xCreator); - } - //这边计算的时候会先把组件间隔去掉 - moveComponents2FitLayout(xfl); - FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); - formDesigner.getSelectionModel().setSelectedCreator(xfl); - - for (int i = 0; i < components.length; i++) { - Component comp = xfl.getComponent(i); - XCreator creator = (XCreator) comp; - creator.setBackupBound(components[i].getBounds()); - } - - //把组件间隔加上 - if (xfl.toData().getCompInterval() != compInterval) { - xfl.moveContainerMargin(); - xfl.moveCompInterval(xfl.getAcualInterval()); - xfl.toData().setCompInterval(compInterval); - xfl.addCompInterval(xfl.getAcualInterval()); - } - xfl.toData().setLayoutType(WBodyLayoutType.FIT); - return true; + return switch2FitBodyLayout(); } } if (row == 1) { @@ -166,7 +128,57 @@ public class FRAbsoluteBodyLayoutPropertiesGroupModel extends FRAbsoluteLayoutPr return true; } - //把绝对布局中的元素按规则移动到自适应布局中 + private boolean switch2FitBodyLayout() { + try { + XWFitLayout xfl = (XWFitLayout) xwAbsoluteLayout.getBackupParent(); + //备份一下组件间隔 + int compInterval = xfl.toData().getCompInterval(); + Component[] components = xwAbsoluteLayout.getComponents(); + + Arrays.sort(components, new ComparatorComponentLocation()); + + xfl.getLayoutAdapter().removeBean(xwAbsoluteLayout, xwAbsoluteLayout.getWidth(), xwAbsoluteLayout.getHeight()); + xfl.remove(xwAbsoluteLayout); + + for (Component comp : components) { + XCreator xCreator = (XCreator) comp; + if (xCreator.shouldScaleCreator()) { + XLayoutContainer parentPanel = xCreator.initCreatorWrapper(xCreator.getHeight()); + xfl.add(parentPanel, xCreator.toData().getWidgetName()); + parentPanel.updateChildBound(xfl.getActualMinHeight()); + continue; + } + xfl.add(xCreator); + } + //这边计算的时候会先把组件间隔去掉 + moveComponents2FitLayout(xfl); + FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); + formDesigner.getSelectionModel().setSelectedCreator(xfl); + + for (int i = 0; i < components.length; i++) { + Component comp = xfl.getComponent(i); + XCreator creator = (XCreator) comp; + creator.setBackupBound(components[i].getBounds()); + } + + //把组件间隔加上 + if (xfl.toData().getCompInterval() != compInterval) { + xfl.moveContainerMargin(); + xfl.moveCompInterval(xfl.getAcualInterval()); + xfl.toData().setCompInterval(compInterval); + xfl.addCompInterval(xfl.getAcualInterval()); + } + xfl.toData().setLayoutType(WBodyLayoutType.FIT); + return true; + } + catch (Exception e){ + FRLogger.getLogger().error(e.getMessage()); + return false; + } + } + + // 把绝对布局中的元素按规则移动到自适应布局中 + // 规则:各元素按顺序放置,其中每行最多4个元素,超出则换行,各元素均分body的高度和宽度 private void moveComponents2FitLayout(XWFitLayout xwFitLayout) { int eachRowCount = 4; Component[] components = xwFitLayout.getComponents(); diff --git a/designer_form/src/com/fr/design/designer/properties/FRFitLayoutPropertiesGroupModel.java b/designer_form/src/com/fr/design/designer/properties/FRFitLayoutPropertiesGroupModel.java index c9654e26d..9ffad4533 100644 --- a/designer_form/src/com/fr/design/designer/properties/FRFitLayoutPropertiesGroupModel.java +++ b/designer_form/src/com/fr/design/designer/properties/FRFitLayoutPropertiesGroupModel.java @@ -17,6 +17,7 @@ import com.fr.form.ui.container.WAbsoluteBodyLayout; import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WBodyLayoutType; import com.fr.form.ui.container.WFitLayout; +import com.fr.general.FRLogger; import com.fr.general.Inter; import javax.swing.table.DefaultTableCellRenderer; @@ -145,34 +146,38 @@ public class FRFitLayoutPropertiesGroupModel implements GroupModel { layout.setCompState(state); return true; }else if (row == 0) { - layout.setLayoutType(WBodyLayoutType.parse(state)); - if (state == WBodyLayoutType.ABSOLUTE.getTypeValue()) { - WAbsoluteBodyLayout wAbsoluteBodyLayout = new WAbsoluteBodyLayout("body"); - wAbsoluteBodyLayout.setCompState(WAbsoluteLayout.STATE_FIXED); - Component[] components = xfl.getComponents(); - xfl.removeAll(); - XWAbsoluteBodyLayout xwAbsoluteBodyLayout = new XWAbsoluteBodyLayout(wAbsoluteBodyLayout, new Dimension(0,0)); - xfl.getLayoutAdapter().addBean(xwAbsoluteBodyLayout, 0, 0); - for (Component component : components) { - XCreator xCreator = (XCreator)component; - //部分控件被ScaleLayout包裹着,绝对布局里面要放出来 - if (xCreator.acceptType(XWScaleLayout.class)){ - if (xCreator.getComponentCount() > 0 && ((XCreator)xCreator.getComponent(0)).shouldScaleCreator()) { - component = xCreator.getComponent(0); - component.setBounds(xCreator.getBounds()); + try { + if (state == WBodyLayoutType.ABSOLUTE.getTypeValue()) { + WAbsoluteBodyLayout wAbsoluteBodyLayout = new WAbsoluteBodyLayout("body"); + wAbsoluteBodyLayout.setCompState(WAbsoluteLayout.STATE_FIXED); + Component[] components = xfl.getComponents(); + xfl.removeAll(); + XWAbsoluteBodyLayout xwAbsoluteBodyLayout = new XWAbsoluteBodyLayout(wAbsoluteBodyLayout, new Dimension(0, 0)); + xfl.getLayoutAdapter().addBean(xwAbsoluteBodyLayout, 0, 0); + for (Component component : components) { + XCreator xCreator = (XCreator) component; + //部分控件被ScaleLayout包裹着,绝对布局里面要放出来 + if (xCreator.acceptType(XWScaleLayout.class)) { + if (xCreator.getComponentCount() > 0 && ((XCreator) xCreator.getComponent(0)).shouldScaleCreator()) { + component = xCreator.getComponent(0); + component.setBounds(xCreator.getBounds()); + } } + xwAbsoluteBodyLayout.add(component); } - xwAbsoluteBodyLayout.add(component); + FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); + formDesigner.getSelectionModel().setSelectedCreators( + FormSelectionUtils.rebuildSelection(xfl, new Widget[]{wAbsoluteBodyLayout})); + } else { + FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); + formDesigner.getSelectionModel().setSelectedCreators( + FormSelectionUtils.rebuildSelection(xfl, new Widget[]{xfl.toData()})); } - FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); - formDesigner.getSelectionModel().setSelectedCreators( - FormSelectionUtils.rebuildSelection(xfl, new Widget[]{wAbsoluteBodyLayout})); - } - else { - FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); - formDesigner.getSelectionModel().setSelectedCreators( - FormSelectionUtils.rebuildSelection(xfl, new Widget[]{xfl.toData()})); + }catch (Exception e){ + FRLogger.getLogger().error(e.getMessage()); + return false; } + layout.setLayoutType(WBodyLayoutType.parse(state)); return true; } return false;