From baba369ca7346706326d53a92b46c7b04822cf45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E7=A3=8A?= <294531121@qq.com> Date: Fri, 31 Dec 2021 17:36:24 +0800 Subject: [PATCH 01/18] =?UTF-8?q?REPORT-64149=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=8B=96=E6=8B=BD=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/beans/ComponentAdapter.java | 27 +-- .../design/designer/beans/LayoutAdapter.java | 22 +++ .../component/CompositeComponentAdapter.java | 17 -- .../layout/AbstractLayoutAdapter.java | 31 ++++ .../layout/FRAbsoluteLayoutAdapter.java | 15 ++ .../adapters/layout/FRBodyLayoutAdapter.java | 8 +- .../adapters/layout/FRFitLayoutAdapter.java | 28 ++++ .../designer/beans/models/AddingModel.java | 42 +---- .../designer/beans/models/DraggingModel.java | 88 ++++++++++ .../mainframe/EditingMouseListener.java | 155 ++++++------------ .../mainframe/FormCreatorDropTarget.java | 16 +- .../com/fr/design/mainframe/FormDesigner.java | 69 +++++--- .../fr/design/mainframe/FormDesignerUI.java | 32 ++-- .../fr/design/mainframe/ToolBarButton.java | 17 +- .../share/ui/block/LocalWidgetBlock.java | 4 +- .../share/ui/block/OnlineWidgetBlock.java | 2 +- .../guide/creator/GuideCreateUtils.java | 2 +- 17 files changed, 333 insertions(+), 242 deletions(-) create mode 100644 designer-form/src/main/java/com/fr/design/designer/beans/models/DraggingModel.java diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/ComponentAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/ComponentAdapter.java index 174f56ea2..b296da48b 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/ComponentAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/ComponentAdapter.java @@ -1,35 +1,24 @@ package com.fr.design.designer.beans; -import java.awt.Graphics; -import java.awt.event.MouseEvent; -import java.util.ArrayList; - -import javax.swing.JComponent; -import javax.swing.JPopupMenu; - import com.fr.design.beans.GroupModel; import com.fr.design.designer.beans.events.DesignerEditor; import com.fr.design.designer.creator.PropertyGroupPane; +import javax.swing.JComponent; +import javax.swing.JPopupMenu; +import java.awt.event.MouseEvent; +import java.util.ArrayList; + /** * 组件适配器接口 * 主要目的是为具体组件提供特殊设计行为 */ public interface ComponentAdapter { - /** - * 在组件选择面板上选择了组件类型后,在设计界面上跟随鼠标移动用来代表当前要添加组件的图形 - * 一般使用组件自身的图形代替。 - * - * @param component 要添加的组件 - * @param g 当前设计器的图形上下文对象 - */ - void paintComponentMascot(Graphics g); - /** * 当鼠标在此设计组件上右键点击时,该方法根据上下文和组件类型提供弹出响应的菜单 * - * @param 引发弹出菜单的鼠标事件 + * @param e 引发弹出菜单的鼠标事件 * * @return 弹出菜单 */ @@ -49,7 +38,7 @@ public interface ComponentAdapter { /** * 提供双击设计器的编辑器 - * @param bean 鼠标双击的被设计组件 + * * @return 被设计的编辑器 */ public DesignerEditor extends JComponent> getDesignerEditor(); @@ -57,5 +46,5 @@ public interface ComponentAdapter { /** * 实例化组件的适配器后,在这儿进行初始化 */ - void initialize(); + void initialize(); } \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/LayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/LayoutAdapter.java index 3c0c2bd5f..060bbbc90 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/LayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/LayoutAdapter.java @@ -3,11 +3,15 @@ package com.fr.design.designer.beans; import com.fr.design.beans.GroupModel; import com.fr.design.designer.beans.adapters.layout.DefaultDesignerBaseOperate; import com.fr.design.designer.beans.adapters.layout.DesignerBaseOperate; +import com.fr.design.designer.beans.models.DraggingModel; import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.treeview.DefaultXCreatorTreeCellRender; import com.fr.design.designer.treeview.XCreatorTreeCellRender; +import java.awt.Dimension; +import java.awt.Graphics; + /** * 该接口是LayoutManager的BeanInfo类。标准Java平台没有提供布局管理器的BeanInfo类, * 对于界面设计工具来说还需一些特殊的行为。 @@ -140,4 +144,22 @@ public interface LayoutAdapter { default void dragOver(XCreator xCreator, SelectionModel selectionModel, int x, int y) { }; + + void dragging(DraggingModel model); + + /** + * 绘制组件拖拽阴影 + * + * @param g 当前设计器的图形上下文对象 + * @param xCreator 被拖拽的组件 + */ + void paintComponentMascot(Graphics g, XCreator xCreator); + + /** + * 描述组件被拖拽的时候应该显示的尺寸 + * + * @param creator 被拖拽的组件 + * @return 组件大小 + */ + Dimension getDragSize(XCreator creator); } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/component/CompositeComponentAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/component/CompositeComponentAdapter.java index cb7a7a620..d97b85c5a 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/component/CompositeComponentAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/component/CompositeComponentAdapter.java @@ -23,13 +23,9 @@ import com.fr.stable.core.PropertyChangeAdapter; import javax.swing.Action; import javax.swing.JComponent; import javax.swing.JPopupMenu; -import java.awt.AlphaComposite; import java.awt.Component; import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; import java.awt.event.MouseEvent; -import java.awt.image.BufferedImage; import java.beans.IntrospectionException; import java.util.ArrayList; import java.util.Collections; @@ -63,19 +59,6 @@ public class CompositeComponentAdapter implements ComponentAdapter { } } - @Override - public void paintComponentMascot(Graphics g) { - //自适应交叉点渲染有点问题,拖拽的控件设置成半透明 - Graphics2D g2d = (Graphics2D) g; - AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f); - g2d.setComposite(composite); - BufferedImage im = new BufferedImage(xCreator.getWidth(), xCreator.getHeight(), BufferedImage.TYPE_INT_ARGB); - xCreator.paint(im.getGraphics()); - g.drawImage(im, 0, 0, xCreator.initEditorSize().width - 1, xCreator.initEditorSize().height - 1, null); - g.setColor(XCreatorConstants.RESIZE_BOX_BORDER_COLOR); - g.drawRect(0, 0, xCreator.initEditorSize().width - 1, xCreator.initEditorSize().height - 1); - } - @Override public JPopupMenu getContextPopupMenu(MouseEvent e) { JPopupMenu popupMenu = new JPopupMenu(); diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java index 7d287e5a5..e0f79e65e 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java @@ -4,16 +4,23 @@ 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.DraggingModel; import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.beans.painters.NullPainter; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XWidgetCreator; +import com.fr.design.form.util.XCreatorConstants; import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.gui.LayoutUtils; import com.fr.general.ComparatorUtils; +import java.awt.AlphaComposite; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.LayoutManager; +import java.awt.image.BufferedImage; public abstract class AbstractLayoutAdapter implements LayoutAdapter { @@ -209,4 +216,28 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter { selectionModel.removeCreator(xCreator, xCreator.getWidth(), xCreator.getHeight()); selectionModel.setSelectedCreator(container); } + + @Override + public void dragging(DraggingModel model) { + + } + + @Override + public void paintComponentMascot(Graphics g, XCreator xCreator) { + //自适应交叉点渲染有点问题,拖拽的控件设置成半透明 + int dragWidth = this.getDragSize(xCreator).width, dragHeight = this.getDragSize(xCreator).height; + Graphics2D g2d = (Graphics2D) g; + AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f); + g2d.setComposite(composite); + BufferedImage im = new BufferedImage(xCreator.getWidth(), xCreator.getHeight(), BufferedImage.TYPE_INT_ARGB); + xCreator.paint(im.getGraphics()); + g.drawImage(im, 0, 0, dragWidth - 1, dragHeight - 1, null); + g.setColor(XCreatorConstants.RESIZE_BOX_BORDER_COLOR); + g.drawRect(0, 0, dragWidth - 1, dragHeight - 1); + } + + @Override + public Dimension getDragSize(XCreator xCreator) { + return xCreator.initEditorSize(); + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java index e4426f61a..3f49ebe3f 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java @@ -3,10 +3,12 @@ package com.fr.design.designer.beans.adapters.layout; 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.models.DraggingModel; import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter; import com.fr.design.designer.creator.*; import com.fr.design.designer.properties.BoundsGroupModel; import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel; +import com.fr.design.mainframe.FormDesigner; import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.gui.LayoutUtils; import com.fr.form.ui.Widget; @@ -15,6 +17,7 @@ import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import java.awt.*; +import java.awt.event.MouseEvent; public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { //是不是添加到父容器上 @@ -345,4 +348,16 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container; return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout); } + + @Override + public void dragging(DraggingModel model) { + FormDesigner designer = model.getDesigner(); + MouseEvent dragEvent = model.getDragEvent(); + designer.getStateModel().dragging(dragEvent); + } + + @Override + public Dimension getDragSize(XCreator xCreator) { + return xCreator.getSize(); + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java index 5a31bab40..f4c045861 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java @@ -6,12 +6,13 @@ import com.fr.design.designer.creator.XWParameterLayout; import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; import com.fr.design.utils.ComponentUtils; import com.fr.form.ui.PaddingMargin; -import com.fr.form.ui.container.WBorderLayout; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.general.ComparatorUtils; -import java.awt.*; -import java.util.*; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Rectangle; +import java.util.ArrayList; /** * 这个类用作fit和absolute的父类,存放公共的方法 @@ -1182,5 +1183,4 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter { this.isCalculateChildPos = false; return childPosition; } - } 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 9871d1b32..db40eec0f 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,6 +8,8 @@ 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; import com.fr.design.designer.creator.XCreatorUtils; @@ -22,6 +24,8 @@ import com.fr.design.designer.properties.FRFitLayoutConstraints; import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel; import com.fr.design.designer.treeview.XCreatorTreeCellRender; import com.fr.design.fun.FormWidgetOptionProvider; +import com.fr.design.mainframe.FormCreatorDropTarget; +import com.fr.design.mainframe.FormDesigner; import com.fr.design.utils.ComponentUtils; import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.container.WAbsoluteLayout; @@ -34,6 +38,7 @@ import com.fr.general.act.BorderPacker; import java.awt.Component; import java.awt.Dimension; import java.awt.Rectangle; +import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -1244,4 +1249,27 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { public void dragOver(XCreator xCreator, SelectionModel selectionModel,int x, int y) { frLayoutState.dragOver(xCreator, selectionModel,x,y); } + + @Override + public void dragging(DraggingModel model) { + FormDesigner designer = model.getDesigner(); + MouseEvent lastPressEvent = model.getLastPressEvent(); + MouseEvent dragEvent = model.getDragEvent(); + XCreator creator = model.getCreator(); + if ((lastPressEvent == null) || (creator == null)) { + return; + } + + 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.repaint(); + } + dragEvent.consume(); + } + } } 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 ba0cf5dd0..f33810bae 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 @@ -20,18 +20,13 @@ public class AddingModel { // 当前要添加的组件 private XCreator creator; - // 记录当前鼠标的位置信息 - private int currentX; - private int currentY; private boolean added; private boolean addedIllegal = false; // 有时候是添加完成了,但是添加会造成某些控件size不合法,例如tab + private FormDesigner designer; public AddingModel(FormDesigner designer, XCreator xCreator) { this.creator = xCreator; instantiateCreator(designer); - // 初始的时候隐藏该组件的图标 - currentY = -this.creator.getWidth(); - currentX = -this.creator.getHeight(); } /** @@ -52,16 +47,6 @@ public class AddingModel { this.creator = xCreator; this.creator.backupCurrentSize(); this.creator.backupParent(); - currentX = x - (xCreator.initEditorSize().width / 2); - currentY = y - (xCreator.initEditorSize().height / 2); - } - - /** - * 隐藏当前组件的图标 - */ - public void reset() { - currentX = -this.creator.getWidth(); - currentY = -this.creator.getHeight(); } public String getXCreatorName(FormDesigner designer, XCreator x) { @@ -76,35 +61,10 @@ public class AddingModel { return def + i; } - - public int getCurrentX() { - return currentX; - } - - public int getCurrentY() { - return currentY; - } - - - /** - * 移动组件图标到鼠标事件发生的位置 - * - * @param x 坐标 - * @param y 坐标 - */ - public void moveTo(int x, int y) { - currentX = x - (this.creator.initEditorSize().width / 2); - currentY = y - (this.creator.initEditorSize().height / 2); - } - public XCreator getXCreator() { return this.creator; } - public boolean need2paint(){ - return currentX + this.creator.getWidth() > 0 && currentY + this.creator.getHeight() > 0; - } - /** * 当前组件是否已经添加到某个容器中 * 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 new file mode 100644 index 000000000..47a50327e --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/DraggingModel.java @@ -0,0 +1,88 @@ +package com.fr.design.designer.beans.models; + +import com.fr.design.designer.beans.LayoutAdapter; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.mainframe.FormDesigner; + +import java.awt.event.MouseEvent; + +public class DraggingModel { + private FormDesigner designer; + private XCreator creator; + private MouseEvent lastPressEvent; + private MouseEvent dragEvent; + private int creatorLeftTopX = -999; // 隐藏 + private int creatorLeftTopY = -999; // 隐藏 + + public DraggingModel() { + + } + + public DraggingModel designer(FormDesigner designer) { + this.designer = designer; + return this; + } + + public DraggingModel lastPressEvent(MouseEvent lastPressEvent) { + this.lastPressEvent = lastPressEvent; + return this; + } + + public DraggingModel dragEvent(MouseEvent dragEvent) { + this.dragEvent = dragEvent; + return this; + } + + public DraggingModel creator(XCreator creator) { + this.creator = creator; + return this; + } + + public FormDesigner getDesigner() { + return designer; + } + + public MouseEvent getLastPressEvent() { + return lastPressEvent; + } + + public MouseEvent getDragEvent() { + return dragEvent; + } + + public XCreator getCreator() { + return creator; + } + + /** + * 获取被拖拽组件当前随着鼠标移动时应当所在的左上角横坐标 + * + * @return + */ + public int getCreatorLeftTopX() { + return creatorLeftTopX; + } + + /** + * 获取被拖拽组件当前随着鼠标移动时应当所在的左上角纵坐标 + * + * @return + */ + public int getCreatorLeftTopY() { + return creatorLeftTopY; + } + + public void moveTo(int x, int y) { + XLayoutContainer container = designer.getDraggingHotspotLayout(); + LayoutAdapter adapter = container.getLayoutAdapter(); + + creatorLeftTopX = x - adapter.getDragSize(creator).width / 2; + creatorLeftTopY = y - adapter.getDragSize(creator).height / 2; + } + + public void reset() { + creatorLeftTopX = -creator.getWidth(); + creatorLeftTopY = -creator.getHeight(); + } +} 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 b0463a685..5053ae013 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 @@ -1,14 +1,15 @@ package com.fr.design.mainframe; -import com.fr.base.BaseUtils; import com.fr.base.vcs.DesignerMode; import com.fr.common.inputevent.InputEventBaseOnOS; 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.events.DesignerEditor; import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.location.Direction; import com.fr.design.designer.beans.location.Location; +import com.fr.design.designer.beans.models.DraggingModel; import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.beans.models.StateModel; import com.fr.design.designer.creator.XBorderStyleWidgetCreator; @@ -25,25 +26,18 @@ import com.fr.design.designer.creator.cardlayout.XCardAddButton; import com.fr.design.designer.creator.cardlayout.XCardSwitchButton; import com.fr.design.designer.creator.cardlayout.XWCardLayout; import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; -import com.fr.design.form.util.XCreatorConstants; -import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.gui.xpane.ToolTipEditor; -import com.fr.design.icon.IconPathConstants; import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.LayoutUtils; import com.fr.general.ComparatorUtils; import com.fr.stable.ArrayUtils; -import com.fr.stable.Constants; -import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JPopupMenu; -import javax.swing.JWindow; import javax.swing.SwingUtilities; import javax.swing.event.MouseInputAdapter; -import java.awt.Color; import java.awt.Container; import java.awt.Cursor; import java.awt.Insets; @@ -95,9 +89,6 @@ public class EditingMouseListener extends MouseInputAdapter { private DesignerEditor extends JComponent> currentEditor; private XCreator currentXCreator; - //备份开始拖动的位置和大小 - private Rectangle dragBackupBounds; - private int pressX; private int pressY; @@ -121,40 +112,12 @@ public class EditingMouseListener extends MouseInputAdapter { private XElementCase xElementCase; private XChartEditor xChartEditor; - private JWindow promptWindow = new JWindow(); - public EditingMouseListener(FormDesigner designer) { this.designer = designer; stateModel = designer.getStateModel(); selectionModel = designer.getSelectionModel(); - UIButton promptButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Forbid_Drag_Into_Adapt_Pane"), BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); - this.promptWindow.add(promptButton); - } - - private void promptUser(int x, int y, XLayoutContainer container) { - if (!selectionModel.getSelection().getSelectedCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)) { - promptWidgetForbidEnter(x, y, container); - } else { - cancelPromptWidgetForbidEnter(); - } } - private void promptWidgetForbidEnter(int x, int y, XLayoutContainer container) { - container.setBorder(BorderFactory.createLineBorder(Color.RED, Constants.LINE_MEDIUM)); - int screenX = (int) designer.getArea().getLocationOnScreen().getX(); - int screenY = (int) designer.getArea().getLocationOnScreen().getY(); - this.promptWindow.setSize(promptWindow.getPreferredSize()); - this.promptWindow.setPreferredSize(promptWindow.getPreferredSize()); - promptWindow.setLocation(screenX + x + GAP, screenY + y + GAP); - promptWindow.setVisible(true); - } - - private void cancelPromptWidgetForbidEnter() { - designer.getRootComponent().setBorder(BorderFactory.createLineBorder(XCreatorConstants.LAYOUT_SEP_COLOR, Constants.LINE_THIN)); - promptWindow.setVisible(false); - } - - /** * 按下 * @@ -181,18 +144,14 @@ public class EditingMouseListener extends MouseInputAdapter { } if (dir == Location.outer) { - if (designer.isDrawLineMode()) { - designer.updateDrawLineMode(e); + if (selectionModel.hasSelectionComponent() + && selectionModel.getSelection().getRelativeBounds().contains( + designer.getHorizontalScaleValue() + e.getX(), + designer.getVerticalScaleValue() + e.getY())) { + lastPressEvent = e; + lastXCreator = selectionModel.getSelection().getSelectedCreator(); } else { - if (selectionModel.hasSelectionComponent() - && selectionModel.getSelection().getRelativeBounds().contains( - designer.getHorizontalScaleValue() + e.getX(), - designer.getVerticalScaleValue() + e.getY())) { - lastPressEvent = e; - lastXCreator = selectionModel.getSelection().getSelectedCreator(); - } else { - stateModel.startSelecting(e); - } + stateModel.startSelecting(e); } } else { stateModel.startResizing(e); @@ -258,13 +217,6 @@ public class EditingMouseListener extends MouseInputAdapter { private void mouseDraggingRelease(MouseEvent e) { // 当前鼠标所在的组件 XCreator hoveredComponent = designer.getComponentAt(e.getX(), e.getY()); - if (designer.isWidgetsIntersect() && dragBackupBounds != null && hoveredComponent != null) { - XCreator selectionXCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); - if (selectionXCreator != null) { - selectionXCreator.setBounds(dragBackupBounds.x, dragBackupBounds.y, dragBackupBounds.width, dragBackupBounds.height); - } - } - dragBackupBounds = null; // 拉伸时鼠标拖动过快,导致所在组件获取会为空 if (hoveredComponent == null && e.getY() < 0) { // bug63538 @@ -285,7 +237,6 @@ public class EditingMouseListener extends MouseInputAdapter { selectionModel.deleteSelection(); designer.setPainter(null); } - cancelPromptWidgetForbidEnter(); } } @@ -499,61 +450,56 @@ public class EditingMouseListener extends MouseInputAdapter { if (DesignerMode.isAuthorityEditing()) { return; } - boolean shiftSelecting = e.isShiftDown(); - boolean ctrlSelecting = InputEventBaseOnOS.isControlDown(e); - int currentCursorType = this.designer.getCursor().getType(); - boolean shiftResizing = e.isShiftDown() && ( Cursor.SW_RESIZE_CURSOR <= currentCursorType && currentCursorType <= Cursor.E_RESIZE_CURSOR); - if ((shiftSelecting || ctrlSelecting) && !shiftResizing && !stateModel.isSelecting()) { + if (SwingUtilities.isRightMouseButton(e)) { + return; + } + + if (isMultiKeySelectingDrag(e)) { stateModel.startSelecting(e); } - // 如果当前是左键拖拽状态,拖拽组件 - if (stateModel.dragable()) { - if (SwingUtilities.isRightMouseButton(e)) { - return; - } else { - stateModel.dragging(e); - // 获取e所在的焦点组件 - XCreator hotspot = designer.getComponentAt(e.getX(), e.getY()); - if (dragBackupBounds == null) { - XCreator selectingXCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); - if (selectingXCreator != null) { - dragBackupBounds = new Rectangle(selectingXCreator.getX(), selectingXCreator.getY(), selectingXCreator.getWidth(), selectingXCreator.getHeight()); - } - } - // 拉伸时鼠标拖动过快,导致所在组件获取会为空 - if (hotspot == null) { - return; - } - // 获取焦点组件所在的焦点容器 - XLayoutContainer container = XCreatorUtils.getHotspotContainer(hotspot); - //提示组件是否可以拖入 - promptUser(e.getX(), e.getY(), container); - } - } else if (designer.isDrawLineMode()) { - if (stateModel.prepareForDrawLining()) { - stateModel.drawLine(e); - } - } else if (stateModel.isSelecting() && (selectionModel.getHotspotBounds() != null)) { - // 如果是拖拽选择区域状态,则更新选择区域 + + if (isSelectionDrag()) { stateModel.changeSelection(e); - } else { - if ((lastPressEvent == null) || (lastXCreator == null)) { - return; - } - if (e.getPoint().distance(lastPressEvent.getPoint()) > minDragSize) { - //参数面板和自适应布局不支持拖拽 - if (lastXCreator.isSupportDrag()) { - designer.startDraggingComponent(lastXCreator, lastPressEvent, e.getX(), e.getY()); - } - e.consume(); - lastPressEvent = null; - } + return; } + + System.out.println("===set==="); + designer.setDraggingModel(new DraggingModel() + .designer(designer) + .creator(lastXCreator) + .lastPressEvent(lastPressEvent) + .dragEvent(e)); + XLayoutContainer container = designer.getDraggingHotspotLayout(); + LayoutAdapter adapter = container.getLayoutAdapter(); + adapter.dragging(designer.getDraggingModel()); + e.translatePoint(oldX - e.getX(), oldY - e.getY()); designer.repaint(); } + /** + * 当前拖拽是否是正在shift或者control拖拽一个选择框 + * @param e + * @return + */ + private boolean isMultiKeySelectingDrag(MouseEvent e) { + boolean shiftSelecting = e.isShiftDown(); + boolean ctrlSelecting = InputEventBaseOnOS.isControlDown(e); + int currentCursorType = this.designer.getCursor().getType(); + boolean shiftResizing = e.isShiftDown() && ( Cursor.SW_RESIZE_CURSOR <= currentCursorType && currentCursorType <= Cursor.E_RESIZE_CURSOR); + return (shiftSelecting || ctrlSelecting) && !shiftResizing && !stateModel.isSelecting(); + } + + /** + * 是否正在拖拽选择框 + * + * @return + */ + private boolean isSelectionDrag() { + return stateModel.isSelecting() && selectionModel.getHotspotBounds() != null; + } + //当前编辑的组件是在布局中,鼠标点击布局外部,需要一次性将布局及其父布局都置为不可编辑 private void setTopLayoutUnEditable(XLayoutContainer clickedTopLayout, XLayoutContainer clickingTopLayout) { //双击的前后点击click为相同对象,过滤掉 @@ -718,7 +664,6 @@ public class EditingMouseListener extends MouseInputAdapter { if (designer.getCursor().getType() != Cursor.DEFAULT_CURSOR && !(e.isShiftDown() || InputEventBaseOnOS.isControlDown(e))) { designer.setCursor(Cursor.getDefaultCursor()); } - cancelPromptWidgetForbidEnter(); e.translatePoint(oldX - e.getX(), oldY - e.getY()); } 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 5eb354c6c..2e4a5e6d4 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) { // 将要添加的组件图标移动到鼠标下的位置 - addingModel.moveTo(x, y); + designer.getDraggingModel().moveTo(x, y); designer.repaint(); } private void exiting() { cancelPromptWidgetForbidEnter(); // 隐藏组件图标 - addingModel.reset(); + designer.getDraggingModel().reset(); designer.setPainter(null); designer.repaint(); } private void hovering(int x, int y) { // 当前位置移植鼠标e所在的位置 - addingModel.moveTo(x, y); + designer.getDraggingModel().moveTo(x, y); // 获取e所在的焦点组件 XCreator hotspot = designer.getComponentAt(x, y); // 获取焦点组件所在的焦点容器 @@ -290,7 +290,15 @@ public class FormCreatorDropTarget extends DropTarget { int y = designer.getRelativeY(loc.y); hovering(x, y); tabDragInner.canDragIn(designer.getComponentAt(x, y), x, y); - designer.draggingComponent(x, y); + + XCreator xCreator = designer.getAddingModel().getXCreator(); + XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(xCreator); + if (parent!= null && parent.getLayoutAdapter()!=null){ + parent.getLayoutAdapter().dragOver(xCreator, designer.getSelectionModel(), x, y); + } + + // 触发状态添加模式事件 + designer.repaint(); } /** 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 adc59581a..ecf67bf54 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 @@ -19,8 +19,8 @@ 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.layout.DefaultDesignerBaseOperate; -import com.fr.design.designer.beans.adapters.layout.FRParameterLayoutAdapter; import com.fr.design.designer.beans.adapters.layout.DesignerBaseOperate; +import com.fr.design.designer.beans.adapters.layout.FRParameterLayoutAdapter; import com.fr.design.designer.beans.events.CreatorEventListenerTable; import com.fr.design.designer.beans.events.DesignerEditListener; import com.fr.design.designer.beans.events.DesignerEvent; @@ -28,6 +28,7 @@ import com.fr.design.designer.beans.location.Direction; 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.SelectionModel; import com.fr.design.designer.beans.models.StateModel; import com.fr.design.designer.creator.XChartEditor; @@ -144,6 +145,7 @@ public class FormDesigner extends TargetComponent