neil 7 years ago
parent
commit
d0ebad3d07
  1. 467
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  2. 6
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  3. 89
      designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java
  4. 4
      designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

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

@ -16,78 +16,77 @@ 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();
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); 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(x, y);
} }
} 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) {
@ -108,57 +107,56 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
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();
} }
/** /**
* 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分 * 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分
* * @param parentComp 鼠标所在区域的组件
* @param parentComp 鼠标所在区域的组件 * @param x 坐标x
* @param x 坐标x * @param y 坐标y
* @param y 坐标y * @return 是则返回true
* @return 是则返回true */
*/ public boolean isTrisectionArea(Component parentComp, int x, int y) {
public boolean isTrisectionArea(Component parentComp, int x, int y) { XCreator creator = (XCreator)parentComp;
XCreator creator = (XCreator) parentComp; trisectAreaDirect = 0;
trisectAreaDirect = 0; if (container.getComponentCount()<=1) {
if (container.getComponentCount() <= 1) { return false;
return false; }
} int maxWidth = parentComp.getWidth();
int maxWidth = parentComp.getWidth(); int maxHeight = parentComp.getHeight();
int maxHeight = parentComp.getHeight(); 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; }
}
return !ComparatorUtils.equals(trisectAreaDirect, 0); return !ComparatorUtils.equals(trisectAreaDirect, 0);
} }
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围 //当前绝对布局不可编辑,就当成一个控件,组件添加在周围
private boolean acceptWidget(int x, int y) { private boolean acceptWidget(int x, int y) {
@ -170,177 +168,174 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
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方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
* *
* @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) {
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)) {
return false; return false;
} }
addComp(creator, posX, posY); addComp(creator, posX, posY);
((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) {
Rectangle r = ComponentUtils.getRelativeBounds(container); Rectangle r = ComponentUtils.getRelativeBounds(container);
x = x - r.x; x = x - r.x;
y = y - r.y; y = y - r.y;
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;
} else { } else {
int w = creator.getWidth() / 2; int w = creator.getWidth() / 2;
int h = creator.getHeight() / 2; int h = creator.getHeight() / 2;
x = x - w; x = x - w;
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);
updateCreatorBackBound(); updateCreatorBackBound();
LayoutUtils.layoutRootContainer(container); LayoutUtils.layoutRootContainer(container);
} else { }else{
fixAbsolute(creator, x, y); fixAbsolute(creator, x, y);
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { if (creator.shouldScaleCreator() || creator.hasTitleStyle()) {
addParentCreator(creator); addParentCreator(creator);
} 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
layout.updateBoundsWidget(); layout.updateBoundsWidget();
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);
creator.updateChildBound(minHeight); creator.updateChildBound(minHeight);
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);
} }
/** /**
* 新拖入组件时计算调整其他关联组件位置大小 * 新拖入组件时计算调整其他关联组件位置大小
* * @param child 新拖入的组件
* @param child 新拖入的组件 * @param x 鼠标所在x坐标
* @param x 鼠标所在x坐标 * @param y 鼠标所在y坐标
* @param y 鼠标所在y坐标 */
*/ private void fixAbsolute(XCreator child, int x, int y) {
private void fixAbsolute(XCreator child, int x, int y) { Component parentComp = container.getComponentAt(x, y);
Component parentComp = container.getComponentAt(x, y); if (container.getComponentCount()==0){
if (container.getComponentCount() == 0) { child.setLocation(0, 0);
child.setLocation(0, 0); child.setSize(parentComp.getWidth(), parentComp.getHeight());
child.setSize(parentComp.getWidth(), parentComp.getHeight()); } else if(isCrossPointArea(parentComp, x, y)){
} else if (isCrossPointArea(parentComp, x, y)) { //交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入
//交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入 fixCrossPointArea(parentComp, child, x, y);
fixCrossPointArea(parentComp, child, x, y); return;
return; } else if (isTrisectionArea(parentComp, x, y)) {
} else if (isTrisectionArea(parentComp, x, y)) { // 在边界三等分区域,就不再和组件二等分了
// 在边界三等分区域,就不再和组件二等分了 fixTrisect(parentComp, child, x, y);
fixTrisect(parentComp, child, x, y); return;
return; } else{
} else { fixHalve(parentComp, child, x, y);
fixHalve(parentComp, child, x, y); }
} }
}
/** /**
* 组件拖拽后调整大小 * 组件拖拽后调整大小
*
* @param creator 组件 * @param creator 组件
*/ */
@Override @Override
public void fix(XCreator creator) { public void fix(XCreator creator) {
WAbsoluteLayout wabs = (WAbsoluteLayout) container.toData(); WAbsoluteLayout wabs = (WAbsoluteLayout)container.toData();
fix(creator, creator.getX(), creator.getY()); fix(creator,creator.getX(),creator.getY());
wabs.setBounds(creator.toData(), creator.getBounds()); wabs.setBounds(creator.toData(),creator.getBounds());
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
layout.updateBoundsWidget(creator); layout.updateBoundsWidget(creator);
} }
/** /**
* 调整组件大小到合适尺寸位置 * 调整组件大小到合适尺寸位置
*
* @param creator 组件 * @param creator 组件
* @param x 坐标x * @param x 坐标x
* @param y 坐标y * @param y 坐标y
*/ */
public void fix(XCreator creator, int x, int y) { public void fix(XCreator creator ,int x, int y) {
int height = creator.getHeight(); int height = creator.getHeight();
int width = creator.getWidth(); int width = creator.getWidth();
if (x < 0) { if (x < 0) {
x = container.getX(); x = container.getX();
} 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;
return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout); return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout);
} }
} }

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

