Browse Source

REPORT-32149【组件加密】@harrison两个组件进行拖入,模板预览很奇怪

将逻辑分散到各个组件中。
减少同一个方法中的耦合
feature/big-screen
Harrison 5 years ago
parent
commit
628727d69e
  1. 27
      designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtil.java
  2. 9
      designer-form/src/main/java/com/fr/design/designer/creator/DedicateLayoutContainer.java
  3. 22
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  4. 17
      designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java
  5. 5
      designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java

27
designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtil.java

@ -22,29 +22,12 @@ abstract class ModelUtil {
private static void recursiveRenameWidgetName(Form form, XCreator xCreator, Set<String> duplicated) {
//有可能并不需要对自己处理,而是对其他的组件处理。所以要找到目标值
XCreator target = xCreator.getXCreator();
String uniqueName = uniqueName(form, target, duplicated);
int componentCount = target.getComponentCount();
//如果没有子类,说明是刚创建的,直接对自己处理就好啦
if (componentCount == 0) {
target.toData().setWidgetName(uniqueName);
return;
}
//专属容器,直接返回啦
if (target.isDedicateContainer()) {
Set<XCreator> nameRelatedCreators = new HashSet<>();
//直接遍历出来目标值,然后按需处理
xCreator.traversalNameRelatedXCreators(nameRelatedCreators);
for (XCreator target : nameRelatedCreators) {
String uniqueName = uniqueName(form, target, duplicated);
target.resetCreatorName(uniqueName);
return;
}
target.resetCreatorName(uniqueName);
int count = target.getComponentCount();
for (int a = 0; a < count; a++) {
if (target.getComponent(a) instanceof XCreator) {
XCreator child = (XCreator) target.getComponent(a);
recursiveRenameWidgetName(form, child, duplicated);
}
}
}

9
designer-form/src/main/java/com/fr/design/designer/creator/DedicateLayoutContainer.java

@ -9,6 +9,7 @@ import java.awt.Component;
import java.awt.Dimension;
import java.beans.IntrospectionException;
import java.util.List;
import java.util.Set;
/**
* 一些控件专属的容器如标题容器sclae容器
@ -70,12 +71,18 @@ public abstract class DedicateLayoutContainer extends XLayoutContainer {
child.toData().setWidgetName(name);
}
@Override
public void traversalNameRelatedXCreators(Set<XCreator> xCreators) {
xCreators.add(this);
}
/**
* 重置组件的可见性
*
* @param visible 可见性
*/
@Override
public void resetVisible(boolean visible){
public void resetVisible(boolean visible) {
super.resetVisible(visible);
XCreator child = getXCreator(XWScaleLayout.INDEX);
child.toData().setVisible(visible);

22
designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java

@ -41,6 +41,7 @@ import java.awt.event.MouseEvent;
import java.beans.IntrospectionException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* @author richer
@ -410,6 +411,7 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
/**
* 重置组件的名称
*
* @param name 名称
*/
@Override
@ -417,11 +419,29 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
toData().setWidgetName(name);
}
/**
* 遍历所有命名相关的组件到集合中
*
* @param xCreators 集合
*/
public void traversalNameRelatedXCreators(Set<XCreator> xCreators) {
xCreators.add(this);
int componentCount = getComponentCount();
for (int i = 0; i < componentCount; i++) {
XCreator xCreator = (XCreator) getComponent(i);
//获取真实的 creator
XCreator realCreator = xCreator.getXCreator();
realCreator.traversalNameRelatedXCreators(xCreators);
}
}
/**
* 重置组件的可见性
*
* @param visible 可见性
*/
public void resetVisible(boolean visible){
public void resetVisible(boolean visible) {
toData().setVisible(visible);
}

17
designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java

@ -433,13 +433,16 @@ public class XWCardLayout extends XLayoutContainer {
//修改相关SwitchButton所绑定的cardLayout控件名
private void changeRelateSwitchCardName(String cardLayoutName) {
XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout) this.getBackupParent();
WCardMainBorderLayout border = borderLayout.toData();
WCardTitleLayout titleLayout = border.getTitlePart();
titleLayout.setCardName(cardLayoutName);
WCardTagLayout tagLayout = titleLayout.getTagPart();
for (int i = 0, len = tagLayout.getWidgetCount(); i < len; i++) {
CardSwitchButton button = tagLayout.getSwitchButton(i);
button.setCardLayoutName(cardLayoutName);
//可能为空
if (borderLayout != null) {
WCardMainBorderLayout border = borderLayout.toData();
WCardTitleLayout titleLayout = border.getTitlePart();
titleLayout.setCardName(cardLayoutName);
WCardTagLayout tagLayout = titleLayout.getTagPart();
for (int i = 0, len = tagLayout.getWidgetCount(); i < len; i++) {
CardSwitchButton button = tagLayout.getSwitchButton(i);
button.setCardLayoutName(cardLayoutName);
}
}
}

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

@ -92,6 +92,7 @@ public class AddingModelTest {
Form form = EasyMock.mock(Form.class);
EasyMock.expect(form.isNameExist("cardlayout")).andReturn(true).once();
EasyMock.expect(form.isNameExist("cardlayout0")).andReturn(true).once();
EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes();
EasyMock.replay(form);
@ -100,12 +101,12 @@ public class AddingModelTest {
EasyMock.replay(mock);
WCardLayout wCardLayout = new WCardLayout(20, 20);
XWCardLayout xwCardLayout = new XWCardLayout(wCardLayout, new Dimension(20, 20));
XWCardLayout xwCardLayout = new XWCardLayout(wCardLayout, new Dimension(40, 40));
AddingModel addingModel = new AddingModel(mock, xwCardLayout);
Assert.assertEquals("cardlayout1", xwCardLayout.toData().getWidgetName());
//依赖于 cardlayout 创建 container
XLayoutContainer parentLayOut = xwCardLayout.initCreatorWrapper(20);
XLayoutContainer parentLayOut = xwCardLayout.initCreatorWrapper(80);
AddingModel parentModel = new AddingModel(mock, parentLayOut);
Assert.assertEquals("tablayout1", parentLayOut.toData().getWidgetName());
Assert.assertEquals("tabpane1", ((XCreator) (parentLayOut.getComponent(0))).getXCreator().toData().getWidgetName());

Loading…
Cancel
Save