Browse Source

REPORT-35016【组件生成】目前生成的组件,从组件库拖入模板中会变大

[场景]
从组件库拖入时,不会保持原有的大小。
[解决方案]
将原来的大小,在创建时一并初始化
feature/big-screen
Harrison 4 years ago
parent
commit
87e818f272
  1. 53
      designer-form/src/main/java/com/fr/design/mainframe/ShareWidgetButton.java
  2. 38
      designer-form/src/test/java/com/fr/design/mainframe/ShareWidgetButtonTest.java

53
designer-form/src/main/java/com/fr/design/mainframe/ShareWidgetButton.java

@ -14,6 +14,7 @@ import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.share.ShareConstants;
import com.fr.stable.StringUtils;
import org.jetbrains.annotations.NotNull;
import javax.swing.Icon;
import javax.swing.ImageIcon;
@ -52,12 +53,12 @@ import java.io.Serializable;
*/
public class ShareWidgetButton extends JPanel implements MouseListener, MouseMotionListener, Serializable {
private static final Dimension TAB_DEFAULT_SIZE = new Dimension(500, 300);
private SharableWidgetProvider bindInfo;
private MouseEvent lastPressEvent;
private JPanel reportPane;
private boolean isEdit;
private boolean isMarked;
protected SharableWidgetProvider bindInfo;
protected MouseEvent lastPressEvent;
protected JPanel reportPane;
protected boolean isEdit;
protected boolean isMarked;
private ShareWidgetUI ui;
private Icon markedMode = IOUtils.readIcon("/com/fr/design/form/images/marked.png");
private Icon unMarkedMode = IOUtils.readIcon("/com/fr/design/form/images/unmarked.png");
private AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 60 / 100.0F);
@ -72,8 +73,10 @@ public class ShareWidgetButton extends JPanel implements MouseListener, MouseMot
}
};
public ShareWidgetButton(SharableWidgetProvider bindInfo) {
public ShareWidgetButton(SharableWidgetProvider bindInfo, ShareWidgetUI ui) {
this.bindInfo = bindInfo;
this.ui = ui;
this.setPreferredSize(new Dimension(108, 68));
initUI();
this.setLayout(getCoverLayout());
@ -82,6 +85,11 @@ public class ShareWidgetButton extends JPanel implements MouseListener, MouseMot
new DragAndDropDragGestureListener(this, DnDConstants.ACTION_COPY_OR_MOVE);
}
public ShareWidgetButton(SharableWidgetProvider bindInfo) {
this(bindInfo, new ShareWidgetUI());
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite();
@ -219,14 +227,7 @@ public class ShareWidgetButton extends JPanel implements MouseListener, MouseMot
if (creatorSource != null) {
((AbstractBorderStyleWidget)creatorSource).addWidgetAttrMark(new SharableAttrMark(true));
//tab布局WCardMainBorderLayout通过反射出来的大小是960*480
XCreator xCreator = null;
if (creatorSource instanceof WCardMainBorderLayout) {
xCreator = XCreatorUtils.createXCreator(creatorSource, TAB_DEFAULT_SIZE);
} else {
xCreator = XCreatorUtils.createXCreator(creatorSource);
}
xCreator.setBackupBound(new Rectangle(no.getBindInfo().getWidth(), no.getBindInfo().getHeight()));
xCreator.setShareId(shareId);
XCreator xCreator = ui.createXCreator(creatorSource, shareId, no.getBindInfo());
WidgetToolBarPane.getTarget().startDraggingBean(xCreator);
lastPressEvent = null;
this.setBorder(null);
@ -288,4 +289,26 @@ public class ShareWidgetButton extends JPanel implements MouseListener, MouseMot
return widget;
}
}
/**
* 抽出来专门为了创建 ui 来搞
*/
public static class ShareWidgetUI {
private static final Dimension TAB_DEFAULT_SIZE = new Dimension(500, 300);
@NotNull
public XCreator createXCreator(Widget creatorSource, String shareId, SharableWidgetProvider provider) {
XCreator xCreator = null;
if (creatorSource instanceof WCardMainBorderLayout) {
xCreator = XCreatorUtils.createXCreator(creatorSource, TAB_DEFAULT_SIZE);
} else {
xCreator = XCreatorUtils.createXCreator(creatorSource, new Dimension(provider.getWidth(), provider.getHeight()));
}
xCreator.setBackupBound(new Rectangle(provider.getWidth(), provider.getHeight()));
xCreator.setShareId(shareId);
return xCreator;
}
}
}

38
designer-form/src/test/java/com/fr/design/mainframe/ShareWidgetButtonTest.java

@ -0,0 +1,38 @@
package com.fr.design.mainframe;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.design.designer.creator.XCreator;
import com.fr.form.share.SharableWidgetProvider;
import com.fr.form.ui.ChartEditor;
import com.fr.general.ImageWithSuffix;
import com.fr.invoke.Reflect;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"com.fr.jvm.assist.*", "javax.swing.*"})
public class ShareWidgetButtonTest {
@Test
public void testCreateXCreator() throws Exception {
SharableWidgetProvider provider = EasyMock.mock(SharableWidgetProvider.class);
EasyMock.expect(provider.getWidth()).andReturn(300).anyTimes();
EasyMock.expect(provider.getHeight()).andReturn(400).anyTimes();
EasyMock.expect(provider.getName()).andReturn("test-drag").anyTimes();
EasyMock.expect(provider.getCover()).andReturn(new ImageWithSuffix("utf-8")).anyTimes();
EasyMock.replay(provider);
ShareWidgetButton.ShareWidgetUI ui = new ShareWidgetButton.ShareWidgetUI();
ChartEditor editor = new ChartEditor();
Reflect.on(editor).set("chartCollection", new ChartCollection());
XCreator xCreator = ui.createXCreator(editor, "333", provider);
Assert.assertEquals(300, xCreator.getWidth());
Assert.assertEquals(400, xCreator.getHeight());
}
}
Loading…
Cancel
Save