diff --git a/designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java b/designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java index dde94561d9..de03fb61b5 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java @@ -198,6 +198,7 @@ public class EditingMouseListener extends MouseInputAdapter { } lastPressEvent = null; lastXCreator = null; + designer.stopDragging(); e.translatePoint(oldX - e.getX(), oldY - e.getY()); if (isAutoFire(transEvent, clickEvent)) { // click只有在mouseReleased和mousePressed前后x/y坐标相等时才会被触发在mouseReleased之后 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 2e4a5e6d4c..66a0edeea3 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 @@ -168,21 +168,21 @@ public class FormCreatorDropTarget extends DropTarget { private void entering(int x, int y) { // 将要添加的组件图标移动到鼠标下的位置 - designer.getDraggingModel().moveTo(x, y); + designer.updateDraggingPosition(x, y); designer.repaint(); } private void exiting() { cancelPromptWidgetForbidEnter(); // 隐藏组件图标 - designer.getDraggingModel().reset(); + designer.resetDraggingPosition(); designer.setPainter(null); designer.repaint(); } private void hovering(int x, int y) { // 当前位置移植鼠标e所在的位置 - designer.getDraggingModel().moveTo(x, y); + designer.updateDraggingPosition(x, y); // 获取e所在的焦点组件 XCreator hotspot = designer.getComponentAt(x, y); // 获取焦点组件所在的焦点容器 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 ecf67bf544..66626b1711 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 @@ -785,6 +785,31 @@ public class FormDesigner extends TargetComponent
implements TreeSelection repaint(); } + /** + * 停止拖拽 + */ + public void stopDragging() { + draggingModel = null; + } + + /** + * 更新拖拽model的位置 + */ + public void updateDraggingPosition(int x, int y) { + if (draggingModel != null) { + draggingModel.moveTo(x, y); + } + } + + /** + * 重置拖拽model的位置 + */ + public void resetDraggingPosition() { + if (draggingModel != null) { + draggingModel.reset(); + } + } + /** * 设置其UI类为DesignerUI,负责渲染 */ @@ -1202,15 +1227,6 @@ public class FormDesigner extends TargetComponent implements TreeSelection repaint(); } - public void startDraggingNewWidget(XCreator xCreator, MouseEvent lastPressEvent, MouseEvent dragEvent) { - draggingModel = new DraggingModel() - .designer(this) - .creator(xCreator) - .lastPressEvent(lastPressEvent) - .dragEvent(dragEvent); - startDraggingNewWidget(xCreator); - } - /** * 绑定transferHandler,主要实现拖拽结束的回调,在拖拽已有组件的时候有用,需要在回调里面手动把拖拽失败的组件复原,否则组件会消失 * diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java b/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java index 94b61737e7..d1b6f41f72 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java @@ -200,6 +200,9 @@ public class FormDesignerUI extends ComponentUI { */ private void paintDraggingBean(Graphics g) { DraggingModel model = designer.getDraggingModel(); + if (model == null) { + return; + } XCreator bean = model.getCreator(); int x = model.getCreatorLeftTopX(); int y = model.getCreatorLeftTopY() ; diff --git a/designer-form/src/main/java/com/fr/design/mainframe/ToolBarButton.java b/designer-form/src/main/java/com/fr/design/mainframe/ToolBarButton.java index 6b92cdaf0c..dec015e9f0 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/ToolBarButton.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/ToolBarButton.java @@ -1,6 +1,7 @@ package com.fr.design.mainframe; import com.fr.base.vcs.DesignerMode; +import com.fr.design.designer.beans.models.DraggingModel; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreatorUtils; import com.fr.design.file.HistoryTemplateListCache; @@ -75,7 +76,7 @@ public class ToolBarButton extends UIButton implements MouseListener, MouseMotio } public void mouseReleased(MouseEvent e) { - + WidgetToolBarPane.getTarget().stopDragging(); } @Override @@ -105,7 +106,13 @@ public class ToolBarButton extends UIButton implements MouseListener, MouseMotio } if (creatorSource != null) { XCreator xCreator = XCreatorUtils.createThemedXCreator(creatorSource); - WidgetToolBarPane.getTarget().startDraggingNewWidget(xCreator, lastPressEvent, e); + FormDesigner designer = WidgetToolBarPane.getTarget(); + designer.setDraggingModel(new DraggingModel() + .designer(designer) + .creator(xCreator) + .lastPressEvent(lastPressEvent) + .dragEvent(e)); + designer.startDraggingNewWidget(xCreator); FormDesignerUtils.addWidgetProcessInfo(xCreator.toData()); lastPressEvent = null; this.setBorder(null); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java index 13bb226fae..e8ed121683 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java @@ -4,6 +4,7 @@ import com.fr.base.FRContext; import com.fr.base.GraphHelper; import com.fr.base.iofile.attr.SharableAttrMark; import com.fr.design.base.mode.DesignModeContext; +import com.fr.design.designer.beans.models.DraggingModel; import com.fr.design.designer.creator.XCreator; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.form.util.XCreatorConstants; @@ -11,6 +12,7 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.WidgetToolBarPane; import com.fr.design.mainframe.share.group.ui.GroupMoveDialog; import com.fr.design.mainframe.share.ui.actions.SharedComponentPopupAction; @@ -180,6 +182,7 @@ public class LocalWidgetBlock extends PreviewWidgetBlock dealClickAction(e); } pressed = false; + WidgetToolBarPane.getTarget().stopDragging(); } @Override @@ -237,7 +240,13 @@ public class LocalWidgetBlock extends PreviewWidgetBlock if (xCreator == null) { return; } - WidgetToolBarPane.getTarget().startDraggingNewWidget(xCreator, lastPressEvent, e); + FormDesigner designer = WidgetToolBarPane.getTarget(); + designer.setDraggingModel(new DraggingModel() + .designer(designer) + .creator(xCreator) + .lastPressEvent(lastPressEvent) + .dragEvent(e)); + designer.startDraggingNewWidget(xCreator); lastPressEvent = null; this.setBorder(null); } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java index 539b8d25ed..471540ffd2 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java @@ -4,6 +4,7 @@ import com.fr.base.GraphHelper; import com.fr.base.iofile.attr.SharableAttrMark; import com.fr.design.DesignerEnvManager; import com.fr.design.base.mode.DesignModeContext; +import com.fr.design.designer.beans.models.DraggingModel; import com.fr.design.designer.creator.XCreator; import com.fr.design.form.util.XCreatorConstants; import com.fr.design.gui.ilable.UILabel; @@ -11,6 +12,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.login.DesignerLoginHelper; import com.fr.design.login.DesignerLoginSource; +import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.WidgetToolBarPane; import com.fr.design.mainframe.share.collect.ComponentCollector; import com.fr.design.mainframe.share.ui.online.AbstractOnlineWidgetSelectPane; @@ -163,6 +165,12 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock { } } + @Override + public void mouseReleased(MouseEvent e) { + super.mouseReleased(e); + WidgetToolBarPane.getTarget().stopDragging(); + } + @Override public void mouseDragged(MouseEvent e) { if (!getWidget().isCompatibleWithCurrentEnv()) { @@ -200,7 +208,13 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock { } else { xCreator = ShareComponentUtils.createXCreator(creatorSource, shareId, bindInfo); } - WidgetToolBarPane.getTarget().startDraggingNewWidget(xCreator, lastPressEvent, e); + FormDesigner designer = WidgetToolBarPane.getTarget(); + designer.setDraggingModel(new DraggingModel() + .designer(designer) + .creator(xCreator) + .lastPressEvent(lastPressEvent) + .dragEvent(e)); + designer.startDraggingNewWidget(xCreator); lastPressEvent = null; this.setBorder(null); }