Ejemplo n.º 1
0
  /**
   * Allocate a superBlock
   *
   * @param parentGraph the base graph
   * @param selection the selected blocks
   * @return the allocated super block (without specific listeners)
   */
  private SuperBlock allocateSuperBlock(final XcosDiagram parentGraph, final Object[] selection) {
    final SuperBlock superBlock = (SuperBlock) BlockFactory.createBlock(INTERFUNCTION_NAME);
    superBlock.setStyle(INTERFUNCTION_NAME);

    /*
     * Allocate the diagram
     */
    final SuperBlockDiagram diag = new SuperBlockDiagram(superBlock);
    superBlock.setChild(diag);
    superBlock.setParentDiagram(parentGraph);

    /*
     * Place the super block
     */
    final mxRectangle dims = parentGraph.getBoundingBoxFromGeometry(selection);
    final double minX = dims.getX();
    final double maxX = minX + dims.getWidth();

    final double minY = dims.getY();
    final double maxY = minY + dims.getHeight();

    superBlock.getGeometry().setX((maxX + minX - superBlock.getGeometry().getWidth()) / 2.0);
    superBlock.getGeometry().setY((maxY + minY - superBlock.getGeometry().getHeight()) / 2.0);

    /*
     * get statistics
     */
    int angleCounter = 0;
    int flipCounter = 0;
    int mirrorCounter = 0;
    for (Object object : selection) {
      if (object instanceof BasicBlock) {
        final BasicBlock b = (BasicBlock) object;

        angleCounter += b.getAngle();
        if (b.getFlip()) {
          flipCounter++;
        }
        if (b.getMirror()) {
          mirrorCounter++;
        }
      }
    }

    /*
     * apply statistics
     */
    final int halfSize = selection.length / 2;
    superBlock.setAngle(BlockPositioning.roundAngle(angleCounter / selection.length));
    superBlock.setFlip(flipCounter > halfSize);
    superBlock.setMirror(mirrorCounter > halfSize);

    return superBlock;
  }