Browse Source

沿用之前的命名规则。

只进行 n 对 n 的匹配。
feature/big-screen
Harrison 4 years ago
parent
commit
c5b4410d9a
  1. 41
      designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java
  2. 23
      designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java

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

@ -6,11 +6,11 @@ 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.Widget;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.ComparatorUtils;
@ -23,8 +23,6 @@ import java.util.Set;
*/
public class AddingModel {
private static final String POSTFIX = "_a";
// 当前要添加的组件
private XCreator creator;
// 记录当前鼠标的位置信息
@ -77,41 +75,46 @@ public class AddingModel {
* @param xCreator 创建器
*/
private static void renameWidgetName(Form form, XCreator xCreator) {
Set<String> nameSpace = new HashSet<>(8);
recursiveRenameWidgetName(form, nameSpace, xCreator);
Set<String> nameSpace = new HashSet<>();
recursiveRenameWidgetName(form, xCreator, nameSpace);
}
private static void recursiveRenameWidgetName(Form form, Set<String> nameSpace, XCreator xCreator) {
private static void recursiveRenameWidgetName(Form form, XCreator xCreator, Set<String> nameSpace) {
String copyName = getAddWidgetName(form, xCreator.toData(), nameSpace);
String creatorName = uniqueName(form, xCreator, nameSpace);
if (xCreator.toData() instanceof WTitleLayout) {
XWTitleLayout xwTitleLayout = new XWTitleLayout((WTitleLayout) xCreator.toData(), xCreator.getSize());
xwTitleLayout.resetCreatorName(copyName);
xwTitleLayout.resetCreatorName(creatorName);
return;
}
xCreator.resetCreatorName(copyName);
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, nameSpace, child);
recursiveRenameWidgetName(form, child, nameSpace);
}
}
}
/**
* 组件拷贝命名规则
* 组件命名规则
*/
private static String getAddWidgetName(Form form, Widget added, Set<String> nameSpace) {
public static String uniqueName(Form form, XCreator x, Set<String> nameSpace) {
StringBuilder name = new StringBuilder(added.getWidgetName());
do {
name.append(POSTFIX);
} while (form.isNameExist(name.toString()) || nameSpace.contains(name.toString()));
nameSpace.add(name.toString());
return name.toString();
String def = x.createDefaultName();
if (x.acceptType(XWParameterLayout.class)) {
return def;
}
int i = 0;
String name = def + i;
while (form.isNameExist(name) || nameSpace.contains(name)) {
i++;
name = def + i;
}
return name;
}
public int getCurrentX() {

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

@ -17,36 +17,41 @@ public class AddingModelTest {
@Test
public void testInstantiateCreator() throws Exception {
ChartEditor chartEditor = new ChartEditor();
chartEditor.setWidgetName("test");
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("test_a")).andReturn(true).once();
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("test_a_a", xCreator.toData().getWidgetName());
Assert.assertEquals("test1", xCreator.toData().getWidgetName());
}
}
Loading…
Cancel
Save