neil 8 years ago
parent
commit
d8daeae404
  1. 114
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  2. 63
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  3. 95
      designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java

114
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java

@ -1,7 +1,5 @@
package com.fr.design.designer.beans.adapters.layout; package com.fr.design.designer.beans.adapters.layout;
import java.awt.*;
import com.fr.design.beans.GroupModel; import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.HoverPainter;
@ -9,13 +7,14 @@ import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter;
import com.fr.design.designer.creator.*; import com.fr.design.designer.creator.*;
import com.fr.design.designer.properties.BoundsGroupModel; import com.fr.design.designer.properties.BoundsGroupModel;
import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel; import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel;
import com.fr.form.ui.container.WAbsoluteLayout;
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.WAbsoluteLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import java.awt.*;
public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
//是不是添加到父容器上 //是不是添加到父容器上
private boolean isAdd2ParentLayout = false; private boolean isAdd2ParentLayout = false;
@ -42,6 +41,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 是否能在指定位置添加组件 * 是否能在指定位置添加组件
*
* @param creator 组件 * @param creator 组件
* @param x 坐标x * @param x 坐标x
* @param y 坐标y * @param y 坐标y
@ -57,70 +57,61 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
//布局控件要先判断是不是可编辑 //布局控件要先判断是不是可编辑
//可以编辑,按原有逻辑判断 //可以编辑,按原有逻辑判断
//不可编辑,当成一整个控件处理 //不可编辑,当成一整个控件处理
if (comp == null){ if (comp == null) {
return false; return false;
} }
//参数面板内的组件不允许拖往绝对布局中 //参数面板内的组件不允许拖往绝对布局中
if (creator.getParent() != null && ((XCreator)creator.getParent()).acceptType(XWParameterLayout.class)){ if (creator.getParent() != null && ((XCreator) creator.getParent()).acceptType(XWParameterLayout.class)) {
Rectangle rec = creator.getBounds(); Rectangle rec = creator.getBounds();
rec.y = creator.getParent().getHeight() - rec.height; rec.y = creator.getParent().getHeight() - rec.height;
creator.setBounds(rec); creator.setBounds(rec);
return false; return false;
} }
//判断下组件能不能拖入绝对布局 //判断组件能不能拖入绝对布局
if (!creator.canEnterIntoAbsolutePane()){ if (!creator.canEnterIntoAbsolutePane()) {
return false; return false;
} }
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.isEditable()) {
return topLayoutAccept(creator, x, y, topLayout); return topLayoutAccept(creator, x, y);
} }
//绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局 //绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局
else if (((XLayoutContainer)topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) { else if (((XLayoutContainer) topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) {
return false; return false;
} else {
return acceptWidget(x, y);
} }
else { } else {
return acceptWidget(creator, x, y);
}
}
else{
FRLogger.getLogger().error("top layout is null!"); FRLogger.getLogger().error("top layout is null!");
} }
return false; return false;
} }
//toplayout假如可以编辑的话就往里面添加组件 //topLayout假如可以编辑的话就往里面添加组件
private boolean topLayoutAccept(XCreator creator, int x, int y, XLayoutContainer topLayout) { private boolean topLayoutAccept(XCreator creator, int x, int y) {
//判断有没有和当前控件重叠 //允许组件重叠,可以不判断有没有和当前控件重叠
//先计算当前控件的位置 //先计算当前控件的位置
int creatorX, creatorY; int creatorX, creatorY;
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { if (XCreatorUtils.getParentXLayoutContainer(creator) != null) {
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator);
creatorX = creatorRectangle.x; creatorX = creatorRectangle.x;
creatorY = creatorRectangle.y; creatorY = creatorRectangle.y;
} else { } else {
//这边计算得到的组件其实位置是正确的,
//因为传入的x和y已经加上了宽度或者高度的一半,再减去相同的宽度和高度的一半是没区别的,
// 例如高度为21,那么就是+10-10;
// 高度为20,那么就是+10-10; 没区别
int w = creator.getWidth() / 2; int w = creator.getWidth() / 2;
int h = creator.getHeight() / 2; int h = creator.getHeight() / 2;
creatorX = x - w; creatorX = x - w;
creatorY = y - h; creatorY = y - h;
}
//再判断和布局中其他控件重叠
Rectangle curRec = new Rectangle(creatorX, creatorY, creator.getWidth(), creator.getHeight());
WAbsoluteLayout wAbsoluteLayout = (WAbsoluteLayout)topLayout.toData();
for (int i = 0, count = wAbsoluteLayout.getWidgetCount(); i < count; i++) {
BoundsWidget temp = (BoundsWidget) wAbsoluteLayout.getWidget(i);
Rectangle rectangle = temp.getBounds();
if (curRec.intersects(rectangle)){
return false;
}
} }
if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) { if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) {
return false; return false;
} }
if (creatorY < 0 || creatorY + creator.getHeight() > container.getHeight()){ if (creatorY < 0 || creatorY + creator.getHeight() > container.getHeight()) {
return false; return false;
} }
return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight() return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight()
@ -129,15 +120,16 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分 * 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分
*
* @param parentComp 鼠标所在区域的组件 * @param parentComp 鼠标所在区域的组件
* @param x 坐标x * @param x 坐标x
* @param y 坐标y * @param y 坐标y
* @return 是则返回true * @return 是则返回true
*/ */
public boolean isTrisectionArea(Component parentComp, int x, int y) { public boolean isTrisectionArea(Component parentComp, int x, int y) {
XCreator creator = (XCreator)parentComp; XCreator creator = (XCreator) parentComp;
trisectAreaDirect = 0; trisectAreaDirect = 0;
if (container.getComponentCount()<=1) { if (container.getComponentCount() <= 1) {
return false; return false;
} }
int maxWidth = parentComp.getWidth(); int maxWidth = parentComp.getWidth();
@ -145,23 +137,23 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
int xL = parentComp.getX(); int xL = parentComp.getX();
int yL = parentComp.getY(); int yL = parentComp.getY();
// 组件宽高的十分之一和默认值取大 // 组件宽高的十分之一和默认值取大
int minRangeWidth = Math.max(maxWidth/BORDER_PROPORTION, DEFAULT_AREA_LENGTH); int minRangeWidth = Math.max(maxWidth / BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
int minRangeHeight = Math.max(maxHeight/BORDER_PROPORTION, DEFAULT_AREA_LENGTH); int minRangeHeight = Math.max(maxHeight / BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
if(y<yL+minRangeHeight ) { if (y < yL + minRangeHeight) {
// 在组件上侧三等分 // 在组件上侧三等分
trisectAreaDirect = COMP_TOP; trisectAreaDirect = COMP_TOP;
} else if(y>yL+maxHeight-minRangeHeight) { } else if (y > yL + maxHeight - minRangeHeight) {
// 在组件下侧三等分 // 在组件下侧三等分
trisectAreaDirect = COMP_BOTTOM; trisectAreaDirect = COMP_BOTTOM;
} else if (x<xL+minRangeWidth) { } else if (x < xL + minRangeWidth) {
// 在组件左侧三等分 // 在组件左侧三等分
trisectAreaDirect = COMP_LEFT; trisectAreaDirect = COMP_LEFT;
} else if(x>xL+maxWidth-minRangeWidth) { } else if (x > xL + maxWidth - minRangeWidth) {
// 在组件右侧三等分 // 在组件右侧三等分
trisectAreaDirect = COMP_RIGHT; trisectAreaDirect = COMP_RIGHT;
} }
// tab布局的边界特殊处理,不进行三等分 // tab布局的边界特殊处理,不进行三等分
if(!creator.getTargetChildrenList().isEmpty()){ if (!creator.getTargetChildrenList().isEmpty()) {
return false; return false;
} }
@ -169,11 +161,10 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
} }
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围 //当前绝对布局不可编辑,就当成一个控件,组件添加在周围
private boolean acceptWidget(XCreator creator, int x, int y){ private boolean acceptWidget(int x, int y) {
isFindRelatedComps = false; isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y); Component comp = container.getComponentAt(x, y);
boolean isMatchEdge = false;
//如果当前处于边缘地带, 那么就把他贴到父容器上 //如果当前处于边缘地带, 那么就把他贴到父容器上
XLayoutContainer parent = container.findNearestFit(); XLayoutContainer parent = container.findNearestFit();
container = parent != null ? parent : container; container = parent != null ? parent : container;
@ -224,7 +215,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
@Override @Override
protected void addComp(XCreator creator, int x, int y) { protected void addComp(XCreator creator, int x, int y) {
if(!isAdd2ParentLayout) { if (!isAdd2ParentLayout) {
Rectangle r = ComponentUtils.getRelativeBounds(container); Rectangle r = ComponentUtils.getRelativeBounds(container);
x = x - r.x; x = x - r.x;
y = y - r.y; y = y - r.y;
@ -250,7 +241,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
layout.updateBoundsWidget(creator); layout.updateBoundsWidget(creator);
updateCreatorBackBound(); updateCreatorBackBound();
LayoutUtils.layoutRootContainer(container); LayoutUtils.layoutRootContainer(container);
}else{ } else {
fixAbsolute(creator, x, y); fixAbsolute(creator, x, y);
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { if (creator.shouldScaleCreator() || creator.hasTitleStyle()) {
addParentCreator(creator); addParentCreator(creator);
@ -265,7 +256,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
} }
private void updateCreatorBackBound() { private void updateCreatorBackBound() {
for (int i=0,size=container.getComponentCount(); i<size; i++) { for (int i = 0, size = container.getComponentCount(); i < size; i++) {
XCreator creator = (XCreator) container.getComponent(i); XCreator creator = (XCreator) container.getComponent(i);
creator.updateChildBound(minHeight); creator.updateChildBound(minHeight);
creator.setBackupBound(creator.getBounds()); creator.setBackupBound(creator.getBounds());
@ -279,16 +270,17 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 新拖入组件时计算调整其他关联组件位置大小 * 新拖入组件时计算调整其他关联组件位置大小
*
* @param child 新拖入的组件 * @param child 新拖入的组件
* @param x 鼠标所在x坐标 * @param x 鼠标所在x坐标
* @param y 鼠标所在y坐标 * @param y 鼠标所在y坐标
*/ */
private void fixAbsolute(XCreator child, int x, int y) { private void fixAbsolute(XCreator child, int x, int y) {
Component parentComp = container.getComponentAt(x, y); Component parentComp = container.getComponentAt(x, y);
if (container.getComponentCount()==0){ if (container.getComponentCount() == 0) {
child.setLocation(0, 0); child.setLocation(0, 0);
child.setSize(parentComp.getWidth(), parentComp.getHeight()); child.setSize(parentComp.getWidth(), parentComp.getHeight());
} else if(isCrossPointArea(parentComp, x, y)){ } else if (isCrossPointArea(parentComp, x, y)) {
//交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入 //交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入
fixCrossPointArea(parentComp, child, x, y); fixCrossPointArea(parentComp, child, x, y);
return; return;
@ -296,20 +288,21 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
// 在边界三等分区域,就不再和组件二等分了 // 在边界三等分区域,就不再和组件二等分了
fixTrisect(parentComp, child, x, y); fixTrisect(parentComp, child, x, y);
return; return;
} else{ } else {
fixHalve(parentComp, child, x, y); fixHalve(parentComp, child, x, y);
} }
} }
/** /**
* 组件拖拽后调整大小 * 组件拖拽后调整大小
*
* @param creator 组件 * @param creator 组件
*/ */
@Override @Override
public void fix(XCreator creator) { public void fix(XCreator creator) {
WAbsoluteLayout wabs = (WAbsoluteLayout)container.toData(); WAbsoluteLayout wabs = (WAbsoluteLayout) container.toData();
fix(creator,creator.getX(),creator.getY()); fix(creator, creator.getX(), creator.getY());
wabs.setBounds(creator.toData(),creator.getBounds()); wabs.setBounds(creator.toData(), creator.getBounds());
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
layout.updateBoundsWidget(creator); layout.updateBoundsWidget(creator);
@ -317,25 +310,24 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 调整组件大小到合适尺寸位置 * 调整组件大小到合适尺寸位置
*
* @param creator 组件 * @param creator 组件
* @param x 坐标x * @param x 坐标x
* @param y 坐标y * @param y 坐标y
*/ */
public void fix(XCreator creator ,int x, int y) { public void fix(XCreator creator, int x, int y) {
int height = creator.getHeight(); int height = creator.getHeight();
int width = creator.getWidth(); int width = creator.getWidth();
if (x < 0) { if (x < 0) {
width += x; x = container.getX();
x = 0;
} else if (x + creator.getWidth() > container.getWidth()) { } else if (x + creator.getWidth() > container.getWidth()) {
width = container.getWidth() - x; x = container.getWidth() - width;
} }
if (y < 0) { if (y < 0) {
height += y; y = container.getY();
y = 0;
} else if (y + creator.getHeight() > container.getHeight()) { } else if (y + creator.getHeight() > container.getHeight()) {
height = container.getHeight() - y; y = container.getHeight() - height;
} }
creator.setBounds(x, y, width, height); creator.setBounds(x, y, width, height);
@ -343,7 +335,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
@Override @Override
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { public ConstraintsGroupModel getLayoutConstraints(XCreator creator) {
return new BoundsGroupModel((XWAbsoluteLayout)container, creator); return new BoundsGroupModel((XWAbsoluteLayout) container, creator);
} }
@Override @Override

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

@ -3,12 +3,6 @@
*/ */
package com.fr.design.designer.beans.adapters.layout; package com.fr.design.designer.beans.adapters.layout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import com.fr.design.beans.GroupModel; import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.HoverPainter;
@ -28,8 +22,12 @@ import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.LayoutBorderStyle;
import com.fr.form.ui.container.WLayout; import com.fr.form.ui.container.WLayout;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.form.ui.widget.BoundsWidget;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/** /**
* 自适应布局的容器适配器 * 自适应布局的容器适配器
@ -52,6 +50,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
public void setEdit(boolean edit) { public void setEdit(boolean edit) {
isEdit = edit; isEdit = edit;
} }
/** /**
* 构造函数 * 构造函数
* *
@ -134,7 +133,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
isFindRelatedComps = false; isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y); Component comp = container.getComponentAt(x, y);
if (checkInterval(comp)) { if (comp == null || checkInterval(comp)) {
return false; return false;
} }
//如果当前处于边缘地带, 那么就把他贴到父容器上 //如果当前处于边缘地带, 那么就把他贴到父容器上
@ -269,15 +268,8 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
return super.isCrossPointArea(currentComp, x, y); return super.isCrossPointArea(currentComp, x, y);
} }
protected void initCompsList() {
super.initCompsList();
}
protected void clearCompsList() {
super.clearCompsList();
}
protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout){ protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) {
return mainLayout.getBounds(); return mainLayout.getBounds();
} }
@ -359,7 +351,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
* @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 +362,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 +416,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 +432,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;
@ -558,8 +550,8 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
difference = Math.max(difference, minWidth - getMinWidth(leftComps)); difference = Math.max(difference, minWidth - getMinWidth(leftComps));
} }
//重新计算左右两侧组件size、point //重新计算左右两侧组件size、point
if (CalculateLefttRelatComponent(difference)) { if (calculateLefttRelatComponent(difference)) {
CalculateRightRelatComponent(objx + difference, -difference); calculateRightRelatComponent(objx + difference, -difference);
} }
} }
@ -674,10 +666,9 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
difference = Math.max(difference, minHeight - getMinHeight(upComps)); difference = Math.max(difference, minHeight - getMinHeight(upComps));
} }
//重新计算上下两侧组件size、point //重新计算上下两侧组件size、point
if (CalculateUpRelatComponent(difference)) { if (calculateUpRelatComponent(difference)) {
CalculateDownRelatComponent(objY + difference, -difference); calculateDownRelatComponent(objY + difference, -difference);
} }
;
} }
/** /**
@ -757,13 +748,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
int height = creatorHeight; int height = creatorHeight;
calculateRelatedComponent(x, y, width, height); calculateRelatedComponent(x, y, width, height);
if (!rightComps.isEmpty() && getAllHeight(rightComps) == height) { if (!rightComps.isEmpty() && getAllHeight(rightComps) == height) {
CalculateRightRelatComponent(x, width + actualVal); calculateRightRelatComponent(x, width + actualVal);
} else if (!leftComps.isEmpty() && getAllHeight(leftComps) == height) { } else if (!leftComps.isEmpty() && getAllHeight(leftComps) == height) {
CalculateLefttRelatComponent(width + actualVal); calculateLefttRelatComponent(width + actualVal);
} else if (!downComps.isEmpty() && getAllWidth(downComps) == width) { } else if (!downComps.isEmpty() && getAllWidth(downComps) == width) {
CalculateDownRelatComponent(y, height + actualVal); calculateDownRelatComponent(y, height + actualVal);
} else if (!upComps.isEmpty() && getAllWidth(upComps) == width) { } else if (!upComps.isEmpty() && getAllWidth(upComps) == width) {
CalculateUpRelatComponent(height + actualVal); calculateUpRelatComponent(height + actualVal);
} else { } else {
// 由于布局三等分的存在,可能会出现删除组件时,找不到关联的组件填充,此时特殊处理 // 由于布局三等分的存在,可能会出现删除组件时,找不到关联的组件填充,此时特殊处理
calculateNoRelatedComponent(x, y, width, height); calculateNoRelatedComponent(x, y, width, height);
@ -1026,7 +1017,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
setAdjustedSize(tabLayout, offset, isHor); setAdjustedSize(tabLayout, offset, isHor);
for (int m = 0; m < tabLayout.getComponentCount(); m++) { for (int m = 0; m < tabLayout.getComponentCount(); m++) {
XCreator childCreator = tabLayout.getXCreator(m); XCreator childCreator = tabLayout.getXCreator(m);
BoundsWidget wgt = (BoundsWidget) tabLayout.toData().getBoundsWidget(childCreator.toData()); BoundsWidget wgt = tabLayout.toData().getBoundsWidget(childCreator.toData());
wgt.setBounds(tabLayout.getComponent(m).getBounds()); wgt.setBounds(tabLayout.getComponent(m).getBounds());
} }
adjustCreatorsSize(percent, tabLayout, isHor); adjustCreatorsSize(percent, tabLayout, isHor);
@ -1069,7 +1060,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
* @param objX 调整后的坐标x * @param objX 调整后的坐标x
* @param objWidth 调整后的宽度 * @param objWidth 调整后的宽度
*/ */
protected void CalculateRightRelatComponent(int objX, int objWidth) { protected void calculateRightRelatComponent(int objX, int objWidth) {
int count = rightComps.size(); int count = rightComps.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XCreator creator = (XCreator) rightComps.get(i); XCreator creator = (XCreator) rightComps.get(i);
@ -1109,7 +1100,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 删除或拉伸控件左边框时 调整左侧的组件位置大小 * 删除或拉伸控件左边框时 调整左侧的组件位置大小
*/ */
protected boolean CalculateLefttRelatComponent(int objWidth) { protected boolean calculateLefttRelatComponent(int objWidth) {
if (isBeyondAdjustWidthScope(objWidth)) { if (isBeyondAdjustWidthScope(objWidth)) {
return false; return false;
} }
@ -1127,7 +1118,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 删除或拉伸下边框 调整下方的组件位置大小 * 删除或拉伸下边框 调整下方的组件位置大小
*/ */
protected void CalculateDownRelatComponent(int objY, int objHeight) { protected void calculateDownRelatComponent(int objY, int objHeight) {
int count = downComps.size(); int count = downComps.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XCreator creator = (XCreator) downComps.get(i); XCreator creator = (XCreator) downComps.get(i);
@ -1167,7 +1158,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 删除或拉伸上边框 调整上方的组件位置大小 * 删除或拉伸上边框 调整上方的组件位置大小
*/ */
protected boolean CalculateUpRelatComponent(int objHeight) { protected boolean calculateUpRelatComponent(int objHeight) {
if (isBeyondAdjustHeightScope(objHeight)) { if (isBeyondAdjustHeightScope(objHeight)) {
return false; return false;
} }

95
designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java

@ -3,18 +3,16 @@
*/ */
package com.fr.design.designer.beans.location; package com.fr.design.designer.beans.location;
import java.awt.*;
import com.fr.design.beans.location.Absorptionline; import com.fr.design.beans.location.Absorptionline;
import com.fr.design.beans.location.MoveUtils; import com.fr.design.beans.location.MoveUtils;
import com.fr.design.designer.creator.*; import com.fr.design.designer.creator.*;
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.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.form.main.Form;
import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WParameterLayout; import com.fr.form.ui.widget.BoundsWidget;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import java.awt.*;
/** /**
* @author richer * @author richer
@ -28,27 +26,25 @@ public abstract class AccessDirection implements Direction {
abstract int getCursor(); abstract int getCursor();
protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle currentBounds, FormDesigner designer,
Rectangle oldbounds); Rectangle oldBounds);
protected int[] sorption(int x, int y,Rectangle current_bounds, FormDesigner designer) { protected int[] sorption(int x, int y, Rectangle currentBounds, FormDesigner designer) {
// 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理 // 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理
if (!designer.hasWAbsoluteLayout()) { if (!designer.hasWAbsoluteLayout()) {
designer.getStateModel().setEquidistantLine(null); designer.getStateModel().setEquidistantLine(null);
designer.getStateModel().setXAbsorptionline(null); designer.getStateModel().setXAbsorptionline(null);
designer.getStateModel().setYAbsorptionline(null); designer.getStateModel().setYAbsorptionline(null);
return new int[] { x, y }; return new int[]{x, y};
} else { } else {
int posy = current_bounds.y; Point relativePoint = getRelativePoint(x, y, currentBounds, designer);
sorptionPoint(relativePoint, currentBounds, designer);
Point relativePoint = getRelativePoint(x, y, current_bounds,designer); return new int[]{relativePoint.x, relativePoint.y};
sorptionPoint(relativePoint,current_bounds, designer);
return new int[] { relativePoint.x, relativePoint.y };
} }
} }
protected Point getRelativePoint(int x, int y, Rectangle current_bounds,FormDesigner designer) { protected Point getRelativePoint(int x, int y, Rectangle currentBounds, FormDesigner designer) {
if (x < 0) { if (x < 0) {
x = 0; x = 0;
} else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) { } else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) {
@ -64,12 +60,11 @@ public abstract class AccessDirection implements Direction {
return new Point(x, y); return new Point(x, y);
} }
protected void sorptionPoint(Point point, Rectangle current_bounds,FormDesigner designer) { protected void sorptionPoint(Point point, Rectangle currentBounds, FormDesigner designer) {
boolean findInX = current_bounds.getWidth() <= MoveUtils.SORPTION_UNIT ? true : false; boolean findInX = currentBounds.getWidth() <= MoveUtils.SORPTION_UNIT;
boolean findInY = current_bounds.getHeight() <= MoveUtils.SORPTION_UNIT ? true : false; boolean findInY = currentBounds.getHeight() <= MoveUtils.SORPTION_UNIT;
WAbsoluteLayout layout =getLayout(designer); WAbsoluteLayout layout = getLayout(designer);
FormSelection selection = designer.getSelectionModel().getSelection(); FormSelection selection = designer.getSelectionModel().getSelection();
boolean isWidgetsIntersect = false;
for (int i = 0, count = layout.getWidgetCount(); i < count; i++) { for (int i = 0, count = layout.getWidgetCount(); i < count; i++) {
BoundsWidget temp = (BoundsWidget) layout.getWidget(i); BoundsWidget temp = (BoundsWidget) layout.getWidget(i);
if (!temp.isVisible() || selection.contains(temp.getWidget())) { if (!temp.isVisible() || selection.contains(temp.getWidget())) {
@ -105,21 +100,18 @@ public abstract class AccessDirection implements Direction {
break; break;
} }
if (current_bounds.intersects(bounds) && !(layout instanceof WParameterLayout)){
isWidgetsIntersect = true;
} }
} setDesignerStateModelProperties(designer, findInX, findInY, currentBounds, point);
processRectangleIntersects(designer, point.x, point.y, isWidgetsIntersect);
setDesignerStateModelProperties(designer, findInX, findInY, current_bounds, point);
} }
private void setDesignerStateModelProperties (FormDesigner designer, boolean findInX, boolean findInY, Rectangle current_bounds, Point point) { private void setDesignerStateModelProperties(FormDesigner designer, boolean findInX, boolean findInY, Rectangle
designer.getStateModel().setXAbsorptionline(findInX && current_bounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null); currentBounds, Point point) {
designer.getStateModel().setYAbsorptionline(findInY && current_bounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null); designer.getStateModel().setXAbsorptionline(findInX && currentBounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null);
designer.getStateModel().setYAbsorptionline(findInY && currentBounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null);
designer.getStateModel().setEquidistantLine(null); designer.getStateModel().setEquidistantLine(null);
} }
private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection){ private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection) {
Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height); Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (parent == null) { if (parent == null) {
@ -131,32 +123,19 @@ public abstract class AccessDirection implements Direction {
return relativeRec; return relativeRec;
} }
private void processRectangleIntersects(FormDesigner designer, int x, int y, boolean isIntersects){
if(isIntersects){
if(designer.getLocationOnScreen() != null) {
MoveUtils.displayForbidWindow(x + designer.getLocationOnScreen().x, y + designer.getLocationOnScreen().y);
}
designer.setWidgetsIntersect(true);
}
else{
MoveUtils.hideForbidWindow();
designer.setWidgetsIntersect(false);
}
}
private WAbsoluteLayout getLayout(final FormDesigner designer){ private WAbsoluteLayout getLayout(final FormDesigner designer) {
XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator( XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(
designer.getTarget().getContainer()); designer.getTarget().getContainer());
WAbsoluteLayout layout; WAbsoluteLayout layout;
if (formLayoutContainer.acceptType(XWBorderLayout.class)){//看起来这边的作用应该是为了区别cpt(得到XWParameterLayout)还是frm(得到XWBorderLayout)的参数界面 if (formLayoutContainer.acceptType(XWBorderLayout.class)) {//看起来这边的作用应该是为了区别cpt(得到XWParameterLayout)还是frm(得到XWBorderLayout)的参数界面
Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent(); Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent();
if(container instanceof XWAbsoluteLayout){ if (container instanceof XWAbsoluteLayout) {
layout = ((XWAbsoluteLayout)container).toData(); layout = ((XWAbsoluteLayout) container).toData();
} } else {
else {
layout = (WAbsoluteLayout) designer.getParaComponent().toData(); layout = (WAbsoluteLayout) designer.getParaComponent().toData();
} }
} else{ } else {
layout = (WAbsoluteLayout) designer.getTarget().getContainer(); layout = (WAbsoluteLayout) designer.getTarget().getContainer();
} }
return layout; return layout;
@ -164,20 +143,26 @@ public abstract class AccessDirection implements Direction {
/** /**
* 拖拽 * 拖拽
*
* @param dx 坐标x * @param dx 坐标x
* @param dy 坐标y * @param dy 坐标y
* @param designer 设计界面 * @param designer 设计界面
*/ */
public void drag(int dx, int dy, FormDesigner designer) { public void drag(int dx, int dy, FormDesigner designer) {
Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds()); Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds());
if (rec != null) {
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer);
} else {
return;
}
//设定控件最小高度21,因每次拖曳至少移动1,防止控件高度等于21时,拖曳导致rec.y的变化使得控件不停的向上或向下移动。 //设定控件最小高度21,因每次拖曳至少移动1,防止控件高度等于21时,拖曳导致rec.y的变化使得控件不停的向上或向下移动。
if(rec.height == MINHEIGHT){ if (rec.height == MINHEIGHT) {
ymin = rec.y; ymin = rec.y;
} }
if(rec.height == MINHEIGHT - 1){ if (rec.height == MINHEIGHT - 1) {
ymin = ymin == rec.y ? rec.y : rec.y - 1; ymin = ymin == rec.y ? rec.y : rec.y - 1;
} }
if(rec.height < MINHEIGHT){ if (rec.height < MINHEIGHT) {
rec.height = MINHEIGHT; rec.height = MINHEIGHT;
rec.y = ymin; rec.y = ymin;
} }
@ -185,20 +170,19 @@ public abstract class AccessDirection implements Direction {
if (rec.width == MINWIDTH) { if (rec.width == MINWIDTH) {
xmin = rec.x; xmin = rec.x;
} }
if(rec.width == MINWIDTH - 1){ if (rec.width == MINWIDTH - 1) {
xmin = xmin == rec.x ? rec.x : rec.x - 1; xmin = xmin == rec.x ? rec.x : rec.x - 1;
} }
if (rec.width < MINWIDTH) { if (rec.width < MINWIDTH) {
rec.width = MINWIDTH; rec.width = MINWIDTH;
rec.x = xmin; rec.x = xmin;
} }
if(rec != null) {
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer);
}
} }
/** /**
* 更新鼠标指针形状 * 更新鼠标指针形状
*
* @param formEditor 设计界面组件 * @param formEditor 设计界面组件
*/ */
public void updateCursor(FormDesigner formEditor) { public void updateCursor(FormDesigner formEditor) {
@ -214,6 +198,7 @@ public abstract class AccessDirection implements Direction {
/** /**
* 生成组件备用的bound * 生成组件备用的bound
*
* @param formEditor 设计界面组件 * @param formEditor 设计界面组件
*/ */
public void backupBounds(FormDesigner formEditor) { public void backupBounds(FormDesigner formEditor) {

Loading…
Cancel
Save