Browse Source

Merge branch 'release/10.0' of ssh://cloud.finedevelop.com:7999/~lanlan/design into release/10.0

feature/big-screen
Lanlan 5 years ago
parent
commit
fcae4b8f82
  1. 86
      designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java
  2. 57
      designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java

86
designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java

@ -1,47 +1,50 @@
package com.fr.design.designer.beans.models;
import java.awt.Rectangle;
import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.XWTitleLayout;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.utils.ComponentUtils;
import com.fr.form.main.Form;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.ComparatorUtils;
import java.awt.Rectangle;
import java.util.HashSet;
import java.util.Set;
/**
* 添加状态下的model
*/
public class AddingModel {
// 当前要添加的组件
private XCreator creator;
// 记录当前鼠标的位置信息
private int currentX;
private int currentY;
private boolean added;
public AddingModel(FormDesigner designer, XCreator xCreator) {
String creatorName = getXCreatorName(designer, xCreator);
this.creator = xCreator;
instantiateCreator(designer, creatorName);
instantiateCreator(designer);
// 初始的时候隐藏该组件的图标
currentY = -this.creator.getWidth();
currentX = -this.creator.getHeight();
}
/**
* 待说明
* 初始化创建器
*
* @param designer 设计器
* @param creatorName 组件名
* @param designer 设计器
*/
public void instantiateCreator(FormDesigner designer, String creatorName) {
creator.toData().setWidgetName(creatorName);
public void instantiateCreator(FormDesigner designer) {
renameWidgetName(designer.getTarget(), creator);
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator);
adapter.initialize();
creator.addNotify();
@ -56,7 +59,7 @@ public class AddingModel {
currentX = x - (xCreator.getWidth() / 2);
currentY = y - (xCreator.getHeight() / 2);
}
/**
* 隐藏当前组件的图标
*/
@ -64,28 +67,65 @@ public class AddingModel {
currentX = -this.creator.getWidth();
currentY = -this.creator.getHeight();
}
public String getXCreatorName(FormDesigner designer, XCreator x) {
/**
* 防止冲突重命名 XCreator 内部的 widget
*
* @param form 表单
* @param xCreator 创建器
*/
private static void renameWidgetName(Form form, XCreator xCreator) {
Set<String> nameSpace = new HashSet<>();
recursiveRenameWidgetName(form, xCreator, nameSpace);
}
private static void recursiveRenameWidgetName(Form form, XCreator xCreator, Set<String> nameSpace) {
String creatorName = uniqueName(form, xCreator, nameSpace);
if (xCreator.toData() instanceof WTitleLayout) {
XWTitleLayout xwTitleLayout = new XWTitleLayout((WTitleLayout) xCreator.toData(), xCreator.getSize());
xwTitleLayout.resetCreatorName(creatorName);
return;
}
xCreator.resetCreatorName(creatorName);
int count = xCreator.getComponentCount();
for (int a = 0; a < count; a++) {
if (xCreator.getComponent(a) instanceof XCreator) {
XCreator child = (XCreator) xCreator.getComponent(a);
recursiveRenameWidgetName(form, child, nameSpace);
}
}
}
/**
* 组件命名规则
*/
public static String uniqueName(Form form, XCreator x, Set<String> nameSpace) {
String def = x.createDefaultName();
if (x.acceptType(XWParameterLayout.class)) {
return def;
}
int i = 0;
while (designer.getTarget().isNameExist(def + i)) {
String name = def + i;
while (form.isNameExist(name) || nameSpace.contains(name)) {
i++;
name = def + i;
}
return def + i;
return name;
}
public int getCurrentX() {
return currentX;
}
public int getCurrentY() {
return currentY;
}
/**
* 移动组件图标到鼠标事件发生的位置
*

57
designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java

@ -0,0 +1,57 @@
package com.fr.design.designer.beans.models;
import com.fr.design.designer.creator.CRPropertyDescriptor;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.mainframe.FormDesigner;
import com.fr.form.main.Form;
import com.fr.form.ui.ChartEditor;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import javax.swing.JComponent;
import java.awt.Dimension;
import java.beans.IntrospectionException;
public class AddingModelTest {
@Test
public void testInstantiateCreator() throws Exception {
ChartEditor chartEditor = new ChartEditor();
chartEditor.setWidgetName("test01");
XCreator xCreator = new XCreator(chartEditor, new Dimension(20, 20)) {
@Override
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
return new CRPropertyDescriptor[0];
}
@Override
protected JComponent initEditor() {
return null;
}
@Override
protected void initXCreatorProperties() {
}
@Override
public String createDefaultName() {
return "test";
}
};
AddingModel addingModel = new AddingModel(xCreator, 20, 20);
Form form = EasyMock.mock(Form.class);
EasyMock.expect(form.isNameExist("test0")).andReturn(true).once();
EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes();
EasyMock.replay(form);
FormDesigner mock = EasyMock.mock(FormDesigner.class);
EasyMock.expect(mock.getTarget()).andReturn(form).anyTimes();
EasyMock.replay(mock);
addingModel.instantiateCreator(mock);
Assert.assertEquals("test1", xCreator.toData().getWidgetName());
}
}
Loading…
Cancel
Save