diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java index 53a72e911..107e31ed1 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java @@ -106,6 +106,16 @@ public class XWCardLayout extends XLayoutContainer { return new Dimension(500, 300); } + /** + * 重置组件的名称 + * @param name 名称 + */ + public void resetCreatorName(String name) { + super.resetCreatorName(name); + changeRelateSwitchCardName(name); + } + + @Override protected void initLayoutManager() { cardLayout = new FRCardLayout(toData().getHgap(), toData().getVgap()); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormSelectionUtils.java b/designer-form/src/main/java/com/fr/design/mainframe/FormSelectionUtils.java index 9a6a5d546..f88b9e540 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormSelectionUtils.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormSelectionUtils.java @@ -14,12 +14,11 @@ import com.fr.design.designer.creator.XWScaleLayout; import com.fr.design.designer.creator.XWTitleLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.utils.ComponentUtils; +import com.fr.form.main.Form; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WTitleLayout; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; - - import java.awt.Component; import java.awt.Point; import java.awt.Rectangle; @@ -97,8 +96,7 @@ public class FormSelectionUtils { Rectangle rec = clipboard.getSelctionBounds(); for (XCreator creator : clipboard.getSelectedCreators()) { try { - Widget copied = copyWidget(designer, creator); - XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); + XCreator copiedCreator = copyXcreator(designer.getTarget(), creator); // 获取位置 Point point = getPasteLocation((AbstractLayoutAdapter) adapter, copiedCreator, @@ -181,8 +179,7 @@ public class FormSelectionUtils { private static void relativePasteXCreator(FormDesigner designer, XCreator creator, LayoutAdapter adapter, Rectangle tabContainerRect, int x, int y) { try { - Widget copied = copyWidget(designer, creator); - XCreator copiedXCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); + XCreator copiedXCreator = copyXcreator(designer.getTarget(), creator); if (adapter.getClass().equals(FRTabFitLayoutAdapter.class)) { if (!adapter.accept(copiedXCreator, x - tabContainerRect.x, y - tabContainerRect.y)) { designer.showMessageDialog(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Too_Small_To_Paste")); @@ -235,33 +232,52 @@ public class FormSelectionUtils { return new Point(x, y); } - /** * 拷贝组件 + * @param form 当前表单 + * @param xCreator 待拷贝的组件 + * @return XCreator 拷贝的组件 */ - private static Widget copyWidget(FormDesigner formDesigner, XCreator xCreator) throws - CloneNotSupportedException { - ArrayList nameSpace = new ArrayList<>(); + public static XCreator copyXcreator(Form form, XCreator xCreator) throws CloneNotSupportedException{ Widget copied = (Widget) xCreator.toData().clone(); - //重命名拷贝的组件 - String name = getCopiedName(formDesigner, copied, nameSpace); - if (copied instanceof WTitleLayout) { - XWTitleLayout xwTitleLayout = new XWTitleLayout((WTitleLayout) copied, xCreator.getSize()); - xwTitleLayout.resetCreatorName(name); - } else { - copied.setWidgetName(name); + XCreator copiedCreator = XCreatorUtils.createXCreator(copied, xCreator.getSize()); + ArrayList nameSpace = new ArrayList<>(); + copyWidgetName(form, nameSpace, copiedCreator); + return copiedCreator; + } + + /** + * 拷贝组件 + * @param form 当前表单 + * @param nameSpace 命名空间 + * @param xCreator 拷贝的组件 + */ + private static void copyWidgetName(Form form, ArrayList nameSpace, XCreator xCreator){ + String copyName = FormSelectionUtils.getCopiedName(form, xCreator.toData(), nameSpace); + if (xCreator.toData() instanceof WTitleLayout) { + XWTitleLayout xwTitleLayout = new XWTitleLayout((WTitleLayout) xCreator.toData(), xCreator.getSize()); + xwTitleLayout.resetCreatorName(copyName); + return; + } + xCreator.resetCreatorName(copyName); + int count = xCreator.getComponentCount(); + for(int a = 0; a nameSpace) { + private static String getCopiedName(Form form, Widget copied, ArrayList nameSpace) { StringBuilder name = new StringBuilder(copied.getWidgetName()); do { name.append(POSTFIX); - } while (formDesigner.getTarget().isNameExist(name.toString()) || nameSpace.contains(name.toString())); + } while (form.isNameExist(name.toString()) || nameSpace.contains(name.toString())); nameSpace.add(name.toString()); return name.toString(); } @@ -308,4 +324,4 @@ public class FormSelectionUtils { } } } -} +} \ No newline at end of file