Package org.tinyuml.draw

Examples of org.tinyuml.draw.Node


  /**
   * Tests clone() method.
   */
  public void testClone() {
    MyCompositeNode node = new MyCompositeNode();
    Node child = new MyCompositeNode();
    node.addChild(child);
    MyCompositeNode cloned = (MyCompositeNode) node.clone();
   
    // AbstractCompositeNode
    assertEquals(node.getChildren().size(), cloned.getChildren().size());
View Full Code Here


    MyCompositeNode node = new MyCompositeNode();
    node.setParent(parent);
    node.setOrigin(0, 0);
    node.setSize(100, 100);
    // test parent assignment
    Node child = new MyCompositeNode();
    child.setOrigin(5, 5);
    child.setSize(10, 10);
    node.addChild(child);
    assertEquals(node, child.getParent());
    node.removeChild(child);
    assertEquals(node, child.getParent());

    // test getChildAt()
    mockParent.expects(atLeastOnce()).method("getAbsoluteX1").
      will(returnValue(0.0));
    mockParent.expects(atLeastOnce()).method("getAbsoluteY1").
View Full Code Here

 
  /**
   * Tests initial state.
   */
  public void testInitial() {
    Node boxedShape = new MyBoxedShape();
    assertNull(boxedShape.getParent());
    assertNotNull(boxedShape.getOrigin());
    assertNotNull(boxedShape.getSize());
    assertNotNull(boxedShape.getMinimumSize());
  }
View Full Code Here

 
  /**
   * Tests the setter methods.
   */
  public void testSetters() {
    Node boxedShape = new MyBoxedShape();   
    MyShapeContainer parent = new MyShapeContainer();
    parent.setOrigin(2.5, 2.5);
     
    boxedShape.setParent(parent);
    boxedShape.setOrigin(1.0, 3.3);
    boxedShape.setSize(3.2, 4.1);
    boxedShape.setMinimumSize(5.1, 6.3);
   
    assertEquals(parent, boxedShape.getParent());
    assertEquals(1.0, boxedShape.getOrigin().getX());
    assertEquals(3.3, boxedShape.getOrigin().getY());
    assertEquals(3.2, boxedShape.getSize().getWidth());
    assertEquals(4.1, boxedShape.getSize().getHeight());
    assertEquals(5.1, boxedShape.getMinimumSize().getWidth());
    assertEquals(6.3, boxedShape.getMinimumSize().getHeight());
   
    // Absolute position
    assertEquals(boxedShape.getOrigin().getX() + parent.getAbsoluteX(),
                 boxedShape.getAbsoluteX());
    assertEquals(boxedShape.getOrigin().getY() + parent.getAbsoluteY(),
                 boxedShape.getAbsoluteY());
    boxedShape.setAbsolutePos(8.3, 9.5);
    assertEquals(8.3, boxedShape.getAbsoluteX());
    assertEquals(9.5, boxedShape.getAbsoluteY());
    assertEquals(8.3 - parent.getAbsoluteX(), boxedShape.getOrigin().getX());
    assertEquals(9.5 - parent.getAbsoluteY(), boxedShape.getOrigin().getY());
    // mapped positions
    assertTrue(Math.abs(0.3 - boxedShape.getMappedX(8.6)) < EPS);
    assertTrue(Math.abs(1.0 - boxedShape.getMappedY(10.5)) < EPS);
  }
View Full Code Here

 
  /**
   * Tests the contains() method.
   */
  public void testContains() {
    Node boxedShape = new MyBoxedShape();   
    MyShapeContainer parent = new MyShapeContainer();
    parent.setOrigin(2.5, 2.5);
    boxedShape.setOrigin(3.0, 3.0);
    boxedShape.setSize(1.0, 1.0);
    boxedShape.setParent(parent);
   
    // contains is in absolute coordinates
    assertTrue(boxedShape.contains(5.8, 5.7));
    assertFalse(boxedShape.contains(3.1, 3.3));
  }
View Full Code Here

 
  /**
   * Tests absolute center calculation.
   */
  public void testGetAbsoluteCenter() {
    Node boxedShape = new MyBoxedShape();   
    MyShapeContainer parent = new MyShapeContainer();
    parent.setOrigin(0, 0);
    boxedShape.setOrigin(3.0, 5.0);
    boxedShape.setSize(2.0, 3.0);
    boxedShape.setParent(parent);
    assertEquals(4.0, boxedShape.getAbsCenterX());
    assertEquals(6.5, boxedShape.getAbsCenterY());
  }
View Full Code Here

  /**
   * Tests the isVisible() method.
   */
  public void testIsVisible() {
    Node boxedShape = new MyBoxedShape();   
    MyShapeContainer parent = new MyShapeContainer();
    parent.setOrigin(2.5, 2.5);
    // origin: (5.5, 5.5) x1, y1: (6.5, 6.5)
    boxedShape.setOrigin(3.0, 3.0);
    boxedShape.setSize(1.0, 1.0);
    boxedShape.setParent(parent);
   
    // isVisible is in absolute coordinates
    Rectangle clipBounds = new Rectangle(1, 1, 4, 4);
    assertFalse(boxedShape.isVisible(clipBounds));
   
    // Translate to overlap with (5.5, 5.5), and now, the areas are overlapping
    clipBounds = new Rectangle(2, 2, 4, 5);
    assertTrue(boxedShape.isVisible(clipBounds));
   
    // Make it so big that it encloses the area
    clipBounds = new Rectangle(5, 5, 10, 10);
    assertTrue(boxedShape.isVisible(clipBounds));
  }
View Full Code Here

 
  /**
   * Tests the getNodeDirection() method.
   */
  public void testGetNodeDirection() {
    Node node1 = new MyNode();
    Node node2 = new MyNode();
   
    // WEST-EAST
    node1.setOrigin(10, 10);
    node1.setSize(120, 80);
    node2.setOrigin(200, 50);
    node2.setSize(20, 50);
    assertEquals(NodeDirection.WEST_EAST, builder.getNodeDirection(node1, node2));
    // WEST-EAST (reverse node order)
    assertEquals(NodeDirection.EAST_WEST, builder.getNodeDirection(node2, node1));

    // NORTH-SOUTH
    node1.setOrigin(30, 50);
    node1.setSize(50, 30);
    node2.setOrigin(25, 100);
    node2.setSize(40, 30);
    assertEquals(NodeDirection.NORTH_SOUTH, builder.getNodeDirection(node1, node2));
    // SOUTH-NORTH (reverse node order)
    assertEquals(NodeDirection.SOUTH_NORTH, builder.getNodeDirection(node2, node1));
   
    // NW-SE
    node1.setOrigin(30, 50);
    node1.setSize(50, 30);
    node2.setOrigin(100, 100);
    node2.setSize(40, 30);
    assertEquals(NodeDirection.NW_SE, builder.getNodeDirection(node1, node2));
    // SE-NW (reverse node order)
    assertEquals(NodeDirection.SE_NW, builder.getNodeDirection(node2, node1));
   
    // SW-NE
    node1.setOrigin(30, 150);
    node1.setSize(50, 30);
    node2.setOrigin(100, 40);
    node2.setSize(40, 30);
    assertEquals(NodeDirection.SW_NE, builder.getNodeDirection(node1, node2));   
    // NE-SW (reverse node order)
    assertEquals(NodeDirection.NE_SW, builder.getNodeDirection(node2, node1));
  }
View Full Code Here

  /**
   * Tests generation between two nodes that can be aligned in WEST-EAST
   * direction.
   */
  public void testCalculateLineSegmentsWithNodesWestEast() {
    Node node1 = new MyNode();
    node1.setOrigin(10, 10);
    node1.setSize(120, 80); // y from 10 - 90
    Node node2 = new MyNode();
    node2.setOrigin(200, 50);
    node2.setSize(80, 30); // y from 50 - 80 -> overlap is from 50 - 80
    List<Point2D> points = builder.calculateLineSegments(node1, node2);
    assertEquals(2, points.size());
    assertEquals(node1.getAbsoluteX2(), points.get(0).getX());
    assertEquals(node2.getAbsoluteX1(), points.get(1).getX());
    assertEquals(points.get(0).getY(), points.get(1).getY());
    assertTrue(points.get(0).getY() >= 50);
    assertTrue(points.get(0).getY() <= 80);
   
    // reverse direction EAST-WEST
    points = builder.calculateLineSegments(node2, node1);
    assertEquals(2, points.size());
    assertEquals(node2.getAbsoluteX1(), points.get(0).getX());
    assertEquals(node1.getAbsoluteX2(), points.get(1).getX());
    assertEquals(points.get(0).getY(), points.get(1).getY());
    assertTrue(points.get(0).getY() >= 50);
    assertTrue(points.get(0).getY() <= 80);
  }
View Full Code Here

  /**
   * Tests generation between two nodes that can be aligned in NORTH-SOUTH
   * direction.
   */
  public void testCalculateLineSegmentsWithNodesNorthSouth() {
    Node node1 = new MyNode();
    node1.setOrigin(10, 10);
    node1.setSize(120, 80); // x from 10 to 130
    Node node2 = new MyNode();
    node2.setOrigin(5, 150);
    node2.setSize(80, 30); // x from 5 to 85 -> (10, 85)
    List<Point2D> points = builder.calculateLineSegments(node1, node2);
    assertEquals(2, points.size());
    assertEquals(node1.getAbsoluteY2(), points.get(0).getY());
    assertEquals(node2.getAbsoluteY1(), points.get(1).getY());
    assertEquals(points.get(0).getX(), points.get(1).getX());
    assertTrue(points.get(0).getX() >= 10);
    assertTrue(points.get(0).getX() <= 130);
   
    // reverse direction EAST-WEST
    points = builder.calculateLineSegments(node2, node1);
    assertEquals(2, points.size());
    assertEquals(node2.getAbsoluteY1(), points.get(0).getY());
    assertEquals(node1.getAbsoluteY2(), points.get(1).getY());
    assertEquals(points.get(0).getX(), points.get(1).getX());
    assertTrue(points.get(0).getX() >= 10);
    assertTrue(points.get(0).getX() <= 130);
  }
View Full Code Here

TOP

Related Classes of org.tinyuml.draw.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.