From 00cc1fad3740f1b7fe5848515d7055a224cbf1bd Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Wed, 15 Nov 2017 13:59:19 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-4729=20=E5=86=B3=E7=AD=96=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E8=87=AA=E9=80=82=E5=BA=94=E5=B8=83=E5=B1=80=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E5=A4=8D=E7=94=A8=E7=B2=98=E8=B4=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/mainframe/FormSelectionUtils.java | 117 ++++++++++++------ 1 file changed, 77 insertions(+), 40 deletions(-) diff --git a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java index 7a03782c2..ebf7328a2 100644 --- a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java +++ b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java @@ -5,24 +5,45 @@ 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.designer.creator.XCreator; +import com.fr.design.designer.creator.XCreatorUtils; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWAbsoluteLayout; +import com.fr.design.designer.creator.XWFitLayout; +import com.fr.design.designer.creator.XWScaleLayout; +import com.fr.design.designer.creator.XWTitleLayout; import com.fr.design.utils.ComponentUtils; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WTitleLayout; import com.fr.general.ComparatorUtils; +import com.fr.general.FRLogger; import com.fr.general.Inter; -import java.awt.*; +import java.awt.Component; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Toolkit; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +/** + * 表单选中工具类 + * + * @author yaoh.wu + * @version 2017年11月15日13点51分 + * @since 8.0 + */ public class FormSelectionUtils { - //组件复制时坐标偏移 + /** + * 组件复制时坐标偏移 + */ private static final int DELAY_X_Y = 20; - //组件重命名后缀 + /** + * 组件重命名后缀 + */ private static final String POSTFIX = "_c"; private FormSelectionUtils() { @@ -47,6 +68,25 @@ public class FormSelectionUtils { Toolkit.getDefaultToolkit().beep(); } + + public static void rebuildSelection(FormDesigner designer) { + ArrayList newSelection = new ArrayList<>(); + List widgetList = new ArrayList<>(); + for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) { + widgetList.add(comp.toData()); + } + designer.getSelectionModel().setSelectedCreators( + rebuildSelection(designer.getRootComponent(), widgetList, newSelection)); + } + + public static ArrayList rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { + List selectionWidget = new ArrayList<>(); + if (selectWidgets != null) { + selectionWidget.addAll(Arrays.asList(selectWidgets)); + } + return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList()); + } + /** * 绝对布局粘贴 */ @@ -92,26 +132,15 @@ public class FormSelectionUtils { designer.getSelectionModel().getSelection().reset(); for (XCreator creator : clipboard.getSelectedCreators()) { - try { - Widget copied = copyWidget(designer, creator); - XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); - 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) { - designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); + if (creator instanceof XWScaleLayout) { + //XWScaleLayout封装了在自适应布局中需要保持默认高度的控件,由于自适应粘贴时会再次包装,因此复制时要进行解包 + Component[] innerComponents = creator.getComponents(); + for (Component innerComponent : innerComponents) { + XCreator innerXCreator = (XCreator) innerComponent; + relativePasteXCreator(designer, innerXCreator, adapter, tabContainerRect, x, y); } - } catch (CloneNotSupportedException e) { - FRContext.getLogger().error(e.getMessage(), e); + } else { + relativePasteXCreator(designer, creator, adapter, tabContainerRect, x, y); } } rebuildSelection(designer); @@ -119,6 +148,31 @@ public class FormSelectionUtils { designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); } + + 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()); + if (adapter.getClass().equals(FRTabFitLayoutAdapter.class)) { + if (!adapter.accept(copiedXCreator, x - tabContainerRect.x, y - tabContainerRect.y)) { + designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste")); + return; + } + } else { + if (!adapter.accept(copiedXCreator, x, y)) { + designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste")); + return; + } + } + boolean addSuccess = adapter.addBean(copiedXCreator, x, y); + if (addSuccess) { + designer.getSelectionModel().getSelection().addSelectedCreator(copiedXCreator); + } + } catch (CloneNotSupportedException e) { + FRLogger.getLogger().error(e.getMessage(), e); + } + } + /** * 组件复用绝对布局获取粘贴组件位置 */ @@ -182,23 +236,6 @@ public class FormSelectionUtils { return name.toString(); } - public static void rebuildSelection(FormDesigner designer) { - ArrayList newSelection = new ArrayList<>(); - List widgetList = new ArrayList<>(); - for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) { - widgetList.add(comp.toData()); - } - designer.getSelectionModel().setSelectedCreators( - rebuildSelection(designer.getRootComponent(), widgetList, newSelection)); - } - - public static ArrayList rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { - List selectionWidget = new ArrayList<>(); - if (selectWidgets != null) { - selectionWidget.addAll(Arrays.asList(selectWidgets)); - } - return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList()); - } private static ArrayList rebuildSelection(XCreator rootComponent, List selectionWidget, ArrayList newSelection) {