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

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

@ -1,354 +1,346 @@
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.designer.beans.ConstraintsGroupModel;
import com.fr.design.beans.GroupModel; import com.fr.design.designer.beans.HoverPainter;
import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter;
import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.creator.*;
import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter; import com.fr.design.designer.properties.BoundsGroupModel;
import com.fr.design.designer.creator.*; import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel;
import com.fr.design.designer.properties.BoundsGroupModel; import com.fr.design.utils.ComponentUtils;
import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel; import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.design.utils.ComponentUtils; import com.fr.general.ComparatorUtils;
import com.fr.design.utils.gui.LayoutUtils; import com.fr.general.FRLogger;
import com.fr.general.ComparatorUtils;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import java.awt.*;
import com.fr.general.FRLogger;
public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { //是不是添加到父容器上
//是不是添加到父容器上 private boolean isAdd2ParentLayout = false;
private boolean isAdd2ParentLayout = false; private HoverPainter painter;
private HoverPainter painter;
public FRAbsoluteLayoutAdapter(XLayoutContainer container) {
public FRAbsoluteLayoutAdapter(XLayoutContainer container) { super(container);
super(container); painter = new FRAbsoluteLayoutPainter(container);
painter = new FRAbsoluteLayoutPainter(container); initMinSize();
initMinSize(); }
}
private void initMinSize() {
private void initMinSize() { XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; minWidth = layout.getActualMinWidth();
minWidth = layout.getActualMinWidth(); minHeight = layout.getActualMinHeight();
minHeight = layout.getActualMinHeight(); actualVal = layout.getAcualInterval();
actualVal = layout.getAcualInterval(); margin = layout.toData().getMargin();
margin = layout.toData().getMargin(); }
}
@Override
@Override public HoverPainter getPainter() {
public HoverPainter getPainter() { return painter;
return painter; }
}
/**
/** * 是否能在指定位置添加组件
* 是否能在指定位置添加组件 *
* @param creator 组件 * @param creator 组件
* @param x 坐标x * @param x 坐标x
* @param y 坐标y * @param y 坐标y
* @return 能则返回true * @return 能则返回true
*/ */
//这个地方的逻辑非常复杂, //这个地方的逻辑非常复杂,
// 1.当前绝对布局是不可编辑且是最外层,那么其他控件添加在它周围, // 1.当前绝对布局是不可编辑且是最外层,那么其他控件添加在它周围,
// 2.当前绝对布局是不可编辑且不是最外层,那么控件不可添加,(嵌套) // 2.当前绝对布局是不可编辑且不是最外层,那么控件不可添加,(嵌套)
// 3.当前绝对布局可编辑,那么控件添加 // 3.当前绝对布局可编辑,那么控件添加
@Override @Override
public boolean accept(XCreator creator, int x, int y) { public boolean accept(XCreator creator, int x, int y) {
Component comp = container.getComponentAt(x, y); Component comp = container.getComponentAt(x, y);
//布局控件要先判断是不是可编辑 //布局控件要先判断是不是可编辑
//可以编辑,按原有逻辑判断 //可以编辑,按原有逻辑判断
//不可编辑,当成一整个控件处理 //不可编辑,当成一整个控件处理
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 {
else { return acceptWidget(x, y);
return acceptWidget(creator, x, y); }
} } else {
} FRLogger.getLogger().error("top layout is null!");
else{ }
FRLogger.getLogger().error("top layout is null!");
} return false;
}
return false;
} //topLayout假如可以编辑的话就往里面添加组件
private boolean topLayoutAccept(XCreator creator, int x, int y) {
//toplayout假如可以编辑的话就往里面添加组件 //允许组件重叠,可以不判断有没有和当前控件重叠
private boolean topLayoutAccept(XCreator creator, int x, int y, XLayoutContainer topLayout) { //先计算当前控件的位置
//判断有没有和当前控件重叠 int creatorX, creatorY;
//先计算当前控件的位置 if (XCreatorUtils.getParentXLayoutContainer(creator) != null) {
int creatorX, creatorY; Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator);
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { creatorX = creatorRectangle.x;
creatorY = creatorRectangle.y;
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); } else {
creatorX = creatorRectangle.x; //这边计算得到的组件其实位置是正确的,
creatorY = creatorRectangle.y; //因为传入的x和y已经加上了宽度或者高度的一半,再减去相同的宽度和高度的一半是没区别的,
} else { // 例如高度为21,那么就是+10-10;
int w = creator.getWidth() / 2; // 高度为20,那么就是+10-10; 没区别
int h = creator.getHeight() / 2; int w = creator.getWidth() / 2;
creatorX = x - w; int h = creator.getHeight() / 2;
creatorY = y - h; creatorX = x - w;
} creatorY = y - h;
//再判断和布局中其他控件重叠 }
Rectangle curRec = new Rectangle(creatorX, creatorY, creator.getWidth(), creator.getHeight()); if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) {
WAbsoluteLayout wAbsoluteLayout = (WAbsoluteLayout)topLayout.toData(); return false;
for (int i = 0, count = wAbsoluteLayout.getWidgetCount(); i < count; i++) { }
BoundsWidget temp = (BoundsWidget) wAbsoluteLayout.getWidget(i); if (creatorY < 0 || creatorY + creator.getHeight() > container.getHeight()) {
Rectangle rectangle = temp.getBounds(); return false;
if (curRec.intersects(rectangle)){ }
return false; return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight()
} && creator.getWidth() <= container.getWidth();
} }
if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) {
return false; /**
} * 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分
if (creatorY < 0 || creatorY + creator.getHeight() > container.getHeight()){ *
return false; * @param parentComp 鼠标所在区域的组件
} * @param x 坐标x
return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight() * @param y 坐标y
&& creator.getWidth() <= container.getWidth(); * @return 是则返回true
} */
public boolean isTrisectionArea(Component parentComp, int x, int y) {
/** XCreator creator = (XCreator) parentComp;
* 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分 trisectAreaDirect = 0;
* @param parentComp 鼠标所在区域的组件 if (container.getComponentCount() <= 1) {
* @param x 坐标x return false;
* @param y 坐标y }
* @return 是则返回true int maxWidth = parentComp.getWidth();
*/ int maxHeight = parentComp.getHeight();
public boolean isTrisectionArea(Component parentComp, int x, int y) { int xL = parentComp.getX();
XCreator creator = (XCreator)parentComp; int yL = parentComp.getY();
trisectAreaDirect = 0; // 组件宽高的十分之一和默认值取大
if (container.getComponentCount()<=1) { int minRangeWidth = Math.max(maxWidth / BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
return false; int minRangeHeight = Math.max(maxHeight / BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
} if (y < yL + minRangeHeight) {
int maxWidth = parentComp.getWidth(); // 在组件上侧三等分
int maxHeight = parentComp.getHeight(); trisectAreaDirect = COMP_TOP;
int xL = parentComp.getX(); } else if (y > yL + maxHeight - minRangeHeight) {
int yL = parentComp.getY(); // 在组件下侧三等分
// 组件宽高的十分之一和默认值取大 trisectAreaDirect = COMP_BOTTOM;
int minRangeWidth = Math.max(maxWidth/BORDER_PROPORTION, DEFAULT_AREA_LENGTH); } else if (x < xL + minRangeWidth) {
int minRangeHeight = Math.max(maxHeight/BORDER_PROPORTION, DEFAULT_AREA_LENGTH); // 在组件左侧三等分
if(y<yL+minRangeHeight ) { trisectAreaDirect = COMP_LEFT;
// 在组件上侧三等分 } else if (x > xL + maxWidth - minRangeWidth) {
trisectAreaDirect = COMP_TOP; // 在组件右侧三等分
} else if(y>yL+maxHeight-minRangeHeight) { trisectAreaDirect = COMP_RIGHT;
// 在组件下侧三等分 }
trisectAreaDirect = COMP_BOTTOM; // tab布局的边界特殊处理,不进行三等分
} else if (x<xL+minRangeWidth) { if (!creator.getTargetChildrenList().isEmpty()) {
// 在组件左侧三等分 return false;
trisectAreaDirect = COMP_LEFT; }
} else if(x>xL+maxWidth-minRangeWidth) {
// 在组件右侧三等分 return !ComparatorUtils.equals(trisectAreaDirect, 0);
trisectAreaDirect = COMP_RIGHT; }
}
// tab布局的边界特殊处理,不进行三等分 //当前绝对布局不可编辑,就当成一个控件,组件添加在周围
if(!creator.getTargetChildrenList().isEmpty()){ private boolean acceptWidget(int x, int y) {
return false; isFindRelatedComps = false;
} //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y);
return !ComparatorUtils.equals(trisectAreaDirect, 0); //如果当前处于边缘地带, 那么就把他贴到父容器上
} XLayoutContainer parent = container.findNearestFit();
container = parent != null ? parent : container;
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围 isAdd2ParentLayout = true;
private boolean acceptWidget(XCreator creator, int x, int y){
isFindRelatedComps = false; int componentHeight = comp.getHeight();
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 int componentWidth = comp.getWidth();
Component comp = container.getComponentAt(x, y); //上半部分高度
boolean isMatchEdge = false; int upHeight = (int) (componentHeight * TOP_HALF) + comp.getY();
//如果当前处于边缘地带, 那么就把他贴到父容器上 //下半部分高度
XLayoutContainer parent = container.findNearestFit(); int downHeight = (int) (componentHeight * BOTTOM_HALF) + comp.getY();
container = parent != null ? parent : container;
isAdd2ParentLayout = true; if (isCrossPointArea(comp, x, y)) {
return canAcceptWhileCrossPoint(comp, x, y);
int componentHeight = comp.getHeight(); }
int componentWidth = comp.getWidth();
//上半部分高度 if (isTrisectionArea(comp, x, y)) {
int upHeight = (int) (componentHeight * TOP_HALF) + comp.getY(); return canAcceptWhileTrisection(comp, x, y);
//下半部分高度 }
int downHeight = (int) (componentHeight * BOTTOM_HALF) + comp.getY();
boolean horizonValid = componentWidth >= minWidth * 2 + actualVal;
if (isCrossPointArea(comp, x, y)) { boolean verticalValid = componentHeight >= minHeight * 2 + actualVal;
return canAcceptWhileCrossPoint(comp, x, y); return y > upHeight && y < downHeight ? horizonValid : verticalValid;
} }
if (isTrisectionArea(comp, x, y)) { /**
return canAcceptWhileTrisection(comp, x, y); * 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
} * addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
*
boolean horizonValid = componentWidth >= minWidth * 2 + actualVal; * @param creator 被添加的新组件
boolean verticalValid = componentHeight >= minHeight * 2 + actualVal; * @param x 添加的位置x该位置是相对于container的
return y > upHeight && y < downHeight ? horizonValid : verticalValid; * @param y 添加的位置y该位置是相对于container的
} * @return 是否添加成功成功返回true否则false
*/
/** @Override
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的 public boolean addBean(XCreator creator, int x, int y) {
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能 Rectangle rect = ComponentUtils.getRelativeBounds(container);
*
* @param creator 被添加的新组件 int posX = x + rect.x;
* @param x 添加的位置x该位置是相对于container的 int posY = y + rect.y;
* @param y 添加的位置y该位置是相对于container的 if (!accept(creator, x, y)) {
* @return 是否添加成功成功返回true否则false return false;
*/ }
@Override addComp(creator, posX, posY);
public boolean addBean(XCreator creator, int x, int y) { ((XWidgetCreator) creator).recalculateChildrenSize();
Rectangle rect = ComponentUtils.getRelativeBounds(container); return true;
}
int posX = x + rect.x;
int posY = y + rect.y; @Override
if (!accept(creator, x, y)) { protected void addComp(XCreator creator, int x, int y) {
return false; if (!isAdd2ParentLayout) {
} Rectangle r = ComponentUtils.getRelativeBounds(container);
addComp(creator, posX, posY); x = x - r.x;
((XWidgetCreator) creator).recalculateChildrenSize(); y = y - r.y;
return true; if (XCreatorUtils.getParentXLayoutContainer(creator) != null) {
}
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator);
@Override x = creatorRectangle.x - r.x;
protected void addComp(XCreator creator, int x, int y) { y = creatorRectangle.y - r.y;
if(!isAdd2ParentLayout) { } else {
Rectangle r = ComponentUtils.getRelativeBounds(container); int w = creator.getWidth() / 2;
x = x - r.x; int h = creator.getHeight() / 2;
y = y - r.y; x = x - w;
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { y = y - h;
}
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); fix(creator, x, y);
x = creatorRectangle.x - r.x;
y = creatorRectangle.y - r.y; if (creator.hasTitleStyle()) {
} else { addParentCreator(creator);
int w = creator.getWidth() / 2; } else {
int h = creator.getHeight() / 2; container.add(creator, creator.toData().getWidgetName());
x = x - w; }
y = y - h; XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
} layout.updateBoundsWidget(creator);
fix(creator, x, y); updateCreatorBackBound();
LayoutUtils.layoutRootContainer(container);
if (creator.hasTitleStyle()) { } else {
addParentCreator(creator); fixAbsolute(creator, x, y);
} else { if (creator.shouldScaleCreator() || creator.hasTitleStyle()) {
container.add(creator, creator.toData().getWidgetName()); addParentCreator(creator);
} } else {
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; container.add(creator, creator.toData().getWidgetName());
layout.updateBoundsWidget(creator); }
updateCreatorBackBound(); XWFitLayout layout = (XWFitLayout) container;
LayoutUtils.layoutRootContainer(container); // 更新对应的BoundsWidget
}else{ layout.updateBoundsWidget();
fixAbsolute(creator, x, y); updateCreatorBackBound();
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { }
addParentCreator(creator); }
} else {
container.add(creator, creator.toData().getWidgetName()); private void updateCreatorBackBound() {
} for (int i = 0, size = container.getComponentCount(); i < size; i++) {
XWFitLayout layout = (XWFitLayout) container; XCreator creator = (XCreator) container.getComponent(i);
// 更新对应的BoundsWidget creator.updateChildBound(minHeight);
layout.updateBoundsWidget(); creator.setBackupBound(creator.getBounds());
updateCreatorBackBound(); }
} }
}
private void addParentCreator(XCreator child) {
private void updateCreatorBackBound() { XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight());
for (int i=0,size=container.getComponentCount(); i<size; i++) { container.add(parentPanel, child.toData().getWidgetName());
XCreator creator = (XCreator) container.getComponent(i); }
creator.updateChildBound(minHeight);
creator.setBackupBound(creator.getBounds()); /**
} * 新拖入组件时计算调整其他关联组件位置大小
} *
* @param child 新拖入的组件
private void addParentCreator(XCreator child) { * @param x 鼠标所在x坐标
XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight()); * @param y 鼠标所在y坐标
container.add(parentPanel, child.toData().getWidgetName()); */
} private void fixAbsolute(XCreator child, int x, int y) {
Component parentComp = container.getComponentAt(x, y);
/** if (container.getComponentCount() == 0) {
* 新拖入组件时计算调整其他关联组件位置大小 child.setLocation(0, 0);
* @param child 新拖入的组件 child.setSize(parentComp.getWidth(), parentComp.getHeight());
* @param x 鼠标所在x坐标 } else if (isCrossPointArea(parentComp, x, y)) {
* @param y 鼠标所在y坐标 //交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入
*/ fixCrossPointArea(parentComp, child, x, y);
private void fixAbsolute(XCreator child, int x, int y) { return;
Component parentComp = container.getComponentAt(x, y); } else if (isTrisectionArea(parentComp, x, y)) {
if (container.getComponentCount()==0){ // 在边界三等分区域,就不再和组件二等分了
child.setLocation(0, 0); fixTrisect(parentComp, child, x, y);
child.setSize(parentComp.getWidth(), parentComp.getHeight()); return;
} else if(isCrossPointArea(parentComp, x, y)){ } else {
//交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入 fixHalve(parentComp, child, x, y);
fixCrossPointArea(parentComp, child, x, y); }
return; }
} else if (isTrisectionArea(parentComp, x, y)) {
// 在边界三等分区域,就不再和组件二等分了 /**
fixTrisect(parentComp, child, x, y); * 组件拖拽后调整大小
return; *
} else{ * @param creator 组件
fixHalve(parentComp, child, x, y); */
} @Override
} public void fix(XCreator creator) {
WAbsoluteLayout wabs = (WAbsoluteLayout) container.toData();
/** fix(creator, creator.getX(), creator.getY());
* 组件拖拽后调整大小 wabs.setBounds(creator.toData(), creator.getBounds());
* @param creator 组件
*/ XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
@Override layout.updateBoundsWidget(creator);
public void fix(XCreator creator) { }
WAbsoluteLayout wabs = (WAbsoluteLayout)container.toData();
fix(creator,creator.getX(),creator.getY()); /**
wabs.setBounds(creator.toData(),creator.getBounds()); * 调整组件大小到合适尺寸位置
*
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; * @param creator 组件
layout.updateBoundsWidget(creator); * @param x 坐标x
} * @param y 坐标y
*/
/** public void fix(XCreator creator, int x, int y) {
* 调整组件大小到合适尺寸位置 int height = creator.getHeight();
* @param creator 组件 int width = creator.getWidth();
* @param x 坐标x if (x < 0) {
* @param y 坐标y x = container.getX();
*/ } else if (x + creator.getWidth() > container.getWidth()) {
public void fix(XCreator creator ,int x, int y) { x = container.getWidth() - width;
int height = creator.getHeight(); }
int width = creator.getWidth();
if (x < 0) { if (y < 0) {
width += x; y = container.getY();
x = 0; } else if (y + creator.getHeight() > container.getHeight()) {
} else if (x + creator.getWidth() > container.getWidth()) { y = container.getHeight() - height;
width = container.getWidth() - x; }
}
creator.setBounds(x, y, width, height);
if (y < 0) { }
height += y;
y = 0; @Override
} else if (y + creator.getHeight() > container.getHeight()) { public ConstraintsGroupModel getLayoutConstraints(XCreator creator) {
height = container.getHeight() - y; return new BoundsGroupModel((XWAbsoluteLayout) container, creator);
} }
creator.setBounds(x, y, width, height); @Override
} public GroupModel getLayoutProperties() {
XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container;
@Override return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout);
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { }
return new BoundsGroupModel((XWAbsoluteLayout)container, creator);
}
@Override
public GroupModel getLayoutProperties() {
XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container;
return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout);
}
} }

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

