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 932338a3f..4b3147c0a 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 @@ -72,7 +72,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { } XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout(); if(topLayout != null){ - if (topLayout.isEditable()){ + if (topLayout.isDragInAble() || topLayout.isEditable()){ return topLayoutAccept(creator, x, y); } //绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局 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 22d74d774..c893268ba 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 @@ -19,12 +19,7 @@ import com.fr.design.designer.creator.cardlayout.XWCardTitleLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.designer.properties.FRFitLayoutConstraints; import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel; -import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.fun.FormWidgetOptionProvider; -import com.fr.design.mainframe.FormDesigner; -import com.fr.design.mainframe.JForm; -import com.fr.design.mainframe.JTemplate; -import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.utils.ComponentUtils; import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.container.WAbsoluteLayout; @@ -169,7 +164,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { //布局控件要先判断是不是可编辑 XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator) comp).getTopLayout(); - boolean access = topLayout != null && !isMatchEdge && !topLayout.isEditable() && !topLayout.acceptType(XWAbsoluteLayout.class) && !isExtraContainer(comp); + boolean access = topLayout != null && !isMatchEdge && !topLayout.isEditable() && !topLayout.acceptType(XWAbsoluteLayout.class) && !isExtraContainer(comp) && !topLayout.isDragInAble(); if (access) { return false; } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java b/designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java index 9044d6c3c..07220df0d 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java @@ -48,6 +48,8 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme //鼠标移动到布局画出编辑层 protected boolean isMouseEnter = false; + private volatile boolean dragInAble; + public void setMouseEnter(boolean mouseEnter) { isMouseEnter = mouseEnter; } @@ -577,4 +579,11 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme return false; } + public boolean isDragInAble() { + return dragInAble; + } + + public void setDragInAble(boolean dragInAble) { + this.dragInAble = dragInAble; + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java index 2d5b5ba91..47b927505 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java @@ -447,4 +447,9 @@ public class XWCardMainBorderLayout extends XWBorderLayout { return true; } + @Override + public Dimension initEditorSize() { + return LARGEPREFERREDSIZE; + } + } 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 01a46d25b..515fd209e 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 @@ -8,6 +8,7 @@ import com.fr.design.DesignModelAdapter; import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.datapane.TableDataTreePane; import com.fr.design.designer.beans.AdapterBus; +import com.fr.design.designer.beans.ComponentAdapter; import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.Painter; import com.fr.design.designer.beans.events.DesignerEvent; @@ -66,6 +67,8 @@ public class FormCreatorDropTarget extends DropTarget { private AddingModel addingModel; private static final int GAP = 30; + private TabDragInner tabDragInner; + private JWindow promptWindow = new JWindow(); private UIButton promptButton = new UIButton("", BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); @@ -73,6 +76,7 @@ public class FormCreatorDropTarget extends DropTarget { this.designer = designer; this.addingModel = designer.getAddingModel(); this.promptWindow.add(promptButton); + this.tabDragInner = new TabDragInner(designer); } private void adding(int x, int y) { @@ -128,6 +132,7 @@ public class FormCreatorDropTarget extends DropTarget { designer.getSelectionModel().setSelectedCreators( FormSelectionUtils.rebuildSelection(xCreator, new Widget[]{widget})); designer.getEditListenerTable().fireCreatorModified(addingModel.getXCreator(), DesignerEvent.CREATOR_ADDED); + tryEditTabContainer(); } else { Toolkit.getDefaultToolkit().beep(); } @@ -137,6 +142,24 @@ public class FormCreatorDropTarget extends DropTarget { designer.stopAddingState(); } + /** + * 尝试进入tab编辑 + */ + private void tryEditTabContainer() { + XLayoutContainer belowXLayoutContainer = tabDragInner.getBelowXLayoutContainer(); + if (belowXLayoutContainer != null && belowXLayoutContainer.isDragInAble()) { + EditingMouseListener editingMouseListener = new EditingMouseListener(designer); + editingMouseListener.refreshTopXCreator(); + belowXLayoutContainer.setEditable(true); + if (editingMouseListener.stopEditing() && belowXLayoutContainer != designer.getRootComponent()) { + ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, belowXLayoutContainer); + if (adapter != null) { + editingMouseListener.startEditing(belowXLayoutContainer, adapter.getDesignerEditor(), adapter); + } + } + } + } + private void entering(int x, int y) { // 将要添加的组件图标移动到鼠标下的位置 addingModel.moveTo(x, y); @@ -263,7 +286,10 @@ public class FormCreatorDropTarget extends DropTarget { @Override public synchronized void dragOver(DropTargetDragEvent dtde) { Point loc = dtde.getLocation(); - hovering(designer.getRelativeX(loc.x), designer.getRelativeY(loc.y)); + int x = designer.getRelativeX(loc.x); + int y = designer.getRelativeY(loc.y); + hovering(x, y); + tabDragInner.dragIn(designer.getComponentAt(x, y), x, y); } /** diff --git a/designer-form/src/main/java/com/fr/design/mainframe/TabDragInner.java b/designer-form/src/main/java/com/fr/design/mainframe/TabDragInner.java new file mode 100644 index 000000000..1b0b976a9 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/TabDragInner.java @@ -0,0 +1,65 @@ +package com.fr.design.mainframe; + +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.cardlayout.XWCardMainBorderLayout; + +/** + * 判断tab块是否能拖入 + * + * @author hades + * @version 10.0 + * Created by hades on 2021/6/29 + */ +public class TabDragInner { + + /** + * 悬浮停留的时间间隔 + */ + private static final long TIME_GAP = 1000; + + private FormDesigner designer; + private XLayoutContainer belowXLayoutContainer; + private long timer; + private int oldX; + private int oldY; + + public TabDragInner(FormDesigner designer) { + this.designer = designer; + } + + /** + * 判断拖入 + * + * @param creator 当前拖拽的组件下方所在布局最上层的组件 + * @param x + * @param y + */ + public void dragIn(XCreator creator, int x, int y) { + XCreator xCreator = designer.getComponentAt(x, y); + XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(xCreator).getTopLayout(); + boolean dragInAble = false; + if (topLayout != null && topLayout.acceptType(XWCardMainBorderLayout.class) && belowXLayoutContainer == null) { + belowXLayoutContainer = topLayout; + timer = System.currentTimeMillis(); + } else if (topLayout == belowXLayoutContainer && topLayout != null && oldX == x && oldY == y) { + if (System.currentTimeMillis() - timer > TIME_GAP) { + dragInAble = true; + } + } else { + timer = 0; + belowXLayoutContainer = null; + } + if (topLayout != null) { + topLayout.setDragInAble(dragInAble); + } + oldX = x; + oldY = y; + } + + + public XLayoutContainer getBelowXLayoutContainer() { + return belowXLayoutContainer; + } +}