neil 8 years ago
parent
commit
d0ebad3d07
  1. 685
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  2. 68
      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. 280
      designer_form/src/com/fr/design/designer/beans/models/AddingModel.java
  5. 950
      designer_form/src/com/fr/design/designer/beans/models/StateModel.java
  6. 190
      designer_form/src/com/fr/design/designer/beans/painters/AbstractPainter.java
  7. 4
      designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

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

@ -1,346 +1,341 @@
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.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.general.ComparatorUtils; 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();
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) { //允许组件重叠,可以不判断有没有和当前控件重叠
//允许组件重叠,可以不判断有没有和当前控件重叠 //先计算当前控件的位置
//先计算当前控件的位置 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(); }
}
/**
/** * 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分
* 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分 * @param parentComp 鼠标所在区域的组件
* * @param x 坐标x
* @param parentComp 鼠标所在区域的组件 * @param y 坐标y
* @param x 坐标x * @return 是则返回true
* @param y 坐标y */
* @return 是则返回true public boolean isTrisectionArea(Component parentComp, int x, int y) {
*/ XCreator creator = (XCreator)parentComp;
public boolean isTrisectionArea(Component parentComp, int x, int y) { trisectAreaDirect = 0;
XCreator creator = (XCreator) parentComp; if (container.getComponentCount()<=1) {
trisectAreaDirect = 0; return false;
if (container.getComponentCount() <= 1) { }
return false; int maxWidth = parentComp.getWidth();
} int maxHeight = parentComp.getHeight();
int maxWidth = parentComp.getWidth(); int xL = parentComp.getX();
int maxHeight = parentComp.getHeight(); int yL = parentComp.getY();
int xL = parentComp.getX(); // 组件宽高的十分之一和默认值取大
int yL = parentComp.getY(); int minRangeWidth = Math.max(maxWidth/BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
// 组件宽高的十分之一和默认值取大 int minRangeHeight = Math.max(maxHeight/BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
int minRangeWidth = Math.max(maxWidth / BORDER_PROPORTION, DEFAULT_AREA_LENGTH); if(y<yL+minRangeHeight ) {
int minRangeHeight = Math.max(maxHeight / BORDER_PROPORTION, DEFAULT_AREA_LENGTH); // 在组件上侧三等分
if (y < yL + minRangeHeight) { trisectAreaDirect = COMP_TOP;
// 在组件上侧三等分 } else if(y>yL+maxHeight-minRangeHeight) {
trisectAreaDirect = COMP_TOP; // 在组件下侧三等分
} else if (y > yL + maxHeight - minRangeHeight) { trisectAreaDirect = COMP_BOTTOM;
// 在组件下侧三等分 } else if (x<xL+minRangeWidth) {
trisectAreaDirect = COMP_BOTTOM; // 在组件左侧三等分
} else if (x < xL + minRangeWidth) { trisectAreaDirect = COMP_LEFT;
// 在组件左侧三等分 } else if(x>xL+maxWidth-minRangeWidth) {
trisectAreaDirect = COMP_LEFT; // 在组件右侧三等分
} else if (x > xL + maxWidth - minRangeWidth) { trisectAreaDirect = COMP_RIGHT;
// 在组件右侧三等分 }
trisectAreaDirect = COMP_RIGHT; // tab布局的边界特殊处理,不进行三等分
} if(!creator.getTargetChildrenList().isEmpty()){
// tab布局的边界特殊处理,不进行三等分 return false;
if (!creator.getTargetChildrenList().isEmpty()) { }
return false;
} return !ComparatorUtils.equals(trisectAreaDirect, 0);
}
return !ComparatorUtils.equals(trisectAreaDirect, 0);
} //当前绝对布局不可编辑,就当成一个控件,组件添加在周围
private boolean acceptWidget(int x, int y) {
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围 isFindRelatedComps = false;
private boolean acceptWidget(int x, int y) { //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
isFindRelatedComps = false; Component comp = container.getComponentAt(x, y);
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 //如果当前处于边缘地带, 那么就把他贴到父容器上
Component comp = container.getComponentAt(x, y); XLayoutContainer parent = container.findNearestFit();
//如果当前处于边缘地带, 那么就把他贴到父容器上 container = parent != null ? parent : container;
XLayoutContainer parent = container.findNearestFit(); isAdd2ParentLayout = true;
container = parent != null ? parent : container;
isAdd2ParentLayout = true; int componentHeight = comp.getHeight();
int componentWidth = comp.getWidth();
int componentHeight = comp.getHeight(); //上半部分高度
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)) {
return canAcceptWhileCrossPoint(comp, x, y);
if (isCrossPointArea(comp, x, y)) { }
return canAcceptWhileCrossPoint(comp, x, y);
} if (isTrisectionArea(comp, x, y)) {
return canAcceptWhileTrisection(comp, x, y);
if (isTrisectionArea(comp, x, y)) { }
return canAcceptWhileTrisection(comp, x, y);
} boolean horizonValid = componentWidth >= minWidth * 2 + actualVal;
boolean verticalValid = componentHeight >= minHeight * 2 + actualVal;
boolean horizonValid = componentWidth >= minWidth * 2 + actualVal; return y > upHeight && y < downHeight ? horizonValid : verticalValid;
boolean verticalValid = componentHeight >= minHeight * 2 + actualVal; }
return y > upHeight && y < downHeight ? horizonValid : verticalValid;
} /**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
/** * addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的 *
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能 * @param creator 被添加的新组件
* * @param x 添加的位置x该位置是相对于container的
* @param creator 被添加的新组件 * @param y 添加的位置y该位置是相对于container的
* @param x 添加的位置x该位置是相对于container的 * @return 是否添加成功成功返回true否则false
* @param y 添加的位置y该位置是相对于container的 */
* @return 是否添加成功成功返回true否则false @Override
*/ public boolean addBean(XCreator creator, int x, int y) {
@Override Rectangle rect = ComponentUtils.getRelativeBounds(container);
public boolean addBean(XCreator creator, int x, int y) {
Rectangle rect = ComponentUtils.getRelativeBounds(container); int posX = x + rect.x;
int posY = y + rect.y;
int posX = x + rect.x; if (!accept(creator, x, y)) {
int posY = y + rect.y; return false;
if (!accept(creator, x, y)) { }
return false; addComp(creator, posX, posY);
} ((XWidgetCreator) creator).recalculateChildrenSize();
addComp(creator, posX, posY); return true;
((XWidgetCreator) creator).recalculateChildrenSize(); }
return true;
} @Override
protected void addComp(XCreator creator, int x, int y) {
@Override if(!isAdd2ParentLayout) {
protected void addComp(XCreator creator, int x, int y) { Rectangle r = ComponentUtils.getRelativeBounds(container);
if (!isAdd2ParentLayout) { x = x - r.x;
Rectangle r = ComponentUtils.getRelativeBounds(container); y = y - r.y;
x = x - r.x; if (XCreatorUtils.getParentXLayoutContainer(creator) != null) {
y = y - r.y;
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator);
x = creatorRectangle.x - r.x;
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); y = creatorRectangle.y - r.y;
x = creatorRectangle.x - r.x; } else {
y = creatorRectangle.y - r.y; int w = creator.getWidth() / 2;
} else { int h = creator.getHeight() / 2;
int w = creator.getWidth() / 2; x = x - w;
int h = creator.getHeight() / 2; y = y - h;
x = x - w; }
y = y - h; fix(creator, x, y);
}
fix(creator, x, y); if (creator.hasTitleStyle()) {
addParentCreator(creator);
if (creator.hasTitleStyle()) { } else {
addParentCreator(creator); container.add(creator, creator.toData().getWidgetName(),0);
} else { }
container.add(creator, creator.toData().getWidgetName(), 0); XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
} layout.updateBoundsWidget(creator);
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; updateCreatorBackBound();
layout.updateBoundsWidget(creator); LayoutUtils.layoutRootContainer(container);
updateCreatorBackBound(); }else{
LayoutUtils.layoutRootContainer(container); fixAbsolute(creator, x, y);
} else { if (creator.shouldScaleCreator() || creator.hasTitleStyle()) {
fixAbsolute(creator, x, y); addParentCreator(creator);
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { } else {
addParentCreator(creator); container.add(creator, creator.toData().getWidgetName(),0);
} else { }
container.add(creator, creator.toData().getWidgetName(), 0); XWFitLayout layout = (XWFitLayout) container;
} // 更新对应的BoundsWidget
XWFitLayout layout = (XWFitLayout) container; layout.updateBoundsWidget();
// 更新对应的BoundsWidget updateCreatorBackBound();
layout.updateBoundsWidget(); }
updateCreatorBackBound(); }
}
} private void updateCreatorBackBound() {
for (int i=0,size=container.getComponentCount(); i<size; i++) {
private void updateCreatorBackBound() { XCreator creator = (XCreator) container.getComponent(i);
for (int i = 0, size = container.getComponentCount(); i < size; i++) { creator.updateChildBound(minHeight);
XCreator creator = (XCreator) container.getComponent(i); creator.setBackupBound(creator.getBounds());
creator.updateChildBound(minHeight); }
creator.setBackupBound(creator.getBounds()); }
}
} private void addParentCreator(XCreator child) {
XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight());
private void addParentCreator(XCreator child) { container.add(parentPanel, child.toData().getWidgetName(),0);
XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight()); }
container.add(parentPanel, child.toData().getWidgetName(), 0);
} /**
* 新拖入组件时计算调整其他关联组件位置大小
/** * @param child 新拖入的组件
* 新拖入组件时计算调整其他关联组件位置大小 * @param x 鼠标所在x坐标
* * @param y 鼠标所在y坐标
* @param child 新拖入的组件 */
* @param x 鼠标所在x坐标 private void fixAbsolute(XCreator child, int x, int y) {
* @param y 鼠标所在y坐标 Component parentComp = container.getComponentAt(x, y);
*/ if (container.getComponentCount()==0){
private void fixAbsolute(XCreator child, int x, int y) { child.setLocation(0, 0);
Component parentComp = container.getComponentAt(x, y); child.setSize(parentComp.getWidth(), parentComp.getHeight());
if (container.getComponentCount() == 0) { } else if(isCrossPointArea(parentComp, x, y)){
child.setLocation(0, 0); //交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入
child.setSize(parentComp.getWidth(), parentComp.getHeight()); fixCrossPointArea(parentComp, child, x, y);
} else if (isCrossPointArea(parentComp, x, y)) { return;
//交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入 } else if (isTrisectionArea(parentComp, x, y)) {
fixCrossPointArea(parentComp, child, x, y); // 在边界三等分区域,就不再和组件二等分了
return; fixTrisect(parentComp, child, x, y);
} else if (isTrisectionArea(parentComp, x, y)) { return;
// 在边界三等分区域,就不再和组件二等分了 } else{
fixTrisect(parentComp, child, x, y); fixHalve(parentComp, child, x, y);
return; }
} else { }
fixHalve(parentComp, child, x, y);
} /**
} * 组件拖拽后调整大小
* @param creator 组件
/** */
* 组件拖拽后调整大小 @Override
* public void fix(XCreator creator) {
* @param creator 组件 WAbsoluteLayout wabs = (WAbsoluteLayout)container.toData();
*/ fix(creator,creator.getX(),creator.getY());
@Override wabs.setBounds(creator.toData(),creator.getBounds());
public void fix(XCreator creator) {
WAbsoluteLayout wabs = (WAbsoluteLayout) container.toData(); XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
fix(creator, creator.getX(), creator.getY()); layout.updateBoundsWidget(creator);
wabs.setBounds(creator.toData(), creator.getBounds()); }
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; /**
layout.updateBoundsWidget(creator); * 调整组件大小到合适尺寸位置
} * @param creator 组件
* @param x 坐标x
/** * @param y 坐标y
* 调整组件大小到合适尺寸位置 */
* public void fix(XCreator creator ,int x, int y) {
* @param creator 组件 int height = creator.getHeight();
* @param x 坐标x int width = creator.getWidth();
* @param y 坐标y if (x < 0) {
*/ x = container.getX();
public void fix(XCreator creator, int x, int y) { } else if (x + creator.getWidth() > container.getWidth()) {
int height = creator.getHeight(); x = container.getWidth() - width;
int width = creator.getWidth(); }
if (x < 0) {
x = container.getX(); if (y < 0) {
} else if (x + creator.getWidth() > container.getWidth()) { y = container.getY();
x = container.getWidth() - width; } else if (y + creator.getHeight() > container.getHeight()) {
} y = container.getHeight() - height;
}
if (y < 0) {
y = container.getY(); creator.setBounds(x, y, width, height);
} else if (y + creator.getHeight() > container.getHeight()) { }
y = container.getHeight() - height;
} @Override
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) {
creator.setBounds(x, y, width, height); return new BoundsGroupModel((XWAbsoluteLayout)container, creator);
} }
@Override @Override
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { public GroupModel getLayoutProperties() {
return new BoundsGroupModel((XWAbsoluteLayout) container, creator); XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container;
} return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout);
}
@Override
public GroupModel getLayoutProperties() {
XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container;
return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout);
}
} }

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

