Browse Source

解决冲突代码

master
mengao 8 years ago
parent
commit
c3e8ef59f8
  1. 2
      designer_base/src/com/fr/design/locale/designer.properties
  2. 2
      designer_base/src/com/fr/design/locale/designer_en_US.properties
  3. 2
      designer_base/src/com/fr/design/locale/designer_zh_CN.properties
  4. 2
      designer_base/src/com/fr/design/locale/designer_zh_TW.properties
  5. 11
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  6. 26
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java
  7. 2
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  8. 15
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java
  9. 272
      designer_form/src/com/fr/design/designer/beans/models/AddingModel.java
  10. 46
      designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java
  11. 920
      designer_form/src/com/fr/design/designer/beans/models/StateModel.java
  12. 187
      designer_form/src/com/fr/design/designer/beans/painters/AbstractPainter.java
  13. 435
      designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java
  14. 338
      designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java
  15. 17
      designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java
  16. 6
      designer_form/src/com/fr/design/mainframe/FormDesigner.java
  17. 12
      designer_form/src/com/fr/design/mainframe/FormSelection.java
  18. 75
      designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

2
designer_base/src/com/fr/design/locale/designer.properties

@ -589,3 +589,5 @@ FR-Designer_AxisReversed=Axis Reversed
FR-Designer_Logarithmic=Logarithmic FR-Designer_Logarithmic=Logarithmic
FR-Designer_Chart_Log_Base=Log Base FR-Designer_Chart_Log_Base=Log Base
FR-Designer_Chart_F_Radar_Axis=Chart_F_Radar_Axis FR-Designer_Chart_F_Radar_Axis=Chart_F_Radar_Axis
FR-Designer_Too_Large_To_Paste=too large to paste
FR-Designer_Too_Small_To_Paste=Too small to paste

2
designer_base/src/com/fr/design/locale/designer_en_US.properties

@ -590,3 +590,5 @@ FR-Designer_AxisReversed=Axis in reverse order
FR-Designer_Logarithmic=Log scale FR-Designer_Logarithmic=Log scale
FR-Designer_Chart_Log_Base=Log Base FR-Designer_Chart_Log_Base=Log Base
FR-Designer_Chart_F_Radar_Axis=Value Axis FR-Designer_Chart_F_Radar_Axis=Value Axis
FR-Designer_Too_Large_To_Paste=Too large to paste!
FR-Designer_Too_Small_To_Paste=Too small to paste!

2
designer_base/src/com/fr/design/locale/designer_zh_CN.properties

@ -594,3 +594,5 @@ FR-Designer_AxisReversed=\u8F74\u9006\u5E8F
FR-Designer_Logarithmic=\u5BF9\u6570\u523B\u5EA6 FR-Designer_Logarithmic=\u5BF9\u6570\u523B\u5EA6
FR-Designer_Chart_Log_Base=\u5E95\u6570 FR-Designer_Chart_Log_Base=\u5E95\u6570
FR-Designer_Chart_F_Radar_Axis=\u503C\u8F74 FR-Designer_Chart_F_Radar_Axis=\u503C\u8F74
FR-Designer_Too_Large_To_Paste=\u7EC4\u4EF6\u5927\u5C0F\u8D85\u51FA\u8FB9\u754C\uFF0C\u65E0\u6CD5\u7C98\u8D34\uFF01
FR-Designer_Too_Small_To_Paste=\u6B64\u5904\u65E0\u6CD5\u7C98\u8D34\uFF0C\u5C0F\u4E8E\u7EC4\u4EF6\u6700\u5C0F\u9AD8\u5EA6\uFF01

2
designer_base/src/com/fr/design/locale/designer_zh_TW.properties

@ -582,3 +582,5 @@ FR-Designer_AxisReversed=\u8EF8\u9006\u5E8F
FR-Designer_Logarithmic=\u5C0D\u6578\u523B\u5EA6 FR-Designer_Logarithmic=\u5C0D\u6578\u523B\u5EA6
FR-Designer_Chart_Log_Base=\u5E95\u6578 FR-Designer_Chart_Log_Base=\u5E95\u6578
FR-Designer_Chart_F_Radar_Axis=\u503C\u8EF8 FR-Designer_Chart_F_Radar_Axis=\u503C\u8EF8
FR-Designer_Too_Large_To_Paste=\u7D44\u4EF6\u5927\u5C0F\u8D85\u51FA\u908A\u754C\uFF0C\u7121\u6CD5\u7C98\u8CBC\uFF01
FR-Designer_Too_Small_To_Paste=\u6B64\u8655\u7121\u6CD5\u7C98\u8CBC\uFF0C\u5C0F\u65BC\u7D44\u4EF6\u6700\u5C0F\u9AD8\u5EA6\uFF01

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

