@Test @Ignore @SuppressWarnings("unchecked") public void getNextFromRoot() { Node node1 = mock(Node.class); Bounds boundsNode1 = Bounds.create(100d, 100d, 300d, 200d); View viewNode1 = mock(View.class); when(node1.getContent()).thenReturn(viewNode1); when(viewNode1.getBounds()).thenReturn(boundsNode1); Node node2 = mock(Node.class); Bounds boundsNode2 = Bounds.create(100d, 100d, 300d, 200d); View viewNode2 = mock(View.class); when(node2.getContent()).thenReturn(viewNode2); when(viewNode2.getBounds()).thenReturn(boundsNode2); Node nodeRoot = mock(Node.class); double rootWidth = 40d; double rootHeight = 40d; Bounds rootBounds = Bounds.create(0d, 0d, rootWidth, rootHeight); View rootView = mock(View.class); when(nodeRoot.getContent()).thenReturn(rootView); when(rootView.getBounds()).thenReturn(rootBounds); List<Node> nodes = new ArrayList<>(); List<Edge> edges = new ArrayList<>(); Edge edge = mock(Edge.class); edges.add(edge); when(nodeRoot.getOutEdges()).thenReturn(edges); when(edge.getTargetNode()).thenReturn(node1); when(nodeRoot.getContent()).thenReturn(rootView); nodes.add(nodeRoot); when(graph.nodes()).thenReturn(nodes); when(node2.getInEdges()).thenReturn(edges); when(nodeRoot.asNode()).thenReturn(nodeRoot); Point2D next = canvasLayoutUtils.getNext(canvasHandler, nodeRoot, node2); assertTrue(next.getX() > rootWidth); assertTrue(next.getY() > NEW_NODE_HEIGHT); }
@SuppressWarnings("unchecked") public Point2D getNext(final AbstractCanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) { final double[] rootBounds = getBoundCoordinates(root); final double[] rootSize = GraphUtils.getNodeSize(root.getContent()); final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent()); Point2D[] offset = {new Point2D(PADDING_X, 0)}; Point2D[] parentOffset = {new Point2D(0, 0)}; double maxNodeY[] = {0}; if (root.getOutEdges().size() > 0) { root.getOutEdges().stream() .filter(e -> e.getContent() instanceof ViewConnector) .filter(e -> null != e.getTargetNode() && !e.getTargetNode().equals(newNode)) .forEach(n -> { final Node<View<?>, Edge> node = n.getTargetNode(); final Point2D nodePos = GraphUtils.getPosition(node.getContent()); final Point2D rootPos = GraphUtils.getPosition(root.getContent()); if (nodePos.getY() > maxNodeY[0]) { maxNodeY[0] = nodePos.getY(); final double[] nodeSize = GraphUtils.getNodeSize(node.getContent()); offset[0].setY(maxNodeY[0] + nodeSize[1] - rootPos.getY()); } }); offset[0].setY(offset[0].getY() + parentOffset[0].getY() + PADDING_Y); } else { offset[0].setY(parentOffset[0].getY() - (newNodeSize[1] - rootSize[1]) / 2); } offset[0].setX(offset[0].getX() + PADDING_X); final Point2D offsetCoordinates = new Point2D(offset[0].getX(), offset[0].getY()); final Point2D rootNodeCoordinates = new Point2D(rootBounds[0], rootBounds[1]); return getNext(canvasHandler, root, rootSize[0], rootSize[1], newNodeSize[0], newNodeSize[1], offsetCoordinates, rootNodeCoordinates ); }
CanvasLayoutUtils { @SuppressWarnings("unchecked") public Point2D getNext(final AbstractCanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) { final double[] rootBounds = getBoundCoordinates(root); final double[] rootSize = GraphUtils.getNodeSize(root.getContent()); final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent()); Point2D[] offset = {new Point2D(PADDING_X, 0)}; Point2D[] parentOffset = {new Point2D(0, 0)}; double maxNodeY[] = {0}; if (root.getOutEdges().size() > 0) { root.getOutEdges().stream() .filter(e -> e.getContent() instanceof ViewConnector) .filter(e -> null != e.getTargetNode() && !e.getTargetNode().equals(newNode)) .forEach(n -> { final Node<View<?>, Edge> node = n.getTargetNode(); final Point2D nodePos = GraphUtils.getPosition(node.getContent()); final Point2D rootPos = GraphUtils.getPosition(root.getContent()); if (nodePos.getY() > maxNodeY[0]) { maxNodeY[0] = nodePos.getY(); final double[] nodeSize = GraphUtils.getNodeSize(node.getContent()); offset[0].setY(maxNodeY[0] + nodeSize[1] - rootPos.getY()); } }); offset[0].setY(offset[0].getY() + parentOffset[0].getY() + PADDING_Y); } else { offset[0].setY(parentOffset[0].getY() - (newNodeSize[1] - rootSize[1]) / 2); } offset[0].setX(offset[0].getX() + PADDING_X); final Point2D offsetCoordinates = new Point2D(offset[0].getX(), offset[0].getY()); final Point2D rootNodeCoordinates = new Point2D(rootBounds[0], rootBounds[1]); return getNext(canvasHandler, root, rootSize[0], rootSize[1], newNodeSize[0], newNodeSize[1], offsetCoordinates, rootNodeCoordinates ); } }
CanvasLayoutUtils { @SuppressWarnings("unchecked") public Point2D getNext(final AbstractCanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) { final double[] rootBounds = getBoundCoordinates(root); final double[] rootSize = GraphUtils.getNodeSize(root.getContent()); final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent()); Point2D[] offset = {new Point2D(PADDING_X, 0)}; Point2D[] parentOffset = {new Point2D(0, 0)}; double maxNodeY[] = {0}; if (root.getOutEdges().size() > 0) { root.getOutEdges().stream() .filter(e -> e.getContent() instanceof ViewConnector) .filter(e -> null != e.getTargetNode() && !e.getTargetNode().equals(newNode)) .forEach(n -> { final Node<View<?>, Edge> node = n.getTargetNode(); final Point2D nodePos = GraphUtils.getPosition(node.getContent()); final Point2D rootPos = GraphUtils.getPosition(root.getContent()); if (nodePos.getY() > maxNodeY[0]) { maxNodeY[0] = nodePos.getY(); final double[] nodeSize = GraphUtils.getNodeSize(node.getContent()); offset[0].setY(maxNodeY[0] + nodeSize[1] - rootPos.getY()); } }); offset[0].setY(offset[0].getY() + parentOffset[0].getY() + PADDING_Y); } else { offset[0].setY(parentOffset[0].getY() - (newNodeSize[1] - rootSize[1]) / 2); } offset[0].setX(offset[0].getX() + PADDING_X); final Point2D offsetCoordinates = new Point2D(offset[0].getX(), offset[0].getY()); final Point2D rootNodeCoordinates = new Point2D(rootBounds[0], rootBounds[1]); return getNext(canvasHandler, root, rootSize[0], rootSize[1], newNodeSize[0], newNodeSize[1], offsetCoordinates, rootNodeCoordinates ); } @Inject  CanvasLayoutUtils(final GraphBoundsIndexer graphBoundsIndexer); }
CanvasLayoutUtils { @SuppressWarnings("unchecked") public Point2D getNext(final AbstractCanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) { final double[] rootBounds = getBoundCoordinates(root); final double[] rootSize = GraphUtils.getNodeSize(root.getContent()); final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent()); Point2D[] offset = {new Point2D(PADDING_X, 0)}; Point2D[] parentOffset = {new Point2D(0, 0)}; double maxNodeY[] = {0}; if (root.getOutEdges().size() > 0) { root.getOutEdges().stream() .filter(e -> e.getContent() instanceof ViewConnector) .filter(e -> null != e.getTargetNode() && !e.getTargetNode().equals(newNode)) .forEach(n -> { final Node<View<?>, Edge> node = n.getTargetNode(); final Point2D nodePos = GraphUtils.getPosition(node.getContent()); final Point2D rootPos = GraphUtils.getPosition(root.getContent()); if (nodePos.getY() > maxNodeY[0]) { maxNodeY[0] = nodePos.getY(); final double[] nodeSize = GraphUtils.getNodeSize(node.getContent()); offset[0].setY(maxNodeY[0] + nodeSize[1] - rootPos.getY()); } }); offset[0].setY(offset[0].getY() + parentOffset[0].getY() + PADDING_Y); } else { offset[0].setY(parentOffset[0].getY() - (newNodeSize[1] - rootSize[1]) / 2); } offset[0].setX(offset[0].getX() + PADDING_X); final Point2D offsetCoordinates = new Point2D(offset[0].getX(), offset[0].getY()); final Point2D rootNodeCoordinates = new Point2D(rootBounds[0], rootBounds[1]); return getNext(canvasHandler, root, rootSize[0], rootSize[1], newNodeSize[0], newNodeSize[1], offsetCoordinates, rootNodeCoordinates ); } @Inject  CanvasLayoutUtils(final GraphBoundsIndexer graphBoundsIndexer); static boolean isCanvasRoot(final Diagram diagram,
                                       final Element parent); static boolean isCanvasRoot(final Diagram diagram,
                                       final String pUUID); static int getPaddingX(); static int getPaddingY(); @PreDestroy void destroy(); @SuppressWarnings("unchecked") Point2D getNext(final AbstractCanvasHandler canvasHandler,
                           final Node<View<?>, Edge> root,
                           final Node<View<?>, Edge> newNode); @SuppressWarnings("unchecked") Point2D getNext(final AbstractCanvasHandler canvasHandler,
                           final Node<View<?>, Edge> root,
                           final double rootNodeWidth,
                           final double rootNodeHeight,
                           final double newNodeWidth,
                           final double newNodeHeight,
                           Point2D offset,
                           Point2D rootNodeCoordinates
    ); @SuppressWarnings("unchecked") static Element<? extends Definition<?>> getElement(final AbstractCanvasHandler canvasHandler,
                                                              final String uuid); static void fireElementSelectedEvent(final Event<CanvasSelectionEvent> selectionEvent,
                                                final AbstractCanvasHandler canvasHandler,
                                                final String uuid); }
