Browse Source

report-1945frm本地组件复用:1、自适应或者tab布局时,不选中粘贴默认为上下平分左上角的组件;2、tab布局(有无参数面板)粘贴位置问题

master
yaoh.wu 8 years ago
parent
commit
40dbc0272f
  1. 48
      designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java
  2. 20
      designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

48
designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java

@ -15,6 +15,8 @@ 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.ComponentUtils;
import com.fr.design.utils.gui.LayoutUtils; import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.form.ui.container.cardlayout.WTabFitLayout;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import java.awt.*; import java.awt.*;
@ -27,7 +29,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 double OFFSET_RELATIVE = 0.80; private static final double OFFSET_RELATIVE = 0.78;
private static FormSelection clipboard = new FormSelection(); private static FormSelection clipboard = new FormSelection();
private FormDesigner designer; private FormDesigner designer;
private FormSelection selection; private FormSelection selection;
@ -136,19 +138,20 @@ public class SelectionModel {
if (designer.getClass().equals(FormDesigner.class)) { if (designer.getClass().equals(FormDesigner.class)) {
if (selection.getSelectedCreator() instanceof XWFitLayout) { if (selection.getSelectedCreator() instanceof XWFitLayout) {
if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) { if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) {
Rectangle rec = selection.getRelativeBounds(); XLayoutContainer container = (XLayoutContainer) selection.getSelectedCreator();
//Tab布局 //tab布局编辑器内部左上角第一个坐标点
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), int leftUpX = container.toData().getMargin().getLeft() + 1;
clipboard, int leftUpY = container.toData().getMargin().getTop() + 1;
rec.x + rec.width / 2, //选中第一个坐标点坐在的组件
rec.y + DELTA_X_Y); selection.setSelectedCreator((XCreator) container.getComponentAt(leftUpX, leftUpY));
pasteFromClipBoard();
} else { } else {
Rectangle rec = selection.getRelativeBounds(); //自适应布局编辑器内部左上角第一个坐标点
//自适应布局 int leftUpX = designer.getRootComponent().toData().getMargin().getLeft() + 1;
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), int leftUpY = designer.getRootComponent().toData().getMargin().getTop() + 1;
clipboard, //选中第一个坐标点坐在的组件
rec.x + rec.width / 2, selection.setSelectedCreator((XCreator) designer.getRootComponent().getComponentAt(leftUpX, leftUpY));
rec.y + DELTA_X_Y); pasteFromClipBoard();
} }
} else { } else {
//绝对布局 //绝对布局
@ -178,12 +181,23 @@ public class SelectionModel {
container = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); container = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (container != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) { if (container != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) {
//自适应布局 //自适应布局
Rectangle selectionRec = selection.getRelativeBounds(); Rectangle selectionRec = selection.getRelativeBounds();
//获取父容器位置,补充因参数面板高度导致的位置坐标计算偏移
Rectangle containerRec = ComponentUtils.getRelativeBounds(container); Rectangle containerRec = ComponentUtils.getRelativeBounds(container);
//计算自适应布局位置 int positionX, positionY;
int positionX = selectionRec.x - containerRec.x + selectionRec.width / 2;
int positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE); if (container.getClass().equals(XWTabFitLayout.class)) {
//tab内部粘贴不补充高度偏移
//且不计算参数面板造成的影响,因为在
//@see com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter#addBean中做了
positionX = selectionRec.x + selectionRec.width / 2;
positionY = (int) (selectionRec.y + selectionRec.height * OFFSET_RELATIVE);
} else {
//计算自适应布局位置
positionX = selectionRec.x - containerRec.x + selectionRec.width / 2;
positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE);
}
FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY); FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY);
} else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { } else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) {
//绝对布局 //绝对布局

20
designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

@ -3,8 +3,10 @@ package com.fr.design.mainframe;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter; import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.*; import com.fr.design.designer.creator.*;
import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WTitleLayout; import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
@ -83,14 +85,26 @@ public class FormSelectionUtils {
* 相对布局粘贴 * 相对布局粘贴
*/ */
private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) {
//@see FRTabFitLayoutAdapter
Rectangle tabContainerRect = ComponentUtils.getRelativeBounds(designer.getSelectionModel().getSelection()
.getSelectedCreator().getParent());
designer.getSelectionModel().getSelection().reset(); designer.getSelectionModel().getSelection().reset();
for (XCreator creator : clipboard.getSelectedCreators()) { for (XCreator creator : clipboard.getSelectedCreators()) {
try { try {
Widget copied = copyWidget(designer, creator); Widget copied = copyWidget(designer, creator);
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize());
if (!adapter.accept(copiedCreator, x, y)) { if (adapter.getClass().equals(FRTabFitLayoutAdapter.class)) {
designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste")); if (!adapter.accept(copiedCreator, x - tabContainerRect.x, y - tabContainerRect.y)) {
return; designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste"));
return;
}
} else {
if (!adapter.accept(copiedCreator, x, y)) {
designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste"));
return;
}
} }
boolean addSuccess = adapter.addBean(copiedCreator, x, y); boolean addSuccess = adapter.addBean(copiedCreator, x, y);
if (addSuccess) { if (addSuccess) {

Loading…
Cancel
Save