Browse Source

REPORT-64149

feature/x
方磊 3 years ago
parent
commit
f254826a80
  1. 2
      designer-form/src/main/java/com/fr/design/designer/beans/LayoutAdapter.java
  2. 45
      designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java
  3. 10
      designer-form/src/main/java/com/fr/design/designer/beans/models/DraggingModel.java
  4. 14
      designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java
  5. 31
      designer-form/src/main/java/com/fr/design/mainframe/DesignerTransferHandler.java
  6. 16
      designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java
  7. 52
      designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java
  8. 68
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java
  9. 11
      designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java
  10. 1
      designer-form/src/main/java/com/fr/design/mainframe/ToolBarButton.java
  11. 1
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java
  12. 1
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java
  13. 9
      designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/GuideCreateUtils.java
  14. 4
      designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/layout/ChangeLayoutComponentGuide.java
  15. 2
      designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/layout/UseLayoutAndComponentGuide.java

2
designer-form/src/main/java/com/fr/design/designer/beans/LayoutAdapter.java

@ -148,7 +148,7 @@ public interface LayoutAdapter {
void dragStart(XCreator xCreator, SelectionModel selectionModel);
/**
* 拖拽结束
* 拖拽经过
*
* @param xCreator
* @param selectionModel

45
designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java

@ -1,13 +1,6 @@
package com.fr.design.designer.beans.models;
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.mainframe.FormDesigner;
import com.fr.design.utils.ComponentUtils;
import com.fr.general.ComparatorUtils;
import java.awt.Rectangle;
/**
* 添加状态下的model
@ -16,7 +9,6 @@ public class AddingModel {
// 当前要添加的组件
private XCreator creator;
private boolean added;
private boolean addedIllegal = false; // 有时候是添加完成了,但是添加会造成某些控件size不合法,例如tab
public AddingModel(XCreator xCreator) {
@ -27,43 +19,6 @@ public class AddingModel {
return this.creator;
}
/**
* 当前组件是否已经添加到某个容器中
*
* @return 是返回true
*/
public boolean isCreatorAdded() {
return added;
}
/**
* 加入容器
*
* @param designer 设计器
* @param container 容器
* @param x 坐标
* @param y 坐标
* @return 成功返回true
*/
public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) {
//考虑不同布局嵌套的情况,获取顶层容器
XLayoutContainer xLayoutContainer = XCreatorUtils.getTopEditableContainer(container);
if (xLayoutContainer != null) {
container = xLayoutContainer;
}
Rectangle rect = ComponentUtils.getRelativeBounds(container);
if (!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())) {
added = container.getLayoutAdapter().addBean(creator,
x + designer.getHorizontalScaleValue(),
y + designer.getVerticalScaleValue() );
return added;
}
added = container.getLayoutAdapter().addBean(creator,
x + designer.getHorizontalScaleValue() - rect.x,
y + designer.getVerticalScaleValue() - rect.y);
return added;
}
public boolean isAddedIllegal() {
return addedIllegal;
}

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

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

14
designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java

@ -13,9 +13,11 @@ import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.widget.editors.PaddingMarginEditor;
import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor;
import com.fr.design.parameter.ParameterBridge;
import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WLayout;
import com.fr.general.Background;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils;
import com.fr.stable.core.PropertyChangeAdapter;
@ -24,6 +26,7 @@ import javax.swing.JComponent;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.beans.IntrospectionException;
@ -609,4 +612,15 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
public boolean isComponent() {
return true;
}
public boolean addWidgetToContainer(XCreator creator, int x, int y) {
//考虑不同布局嵌套的情况,获取顶层容器
XLayoutContainer xLayoutContainer = XCreatorUtils.getTopEditableContainer(this);
XLayoutContainer container = xLayoutContainer != null ? xLayoutContainer : this;
Rectangle rect = ComponentUtils.getRelativeBounds(container);
if (!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())) {
return container.getLayoutAdapter().addBean(creator, x, y);
}
return container.getLayoutAdapter().addBean(creator, x - rect.x, y - rect.y);
}
}

31
designer-form/src/main/java/com/fr/design/mainframe/DesignerTransferHandler.java