File diff suppressed because it is too large Load Diff

335
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
@ -26,197 +24,184 @@ public abstract class AccessDirection implements Direction {
private int ymin; private int ymin;
private int xmin; private int xmin;
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 currentBounds, FormDesigner designer) {
if (x < 0) {
protected Point getRelativePoint(int x, int y, Rectangle current_bounds,FormDesigner designer) { x = 0;
if (x < 0) { } else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) {
x = 0; x = designer.getRootComponent().getWidth();
} else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) { }
x = designer.getRootComponent().getWidth();
}
//参数面板可以无下限拉长 //参数面板可以无下限拉长
if (y < 0) { if (y < 0) {
y = 0; y = 0;
} else if (y > designer.getRootComponent().getHeight() + designer.getParaHeight() && designer.getSelectionModel().hasSelectionComponent() } else if (y > designer.getRootComponent().getHeight() + designer.getParaHeight() && designer.getSelectionModel().hasSelectionComponent()
&& !designer.getSelectionModel().getSelection().getSelectedCreator().acceptType(XWParameterLayout.class)) { && !designer.getSelectionModel().getSelection().getSelectedCreator().acceptType(XWParameterLayout.class)) {
y = designer.getRootComponent().getHeight() + designer.getParaHeight(); y = designer.getRootComponent().getHeight() + designer.getParaHeight();
} }
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())) { continue;
continue; }
} Rectangle bounds = getWidgetRelativeBounds(temp.getBounds(), selection);
Rectangle bounds = getWidgetRelativeBounds(temp.getBounds(), selection); if (!findInX) {
if (!findInX) { int x1 = bounds.x;
int x1 = bounds.x; if (Math.abs(x1 - point.x) <= MoveUtils.SORPTION_UNIT) {
if (Math.abs(x1 - point.x) <= MoveUtils.SORPTION_UNIT) { point.x = x1;
point.x = x1; findInX = true;
findInX = true; }
} int x2 = bounds.x + bounds.width;
int x2 = bounds.x + bounds.width; if (Math.abs(x2 - point.x) <= MoveUtils.SORPTION_UNIT) {
if (Math.abs(x2 - point.x) <= MoveUtils.SORPTION_UNIT) { point.x = x2;
point.x = x2; findInX = true;
findInX = true; }
} }
} if (!findInY) {
if (!findInY) { int y1 = bounds.y;
int y1 = bounds.y; if (Math.abs(y1 - point.y) <= MoveUtils.SORPTION_UNIT) {
if (Math.abs(y1 - point.y) <= MoveUtils.SORPTION_UNIT) { point.y = y1;
point.y = y1; findInY = true;
findInY = true; }
} int y2 = bounds.y + bounds.height;
int y2 = bounds.y + bounds.height; if (Math.abs(y2 - point.y) <= MoveUtils.SORPTION_UNIT) {
if (Math.abs(y2 - point.y) <= MoveUtils.SORPTION_UNIT) { point.y = y2;
point.y = y2; findInY = true;
findInY = true; }
}
}
} if (findInX && findInY) {
if (findInX && findInY) { break;
break; }
}
}
if (current_bounds.intersects(bounds) && !(layout instanceof WParameterLayout)){ setDesignerStateModelProperties(designer, findInX, findInY, currentBounds, point);
isWidgetsIntersect = true; }
}
} private void setDesignerStateModelProperties(FormDesigner designer, boolean findInX, boolean findInY, Rectangle
processRectangleIntersects(designer, point.x, point.y, isWidgetsIntersect); currentBounds, Point point) {
setDesignerStateModelProperties(designer, findInX, findInY, current_bounds, point); 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);
private void setDesignerStateModelProperties (FormDesigner designer, boolean findInX, boolean findInY, Rectangle current_bounds, Point point) { }
designer.getStateModel().setXAbsorptionline(findInX && current_bounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null);
designer.getStateModel().setYAbsorptionline(findInY && current_bounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null); private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection) {
designer.getStateModel().setEquidistantLine(null); Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
} XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (parent == null) {
private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection){ return relativeRec;
Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height); }
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); Rectangle rec = ComponentUtils.getRelativeBounds(parent);
if (parent == null) { relativeRec.x += rec.x;
return relativeRec; relativeRec.y += rec.y;
} return relativeRec;
Rectangle rec = ComponentUtils.getRelativeBounds(parent); }
relativeRec.x += rec.x;
relativeRec.y += rec.y;
return relativeRec; private WAbsoluteLayout getLayout(final FormDesigner designer) {
}
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){
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;
} }
/** /**
* 拖拽 * 拖拽
* @param dx 坐标x *
* @param dy 坐标y * @param dx 坐标x
* @param designer 设计界面 * @param dy 坐标y
*/ * @param designer 设计界面
public void drag(int dx, int dy, FormDesigner designer) { */
Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds()); public void drag(int dx, int dy, FormDesigner designer) {
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;
} }
// 增加下宽度也设最小为21 // 增加下宽度也设最小为21
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;
}
}
/**
* 更新鼠标指针形状
*
* @param formEditor 设计界面组件
*/
public void updateCursor(FormDesigner formEditor) {
// 调用位置枚举的多态方法getCursor获取鼠标形状
int type = getCursor();
if (type != formEditor.getCursor().getType()) {
// 设置当前形状
formEditor.setCursor(Cursor.getPredefinedCursor(type));
} }
if(rec != null) { }
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer);
} /**
} * 生成组件备用的bound
*
/** * @param formEditor 设计界面组件
* 更新鼠标指针形状 */
* @param formEditor 设计界面组件 public void backupBounds(FormDesigner formEditor) {
*/ formEditor.getSelectionModel().getSelection().backupBounds();
public void updateCursor(FormDesigner formEditor) { }
// 调用位置枚举的多态方法getCursor获取鼠标形状
int type = getCursor();
if (type != formEditor.getCursor().getType()) {
// 设置当前形状
formEditor.setCursor(Cursor.getPredefinedCursor(type));
}
}
/**
* 生成组件备用的bound
* @param formEditor 设计界面组件
*/
public void backupBounds(FormDesigner formEditor) {
formEditor.getSelectionModel().getSelection().backupBounds();
}
} }
Loading…
Cancel
Save