From 31e9e165bbfb54048f0975f212bc2837d1bea76f Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Tue, 28 Mar 2017 11:46:33 +0800 Subject: [PATCH] =?UTF-8?q?tab=20=E6=96=87=E4=BB=B6=E9=97=B4=E5=A4=8D?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapters/layout/FRFitLayoutAdapter.java | 23 ++++---- .../layout/FRTabFitLayoutAdapter.java | 2 +- .../designer/beans/models/SelectionModel.java | 59 ++++++++++++------- 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java index f578b28ab..417e95c35 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java @@ -52,6 +52,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { public void setEdit(boolean edit) { isEdit = edit; } + /** * 构造函数 * @@ -277,7 +278,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { super.clearCompsList(); } - protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout){ + protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) { return mainLayout.getBounds(); } @@ -353,13 +354,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { * 拖拽控件边框后,根据控件的大小尺寸,进行相关组件的调整 * * @param backupBound 边界备份 - * @param bounds 组件边界 - * @param xCreator 组件 - * @param row 选中的行 - * @param difference 偏移量 + * @param bounds 组件边界 + * @param xCreator 组件 + * @param row 选中的行 + * @param difference 偏移量 */ public void calculateBounds(Rectangle backupBound, Rectangle bounds, XCreator xCreator, int row, int difference) { - Rectangle rc = new Rectangle(0,0,0,0); + Rectangle rc = new Rectangle(0, 0, 0, 0); XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(xCreator); if (parent != null) { Rectangle rec = ComponentUtils.getRelativeBounds(parent); @@ -370,17 +371,17 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { //处理左右延伸 switch (row) { case 0: - if (backupBound.width + backupBound.x == container.getWidth() - margin.getRight() +rc.x) { + if (backupBound.width + backupBound.x == container.getWidth() - margin.getRight() + rc.x) { x += difference; } break; case 1: - if(backupBound.y + backupBound.height == container.getHeight() - margin.getBottom() +rc.y){ + if (backupBound.y + backupBound.height == container.getHeight() - margin.getBottom() + rc.y) { y += difference; } break; } - bounds.setLocation(x,y); + bounds.setLocation(x, y); xCreator.setBackupBound(backupBound); xCreator.setBounds(bounds); this.fix(xCreator); @@ -424,7 +425,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { // 根据需要依附的位置调整拖拽的坐标值 private int adjustCoordinateByDependingLine(int coordinate, int[] coordinates) { - if(!isEdit) { + if (!isEdit) { for (int i = 0; i < coordinates.length; i++) { if (coordinate == coordinates[i]) { continue; @@ -440,7 +441,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { // 根据需要依附的位置调整拖拽的距离 private int adjustDiffByDependingLine(int coordinate, int[] coordinates, int diff) { - if(!isEdit) { + if (!isEdit) { for (int i = 0; i < coordinates.length; i++) { if (coordinate + diff > coordinates[i] - DEPENDING_SCOPE && coordinate + diff < coordinates[i] + DEPENDING_SCOPE) { diff = coordinates[i] - coordinate; diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java index 63a70e1bb..c2093f1ce 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java @@ -69,7 +69,7 @@ public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter { if (!accept(creator, posX, posY)) { return false; } - // posX,posY是新拖入组件相对于容器的位置,若在tab布局的边缘,则需要把新组件添加到 + // posX,posY是新拖入组件相对于容器的位置,若在tab布局的边缘,则需要把新组件添加到l // 父层自适应布局中,这时候的添加位置就是tab布局所在的位置 if (this.intersectsEdge(posX, posY, backUpContainer)) { if (!ComparatorUtils.equals(backUpContainer.getOuterLayout(), backUpContainer.getBackupParent())) { 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 9bde1f4ed..697cb0b43 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 @@ -12,11 +12,15 @@ import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.location.Direction; import com.fr.design.designer.beans.location.Location; import com.fr.design.designer.creator.*; +import com.fr.design.designer.creator.cardlayout.XWCardLayout; +import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; +import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.form.util.XCreatorConstants; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormSelection; import com.fr.design.mainframe.FormSelectionUtils; import com.fr.design.utils.gui.LayoutUtils; +import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.stable.ArrayUtils; /** @@ -25,6 +29,7 @@ import com.fr.stable.ArrayUtils; public class SelectionModel { //被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。 private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离 + private static final int BORDER_PROPORTION = 10; private static FormSelection CLIP_BOARD = new FormSelection(); private FormDesigner designer; private FormSelection selection; @@ -111,15 +116,26 @@ public class SelectionModel { public boolean pasteFromClipBoard() { if (!CLIP_BOARD.isEmpty()) { XLayoutContainer parent = null; + //未选 if (!hasSelectionComponent()) { if (designer.getClass().equals(FormDesigner.class)) { - if (selection.getSelectedCreator() instanceof XWFitLayout) { - //相对布局 - FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), - CLIP_BOARD, - DELTA_X_Y, - DELTA_X_Y); + if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) { + Rectangle rec = selection.getRelativeBounds(); + //Tab布局 + System.out.println("ADD: " + (rec.x + rec.width / 2) + "\t" + (rec.y + BORDER_PROPORTION)); + FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), + CLIP_BOARD, + rec.x + rec.width / 2, + rec.y + BORDER_PROPORTION); + } else { + Rectangle rec = selection.getRelativeBounds(); + //自适应布局 + FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), + CLIP_BOARD, + rec.x + rec.width / 2, + rec.y + BORDER_PROPORTION); + } } else { //绝对布局 //编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层 @@ -137,15 +153,17 @@ public class SelectionModel { DELTA_X_Y, DELTA_X_Y); } - } else { + } + //已选 + else { //获取到编辑器的表层容器(已选的组件的父容器就是表层容器) parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); 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); + rec.height - BORDER_PROPORTION); } } else if (selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { //绝对布局 @@ -256,18 +274,17 @@ public class SelectionModel { public boolean hasSelectionComponent() { if (designer.getClass().equals(FormDesigner.class)) { //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; - } + return selection.getSelectedCreator() != null + && !( + //frm绝对布局编辑器 + selection.getSelectedCreator().getClass().equals(XWAbsoluteBodyLayout.class) + //Tab布局编辑器 + || selection.getSelectedCreator().getClass().equals(XWCardMainBorderLayout.class) + || selection.getSelectedCreator().getClass().equals(XWCardLayout.class) + || selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class) + //自适应布局编辑器 + || selection.getSelectedCreator().getClass().equals(XWFitLayout.class) + ); } else { //cpt本地组件复用,selection.getSelectedCreator().getParent()=@XWParameterLayout instanceof @XWAbsoluteLayout return selection.getSelectedCreator() != null && selection.getSelectedCreator().getParent() != null;