@ -1,31 +0,0 @@
package com.fr.design.mainframe;
import com.fr.design.designer.beans.models.AddingModel;
import com.fr.design.file.HistoryTemplateListPane;
import javax.swing.JComponent;
import javax.swing.TransferHandler;
import java.awt.datatransfer.Transferable;
public class DesignerTransferHandler extends TransferHandler {
private FormDesigner designer;
public DesignerTransferHandler(FormDesigner designer, AddingModel addingModel) {
super("rootComponent");
this.designer = designer;
}
protected void exportDone(JComponent source, Transferable data, int action) {
if (designer.getAddingModel() != null && !designer.getAddingModel().isCreatorAdded()) {
undoWhenAddingFailed();
}
}
private void undoWhenAddingFailed() {
JTemplate<?, ?> jt = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate();
if (jt != null) {
jt.undoToCurrent();
}
}
}

16
designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java

@ -196,7 +196,6 @@ 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之后
@ -463,11 +462,26 @@ public class EditingMouseListener extends MouseInputAdapter {
return;
}
// 调整大小这边单独提出来,不跟后面拖组件混在一起,实在不好管理
if (isDraggingSize()) {
stateModel.dragging(e);
return;
}
designer.startDraggingFormWidget(lastXCreator, lastPressEvent, e);
e.translatePoint(oldX - e.getX(), oldY - e.getY());
designer.repaint();
}
/**
* 是否正在调整大小
*
* @return
*/
private boolean isDraggingSize() {
return stateModel.getDirection() != Location.inner && stateModel.getDirection() != Location.outer;
}
/**
* 当前拖拽是否是正在shift或者control拖拽一个选择框
* @param e

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

@ -5,12 +5,14 @@ import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.HoverPainter;
import com.fr.design.designer.beans.Painter;
import com.fr.design.designer.beans.events.AddingWidgetListener;
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.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWFitLayout;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.icon.IconPathConstants;
@ -68,6 +70,8 @@ public class FormCreatorDropTarget extends DropTarget {
public void afterAdded(boolean addResult) {
if (addResult) {
tabDragInner.reset();
} else {
undoWhenAddingFailed();
}
}
});
@ -234,7 +238,6 @@ public class FormCreatorDropTarget extends DropTarget {
*/
@Override
public synchronized void drop(DropTargetDropEvent dtde) {
try {
dropXCreator(dtde);
} catch (Exception e) {
@ -249,27 +252,46 @@ public class FormCreatorDropTarget extends DropTarget {
}
dtde.rejectDrop();
}
designer.stopDragging();
designer.clearDropTarget();
}
private void dropXCreator(DropTargetDropEvent dtde) {
cancelPromptWidgetForbidEnter();
Point loc = dtde.getLocation();
designer.addWidgetToForm(creator, designer.getRelativeX(loc.x), designer.getRelativeY(loc.y));
// 放到事件末尾执行
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// 拖拽释放后标记未选中
for (XCreator xCreator : designer.getSelectionModel().getSelection().getSelectedCreators()) {
xCreator.setSelected(true);
}
DraggingModel model = designer.getDraggingModel();
if (model != null) {
cancelPromptWidgetForbidEnter();
Point loc = dtde.getLocation();
int x = designer.getRelativeX(loc.x);
int y = designer.getRelativeY(loc.y);
if (model.isDragNewWidget()) {
designer.addNewWidget(creator, x, y);
} else {
designer.changeWidgetPlace(creator, x, y);
}
});
//针对在表单中拖入一个控件直接ctrl+s无反应
designer.requestFocus();
// 放到事件末尾执行
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// 拖拽释放后标记未选中
for (XCreator xCreator : designer.getSelectionModel().getSelection().getSelectedCreators()) {
xCreator.setSelected(true);
}
}
});
//针对在表单中拖入一个控件直接ctrl+s无反应
designer.requestFocus();
}
}
public TabDragInner getTabDragInner() {
return this.tabDragInner;
}
private void undoWhenAddingFailed() {
JTemplate<?, ?> jt = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate();
if (jt != null) {
jt.undoToCurrent();
}
}
}

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

