From a2d95f38eafdd39f606faba0dd31a371730f3ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E7=A3=8A?= <294531121@qq.com> Date: Fri, 7 Jan 2022 11:44:13 +0800 Subject: [PATCH] REPORT-64149 --- .../adapters/layout/FRFitLayoutAdapter.java | 4 +- .../designer/beans/models/AddingModel.java | 39 +--- .../mainframe/DesignerTransferHandler.java | 4 +- .../mainframe/FormCreatorDropTarget.java | 30 ++- .../com/fr/design/mainframe/FormDesigner.java | 31 ++- .../beans/models/AddingModelTest.java | 210 ------------------ .../guide/creator/GuideCreateUtils.java | 13 +- .../layout/ChangeLayoutComponentGuide.java | 4 +- .../layout/UseLayoutAndComponentGuide.java | 2 +- 9 files changed, 40 insertions(+), 297 deletions(-) delete mode 100644 designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java index e0d97ff1ce..3814dc6006 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java @@ -8,7 +8,6 @@ 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.LayoutAdapter; -import com.fr.design.designer.beans.models.AddingModel; import com.fr.design.designer.beans.models.DraggingModel; import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.creator.XCreator; @@ -1262,10 +1261,9 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { if (dragEvent.getPoint().distance(lastPressEvent.getPoint()) > 5) { if (creator.isSupportDrag()) { - designer.setAddingModel(new AddingModel(creator, dragEvent.getX(), dragEvent.getY())); designer.bindTransferHandler(lastPressEvent); designer.fireParentLayoutDragStart(creator); - designer.setDropTarget(new FormCreatorDropTarget(designer)); + designer.setDropTarget(new FormCreatorDropTarget(designer, creator)); // 触发状态添加模式事件 designer.repaint(); } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java index 7a6a1cf0c8..cb16cf66d6 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java @@ -1,12 +1,8 @@ package com.fr.design.designer.beans.models; -import com.fr.design.designer.beans.AdapterBus; -import com.fr.design.designer.beans.ComponentAdapter; -import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; 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.mainframe.FormDesigner; import com.fr.design.utils.ComponentUtils; import com.fr.general.ComparatorUtils; @@ -23,41 +19,8 @@ public class AddingModel { private boolean added; private boolean addedIllegal = false; // 有时候是添加完成了,但是添加会造成某些控件size不合法,例如tab - public AddingModel(FormDesigner designer, XCreator xCreator) { + public AddingModel(XCreator xCreator) { this.creator = xCreator; - instantiateCreator(designer); - } - - /** - * 待说明 - * - * @param designer 设计器 - */ - public void instantiateCreator(FormDesigner designer) { - - ModelUtil.renameWidgetName(designer.getTarget(), creator); - ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator); - adapter.initialize(); - creator.addNotify(); - creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter); - } - - public AddingModel(XCreator xCreator, int x, int y) { - this.creator = xCreator; - this.creator.backupCurrentSize(); - this.creator.backupParent(); - } - - public String getXCreatorName(FormDesigner designer, XCreator x) { - String def = x.createDefaultName(); - if (x.acceptType(XWParameterLayout.class)) { - return def; - } - int i = 0; - while (designer.getTarget().isNameExist(def + i)) { - i++; - } - return def + i; } public XCreator getXCreator() { diff --git a/designer-form/src/main/java/com/fr/design/mainframe/DesignerTransferHandler.java b/designer-form/src/main/java/com/fr/design/mainframe/DesignerTransferHandler.java index e5b11dd9a4..71360a9064 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/DesignerTransferHandler.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/DesignerTransferHandler.java @@ -10,16 +10,14 @@ import java.awt.datatransfer.Transferable; public class DesignerTransferHandler extends TransferHandler { private FormDesigner designer; - private AddingModel addingModel; public DesignerTransferHandler(FormDesigner designer, AddingModel addingModel) { super("rootComponent"); this.designer = designer; - this.addingModel = addingModel; } protected void exportDone(JComponent source, Transferable data, int action) { - if (!addingModel.isCreatorAdded()) { + if (designer.getAddingModel() != null && !designer.getAddingModel().isCreatorAdded()) { undoWhenAddingFailed(); } } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java b/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java index d48cfe9dd8..c8e6bdd675 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java @@ -5,7 +5,6 @@ import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.Painter; import com.fr.design.designer.beans.events.AddingWidgetListener; -import com.fr.design.designer.beans.models.AddingModel; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreatorUtils; import com.fr.design.designer.creator.XLayoutContainer; @@ -43,20 +42,16 @@ public class FormCreatorDropTarget extends DropTarget { * 当前鼠标的设计组件 */ private Component current; - /** - * 当前添加模式对应的model - */ - private AddingModel addingModel; private static final int GAP = 30; private TabDragInner tabDragInner; - + private XCreator creator; private JWindow promptWindow = new JWindow(); private UIButton promptButton = new UIButton("", BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); - public FormCreatorDropTarget(FormDesigner designer) { + public FormCreatorDropTarget(FormDesigner designer, XCreator creator) { this.designer = designer; - this.addingModel = designer.getAddingModel(); + this.creator = creator; this.promptWindow.add(promptButton); this.tabDragInner = new TabDragInner(designer); initAddingListener(); @@ -71,7 +66,9 @@ public class FormCreatorDropTarget extends DropTarget { @Override public void afterAdded(boolean addResult) { - tabDragInner.reset(); + if (addResult) { + tabDragInner.reset(); + } } }); } @@ -145,15 +142,15 @@ public class FormCreatorDropTarget extends DropTarget { rect.y -= designer.getArea().getVerticalValue(); painter.setRenderingBounds(rect); painter.setHotspot(new Point(x, y)); - painter.setCreator(addingModel.getXCreator()); + painter.setCreator(creator); } } private void promptUser(int x, int y, XLayoutContainer container) { - if (!addingModel.getXCreator().canEnterIntoParaPane() && container.acceptType(XWParameterLayout.class)) { + if (!creator.canEnterIntoParaPane() && container.acceptType(XWParameterLayout.class)) { promptButton.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Forbid_Drag_Into_Para_Pane")); promptWidgetForbidEnter(x, y, container); - } else if (!addingModel.getXCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)) { + } else if (!creator.canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)) { promptButton.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Forbid_Drag_Into_Adapt_Pane")); promptWidgetForbidEnter(x, y, container); } else { @@ -201,10 +198,9 @@ public class FormCreatorDropTarget extends DropTarget { hovering(x, y); tabDragInner.setTabDragInAble(designer.getComponentAt(x, y), x, y); - XCreator xCreator = designer.getAddingModel().getXCreator(); - XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(xCreator); + XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator); if (parent!= null && parent.getLayoutAdapter()!=null){ - parent.getLayoutAdapter().dragOver(xCreator, designer.getSelectionModel(), x, y); + parent.getLayoutAdapter().dragOver(creator, designer.getSelectionModel(), x, y); } // 触发状态添加模式事件 @@ -243,7 +239,7 @@ public class FormCreatorDropTarget extends DropTarget { dropXCreator(dtde); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); - if (addingModel.getXCreator().isShared()) { + if (creator.isShared()) { FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Share_Drag_Component_Error_Info"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Error"), @@ -258,7 +254,7 @@ public class FormCreatorDropTarget extends DropTarget { private void dropXCreator(DropTargetDropEvent dtde) { cancelPromptWidgetForbidEnter(); Point loc = dtde.getLocation(); - designer.addWidgetToForm(designer.getRelativeX(loc.x), designer.getRelativeY(loc.y)); + designer.addWidgetToForm(creator, designer.getRelativeX(loc.x), designer.getRelativeY(loc.y)); // 放到事件末尾执行 SwingUtilities.invokeLater(new Runnable() { @Override diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java index a4ec9ff191..4f2762d80a 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java @@ -14,6 +14,7 @@ import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.datapane.TableDataTreePane; import com.fr.design.designer.TargetComponent; import com.fr.design.designer.beans.AdapterBus; +import com.fr.design.designer.beans.ComponentAdapter; import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.Painter; import com.fr.design.designer.beans.actions.CopyAction; @@ -24,6 +25,7 @@ import com.fr.design.designer.beans.actions.MoveToBottomAction; import com.fr.design.designer.beans.actions.MoveToTopAction; import com.fr.design.designer.beans.actions.MoveUpAction; import com.fr.design.designer.beans.actions.PasteAction; +import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; import com.fr.design.designer.beans.adapters.layout.DefaultDesignerBaseOperate; import com.fr.design.designer.beans.adapters.layout.DesignerBaseOperate; import com.fr.design.designer.beans.adapters.layout.FRParameterLayoutAdapter; @@ -36,6 +38,7 @@ import com.fr.design.designer.beans.location.Location; import com.fr.design.designer.beans.location.RootResizeDirection; import com.fr.design.designer.beans.models.AddingModel; import com.fr.design.designer.beans.models.DraggingModel; +import com.fr.design.designer.beans.models.ModelUtil; import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.beans.models.StateModel; import com.fr.design.designer.creator.XChartEditor; @@ -1163,18 +1166,10 @@ public class FormDesigner extends TargetComponent