@ -283,7 +283,6 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
} else if (isCrossPointArea(parentComp, x, y)) { } else if (isCrossPointArea(parentComp, x, y)) {
//交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入 //交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入
fixCrossPointArea(parentComp, child, x, y); fixCrossPointArea(parentComp, child, x, y);
//TODO 尽量不要出现这种写法吧?if else条件要么互斥,要么多个if判断return,不要在一条if else语句里面return吧?
return; return;
} else if (isTrisectionArea(parentComp, x, y)) { } else if (isTrisectionArea(parentComp, x, y)) {
// 在边界三等分区域,就不再和组件二等分了 // 在边界三等分区域,就不再和组件二等分了
@ -320,17 +319,15 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
int height = creator.getHeight(); int height = creator.getHeight();
int width = creator.getWidth(); int width = creator.getWidth();
if (x < 0) { if (x < 0) {
width += x; x = container.getX();
x = 0;
} else if (x + creator.getWidth() > container.getWidth()) { } else if (x + creator.getWidth() > container.getWidth()) {
width = container.getWidth() - x; x = container.getWidth() - width;
} }
if (y < 0) { if (y < 0) {
height += y; y = container.getY();
y = 0;
} else if (y + creator.getHeight() > container.getHeight()) { } else if (y + creator.getHeight() > container.getHeight()) {
height = container.getHeight() - y; y = container.getHeight() - height;
} }
creator.setBounds(x, y, width, height); creator.setBounds(x, y, width, height);

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

@ -640,11 +640,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter {
* 又通过ComponentUtils.getRelativeBounds()方法获取到了绝对坐标 * 又通过ComponentUtils.getRelativeBounds()方法获取到了绝对坐标
* 再次计算相对坐标所以将y值重新变成绝对坐标 * 再次计算相对坐标所以将y值重新变成绝对坐标
* */ * */
if (currentCreator.getBackupParent().getLocation().y == WBorderLayout.DEFAULT_SIZE) { y = y + WCardMainBorderLayout.TAB_HEIGHT + this.getParaEditorYOffset();
y = y + WCardMainBorderLayout.TAB_HEIGHT + WBorderLayout.DEFAULT_SIZE;
} else {
y = y + WCardMainBorderLayout.TAB_HEIGHT;
}
int tempX = x - rect.x; int tempX = x - rect.x;
int tempY = y - rect.y; int tempY = y - rect.y;
int containerX = container.getX(); int containerX = container.getX();
@ -675,6 +671,26 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter {
return position; return position;
} }
/**
* 获取因为参数面板导致的Y坐标偏移
*
* @return 参数面板导致的Y坐标偏移
*/
protected int getParaEditorYOffset() {
int offset = 0;
if (container.getParent() != null) {
Component components[] = container.getParent().getComponents();
for (Component component : components) {
if (component instanceof XWParameterLayout) {
offset = component.getY() + component.getHeight();
break;
}
}
}
return offset;
}
/** /**
* 组件交叉区域进行插入时调整受到变动的其他组件,之前是交叉区域插入也按照三等分逻辑后面测试中发现有bug改为和bi一样的鼠标所在侧平分 * 组件交叉区域进行插入时调整受到变动的其他组件,之前是交叉区域插入也按照三等分逻辑后面测试中发现有bug改为和bi一样的鼠标所在侧平分
* 默认左上角右下角区域是垂直方向插入组件 * 默认左上角右下角区域是垂直方向插入组件

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

@ -133,7 +133,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
isFindRelatedComps = false; isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y); Component comp = container.getComponentAt(x, y);
if (checkInterval(comp)) { if (comp == null || checkInterval(comp)) {
return false; return false;
} }
//如果当前处于边缘地带, 那么就把他贴到父容器上 //如果当前处于边缘地带, 那么就把他贴到父容器上

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

@ -7,11 +7,13 @@ 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.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.XWidgetCreator; import com.fr.design.designer.creator.XWidgetCreator;
import com.fr.design.designer.creator.cardlayout.XWCardLayout; import com.fr.design.designer.creator.cardlayout.XWCardLayout;
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; 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.FRTabFitLayoutPropertiesGroupModel; import com.fr.design.designer.properties.FRTabFitLayoutPropertiesGroupModel;
import com.fr.design.mainframe.widget.editors.ParameterEditor;
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.WBorderLayout; import com.fr.form.ui.container.WBorderLayout;
@ -82,16 +84,14 @@ public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter {
return true; return true;
} }
// tab布局的纵坐标受到tab高度的影响,判断的上边界取得是里面XWTabFitLayout的上边界, // tab布局的纵坐标受到tab高度以及参数面板高度的影响,判断的上边界取得是里面XWTabFitLayout的上边界,
// 实际计算的时候的纵坐标用了外层的CardMainBorerLayout,需要将tab高度减掉 // 实际计算的时候的纵坐标用了外层的CardMainBorerLayout,需要将tab高度和参数面板高度减掉
//将y值变为相对坐标以实现获取到鼠标drop位置的控件 // 将y值变为相对坐标以实现获取到鼠标drop位置的控件
//TODO 可以直接在这边将x,y都变成相对坐标,这样在后面判断拖进来的新控件放置方式的时候就不用再判断了 // TODO 可以直接在这边将x,y都变成相对坐标,这样在后面判断拖进来的新控件放置方式的时候就不用再判断了
private int adjustY(int y, XWTabFitLayout tabLayout) { private int adjustY(int y, XWTabFitLayout tabLayout) {
XWCardLayout cardLayout = (XWCardLayout) tabLayout.getBackupParent(); XWCardLayout cardLayout = (XWCardLayout) tabLayout.getBackupParent();
LayoutBorderStyle style = cardLayout.toData().getBorderStyle(); LayoutBorderStyle style = cardLayout.toData().getBorderStyle();
if (container.getLocation().y == WBorderLayout.DEFAULT_SIZE) { y = y - this.getParaEditorYOffset();
y = y - WBorderLayout.DEFAULT_SIZE;
}
if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) { if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) {
y = y - WCardMainBorderLayout.TAB_HEIGHT; y = y - WCardMainBorderLayout.TAB_HEIGHT;
} }
@ -101,4 +101,5 @@ public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter {
protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) { protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) {
return ComponentUtils.getRelativeBounds(mainLayout); return ComponentUtils.getRelativeBounds(mainLayout);
} }
} }

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

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

46
designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java

@ -13,6 +13,7 @@ import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.FormSelection; import com.fr.design.mainframe.FormSelection;
import com.fr.design.mainframe.FormSelectionUtils; import com.fr.design.mainframe.FormSelectionUtils;
import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.LayoutUtils; import com.fr.design.utils.gui.LayoutUtils;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
@ -26,7 +27,7 @@ import java.util.ArrayList;
public class SelectionModel { public class SelectionModel {
//被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。 //被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。
private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离 private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离
private static final int BORDER_PROPORTION = 20; private static final double OFFSET_RELATIVE = 0.80;
private static FormSelection clipboard = new FormSelection(); private static FormSelection clipboard = new FormSelection();
private FormDesigner designer; private FormDesigner designer;
private FormSelection selection; private FormSelection selection;
@ -111,7 +112,7 @@ public class SelectionModel {
*/ */
public boolean pasteFromClipBoard() { public boolean pasteFromClipBoard() {
if (!clipboard.isEmpty()) { if (!clipboard.isEmpty()) {
if (!hasSelectionComponent()) { if (!hasSelectedPasteSource()) {
//未选 //未选
unselectedPaste(); unselectedPaste();
} else { } else {
@ -140,14 +141,14 @@ public class SelectionModel {
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(),
clipboard, clipboard,
rec.x + rec.width / 2, rec.x + rec.width / 2,
rec.y + BORDER_PROPORTION); rec.y + DELTA_X_Y);
} else { } else {
Rectangle rec = selection.getRelativeBounds(); Rectangle rec = selection.getRelativeBounds();
//自适应布局 //自适应布局
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
clipboard, clipboard,
rec.x + rec.width / 2, rec.x + rec.width / 2,
rec.y + BORDER_PROPORTION); rec.y + DELTA_X_Y);
} }
} else { } else {
//绝对布局 //绝对布局
@ -172,18 +173,22 @@ public class SelectionModel {
* 粘贴时选择组件 * 粘贴时选择组件
*/ */
private void selectedPaste() { private void selectedPaste() {
XLayoutContainer parent = null; XLayoutContainer container = null;
//获取到编辑器的表层容器(已选的组件的父容器就是表层容器) //获取到编辑器的表层容器(已选的组件的父容器就是表层容器)
parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); container = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (parent != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) { if (container != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) {
//自适应布局 //自适应布局
Rectangle rec = selection.getRelativeBounds(); Rectangle selectionRec = selection.getRelativeBounds();
FormSelectionUtils.paste2Container(designer, parent, clipboard, rec.x + rec.width / 2, rec.y + Rectangle containerRec = ComponentUtils.getRelativeBounds(container);
rec.height - BORDER_PROPORTION); //计算自适应布局位置
} else if (parent != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { int positionX = selectionRec.x - containerRec.x + selectionRec.width / 2;
int positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE);
FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY);
} else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) {
//绝对布局 //绝对布局
Rectangle rec = selection.getSelctionBounds(); Rectangle rec = selection.getSelctionBounds();
FormSelectionUtils.paste2Container(designer, parent, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); FormSelectionUtils.paste2Container(designer, container, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y);
} }
} }
@ -198,13 +203,13 @@ public class SelectionModel {
if (creator.acceptType(XWParameterLayout.class)) { if (creator.acceptType(XWParameterLayout.class)) {
designer.removeParaComponent(); designer.removeParaComponent();
} }
removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight()); removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight());
creator.removeAll(); creator.removeAll();
// 清除被选中的组件 // 清除被选中的组件
selection.reset(); selection.reset();
} }
setSelectedCreator(designer.getRootComponent()); setSelectedCreator(designer.getRootComponent());
FormSelectionUtils.rebuildSelection(designer);
// 触发事件 // 触发事件
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED);
designer.repaint(); designer.repaint();
@ -275,7 +280,7 @@ public class SelectionModel {
* 但是编辑窗口的最外层其实是表层@see {@link com.fr.design.designer.creator.XWAbsoluteBodyLayout}, * 但是编辑窗口的最外层其实是表层@see {@link com.fr.design.designer.creator.XWAbsoluteBodyLayout},
* 其他两层不是靠添加组件就可以编辑的 * 其他两层不是靠添加组件就可以编辑的
*/ */
public boolean hasSelectionComponent() { public boolean hasSelectedPasteSource() {
XCreator selectionXCreator = selection.getSelectedCreator(); XCreator selectionXCreator = selection.getSelectedCreator();
if (designer.getClass().equals(FormDesigner.class)) { if (designer.getClass().equals(FormDesigner.class)) {
//frm本地组件复用 //frm本地组件复用
@ -286,10 +291,12 @@ public class SelectionModel {
|| selectionXCreator.getClass().equals(XWTabFitLayout.class); || selectionXCreator.getClass().equals(XWTabFitLayout.class);
//选中的是否是frm绝对布局编辑器本身 //选中的是否是frm绝对布局编辑器本身
boolean absoluteEditor = selectionXCreator.getClass().equals(XWAbsoluteBodyLayout.class); boolean absoluteEditor = selectionXCreator.getClass().equals(XWAbsoluteBodyLayout.class);
//选中是否是frm绝对画布块编辑器本身
boolean absoluteCanvas = selectionXCreator.getClass().equals(XWAbsoluteLayout.class);
//选中的是否是相对布局编辑器本身 //选中的是否是相对布局编辑器本身
boolean relativeEditor = selectionXCreator.getClass().equals(XWFitLayout.class); boolean relativeEditor = selectionXCreator.getClass().equals(XWFitLayout.class);
return !(tabEditor || absoluteEditor || relativeEditor); return !(tabEditor || absoluteEditor || absoluteCanvas || relativeEditor);
} else { } else {
return false; return false;
} }
@ -299,6 +306,15 @@ public class SelectionModel {
} }
} }
/**
* 是否有组件被选择如果所选组件是最底层容器也视为无选择
*
* @return 是则返回true
*/
public boolean hasSelectionComponent() {
return !selection.isEmpty() && selection.getSelectedCreator().getParent() != null;
}
/** /**
* 移动组件至指定位置 * 移动组件至指定位置
* *

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

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

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

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

435
designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java

@ -30,12 +30,12 @@ import java.util.List;
* @since 6.5.3 * @since 6.5.3
*/ */
public abstract class XLayoutContainer extends XBorderStyleWidgetCreator implements ContainerListener, ParameterBridge { public abstract class XLayoutContainer extends XBorderStyleWidgetCreator implements ContainerListener, ParameterBridge {
// 布局内部组件默认最小宽度36,最小高度21 // 布局内部组件默认最小宽度36,最小高度21
public static int MIN_WIDTH = 36; public static int MIN_WIDTH = 36;
public static int MIN_HEIGHT = 21; public static int MIN_HEIGHT = 21;
protected static final Dimension LARGEPREFERREDSIZE = new Dimension(200, 200); protected static final Dimension LARGEPREFERREDSIZE = new Dimension(200, 200);
protected boolean isRefreshing; protected boolean isRefreshing;
protected int default_Length = 5; // 取指定点坐在的组件,默认为5保证取四侧相邻的组件时x、y在组件内非边框上 protected int default_Length = 5; // 取指定点坐在的组件,默认为5保证取四侧相邻的组件时x、y在组件内非边框上
@ -45,6 +45,7 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
protected boolean editable = false; protected boolean editable = false;
//鼠标移动到布局画出编辑层 //鼠标移动到布局画出编辑层
protected boolean isMouseEnter = false; protected boolean isMouseEnter = false;
public void setMouseEnter(boolean mouseEnter) { public void setMouseEnter(boolean mouseEnter) {
isMouseEnter = mouseEnter; isMouseEnter = mouseEnter;
} }
@ -55,12 +56,13 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
} }
/** /**
* 得到属性名 * 得到属性名
*
* @return 属性名 * @return 属性名
* @throws IntrospectionException * @throws IntrospectionException
*/ */
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
return new CRPropertyDescriptor[] { return new CRPropertyDescriptor[]{
new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(Inter new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(Inter
.getLocText("FR-Designer_Form-Widget_Name")), .getLocText("FR-Designer_Form-Widget_Name")),
new CRPropertyDescriptor("borderStyle", this.data.getClass()).setEditorClass( new CRPropertyDescriptor("borderStyle", this.data.getClass()).setEditorClass(
@ -68,19 +70,20 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
Inter.getLocText("FR-Engine_Style")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") Inter.getLocText("FR-Engine_Style")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced")
.setPropertyChangeListener(new PropertyChangeAdapter() { .setPropertyChangeListener(new PropertyChangeAdapter() {
@Override @Override
public void propertyChange() { public void propertyChange() {
initStyle(); initStyle();
} }
}), }),
new CRPropertyDescriptor("margin", this.data.getClass()).setEditorClass(PaddingMarginEditor.class) new CRPropertyDescriptor("margin", this.data.getClass()).setEditorClass(PaddingMarginEditor.class)
.setI18NName(Inter.getLocText("FR-Designer_Layout-Padding")) .setI18NName(Inter.getLocText("FR-Designer_Layout-Padding"))
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), .putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"),
}; };
} }
/** /**
* 控件名属性 * 控件名属性
*
* @return * @return
* @throws IntrospectionException * @throws IntrospectionException
*/ */
@ -91,6 +94,7 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/** /**
* 边距属性 * 边距属性
*
* @return * @return
* @throws IntrospectionException * @throws IntrospectionException
*/ */
@ -101,47 +105,50 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
} }
/** /**
* 返回对应的wlayout * 返回对应的wlayout
*
* @return wlayout控件 * @return wlayout控件
*/ */
public WLayout toData() { public WLayout toData() {
return (WLayout) data; return (WLayout) data;
} }
@Override @Override
protected void initXCreatorProperties() { protected void initXCreatorProperties() {
super.initXCreatorProperties(); super.initXCreatorProperties();
initBorderStyle(); initBorderStyle();
this.initLayoutManager(); this.initLayoutManager();
this.convert(); this.convert();
} }
@Override @Override
protected JComponent initEditor() { protected JComponent initEditor() {
return this; return this;
} }
/** /**
* 当前组件zorder位置替换新的控件 * 当前组件zorder位置替换新的控件
* @param widget 控件 *
* @param oldcreator 旧组件 * @param widget 控件
* @return 组件 * @param oldcreator 旧组件
*/ * @return 组件
public XCreator replace(Widget widget, XCreator oldcreator) { */
int i = this.getComponentZOrder(oldcreator); public XCreator replace(Widget widget, XCreator oldcreator) {
if (i != -1) { int i = this.getComponentZOrder(oldcreator);
this.toData().replace(widget, oldcreator.toData()); if (i != -1) {
this.convert(); this.toData().replace(widget, oldcreator.toData());
XCreator creator = (XCreator) this.getComponent(i); this.convert();
creator.setSize(oldcreator.getSize()); XCreator creator = (XCreator) this.getComponent(i);
return creator; creator.setSize(oldcreator.getSize());
} return creator;
return null; }
} return null;
}
/**
* 初始化时默认的组件大小 /**
* @return 默认Dimension * 初始化时默认的组件大小
*
* @return 默认Dimension
*/ */
public Dimension initEditorSize() { public Dimension initEditorSize() {
return LARGEPREFERREDSIZE; return LARGEPREFERREDSIZE;
@ -172,7 +179,8 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/** /**
* 设计界面中有组件添加时要通知WLayout容器重新paint * 设计界面中有组件添加时要通知WLayout容器重新paint
* @param e 待说明 *
* @param e 待说明
*/ */
@Override @Override
public void componentAdded(ContainerEvent e) { public void componentAdded(ContainerEvent e) {
@ -188,7 +196,8 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/** /**
* 设计界面中有组件添加时要通知WLayout容器重新paint * 设计界面中有组件添加时要通知WLayout容器重新paint
* @param e 待说明 *
* @param e 待说明
*/ */
@Override @Override
public void componentRemoved(ContainerEvent e) { public void componentRemoved(ContainerEvent e) {
@ -203,6 +212,7 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/** /**
* 根据widget的属性值来获取 * 根据widget的属性值来获取
*
* @param wgt * @param wgt
* @return * @return
*/ */
@ -226,30 +236,32 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
public int getXCreatorCount() { public int getXCreatorCount() {
return getComponentCount(); return getComponentCount();
} }
public XCreator getXCreator(int i) { public XCreator getXCreator(int i) {
return (XCreator) getComponent(i); return (XCreator) getComponent(i);
} }
/** /**
* 该组件是否可以拖入参数面板 * 该组件是否可以拖入参数面板
*
* @return 是则返回true * @return 是则返回true
*/ */
public boolean canEnterIntoParaPane(){ public boolean canEnterIntoParaPane() {
return false; return false;
} }
/** /**
* 是否作为控件树的叶子节点 * 是否作为控件树的叶子节点
* @return 是则返回true *
*/ * @return 是则返回true
public boolean isComponentTreeLeaf() { */
return false; public boolean isComponentTreeLeaf() {
} return false;
}
public List<String> getAllXCreatorNameList(XCreator xCreator, List<String> namelist){ public List<String> getAllXCreatorNameList(XCreator xCreator, List<String> namelist) {
for (int i = 0; i < ((XLayoutContainer)xCreator).getXCreatorCount(); i++) { for (int i = 0; i < ((XLayoutContainer) xCreator).getXCreatorCount(); i++) {
XCreator creatorSon = ((XLayoutContainer)xCreator).getXCreator(i); XCreator creatorSon = ((XLayoutContainer) xCreator).getXCreator(i);
creatorSon.getAllXCreatorNameList(creatorSon, namelist); creatorSon.getAllXCreatorNameList(creatorSon, namelist);
} }
return namelist; return namelist;
@ -257,19 +269,20 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/** /**
* 是否有查询按钮 * 是否有查询按钮
* @param xCreator 控件或容器 *
* @return 有无查询按钮 * @param xCreator 控件或容器
* @return 有无查询按钮
*/ */
public boolean SearchQueryCreators(XCreator xCreator) { public boolean SearchQueryCreators(XCreator xCreator) {
for (int i = 0; i < ((XLayoutContainer)xCreator).getXCreatorCount(); i++) { for (int i = 0; i < ((XLayoutContainer) xCreator).getXCreatorCount(); i++) {
XCreator creatorSon = ((XLayoutContainer)xCreator).getXCreator(i); XCreator creatorSon = ((XLayoutContainer) xCreator).getXCreator(i);
if(creatorSon.SearchQueryCreators(creatorSon)){ if (creatorSon.SearchQueryCreators(creatorSon)) {
return true; return true;
} }
} }
return false; return false;
} }
public FRLayoutManager getFRLayout() { public FRLayoutManager getFRLayout() {
LayoutManager layout = getLayout(); LayoutManager layout = getLayout();
if (layout instanceof FRLayoutManager) { if (layout instanceof FRLayoutManager) {
@ -279,111 +292,120 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
return null; return null;
} }
public abstract LayoutAdapter getLayoutAdapter(); public abstract LayoutAdapter getLayoutAdapter();
public int getIndexOfChild(Object child) { public int getIndexOfChild(Object child) {
int count = getComponentCount(); int count = getComponentCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Component comp = getComponent(i); Component comp = getComponent(i);
if (comp == child) { if (comp == child) {
return i; return i;
} }
} }
return -1; return -1;
} }
/** /**
* 主要为自适应用 * 主要为自适应用
* 返回指定point的上方组件 * 返回指定point的上方组件
* @param x x位置 *
* @param y y位置 * @param x x位置
* @return 指定位置的组件 * @param y y位置
*/ * @return 指定位置的组件
public Component getTopComp(int x, int y) { */
return this.getComponentAt(x, y-default_Length); public Component getTopComp(int x, int y) {
} return this.getComponentAt(x, y - default_Length);
}
/**
* 主要为自适应用 /**
* 返回指定point的左方组件 * 主要为自适应用
* @param x x位置 * 返回指定point的左方组件
* @param y y位置 *
* @return 指定位置的组件 * @param x x位置
*/ * @param y y位置
public Component getLeftComp(int x, int y) { * @return 指定位置的组件
return this.getComponentAt(x-default_Length, y); */
} public Component getLeftComp(int x, int y) {
return this.getComponentAt(x - default_Length, y);
/** }
* 返回指定point的右方组件
* @param x x位置 /**
* @param y y位置 * 返回指定point的右方组件
* @param w 宽度 *
* @return 指定位置的组件 * @param x x位置
*/ * @param y y位置
public Component getRightComp(int x, int y, int w) { * @param w 宽度
return this.getComponentAt(x+w+default_Length, y); * @return 指定位置的组件
} */
public Component getRightComp(int x, int y, int w) {
/** return this.getComponentAt(x + w + default_Length, y);
* 返回指定point的下方组件 }
* @param x x位置
* @param y y位置 /**
* @param h 高度 * 返回指定point的下方组件
* @return 指定位置的组件 *
*/ * @param x x位置
public Component getBottomComp(int x, int y, int h) { * @param y y位置
return this.getComponentAt(x, y+h+default_Length); * @param h 高度
} * @return 指定位置的组件
*/
/** public Component getBottomComp(int x, int y, int h) {
* 返回指定point的上方且是右侧的组件 return this.getComponentAt(x, y + h + default_Length);
* @param x x位置 }
* @param y y位置
* @param w 宽度 /**
* @return 指定位置的组件 * 返回指定point的上方且是右侧的组件
*/ *
public Component getRightTopComp(int x, int y, int w) { * @param x x位置
return this.getComponentAt(x+w-default_Length, y-default_Length); * @param y y位置
} * @param w 宽度
* @return 指定位置的组件
/** */
* 返回指定point的左方且是下侧的组件 public Component getRightTopComp(int x, int y, int w) {
* @param x x位置 return this.getComponentAt(x + w - default_Length, y - default_Length);
* @param y y位置 }
* @param h 高度
* @return 指定位置的组件 /**
*/ * 返回指定point的左方且是下侧的组件
public Component getBottomLeftComp(int x, int y, int h) { *
return this.getComponentAt(x-default_Length, y+h-default_Length); * @param x x位置
} * @param y y位置
* @param h 高度
/** * @return 指定位置的组件
* 返回指定point的右方且是下侧的组件 */
* @param x x位置 public Component getBottomLeftComp(int x, int y, int h) {
* @param y y位置 return this.getComponentAt(x - default_Length, y + h - default_Length);
* @param h 高度 }
* @param w 宽度
* @return 指定位置的组件 /**
*/ * 返回指定point的右方且是下侧的组件
public Component getBottomRightComp(int x, int y, int h, int w) { *
return this.getComponentAt(x+w+default_Length, y+h-default_Length); * @param x x位置
} * @param y y位置
* @param h 高度
/** * @param w 宽度
* 返回指定point的下方且是右侧的组件 * @return 指定位置的组件
* @param x x位置 */
* @param y y位置 public Component getBottomRightComp(int x, int y, int h, int w) {
* @param h 高度 return this.getComponentAt(x + w + default_Length, y + h - default_Length);
* @param w 宽度 }
* @return 指定位置的组件
*/ /**
public Component getRightBottomComp(int x, int y, int h, int w) { * 返回指定point的下方且是右侧的组件
return this.getComponentAt(x+w-default_Length, y+h+default_Length); *
} * @param x x位置
* @param y y位置
* @param h 高度
* @param w 宽度
* @return 指定位置的组件
*/
public Component getRightBottomComp(int x, int y, int h, int w) {
return this.getComponentAt(x + w - default_Length, y + h + default_Length);
}
/** /**
* 是否延迟展示报表内容也就是说是否要等点击了查询之后才执行报表 * 是否延迟展示报表内容也就是说是否要等点击了查询之后才执行报表
*
* @return 如果是true则表示点击之后才开始计算false则表示会根据参数默认值直接计算报表并展现 * @return 如果是true则表示点击之后才开始计算false则表示会根据参数默认值直接计算报表并展现
*/ */
public boolean isDelayDisplayContent() { public boolean isDelayDisplayContent() {
@ -392,18 +414,20 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/** /**
* 是否显示参数界面 * 是否显示参数界面
*
* @return 显示参数界面则返回true否则返回false * @return 显示参数界面则返回true否则返回false
*/ */
public boolean isDisplay() { public boolean isDisplay() {
return false; return false;
} }
public Background getDataBackground(){ public Background getDataBackground() {
return toData().getBackground(); return toData().getBackground();
} }
/** /**
* 获取参数界面的宽度 * 获取参数界面的宽度
*
* @return 宽度 * @return 宽度
*/ */
public int getDesignWidth() { public int getDesignWidth() {
@ -412,83 +436,82 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/** /**
* 获取参数面板的对齐方式 * 获取参数面板的对齐方式
*
* @return 左中右三种对齐方式 * @return 左中右三种对齐方式
*/ */
public int getPosition() { public int getPosition() {
return 0; return 0;
} }
/** /**
* 切换到非添加状态 * 切换到非添加状态
* *
* @param designer 表单设计器 * @param designer 表单设计器
*/ */
public void stopAddingState(FormDesigner designer){ public void stopAddingState(FormDesigner designer) {
return; }
}
/**
/** * 寻找最近的为自适应布局的父容器
* 寻找最近的为自适应布局的父容器 *
* * @return 布局容器
* @return 布局容器 * @date 2014-12-30-下午3:15:28
* */
* public XLayoutContainer findNearestFit() {
* @date 2014-12-30-下午3:15:28 //一层一层网上找, 找到最近的fit那一层就return
* XLayoutContainer parent = this.getBackupParent();
*/ return parent == null ? null : parent.findNearestFit();
public XLayoutContainer findNearestFit(){ }
//一层一层网上找, 找到最近的fit那一层就return
XLayoutContainer parent = this.getBackupParent();
return parent == null ? null : parent.findNearestFit();
}
/** /**
* 获取容器所有内部组件横坐标值 * 获取容器所有内部组件横坐标值
* *
* @return 横坐标数组 * @return 横坐标数组
*/ */
public int[] getHors(){ public int[] getHors() {
return ArrayUtils.EMPTY_INT_ARRAY; return ArrayUtils.EMPTY_INT_ARRAY;
} }
/** /**
* 获取容器所有内部组件纵坐标值 * 获取容器所有内部组件纵坐标值
* *
* @return 纵坐标数组 * @return 纵坐标数组
*/ */
public int[] getVeris(){ public int[] getVeris() {
return ArrayUtils.EMPTY_INT_ARRAY; return ArrayUtils.EMPTY_INT_ARRAY;
} }
public void setDelayDisplayContent(boolean delayPlaying){ public void setDelayDisplayContent(boolean delayPlaying) {
} }
public void setPosition(int align){ public void setPosition(int align) {
} }
public void setDisplay(boolean showWindow){ public void setDisplay(boolean showWindow) {
} }
public void setBackground(Background background){ public void setBackground(Background background) {
} }
/** /**
* 布局是否可编辑不可则显示编辑蒙层 * 布局是否可编辑不可则显示编辑蒙层
*
* @return 可否编辑 * @return 可否编辑
*/ */
public boolean isEditable(){ public boolean isEditable() {
return this.editable; return this.editable;
} }
/** /**
* 设置布局是否可编辑不可则显示编辑蒙层 * 设置布局是否可编辑不可则显示编辑蒙层
*
* @param isEditable 可否编辑 * @param isEditable 可否编辑
*/ */
public void setEditable(boolean isEditable){ public void setEditable(boolean isEditable) {
this.editable = isEditable; this.editable = isEditable;
} }
} }

338
designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java

@ -1,5 +1,5 @@
/** /**
* *
*/ */
package com.fr.design.designer.creator.cardlayout; package com.fr.design.designer.creator.cardlayout;
@ -25,114 +25,109 @@ import com.fr.form.ui.container.cardlayout.WCardTagLayout;
import com.fr.form.ui.container.cardlayout.WTabFitLayout; import com.fr.form.ui.container.cardlayout.WTabFitLayout;
/** /**
*
*
* @date: 2014-11-25-下午3:11:14 * @date: 2014-11-25-下午3:11:14
*/ */
public class XWCardTagLayout extends XWHorizontalBoxLayout { public class XWCardTagLayout extends XWHorizontalBoxLayout {
private static final int MIN_SIZE = 1; private static final int MIN_SIZE = 1;
private String tagName = "Tab"; private String tagName = "Tab";
private boolean switchingTab = false; private boolean switchingTab = false;
//增加一个tabNameIndex防止tabFitLayout重名 //增加一个tabNameIndex防止tabFitLayout重名
private int tabFitIndex = 0; private int tabFitIndex = 0;
private CardSwitchButton currentCard; private CardSwitchButton currentCard;
public CardSwitchButton getCurrentCard() { public CardSwitchButton getCurrentCard() {
return currentCard; return currentCard;
} }
public void setCurrentCard(CardSwitchButton currentCard) { public void setCurrentCard(CardSwitchButton currentCard) {
this.currentCard = currentCard; this.currentCard = currentCard;
} }
public int getTabFitIndex() { public int getTabFitIndex() {
return tabFitIndex; return tabFitIndex;
} }
public void setTabFitIndex(int tabFitIndex) { public void setTabFitIndex(int tabFitIndex) {
this.tabFitIndex = tabFitIndex; this.tabFitIndex = tabFitIndex;
} }
public String getTagName() { public String getTagName() {
return tagName; return tagName;
} }
public void setTagName(String tagName) { public void setTagName(String tagName) {
this.tagName = tagName; this.tagName = tagName;
} }
public boolean isSwitchingTab() { public boolean isSwitchingTab() {
return switchingTab; return switchingTab;
} }
public void setSwitchingTab(boolean switchingTab) { public void setSwitchingTab(boolean switchingTab) {
this.switchingTab = switchingTab; this.switchingTab = switchingTab;
} }
private XWCardLayout cardLayout; private XWCardLayout cardLayout;
public XWCardTagLayout(WCardTagLayout widget, Dimension initSize){ public XWCardTagLayout(WCardTagLayout widget, Dimension initSize) {
super(widget, initSize); super(widget, initSize);
} }
/** /**
* 构造函数 * 构造函数
*/ */
public XWCardTagLayout(WCardTagLayout widget, Dimension initSize, XWCardLayout cardLayout) { public XWCardTagLayout(WCardTagLayout widget, Dimension initSize, XWCardLayout cardLayout) {
super(widget, initSize); super(widget, initSize);
this.cardLayout = cardLayout; this.cardLayout = cardLayout;
} }
/** /**
* 添加组件的监听事件 * 添加组件的监听事件
* *
* @param e 事件 * @param e 事件
* * @date 2014-11-25-下午6:20:10
* */
* @date 2014-11-25-下午6:20:10 public void componentAdded(ContainerEvent e) {
* super.componentAdded(e);
*/
public void componentAdded(ContainerEvent e) { if (isSwitchingTab()) {
super.componentAdded(e); return;
}
if (isSwitchingTab()){
return; if (this.cardLayout == null) {
} initCardLayout();
}
if(this.cardLayout == null){
initCardLayout(); int index = this.cardLayout.toData().getWidgetCount();
} //新加一个card
String widgetName = tagName + getTabNameIndex();
int index = this.cardLayout.toData().getWidgetCount(); WTabFitLayout fitLayout = new WTabFitLayout(widgetName, tabFitIndex, currentCard);
//新加一个card fitLayout.setTabNameIndex(getTabNameIndex());
String widgetName = tagName+getTabNameIndex(); XWTabFitLayout tabFitLayout = new XWTabFitLayout(fitLayout, new Dimension());
WTabFitLayout fitLayout = new WTabFitLayout(widgetName,tabFitIndex,currentCard); tabFitLayout.setBackupParent(cardLayout);
fitLayout.setTabNameIndex(getTabNameIndex()); cardLayout.add(tabFitLayout, widgetName);
XWTabFitLayout tabFitLayout = new XWTabFitLayout(fitLayout, new Dimension()); this.cardLayout.toData().setShowIndex(index);
tabFitLayout.setBackupParent(cardLayout); cardLayout.showCard();
cardLayout.add(tabFitLayout, widgetName); }
this.cardLayout.toData().setShowIndex(index);
cardLayout.showCard(); private void initCardLayout() {
} XWCardTitleLayout titleLayout = (XWCardTitleLayout) this.getBackupParent();
XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout) titleLayout.getBackupParent();
private void initCardLayout(){
XWCardTitleLayout titleLayout = (XWCardTitleLayout)this.getBackupParent(); this.cardLayout = borderLayout.getCardPart();
XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout)titleLayout.getBackupParent(); }
this.cardLayout = borderLayout.getCardPart();
}
/** /**
* 将WLayout转换为XLayoutContainer * 将WLayout转换为XLayoutContainer
*/ */
public void convert() { public void convert() {
isRefreshing = true; isRefreshing = true;
WCardTagLayout layout = (WCardTagLayout)this.toData(); WCardTagLayout layout = (WCardTagLayout) this.toData();
this.removeAll(); this.removeAll();
for (int i = 0; i < layout.getWidgetCount(); i++) { for (int i = 0; i < layout.getWidgetCount(); i++) {
Widget wgt = layout.getWidget(i); Widget wgt = layout.getWidget(i);
@ -144,82 +139,81 @@ public class XWCardTagLayout extends XWHorizontalBoxLayout {
} }
isRefreshing = false; isRefreshing = false;
} }
/** /**
* 切换到非添加状态 * 切换到非添加状态
* *
* @return designer 表单设计器 * @return designer 表单设计器
*/ */
public void stopAddingState(FormDesigner designer){ public void stopAddingState(FormDesigner designer) {
designer.stopAddingState(); designer.stopAddingState();
return;
} }
//新增时去tabFitLayout名字中最大的Index+1,防止重名 //新增时去tabFitLayout名字中最大的Index+1,防止重名
private int getTabNameIndex(){ private int getTabNameIndex() {
int tabNameIndex = 0; int tabNameIndex = 0;
WCardLayout layout = this.cardLayout.toData(); WCardLayout layout = this.cardLayout.toData();
int size = layout.getWidgetCount(); int size = layout.getWidgetCount();
if(size < MIN_SIZE){ if (size < MIN_SIZE) {
return tabNameIndex; return tabNameIndex;
} }
for(int i=0;i<size;i++){ for (int i = 0; i < size; i++) {
WTabFitLayout fitLayout = (WTabFitLayout) layout.getWidget(i); WTabFitLayout fitLayout = (WTabFitLayout) layout.getWidget(i);
int tempIndex = fitLayout.getTabNameIndex(); int tempIndex = fitLayout.getTabNameIndex();
tabNameIndex = Math.max(tempIndex, tabNameIndex); tabNameIndex = Math.max(tempIndex, tabNameIndex);
} }
return ++tabNameIndex; return ++tabNameIndex;
} }
/** /**
* 调整tab宽度 * 调整tab宽度
* * <p>
* void * void
*/ */
public void adjustComponentWidth(){ public void adjustComponentWidth() {
} }
/** /**
* 该布局需要隐藏无需对边框进行操作 * 该布局需要隐藏无需对边框进行操作
* @param 边框 *
* * @param
*/ */
public void setBorder(Border border) { public void setBorder(Border border) {
return;
} }
@Override @Override
/** /**
* 该布局隐藏点击该布局时选中相应的tab布局主体 * 该布局隐藏点击该布局时选中相应的tab布局主体
* @param editingMouseListener 监听 * @param editingMouseListener 监听
* @param e 鼠标点击事件 * @param e 鼠标点击事件
* *
*/ */
public void respondClick(EditingMouseListener editingMouseListener, public void respondClick(EditingMouseListener editingMouseListener,
MouseEvent e) { MouseEvent e) {
FormDesigner designer = editingMouseListener.getDesigner(); FormDesigner designer = editingMouseListener.getDesigner();
SelectionModel selectionModel = editingMouseListener.getSelectionModel(); SelectionModel selectionModel = editingMouseListener.getSelectionModel();
XWCardTitleLayout titleLayout = (XWCardTitleLayout) this.getBackupParent(); XWCardTitleLayout titleLayout = (XWCardTitleLayout) this.getBackupParent();
if(titleLayout != null){ if (titleLayout != null) {
XWCardMainBorderLayout mainLayout = (XWCardMainBorderLayout)titleLayout.getBackupParent(); XWCardMainBorderLayout mainLayout = (XWCardMainBorderLayout) titleLayout.getBackupParent();
if(mainLayout != null){ if (mainLayout != null) {
XWCardLayout cardLayout = mainLayout.getCardPart(); XWCardLayout cardLayout = mainLayout.getCardPart();
selectionModel.setSelectedCreator(cardLayout); selectionModel.setSelectedCreator(cardLayout);
} }
} }
if (editingMouseListener.stopEditing()) { if (editingMouseListener.stopEditing()) {
if (this != designer.getRootComponent()) { if (this != designer.getRootComponent()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this); ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter); editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter);
} }
} }
} }
@Override @Override
public XLayoutContainer getTopLayout() { public XLayoutContainer getTopLayout() {
return this.getBackupParent().getTopLayout(); return this.getBackupParent().getTopLayout();
} }
} }

17
designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java

@ -43,7 +43,7 @@ public class FormCreatorDropTarget extends DropTarget {
* 当前添加模式对应的model * 当前添加模式对应的model
*/ */
private AddingModel addingModel; private AddingModel addingModel;
private final static int GAP = 30; private static final int GAP = 30;
private JWindow promptWindow = new JWindow(); private JWindow promptWindow = new JWindow();
private UIButton promptButton = new UIButton("", BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); private UIButton promptButton = new UIButton("", BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH));
@ -59,10 +59,11 @@ public class FormCreatorDropTarget extends DropTarget {
XCreator hoveredComponent = designer.getComponentAt(x, y); XCreator hoveredComponent = designer.getComponentAt(x, y);
// 获取该组件所在的焦点容器 // 获取该组件所在的焦点容器
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent);
//cardTagLayout里用到
container.stopAddingState(designer);
boolean success = false; boolean success = false;
if (container != null) { if (container != null) {
//XWCardTagLayout 切换添加状态到普通状态
container.stopAddingState(designer);
// 如果是容器,则调用其acceptComponent接受组件 // 如果是容器,则调用其acceptComponent接受组件
AddingModel model = designer.getAddingModel(); AddingModel model = designer.getAddingModel();
@ -129,9 +130,7 @@ public class FormCreatorDropTarget extends DropTarget {
//提示组件是否可以拖入 //提示组件是否可以拖入
promptUser(x, y, container); promptUser(x, y, container);
if (container != null) { if (container != null) {
dealWithContainer(x, y, container); dealWithContainer(x, y, container);
} else { } else {
// 如果鼠标不在任何组件上,则取消提示器 // 如果鼠标不在任何组件上,则取消提示器
designer.setPainter(null); designer.setPainter(null);
@ -197,11 +196,9 @@ public class FormCreatorDropTarget extends DropTarget {
private void promptWidgetForbidEnter(int x, int y, XLayoutContainer container) { private void promptWidgetForbidEnter(int x, int y, XLayoutContainer container) {
container.setBorder(BorderFactory.createLineBorder(Color.RED, Constants.LINE_MEDIUM)); container.setBorder(BorderFactory.createLineBorder(Color.RED, Constants.LINE_MEDIUM));
int screen_X = (int) designer.getArea().getLocationOnScreen().getX(); int screenX = designer.getArea().getLocationOnScreen().x;
int screen_Y = (int) designer.getArea().getLocationOnScreen().getY(); int screenY = designer.getArea().getLocationOnScreen().y;
this.promptWindow.setSize(promptWindow.getPreferredSize()); promptWindow.setLocation(screenX + x + GAP, screenY + y + GAP);
this.promptWindow.setPreferredSize(promptWindow.getPreferredSize());
promptWindow.setLocation(screen_X + x + GAP, screen_Y + y + GAP);
promptWindow.setVisible(true); promptWindow.setVisible(true);
} }

6
designer_form/src/com/fr/design/mainframe/FormDesigner.java

@ -612,6 +612,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
return true; return true;
} }
public void showMessageDialog(String message) {
JOptionPane.showMessageDialog(this, message, Inter.getLocText("FR-Designer_Alert"), JOptionPane.WARNING_MESSAGE);
FormSelectionUtils.rebuildSelection(this);
repaint();
}
/** /**
* 保存参数界面的宽度 * 保存参数界面的宽度
* *

12
designer_form/src/com/fr/design/mainframe/FormSelection.java

@ -8,12 +8,7 @@ import com.fr.base.FRContext;
import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.location.Direction; import com.fr.design.designer.beans.location.Direction;
import com.fr.design.designer.creator.XComponent; import com.fr.design.designer.creator.*;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
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;
@ -273,6 +268,11 @@ public class FormSelection {
if (parent == null) { if (parent == null) {
return; return;
} }
boolean changeCreator = creator.shouldScaleCreator() || creator.hasTitleStyle();
if (parent.acceptType(XWFitLayout.class) && changeCreator) {
creator = (XCreator) creator.getParent();
}
parent.getLayoutAdapter().removeBean(creator, creator.getWidth(), creator.getHeight());
// 删除其根组件,同时就删除了同时被选择的叶子组件 // 删除其根组件,同时就删除了同时被选择的叶子组件
parent.remove(creator); parent.remove(creator);
LayoutManager layout = parent.getLayout(); LayoutManager layout = parent.getLayout();

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

@ -8,6 +8,7 @@ import com.fr.design.designer.creator.*;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WTitleLayout; import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -17,11 +18,7 @@ import java.util.List;
public class FormSelectionUtils { public class FormSelectionUtils {
//组件复制时坐标偏移 //组件复制时坐标偏移
private static final int DELAY_X = 20; private static final int DELAY_X_Y = 20;
private static final int DELAY_Y = 20;
//组件复制时是否已经向左上偏移
private static boolean backoffset = false;
//组件重命名后缀 //组件重命名后缀
private static final String POSTFIX = "_c"; private static final String POSTFIX = "_c";
@ -31,11 +28,7 @@ public class FormSelectionUtils {
} }
/** /**
* @param designer 编辑器 * 粘贴到容器
* @param parent 粘贴依据的组件
* @param clipboard 剪贴板内容
* @param x x
* @param y y
*/ */
public static void paste2Container(FormDesigner designer, XLayoutContainer parent, public static void paste2Container(FormDesigner designer, XLayoutContainer parent,
FormSelection clipboard, int x, int y) { FormSelection clipboard, int x, int y) {
@ -54,12 +47,6 @@ public class FormSelectionUtils {
/** /**
* 绝对布局粘贴 * 绝对布局粘贴
*
* @param designer
* @param clipboard
* @param adapter
* @param x
* @param y
*/ */
private static void absolutePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { private static void absolutePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) {
@ -74,6 +61,10 @@ public class FormSelectionUtils {
copiedCreator, copiedCreator,
x + creator.getX() - rec.x + copiedCreator.getWidth() / 2, x + creator.getX() - rec.x + copiedCreator.getWidth() / 2,
y + creator.getY() - rec.y + copiedCreator.getHeight() / 2); y + creator.getY() - rec.y + copiedCreator.getHeight() / 2);
if (!adapter.accept(copiedCreator, point.x, point.y)) {
designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Large_To_Paste"));
return;
}
boolean addSuccess = adapter.addBean(copiedCreator, point.x, point.y); boolean addSuccess = adapter.addBean(copiedCreator, point.x, point.y);
if (addSuccess) { if (addSuccess) {
designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator);
@ -90,12 +81,6 @@ public class FormSelectionUtils {
/** /**
* 相对布局粘贴 * 相对布局粘贴
*
* @param designer
* @param clipboard
* @param adapter
* @param x
* @param y
*/ */
private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) {
designer.getSelectionModel().getSelection().reset(); designer.getSelectionModel().getSelection().reset();
@ -103,6 +88,10 @@ public class FormSelectionUtils {
try { try {
Widget copied = copyWidget(designer, creator); Widget copied = copyWidget(designer, creator);
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize());
if (!adapter.accept(copiedCreator, x, y)) {
designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste"));
return;
}
boolean addSuccess = adapter.addBean(copiedCreator, x, y); boolean addSuccess = adapter.addBean(copiedCreator, x, y);
if (addSuccess) { if (addSuccess) {
designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator);
@ -118,14 +107,6 @@ public class FormSelectionUtils {
/** /**
* 组件复用绝对布局获取粘贴组件位置 * 组件复用绝对布局获取粘贴组件位置
*
* @param layoutAdapter 绝对布局容器AbstractLayoutAdapter
* @param copiedCreator 复制的组件
* @param x x=组件x + clonedCreator.getWidth() / 2
* @param y y=组件y + clonedCreator.getHeight() / 2
* 除2的步骤会导致当宽度或者高度为奇数是中心点向左上各偏移一个像素
* 由于中心点向左上各偏移一个像素依赖中心点计算的右下点就会相应的想做上偏移一个像素导致结果不准确
* @return 新位置坐标
*/ */
private static Point getPasteLocation(AbstractLayoutAdapter layoutAdapter, XCreator copiedCreator, int x, int y) { private static Point getPasteLocation(AbstractLayoutAdapter layoutAdapter, XCreator copiedCreator, int x, int y) {
//当宽度为奇数时 设置偏移 //当宽度为奇数时 设置偏移
@ -144,12 +125,10 @@ public class FormSelectionUtils {
* x,y同时越界 * x,y同时越界
*/ */
if (xOut && yOut) { if (xOut && yOut) {
x = backoffset ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset //向左偏移
: container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X - xoffset; x = container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X_Y - xoffset;
y = backoffset ? //紧贴下边界
container.getHeight() - copiedCreator.getHeight() / 2 - yoffset y = container.getHeight() - copiedCreator.getHeight() / 2 - yoffset;
: container.getHeight() - copiedCreator.getHeight() / 2 - DELAY_Y - yoffset;
backoffset = !backoffset;
return new Point(x, y); return new Point(x, y);
} }
/* /*
@ -158,7 +137,7 @@ public class FormSelectionUtils {
* 距离大于20像素的一侧正常错开 * 距离大于20像素的一侧正常错开
* x,y中只有一个越界 * x,y中只有一个越界
*/ */
else if ((xOut || yOut)) { if ((xOut || yOut)) {
x = xOut ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset : x; x = xOut ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset : x;
y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y; y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y;
return new Point(x, y); return new Point(x, y);
@ -170,15 +149,10 @@ public class FormSelectionUtils {
/** /**
* 拷贝组件 * 拷贝组件
*
* @param formDesigner
* @param xCreator
* @return
* @throws CloneNotSupportedException
*/ */
private static Widget copyWidget(FormDesigner formDesigner, XCreator xCreator) throws private static Widget copyWidget(FormDesigner formDesigner, XCreator xCreator) throws
CloneNotSupportedException { CloneNotSupportedException {
ArrayList<String> nameSpace = new ArrayList<String>(); ArrayList<String> nameSpace = new ArrayList<>();
Widget copied = (Widget) xCreator.toData().clone(); Widget copied = (Widget) xCreator.toData().clone();
//重命名拷贝的组件 //重命名拷贝的组件
String name = getCopiedName(formDesigner, copied, nameSpace); String name = getCopiedName(formDesigner, copied, nameSpace);
@ -193,14 +167,9 @@ public class FormSelectionUtils {
/** /**
* 组件拷贝命名规则 * 组件拷贝命名规则
*
* @param formDesigner
* @param copied
* @param nameSpace
* @return name
*/ */
private static String getCopiedName(FormDesigner formDesigner, Widget copied, ArrayList<String> nameSpace) { private static String getCopiedName(FormDesigner formDesigner, Widget copied, ArrayList<String> nameSpace) {
StringBuffer name = new StringBuffer(copied.getWidgetName()); StringBuilder name = new StringBuilder(copied.getWidgetName());
do { do {
name.append(POSTFIX); name.append(POSTFIX);
} while (formDesigner.getTarget().isNameExist(name.toString()) || nameSpace.contains(name.toString())); } while (formDesigner.getTarget().isNameExist(name.toString()) || nameSpace.contains(name.toString()));
@ -209,8 +178,8 @@ public class FormSelectionUtils {
} }
public static void rebuildSelection(FormDesigner designer) { public static void rebuildSelection(FormDesigner designer) {
ArrayList<XCreator> newSelection = new ArrayList<XCreator>(); ArrayList<XCreator> newSelection = new ArrayList<>();
List<Widget> widgetList = new ArrayList<Widget>(); List<Widget> widgetList = new ArrayList<>();
for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) { for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) {
widgetList.add(comp.toData()); widgetList.add(comp.toData());
} }
@ -219,11 +188,11 @@ public class FormSelectionUtils {
} }
public static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { public static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) {
List<Widget> selectionWidget = new ArrayList<Widget>(); List<Widget> selectionWidget = new ArrayList<>();
if (selectWidgets != null) { if (selectWidgets != null) {
selectionWidget.addAll(Arrays.asList(selectWidgets)); selectionWidget.addAll(Arrays.asList(selectWidgets));
} }
return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList<XCreator>()); return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList<>());
} }
private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget, private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget,

Loading…
Cancel
Save