@ -229,6 +229,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
populateParameterPropertyPane();
spacingLineDrawer = new FormSpacingLineDrawer(this);
clearDropTarget();
}
@ -822,6 +823,10 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
draggingModel = null;
}
public void clearDropTarget() {
this.setDropTarget(null);
}
/**
* 更新拖拽model的位置
*/
@ -1243,7 +1248,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* @param currentDragEvent
*/
public void startDraggingNewWidget(XCreator xCreator, MouseEvent startDragEvent, MouseEvent currentDragEvent) {
if (startDragEvent == null || currentDragEvent == null) {
if (currentDragEvent == null || this.getDropTarget() != null) {
return;
}
@ -1251,21 +1256,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
.designer(this)
.creator(xCreator)
.startDragEvent(startDragEvent)
.currentDragEvent(currentDragEvent);
instantiateCreator(xCreator);
addingModel = new AddingModel(xCreator);
.currentDragEvent(currentDragEvent)
.dragNewWidget(true);
this.setDropTarget(new FormCreatorDropTarget(this, xCreator));
repaint();
}
public void instantiateCreator(XCreator creator) {
ModelUtil.renameWidgetName(this.getTarget(), creator);
ComponentAdapter adapter = new CompositeComponentAdapter(this, creator);
adapter.initialize();
creator.addNotify();
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter);
}
/**
* 拖拽表单上的组件
*
@ -1274,25 +1270,29 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* @param currentDragEvent
*/
public void startDraggingFormWidget(XCreator xCreator, MouseEvent startDragEvent, MouseEvent currentDragEvent) {
if (currentDragEvent == null || this.getDropTarget() != null) {
return;
}
draggingModel = new DraggingModel()
.designer(this)
.creator(xCreator)
.startDragEvent(startDragEvent)
.currentDragEvent(currentDragEvent);
xCreator.backupCurrentSize();
xCreator.backupParent();
.currentDragEvent(currentDragEvent)
.dragNewWidget(false);
XLayoutContainer container = this.getDraggingHotspotLayout();
LayoutAdapter adapter = container.getLayoutAdapter();
adapter.dragging(this.getDraggingModel());
repaint();
}
/**
* 绑定transferHandler主要实现拖拽结束的回调在拖拽已有组件的时候有用需要在回调里面手动把拖拽失败的组件复原否则组件会消失
* 绑定transferHandler貌似这边用的还是低级的DND方式绑定的鼠标手势高级的可参考ToolBarButton那边"rootComponent"常量是
* 从原来的DesignerTransferHandler里面直接搬来的目前意义还不明确
*
* @param e
*/
public void bindTransferHandler(MouseEvent e) {
TransferHandler handler = new DesignerTransferHandler(this, addingModel);
TransferHandler handler = new TransferHandler("rootComponent");
this.setTransferHandler(handler);
handler.exportAsDrag(this, e, TransferHandler.COPY);
}
@ -1987,7 +1987,27 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
return spacingLineDrawer;
}
public void addWidgetToForm(XCreator creator, int x, int y) {
private void instantiateCreator(XCreator creator) {
ModelUtil.renameWidgetName(this.getTarget(), creator);
creator.addNotify();
ComponentAdapter adapter = new CompositeComponentAdapter(this, creator);
adapter.initialize();
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter);
}
public void addNewWidget(XCreator creator, int x, int y) {
instantiateCreator(creator);
addWidgetToForm(creator, x, y);
}
public void changeWidgetPlace(XCreator creator, int x, int y) {
creator.backupCurrentSize();
creator.backupParent();
addWidgetToForm(creator, x, y);
}
private void addWidgetToForm(XCreator creator, int x, int y) {
if(creator == null) {
return;
}
@ -2000,14 +2020,16 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
boolean success = false;
if (container != null) {
// 如果是容器,则调用其acceptComponent接受组件
AddingModel model = this.getAddingModel();
boolean chartEnter2Para = !addingModel.getXCreator().canEnterIntoParaPane() && container.acceptType(XWParameterLayout.class);
boolean formSubmit2Adapt = !addingModel.getXCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class);
if (model != null && !chartEnter2Para && !formSubmit2Adapt) {
if (!chartEnter2Para && !formSubmit2Adapt) {
getAddingWidgetListeners().beforeAdded();
success = model.add2Container(this, container, x, y);
success = container.addWidgetToContainer(
creator,
x + this.getHorizontalScaleValue(),
y + this.getVerticalScaleValue()
);
}
getAddingWidgetListeners().afterAdded(success);
defaultAfterWidgetAdded(success, container);
@ -2034,6 +2056,8 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
}
}
private void defaultAfterWidgetAdded(boolean addResult, XLayoutContainer container) {
if (addResult) {
// 如果添加成功,则触发相应事件

11
designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java

@ -8,7 +8,6 @@ import com.fr.base.vcs.DesignerMode;
import com.fr.design.constants.UIConstants;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.location.Direction;
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;
@ -117,9 +116,8 @@ public class FormDesignerUI extends ComponentUI {
designer.getPainter().paint(g, designer.getArea().getHorizontalValue(),
designer.getArea().getVerticalValue() + designer.getParaHeight());
}
AddingModel addingModel = designer.getAddingModel();
if ((addingModel != null) && (addingModel.getXCreator() != null)) {
DraggingModel draggingModel = designer.getDraggingModel();
if (draggingModel != null && draggingModel.getCreator() != null) {
// 当前正在添加的组件
paintDraggingBean(g);
}
@ -200,12 +198,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() ;
int y = model.getCreatorLeftTopY();
XLayoutContainer container = designer.getDraggingHotspotLayout();
LayoutAdapter adapter = container.getLayoutAdapter();

1
designer-form/src/main/java/com/fr/design/mainframe/ToolBarButton.java

@ -75,7 +75,6 @@ public class ToolBarButton extends UIButton implements MouseListener, MouseMotio
}
public void mouseReleased(MouseEvent e) {
WidgetToolBarPane.getTarget().stopDragging();
}
@Override

1
designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java

@ -180,7 +180,6 @@ public class LocalWidgetBlock extends PreviewWidgetBlock<DefaultSharableWidget>
dealClickAction(e);
}
pressed = false;
WidgetToolBarPane.getTarget().stopDragging();
}
@Override

