@Test public void testCreateConnections() { Element element = mock(Element.class); View<?> content = mock(View.class); Bounds bounds = Bounds.create(0d, 0d, 10d, 20d); when(element.getContent()).thenReturn(content); when(content.getBounds()).thenReturn(bounds); MagnetConnection c1 = ConnectionAcceptorControlImpl.createConnection(element); assertEquals(5, c1.getLocation().getX(), 0); assertEquals(10, c1.getLocation().getY(), 0); assertEquals(MagnetConnection.MAGNET_CENTER, c1.getMagnetIndex().getAsInt()); assertFalse(c1.isAuto()); WiresConnection wiresConnection = mock(WiresConnection.class); when(wiresConnection.isAutoConnection()).thenReturn(true); WiresMagnet wiresMagnet = mock(WiresMagnet.class); when(wiresMagnet.getX()).thenReturn(122d); when(wiresMagnet.getY()).thenReturn(543d); when(wiresMagnet.getIndex()).thenReturn(7); MagnetConnection c2 = (MagnetConnection) ConnectionAcceptorControlImpl.createConnection(wiresConnection, wiresMagnet); assertEquals(122, c2.getLocation().getX(), 0); assertEquals(543, c2.getLocation().getY(), 0); assertEquals(7, c2.getMagnetIndex().getAsInt()); assertTrue(c2.isAuto()); when(wiresConnection.getPoint()).thenReturn(new Point2D(122d, 543d)); final Connection pointConnection = ConnectionAcceptorControlImpl.createConnection(wiresConnection, null); assertEquals(122d, pointConnection.getLocation().getX(), 0); assertEquals(543d, pointConnection.getLocation().getY(), 0); assertNull(ConnectionAcceptorControlImpl.createConnection(null)); assertNull(ConnectionAcceptorControlImpl.createConnection(null, null)); }
public static Connection createConnection(final WiresConnection wiresConnection, final WiresMagnet wiresMagnet) { if (null == wiresMagnet && null == wiresConnection) { return null; } if (null == wiresMagnet) { return Point2DConnection.at(Point2D.create(wiresConnection.getPoint().getX(), wiresConnection.getPoint().getY())); } return new MagnetConnection.Builder() .atX(wiresMagnet.getX()) .atY(wiresMagnet.getY()) .auto(null != wiresConnection && wiresConnection.isAutoConnection()) .magnet(wiresMagnet.getIndex()) .build(); }
ConnectionAcceptorControlImpl extends AbstractAcceptorControl implements ConnectionAcceptorControl<AbstractCanvasHandler> { public static Connection createConnection(final WiresConnection wiresConnection, final WiresMagnet wiresMagnet) { if (null == wiresMagnet && null == wiresConnection) { return null; } if (null == wiresMagnet) { return Point2DConnection.at(Point2D.create(wiresConnection.getPoint().getX(), wiresConnection.getPoint().getY())); } return new MagnetConnection.Builder() .atX(wiresMagnet.getX()) .atY(wiresMagnet.getY()) .auto(null != wiresConnection && wiresConnection.isAutoConnection()) .magnet(wiresMagnet.getIndex()) .build(); } }
ConnectionAcceptorControlImpl extends AbstractAcceptorControl implements ConnectionAcceptorControl<AbstractCanvasHandler> { public static Connection createConnection(final WiresConnection wiresConnection, final WiresMagnet wiresMagnet) { if (null == wiresMagnet && null == wiresConnection) { return null; } if (null == wiresMagnet) { return Point2DConnection.at(Point2D.create(wiresConnection.getPoint().getX(), wiresConnection.getPoint().getY())); } return new MagnetConnection.Builder() .atX(wiresMagnet.getX()) .atY(wiresMagnet.getY()) .auto(null != wiresConnection && wiresConnection.isAutoConnection()) .magnet(wiresMagnet.getIndex()) .build(); } @Inject  ConnectionAcceptorControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory,
                                         final CanvasHighlight canvasHighlight); }
ConnectionAcceptorControlImpl extends AbstractAcceptorControl implements ConnectionAcceptorControl<AbstractCanvasHandler> { public static Connection createConnection(final WiresConnection wiresConnection, final WiresMagnet wiresMagnet) { if (null == wiresMagnet && null == wiresConnection) { return null; } if (null == wiresMagnet) { return Point2DConnection.at(Point2D.create(wiresConnection.getPoint().getX(), wiresConnection.getPoint().getY())); } return new MagnetConnection.Builder() .atX(wiresMagnet.getX()) .atY(wiresMagnet.getY()) .auto(null != wiresConnection && wiresConnection.isAutoConnection()) .magnet(wiresMagnet.getIndex()) .build(); } @Inject  ConnectionAcceptorControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory,
                                         final CanvasHighlight canvasHighlight); @Override @SuppressWarnings("unchecked") boolean allowSource(final Node source,
                               final Edge<ViewConnector<?>, Node> connector,
                               final Connection connection); @Override @SuppressWarnings("unchecked") boolean allowTarget(final Node target,
                               final Edge<ViewConnector<?>, Node> connector,
                               final Connection connection); @Override @SuppressWarnings("unchecked") boolean acceptSource(final Node source,
                                final Edge<ViewConnector<?>, Node> connector,
                                final Connection connection); @Override @SuppressWarnings("unchecked") boolean acceptTarget(final Node target,
                                final Edge<ViewConnector<?>, Node> connector,
                                final Connection connection); static Connection createConnection(final WiresConnection wiresConnection,
                                              final WiresMagnet wiresMagnet); @SuppressWarnings("unchecked") static MagnetConnection createConnection(final Element element); }
ConnectionAcceptorControlImpl extends AbstractAcceptorControl implements ConnectionAcceptorControl<AbstractCanvasHandler> { public static Connection createConnection(final WiresConnection wiresConnection, final WiresMagnet wiresMagnet) { if (null == wiresMagnet && null == wiresConnection) { return null; } if (null == wiresMagnet) { return Point2DConnection.at(Point2D.create(wiresConnection.getPoint().getX(), wiresConnection.getPoint().getY())); } return new MagnetConnection.Builder() .atX(wiresMagnet.getX()) .atY(wiresMagnet.getY()) .auto(null != wiresConnection && wiresConnection.isAutoConnection()) .magnet(wiresMagnet.getIndex()) .build(); } @Inject  ConnectionAcceptorControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory,
                                         final CanvasHighlight canvasHighlight); @Override @SuppressWarnings("unchecked") boolean allowSource(final Node source,
                               final Edge<ViewConnector<?>, Node> connector,
                               final Connection connection); @Override @SuppressWarnings("unchecked") boolean allowTarget(final Node target,
                               final Edge<ViewConnector<?>, Node> connector,
                               final Connection connection); @Override @SuppressWarnings("unchecked") boolean acceptSource(final Node source,
                                final Edge<ViewConnector<?>, Node> connector,
                                final Connection connection); @Override @SuppressWarnings("unchecked") boolean acceptTarget(final Node target,
                                final Edge<ViewConnector<?>, Node> connector,
                                final Connection connection); static Connection createConnection(final WiresConnection wiresConnection,
                                              final WiresMagnet wiresMagnet); @SuppressWarnings("unchecked") static MagnetConnection createConnection(final Element element);  }