Browse Source

Merge pull request #818 in BA/design from ~ZACK/design:master to master

* commit '08069fbfe0b9d75a73bc51eb4557246368826851':
  无JIRA任务   解决代码冲突
master
superman 8 years ago
parent
commit
8c5e96aaa3
  1. 162
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java

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

@ -1,31 +1,31 @@
package com.fr.design.designer.beans.adapters.layout; package com.fr.design.designer.beans.adapters.layout;
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;
import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter; 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.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.general.ComparatorUtils; import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import java.awt.*; import java.awt.*;
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();
@ -33,25 +33,25 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
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);
//布局控件要先判断是不是可编辑 //布局控件要先判断是不是可编辑
@ -85,39 +85,39 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
} else { } 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) { 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已经加上了宽度或者高度的一半,再减去相同的宽度和高度的一半是没区别的, //因为传入的x和y已经加上了宽度或者高度的一半,再减去相同的宽度和高度的一半是没区别的,
// 例如高度为21,那么就是+10-10; // 例如高度为21,那么就是+10-10;
// 高度为20,那么就是+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;
} }
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()
&& creator.getWidth() <= container.getWidth(); && creator.getWidth() <= container.getWidth();
} }
/** /**
* 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分 * 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分
* *
@ -156,10 +156,10 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
if (!creator.getTargetChildrenList().isEmpty()) { if (!creator.getTargetChildrenList().isEmpty()) {
return false; return false;
} }
return !ComparatorUtils.equals(trisectAreaDirect, 0); return !ComparatorUtils.equals(trisectAreaDirect, 0);
} }
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围 //当前绝对布局不可编辑,就当成一个控件,组件添加在周围
private boolean acceptWidget(int x, int y) { private boolean acceptWidget(int x, int y) {
isFindRelatedComps = false; isFindRelatedComps = false;
@ -169,27 +169,27 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
XLayoutContainer parent = container.findNearestFit(); XLayoutContainer parent = container.findNearestFit();
container = parent != null ? parent : container; container = parent != null ? parent : container;
isAdd2ParentLayout = true; isAdd2ParentLayout = true;
int componentHeight = comp.getHeight(); int componentHeight = comp.getHeight();
int componentWidth = comp.getWidth(); int componentWidth = comp.getWidth();
//上半部分高度 //上半部分高度
int upHeight = (int) (componentHeight * TOP_HALF) + comp.getY(); int upHeight = (int) (componentHeight * TOP_HALF) + comp.getY();
//下半部分高度 //下半部分高度
int downHeight = (int) (componentHeight * BOTTOM_HALF) + comp.getY(); int downHeight = (int) (componentHeight * BOTTOM_HALF) + comp.getY();
if (isCrossPointArea(comp, x, y)) { if (isCrossPointArea(comp, x, y)) {
return canAcceptWhileCrossPoint(comp, x, y); return canAcceptWhileCrossPoint(comp, x, y);
} }
if (isTrisectionArea(comp, x, y)) { if (isTrisectionArea(comp, x, y)) {
return canAcceptWhileTrisection(comp, x, y); return canAcceptWhileTrisection(comp, x, y);
} }
boolean horizonValid = componentWidth >= minWidth * 2 + actualVal; boolean horizonValid = componentWidth >= minWidth * 2 + actualVal;
boolean verticalValid = componentHeight >= minHeight * 2 + actualVal; boolean verticalValid = componentHeight >= minHeight * 2 + actualVal;
return y > upHeight && y < downHeight ? horizonValid : verticalValid; return y > upHeight && y < downHeight ? horizonValid : verticalValid;
} }
/** /**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的 * 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能 * addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
@ -202,7 +202,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
@Override @Override
public boolean addBean(XCreator creator, int x, int y) { public boolean addBean(XCreator creator, int x, int y) {
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, x, y)) { if (!accept(creator, x, y)) {
@ -212,7 +212,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
((XWidgetCreator) creator).recalculateChildrenSize(); ((XWidgetCreator) creator).recalculateChildrenSize();
return true; return true;
} }
@Override @Override
protected void addComp(XCreator creator, int x, int y) { protected void addComp(XCreator creator, int x, int y) {
if (!isAdd2ParentLayout) { if (!isAdd2ParentLayout) {
@ -220,7 +220,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
x = x - r.x; x = x - r.x;
y = y - r.y; y = y - r.y;
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { if (XCreatorUtils.getParentXLayoutContainer(creator) != null) {
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator);
x = creatorRectangle.x - r.x; x = creatorRectangle.x - r.x;
y = creatorRectangle.y - r.y; y = creatorRectangle.y - r.y;
@ -231,11 +231,11 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
y = y - h; y = y - h;
} }
fix(creator, x, y); fix(creator, x, y);
if (creator.hasTitleStyle()) { if (creator.hasTitleStyle()) {
addParentCreator(creator); addParentCreator(creator);
} else { } else {
container.add(creator, creator.toData().getWidgetName(),0); container.add(creator, creator.toData().getWidgetName(), 0);
} }
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
layout.updateBoundsWidget(creator); layout.updateBoundsWidget(creator);
@ -246,7 +246,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { if (creator.shouldScaleCreator() || creator.hasTitleStyle()) {
addParentCreator(creator); addParentCreator(creator);
} else { } else {
container.add(creator, creator.toData().getWidgetName(),0); container.add(creator, creator.toData().getWidgetName(), 0);
} }
XWFitLayout layout = (XWFitLayout) container; XWFitLayout layout = (XWFitLayout) container;
// 更新对应的BoundsWidget // 更新对应的BoundsWidget
@ -254,7 +254,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
updateCreatorBackBound(); updateCreatorBackBound();
} }
} }
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);
@ -262,12 +262,12 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
creator.setBackupBound(creator.getBounds()); creator.setBackupBound(creator.getBounds());
} }
} }
private void addParentCreator(XCreator child) { private void addParentCreator(XCreator child) {
XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight()); XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight());
container.add(parentPanel, child.toData().getWidgetName(),0); container.add(parentPanel, child.toData().getWidgetName(), 0);
} }
/** /**
* 新拖入组件时计算调整其他关联组件位置大小 * 新拖入组件时计算调整其他关联组件位置大小
* *
@ -292,29 +292,29 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
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);
} }
/** /**
* 调整组件大小到合适尺寸位置 * 调整组件大小到合适尺寸位置
* *
* @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();
@ -323,21 +323,21 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
} else if (x + creator.getWidth() > container.getWidth()) { } else if (x + creator.getWidth() > container.getWidth()) {
x = container.getWidth() - width; x = container.getWidth() - width;
} }
if (y < 0) { if (y < 0) {
y = container.getY(); y = container.getY();
} else if (y + creator.getHeight() > container.getHeight()) { } else if (y + creator.getHeight() > container.getHeight()) {
y = container.getHeight() - height; y = container.getHeight() - height;
} }
creator.setBounds(x, y, width, height); creator.setBounds(x, y, width, height);
} }
@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
public GroupModel getLayoutProperties() { public GroupModel getLayoutProperties() {
XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container; XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container;

Loading…
Cancel
Save