From 6bad68469e767148c6eccc34aa250b91e3d688b6 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Thu, 23 Mar 2017 15:49:44 +0800 Subject: [PATCH] =?UTF-8?q?FRM=E7=BB=84=E4=BB=B6=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=96=87=E4=BB=B6=E9=97=B4=E7=9B=B8=E4=BA=92=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=EF=BC=8C=E9=81=97=E7=95=99=EF=BC=9A=E8=87=AA=E9=80=82?= =?UTF-8?q?=E5=BA=94to=E7=BB=9D=E5=AF=B9=E4=BC=9A=E5=9B=A0=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E8=B6=85=E5=87=BA=E8=80=8C=E4=B8=8D=E8=83=BD=E5=A4=8D?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/beans/models/SelectionModel.java | 56 ++++++++++++++----- .../design/mainframe/FormSelectionUtils.java | 28 +++++++++- 2 files changed, 69 insertions(+), 15 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 75bacfff5..9bde1f4ed 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 @@ -113,12 +113,22 @@ public class SelectionModel { XLayoutContainer parent = null; if (!hasSelectionComponent()) { if (designer.getClass().equals(FormDesigner.class)) { - //编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层 - //当前选择的就是编辑器表层 - FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), - CLIP_BOARD, - DELTA_X_Y, - DELTA_X_Y); + + if (selection.getSelectedCreator() instanceof XWFitLayout) { + //相对布局 + FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), + CLIP_BOARD, + DELTA_X_Y, + DELTA_X_Y); + } else { + //绝对布局 + //编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层 + //当前选择的就是编辑器表层 + FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), + CLIP_BOARD, + DELTA_X_Y, + DELTA_X_Y); + } } else { //cpt本地组件复用,编辑器就一层,是最底层,使用designer.getRootComponent()就可以获取到 //使用selection.getSelectedCreator()也应该是可以获取到的。 @@ -130,9 +140,19 @@ public class SelectionModel { } else { //获取到编辑器的表层容器(已选的组件的父容器就是表层容器) parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); - if (parent != null) { - Rectangle rec = selection.getSelctionBounds(); - FormSelectionUtils.paste2Container(designer, parent, CLIP_BOARD, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); + if (selection.getSelectedCreator().getParent() instanceof XWFitLayout) { + //相对布局 + if (parent != null) { + Rectangle rec = selection.getSelctionBounds(); + FormSelectionUtils.paste2Container(designer, parent, CLIP_BOARD, rec.x + rec.width / 2, rec.y + + rec.height - 2); + } + } else if (selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { + //绝对布局 + if (parent != null) { + Rectangle rec = selection.getSelctionBounds(); + FormSelectionUtils.paste2Container(designer, parent, CLIP_BOARD, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); + } } } } else { @@ -235,11 +255,21 @@ public class SelectionModel { */ public boolean hasSelectionComponent() { if (designer.getClass().equals(FormDesigner.class)) { - //frm组件复用选择 - return selection.getSelectedCreator() != null && !(selection.getSelectedCreator().getParent() instanceof - XWFitLayout); + //frm本地组件复用 + if (selection.getSelectedCreator() == null) { + return false; + } else if (selection.getSelectedCreator().getParent() instanceof XWFitLayout) { + // 相对布局 + // 已选:selection.getSelectedCreator().getParent() instanceof @XWFitLayout + // 未选:selection.getSelectedCreator() instanceof @XWFitLayout + return !(selection.getSelectedCreator() instanceof XWAbsoluteLayout); + } else { + //绝对布局 + //已选:selection.getSelectedCreator().getParent() instanceof @XWAbsoluteLayout + return selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout; + } } else { - //cpt本地组件复用 + //cpt本地组件复用,selection.getSelectedCreator().getParent()=@XWParameterLayout instanceof @XWAbsoluteLayout return selection.getSelectedCreator() != null && selection.getSelectedCreator().getParent() != null; } } diff --git a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java index 8816e1c8b..d1c088d40 100644 --- a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java +++ b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java @@ -34,10 +34,11 @@ public class FormSelectionUtils { * @param x x * @param y y */ - public static void paste2Container(FormDesigner designer, XLayoutContainer parent, FormSelection clipBoard, int x, - int y) { + public static void paste2Container(FormDesigner designer, XLayoutContainer parent, + FormSelection clipBoard, int x, int y) { LayoutAdapter adapter = parent.getLayoutAdapter(); if (parent instanceof XWAbsoluteLayout) { + //绝对布局 designer.getSelectionModel().getSelection().reset(); Rectangle rec = clipBoard.getSelctionBounds(); for (XCreator creator : clipBoard.getSelectedCreators()) { @@ -63,6 +64,29 @@ public class FormSelectionUtils { designer.getEditListenerTable().fireCreatorModified( designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); return; + } else if (parent instanceof XWFitLayout) { + //相对布局 + designer.getSelectionModel().getSelection().reset(); + Rectangle rec = clipBoard.getSelctionBounds(); + for (XCreator creator : clipBoard.getSelectedCreators()) { + try { + Widget copied = copyWidget(designer, creator); + XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); + // TODO 获取位置 + boolean addSuccess = adapter.addBean(copiedCreator, x, y); + + if (addSuccess) { + designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); + } + + } catch (CloneNotSupportedException e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + rebuildSelection(designer); + designer.getEditListenerTable().fireCreatorModified( + designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); + return; } Toolkit.getDefaultToolkit().beep(); }