From 455166016db1f124decda92ba3570648bbf6a485 Mon Sep 17 00:00:00 2001 From: zhouping Date: Thu, 11 Aug 2016 16:53:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=9D=A2=E6=9D=BF=E9=87=8D?= =?UTF-8?q?=E5=86=99=E7=88=B6=E7=B1=BB=E4=B8=AD=E7=9A=84=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=88=E9=83=BD=E6=98=AF=E7=BB=9D=E5=AF=B9?= =?UTF-8?q?=E5=B8=83=E5=B1=80=E4=B8=AD=E5=8E=9F=E6=9D=A5=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=89=8D=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../layout/FRParameterLayoutAdapter.java | 69 ++++++++++++++++++- .../designer/creator/XWParameterLayout.java | 9 +++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRParameterLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRParameterLayoutAdapter.java index 65858c2992..c88579c414 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRParameterLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRParameterLayoutAdapter.java @@ -1,14 +1,20 @@ package com.fr.design.designer.beans.adapters.layout; import com.fr.design.beans.GroupModel; +import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.painters.FRParameterLayoutPainter; import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XCreatorUtils; import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XWParameterLayout; import com.fr.design.form.parameter.RootDesignGroupModel; +import com.fr.design.utils.ComponentUtils; +import com.fr.design.utils.gui.LayoutUtils; import com.fr.form.ui.container.WParameterLayout; +import java.awt.*; + /** * 表单参数界面的监听器 */ @@ -39,5 +45,66 @@ public class FRParameterLayoutAdapter extends FRAbsoluteLayoutAdapter { WParameterLayout wabs = (WParameterLayout)container.toData(); wabs.refreshTagList(); } - + + /** + * 是否能在指定位置添加组件 + * + * @param creator 组件 + * @param x 坐标x + * @param y 坐标y + * @return 能则返回true + */ + @Override + public boolean accept(XCreator creator, int x, int y) { + return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight() + && creator.getWidth() <= container.getWidth(); + } + + @Override + protected void addComp(XCreator creator, int x, int y) { + if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { + Rectangle r = ComponentUtils.getRelativeBounds(container); + Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); + x = creatorRectangle.x - r.x; + y = creatorRectangle.y - r.y; + } else { + int w = creator.getWidth() / 2; + int h = creator.getHeight() / 2; + x = x - w; + y = y - h; + } + + fix(creator, x, y); + container.add(creator); + LayoutUtils.layoutRootContainer(container); + } + + /** + * 调整组件大小到合适尺寸位置 + * + * @param creator 组件 + * @param x 坐标x + * @param y 坐标y + */ + @Override + public void fix(XCreator creator, int x, int y) { + if (x < 0) { + x = 0; + } else if (x + creator.getWidth() > container.getWidth()) { + x = container.getWidth() - creator.getWidth(); + } + + if (y < 0) { + y = 0; + } else if (y + creator.getHeight() > container.getHeight()) { + y = container.getHeight() - creator.getHeight(); + } + + creator.setLocation(x, y); + } + + @Override + public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { + return super.getLayoutConstraints(creator); + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/creator/XWParameterLayout.java b/designer_form/src/com/fr/design/designer/creator/XWParameterLayout.java index 890612ccc5..e1ab80b7c4 100644 --- a/designer_form/src/com/fr/design/designer/creator/XWParameterLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/XWParameterLayout.java @@ -174,4 +174,13 @@ public class XWParameterLayout extends XWAbsoluteLayout { public XLayoutContainer getTopLayout() { return this; } + + /** + * 新增删除拉伸后更新每个组件的BoundsWidget + * + * @param xCreator + */ + @Override + public void updateBoundsWidget(XCreator xCreator) { + } } \ No newline at end of file