Browse Source

REPORT-66884 修正拖拽组件时候备份组件的时机

bugfix/11.0
方磊 3 years ago
parent
commit
776c38aa4e
  1. 10
      designer-form/src/main/java/com/fr/design/designer/beans/models/DraggingModel.java
  2. 6
      designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java
  3. 20
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java
  4. 7
      designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/GuideCreateUtils.java

10
designer-form/src/main/java/com/fr/design/designer/beans/models/DraggingModel.java

@ -14,7 +14,6 @@ public class DraggingModel {
private MouseEvent currentDragEvent; private MouseEvent currentDragEvent;
private int creatorLeftTopX = -999; // 隐藏 private int creatorLeftTopX = -999; // 隐藏
private int creatorLeftTopY = -999; // 隐藏 private int creatorLeftTopY = -999; // 隐藏
private boolean dragNewWidget; // 是否正在拖拽一个新的组件下来
public DraggingModel() { public DraggingModel() {
@ -40,11 +39,6 @@ public class DraggingModel {
return this; return this;
} }
public DraggingModel dragNewWidget(boolean dragNewWidget) {
this.dragNewWidget = dragNewWidget;
return this;
}
public FormDesigner getDesigner() { public FormDesigner getDesigner() {
return designer; return designer;
} }
@ -79,10 +73,6 @@ public class DraggingModel {
return creatorLeftTopY; return creatorLeftTopY;
} }
public boolean isDragNewWidget() {
return dragNewWidget;
}
public void moveTo(int x, int y) { public void moveTo(int x, int y) {
XLayoutContainer container = designer.getDraggingHotspotLayout(); XLayoutContainer container = designer.getDraggingHotspotLayout();
LayoutAdapter adapter = container.getLayoutAdapter(); LayoutAdapter adapter = container.getLayoutAdapter();

6
designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java

@ -264,11 +264,7 @@ public class FormCreatorDropTarget extends DropTarget {
Point loc = dtde.getLocation(); Point loc = dtde.getLocation();
int x = designer.getRelativeX(loc.x); int x = designer.getRelativeX(loc.x);
int y = designer.getRelativeY(loc.y); int y = designer.getRelativeY(loc.y);
if (model.isDragNewWidget()) { designer.addWidgetToForm(creator, x, y);
designer.addNewWidget(creator, x, y);
} else {
designer.changeWidgetPlace(creator, x, y);
}
// 放到事件末尾执行 // 放到事件末尾执行
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override

20
designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java

@ -1252,12 +1252,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
return; return;
} }
instantiateCreator(xCreator);
draggingModel = new DraggingModel() draggingModel = new DraggingModel()
.designer(this) .designer(this)
.creator(xCreator) .creator(xCreator)
.startDragEvent(startDragEvent) .startDragEvent(startDragEvent)
.currentDragEvent(currentDragEvent) .currentDragEvent(currentDragEvent);
.dragNewWidget(true);
this.setDropTarget(new FormCreatorDropTarget(this, xCreator)); this.setDropTarget(new FormCreatorDropTarget(this, xCreator));
repaint(); repaint();
} }
@ -1273,12 +1273,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
if (currentDragEvent == null || this.getDropTarget() != null) { if (currentDragEvent == null || this.getDropTarget() != null) {
return; return;
} }
backUpCreator(xCreator);
draggingModel = new DraggingModel() draggingModel = new DraggingModel()
.designer(this) .designer(this)
.creator(xCreator) .creator(xCreator)
.startDragEvent(startDragEvent) .startDragEvent(startDragEvent)
.currentDragEvent(currentDragEvent) .currentDragEvent(currentDragEvent);
.dragNewWidget(false);
XLayoutContainer container = this.getDraggingHotspotLayout(); XLayoutContainer container = this.getDraggingHotspotLayout();
LayoutAdapter adapter = container.getLayoutAdapter(); LayoutAdapter adapter = container.getLayoutAdapter();
adapter.dragging(this.getDraggingModel()); adapter.dragging(this.getDraggingModel());
@ -1990,7 +1990,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
return spacingLineDrawer; return spacingLineDrawer;
} }
private void instantiateCreator(XCreator creator) { public void instantiateCreator(XCreator creator) {
ModelUtil.renameWidgetName(this.getTarget(), creator); ModelUtil.renameWidgetName(this.getTarget(), creator);
creator.addNotify(); creator.addNotify();
@ -1999,18 +1999,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter); creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter);
} }
public void addNewWidget(XCreator creator, int x, int y) { public void backUpCreator(XCreator creator) {
instantiateCreator(creator);
addWidgetToForm(creator, x, y);
}
public void changeWidgetPlace(XCreator creator, int x, int y) {
creator.backupCurrentSize(); creator.backupCurrentSize();
creator.backupParent(); 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) { if(creator == null) {
return; return;
} }

7
designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/GuideCreateUtils.java

@ -130,12 +130,13 @@ public class GuideCreateUtils {
return; return;
} }
FormDesigner designer = GuideCreateUtils.getFormDesigner(); FormDesigner designer = GuideCreateUtils.getFormDesigner();
designer.getSelectionModel().selectACreator(xLayoutContainer);
if (dragNewComponent) { if (dragNewComponent) {
designer.addNewWidget(xCreator, xLayoutContainer.getX(), xLayoutContainer.getY()); designer.instantiateCreator(xCreator);
} else { } 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); designer.getSelectionModel().selectACreator(xCreator);
} }

Loading…
Cancel
Save