Browse Source

tab 文件间复用

master
yaoh.wu 8 years ago
parent
commit
31e9e165bb
  1. 23
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  2. 2
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java
  3. 59
      designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java

23
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java

@ -52,6 +52,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
public void setEdit(boolean edit) { public void setEdit(boolean edit) {
isEdit = edit; isEdit = edit;
} }
/** /**
* 构造函数 * 构造函数
* *
@ -277,7 +278,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
super.clearCompsList(); super.clearCompsList();
} }
protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout){ protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) {
return mainLayout.getBounds(); return mainLayout.getBounds();
} }
@ -353,13 +354,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
* 拖拽控件边框后根据控件的大小尺寸进行相关组件的调整 * 拖拽控件边框后根据控件的大小尺寸进行相关组件的调整
* *
* @param backupBound 边界备份 * @param backupBound 边界备份
* @param bounds 组件边界 * @param bounds 组件边界
* @param xCreator 组件 * @param xCreator 组件
* @param row 选中的行 * @param row 选中的行
* @param difference 偏移量 * @param difference 偏移量
*/ */
public void calculateBounds(Rectangle backupBound, Rectangle bounds, XCreator xCreator, int row, int difference) { public void calculateBounds(Rectangle backupBound, Rectangle bounds, XCreator xCreator, int row, int difference) {
Rectangle rc = new Rectangle(0,0,0,0); Rectangle rc = new Rectangle(0, 0, 0, 0);
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(xCreator); XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(xCreator);
if (parent != null) { if (parent != null) {
Rectangle rec = ComponentUtils.getRelativeBounds(parent); Rectangle rec = ComponentUtils.getRelativeBounds(parent);
@ -370,17 +371,17 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
//处理左右延伸 //处理左右延伸
switch (row) { switch (row) {
case 0: case 0:
if (backupBound.width + backupBound.x == container.getWidth() - margin.getRight() +rc.x) { if (backupBound.width + backupBound.x == container.getWidth() - margin.getRight() + rc.x) {
x += difference; x += difference;
} }
break; break;
case 1: case 1:
if(backupBound.y + backupBound.height == container.getHeight() - margin.getBottom() +rc.y){ if (backupBound.y + backupBound.height == container.getHeight() - margin.getBottom() + rc.y) {
y += difference; y += difference;
} }
break; break;
} }
bounds.setLocation(x,y); bounds.setLocation(x, y);
xCreator.setBackupBound(backupBound); xCreator.setBackupBound(backupBound);
xCreator.setBounds(bounds); xCreator.setBounds(bounds);
this.fix(xCreator); this.fix(xCreator);
@ -424,7 +425,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
// 根据需要依附的位置调整拖拽的坐标值 // 根据需要依附的位置调整拖拽的坐标值
private int adjustCoordinateByDependingLine(int coordinate, int[] coordinates) { private int adjustCoordinateByDependingLine(int coordinate, int[] coordinates) {
if(!isEdit) { if (!isEdit) {
for (int i = 0; i < coordinates.length; i++) { for (int i = 0; i < coordinates.length; i++) {
if (coordinate == coordinates[i]) { if (coordinate == coordinates[i]) {
continue; continue;
@ -440,7 +441,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
// 根据需要依附的位置调整拖拽的距离 // 根据需要依附的位置调整拖拽的距离
private int adjustDiffByDependingLine(int coordinate, int[] coordinates, int diff) { private int adjustDiffByDependingLine(int coordinate, int[] coordinates, int diff) {
if(!isEdit) { if (!isEdit) {
for (int i = 0; i < coordinates.length; i++) { for (int i = 0; i < coordinates.length; i++) {
if (coordinate + diff > coordinates[i] - DEPENDING_SCOPE && coordinate + diff < coordinates[i] + DEPENDING_SCOPE) { if (coordinate + diff > coordinates[i] - DEPENDING_SCOPE && coordinate + diff < coordinates[i] + DEPENDING_SCOPE) {
diff = coordinates[i] - coordinate; diff = coordinates[i] - coordinate;

2
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java

@ -69,7 +69,7 @@ public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter {
if (!accept(creator, posX, posY)) { if (!accept(creator, posX, posY)) {
return false; return false;
} }
// posX,posY是新拖入组件相对于容器的位置,若在tab布局的边缘,则需要把新组件添加到 // posX,posY是新拖入组件相对于容器的位置,若在tab布局的边缘,则需要把新组件添加到l
// 父层自适应布局中,这时候的添加位置就是tab布局所在的位置 // 父层自适应布局中,这时候的添加位置就是tab布局所在的位置
if (this.intersectsEdge(posX, posY, backUpContainer)) { if (this.intersectsEdge(posX, posY, backUpContainer)) {
if (!ComparatorUtils.equals(backUpContainer.getOuterLayout(), backUpContainer.getBackupParent())) { if (!ComparatorUtils.equals(backUpContainer.getOuterLayout(), backUpContainer.getBackupParent())) {

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

@ -12,11 +12,15 @@ import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.beans.location.Direction; import com.fr.design.designer.beans.location.Direction;
import com.fr.design.designer.beans.location.Location; import com.fr.design.designer.beans.location.Location;
import com.fr.design.designer.creator.*; import com.fr.design.designer.creator.*;
import com.fr.design.designer.creator.cardlayout.XWCardLayout;
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.form.util.XCreatorConstants; 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.gui.LayoutUtils; import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
/** /**
@ -25,6 +29,7 @@ import com.fr.stable.ArrayUtils;
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 = 10;
private static FormSelection CLIP_BOARD = new FormSelection(); private static FormSelection CLIP_BOARD = new FormSelection();
private FormDesigner designer; private FormDesigner designer;
private FormSelection selection; private FormSelection selection;
@ -111,15 +116,26 @@ public class SelectionModel {
public boolean pasteFromClipBoard() { public boolean pasteFromClipBoard() {
if (!CLIP_BOARD.isEmpty()) { if (!CLIP_BOARD.isEmpty()) {
XLayoutContainer parent = null; XLayoutContainer parent = null;
//未选
if (!hasSelectionComponent()) { if (!hasSelectionComponent()) {
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)) {
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), Rectangle rec = selection.getRelativeBounds();
CLIP_BOARD, //Tab布局
DELTA_X_Y, System.out.println("ADD: " + (rec.x + rec.width / 2) + "\t" + (rec.y + BORDER_PROPORTION));
DELTA_X_Y); FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(),
CLIP_BOARD,
rec.x + rec.width / 2,
rec.y + BORDER_PROPORTION);
} else {
Rectangle rec = selection.getRelativeBounds();
//自适应布局
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
CLIP_BOARD,
rec.x + rec.width / 2,
rec.y + BORDER_PROPORTION);
}
} else { } else {
//绝对布局 //绝对布局
//编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层 //编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层
@ -137,15 +153,17 @@ public class SelectionModel {
DELTA_X_Y, DELTA_X_Y,
DELTA_X_Y); DELTA_X_Y);
} }
} else { }
//已选
else {
//获取到编辑器的表层容器(已选的组件的父容器就是表层容器) //获取到编辑器的表层容器(已选的组件的父容器就是表层容器)
parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (selection.getSelectedCreator().getParent() instanceof XWFitLayout) { if (selection.getSelectedCreator().getParent() instanceof XWFitLayout) {
//相对布局 //自适应布局
if (parent != null) { if (parent != null) {
Rectangle rec = selection.getSelctionBounds(); Rectangle rec = selection.getSelctionBounds();
FormSelectionUtils.paste2Container(designer, parent, CLIP_BOARD, rec.x + rec.width / 2, rec.y + FormSelectionUtils.paste2Container(designer, parent, CLIP_BOARD, rec.x + rec.width / 2, rec.y +
rec.height - 2); rec.height - BORDER_PROPORTION);
} }
} else if (selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { } else if (selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) {
//绝对布局 //绝对布局
@ -256,18 +274,17 @@ public class SelectionModel {
public boolean hasSelectionComponent() { public boolean hasSelectionComponent() {
if (designer.getClass().equals(FormDesigner.class)) { if (designer.getClass().equals(FormDesigner.class)) {
//frm本地组件复用 //frm本地组件复用
if (selection.getSelectedCreator() == null) { return selection.getSelectedCreator() != null
return false; && !(
} else if (selection.getSelectedCreator().getParent() instanceof XWFitLayout) { //frm绝对布局编辑器
// 相对布局 selection.getSelectedCreator().getClass().equals(XWAbsoluteBodyLayout.class)
// 已选:selection.getSelectedCreator().getParent() instanceof @XWFitLayout //Tab布局编辑器
// 未选:selection.getSelectedCreator() instanceof @XWFitLayout || selection.getSelectedCreator().getClass().equals(XWCardMainBorderLayout.class)
return !(selection.getSelectedCreator() instanceof XWAbsoluteLayout); || selection.getSelectedCreator().getClass().equals(XWCardLayout.class)
} else { || selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)
//绝对布局 //自适应布局编辑器
//已选:selection.getSelectedCreator().getParent() instanceof @XWAbsoluteLayout || selection.getSelectedCreator().getClass().equals(XWFitLayout.class)
return selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout; );
}
} else { } else {
//cpt本地组件复用,selection.getSelectedCreator().getParent()=@XWParameterLayout instanceof @XWAbsoluteLayout //cpt本地组件复用,selection.getSelectedCreator().getParent()=@XWParameterLayout instanceof @XWAbsoluteLayout
return selection.getSelectedCreator() != null && selection.getSelectedCreator().getParent() != null; return selection.getSelectedCreator() != null && selection.getSelectedCreator().getParent() != null;

Loading…
Cancel
Save