CanvasLayoutUtils { @SuppressWarnings("unchecked") public Point2D getNext(final AbstractCanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) { final double[] rootBounds = getBoundCoordinates(root); final double[] rootSize = GraphUtils.getNodeSize(root.getContent()); final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent()); Point2D[] offset = {new Point2D(PADDING_X, 0)}; Point2D[] parentOffset = {new Point2D(0, 0)}; double maxNodeY[] = {0}; if (root.getOutEdges().size() > 0) { root.getOutEdges().stream() .filter(e -> e.getContent() instanceof ViewConnector) .filter(e -> null != e.getTargetNode() && !e.getTargetNode().equals(newNode)) .forEach(n -> { final Node<View<?>, Edge> node = n.getTargetNode(); final Point2D nodePos = GraphUtils.getPosition(node.getContent()); final Point2D rootPos = GraphUtils.getPosition(root.getContent()); if (nodePos.getY() > maxNodeY[0]) { maxNodeY[0] = nodePos.getY(); final double[] nodeSize = GraphUtils.getNodeSize(node.getContent()); offset[0].setY(maxNodeY[0] + nodeSize[1] - rootPos.getY()); } }); offset[0].setY(offset[0].getY() + parentOffset[0].getY() + PADDING_Y); } else { offset[0].setY(parentOffset[0].getY() - (newNodeSize[1] - rootSize[1]) / 2); } offset[0].setX(offset[0].getX() + PADDING_X); final Point2D offsetCoordinates = new Point2D(offset[0].getX(), offset[0].getY()); final Point2D rootNodeCoordinates = new Point2D(rootBounds[0], rootBounds[1]); return getNext(canvasHandler, root, rootSize[0], rootSize[1], newNodeSize[0], newNodeSize[1], offsetCoordinates, rootNodeCoordinates ); } @Inject  CanvasLayoutUtils(final GraphBoundsIndexer graphBoundsIndexer); static boolean isCanvasRoot(final Diagram diagram,
                                       final Element parent); static boolean isCanvasRoot(final Diagram diagram,
                                       final String pUUID); static int getPaddingX(); static int getPaddingY(); @PreDestroy void destroy(); @SuppressWarnings("unchecked") Point2D getNext(final AbstractCanvasHandler canvasHandler,
                           final Node<View<?>, Edge> root,
                           final Node<View<?>, Edge> newNode); @SuppressWarnings("unchecked") Point2D getNext(final AbstractCanvasHandler canvasHandler,
                           final Node<View<?>, Edge> root,
                           final double rootNodeWidth,
                           final double rootNodeHeight,
                           final double newNodeWidth,
                           final double newNodeHeight,
                           Point2D offset,
                           Point2D rootNodeCoordinates
    ); @SuppressWarnings("unchecked") static Element<? extends Definition<?>> getElement(final AbstractCanvasHandler canvasHandler,
                                                              final String uuid); static void fireElementSelectedEvent(final Event<CanvasSelectionEvent> selectionEvent,
                                                final AbstractCanvasHandler canvasHandler,
                                                final String uuid);  }