From 32ea80b862f4a2f728fade109b651a1af0c7d8d4 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Wed, 29 Mar 2017 09:27:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0=E4=BB=BB=E5=8A=A1=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/mainframe/FormSelectionUtils.java | 110 +++++++++++------- 1 file changed, 67 insertions(+), 43 deletions(-) diff --git a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java index 4f6c937bc7..ff976ef771 100644 --- a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java +++ b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java @@ -33,63 +33,87 @@ public class FormSelectionUtils { /** * @param designer 编辑器 * @param parent 粘贴依据的组件 - * @param clipBoard 剪贴板内容 + * @param clipboard 剪贴板内容 * @param x x * @param y y */ public static void paste2Container(FormDesigner designer, XLayoutContainer parent, - FormSelection clipBoard, int x, int y) { + 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()) { - try { - Widget copied = copyWidget(designer, creator); - XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); - // 获取位置 - Point point = getPasteLocation((AbstractLayoutAdapter) adapter, - copiedCreator, - x + creator.getX() - rec.x + copiedCreator.getWidth() / 2, - y + creator.getY() - rec.y + copiedCreator.getHeight() / 2); - boolean addSuccess = adapter.addBean(copiedCreator, point.x, point.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); + absolutePaste(designer, clipboard, adapter, x, y); return; } else if (parent instanceof XWFitLayout) { //相对布局 - designer.getSelectionModel().getSelection().reset(); - for (XCreator creator : clipBoard.getSelectedCreators()) { - try { - Widget copied = copyWidget(designer, creator); - XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); - boolean addSuccess = adapter.addBean(copiedCreator, x, y); - - if (addSuccess) { - designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); - } + relativePaste(designer, clipboard, adapter, x, y); + return; + } + Toolkit.getDefaultToolkit().beep(); + } + + /** + * 绝对布局粘贴 + * + * @param designer + * @param clipboard + * @param adapter + * @param x + * @param y + */ + private static void absolutePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { - } catch (CloneNotSupportedException e) { - FRContext.getLogger().error(e.getMessage(), e); + 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()); + // 获取位置 + Point point = getPasteLocation((AbstractLayoutAdapter) adapter, + copiedCreator, + x + creator.getX() - rec.x + copiedCreator.getWidth() / 2, + y + creator.getY() - rec.y + copiedCreator.getHeight() / 2); + boolean addSuccess = adapter.addBean(copiedCreator, point.x, point.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(); + rebuildSelection(designer); + designer.getEditListenerTable().fireCreatorModified( + designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); + + } + + /** + * 相对布局粘贴 + * + * @param designer + * @param clipboard + * @param adapter + * @param x + * @param y + */ + private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { + designer.getSelectionModel().getSelection().reset(); + for (XCreator creator : clipboard.getSelectedCreators()) { + try { + Widget copied = copyWidget(designer, creator); + XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); + 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); } /**