|
|
@ -13,6 +13,7 @@ import com.fr.design.form.util.XCreatorConstants; |
|
|
|
import com.fr.design.mainframe.FormDesigner; |
|
|
|
import com.fr.design.mainframe.FormDesigner; |
|
|
|
import com.fr.design.mainframe.FormSelection; |
|
|
|
import com.fr.design.mainframe.FormSelection; |
|
|
|
import com.fr.design.mainframe.FormSelectionUtils; |
|
|
|
import com.fr.design.mainframe.FormSelectionUtils; |
|
|
|
|
|
|
|
import com.fr.design.utils.ComponentUtils; |
|
|
|
import com.fr.design.utils.gui.LayoutUtils; |
|
|
|
import com.fr.design.utils.gui.LayoutUtils; |
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
|
|
|
|
|
|
|
@ -26,7 +27,7 @@ import java.util.ArrayList; |
|
|
|
public class SelectionModel { |
|
|
|
public class SelectionModel { |
|
|
|
//被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。
|
|
|
|
//被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。
|
|
|
|
private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离
|
|
|
|
private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离
|
|
|
|
private static final int BORDER_PROPORTION = 20; |
|
|
|
private static final double OFFSET_RELATIVE = 0.80; |
|
|
|
private static FormSelection clipboard = new FormSelection(); |
|
|
|
private static FormSelection clipboard = new FormSelection(); |
|
|
|
private FormDesigner designer; |
|
|
|
private FormDesigner designer; |
|
|
|
private FormSelection selection; |
|
|
|
private FormSelection selection; |
|
|
@ -140,14 +141,14 @@ public class SelectionModel { |
|
|
|
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), |
|
|
|
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), |
|
|
|
clipboard, |
|
|
|
clipboard, |
|
|
|
rec.x + rec.width / 2, |
|
|
|
rec.x + rec.width / 2, |
|
|
|
rec.y + BORDER_PROPORTION); |
|
|
|
rec.y + DELTA_X_Y); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Rectangle rec = selection.getRelativeBounds(); |
|
|
|
Rectangle rec = selection.getRelativeBounds(); |
|
|
|
//自适应布局
|
|
|
|
//自适应布局
|
|
|
|
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), |
|
|
|
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), |
|
|
|
clipboard, |
|
|
|
clipboard, |
|
|
|
rec.x + rec.width / 2, |
|
|
|
rec.x + rec.width / 2, |
|
|
|
rec.y + BORDER_PROPORTION); |
|
|
|
rec.y + DELTA_X_Y); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//绝对布局
|
|
|
|
//绝对布局
|
|
|
@ -172,18 +173,22 @@ public class SelectionModel { |
|
|
|
* 粘贴时选择组件 |
|
|
|
* 粘贴时选择组件 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void selectedPaste() { |
|
|
|
private void selectedPaste() { |
|
|
|
XLayoutContainer parent = null; |
|
|
|
XLayoutContainer container = null; |
|
|
|
//获取到编辑器的表层容器(已选的组件的父容器就是表层容器)
|
|
|
|
//获取到编辑器的表层容器(已选的组件的父容器就是表层容器)
|
|
|
|
parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); |
|
|
|
container = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); |
|
|
|
if (parent != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) { |
|
|
|
if (container != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) { |
|
|
|
//自适应布局
|
|
|
|
//自适应布局
|
|
|
|
Rectangle rec = selection.getRelativeBounds(); |
|
|
|
Rectangle selectionRec = selection.getRelativeBounds(); |
|
|
|
FormSelectionUtils.paste2Container(designer, parent, clipboard, rec.x + rec.width / 2, rec.y + |
|
|
|
Rectangle containerRec = ComponentUtils.getRelativeBounds(container); |
|
|
|
rec.height - BORDER_PROPORTION); |
|
|
|
//计算自适应布局位置
|
|
|
|
} else if (parent != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { |
|
|
|
int positionX = selectionRec.x - containerRec.x + selectionRec.width / 2; |
|
|
|
|
|
|
|
int positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY); |
|
|
|
|
|
|
|
} else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { |
|
|
|
//绝对布局
|
|
|
|
//绝对布局
|
|
|
|
Rectangle rec = selection.getSelctionBounds(); |
|
|
|
Rectangle rec = selection.getSelctionBounds(); |
|
|
|
FormSelectionUtils.paste2Container(designer, parent, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); |
|
|
|
FormSelectionUtils.paste2Container(designer, container, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -198,13 +203,13 @@ public class SelectionModel { |
|
|
|
if (creator.acceptType(XWParameterLayout.class)) { |
|
|
|
if (creator.acceptType(XWParameterLayout.class)) { |
|
|
|
designer.removeParaComponent(); |
|
|
|
designer.removeParaComponent(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight()); |
|
|
|
removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight()); |
|
|
|
creator.removeAll(); |
|
|
|
creator.removeAll(); |
|
|
|
// 清除被选中的组件
|
|
|
|
// 清除被选中的组件
|
|
|
|
selection.reset(); |
|
|
|
selection.reset(); |
|
|
|
} |
|
|
|
} |
|
|
|
setSelectedCreator(designer.getRootComponent()); |
|
|
|
setSelectedCreator(designer.getRootComponent()); |
|
|
|
|
|
|
|
FormSelectionUtils.rebuildSelection(designer); |
|
|
|
// 触发事件
|
|
|
|
// 触发事件
|
|
|
|
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); |
|
|
|
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); |
|
|
|
designer.repaint(); |
|
|
|
designer.repaint(); |
|
|
|