From 40dbc0272fff3a95ab65a9510735590320e13ab6 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Mon, 10 Apr 2017 17:44:13 +0800 Subject: [PATCH 1/3] =?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) { From b67778a4ded602bd9c9434b83b234268c8054917 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Tue, 11 Apr 2017 10:37:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=97=A0=E4=BB=BB=E5=8A=A1=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/designer/beans/models/SelectionModel.java | 2 -- 1 file changed, 2 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 8ef0033ea..5bd159a43 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,8 +15,6 @@ 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.*; From 6e352e28f6ee49e13bb9b2bdcc11668736ed964f Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Fri, 21 Apr 2017 14:41:18 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=A4=8D=E7=94=A8=E4=B9=8B=E5=89=8Dmaster=E5=90=88?= =?UTF-8?q?=E5=88=B0dev=E6=97=B6=E4=B8=A2=E5=A4=B1=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BB=A5=E5=8F=8A=E7=BB=84=E4=BB=B6=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E8=BF=91=E6=9C=9Fbug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/beans/location/MoveUtils.java | 55 +---- .../beans/location/WidgetForbidWindow.java | 45 ---- .../com/fr/design/locale/designer.properties | 4 +- .../design/locale/designer_en_US.properties | 4 +- .../design/locale/designer_ja_JP.properties | 2 + .../design/locale/designer_zh_CN.properties | 2 + .../design/locale/designer_zh_TW.properties | 2 + .../layout/FRAbsoluteLayoutAdapter.java | 79 +++---- .../adapters/layout/FRFitLayoutAdapter.java | 81 +++---- .../beans/location/AccessDirection.java | 217 ++++++++---------- .../designer/beans/models/SelectionModel.java | 21 +- .../design/mainframe/FormSelectionUtils.java | 33 +-- 12 files changed, 220 insertions(+), 325 deletions(-) delete mode 100644 designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java diff --git a/designer_base/src/com/fr/design/beans/location/MoveUtils.java b/designer_base/src/com/fr/design/beans/location/MoveUtils.java index d89848446..d3dc94a08 100644 --- a/designer_base/src/com/fr/design/beans/location/MoveUtils.java +++ b/designer_base/src/com/fr/design/beans/location/MoveUtils.java @@ -18,9 +18,7 @@ public class MoveUtils { public static final int SORPTION_UNIT = 5; private static final int EQUIDISTANTLINE_UNIT = 4; - public static WidgetForbidWindow widgetForbidWindow = new WidgetForbidWindow(); - - public static ArrayList equidistantLines = new ArrayList<>(); + private static ArrayList equidistantLines = new ArrayList<>(); private MoveUtils() { @@ -259,8 +257,7 @@ public class MoveUtils { equidistantLineInfo.setReference(bounds.y); equidistantLineInfo.setDirection(SwingConstants.BOTTOM); } - } - else if ((leftMiddleY > bounds.getY()) && (leftMiddleY < (bounds.getY() + bounds.getHeight()))){ + } else if ((leftMiddleY > bounds.getY()) && (leftMiddleY < (bounds.getY() + bounds.getHeight()))) { //当前操作rec在bounds的右侧 if (left > (bounds.getX() + bounds.getWidth())){ equidistantLineInfo.setDistance(left - (bounds.x + bounds.width)); @@ -279,13 +276,6 @@ public class MoveUtils { } } - public static void displayForbidWindow(int x, int y) { - widgetForbidWindow.showWindow(x, y); - } - - public static void hideForbidWindow() { - widgetForbidWindow.hideWindow(); - } /** * 吸附 @@ -318,25 +308,16 @@ public class MoveUtils { RectangleIterator iterator = designer.createRectangleIterator(); java.util.List cacheRecs = new ArrayList(); - //是否存在控件重叠 - boolean isWidgetsIntersects = false; - while (iterator.hasNext()) { - Rectangle bounds = iterator.nextRectangle(); - cacheRecs.add(bounds); - boolean isIntersects = operatingRectangle.intersects(bounds); - findX(px, bounds, left, right, width); - findY(py, bounds, top, bottom, height); - - if(!isParameterLayout){ - if(isIntersects) { - isWidgetsIntersects = true; - } - else{ - findEquidistantLine(bounds, left, top, height, width); - } - } - } - showForbiddenWindow(designer, x, y, isWidgetsIntersects); + while (iterator.hasNext()) { + Rectangle bounds = iterator.nextRectangle(); + cacheRecs.add(bounds); + findX(px, bounds, left, right, width); + findY(py, bounds, top, bottom, height); + + if (!isParameterLayout) { + findEquidistantLine(bounds, left, top, height, width); + } + } createXAbsorptionline(px, designer, width, cacheRecs); createYAbsorptionline(py, designer, height, cacheRecs); @@ -353,18 +334,6 @@ public class MoveUtils { return sorptionPoint; } - public static void showForbiddenWindow(RectangleDesigner designer, int x, int y, boolean isIntersects){ - if (isIntersects){ - if(designer.getDesignerLocationOnScreen() != null) { - displayForbidWindow(x + designer.getDesignerLocationOnScreen().x, y + designer.getDesignerLocationOnScreen().y); - } - designer.setWidgetsIntersected(true); - } - else{ - designer.setWidgetsIntersected(false); - hideForbidWindow(); - } - } private static void createXAbsorptionline(PlacePointing px, RectangleDesigner designer, int width, java.util.List cacheRecs) { Absorptionline line = null; diff --git a/designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java b/designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java deleted file mode 100644 index 7c645d0ad..000000000 --- a/designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.fr.design.beans.location; - -import com.fr.base.BaseUtils; -import com.fr.design.gui.ibutton.UIButton; -import com.fr.design.icon.IconPathConstants; -import com.fr.general.Inter; - -import javax.swing.*; - -/** - * Created by zhouping on 2016/7/24. - */ -public class WidgetForbidWindow extends JWindow { - - private static final int WIDTH = 150; - private static final int HEIGHT = 20; - - private UIButton promptButton = new UIButton(Inter.getLocText("FR-Designer_Forbid_Widgets_Intersects"), BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); - - /** - * 构造函数 - */ - public WidgetForbidWindow() { - this.add(promptButton); - this.setSize(WIDTH, HEIGHT); - } - - /** - * 在指定位置显示窗口, 默认将window的中心点放到指定位置上 - * - * @param x x坐标 - * @param y y坐标 - */ - public void showWindow(int x, int y) { - this.setLocation(x - WIDTH / 2, y - HEIGHT / 2); - this.setVisible(true); - } - - /** - * 隐藏当前窗口 - */ - public void hideWindow() { - this.setVisible(false); - } -} diff --git a/designer_base/src/com/fr/design/locale/designer.properties b/designer_base/src/com/fr/design/locale/designer.properties index e3ee03999..ac663b6d6 100644 --- a/designer_base/src/com/fr/design/locale/designer.properties +++ b/designer_base/src/com/fr/design/locale/designer.properties @@ -587,4 +587,6 @@ FR-Designer_Mouse_Click_Tips= FR-Designer-Move_Tab_First=move to first FR-Designer-Move_Tab_End=move to end FR-Designer-Move_Tab_Next=move to next -FR-Designer-Move_Tab_Prev=move to previous \ No newline at end of file +FR-Designer-Move_Tab_Prev=move to previous +FR-Designer_Too_Large_To_Paste=too large to paste +FR-Designer_Too_Small_To_Paste=Too small to paste diff --git a/designer_base/src/com/fr/design/locale/designer_en_US.properties b/designer_base/src/com/fr/design/locale/designer_en_US.properties index a86a7fb14..94cba14c3 100644 --- a/designer_base/src/com/fr/design/locale/designer_en_US.properties +++ b/designer_base/src/com/fr/design/locale/designer_en_US.properties @@ -587,4 +587,6 @@ FR-Designer_Mouse_Click_Tips=The background of the mouse to click the button, in FR-Designer-Move_Tab_First=move to first FR-Designer-Move_Tab_End=move to end FR-Designer-Move_Tab_Next=move to next -FR-Designer-Move_Tab_Prev=move to previous \ No newline at end of file +FR-Designer-Move_Tab_Prev=move to previous +FR-Designer_Too_Large_To_Paste=Too large to paste! +FR-Designer_Too_Small_To_Paste=Too small to paste! diff --git a/designer_base/src/com/fr/design/locale/designer_ja_JP.properties b/designer_base/src/com/fr/design/locale/designer_ja_JP.properties index 943cf181d..214978ed5 100644 --- a/designer_base/src/com/fr/design/locale/designer_ja_JP.properties +++ b/designer_base/src/com/fr/design/locale/designer_ja_JP.properties @@ -553,5 +553,7 @@ FR-Designer_Background_Clear= FR-Designer_Background_Image_Select= FR-Designer_Initial_Background_Tips= FR-Designer_Mouse_Move_Tips= +FR-Designer_Too_Large_To_Paste=\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u306E\u30B5\u30A4\u30BA\u306F\u30DC\u30FC\u30C0\u30FC\u306B\u8D85\u3048\u305F\u306E\u3067\u3001\u8CBC\u308A\u4ED8\u3051\u3067\u304D\u307E\u305B\u3093\uFF01 +FR-Designer_Too_Small_To_Paste=\u8A72\u5F53\u51E6\u306B\u8CBC\u308A\u4ED8\u3051\u3067\u304D\u307E\u305B\u3093\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u306E\u30B5\u30A4\u30BA\u306F\u9AD8\u3059\u304E\uFF01 FR-Designer_Mouse_Click_Tips= FR-Designer_Plugin_Should_Update_Please_Contact_Developer= diff --git a/designer_base/src/com/fr/design/locale/designer_zh_CN.properties b/designer_base/src/com/fr/design/locale/designer_zh_CN.properties index 726a6d0f6..93e219698 100644 --- a/designer_base/src/com/fr/design/locale/designer_zh_CN.properties +++ b/designer_base/src/com/fr/design/locale/designer_zh_CN.properties @@ -588,3 +588,5 @@ FR-Designer_Background_Image_Select=\u9009\u62E9\u56FE\u7247 FR-Designer_Initial_Background_Tips=\u6309\u94AE\u7684\u521D\u59CB\u80CC\u666F FR-Designer_Mouse_Move_Tips=\u9F20\u6807\u79FB\u52A8\u5230\u6309\u94AE\u4E0A\u7684\u80CC\u666F\uFF0C\u82E5\u65E0\u5219\u4E0D\u6539\u53D8\u80CC\u666F FR-Designer_Mouse_Click_Tips=\u9F20\u6807\u70B9\u51FB\u6309\u94AE\u65F6\u80CC\u666F\uFF0C\u82E5\u65E0\u5219\u4E0D\u6539\u53D8\u80CC\u666F +FR-Designer_Too_Large_To_Paste=\u7EC4\u4EF6\u5927\u5C0F\u8D85\u51FA\u8FB9\u754C\uFF0C\u65E0\u6CD5\u7C98\u8D34\uFF01 +FR-Designer_Too_Small_To_Paste=\u6B64\u5904\u65E0\u6CD5\u7C98\u8D34\uFF0C\u5C0F\u4E8E\u7EC4\u4EF6\u6700\u5C0F\u9AD8\u5EA6\uFF01 diff --git a/designer_base/src/com/fr/design/locale/designer_zh_TW.properties b/designer_base/src/com/fr/design/locale/designer_zh_TW.properties index f8b28dba3..bb1442664 100644 --- a/designer_base/src/com/fr/design/locale/designer_zh_TW.properties +++ b/designer_base/src/com/fr/design/locale/designer_zh_TW.properties @@ -573,6 +573,8 @@ FR-Designer_Background_Gradient_Color= FR-Designer_Background_Image= FR-Designer_Background_Clear= FR-Designer_Background_Image_Select= +FR-Designer_Too_Large_To_Paste=\u7D44\u4EF6\u5927\u5C0F\u8D85\u51FA\u908A\u754C\uFF0C\u7121\u6CD5\u7C98\u8CBC\uFF01 +FR-Designer_Too_Small_To_Paste=\u6B64\u8655\u7121\u6CD5\u7C98\u8CBC\uFF0C\u5C0F\u65BC\u7D44\u4EF6\u6700\u5C0F\u9AD8\u5EA6\uFF01 FR-Designer_Initial_Background_Tips= FR-Designer_Mouse_Move_Tips= FR-Designer_Mouse_Click_Tips= \ No newline at end of file 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 7810fc9a6..539e60450 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 @@ -1,7 +1,5 @@ package com.fr.design.designer.beans.adapters.layout; -import java.awt.*; - import com.fr.design.beans.GroupModel; import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.HoverPainter; @@ -9,13 +7,14 @@ import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter; import com.fr.design.designer.creator.*; import com.fr.design.designer.properties.BoundsGroupModel; import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel; -import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.gui.LayoutUtils; +import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.general.ComparatorUtils; -import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.general.FRLogger; +import java.awt.*; + public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { //是不是添加到父容器上 private boolean isAdd2ParentLayout = false; @@ -74,48 +73,39 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout(); if(topLayout != null){ if (topLayout.isEditable()){ - return topLayoutAccept(creator, x, y, topLayout); + return topLayoutAccept(creator, x, y); } //绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局 else if (((XLayoutContainer)topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) { return false; + } else { + return acceptWidget(x, y); } - else { - return acceptWidget(creator, x, y); - } - } - else{ + } else { FRLogger.getLogger().error("top layout is null!"); } return false; } - //toplayout假如可以编辑的话就往里面添加组件 - private boolean topLayoutAccept(XCreator creator, int x, int y, XLayoutContainer topLayout) { - //判断有没有和当前控件重叠 - //先计算当前控件的位置 - int creatorX, creatorY; - if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { - + //topLayout假如可以编辑的话就往里面添加组件 + private boolean topLayoutAccept(XCreator creator, int x, int y) { + //允许组件重叠,可以不判断有没有和当前控件重叠 + //先计算当前控件的位置 + int creatorX, creatorY; + if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); creatorX = creatorRectangle.x; creatorY = creatorRectangle.y; } else { + //这边计算得到的组件其实位置是正确的, + //因为传入的x和y已经加上了宽度或者高度的一半,再减去相同的宽度和高度的一半是没区别的, + // 例如高度为21,那么就是+10-10; + // 高度为20,那么就是+10-10; 没区别 int w = creator.getWidth() / 2; int h = creator.getHeight() / 2; creatorX = x - w; creatorY = y - h; - } - //再判断和布局中其他控件重叠 - Rectangle curRec = new Rectangle(creatorX, creatorY, creator.getWidth(), creator.getHeight()); - WAbsoluteLayout wAbsoluteLayout = (WAbsoluteLayout)topLayout.toData(); - for (int i = 0, count = wAbsoluteLayout.getWidgetCount(); i < count; i++) { - BoundsWidget temp = (BoundsWidget) wAbsoluteLayout.getWidget(i); - Rectangle rectangle = temp.getBounds(); - if (curRec.intersects(rectangle)){ - return false; - } } if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) { return false; @@ -168,16 +158,15 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { return !ComparatorUtils.equals(trisectAreaDirect, 0); } - //当前绝对布局不可编辑,就当成一个控件,组件添加在周围 - private boolean acceptWidget(XCreator creator, int x, int y){ - isFindRelatedComps = false; - //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 - Component comp = container.getComponentAt(x, y); - boolean isMatchEdge = false; - //如果当前处于边缘地带, 那么就把他贴到父容器上 - XLayoutContainer parent = container.findNearestFit(); - container = parent != null ? parent : container; - isAdd2ParentLayout = true; + //当前绝对布局不可编辑,就当成一个控件,组件添加在周围 + private boolean acceptWidget(int x, int y) { + isFindRelatedComps = false; + //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 + Component comp = container.getComponentAt(x, y); + //如果当前处于边缘地带, 那么就把他贴到父容器上 + XLayoutContainer parent = container.findNearestFit(); + container = parent != null ? parent : container; + isAdd2ParentLayout = true; int componentHeight = comp.getHeight(); int componentWidth = comp.getWidth(); @@ -244,7 +233,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { if (creator.hasTitleStyle()) { addParentCreator(creator); } else { - container.add(creator, creator.toData().getWidgetName()); + container.add(creator, creator.toData().getWidgetName(),0); } XWAbsoluteLayout layout = (XWAbsoluteLayout) container; layout.updateBoundsWidget(creator); @@ -255,7 +244,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { addParentCreator(creator); } else { - container.add(creator, creator.toData().getWidgetName()); + container.add(creator, creator.toData().getWidgetName(),0); } XWFitLayout layout = (XWFitLayout) container; // 更新对应的BoundsWidget @@ -274,7 +263,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { private void addParentCreator(XCreator child) { XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight()); - container.add(parentPanel, child.toData().getWidgetName()); + container.add(parentPanel, child.toData().getWidgetName(),0); } /** @@ -325,17 +314,15 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { int height = creator.getHeight(); int width = creator.getWidth(); if (x < 0) { - width += x; - x = 0; + x = container.getX(); } else if (x + creator.getWidth() > container.getWidth()) { - width = container.getWidth() - x; + x = container.getWidth() - width; } if (y < 0) { - height += y; - y = 0; + y = container.getY(); } else if (y + creator.getHeight() > container.getHeight()) { - height = container.getHeight() - y; + y = container.getHeight() - height; } creator.setBounds(x, y, width, height); 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 7401b8d07..3a030f7f2 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 @@ -3,12 +3,6 @@ */ package com.fr.design.designer.beans.adapters.layout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.List; - import com.fr.design.beans.GroupModel; import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.HoverPainter; @@ -22,14 +16,16 @@ import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.designer.properties.FRFitLayoutConstraints; import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel; -import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.mainframe.JForm; import com.fr.design.utils.ComponentUtils; import com.fr.form.ui.LayoutBorderStyle; +import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WLayout; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.general.ComparatorUtils; -import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; /** * 自适应布局的容器适配器 @@ -52,6 +48,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { public void setEdit(boolean edit) { isEdit = edit; } + /** * 构造函数 * @@ -134,7 +131,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { isFindRelatedComps = false; //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 Component comp = container.getComponentAt(x, y); - if (checkInterval(comp)) { + if (comp == null || checkInterval(comp)) { return false; } //如果当前处于边缘地带, 那么就把他贴到父容器上 @@ -269,25 +266,14 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { return super.isCrossPointArea(currentComp, x, y); } - protected void initCompsList() { - super.initCompsList(); - } - - protected void clearCompsList() { - super.clearCompsList(); - } - protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout){ + protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) { return mainLayout.getBounds(); } private Rectangle adjustBackupBound(Rectangle backupBound, XWCardMainBorderLayout mainLayout) { - // 参数界面高度对纵坐标产生的影响 - JForm jform = (JForm) (HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); - if (jform.getFormDesign().getParaComponent() != null) { - backupBound.y -= jform.getFormDesign().getParaHeight(); - } - + // zhouping: REPORT-2334 表单tab布局中图表放大缩小会明显 + // 这边不需要单独处理参数面板高度了,下面的方法中获取的是XWCardMainBorderLayout相对坐标 Rectangle rec = getLayoutBound(mainLayout); // XWTabLayout里面的横纵坐标收到外层XWCardMainBorderLayout的横纵坐标影响 // 减掉之后可以按照它原来的逻辑执行 @@ -353,13 +339,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 +356,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 +410,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 +426,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; @@ -558,8 +544,8 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { difference = Math.max(difference, minWidth - getMinWidth(leftComps)); } //重新计算左右两侧组件size、point - if (CalculateLefttRelatComponent(difference)) { - CalculateRightRelatComponent(objx + difference, -difference); + if (calculateLefttRelatComponent(difference)) { + calculateRightRelatComponent(objx + difference, -difference); } } @@ -674,10 +660,9 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { difference = Math.max(difference, minHeight - getMinHeight(upComps)); } //重新计算上下两侧组件size、point - if (CalculateUpRelatComponent(difference)) { - CalculateDownRelatComponent(objY + difference, -difference); + if (calculateUpRelatComponent(difference)) { + calculateDownRelatComponent(objY + difference, -difference); } - ; } /** @@ -757,13 +742,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { int height = creatorHeight; calculateRelatedComponent(x, y, width, height); if (!rightComps.isEmpty() && getAllHeight(rightComps) == height) { - CalculateRightRelatComponent(x, width + actualVal); + calculateRightRelatComponent(x, width + actualVal); } else if (!leftComps.isEmpty() && getAllHeight(leftComps) == height) { - CalculateLefttRelatComponent(width + actualVal); + calculateLefttRelatComponent(width + actualVal); } else if (!downComps.isEmpty() && getAllWidth(downComps) == width) { - CalculateDownRelatComponent(y, height + actualVal); + calculateDownRelatComponent(y, height + actualVal); } else if (!upComps.isEmpty() && getAllWidth(upComps) == width) { - CalculateUpRelatComponent(height + actualVal); + calculateUpRelatComponent(height + actualVal); } else { // 由于布局三等分的存在,可能会出现删除组件时,找不到关联的组件填充,此时特殊处理 calculateNoRelatedComponent(x, y, width, height); @@ -1026,7 +1011,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { setAdjustedSize(tabLayout, offset, isHor); for (int m = 0; m < tabLayout.getComponentCount(); m++) { XCreator childCreator = tabLayout.getXCreator(m); - BoundsWidget wgt = (BoundsWidget) tabLayout.toData().getBoundsWidget(childCreator.toData()); + WAbsoluteLayout.BoundsWidget wgt = (WAbsoluteLayout.BoundsWidget) tabLayout.toData().getBoundsWidget(childCreator.toData()); wgt.setBounds(tabLayout.getComponent(m).getBounds()); } adjustCreatorsSize(percent, tabLayout, isHor); @@ -1069,7 +1054,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { * @param objX 调整后的坐标x * @param objWidth 调整后的宽度 */ - protected void CalculateRightRelatComponent(int objX, int objWidth) { + protected void calculateRightRelatComponent(int objX, int objWidth) { int count = rightComps.size(); for (int i = 0; i < count; i++) { XCreator creator = (XCreator) rightComps.get(i); @@ -1109,7 +1094,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { /** * 删除或拉伸控件左边框时 调整左侧的组件位置大小; */ - protected boolean CalculateLefttRelatComponent(int objWidth) { + protected boolean calculateLefttRelatComponent(int objWidth) { if (isBeyondAdjustWidthScope(objWidth)) { return false; } @@ -1127,7 +1112,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { /** * 删除或拉伸下边框 调整下方的组件位置大小 */ - protected void CalculateDownRelatComponent(int objY, int objHeight) { + protected void calculateDownRelatComponent(int objY, int objHeight) { int count = downComps.size(); for (int i = 0; i < count; i++) { XCreator creator = (XCreator) downComps.get(i); @@ -1167,7 +1152,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { /** * 删除或拉伸上边框 调整上方的组件位置大小 */ - protected boolean CalculateUpRelatComponent(int objHeight) { + protected boolean calculateUpRelatComponent(int objHeight) { if (isBeyondAdjustHeightScope(objHeight)) { return false; } diff --git a/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java b/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java index 572ac721e..3538d2fd9 100644 --- a/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java +++ b/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java @@ -27,32 +27,30 @@ public abstract class AccessDirection implements Direction { abstract int getCursor(); - protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, - Rectangle oldbounds); - - protected int[] sorption(int x, int y,Rectangle current_bounds, FormDesigner designer) { - // 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理 - if (!designer.hasWAbsoluteLayout()) { - designer.getStateModel().setEquidistantLine(null); - designer.getStateModel().setXAbsorptionline(null); - designer.getStateModel().setYAbsorptionline(null); - return new int[] { x, y }; - } else { - int posy = current_bounds.y; - - Point relativePoint = getRelativePoint(x, y, current_bounds,designer); - sorptionPoint(relativePoint,current_bounds, designer); - return new int[] { relativePoint.x, relativePoint.y }; - } + protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle currentBounds, FormDesigner designer, + Rectangle oldBounds); + + protected int[] sorption(int x, int y, Rectangle currentBounds, FormDesigner designer) { + // 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理 + if (!designer.hasWAbsoluteLayout()) { + designer.getStateModel().setEquidistantLine(null); + designer.getStateModel().setXAbsorptionline(null); + designer.getStateModel().setYAbsorptionline(null); + return new int[]{x, y}; + } else { + Point relativePoint = getRelativePoint(x, y, currentBounds, designer); + sorptionPoint(relativePoint, currentBounds, designer); + return new int[]{relativePoint.x, relativePoint.y}; + } - } + } - protected Point getRelativePoint(int x, int y, Rectangle current_bounds,FormDesigner designer) { - if (x < 0) { - x = 0; - } else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) { - x = designer.getRootComponent().getWidth(); - } + protected Point getRelativePoint(int x, int y, Rectangle currentBounds, FormDesigner designer) { + if (x < 0) { + x = 0; + } else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) { + x = designer.getRootComponent().getWidth(); + } //参数面板可以无下限拉长 if (y < 0) { y = 0; @@ -63,112 +61,101 @@ public abstract class AccessDirection implements Direction { return new Point(x, y); } - protected void sorptionPoint(Point point, Rectangle current_bounds,FormDesigner designer) { - boolean findInX = current_bounds.getWidth() <= MoveUtils.SORPTION_UNIT ? true : false; - boolean findInY = current_bounds.getHeight() <= MoveUtils.SORPTION_UNIT ? true : false; - WAbsoluteLayout layout =getLayout(designer); - FormSelection selection = designer.getSelectionModel().getSelection(); - boolean isWidgetsIntersect = false; - for (int i = 0, count = layout.getWidgetCount(); i < count; i++) { - BoundsWidget temp = (BoundsWidget) layout.getWidget(i); - if (!temp.isVisible() || selection.contains(temp.getWidget())) { - continue; - } - Rectangle bounds = getWidgetRelativeBounds(temp.getBounds(), selection); - if (!findInX) { - int x1 = bounds.x; - if (Math.abs(x1 - point.x) <= MoveUtils.SORPTION_UNIT) { - point.x = x1; - findInX = true; - } - int x2 = bounds.x + bounds.width; - if (Math.abs(x2 - point.x) <= MoveUtils.SORPTION_UNIT) { - point.x = x2; - findInX = true; - } - } - if (!findInY) { - int y1 = bounds.y; - if (Math.abs(y1 - point.y) <= MoveUtils.SORPTION_UNIT) { - point.y = y1; - findInY = true; - } - int y2 = bounds.y + bounds.height; - if (Math.abs(y2 - point.y) <= MoveUtils.SORPTION_UNIT) { - point.y = y2; - findInY = true; - } + protected void sorptionPoint(Point point, Rectangle currentBounds, FormDesigner designer) { + boolean findInX = currentBounds.getWidth() <= MoveUtils.SORPTION_UNIT; + boolean findInY = currentBounds.getHeight() <= MoveUtils.SORPTION_UNIT; + WAbsoluteLayout layout = getLayout(designer); + FormSelection selection = designer.getSelectionModel().getSelection(); + for (int i = 0, count = layout.getWidgetCount(); i < count; i++) { + BoundsWidget temp = (BoundsWidget) layout.getWidget(i); + if (!temp.isVisible() || selection.contains(temp.getWidget())) { + continue; + } + Rectangle bounds = getWidgetRelativeBounds(temp.getBounds(), selection); + if (!findInX) { + int x1 = bounds.x; + if (Math.abs(x1 - point.x) <= MoveUtils.SORPTION_UNIT) { + point.x = x1; + findInX = true; + } + int x2 = bounds.x + bounds.width; + if (Math.abs(x2 - point.x) <= MoveUtils.SORPTION_UNIT) { + point.x = x2; + findInX = true; + } + } + if (!findInY) { + int y1 = bounds.y; + if (Math.abs(y1 - point.y) <= MoveUtils.SORPTION_UNIT) { + point.y = y1; + findInY = true; + } + int y2 = bounds.y + bounds.height; + if (Math.abs(y2 - point.y) <= MoveUtils.SORPTION_UNIT) { + point.y = y2; + findInY = true; + } } if (findInX && findInY) { break; } - if (current_bounds.intersects(bounds) && !(layout instanceof WParameterLayout)){ - isWidgetsIntersect = true; - } - } - processRectangleIntersects(designer, point.x, point.y, isWidgetsIntersect); - setDesignerStateModelProperties(designer, findInX, findInY, current_bounds, point); - } + } + setDesignerStateModelProperties(designer, findInX, findInY, currentBounds, point); + } - private void setDesignerStateModelProperties (FormDesigner designer, boolean findInX, boolean findInY, Rectangle current_bounds, Point point) { - designer.getStateModel().setXAbsorptionline(findInX && current_bounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null); - designer.getStateModel().setYAbsorptionline(findInY && current_bounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null); - designer.getStateModel().setEquidistantLine(null); - } + private void setDesignerStateModelProperties(FormDesigner designer, boolean findInX, boolean findInY, Rectangle + currentBounds, Point point) { + designer.getStateModel().setXAbsorptionline(findInX && currentBounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null); + designer.getStateModel().setYAbsorptionline(findInY && currentBounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null); + designer.getStateModel().setEquidistantLine(null); + } - private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection){ - Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height); - XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); - if (parent == null) { - return relativeRec; - } - Rectangle rec = ComponentUtils.getRelativeBounds(parent); - relativeRec.x += rec.x; - relativeRec.y += rec.y; - return relativeRec; - } + private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection) { + Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height); + XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); + if (parent == null) { + return relativeRec; + } + Rectangle rec = ComponentUtils.getRelativeBounds(parent); + relativeRec.x += rec.x; + relativeRec.y += rec.y; + return relativeRec; + } - private void processRectangleIntersects(FormDesigner designer, int x, int y, boolean isIntersects){ - if(isIntersects){ - if(designer.getLocationOnScreen() != null) { - MoveUtils.displayForbidWindow(x + designer.getLocationOnScreen().x, y + designer.getLocationOnScreen().y); - } - designer.setWidgetsIntersect(true); - } - else{ - MoveUtils.hideForbidWindow(); - designer.setWidgetsIntersect(false); - } - } private WAbsoluteLayout getLayout(final FormDesigner designer){ XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator( designer.getTarget().getContainer()); WAbsoluteLayout layout; - if (formLayoutContainer.acceptType(XWBorderLayout.class)){//看起来这边的作用应该是为了区别cpt(得到XWParameterLayout)还是frm(得到XWBorderLayout)的参数界面 - Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent(); - if(container instanceof XWAbsoluteLayout){ - layout = ((XWAbsoluteLayout)container).toData(); - } - else { - layout = (WAbsoluteLayout) designer.getParaComponent().toData(); - } - } else{ + if (formLayoutContainer.acceptType(XWBorderLayout.class)) {//看起来这边的作用应该是为了区别cpt(得到XWParameterLayout)还是frm(得到XWBorderLayout)的参数界面 + Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent(); + if (container instanceof XWAbsoluteLayout) { + layout = ((XWAbsoluteLayout) container).toData(); + } else { + layout = (WAbsoluteLayout) designer.getParaComponent().toData(); + } + } else { layout = (WAbsoluteLayout) designer.getTarget().getContainer(); } - return layout; + return layout; } - /** - * 拖拽 - * @param dx 坐标x - * @param dy 坐标y - * @param designer 设计界面 - */ - public void drag(int dx, int dy, FormDesigner designer) { - Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds()); + /** + * 拖拽 + * + * @param dx 坐标x + * @param dy 坐标y + * @param designer 设计界面 + */ + public void drag(int dx, int dy, FormDesigner designer) { + Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds()); + if (rec != null) { + designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer); + } else { + return; + } //设定控件最小高度21,因每次拖曳至少移动1,防止控件高度等于21时,拖曳导致rec.y的变化使得控件不停的向上或向下移动。 if(rec.height == MINHEIGHT){ ymin = rec.y; @@ -191,10 +178,8 @@ public abstract class AccessDirection implements Direction { rec.width = MINWIDTH; rec.x = xmin; } - if(rec != null) { - designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer); - } - } + + } /** * 更新鼠标指针形状 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 5bd159a43..13eaa18ac 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 @@ -27,7 +27,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.78; + private static final double OFFSET_RELATIVE = 0.80; private static FormSelection clipboard = new FormSelection(); private FormDesigner designer; private FormSelection selection; @@ -142,14 +142,29 @@ public class SelectionModel { int leftUpY = container.toData().getMargin().getTop() + 1; //选中第一个坐标点坐在的组件 selection.setSelectedCreator((XCreator) container.getComponentAt(leftUpX, leftUpY)); - pasteFromClipBoard(); + Rectangle rectangle = selection.getRelativeBounds(); + if (hasSelectedPasteSource()) { + selectedPaste(); + } else { + FormSelectionUtils.paste2Container(designer, container, clipboard, + rectangle.x + rectangle.width / 2, + rectangle.y + DELTA_X_Y); + } } else { //自适应布局编辑器内部左上角第一个坐标点 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(); + Rectangle rectangle = selection.getRelativeBounds(); + if (hasSelectedPasteSource()) { + selectedPaste(); + } else { + FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), + clipboard, + rectangle.x + rectangle.width / 2, + rectangle.y + DELTA_X_Y); + } } } else { //绝对布局 diff --git a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java index 1978e8432..90945b1e8 100644 --- a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java +++ b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java @@ -132,29 +132,18 @@ public class FormSelectionUtils { XLayoutContainer container = layoutAdapter.getContainer(); boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + xoffset > container.getWidth(); boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + yoffset > container.getHeight(); - /* - * 组件原始位置位于布局的右下角, - * 和布局右下边界线紧挨, - * 粘贴时组件在原始位置向左错开20像素。 - * x,y同时越界 - */ - if (xOut && yOut) { - //向左偏移 - x = container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X_Y - xoffset; + + y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y; + boolean isEdge = (x - DELAY_X_Y == container.getWidth() - copiedCreator.getWidth() / 2 - xoffset); + if (xOut) { + if (isEdge) { + //向左偏移 + x = container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X_Y - xoffset; + } //紧贴下边界 - y = container.getHeight() - copiedCreator.getHeight() / 2 - yoffset; - return new Point(x, y); - } - /* - * 组件原始位置与布局边界距离小于20像素(下边界&右边界同时小于或者任意一个边界小于), - * 则粘贴时距离小于20像素一侧直接贴近布局边界, - * 距离大于20像素的一侧正常错开。 - * x,y中只有一个越界 - */ - if ((xOut || yOut)) { - x = xOut ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset : x; - y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y; - return new Point(x, y); + else { + x = container.getWidth() - copiedCreator.getWidth() / 2 - xoffset; + } } } return new Point(x, y);