diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/DraggingModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/DraggingModel.java index 6308ff70b5..95e003faf3 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/DraggingModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/DraggingModel.java @@ -14,7 +14,6 @@ public class DraggingModel { private MouseEvent currentDragEvent; private int creatorLeftTopX = -999; // 隐藏 private int creatorLeftTopY = -999; // 隐藏 - private boolean dragNewWidget; // 是否正在拖拽一个新的组件下来 public DraggingModel() { @@ -40,11 +39,6 @@ public class DraggingModel { return this; } - public DraggingModel dragNewWidget(boolean dragNewWidget) { - this.dragNewWidget = dragNewWidget; - return this; - } - public FormDesigner getDesigner() { return designer; } @@ -79,10 +73,6 @@ public class DraggingModel { return creatorLeftTopY; } - public boolean isDragNewWidget() { - return dragNewWidget; - } - public void moveTo(int x, int y) { XLayoutContainer container = designer.getDraggingHotspotLayout(); LayoutAdapter adapter = container.getLayoutAdapter(); 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 aa58d713e5..62e256379c 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 @@ -264,11 +264,7 @@ public class FormCreatorDropTarget extends DropTarget { Point loc = dtde.getLocation(); int x = designer.getRelativeX(loc.x); int y = designer.getRelativeY(loc.y); - if (model.isDragNewWidget()) { - designer.addNewWidget(creator, x, y); - } else { - designer.changeWidgetPlace(creator, x, y); - } + designer.addWidgetToForm(creator, x, 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 a703512aba..0e28ef3b69 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 @@ -1252,12 +1252,12 @@ public class FormDesigner extends TargetComponent
implements TreeSelection return; } + instantiateCreator(xCreator); draggingModel = new DraggingModel() .designer(this) .creator(xCreator) .startDragEvent(startDragEvent) - .currentDragEvent(currentDragEvent) - .dragNewWidget(true); + .currentDragEvent(currentDragEvent); this.setDropTarget(new FormCreatorDropTarget(this, xCreator)); repaint(); } @@ -1273,12 +1273,12 @@ public class FormDesigner extends TargetComponent implements TreeSelection if (currentDragEvent == null || this.getDropTarget() != null) { return; } + backUpCreator(xCreator); draggingModel = new DraggingModel() .designer(this) .creator(xCreator) .startDragEvent(startDragEvent) - .currentDragEvent(currentDragEvent) - .dragNewWidget(false); + .currentDragEvent(currentDragEvent); XLayoutContainer container = this.getDraggingHotspotLayout(); LayoutAdapter adapter = container.getLayoutAdapter(); adapter.dragging(this.getDraggingModel()); @@ -1990,7 +1990,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection return spacingLineDrawer; } - private void instantiateCreator(XCreator creator) { + public void instantiateCreator(XCreator creator) { ModelUtil.renameWidgetName(this.getTarget(), creator); creator.addNotify(); @@ -1999,18 +1999,12 @@ public class FormDesigner extends TargetComponent implements TreeSelection creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter); } - public void addNewWidget(XCreator creator, int x, int y) { - instantiateCreator(creator); - addWidgetToForm(creator, x, y); - } - - public void changeWidgetPlace(XCreator creator, int x, int y) { + public void backUpCreator(XCreator creator) { creator.backupCurrentSize(); creator.backupParent(); - addWidgetToForm(creator, x, y); } - private void addWidgetToForm(XCreator creator, int x, int y) { + public void addWidgetToForm(XCreator creator, int x, int y) { if(creator == null) { return; } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/GuideCreateUtils.java b/designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/GuideCreateUtils.java index bb21208740..bb651cce93 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/GuideCreateUtils.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/GuideCreateUtils.java @@ -130,12 +130,13 @@ public class GuideCreateUtils { return; } FormDesigner designer = GuideCreateUtils.getFormDesigner(); - designer.getSelectionModel().selectACreator(xLayoutContainer); if (dragNewComponent) { - designer.addNewWidget(xCreator, xLayoutContainer.getX(), xLayoutContainer.getY()); + designer.instantiateCreator(xCreator); } else { - designer.changeWidgetPlace(xCreator, xLayoutContainer.getX(), xLayoutContainer.getY()); + designer.backUpCreator(xCreator); } + designer.getSelectionModel().selectACreator(xLayoutContainer); + designer.addWidgetToForm(xCreator, xLayoutContainer.getX(), xLayoutContainer.getY()); designer.getSelectionModel().selectACreator(xCreator); }