Esempio n. 1
0
  /**
   * Adds layout options to the elements of the given parent node.
   *
   * @param parentNode parent node representing a graph
   */
  private static void addLayoutOptions(final KNode parentNode) {
    // add options for the parent node
    KShapeLayout parentLayout = parentNode.getData(KShapeLayout.class);
    // set layout direction to horizontal
    parentLayout.setProperty(LayoutOptions.DIRECTION, Direction.RIGHT);

    // add options for the child nodes
    for (KNode childNode : parentNode.getChildren()) {
      KShapeLayout childLayout = childNode.getData(KShapeLayout.class);
      // set some width and height for the child
      childLayout.setWidth(30.0f);
      childLayout.setHeight(30.0f);
      // set fixed size for the child
      // childLayout.setProperty(LayoutOptions.FIXED_SIZE, Boolean.TRUE);
      // set port constraints to fixed port positions
      childLayout.setProperty(LayoutOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);

      // add options for the ports
      int i = 0;
      for (KPort port : childNode.getPorts()) {
        i++;
        KShapeLayout portLayout = port.getData(KShapeLayout.class);
        // set position and side
        portLayout.setYpos(i * 30.0f / (childNode.getPorts().size() + 1));
        if (childNode.getLabels().get(0).getText().equals("node1")) {
          portLayout.setXpos(30.0f);
          portLayout.setProperty(LayoutOptions.PORT_SIDE, PortSide.EAST);
        } else {
          portLayout.setXpos(0.0f);
          portLayout.setProperty(LayoutOptions.PORT_SIDE, PortSide.WEST);
        }
      }
    }
  }