From 87e818f2721dfa1869bfa07ac03b083a684ae78c Mon Sep 17 00:00:00 2001 From: Harrison Date: Wed, 8 Jul 2020 14:42:02 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-35016=E3=80=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=94=9F=E6=88=90=E3=80=91=E7=9B=AE=E5=89=8D=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9A=84=E7=BB=84=E4=BB=B6=EF=BC=8C=E4=BB=8E=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=BA=93=E6=8B=96=E5=85=A5=E6=A8=A1=E6=9D=BF=E4=B8=AD=E4=BC=9A?= =?UTF-8?q?=E5=8F=98=E5=A4=A7=20[=E5=9C=BA=E6=99=AF]=20=E4=BB=8E=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=BA=93=E6=8B=96=E5=85=A5=E6=97=B6=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E4=BF=9D=E6=8C=81=E5=8E=9F=E6=9C=89=E7=9A=84=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E3=80=82=20[=E8=A7=A3=E5=86=B3=E6=96=B9=E6=A1=88]=20?= =?UTF-8?q?=E5=B0=86=E5=8E=9F=E6=9D=A5=E7=9A=84=E5=A4=A7=E5=B0=8F=EF=BC=8C?= =?UTF-8?q?=E5=9C=A8=E5=88=9B=E5=BB=BA=E6=97=B6=E4=B8=80=E5=B9=B6=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/mainframe/ShareWidgetButton.java | 61 +++++++++++++------ .../mainframe/ShareWidgetButtonTest.java | 38 ++++++++++++ 2 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 designer-form/src/test/java/com/fr/design/mainframe/ShareWidgetButtonTest.java diff --git a/designer-form/src/main/java/com/fr/design/mainframe/ShareWidgetButton.java b/designer-form/src/main/java/com/fr/design/mainframe/ShareWidgetButton.java index 7e7d76d896..cdfa095bf6 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/ShareWidgetButton.java +++ b/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); @@ -71,9 +72,11 @@ public class ShareWidgetButton extends JPanel implements MouseListener, MouseMot unMarkedMode.paintIcon(this, g, 0, 0); } }; - - 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()); @@ -81,7 +84,12 @@ public class ShareWidgetButton extends JPanel implements MouseListener, MouseMot this.addMouseMotionListener(this); 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,21 +227,14 @@ 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); } } } - + @Override public void mouseMoved(MouseEvent e) { @@ -283,9 +284,31 @@ public class ShareWidgetButton extends JPanel implements MouseListener, MouseMot } return false; } - + public Object getTransferData(DataFlavor df) throws UnsupportedFlavorException, IOException { 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; + } + } } diff --git a/designer-form/src/test/java/com/fr/design/mainframe/ShareWidgetButtonTest.java b/designer-form/src/test/java/com/fr/design/mainframe/ShareWidgetButtonTest.java new file mode 100644 index 0000000000..50f8afc189 --- /dev/null +++ b/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()); + } +} \ No newline at end of file