@ -16,19 +16,17 @@ 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;
import java.util.List; import java.util.List;
/** /**
* 自适应布局的容器适配器 * 自适应布局的容器适配器
* *
@ -50,7 +48,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
public void setEdit(boolean edit) { public void setEdit(boolean edit) {
isEdit = edit; isEdit = edit;
} }
/** /**
* 构造函数 * 构造函数
* *
@ -133,7 +131,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
isFindRelatedComps = false; isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y); Component comp = container.getComponentAt(x, y);
if (comp == null || checkInterval(comp)) { if (comp == null || checkInterval(comp)) {
return false; return false;
} }
//如果当前处于边缘地带, 那么就把他贴到父容器上 //如果当前处于边缘地带, 那么就把他贴到父容器上
@ -269,13 +267,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
} }
protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) { protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) {
return mainLayout.getBounds(); return mainLayout.getBounds();
} }
private Rectangle adjustBackupBound(Rectangle backupBound, XWCardMainBorderLayout mainLayout) { private Rectangle adjustBackupBound(Rectangle backupBound, XWCardMainBorderLayout mainLayout) {
// zhouping: REPORT-2334 表单tab布局中图表放大缩小会明显 // zhouping: REPORT-2334 表单tab布局中图表放大缩小会明显
// 这边不需要单独处理参数面板高度了,下面的方法中获取的是XWCardMainBorderLayout相对坐标 // 这边不需要单独处理参数面板高度了,下面的方法中获取的是XWCardMainBorderLayout相对坐标
Rectangle rec = getLayoutBound(mainLayout); Rectangle rec = getLayoutBound(mainLayout);
// XWTabLayout里面的横纵坐标收到外层XWCardMainBorderLayout的横纵坐标影响 // XWTabLayout里面的横纵坐标收到外层XWCardMainBorderLayout的横纵坐标影响
// 减掉之后可以按照它原来的逻辑执行 // 减掉之后可以按照它原来的逻辑执行
@ -341,13 +339,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
* 拖拽控件边框后根据控件的大小尺寸进行相关组件的调整 * 拖拽控件边框后根据控件的大小尺寸进行相关组件的调整
* *
* @param backupBound 边界备份 * @param backupBound 边界备份
* @param bounds 组件边界 * @param bounds 组件边界
* @param xCreator 组件 * @param xCreator 组件
* @param row 选中的行 * @param row 选中的行
* @param difference 偏移量 * @param difference 偏移量
*/ */
public void calculateBounds(Rectangle backupBound, Rectangle bounds, XCreator xCreator, int row, int difference) { public void calculateBounds(Rectangle backupBound, Rectangle bounds, XCreator xCreator, int row, int difference) {
Rectangle rc = new Rectangle(0, 0, 0, 0); Rectangle rc = new Rectangle(0, 0, 0, 0);
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(xCreator); XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(xCreator);
if (parent != null) { if (parent != null) {
Rectangle rec = ComponentUtils.getRelativeBounds(parent); Rectangle rec = ComponentUtils.getRelativeBounds(parent);
@ -358,17 +356,17 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
//处理左右延伸 //处理左右延伸
switch (row) { switch (row) {
case 0: case 0:
if (backupBound.width + backupBound.x == container.getWidth() - margin.getRight() + rc.x) { if (backupBound.width + backupBound.x == container.getWidth() - margin.getRight() + rc.x) {
x += difference; x += difference;
} }
break; break;
case 1: case 1:
if (backupBound.y + backupBound.height == container.getHeight() - margin.getBottom() + rc.y) { if (backupBound.y + backupBound.height == container.getHeight() - margin.getBottom() + rc.y) {
y += difference; y += difference;
} }
break; break;
} }
bounds.setLocation(x, y); bounds.setLocation(x, y);
xCreator.setBackupBound(backupBound); xCreator.setBackupBound(backupBound);
xCreator.setBounds(bounds); xCreator.setBounds(bounds);
this.fix(xCreator); this.fix(xCreator);
@ -412,7 +410,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
// 根据需要依附的位置调整拖拽的坐标值 // 根据需要依附的位置调整拖拽的坐标值
private int adjustCoordinateByDependingLine(int coordinate, int[] coordinates) { private int adjustCoordinateByDependingLine(int coordinate, int[] coordinates) {
if (!isEdit) { if (!isEdit) {
for (int i = 0; i < coordinates.length; i++) { for (int i = 0; i < coordinates.length; i++) {
if (coordinate == coordinates[i]) { if (coordinate == coordinates[i]) {
continue; continue;
@ -428,7 +426,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
// 根据需要依附的位置调整拖拽的距离 // 根据需要依附的位置调整拖拽的距离
private int adjustDiffByDependingLine(int coordinate, int[] coordinates, int diff) { private int adjustDiffByDependingLine(int coordinate, int[] coordinates, int diff) {
if (!isEdit) { if (!isEdit) {
for (int i = 0; i < coordinates.length; i++) { for (int i = 0; i < coordinates.length; i++) {
if (coordinate + diff > coordinates[i] - DEPENDING_SCOPE && coordinate + diff < coordinates[i] + DEPENDING_SCOPE) { if (coordinate + diff > coordinates[i] - DEPENDING_SCOPE && coordinate + diff < coordinates[i] + DEPENDING_SCOPE) {
diff = coordinates[i] - coordinate; diff = coordinates[i] - coordinate;
@ -546,8 +544,8 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
difference = Math.max(difference, minWidth - getMinWidth(leftComps)); difference = Math.max(difference, minWidth - getMinWidth(leftComps));
} }
//重新计算左右两侧组件size、point //重新计算左右两侧组件size、point
if (calculateLefttRelatComponent(difference)) { if (calculateLefttRelatComponent(difference)) {
calculateRightRelatComponent(objx + difference, -difference); calculateRightRelatComponent(objx + difference, -difference);
} }
} }
@ -662,8 +660,8 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
difference = Math.max(difference, minHeight - getMinHeight(upComps)); difference = Math.max(difference, minHeight - getMinHeight(upComps));
} }
//重新计算上下两侧组件size、point //重新计算上下两侧组件size、point
if (calculateUpRelatComponent(difference)) { if (calculateUpRelatComponent(difference)) {
calculateDownRelatComponent(objY + difference, -difference); calculateDownRelatComponent(objY + difference, -difference);
} }
} }
@ -744,13 +742,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
int height = creatorHeight; int height = creatorHeight;
calculateRelatedComponent(x, y, width, height); calculateRelatedComponent(x, y, width, height);
if (!rightComps.isEmpty() && getAllHeight(rightComps) == height) { if (!rightComps.isEmpty() && getAllHeight(rightComps) == height) {
calculateRightRelatComponent(x, width + actualVal); calculateRightRelatComponent(x, width + actualVal);
} else if (!leftComps.isEmpty() && getAllHeight(leftComps) == height) { } else if (!leftComps.isEmpty() && getAllHeight(leftComps) == height) {
calculateLefttRelatComponent(width + actualVal); calculateLefttRelatComponent(width + actualVal);
} else if (!downComps.isEmpty() && getAllWidth(downComps) == width) { } else if (!downComps.isEmpty() && getAllWidth(downComps) == width) {
calculateDownRelatComponent(y, height + actualVal); calculateDownRelatComponent(y, height + actualVal);
} else if (!upComps.isEmpty() && getAllWidth(upComps) == width) { } else if (!upComps.isEmpty() && getAllWidth(upComps) == width) {
calculateUpRelatComponent(height + actualVal); calculateUpRelatComponent(height + actualVal);
} else { } else {
// 由于布局三等分的存在,可能会出现删除组件时,找不到关联的组件填充,此时特殊处理 // 由于布局三等分的存在,可能会出现删除组件时,找不到关联的组件填充,此时特殊处理
calculateNoRelatedComponent(x, y, width, height); calculateNoRelatedComponent(x, y, width, height);
@ -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);
@ -1056,7 +1054,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
* @param objX 调整后的坐标x * @param objX 调整后的坐标x
* @param objWidth 调整后的宽度 * @param objWidth 调整后的宽度
*/ */
protected void calculateRightRelatComponent(int objX, int objWidth) { protected void calculateRightRelatComponent(int objX, int objWidth) {
int count = rightComps.size(); int count = rightComps.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XCreator creator = (XCreator) rightComps.get(i); XCreator creator = (XCreator) rightComps.get(i);
@ -1096,7 +1094,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 删除或拉伸控件左边框时 调整左侧的组件位置大小 * 删除或拉伸控件左边框时 调整左侧的组件位置大小
*/ */
protected boolean calculateLefttRelatComponent(int objWidth) { protected boolean calculateLefttRelatComponent(int objWidth) {
if (isBeyondAdjustWidthScope(objWidth)) { if (isBeyondAdjustWidthScope(objWidth)) {
return false; return false;
} }
@ -1114,7 +1112,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 删除或拉伸下边框 调整下方的组件位置大小 * 删除或拉伸下边框 调整下方的组件位置大小
*/ */
protected void calculateDownRelatComponent(int objY, int objHeight) { protected void calculateDownRelatComponent(int objY, int objHeight) {
int count = downComps.size(); int count = downComps.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XCreator creator = (XCreator) downComps.get(i); XCreator creator = (XCreator) downComps.get(i);
@ -1154,7 +1152,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 删除或拉伸上边框 调整上方的组件位置大小 * 删除或拉伸上边框 调整上方的组件位置大小
*/ */
protected boolean calculateUpRelatComponent(int objHeight) { protected boolean calculateUpRelatComponent(int objHeight) {
if (isBeyondAdjustHeightScope(objHeight)) { if (isBeyondAdjustHeightScope(objHeight)) {
return false; return false;
} }

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();
}
} }

280
designer_form/src/com/fr/design/designer/beans/models/AddingModel.java

@ -1,141 +1,141 @@
package com.fr.design.designer.beans.models; package com.fr.design.designer.beans.models;
import java.awt.Rectangle; import java.awt.Rectangle;
import com.fr.design.designer.creator.XWAbsoluteLayout; import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter; import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter;
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.XWParameterLayout;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
/** /**
* 添加状态下的model * 添加状态下的model
*/ */
public class AddingModel { public class AddingModel {
// 当前要添加的组件 // 当前要添加的组件
private XCreator creator; private XCreator creator;
// 记录当前鼠标的位置信息 // 记录当前鼠标的位置信息
private int currentX; private int currentX;
private int currentY; private int currentY;
private boolean added; private boolean added;
public AddingModel(FormDesigner designer, XCreator xCreator) { public AddingModel(FormDesigner designer, XCreator xCreator) {
String creatorName = getXCreatorName(designer, xCreator); String creatorName = getXCreatorName(designer, xCreator);
this.creator = xCreator; this.creator = xCreator;
instantiateCreator(designer, creatorName); instantiateCreator(designer, creatorName);
// 初始的时候隐藏该组件的图标 // 初始的时候隐藏该组件的图标
currentY = -this.creator.getWidth(); currentY = -this.creator.getWidth();
currentX = -this.creator.getHeight(); currentX = -this.creator.getHeight();
} }
/** /**
* 待说明 * 待说明
* *
* @param designer 设计器 * @param designer 设计器
* @param creatorName 组件名 * @param creatorName 组件名
*/ */
public void instantiateCreator(FormDesigner designer, String creatorName) { public void instantiateCreator(FormDesigner designer, String creatorName) {
creator.toData().setWidgetName(creatorName); creator.toData().setWidgetName(creatorName);
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator); ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator);
adapter.initialize(); adapter.initialize();
creator.addNotify(); creator.addNotify();
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter); creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter);
} }
public AddingModel(XCreator xCreator, int x, int y) { public AddingModel(XCreator xCreator, int x, int y) {
this.creator = xCreator; this.creator = xCreator;
this.creator.backupCurrentSize(); this.creator.backupCurrentSize();
this.creator.backupParent(); this.creator.backupParent();
this.creator.setSize(xCreator.initEditorSize()); this.creator.setSize(xCreator.initEditorSize());
currentX = x - (xCreator.getWidth() / 2); currentX = x - (xCreator.getWidth() / 2);
currentY = y - (xCreator.getHeight() / 2); currentY = y - (xCreator.getHeight() / 2);
} }
/** /**
* 隐藏当前组件的图标 * 隐藏当前组件的图标
*/ */
public void reset() { public void reset() {
currentX = -this.creator.getWidth(); currentX = -this.creator.getWidth();
currentY = -this.creator.getHeight(); currentY = -this.creator.getHeight();
} }
public String getXCreatorName(FormDesigner designer, XCreator x) { public String getXCreatorName(FormDesigner designer, XCreator x) {
String def = x.createDefaultName(); String def = x.createDefaultName();
if (x.acceptType(XWParameterLayout.class)) { if (x.acceptType(XWParameterLayout.class)) {
return def; return def;
} }
int i = 0; int i = 0;
while (designer.getTarget().isNameExist(def + i)) { while (designer.getTarget().isNameExist(def + i)) {
i++; i++;
} }
return def + i; return def + i;
} }
public int getCurrentX() { public int getCurrentX() {
return currentX; return currentX;
} }
public int getCurrentY() { public int getCurrentY() {
return currentY; return currentY;
} }
/** /**
* 移动组件图标到鼠标事件发生的位置 * 移动组件图标到鼠标事件发生的位置
* *
* @param x 坐标 * @param x 坐标
* @param y 坐标 * @param y 坐标
*/ */
public void moveTo(int x, int y) { public void moveTo(int x, int y) {
currentX = x - (this.creator.getWidth() / 2); currentX = x - (this.creator.getWidth() / 2);
currentY = y - (this.creator.getHeight() / 2); currentY = y - (this.creator.getHeight() / 2);
} }
public XCreator getXCreator() { public XCreator getXCreator() {
return this.creator; return this.creator;
} }
/** /**
* 当前组件是否已经添加到某个容器中 * 当前组件是否已经添加到某个容器中
* *
* @return 是返回true * @return 是返回true
*/ */
public boolean isCreatorAdded() { public boolean isCreatorAdded() {
return added; return added;
} }
/** /**
* 加入容器 * 加入容器
* *
* @param designer 设计器 * @param designer 设计器
* @param container 容器 * @param container 容器
* @param x 坐标 * @param x 坐标
* @param y 坐标 * @param y 坐标
* @return 成功返回true * @return 成功返回true
*/ */
public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) { public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) {
//考虑不同布局嵌套的情况,获取顶层容器 //考虑不同布局嵌套的情况,获取顶层容器
XLayoutContainer xLayoutContainer = container.getTopLayout(); XLayoutContainer xLayoutContainer = container.getTopLayout();
if (xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class)) { if (xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class)) {
container = xLayoutContainer; container = xLayoutContainer;
} }
Rectangle rect = ComponentUtils.getRelativeBounds(container); Rectangle rect = ComponentUtils.getRelativeBounds(container);
if (!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())) { if (!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())) {
added = container.getLayoutAdapter().addBean(creator, added = container.getLayoutAdapter().addBean(creator,
x + designer.getArea().getHorizontalValue(), x + designer.getArea().getHorizontalValue(),
y + designer.getArea().getVerticalValue()); y + designer.getArea().getVerticalValue());
return added; return added;
} }
added = container.getLayoutAdapter().addBean(creator, added = container.getLayoutAdapter().addBean(creator,
x + designer.getArea().getHorizontalValue() - rect.x, x + designer.getArea().getHorizontalValue() - rect.x,
y + designer.getArea().getVerticalValue() - rect.y); y + designer.getArea().getVerticalValue() - rect.y);
return added; return added;
} }
} }

950
designer_form/src/com/fr/design/designer/beans/models/StateModel.java

@ -1,476 +1,476 @@
package com.fr.design.designer.beans.models; package com.fr.design.designer.beans.models;
import com.fr.design.beans.location.Absorptionline; import com.fr.design.beans.location.Absorptionline;
import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.HoverPainter;
import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.beans.location.Direction; import com.fr.design.designer.beans.location.Direction;
import com.fr.design.designer.beans.location.Location; import com.fr.design.designer.beans.location.Location;
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.FormSelectionUtils; import com.fr.design.mainframe.FormSelectionUtils;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* 普通模式下的状态model * 普通模式下的状态model
*/ */
public class StateModel { public class StateModel {
// 对应的selection model // 对应的selection model
private SelectionModel selectionModel; private SelectionModel selectionModel;
// 当前鼠标进入拖拽区域的位置类型 // 当前鼠标进入拖拽区域的位置类型
private Direction driection; private Direction driection;
// 当前拖拽的起始位置 // 当前拖拽的起始位置
private int currentX; private int currentX;
private int currentY; private int currentY;
//拖拽组件原始位置大小备份 //拖拽组件原始位置大小备份
private Rectangle selectedPositionBackup; private Rectangle selectedPositionBackup;
private Point startPoint = new Point(); private Point startPoint = new Point();
private Point currentPoint = new Point(); private Point currentPoint = new Point();
private Absorptionline lineInX; private Absorptionline lineInX;
private Absorptionline lineInY; private Absorptionline lineInY;
//等距线 //等距线
private Absorptionline lineEquidistant; private Absorptionline lineEquidistant;
// 当前是否处于拖拽选择状态 // 当前是否处于拖拽选择状态
private boolean selecting; private boolean selecting;
private boolean dragging; private boolean dragging;
private boolean addable; private boolean addable;
private FormDesigner designer; private FormDesigner designer;
public StateModel(FormDesigner designer) { public StateModel(FormDesigner designer) {
this.designer = designer; this.designer = designer;
selectionModel = designer.getSelectionModel(); selectionModel = designer.getSelectionModel();
} }
/** /**
* 返回direction * 返回direction
* *
* @return direction方向 * @return direction方向
*/ */
public Direction getDirection() { public Direction getDirection() {
return driection; return driection;
} }
/** /**
* 是否有组件正被选中 * 是否有组件正被选中
* *
* @return true 如果至少一个组件被选中 * @return true 如果至少一个组件被选中
*/ */
public boolean isSelecting() { public boolean isSelecting() {
return selecting; return selecting;
} }
/** /**
* 是否能拖拽 * 是否能拖拽
* *
* @return 非outer且选中为空 * @return 非outer且选中为空
*/ */
public boolean dragable() { public boolean dragable() {
return ((driection != Location.outer) && !selecting); return ((driection != Location.outer) && !selecting);
} }
/** /**
* 拖拽中是否可以转换为添加模式 * 拖拽中是否可以转换为添加模式
* 如果拖拽组件只有一个鼠标当前所在位置的最底层表单容器与这个组件的容器不同 * 如果拖拽组件只有一个鼠标当前所在位置的最底层表单容器与这个组件的容器不同
* 如果拖拽组件为多个鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外还必须是绝对定位布局 * 如果拖拽组件为多个鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外还必须是绝对定位布局
*/ */
private void checkAddable(MouseEvent e) { private void checkAddable(MouseEvent e) {
addable = false; addable = false;
designer.setPainter(null); designer.setPainter(null);
if (driection != Location.inner) { if (driection != Location.inner) {
return; return;
} }
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators());
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp);
XCreator creator = selectionModel.getSelection().getSelectedCreator(); XCreator creator = selectionModel.getSelection().getSelectedCreator();
Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator); Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator);
if (creatorContainer != null && creatorContainer != container if (creatorContainer != null && creatorContainer != container
&& (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) { && (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) {
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); HoverPainter painter = AdapterBus.getContainerPainter(designer, container);
designer.setPainter(painter); designer.setPainter(painter);
if (painter != null) { if (painter != null) {
Rectangle rect = ComponentUtils.getRelativeBounds(container); Rectangle rect = ComponentUtils.getRelativeBounds(container);
rect.x -= designer.getArea().getHorizontalValue(); rect.x -= designer.getArea().getHorizontalValue();
rect.y -= designer.getArea().getVerticalValue(); rect.y -= designer.getArea().getVerticalValue();
painter.setRenderingBounds(rect); painter.setRenderingBounds(rect);
painter.setHotspot(new Point(e.getX(), e.getY())); painter.setHotspot(new Point(e.getX(), e.getY()));
painter.setCreator(creator); painter.setCreator(creator);
} }
addable = true; addable = true;
} }
} }
/** /**
* @param container 容器 * @param container 容器
* @param mouseX 鼠标释放位置X * @param mouseX 鼠标释放位置X
* @param mouseY 鼠标释放位置Y * @param mouseY 鼠标释放位置Y
* @return 是否成功 * @return 是否成功
*/ */
private boolean addBean(XLayoutContainer container, int mouseX, int mouseY) { private boolean addBean(XLayoutContainer container, int mouseX, int mouseY) {
LayoutAdapter adapter = container.getLayoutAdapter(); LayoutAdapter adapter = container.getLayoutAdapter();
Rectangle rectangleContainer = ComponentUtils.getRelativeBounds(container); Rectangle rectangleContainer = ComponentUtils.getRelativeBounds(container);
if (selectionModel.getSelection().size() == 1) { if (selectionModel.getSelection().size() == 1) {
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), return adapter.addBean(selectionModel.getSelection().getSelectedCreator(),
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x,
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y);
} }
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) {
adapter.addBean(creator, adapter.addBean(creator,
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x,
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y);
} }
return true; return true;
} }
/** /**
* @param mouseReleasedX 鼠标释放位置X * @param mouseReleasedX 鼠标释放位置X
* @param mouseReleasedY 鼠标释放位置Y * @param mouseReleasedY 鼠标释放位置Y
*/ */
private void adding(int mouseReleasedX, int mouseReleasedY) { private void adding(int mouseReleasedX, int mouseReleasedY) {
// 当前鼠标所在的组件 // 当前鼠标所在的组件
XCreator hoveredComponent = designer.getComponentAt(mouseReleasedX, mouseReleasedY, selectionModel.getSelection().getSelectedCreators()); XCreator hoveredComponent = designer.getComponentAt(mouseReleasedX, mouseReleasedY, selectionModel.getSelection().getSelectedCreators());
// 获取该组件所在的焦点容器 // 获取该组件所在的焦点容器
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent);
boolean success = false; boolean success = false;
if (container != null) { if (container != null) {
// 如果是容器,则调用其acceptComponent接受组件 // 如果是容器,则调用其acceptComponent接受组件
success = addBean(container, mouseReleasedX, mouseReleasedY); success = addBean(container, mouseReleasedX, mouseReleasedY);
} }
if (success) { if (success) {
FormSelectionUtils.rebuildSelection(designer); FormSelectionUtils.rebuildSelection(designer);
designer.getEditListenerTable().fireCreatorModified( designer.getEditListenerTable().fireCreatorModified(
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED);
} else { } else {
selectionModel.getSelection().setSelectionBounds(selectedPositionBackup, designer); selectionModel.getSelection().setSelectionBounds(selectedPositionBackup, designer);
Toolkit.getDefaultToolkit().beep(); Toolkit.getDefaultToolkit().beep();
} }
// 取消提示 // 取消提示
designer.setPainter(null); designer.setPainter(null);
} }
/** /**
* 是否拖拽 * 是否拖拽
* *
* @return dragging状态 * @return dragging状态
*/ */
public boolean isDragging() { public boolean isDragging() {
return dragging; return dragging;
} }
/** /**
* 是否可以开始画线 * 是否可以开始画线
* *
* @return startPoint不为空返回true * @return startPoint不为空返回true
*/ */
public boolean prepareForDrawLining() { public boolean prepareForDrawLining() {
return startPoint != null; return startPoint != null;
} }
/** /**
* 设置开始位置 * 设置开始位置
* *
* @param p point位置 * @param p point位置
*/ */
public void setStartPoint(Point p) { public void setStartPoint(Point p) {
this.startPoint = p; this.startPoint = p;
} }
/** /**
* 返回开始位置 * 返回开始位置
* *
* @return 点位置 * @return 点位置
*/ */
public Point getStartPoint() { public Point getStartPoint() {
return startPoint; return startPoint;
} }
/** /**
* 返回当前点位置 * 返回当前点位置
* *
* @return 点位置 * @return 点位置
*/ */
public Point getEndPoint() { public Point getEndPoint() {
return currentPoint; return currentPoint;
} }
/** /**
* 当前选中组件 * 当前选中组件
* *
* @param e 鼠标事件 * @param e 鼠标事件
*/ */
public void startSelecting(MouseEvent e) { public void startSelecting(MouseEvent e) {
selecting = true; selecting = true;
selectionModel.setHotspotBounds(new Rectangle()); selectionModel.setHotspotBounds(new Rectangle());
currentX = getMouseXY(e).x; currentX = getMouseXY(e).x;
currentY = getMouseXY(e).y; currentY = getMouseXY(e).y;
} }
/** /**
* 当前鼠标的xy * 当前鼠标的xy
* *
* @param e 鼠标事件 * @param e 鼠标事件
*/ */
public void startResizing(MouseEvent e) { public void startResizing(MouseEvent e) {
if (!selectionModel.getSelection().isEmpty()) { if (!selectionModel.getSelection().isEmpty()) {
driection.backupBounds(designer); driection.backupBounds(designer);
} }
currentX = getMouseXY(e).x; currentX = getMouseXY(e).x;
currentY = getMouseXY(e).y; currentY = getMouseXY(e).y;
} }
/** /**
* 起始点开始DrawLine * 起始点开始DrawLine
* *
* @param p 点位置 * @param p 点位置
*/ */
public void startDrawLine(Point p) { public void startDrawLine(Point p) {
this.startPoint = p; this.startPoint = p;
if (p != null) { if (p != null) {
try { try {
designer.setCursor(XConnector.connectorCursor); designer.setCursor(XConnector.connectorCursor);
} catch (Exception e) { } catch (Exception e) {
} }
} else { } else {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
} }
} }
/** /**
* 鼠标释放时所在的区域及圈中的组件 * 鼠标释放时所在的区域及圈中的组件
* *
* @param e 鼠标事件 * @param e 鼠标事件
*/ */
public void selectCreators(MouseEvent e) { public void selectCreators(MouseEvent e) {
int x = getMouseXY(e).x; int x = getMouseXY(e).x;
int y = getMouseXY(e).y; int y = getMouseXY(e).y;
Rectangle bounds = createCurrentBounds(x, y); Rectangle bounds = createCurrentBounds(x, y);
if ((x != currentX) || (y != currentY)) { if ((x != currentX) || (y != currentY)) {
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent()));
} }
selectionModel.setHotspotBounds(null); selectionModel.setHotspotBounds(null);
} }
/** /**
* 画所在区域线 * 画所在区域线
* *
* @param e 鼠标事件 * @param e 鼠标事件
*/ */
public void drawLine(MouseEvent e) { public void drawLine(MouseEvent e) {
designer.getDrawLineHelper().setDrawLine(true); designer.getDrawLineHelper().setDrawLine(true);
Point p = designer.getDrawLineHelper().getNearWidgetPoint(e); Point p = designer.getDrawLineHelper().getNearWidgetPoint(e);
if (p != null) { if (p != null) {
currentPoint = p; currentPoint = p;
} else { } else {
currentPoint.x = e.getX() + designer.getArea().getHorizontalValue(); currentPoint.x = e.getX() + designer.getArea().getHorizontalValue();
currentPoint.y = e.getY() + designer.getArea().getVerticalValue(); currentPoint.y = e.getY() + designer.getArea().getVerticalValue();
} }
} }
private Rectangle createCurrentBounds(int x, int y) { private Rectangle createCurrentBounds(int x, int y) {
Rectangle bounds = new Rectangle(); Rectangle bounds = new Rectangle();
bounds.x = Math.min(x, currentX); bounds.x = Math.min(x, currentX);
bounds.y = Math.min(y, currentY); bounds.y = Math.min(y, currentY);
bounds.width = Math.max(x, currentX) - bounds.x; bounds.width = Math.max(x, currentX) - bounds.x;
bounds.height = Math.max(y, currentY) - bounds.y; bounds.height = Math.max(y, currentY) - bounds.y;
return bounds; return bounds;
} }
private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) { private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) {
ArrayList<XCreator> creators = new ArrayList<>(); ArrayList<XCreator> creators = new ArrayList<>();
if (!root.isVisible() && !designer.isRoot(root)) { if (!root.isVisible() && !designer.isRoot(root)) {
return creators; return creators;
} }
if (root instanceof XLayoutContainer) { if (root instanceof XLayoutContainer) {
XLayoutContainer container = (XLayoutContainer) root; XLayoutContainer container = (XLayoutContainer) root;
int count = container.getXCreatorCount(); int count = container.getXCreatorCount();
Rectangle clipped = new Rectangle(selection); Rectangle clipped = new Rectangle(selection);
for (int i = count - 1; i >= 0; i--) { for (int i = count - 1; i >= 0; i--) {
XCreator child = container.getXCreator(i); XCreator child = container.getXCreator(i);
if (selection.contains(child.getBounds())) { if (selection.contains(child.getBounds())) {
creators.add(child); creators.add(child);
} else { } else {
clipped.x = selection.x - child.getX(); clipped.x = selection.x - child.getX();
clipped.y = selection.y - child.getY(); clipped.y = selection.y - child.getY();
creators.addAll(getHotspotCreators(clipped, child)); creators.addAll(getHotspotCreators(clipped, child));
} }
} }
} }
return creators; return creators;
} }
/** /**
* 重置model * 重置model
*/ */
public void resetModel() { public void resetModel() {
dragging = false; dragging = false;
selecting = false; selecting = false;
} }
/** /**
* 重置 * 重置
*/ */
public void reset() { public void reset() {
driection = Location.outer; driection = Location.outer;
dragging = false; dragging = false;
selecting = false; selecting = false;
} }
/** /**
* 取消拖拽 * 取消拖拽
*/ */
public void draggingCancel() { public void draggingCancel() {
designer.repaint(); designer.repaint();
reset(); reset();
} }
/** /**
* 设置可拉伸方向 * 设置可拉伸方向
* *
* @param dir 拉伸方向 * @param dir 拉伸方向
*/ */
public void setDirection(Direction dir) { public void setDirection(Direction dir) {
if (driection != dir) { if (driection != dir) {
this.driection = dir; this.driection = dir;
driection.updateCursor(designer); driection.updateCursor(designer);
} }
} }
/** /**
* x吸附线赋值 * x吸附线赋值
* *
* @param line 线 * @param line 线
*/ */
public void setXAbsorptionline(Absorptionline line) { public void setXAbsorptionline(Absorptionline line) {
this.lineInX = line; this.lineInX = line;
} }
/** /**
* y吸附线赋值 * y吸附线赋值
* *
* @param line 线 * @param line 线
*/ */
public void setYAbsorptionline(Absorptionline line) { public void setYAbsorptionline(Absorptionline line) {
this.lineInY = line; this.lineInY = line;
} }
/** /**
* 等距线赋值 * 等距线赋值
* *
* @param line 线 * @param line 线
*/ */
public void setEquidistantLine(Absorptionline line) { public void setEquidistantLine(Absorptionline line) {
this.lineEquidistant = line; this.lineEquidistant = line;
} }
/** /**
* 画吸附线 * 画吸附线
* *
* @param g Graphics类 * @param g Graphics类
*/ */
public void paintAbsorptionline(Graphics g) { public void paintAbsorptionline(Graphics g) {
if (lineInX != null) { if (lineInX != null) {
lineInX.paint(g, designer.getArea()); lineInX.paint(g, designer.getArea());
} }
if (lineInY != null) { if (lineInY != null) {
lineInY.paint(g, designer.getArea()); lineInY.paint(g, designer.getArea());
} }
if (lineEquidistant != null) { if (lineEquidistant != null) {
lineEquidistant.paint(g, designer.getArea()); lineEquidistant.paint(g, designer.getArea());
} }
} }
/** /**
* 拖拽 * 拖拽
* *
* @param e 鼠标事件 * @param e 鼠标事件
*/ */
public void dragging(MouseEvent e) { public void dragging(MouseEvent e) {
//进入dragging状态时备份组件大小和位置 //进入dragging状态时备份组件大小和位置
if (!dragging) { if (!dragging) {
selectedPositionBackup = selectionModel.getSelection().getRelativeBounds(); selectedPositionBackup = selectionModel.getSelection().getRelativeBounds();
} }
checkAddable(e); checkAddable(e);
setDependLinePainter(e); setDependLinePainter(e);
driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer); driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer);
this.dragging = true; this.dragging = true;
} }
// 拖拽时画依附线用到的painter // 拖拽时画依附线用到的painter
private void setDependLinePainter(MouseEvent e) { private void setDependLinePainter(MouseEvent e) {
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators());
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp);
XCreator creator = selectionModel.getSelection().getSelectedCreator(); XCreator creator = selectionModel.getSelection().getSelectedCreator();
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); HoverPainter painter = AdapterBus.getContainerPainter(designer, container);
designer.setPainter(painter); designer.setPainter(painter);
if (painter != null) { if (painter != null) {
painter.setHotspot(new Point(e.getX(), e.getY())); painter.setHotspot(new Point(e.getX(), e.getY()));
painter.setCreator(creator); painter.setCreator(creator);
} }
} }
/** /**
* 释放捕获 * 释放捕获
* *
* @param e 鼠标事件 * @param e 鼠标事件
*/ */
public void releaseDragging(MouseEvent e) { public void releaseDragging(MouseEvent e) {
this.dragging = false; this.dragging = false;
if (addable) { if (addable) {
adding(e.getX(), e.getY()); adding(e.getX(), e.getY());
} else if (!selectionModel.getSelection().isEmpty()) { } else if (!selectionModel.getSelection().isEmpty()) {
selectionModel.releaseDragging(); selectionModel.releaseDragging();
} }
designer.repaint(); designer.repaint();
} }
/** /**
* 改变选择区域 * 改变选择区域
* *
* @param e 鼠标事件 * @param e 鼠标事件
*/ */
public void changeSelection(MouseEvent e) { public void changeSelection(MouseEvent e) {
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y);
selectionModel.setHotspotBounds(bounds); selectionModel.setHotspotBounds(bounds);
} }
/** /**
* 返回鼠标所在的xy 考虑滚动条的值 * 返回鼠标所在的xy 考虑滚动条的值
* *
* @param e 鼠标事件 * @param e 鼠标事件
* @return xy值 * @return xy值
*/ */
public Point getMouseXY(MouseEvent e) { public Point getMouseXY(MouseEvent e) {
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY()
+ designer.getArea().getVerticalValue()); + designer.getArea().getVerticalValue());
return p1; return p1;
} }
} }

