Browse Source

REPORT-1899

master
yaoh.wu 8 years ago
parent
commit
d6b22c772d
  1. 298
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java
  2. 120
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java

298
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java

@ -2,6 +2,7 @@ package com.fr.design.designer.beans.adapters.layout;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.PaddingMargin; import com.fr.form.ui.PaddingMargin;
@ -17,7 +18,7 @@ import java.util.*;
* 所以把公共的方法挪动这边父类里来 * 所以把公共的方法挪动这边父类里来
* Created by zhouping on 2016/8/18. * Created by zhouping on 2016/8/18.
*/ */
public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter {
protected static final int COMP_TOP = 1; protected static final int COMP_TOP = 1;
protected static final int COMP_BOTTOM = 2; protected static final int COMP_BOTTOM = 2;
protected static final int COMP_LEFT = 3; protected static final int COMP_LEFT = 3;
@ -49,6 +50,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
protected int minHeight = 0; protected int minHeight = 0;
protected int actualVal = 0; // 存在间隔时,add move drag 判断对齐等都要考虑 protected int actualVal = 0; // 存在间隔时,add move drag 判断对齐等都要考虑
protected PaddingMargin margin; // 布局容器边距 protected PaddingMargin margin; // 布局容器边距
/** /**
* 在添加组件状态时当鼠标移动到某个容器上方时如果该容器有布局管理器则会调用该布局 * 在添加组件状态时当鼠标移动到某个容器上方时如果该容器有布局管理器则会调用该布局
* 管理适配器的accept来决定当前位置是否可以放置并提供特殊的标识比如红色区域标识 * 管理适配器的accept来决定当前位置是否可以放置并提供特殊的标识比如红色区域标识
@ -76,9 +78,10 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
/** /**
* 交叉点区域时能否对应位置放入组件 * 交叉点区域时能否对应位置放入组件
*
* @param comp 待放置组件 * @param comp 待放置组件
* @param x x * @param x x
* @param y y * @param y y
* @return 能否放入 * @return 能否放入
*/ */
protected boolean canAcceptWhileCrossPoint(Component comp, int x, int y) { protected boolean canAcceptWhileCrossPoint(Component comp, int x, int y) {
@ -95,7 +98,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
min = isNotDefaultArea ? min : minWidth * 2; min = isNotDefaultArea ? min : minWidth * 2;
} else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_RIGHT_BOTTOM)) { } else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_RIGHT_BOTTOM)) {
bottomComp = container.getRightBottomComp(cX, cY, cH, cW); bottomComp = container.getRightBottomComp(cX, cY, cH, cW);
isNotDefaultArea = (bottomComp == null) || (bottomComp.getX()+bottomComp.getWidth() != cX + cW) ; isNotDefaultArea = (bottomComp == null) || (bottomComp.getX() + bottomComp.getWidth() != cX + cW);
rightComp = container.getBottomRightComp(cX, cY, cH, cW); rightComp = container.getBottomRightComp(cX, cY, cH, cW);
minLength = isNotDefaultArea ? Math.min(cH, rightComp.getHeight()) : Math.min(cW, bottomComp.getWidth()); minLength = isNotDefaultArea ? Math.min(cH, rightComp.getHeight()) : Math.min(cW, bottomComp.getWidth());
min = isNotDefaultArea ? min : minWidth * 2; min = isNotDefaultArea ? min : minWidth * 2;
@ -105,12 +108,12 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
minLength = isNotDefaultArea ? Math.min(cW, bottomComp.getWidth()) : Math.min(cH, leftComp.getHeight()); minLength = isNotDefaultArea ? Math.min(cW, bottomComp.getWidth()) : Math.min(cH, leftComp.getHeight());
min = isNotDefaultArea ? minWidth * 2 : min; min = isNotDefaultArea ? minWidth * 2 : min;
} else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_RIGHT_TOP)) { } else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_RIGHT_TOP)) {
isNotDefaultArea = (rightComp == null) || (rightComp.getY() != cY) ; isNotDefaultArea = (rightComp == null) || (rightComp.getY() != cY);
topComp = container.getRightTopComp(cX, cY, cW); topComp = container.getRightTopComp(cX, cY, cW);
minLength = isNotDefaultArea ? Math.min(cW, topComp.getWidth()) : Math.min(cH, rightComp.getWidth()); minLength = isNotDefaultArea ? Math.min(cW, topComp.getWidth()) : Math.min(cH, rightComp.getWidth());
min = isNotDefaultArea ? minWidth * 2 : min ; min = isNotDefaultArea ? minWidth * 2 : min;
} else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_TOP)) { } else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_TOP)) {
minLength= Math.min(rightComp.getHeight(), Math.min(cH, leftComp.getHeight())); minLength = Math.min(rightComp.getHeight(), Math.min(cH, leftComp.getHeight()));
} else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_BOTTOM)) { } else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_BOTTOM)) {
leftComp = container.getBottomLeftComp(cX, cY, cH); leftComp = container.getBottomLeftComp(cX, cY, cH);
rightComp = container.getBottomRightComp(cX, cY, cH, cW); rightComp = container.getBottomRightComp(cX, cY, cH, cW);
@ -129,9 +132,10 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
/** /**
* 三等分区域时能否对应位置放入组件 * 三等分区域时能否对应位置放入组件
*
* @param comp 待放置组件 * @param comp 待放置组件
* @param x x * @param x x
* @param y y * @param y y
* @return 能否放入 * @return 能否放入
*/ */
protected boolean canAcceptWhileTrisection(Component comp, int x, int y) { protected boolean canAcceptWhileTrisection(Component comp, int x, int y) {
@ -142,28 +146,28 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
upMinHeight = getUpMinHeightComp(cY, x); upMinHeight = getUpMinHeightComp(cY, x);
downMinHeight = getDownMinHeightComp(comp, y); downMinHeight = getDownMinHeightComp(comp, y);
return upMinHeight == 0 ? downMinHeight >= minHeight * 2 + actualVal : (upMinHeight + downMinHeight) >= minHeight * 3 + actualVal; return upMinHeight == 0 ? downMinHeight >= minHeight * 2 + actualVal : (upMinHeight + downMinHeight) >= minHeight * 3 + actualVal;
} else if(ComparatorUtils.equals(trisectAreaDirect, COMP_BOTTOM)) { } else if (ComparatorUtils.equals(trisectAreaDirect, COMP_BOTTOM)) {
upMinHeight = getUpMinHeightComp(cY + cH + actualVal, x); upMinHeight = getUpMinHeightComp(cY + cH + actualVal, x);
if (cY + cH + DEFAULT_AREA_LENGTH>container.getHeight() - margin.getBottom()){ if (cY + cH + DEFAULT_AREA_LENGTH > container.getHeight() - margin.getBottom()) {
downMinHeight = 0; downMinHeight = 0;
} else { } else {
Component targetComp = container.getBottomComp(x, cY, cH); Component targetComp = container.getBottomComp(x, cY, cH);
downMinHeight = getDownMinHeightComp(targetComp, cY + cH + DEFAULT_AREA_LENGTH + actualVal); downMinHeight = getDownMinHeightComp(targetComp, cY + cH + DEFAULT_AREA_LENGTH + actualVal);
} }
return downMinHeight == 0 ? (upMinHeight >= minHeight * 2 + actualVal) : ((upMinHeight+downMinHeight) >= minHeight * 3 + actualVal); return downMinHeight == 0 ? (upMinHeight >= minHeight * 2 + actualVal) : ((upMinHeight + downMinHeight) >= minHeight * 3 + actualVal);
} else if(ComparatorUtils.equals(trisectAreaDirect, COMP_LEFT)) { } else if (ComparatorUtils.equals(trisectAreaDirect, COMP_LEFT)) {
rightMinWidth = getMinRightWidth(cX, 0, y); rightMinWidth = getMinRightWidth(cX, 0, y);
if(cX - DEFAULT_AREA_LENGTH < margin.getLeft()) { if (cX - DEFAULT_AREA_LENGTH < margin.getLeft()) {
leftMinWidth = 0; leftMinWidth = 0;
} else { } else {
Component targetRightComp = container.getLeftComp(cX, y); Component targetRightComp = container.getLeftComp(cX, y);
leftMinWidth = getMinLeftWidth(targetRightComp, cX - DEFAULT_AREA_LENGTH - actualVal); leftMinWidth = getMinLeftWidth(targetRightComp, cX - DEFAULT_AREA_LENGTH - actualVal);
} }
return leftMinWidth == 0 ? (rightMinWidth >= minWidth * 2 + actualVal) : ((leftMinWidth+rightMinWidth) >= minWidth * 3 + actualVal); return leftMinWidth == 0 ? (rightMinWidth >= minWidth * 2 + actualVal) : ((leftMinWidth + rightMinWidth) >= minWidth * 3 + actualVal);
} else if(ComparatorUtils.equals(trisectAreaDirect, COMP_RIGHT)) { } else if (ComparatorUtils.equals(trisectAreaDirect, COMP_RIGHT)) {
leftMinWidth = getMinLeftWidth(comp, x); leftMinWidth = getMinLeftWidth(comp, x);
rightMinWidth = getMinRightWidth(cX, cW, y); rightMinWidth = getMinRightWidth(cX, cW, y);
return rightMinWidth == 0 ? (leftMinWidth >= minWidth * 2 + actualVal) : ((leftMinWidth+rightMinWidth) >= minWidth * 3 + actualVal); return rightMinWidth == 0 ? (leftMinWidth >= minWidth * 2 + actualVal) : ((leftMinWidth + rightMinWidth) >= minWidth * 3 + actualVal);
} }
return false; return false;
} }
@ -176,16 +180,16 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
if (cY == margin.getTop()) { if (cY == margin.getTop()) {
return 0; return 0;
} }
int max=container.getWidth() - margin.getRight(); int max = container.getWidth() - margin.getRight();
int mouseX = x; int mouseX = x;
int minHeight = cY; int minHeight = cY;
int bott = 0; int bott = 0;
if (isFindRelatedComps) { if (isFindRelatedComps) {
upComps = new ArrayList<Component>(); upComps = new ArrayList<Component>();
} }
for(; mouseX<max; ){ for (; mouseX < max; ) {
Component comp = container.getTopComp(mouseX, cY); Component comp = container.getTopComp(mouseX, cY);
if(comp == null){ if (comp == null) {
break; break;
} }
bott = comp.getHeight() + comp.getY() + actualVal; bott = comp.getHeight() + comp.getY() + actualVal;
@ -197,26 +201,26 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
if (isFindRelatedComps) { if (isFindRelatedComps) {
upComps.add(comp); upComps.add(comp);
} }
} else{ } else {
break; break;
} }
} }
if(container.getTopComp(x, cY) == null){ if (container.getTopComp(x, cY) == null) {
return 0; return 0;
} }
mouseX = container.getTopComp(x, cY).getX() - DEFAULT_AREA_LENGTH - actualVal; mouseX = container.getTopComp(x, cY).getX() - DEFAULT_AREA_LENGTH - actualVal;
while(mouseX > margin.getLeft()) { while (mouseX > margin.getLeft()) {
Component comp = container.getTopComp(mouseX, cY); Component comp = container.getTopComp(mouseX, cY);
bott = comp.getHeight() + comp.getY()+actualVal; bott = comp.getHeight() + comp.getY() + actualVal;
if (bott == cY) { if (bott == cY) {
if (comp.getHeight() < minHeight) { if (comp.getHeight() < minHeight) {
minHeight = comp.getHeight(); minHeight = comp.getHeight();
} }
mouseX = comp.getX()-DEFAULT_AREA_LENGTH-actualVal; mouseX = comp.getX() - DEFAULT_AREA_LENGTH - actualVal;
if (isFindRelatedComps) { if (isFindRelatedComps) {
upComps.add(comp); upComps.add(comp);
} }
} else{ } else {
break; break;
} }
} }
@ -231,13 +235,13 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
int cX = currentcomp.getX(); int cX = currentcomp.getX();
int cY = currentcomp.getY(); int cY = currentcomp.getY();
int minHeight = currentcomp.getHeight(); int minHeight = currentcomp.getHeight();
int max=container.getWidth() - margin.getRight(); int max = container.getWidth() - margin.getRight();
if (isFindRelatedComps) { if (isFindRelatedComps) {
downComps = new ArrayList<Component>(); downComps = new ArrayList<Component>();
} }
int mouseX = cX + DEFAULT_AREA_LENGTH; int mouseX = cX + DEFAULT_AREA_LENGTH;
while (mouseX < max) { while (mouseX < max) {
Component comp = container.getComponentAt(mouseX, y); Component comp = container.getComponentAt(mouseX, y);
if (comp.getY() == cY) { if (comp.getY() == cY) {
if (comp.getHeight() < minHeight) { if (comp.getHeight() < minHeight) {
minHeight = comp.getHeight(); minHeight = comp.getHeight();
@ -246,12 +250,12 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
if (isFindRelatedComps) { if (isFindRelatedComps) {
downComps.add(comp); downComps.add(comp);
} }
}else{ } else {
break; break;
} }
} }
mouseX = cX - DEFAULT_AREA_LENGTH - actualVal; mouseX = cX - DEFAULT_AREA_LENGTH - actualVal;
while(mouseX > margin.getLeft()) { while (mouseX > margin.getLeft()) {
Component comp = container.getComponentAt(mouseX, y); Component comp = container.getComponentAt(mouseX, y);
if (comp.getY() == cY) { if (comp.getY() == cY) {
if (comp.getHeight() < minHeight) { if (comp.getHeight() < minHeight) {
@ -261,7 +265,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
if (isFindRelatedComps) { if (isFindRelatedComps) {
downComps.add(comp); downComps.add(comp);
} }
}else{ } else {
break; break;
} }
} }
@ -273,9 +277,9 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
* 判断对齐时考虑间隔 * 判断对齐时考虑间隔
*/ */
private int getMinRightWidth(int cX, int cW, int y) { private int getMinRightWidth(int cX, int cW, int y) {
int xL = cX + DEFAULT_AREA_LENGTH ; int xL = cX + DEFAULT_AREA_LENGTH;
xL = cW == 0 ? xL : (xL + cW + actualVal); xL = cW == 0 ? xL : (xL + cW + actualVal);
if (xL > container.getWidth() - margin.getRight()){ if (xL > container.getWidth() - margin.getRight()) {
return 0; return 0;
} }
// 以当前组件紧挨着右侧的组件为基准,在y轴方向查找符合条件的组件 // 以当前组件紧挨着右侧的组件为基准,在y轴方向查找符合条件的组件
@ -286,7 +290,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
rightComps = new ArrayList<Component>(); rightComps = new ArrayList<Component>();
} }
int mouseY = targetComp.getY() + DEFAULT_AREA_LENGTH; int mouseY = targetComp.getY() + DEFAULT_AREA_LENGTH;
while (mouseY<max) { while (mouseY < max) {
Component comp = container.getComponentAt(xL, mouseY); Component comp = container.getComponentAt(xL, mouseY);
if (comp.getX() == targetComp.getX()) { if (comp.getX() == targetComp.getX()) {
if (comp.getWidth() < minWidth) { if (comp.getWidth() < minWidth) {
@ -296,12 +300,12 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
if (isFindRelatedComps) { if (isFindRelatedComps) {
rightComps.add(comp); rightComps.add(comp);
} }
}else{ } else {
break; break;
} }
} }
mouseY = targetComp.getY() - DEFAULT_AREA_LENGTH - actualVal; mouseY = targetComp.getY() - DEFAULT_AREA_LENGTH - actualVal;
while(mouseY > margin.getTop()) { while (mouseY > margin.getTop()) {
Component comp = container.getComponentAt(xL, mouseY); Component comp = container.getComponentAt(xL, mouseY);
if (comp.getX() == targetComp.getX()) { if (comp.getX() == targetComp.getX()) {
if (comp.getWidth() < minWidth) { if (comp.getWidth() < minWidth) {
@ -311,7 +315,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
if (isFindRelatedComps) { if (isFindRelatedComps) {
rightComps.add(comp); rightComps.add(comp);
} }
}else{ } else {
break; break;
} }
} }
@ -329,9 +333,9 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
if (isFindRelatedComps) { if (isFindRelatedComps) {
leftComps = new ArrayList<Component>(); leftComps = new ArrayList<Component>();
} }
int rightx = 0; int rightx = 0;
int mouseY = currentComp.getY() + DEFAULT_AREA_LENGTH; int mouseY = currentComp.getY() + DEFAULT_AREA_LENGTH;
while(mouseY<max) { while (mouseY < max) {
Component comp = container.getComponentAt(x, mouseY); Component comp = container.getComponentAt(x, mouseY);
rightx = comp.getX() + comp.getWidth(); rightx = comp.getX() + comp.getWidth();
if (rightx == compRightLength) { if (rightx == compRightLength) {
@ -342,14 +346,14 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
if (isFindRelatedComps) { if (isFindRelatedComps) {
leftComps.add(comp); leftComps.add(comp);
} }
}else{ } else {
break; break;
} }
} }
mouseY = currentComp.getY() - DEFAULT_AREA_LENGTH - actualVal; mouseY = currentComp.getY() - DEFAULT_AREA_LENGTH - actualVal;
while(mouseY>margin.getTop()) { while (mouseY > margin.getTop()) {
Component comp = container.getComponentAt(x, mouseY); Component comp = container.getComponentAt(x, mouseY);
rightx = comp.getX()+comp.getWidth(); rightx = comp.getX() + comp.getWidth();
if (rightx == compRightLength) { if (rightx == compRightLength) {
if (comp.getWidth() < minWidth) { if (comp.getWidth() < minWidth) {
minWidth = comp.getWidth(); minWidth = comp.getWidth();
@ -358,7 +362,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
if (isFindRelatedComps) { if (isFindRelatedComps) {
leftComps.add(comp); leftComps.add(comp);
} }
}else{ } else {
break; break;
} }
} }
@ -367,13 +371,14 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
/** /**
* 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分 * 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分
*
* @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;
if (container.getComponentCount() <= 1) { if (container.getComponentCount() <= 1) {
return false; return false;
} }
@ -382,23 +387,23 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
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;
} }
@ -407,21 +412,22 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
/** /**
* 是否为组件交叉点区域 或者是相邻三组建中间点 * 是否为组件交叉点区域 或者是相邻三组建中间点
*
* @param currentComp 当前组件 * @param currentComp 当前组件
* @param x 坐标x * @param x 坐标x
* @param y 坐标y * @param y 坐标y
* @return 是则返回true * @return 是则返回true
*/ */
public boolean isCrossPointArea(Component currentComp, int x, int y) { public boolean isCrossPointArea(Component currentComp, int x, int y) {
// 3个及以上都会出现交叉点区域(包括边界处的) // 3个及以上都会出现交叉点区域(包括边界处的)
if(currentComp == null || container.getComponentCount() <= 2){ if (currentComp == null || container.getComponentCount() <= 2) {
return false; return false;
} }
int cX = currentComp.getX(); int cX = currentComp.getX();
int cY = currentComp.getY(); int cY = currentComp.getY();
int cW = currentComp.getWidth(); int cW = currentComp.getWidth();
int cH = currentComp.getHeight(); int cH = currentComp.getHeight();
int areaWidth = Math.max(cW / BORDER_PROPORTION ,DEFAULT_AREA_LENGTH); int areaWidth = Math.max(cW / BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
int areaHeight = Math.max(cH / BORDER_PROPORTION, DEFAULT_AREA_LENGTH); int areaHeight = Math.max(cH / BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
int rx = cX + cW; int rx = cX + cW;
int by = cY + cH; int by = cY + cH;
@ -432,27 +438,27 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
if (x < objX && y < objY) { if (x < objX && y < objY) {
//左上角区域 //左上角区域
crossPointAreaDirect = cY > margin.getTop() || cX > margin.getLeft() ? COMP_LEFT_TOP : 0; crossPointAreaDirect = cY > margin.getTop() || cX > margin.getLeft() ? COMP_LEFT_TOP : 0;
} else if (y < objY && x > rx - areaWidth){ } else if (y < objY && x > rx - areaWidth) {
//右上角 //右上角
crossPointAreaDirect = cY > margin.getTop() || rx < containerW ? COMP_RIGHT_TOP : 0; crossPointAreaDirect = cY > margin.getTop() || rx < containerW ? COMP_RIGHT_TOP : 0;
} else if (x < objX && y > by - areaHeight) { } else if (x < objX && y > by - areaHeight) {
//左下角 //左下角
crossPointAreaDirect = cX > margin.getLeft() || by < containerH ? COMP_LEFT_BOTTOM : 0; crossPointAreaDirect = cX > margin.getLeft() || by < containerH ? COMP_LEFT_BOTTOM : 0;
} else if (x > rx-areaWidth && y > by - areaHeight) { } else if (x > rx - areaWidth && y > by - areaHeight) {
//右下角 //右下角
crossPointAreaDirect = by < containerH || rx < containerW ? COMP_RIGHT_BOTTOM : 0; crossPointAreaDirect = by < containerH || rx < containerW ? COMP_RIGHT_BOTTOM : 0;
} else { } else {
isMiddlePosition(currentComp, x, y, areaWidth, areaHeight); isMiddlePosition(currentComp, x, y, areaWidth, areaHeight);
} }
// tab布局的边界特殊处理 // tab布局的边界特殊处理
XCreator creator = (XCreator)currentComp; XCreator creator = (XCreator) currentComp;
if(!creator.getTargetChildrenList().isEmpty()){ if (!creator.getTargetChildrenList().isEmpty()) {
return false; return false;
} }
return crossPointAreaDirect != 0; return crossPointAreaDirect != 0;
} }
private void isMiddlePosition(Component comp, int x, int y, int areaWidth , int areaHeight) { private void isMiddlePosition(Component comp, int x, int y, int areaWidth, int areaHeight) {
int cX = comp.getX(); int cX = comp.getX();
int cY = comp.getY(); int cY = comp.getY();
int cW = comp.getWidth(); int cW = comp.getWidth();
@ -479,14 +485,14 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
Component bottomComp = container.getBottomComp(cX, cY, cH); Component bottomComp = container.getBottomComp(cX, cY, cH);
if (x < (cX + areaWidth)) { if (x < (cX + areaWidth)) {
isCrosspoint = topComp != null && bottomComp != null && topComp.getX() == cX && bottomComp.getX() == cX; isCrosspoint = topComp != null && bottomComp != null && topComp.getX() == cX && bottomComp.getX() == cX;
crossPointAreaDirect = isCrosspoint ? COMP_LEFT : 0; crossPointAreaDirect = isCrosspoint ? COMP_LEFT : 0;
} else if (x > (cX + cW - areaWidth)) { } else if (x > (cX + cW - areaWidth)) {
topComp = container.getRightTopComp(cX, cY, cW); topComp = container.getRightTopComp(cX, cY, cW);
bottomComp = container.getRightBottomComp(cX, cY, cH, cW); bottomComp = container.getRightBottomComp(cX, cY, cH, cW);
if (topComp != null && bottomComp != null) { if (topComp != null && bottomComp != null) {
isCrosspoint = topComp.getX() + topComp.getWidth() == cX + cW && bottomComp.getX() + bottomComp.getWidth() == cX+cW; isCrosspoint = topComp.getX() + topComp.getWidth() == cX + cW && bottomComp.getX() + bottomComp.getWidth() == cX + cW;
} }
crossPointAreaDirect = isCrosspoint ? COMP_RIGHT : 0; crossPointAreaDirect = isCrosspoint ? COMP_RIGHT : 0;
} }
} }
} }
@ -513,15 +519,16 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
/** /**
* 平分正常情况拖入组件时按照上1/4区域下1/4区域为上下平分中左侧1/2区域中右侧1/2区域为左右平分 * 平分正常情况拖入组件时按照上1/4区域下1/4区域为上下平分中左侧1/2区域中右侧1/2区域为左右平分
*
* @param currentComp 当前位置组件 * @param currentComp 当前位置组件
* @param child 待放置组件 * @param child 待放置组件
* @param x x * @param x x
* @param y y * @param y y
*/ */
protected void fixHalve(Component currentComp, XCreator child, int x, int y) { protected void fixHalve(Component currentComp, XCreator child, int x, int y) {
XCreator creator = (XCreator)currentComp; XCreator creator = (XCreator) currentComp;
if(!creator.getTargetChildrenList().isEmpty()){ if (!creator.getTargetChildrenList().isEmpty()) {
fixHalveOfTab(creator,child,x,y); fixHalveOfTab(creator, child, x, y);
return; return;
} }
int maxWidth = currentComp.getWidth(); int maxWidth = currentComp.getWidth();
@ -536,18 +543,18 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
int finalY = yL; int finalY = yL;
int finalW = maxWidth; int finalW = maxWidth;
int finalH = maxHeight; int finalH = maxHeight;
if (isDividUp){ if (isDividUp) {
dim.width = maxWidth; dim.width = maxWidth;
dim.height = maxHeight / 2 - actualVal / 2; dim.height = maxHeight / 2 - actualVal / 2;
finalY = yL + dim.height + actualVal; finalY = yL + dim.height + actualVal;
finalH = maxHeight - dim.height - actualVal; finalH = maxHeight - dim.height - actualVal;
} else if(isDividDown){ } else if (isDividDown) {
// 若当前区域高度非偶数,那么和isDividUp时计算一致,否则永远都是上半部分小1px // 若当前区域高度非偶数,那么和isDividUp时计算一致,否则永远都是上半部分小1px
dim.height = maxHeight / 2 - actualVal / 2; dim.height = maxHeight / 2 - actualVal / 2;
dim.width = maxWidth; dim.width = maxWidth;
finalH = maxHeight - dim.height - actualVal; finalH = maxHeight - dim.height - actualVal;
yL = yL + finalH + actualVal; yL = yL + finalH + actualVal;
} else if(isDividLeft){ } else if (isDividLeft) {
dim.width = maxWidth / 2 - actualVal / 2; dim.width = maxWidth / 2 - actualVal / 2;
dim.height = maxHeight; dim.height = maxHeight;
finalX = xL + dim.width + actualVal; finalX = xL + dim.width + actualVal;
@ -571,7 +578,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
// 边界判断抄得原来的逻辑 // 边界判断抄得原来的逻辑
// tab布局的边界拖入新组件,和当前tab布局平分,这时候的actualVal组建间隔是tab里面的组建间隔 // tab布局的边界拖入新组件,和当前tab布局平分,这时候的actualVal组建间隔是tab里面的组建间隔
// 不应该在外层自适应布局添加 // 不应该在外层自适应布局添加
private void fixHalveOfTab(XCreator currentCreator, XCreator child, int x, int y){ private void fixHalveOfTab(XCreator currentCreator, XCreator child, int x, int y) {
int maxWidth = currentCreator.getWidth(); int maxWidth = currentCreator.getWidth();
int maxHeight = currentCreator.getHeight(); int maxHeight = currentCreator.getHeight();
int xL = currentCreator.getX(); int xL = currentCreator.getX();
@ -582,7 +589,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
int finalY = yL; int finalY = yL;
int finalW = maxWidth; int finalW = maxWidth;
int finalH = maxHeight; int finalH = maxHeight;
switch(position){ switch (position) {
case COMP_TOP: case COMP_TOP:
dim.width = maxWidth; dim.width = maxWidth;
dim.height = maxHeight / 2; dim.height = maxHeight / 2;
@ -592,7 +599,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
case COMP_BOTTOM: case COMP_BOTTOM:
dim.height = maxHeight / 2; dim.height = maxHeight / 2;
dim.width = maxWidth; dim.width = maxWidth;
finalH = maxHeight-dim.height; finalH = maxHeight - dim.height;
yL = yL + finalH; yL = yL + finalH;
break; break;
case COMP_LEFT: case COMP_LEFT:
@ -619,13 +626,31 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
} }
} }
private int getPositionOfFix(XCreator currentCreator,int x,int y){ private int getPositionOfFix(XCreator currentCreator, int x, int y) {
int position = 0; int position = 0;
XLayoutContainer cardLayout = ((XWCardMainBorderLayout) currentCreator).getCardPart(); XLayoutContainer cardLayout = ((XWCardMainBorderLayout) currentCreator).getCardPart();
XLayoutContainer container = (XLayoutContainer) cardLayout.getComponent(0); XLayoutContainer container = (XLayoutContainer) cardLayout.getComponent(0);
Rectangle rect = ComponentUtils.getRelativeBounds(container); Rectangle rect = ComponentUtils.getRelativeBounds(container);
/*
* 为了获取到鼠标drop位置的控件
* 我们之前已经将y值变为相对坐标值
* 由于在x轴上没有偏移所以x值一直等于相对坐标值最多差一个边界值1
* 在进行新添加的控件位置计算时
* 又通过ComponentUtils.getRelativeBounds()方法获取到了绝对坐标
* 再次计算相对坐标所以将y值重新变成绝对坐标
* */
if (currentCreator.getParent().getParent().getComponent(0) instanceof XWParameterLayout) {
int high = currentCreator.getParent().getParent().getComponent(0).getHeight();
y = y + WCardMainBorderLayout.TAB_HEIGHT + high;
} else {
y = y + WCardMainBorderLayout.TAB_HEIGHT;
}
int tempX = x - rect.x; int tempX = x - rect.x;
int tempY = y - rect.y + WCardMainBorderLayout.TAB_HEIGHT; int tempY = y - rect.y;
int containerX = container.getX(); int containerX = container.getX();
int containerY = container.getY(); int containerY = container.getY();
int containerWidth = container.getWidth(); int containerWidth = container.getWidth();
@ -634,13 +659,13 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
Rectangle currentXY = new Rectangle(tempX, tempY, 1, 1); Rectangle currentXY = new Rectangle(tempX, tempY, 1, 1);
// 上边缘 // 上边缘
Rectangle upEdge = new Rectangle(containerX, containerY, containerWidth, BORDER_PROPORTION); Rectangle upEdge = new Rectangle(containerX, containerY, containerWidth, BORDER_PROPORTION);
if(upEdge.intersects(currentXY)){ if (upEdge.intersects(currentXY)) {
position = COMP_TOP; position = COMP_TOP;
} }
int bottomY = containerY + containerHeight - BORDER_PROPORTION; int bottomY = containerY + containerHeight - BORDER_PROPORTION;
// 下边缘 // 下边缘
Rectangle bottomEdge = new Rectangle(containerX, bottomY, containerWidth, BORDER_PROPORTION); Rectangle bottomEdge = new Rectangle(containerX, bottomY, containerWidth, BORDER_PROPORTION);
if(bottomEdge.intersects(currentXY)){ if (bottomEdge.intersects(currentXY)) {
position = COMP_BOTTOM; position = COMP_BOTTOM;
} }
//左右边缘的高度 -10*2 是为了不和上下边缘重合 //左右边缘的高度 -10*2 是为了不和上下边缘重合
@ -648,7 +673,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
int leftY = containerY + BORDER_PROPORTION; int leftY = containerY + BORDER_PROPORTION;
// 左边缘 // 左边缘
Rectangle leftEdge = new Rectangle(containerX, leftY, BORDER_PROPORTION, verticalHeight); Rectangle leftEdge = new Rectangle(containerX, leftY, BORDER_PROPORTION, verticalHeight);
if(leftEdge.intersects(currentXY)){ if (leftEdge.intersects(currentXY)) {
position = COMP_LEFT; position = COMP_LEFT;
} }
return position; return position;
@ -658,37 +683,38 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
* 组件交叉区域进行插入时调整受到变动的其他组件,之前是交叉区域插入也按照三等分逻辑后面测试中发现有bug改为和bi一样的鼠标所在侧平分 * 组件交叉区域进行插入时调整受到变动的其他组件,之前是交叉区域插入也按照三等分逻辑后面测试中发现有bug改为和bi一样的鼠标所在侧平分
* 默认左上角右下角区域是垂直方向插入组件 * 默认左上角右下角区域是垂直方向插入组件
* 右上角和左下角是水平方向插入组件这样避免田字块时重复 * 右上角和左下角是水平方向插入组件这样避免田字块时重复
*
* @param currentComp 当前位置组件 * @param currentComp 当前位置组件
* @param child 待放置组件 * @param child 待放置组件
* @param x x * @param x x
* @param y y * @param y y
*/ */
protected void fixCrossPointArea(Component currentComp, XCreator child, int x, int y) { protected void fixCrossPointArea(Component currentComp, XCreator child, int x, int y) {
//计算前先全部初始化待调整控件所在的list //计算前先全部初始化待调整控件所在的list
initCompsList(); initCompsList();
switch(crossPointAreaDirect) { switch (crossPointAreaDirect) {
case COMP_LEFT_TOP : case COMP_LEFT_TOP:
dealCrossPointAtLeftTop(currentComp, child); dealCrossPointAtLeftTop(currentComp, child);
break; break;
case COMP_RIGHT_BOTTOM : case COMP_RIGHT_BOTTOM:
dealCrossPointAtRightBottom(currentComp, child); dealCrossPointAtRightBottom(currentComp, child);
break; break;
case COMP_LEFT_BOTTOM : case COMP_LEFT_BOTTOM:
dealCrossPointAtLeftBottom(currentComp, child); dealCrossPointAtLeftBottom(currentComp, child);
break; break;
case COMP_RIGHT_TOP : case COMP_RIGHT_TOP:
dealCrossPointAtRightTop(currentComp, child); dealCrossPointAtRightTop(currentComp, child);
break; break;
case COMP_TOP : case COMP_TOP:
dealCrossPointAtTop(currentComp, child); dealCrossPointAtTop(currentComp, child);
break; break;
case COMP_BOTTOM : case COMP_BOTTOM:
dealCrossPointAtBottom(currentComp, child); dealCrossPointAtBottom(currentComp, child);
break; break;
case COMP_LEFT : case COMP_LEFT:
dealCrossPointAtLeft(currentComp, child); dealCrossPointAtLeft(currentComp, child);
break; break;
case COMP_RIGHT : case COMP_RIGHT:
dealCrossPointAtRight(currentComp, child); dealCrossPointAtRight(currentComp, child);
break; break;
} }
@ -708,16 +734,16 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
Component topComp = container.getTopComp(cX, cY); Component topComp = container.getTopComp(cX, cY);
Component leftComp = container.getLeftComp(cX, cY); Component leftComp = container.getLeftComp(cX, cY);
//上方没有组件或者有一个x坐标不相同的组件 //上方没有组件或者有一个x坐标不相同的组件
if (topComp==null || topComp.getX()!=cX) { if (topComp == null || topComp.getX() != cX) {
minDH = cH < leftComp.getHeight() ? cH : leftComp.getHeight(); minDH = cH < leftComp.getHeight() ? cH : leftComp.getHeight();
downComps.add(leftComp); downComps.add(leftComp);
downComps.add(currentComp); downComps.add(currentComp);
int dLength = minDH / 2; int dLength = minDH / 2;
childw = leftComp.getWidth()+cW+actualVal; childw = leftComp.getWidth() + cW + actualVal;
childh = dLength-actualVal / 2; childh = dLength - actualVal / 2;
if (isCalculateChildPos) { if (isCalculateChildPos) {
childPosition = new int[]{leftComp.getX(), leftComp.getY(), childw, childh}; childPosition = new int[]{leftComp.getX(), leftComp.getY(), childw, childh};
} else{ } else {
//先设置child位置,不然leftComp坐标调整后就不对了 //先设置child位置,不然leftComp坐标调整后就不对了
child.setLocation(leftComp.getX(), leftComp.getY()); child.setLocation(leftComp.getX(), leftComp.getY());
child.setSize(childw, childh); child.setSize(childw, childh);
@ -726,7 +752,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
} else { } else {
rightComps.add(currentComp); rightComps.add(currentComp);
rightComps.add(topComp); rightComps.add(topComp);
minRW = cW<topComp.getWidth() ? cW : topComp.getWidth(); minRW = cW < topComp.getWidth() ? cW : topComp.getWidth();
int rightLength = minRW / 2; int rightLength = minRW / 2;
childw = rightLength - actualVal / 2; childw = rightLength - actualVal / 2;
childh = currentComp.getHeight() + topComp.getHeight() + actualVal; childh = currentComp.getHeight() + topComp.getHeight() + actualVal;
@ -755,12 +781,12 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
minUH = cH < rightComp.getHeight() ? cH : rightComp.getHeight(); minUH = cH < rightComp.getHeight() ? cH : rightComp.getHeight();
upComps.add(currentComp); upComps.add(currentComp);
upComps.add(rightComp); upComps.add(rightComp);
int uLength = minUH / 2 ; int uLength = minUH / 2;
calculateTopComps(uLength, child, uLength); calculateTopComps(uLength, child, uLength);
} else { } else {
leftComps.add(currentComp); leftComps.add(currentComp);
leftComps.add(bottomComp); leftComps.add(bottomComp);
minLW = cW<bottomComp.getWidth() ? cW : bottomComp.getWidth(); minLW = cW < bottomComp.getWidth() ? cW : bottomComp.getWidth();
int leftLength = minLW / 2; int leftLength = minLW / 2;
calculateLeftComps(leftLength, child, leftLength); calculateLeftComps(leftLength, child, leftLength);
} }
@ -807,7 +833,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
Component topComp = container.getRightTopComp(cX, cY, cW); Component topComp = container.getRightTopComp(cX, cY, cW);
Component rightComp = container.getRightComp(cX, cY, cW); Component rightComp = container.getRightComp(cX, cY, cW);
//右方没有组件或者有一个右侧不对齐的组件 //右方没有组件或者有一个右侧不对齐的组件
if (rightComp==null || (rightComp.getY()!=cY)) { if (rightComp == null || (rightComp.getY() != cY)) {
leftComps.add(currentComp); leftComps.add(currentComp);
leftComps.add(topComp); leftComps.add(topComp);
minLW = cW < topComp.getWidth() ? cW : topComp.getWidth(); minLW = cW < topComp.getWidth() ? cW : topComp.getWidth();
@ -840,9 +866,9 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
downComps.add(currentComp); downComps.add(currentComp);
downComps.add(rightComp); downComps.add(rightComp);
int dLength = minDH / 2; int dLength = minDH / 2;
int childw = cW+leftComp.getWidth()+rightComp.getWidth() + actualVal * 2; int childw = cW + leftComp.getWidth() + rightComp.getWidth() + actualVal * 2;
int childh = dLength - actualVal / 2; int childh = dLength - actualVal / 2;
if (isCalculateChildPos){ if (isCalculateChildPos) {
childPosition = new int[]{leftComp.getX(), leftComp.getY(), childw, childh}; childPosition = new int[]{leftComp.getX(), leftComp.getY(), childw, childh};
} else { } else {
child.setLocation(leftComp.getX(), leftComp.getY()); child.setLocation(leftComp.getX(), leftComp.getY());
@ -889,7 +915,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
int rightLength = minRW / 2; int rightLength = minRW / 2;
int childw = rightLength - actualVal / 2; int childw = rightLength - actualVal / 2;
int childh = topComp.getHeight() + currentComp.getHeight() + bottomComp.getHeight() + actualVal * 2; int childh = topComp.getHeight() + currentComp.getHeight() + bottomComp.getHeight() + actualVal * 2;
if (isCalculateChildPos){ if (isCalculateChildPos) {
childPosition = new int[]{topComp.getX(), topComp.getY(), childw, childh}; childPosition = new int[]{topComp.getX(), topComp.getY(), childw, childh};
} else { } else {
child.setLocation(topComp.getX(), topComp.getY()); child.setLocation(topComp.getX(), topComp.getY());
@ -900,8 +926,9 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
/** /**
* 三等分区域时调整相关联的组件 * 三等分区域时调整相关联的组件
* @param currentComp 鼠标所在组件 *
* @param child 待插入组件 * @param currentComp 鼠标所在组件
* @param child 待插入组件
*/ */
protected void fixTrisect(Component currentComp, XCreator child, int x, int y) { protected void fixTrisect(Component currentComp, XCreator child, int x, int y) {
int minUpH = 0, minDownH = 0, minLeftW = 0, minRightW = 0; int minUpH = 0, minDownH = 0, minLeftW = 0, minRightW = 0;
@ -940,15 +967,15 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
*/ */
private void dealTrisectAtTop(XCreator child, int minUH, int minDH) { private void dealTrisectAtTop(XCreator child, int minUH, int minDH) {
// 三等分有间隔时,实际是两侧都要减去半个间隔大小 // 三等分有间隔时,实际是两侧都要减去半个间隔大小
int averageH = (minUH+minDH - actualVal) / 3; int averageH = (minUH + minDH - actualVal) / 3;
int dLength = 0; int dLength = 0;
int uLength = 0; int uLength = 0;
if (minDH==0) { if (minDH == 0) {
dLength = 0; dLength = 0;
uLength = minUH / 2; uLength = minUH / 2;
calculateTopComps(uLength, child, uLength); calculateTopComps(uLength, child, uLength);
return; return;
} else if(minUH == 0){ } else if (minUH == 0) {
dLength = minDH / 2; dLength = minDH / 2;
int witdh = container.getWidth() - margin.getLeft() - margin.getRight(); int witdh = container.getWidth() - margin.getLeft() - margin.getRight();
if (!isCalculateChildPos) { if (!isCalculateChildPos) {
@ -956,22 +983,22 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
child.setLocation(margin.getLeft(), margin.getRight()); child.setLocation(margin.getLeft(), margin.getRight());
child.setSize(witdh, dLength - actualVal / 2); child.setSize(witdh, dLength - actualVal / 2);
} else { } else {
childPosition = new int[] {margin.getLeft(), margin.getRight(), witdh, dLength - actualVal / 2}; childPosition = new int[]{margin.getLeft(), margin.getRight(), witdh, dLength - actualVal / 2};
} }
return; return;
} else if (minUH >= minDH) { } else if (minUH >= minDH) {
minDH -= actualVal / 2; minDH -= actualVal / 2;
if ((minDH * 2 / 3) < minHeight) { if ((minDH * 2 / 3) < minHeight) {
dLength = minDH - minHeight; dLength = minDH - minHeight;
}else { } else {
dLength = minDH / 3; dLength = minDH / 3;
} }
uLength = averageH - dLength; uLength = averageH - dLength;
} else{ } else {
minUH -= actualVal / 2; minUH -= actualVal / 2;
if ((minUH * 2 / 3) < minHeight) { if ((minUH * 2 / 3) < minHeight) {
uLength = minUH - minHeight; uLength = minUH - minHeight;
}else { } else {
uLength = minUH / 3; uLength = minUH / 3;
} }
dLength = averageH - uLength; dLength = averageH - uLength;
@ -999,16 +1026,16 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
child.setLocation(margin.getLeft(), margin.getRight()); child.setLocation(margin.getLeft(), margin.getRight());
child.setSize(rightLength - actualVal / 2, height); child.setSize(rightLength - actualVal / 2, height);
} else { } else {
childPosition = new int[] {margin.getLeft(), margin.getRight(), rightLength - actualVal / 2, height}; childPosition = new int[]{margin.getLeft(), margin.getRight(), rightLength - actualVal / 2, height};
} }
return; return;
} else if(minRW == 0){ } else if (minRW == 0) {
leftLength = minLW / 2; leftLength = minLW / 2;
calculateLeftComps(leftLength, child, leftLength); calculateLeftComps(leftLength, child, leftLength);
return; return;
} else if (minRW >= minLW) { } else if (minRW >= minLW) {
minLW -= actualVal / 2; minLW -= actualVal / 2;
if(minLW * 2 / 3 < minWidth) { if (minLW * 2 / 3 < minWidth) {
leftLength = minLW - minWidth; leftLength = minLW - minWidth;
} else { } else {
leftLength = minLW / 3; leftLength = minLW / 3;
@ -1016,7 +1043,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
rightLength = averageW - leftLength; rightLength = averageW - leftLength;
} else { } else {
minRW -= actualVal / 2; minRW -= actualVal / 2;
if(minRW * 2 / 3 < minWidth) { if (minRW * 2 / 3 < minWidth) {
rightLength = minRW - minWidth; rightLength = minRW - minWidth;
} else { } else {
rightLength = minRW / 3; rightLength = minRW / 3;
@ -1033,12 +1060,12 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
private void calculateBottomComps(int length) { private void calculateBottomComps(int length) {
length += actualVal / 2; length += actualVal / 2;
for (int i = 0,num = downComps.size(); i < num; i++){ for (int i = 0, num = downComps.size(); i < num; i++) {
Component comp = downComps.get(i); Component comp = downComps.get(i);
comp.setLocation(comp.getX(), comp.getY() + length); comp.setLocation(comp.getX(), comp.getY() + length);
int offset = comp.getHeight() - length; int offset = comp.getHeight() - length;
comp.setSize(comp.getWidth(), offset); comp.setSize(comp.getWidth(), offset);
XCreator creator = (XCreator)comp; XCreator creator = (XCreator) comp;
creator.recalculateChildHeight(offset); creator.recalculateChildHeight(offset);
} }
} }
@ -1048,24 +1075,24 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
int childWidth = (upComps.size() - 1) * actualVal; int childWidth = (upComps.size() - 1) * actualVal;
int childX = container.getWidth() - margin.getLeft() - margin.getRight(); int childX = container.getWidth() - margin.getLeft() - margin.getRight();
int childY = 0; int childY = 0;
if(upComps.size() > INDEX_ZERO){ if (upComps.size() > INDEX_ZERO) {
childY = upComps.get(INDEX_ZERO).getY() + upComps.get(INDEX_ZERO).getHeight() - length; childY = upComps.get(INDEX_ZERO).getY() + upComps.get(INDEX_ZERO).getHeight() - length;
} }
for (int i = 0,num = upComps.size(); i < num; i++){ for (int i = 0, num = upComps.size(); i < num; i++) {
Component comp = upComps.get(i); Component comp = upComps.get(i);
childWidth += comp.getWidth(); childWidth += comp.getWidth();
if (comp.getX() < childX){ if (comp.getX() < childX) {
childX = comp.getX(); childX = comp.getX();
} }
if (!isCalculateChildPos) { if (!isCalculateChildPos) {
int offset = comp.getHeight() - length; int offset = comp.getHeight() - length;
comp.setSize(comp.getWidth(), offset); comp.setSize(comp.getWidth(), offset);
XCreator creator = (XCreator)comp; XCreator creator = (XCreator) comp;
creator.recalculateChildHeight(offset); creator.recalculateChildHeight(offset);
} }
} }
childY += actualVal; childY += actualVal;
averageH -= actualVal/2; averageH -= actualVal / 2;
if (isCalculateChildPos) { if (isCalculateChildPos) {
childPosition = new int[]{childX, childY, childWidth, averageH}; childPosition = new int[]{childX, childY, childWidth, averageH};
} else { } else {
@ -1081,25 +1108,25 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
} }
int childH = (leftComps.size() - 1) * actualVal; int childH = (leftComps.size() - 1) * actualVal;
int childX = 0; int childX = 0;
if(leftComps.size() > INDEX_ZERO){ if (leftComps.size() > INDEX_ZERO) {
childX = leftComps.get(INDEX_ZERO).getX() + leftComps.get(INDEX_ZERO).getWidth() - length; childX = leftComps.get(INDEX_ZERO).getX() + leftComps.get(INDEX_ZERO).getWidth() - length;
} }
int childY = container.getHeight() - margin.getBottom(); int childY = container.getHeight() - margin.getBottom();
for (int i = 0,num = leftComps.size(); i < num; i++){ for (int i = 0, num = leftComps.size(); i < num; i++) {
Component comp = leftComps.get(i); Component comp = leftComps.get(i);
childH += comp.getHeight(); childH += comp.getHeight();
if (comp.getY() < childY){ if (comp.getY() < childY) {
childY = comp.getY(); childY = comp.getY();
} }
if (!isCalculateChildPos) { if (!isCalculateChildPos) {
int offset = comp.getWidth() - length; int offset = comp.getWidth() - length;
comp.setSize(offset, comp.getHeight()); comp.setSize(offset, comp.getHeight());
XCreator creator = (XCreator)comp; XCreator creator = (XCreator) comp;
creator.recalculateChildWidth(offset); creator.recalculateChildWidth(offset);
} }
} }
childX += actualVal; childX += actualVal;
averageW -= actualVal/2; averageW -= actualVal / 2;
if (isCalculateChildPos) { if (isCalculateChildPos) {
childPosition = new int[]{childX, childY, averageW, childH}; childPosition = new int[]{childX, childY, averageW, childH};
} else { } else {
@ -1110,33 +1137,34 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{
private void calculateRightComps(int length) { private void calculateRightComps(int length) {
length += actualVal / 2; length += actualVal / 2;
for (int i=0,num=rightComps.size(); i<num; i++){ for (int i = 0, num = rightComps.size(); i < num; i++) {
Component comp = rightComps.get(i); Component comp = rightComps.get(i);
comp.setLocation(comp.getX() + length, comp.getY()); comp.setLocation(comp.getX() + length, comp.getY());
int offset = comp.getWidth() - length; int offset = comp.getWidth() - length;
comp.setSize(offset, comp.getHeight()); comp.setSize(offset, comp.getHeight());
XCreator creator = (XCreator)comp; XCreator creator = (XCreator) comp;
creator.recalculateChildWidth(offset); creator.recalculateChildWidth(offset);
} }
} }
/** /**
* 不调整只计算位置 * 不调整只计算位置
*
* @return child的位置 * @return child的位置
*/ */
public int[] getChildPosition(Component currentComp, XCreator child, int x, int y ) { public int[] getChildPosition(Component currentComp, XCreator child, int x, int y) {
if (currentComp == container) { if (currentComp == container) {
return new int[]{0, 0, container.getWidth(), container.getHeight()}; return new int[]{0, 0, container.getWidth(), container.getHeight()};
} }
this.isCalculateChildPos = true; this.isCalculateChildPos = true;
if (isCrossPointArea(currentComp, x, y)){ if (isCrossPointArea(currentComp, x, y)) {
fixCrossPointArea(currentComp, child, x, y); fixCrossPointArea(currentComp, child, x, y);
} else if (isTrisectionArea(currentComp, x, y)) { } else if (isTrisectionArea(currentComp, x, y)) {
fixTrisect(currentComp, child, x, y); fixTrisect(currentComp, child, x, y);
} else { } else {
fixHalve(currentComp, child, x, y); fixHalve(currentComp, child, x, y);
} }
if (childPosition==null) { if (childPosition == null) {
childPosition = new int[]{0, 0, 0, 0}; childPosition = new int[]{0, 0, 0, 0};
} }
this.isCalculateChildPos = false; this.isCalculateChildPos = false;

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

@ -1,5 +1,5 @@
/** /**
* *
*/ */
package com.fr.design.designer.beans.adapters.layout; package com.fr.design.designer.beans.adapters.layout;
@ -9,6 +9,7 @@ import java.awt.Rectangle;
import com.fr.design.beans.GroupModel; import com.fr.design.beans.GroupModel;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.XWidgetCreator; import com.fr.design.designer.creator.XWidgetCreator;
import com.fr.design.designer.creator.cardlayout.XWCardLayout; import com.fr.design.designer.creator.cardlayout.XWCardLayout;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
@ -20,75 +21,82 @@ import com.fr.general.ComparatorUtils;
/** /**
* tab布局tabFit适配器 * tab布局tabFit适配器
* *
* @author focus * @author focus
* @date 2014-6-24 * @date 2014-6-24
*/ */
public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter { public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter {
//标题栏高度对tab布局内部组件的y坐标造成了偏移 //标题栏高度对tab布局内部组件的y坐标造成了偏移
private static int TAB_HEIGHT = 40; private static int TAB_HEIGHT = 40;
/** /**
* 构造函数 * 构造函数
* @param container XWTabFitLayout容器 *
*/ * @param container XWTabFitLayout容器
public FRTabFitLayoutAdapter(XLayoutContainer container) { */
super(container); public FRTabFitLayoutAdapter(XLayoutContainer container) {
} super(container);
}
/**
* 返回布局自身属性方便一些特有设置在layout刷新时处理 /**
*/ * 返回布局自身属性方便一些特有设置在layout刷新时处理
@Override */
@Override
public GroupModel getLayoutProperties() { public GroupModel getLayoutProperties() {
XWTabFitLayout xfl = (XWTabFitLayout) container; XWTabFitLayout xfl = (XWTabFitLayout) container;
return new FRTabFitLayoutPropertiesGroupModel(xfl); return new FRTabFitLayoutPropertiesGroupModel(xfl);
} }
/** /**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的 * 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能 * addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
*
* @param creator 被添加的新组件 * @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的 * @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的 * @param y 添加的位置y该位置是相对于container的
* @return 是否添加成功成功返回true否则false * @return 是否添加成功成功返回true否则false
*/ */
@Override @Override
public boolean addBean(XCreator creator, int x, int y) { public boolean addBean(XCreator creator, int x, int y) {
// 经过accept判断后,container会被改变,先备份 // 经过accept判断后,container会被改变,先备份
XLayoutContainer backUpContainer = container; XLayoutContainer backUpContainer = container;
Rectangle rect = ComponentUtils.getRelativeBounds(container); Rectangle rect = ComponentUtils.getRelativeBounds(container);
int posX = x - rect.x; int posX = x - rect.x;
int posY = y - rect.y; int posY = y - rect.y;
if (!accept(creator, posX, posY)) { if (!accept(creator, posX, posY)) {
return false; return false;
} }
// posX,posY是新拖入组件相对于容器的位置,若在tab布局的边缘,则需要把新组件添加到 // posX,posY是新拖入组件相对于容器的位置,若在tab布局的边缘,则需要把新组件添加到
// 父层自适应布局中,这时候的添加位置就是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())) {
XWTabFitLayout tabLayout = (XWTabFitLayout)backUpContainer; XWTabFitLayout tabLayout = (XWTabFitLayout) backUpContainer;
y = adjustY(y,tabLayout); y = adjustY(y, tabLayout);
} }
addComp(creator, x, y); addComp(creator, x, y);
((XWidgetCreator) creator).recalculateChildrenSize(); ((XWidgetCreator) creator).recalculateChildrenSize();
return true; return true;
} }
// 如果不在边缘,容器为本自适应布局,增加组件的位置就是相对于容器的位置 // 如果不在边缘,容器为本自适应布局,增加组件的位置就是相对于容器的位置
addComp(creator, posX, posY); addComp(creator, posX, posY);
((XWidgetCreator) creator).recalculateChildrenSize(); ((XWidgetCreator) creator).recalculateChildrenSize();
return true; return true;
} }
// tab布局的纵坐标受到tab高度的影响,判断的上边界取得是里面XWTabFitLayout的上边界, // tab布局的纵坐标受到tab高度的影响,判断的上边界取得是里面XWTabFitLayout的上边界,
// 实际计算的时候的纵坐标用了外层的CardMainBorerLayout,需要将tab高度减掉 // 实际计算的时候的纵坐标用了外层的CardMainBorerLayout,需要将tab高度减掉
private int adjustY(int y,XWTabFitLayout tabLayout){ //将y值变为相对坐标以实现获取到鼠标drop位置的控件
XWCardLayout cardLayout = (XWCardLayout) tabLayout.getBackupParent(); //TODO 可以直接在这边将x,y都变成相对坐标,这样在后面判断拖进来的新控件放置方式的时候就不用再判断了
LayoutBorderStyle style = cardLayout.toData().getBorderStyle(); private int adjustY(int y, XWTabFitLayout tabLayout) {
if(ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)){ XWCardLayout cardLayout = (XWCardLayout) tabLayout.getBackupParent();
y -= WCardMainBorderLayout.TAB_HEIGHT; LayoutBorderStyle style = cardLayout.toData().getBorderStyle();
} if (container.getParent().getComponent(0) instanceof XWParameterLayout) {
return y; y = y - container.getParent().getComponent(0).getHeight() - container.getParent().getComponent(0).getY();
}
if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) {
y -= WCardMainBorderLayout.TAB_HEIGHT;
}
return y;
} }
} }
Loading…
Cancel
Save