Browse Source

REPORT-54155 设计器布局面板上Tab组件拖拽优化

feature/10.0
hades 3 years ago
parent
commit
9a160fb75c
  1. 2
      designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  2. 7
      designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  3. 9
      designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java
  4. 5
      designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java
  5. 28
      designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java
  6. 65
      designer-form/src/main/java/com/fr/design/mainframe/TabDragInner.java

2
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(); XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout();
if(topLayout != null){ if(topLayout != null){
if (topLayout.isEditable()){ if (topLayout.isDragInAble() || topLayout.isEditable()){
return topLayoutAccept(creator, x, y); return topLayoutAccept(creator, x, y);
} }
//绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局 //绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局

7
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.creator.cardlayout.XWTabFitLayout;
import com.fr.design.designer.properties.FRFitLayoutConstraints; import com.fr.design.designer.properties.FRFitLayoutConstraints;
import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel; import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.fun.FormWidgetOptionProvider; 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.design.utils.ComponentUtils;
import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.LayoutBorderStyle;
import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
@ -169,7 +164,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
//布局控件要先判断是不是可编辑 //布局控件要先判断是不是可编辑
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator) comp).getTopLayout(); 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) { if (access) {
return false; return false;
} }

9
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; protected boolean isMouseEnter = false;
private volatile boolean dragInAble;
public void setMouseEnter(boolean mouseEnter) { public void setMouseEnter(boolean mouseEnter) {
isMouseEnter = mouseEnter; isMouseEnter = mouseEnter;
} }
@ -577,4 +579,11 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
return false; return false;
} }
public boolean isDragInAble() {
return dragInAble;
}
public void setDragInAble(boolean dragInAble) {
this.dragInAble = dragInAble;
}
} }

5
designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java

@ -447,4 +447,9 @@ public class XWCardMainBorderLayout extends XWBorderLayout {
return true; return true;
} }
@Override
public Dimension initEditorSize() {
return LARGEPREFERREDSIZE;
}
} }

28
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.DesignTableDataManager;
import com.fr.design.data.datapane.TableDataTreePane; import com.fr.design.data.datapane.TableDataTreePane;
import com.fr.design.designer.beans.AdapterBus; 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.HoverPainter;
import com.fr.design.designer.beans.Painter; import com.fr.design.designer.beans.Painter;
import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.events.DesignerEvent;
@ -66,6 +67,8 @@ public class FormCreatorDropTarget extends DropTarget {
private AddingModel addingModel; private AddingModel addingModel;
private static final int GAP = 30; private static final int GAP = 30;
private TabDragInner tabDragInner;
private JWindow promptWindow = new JWindow(); private JWindow promptWindow = new JWindow();
private UIButton promptButton = new UIButton("", BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); private UIButton promptButton = new UIButton("", BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH));
@ -73,6 +76,7 @@ public class FormCreatorDropTarget extends DropTarget {
this.designer = designer; this.designer = designer;
this.addingModel = designer.getAddingModel(); this.addingModel = designer.getAddingModel();
this.promptWindow.add(promptButton); this.promptWindow.add(promptButton);
this.tabDragInner = new TabDragInner(designer);
} }
private void adding(int x, int y) { private void adding(int x, int y) {
@ -128,6 +132,7 @@ public class FormCreatorDropTarget extends DropTarget {
designer.getSelectionModel().setSelectedCreators( designer.getSelectionModel().setSelectedCreators(
FormSelectionUtils.rebuildSelection(xCreator, new Widget[]{widget})); FormSelectionUtils.rebuildSelection(xCreator, new Widget[]{widget}));
designer.getEditListenerTable().fireCreatorModified(addingModel.getXCreator(), DesignerEvent.CREATOR_ADDED); designer.getEditListenerTable().fireCreatorModified(addingModel.getXCreator(), DesignerEvent.CREATOR_ADDED);
tryEditTabContainer();
} else { } else {
Toolkit.getDefaultToolkit().beep(); Toolkit.getDefaultToolkit().beep();
} }
@ -137,6 +142,24 @@ public class FormCreatorDropTarget extends DropTarget {
designer.stopAddingState(); 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) { private void entering(int x, int y) {
// 将要添加的组件图标移动到鼠标下的位置 // 将要添加的组件图标移动到鼠标下的位置
addingModel.moveTo(x, y); addingModel.moveTo(x, y);
@ -263,7 +286,10 @@ public class FormCreatorDropTarget extends DropTarget {
@Override @Override
public synchronized void dragOver(DropTargetDragEvent dtde) { public synchronized void dragOver(DropTargetDragEvent dtde) {
Point loc = dtde.getLocation(); 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);
} }
/** /**

65
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;
}
}
Loading…
Cancel
Save