190
designer_form/src/com/fr/design/designer/beans/painters/AbstractPainter.java

@ -1,96 +1,96 @@
package com.fr.design.designer.beans.painters; package com.fr.design.designer.beans.painters;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Stroke; import java.awt.Stroke;
import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.HoverPainter;
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.form.util.XCreatorConstants; import com.fr.design.form.util.XCreatorConstants;
import com.fr.general.Inter; import com.fr.general.Inter;
public abstract class AbstractPainter implements HoverPainter { public abstract class AbstractPainter implements HoverPainter {
protected Point hotspot; protected Point hotspot;
protected Rectangle hotspot_bounds; protected Rectangle hotspot_bounds;
protected XLayoutContainer container; protected XLayoutContainer container;
protected XCreator creator; protected XCreator creator;
/** /**
* 构造函数 * 构造函数
* *
* @param container 容器 * @param container 容器
*/ */
public AbstractPainter(XLayoutContainer container) { public AbstractPainter(XLayoutContainer container) {
this.container = container; this.container = container;
} }
@Override @Override
public void setHotspot(Point p) { public void setHotspot(Point p) {
hotspot = p; hotspot = p;
} }
/** /**
* 画初始区域 * 画初始区域
* *
* @param g 画图类 * @param g 画图类
* @param startX 起始x位置 * @param startX 起始x位置
* @param startY 起始y位置 * @param startY 起始y位置
*/ */
public void paint(Graphics g, int startX, int startY) { public void paint(Graphics g, int startX, int startY) {
if (hotspot_bounds != null) { if (hotspot_bounds != null) {
drawHotspot(g, hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height, Color.lightGray, true, false); drawHotspot(g, hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height, Color.lightGray, true, false);
} }
} }
/** /**
* 设置边界 * 设置边界
* *
* @param rect 位置 * @param rect 位置
*/ */
@Override @Override
public void setRenderingBounds(Rectangle rect) { public void setRenderingBounds(Rectangle rect) {
hotspot_bounds = rect; hotspot_bounds = rect;
} }
@Override @Override
public void setCreator(XCreator component) { public void setCreator(XCreator component) {
this.creator = component; this.creator = component;
} }
protected void drawHotspot(Graphics g, int x, int y, int width, int height, boolean accept) { protected void drawHotspot(Graphics g, int x, int y, int width, int height, boolean accept) {
Color bColor = accept ? XCreatorConstants.LAYOUT_HOTSPOT_COLOR : XCreatorConstants.LAYOUT_FORBIDDEN_COLOR; Color bColor = accept ? XCreatorConstants.LAYOUT_HOTSPOT_COLOR : XCreatorConstants.LAYOUT_FORBIDDEN_COLOR;
drawHotspot(g, x, y, width, height, bColor, accept, false); drawHotspot(g, x, y, width, height, bColor, accept, false);
} }
/** /**
* 自适应布局那边渲染提示要画整个背景不是画边框 * 自适应布局那边渲染提示要画整个背景不是画边框
*/ */
protected void drawRegionBackground(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept) { protected void drawRegionBackground(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept) {
drawHotspot(g, x, y, width, height, bColor, accept, true); drawHotspot(g, x, y, width, height, bColor, accept, true);
} }
protected void drawHotspot(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept, boolean drawBackground) { protected void drawHotspot(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept, boolean drawBackground) {
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
Color color = g2d.getColor(); Color color = g2d.getColor();
Stroke backup = g2d.getStroke(); Stroke backup = g2d.getStroke();
// 设置线条的样式 // 设置线条的样式
g2d.setStroke(XCreatorConstants.STROKE); g2d.setStroke(XCreatorConstants.STROKE);
g2d.setColor(bColor); g2d.setColor(bColor);
if (!accept) { if (!accept) {
g2d.drawString(Inter.getLocText("Cannot-Add_To_This_Area") + "!", x + width / 3, y + height / 2); g2d.drawString(Inter.getLocText("Cannot-Add_To_This_Area") + "!", x + width / 3, y + height / 2);
} else if (drawBackground) { } else if (drawBackground) {
g2d.fillRect(x, y, width, height); g2d.fillRect(x, y, width, height);
} else { } else {
g2d.drawRect(x, y, width, height); g2d.drawRect(x, y, width, height);
} }
g2d.setStroke(backup); g2d.setStroke(backup);
g2d.setColor(color); g2d.setColor(color);
} }
} }

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