@ -16,14 +16,12 @@ import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.designer.properties.FRFitLayoutConstraints; import com.fr.design.designer.properties.FRFitLayoutConstraints;
import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel; import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.mainframe.JForm;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.LayoutBorderStyle;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WLayout; import com.fr.form.ui.container.WLayout;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -1013,7 +1011,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
setAdjustedSize(tabLayout, offset, isHor); setAdjustedSize(tabLayout, offset, isHor);
for (int m = 0; m < tabLayout.getComponentCount(); m++) { for (int m = 0; m < tabLayout.getComponentCount(); m++) {
XCreator childCreator = tabLayout.getXCreator(m); XCreator childCreator = tabLayout.getXCreator(m);
BoundsWidget wgt = (BoundsWidget) tabLayout.toData().getBoundsWidget(childCreator.toData()); WAbsoluteLayout.BoundsWidget wgt = (WAbsoluteLayout.BoundsWidget) tabLayout.toData().getBoundsWidget(childCreator.toData());
wgt.setBounds(tabLayout.getComponent(m).getBounds()); wgt.setBounds(tabLayout.getComponent(m).getBounds());
} }
adjustCreatorsSize(percent, tabLayout, isHor); adjustCreatorsSize(percent, tabLayout, isHor);

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

@ -11,6 +11,7 @@ import com.fr.design.mainframe.FormSelection;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import com.fr.form.ui.container.WParameterLayout;
import java.awt.*; import java.awt.*;
@ -24,7 +25,7 @@ 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 currentBounds, FormDesigner designer, protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle currentBounds, FormDesigner designer,
Rectangle oldBounds); Rectangle oldBounds);
@ -51,14 +52,14 @@ public abstract class AccessDirection implements Direction {
x = designer.getRootComponent().getWidth(); 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 currentBounds, FormDesigner designer) { protected void sorptionPoint(Point point, Rectangle currentBounds, FormDesigner designer) {
boolean findInX = currentBounds.getWidth() <= MoveUtils.SORPTION_UNIT; boolean findInX = currentBounds.getWidth() <= MoveUtils.SORPTION_UNIT;
@ -95,10 +96,10 @@ public abstract class AccessDirection implements Direction {
findInY = true; findInY = true;
} }
} }
if (findInX && findInY) { if (findInX && findInY) {
break; break;
} }
} }
setDesignerStateModelProperties(designer, findInX, findInY, currentBounds, point); setDesignerStateModelProperties(designer, findInX, findInY, currentBounds, point);
@ -124,7 +125,7 @@ public abstract class AccessDirection implements Direction {
} }
private WAbsoluteLayout getLayout(final FormDesigner designer) { private WAbsoluteLayout getLayout(final FormDesigner designer){
XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator( XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(
designer.getTarget().getContainer()); designer.getTarget().getContainer());
WAbsoluteLayout layout; WAbsoluteLayout layout;
@ -156,52 +157,50 @@ public abstract class AccessDirection implements Direction {
return; 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 设计界面组件
* @param formEditor 设计界面组件 */
*/ public void updateCursor(FormDesigner formEditor) {
public void updateCursor(FormDesigner formEditor) {
// 调用位置枚举的多态方法getCursor获取鼠标形状
// 调用位置枚举的多态方法getCursor获取鼠标形状 int type = getCursor();
int type = getCursor();
if (type != formEditor.getCursor().getType()) {
if (type != formEditor.getCursor().getType()) { // 设置当前形状
// 设置当前形状 formEditor.setCursor(Cursor.getPredefinedCursor(type));
formEditor.setCursor(Cursor.getPredefinedCursor(type)); }
} }
}
/**
/** * 生成组件备用的bound
* 生成组件备用的bound * @param formEditor 设计界面组件
* */
* @param formEditor 设计界面组件 public void backupBounds(FormDesigner formEditor) {
*/ formEditor.getSelectionModel().getSelection().backupBounds();
public void backupBounds(FormDesigner formEditor) { }
formEditor.getSelectionModel().getSelection().backupBounds();
}
} }

4
designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

@ -133,10 +133,8 @@ public class FormSelectionUtils {
boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + xoffset > container.getWidth(); boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + xoffset > container.getWidth();
boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + yoffset > container.getHeight(); boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + yoffset > container.getHeight();
boolean isEdge = (x - DELAY_X_Y == container.getWidth() - copiedCreator.getWidth() / 2 - xoffset)
&& (y - DELAY_X_Y == container.getHeight() - copiedCreator.getHeight() / 2 - yoffset);
y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y; y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y;
boolean isEdge = (x - DELAY_X_Y == container.getWidth() - copiedCreator.getWidth() / 2 - xoffset);
if (xOut) { if (xOut) {
if (isEdge) { if (isEdge) {
//向左偏移 //向左偏移

Loading…
Cancel
Save