From 40dbc0272fff3a95ab65a9510735590320e13ab6 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Mon, 10 Apr 2017 17:44:13 +0800 Subject: [PATCH] =?UTF-8?q?report-1945frm=E6=9C=AC=E5=9C=B0=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=A4=8D=E7=94=A8=EF=BC=9A1=E3=80=81=E8=87=AA?= =?UTF-8?q?=E9=80=82=E5=BA=94=E6=88=96=E8=80=85tab=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=B8=8D=E9=80=89=E4=B8=AD=E7=B2=98=E8=B4=B4?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=BA=E4=B8=8A=E4=B8=8B=E5=B9=B3=E5=88=86?= =?UTF-8?q?=E5=B7=A6=E4=B8=8A=E8=A7=92=E7=9A=84=E7=BB=84=E4=BB=B6=EF=BC=9B?= =?UTF-8?q?2=E3=80=81tab=E5=B8=83=E5=B1=80=EF=BC=88=E6=9C=89=E6=97=A0?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=9D=A2=E6=9D=BF=EF=BC=89=E7=B2=98=E8=B4=B4?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/beans/models/SelectionModel.java | 48 ++++++++++++------- .../design/mainframe/FormSelectionUtils.java | 20 ++++++-- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java b/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java index a70d9b156..8ef0033ea 100644 --- a/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java +++ b/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java @@ -15,6 +15,8 @@ import com.fr.design.mainframe.FormSelection; import com.fr.design.mainframe.FormSelectionUtils; import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.gui.LayoutUtils; +import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; +import com.fr.form.ui.container.cardlayout.WTabFitLayout; import com.fr.stable.ArrayUtils; import java.awt.*; @@ -27,7 +29,7 @@ import java.util.ArrayList; public class SelectionModel { //被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。 private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离 - private static final double OFFSET_RELATIVE = 0.80; + private static final double OFFSET_RELATIVE = 0.78; private static FormSelection clipboard = new FormSelection(); private FormDesigner designer; private FormSelection selection; @@ -136,19 +138,20 @@ public class SelectionModel { if (designer.getClass().equals(FormDesigner.class)) { if (selection.getSelectedCreator() instanceof XWFitLayout) { if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) { - Rectangle rec = selection.getRelativeBounds(); - //Tab布局 - FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), - clipboard, - rec.x + rec.width / 2, - rec.y + DELTA_X_Y); + XLayoutContainer container = (XLayoutContainer) selection.getSelectedCreator(); + //tab布局编辑器内部左上角第一个坐标点 + int leftUpX = container.toData().getMargin().getLeft() + 1; + int leftUpY = container.toData().getMargin().getTop() + 1; + //选中第一个坐标点坐在的组件 + selection.setSelectedCreator((XCreator) container.getComponentAt(leftUpX, leftUpY)); + pasteFromClipBoard(); } else { - Rectangle rec = selection.getRelativeBounds(); - //自适应布局 - FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), - clipboard, - rec.x + rec.width / 2, - rec.y + DELTA_X_Y); + //自适应布局编辑器内部左上角第一个坐标点 + int leftUpX = designer.getRootComponent().toData().getMargin().getLeft() + 1; + int leftUpY = designer.getRootComponent().toData().getMargin().getTop() + 1; + //选中第一个坐标点坐在的组件 + selection.setSelectedCreator((XCreator) designer.getRootComponent().getComponentAt(leftUpX, leftUpY)); + pasteFromClipBoard(); } } else { //绝对布局 @@ -178,12 +181,23 @@ public class SelectionModel { container = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); if (container != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) { //自适应布局 + Rectangle selectionRec = selection.getRelativeBounds(); + //获取父容器位置,补充因参数面板高度导致的位置坐标计算偏移 Rectangle containerRec = ComponentUtils.getRelativeBounds(container); - //计算自适应布局位置 - int positionX = selectionRec.x - containerRec.x + selectionRec.width / 2; - int positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE); - + int positionX, positionY; + + if (container.getClass().equals(XWTabFitLayout.class)) { + //tab内部粘贴不补充高度偏移 + //且不计算参数面板造成的影响,因为在 + //@see com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter#addBean中做了 + positionX = selectionRec.x + selectionRec.width / 2; + positionY = (int) (selectionRec.y + selectionRec.height * OFFSET_RELATIVE); + } else { + //计算自适应布局位置 + positionX = selectionRec.x - containerRec.x + selectionRec.width / 2; + positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE); + } FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY); } else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { //绝对布局 diff --git a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java index 79f52519e..1978e8432 100644 --- a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java +++ b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java @@ -3,8 +3,10 @@ package com.fr.design.mainframe; import com.fr.base.FRContext; import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter; +import com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter; import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.creator.*; +import com.fr.design.utils.ComponentUtils; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WTitleLayout; import com.fr.general.ComparatorUtils; @@ -83,14 +85,26 @@ public class FormSelectionUtils { * 相对布局粘贴 */ private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { + + //@see FRTabFitLayoutAdapter + Rectangle tabContainerRect = ComponentUtils.getRelativeBounds(designer.getSelectionModel().getSelection() + .getSelectedCreator().getParent()); + designer.getSelectionModel().getSelection().reset(); for (XCreator creator : clipboard.getSelectedCreators()) { try { Widget copied = copyWidget(designer, creator); XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); - if (!adapter.accept(copiedCreator, x, y)) { - designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste")); - return; + if (adapter.getClass().equals(FRTabFitLayoutAdapter.class)) { + if (!adapter.accept(copiedCreator, x - tabContainerRect.x, y - tabContainerRect.y)) { + designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste")); + return; + } + } else { + if (!adapter.accept(copiedCreator, x, y)) { + designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste")); + return; + } } boolean addSuccess = adapter.addBean(copiedCreator, x, y); if (addSuccess) {