1
designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java

@ -166,7 +166,6 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
WidgetToolBarPane.getTarget().stopDragging();
}
@Override

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

@ -125,14 +125,17 @@ public class GuideCreateUtils {
return null;
}
public static void addXCreatorToXLayoutContainer(XCreator xCreator, XLayoutContainer xLayoutContainer) {
public static void addXCreatorToXLayoutContainer(XCreator xCreator, XLayoutContainer xLayoutContainer, boolean dragNewComponent) {
if (xCreator == null) {
return;
}
FormDesigner designer = GuideCreateUtils.getFormDesigner();
designer.getSelectionModel().selectACreator(xLayoutContainer);
designer.addWidgetToForm(xCreator, xLayoutContainer.getX(), xLayoutContainer.getY());
if (dragNewComponent) {
designer.addNewWidget(xCreator, xLayoutContainer.getX(), xLayoutContainer.getY());
} else {
designer.changeWidgetPlace(xCreator, xLayoutContainer.getX(), xLayoutContainer.getY());
}
designer.getSelectionModel().selectACreator(xCreator);
}

4
designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/layout/ChangeLayoutComponentGuide.java

@ -136,8 +136,8 @@ public class ChangeLayoutComponentGuide {
formDesigner.getSelectionModel().removeCreator(from, from.getWidth(), from.getHeight());
formDesigner.getSelectionModel().removeCreator(to, to.getWidth(),to.getHeight());
GuideCreateUtils.addXCreatorToXLayoutContainer(from, (XLayoutContainer) GuideCreateUtils.getXCreatorFormDesigner("box1"));
GuideCreateUtils.addXCreatorToXLayoutContainer(to, (XLayoutContainer) GuideCreateUtils.getXCreatorFormDesigner("box0"));
GuideCreateUtils.addXCreatorToXLayoutContainer(from, (XLayoutContainer) GuideCreateUtils.getXCreatorFormDesigner("box1"), false);
GuideCreateUtils.addXCreatorToXLayoutContainer(to, (XLayoutContainer) GuideCreateUtils.getXCreatorFormDesigner("box0"), false);
return true;
}
});

2
designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/layout/UseLayoutAndComponentGuide.java

@ -246,7 +246,7 @@ public class UseLayoutAndComponentGuide {
LocalWidgetBlock block = getLocalWidgetBlock(shareID);
XCreator xCreator = block.transformXCreator(block);
XOccupiedLayout xOccupiedLayout = getXOccupiedLayout(name);
GuideCreateUtils.addXCreatorToXLayoutContainer(xCreator, xOccupiedLayout);
GuideCreateUtils.addXCreatorToXLayoutContainer(xCreator, xOccupiedLayout, true);
return true;
}
});

Loading…
Cancel
Save