@Override
 public void recoverObjectProperties() {
   // This method has to override abstract class
   // if any one of it's children answer true to wasLayedOut
   // then we assume that this diagram had entities defined and
   // was already layed out at one time.
   // This should be called after the initial layout method only!!!
   List children = getChildren();
   Iterator iter = children.iterator();
   DiagramModelNode nextChild = null;
   while (iter.hasNext()) {
     nextChild = (DiagramModelNode) iter.next();
     if (nextChild.wasLayedOut()) nextChild.recoverObjectProperties();
   }
 }
  @Override
  public boolean wasLayedOut() {
    // This method has to override abstract class
    // if any one of it's children answer true to same method
    // then we assume that this diagram had entities defined and
    // was already layed out at one time.
    List children = getChildren();
    Iterator iter = children.iterator();
    DiagramModelNode nextChild = null;
    while (iter.hasNext()) {
      nextChild = (DiagramModelNode) iter.next();
      if (nextChild.wasLayedOut()) return true;
    }

    return false;
  }
  /*
   *  (non-Javadoc)
   * @see com.metamatrix.modeler.diagram.ui.model.DiagramModelNode#addChildren(java.util.List)
   */
  @Override
  public void addChildren(List newChildren) {
    if (newChildren != null && !newChildren.isEmpty()) {

      Object nextChild;
      Iterator iter = newChildren.iterator();
      while (iter.hasNext()) {
        nextChild = iter.next();
        ((DiagramModelNode) nextChild).setParent(this);
      }
      super.addChildren(newChildren);
    }
  }
Example #4
0
  @Override
  protected int run() {
    if (this.getComponentCount() == 0) return SUCCESSFUL;

    int i = buildTree();

    if (i != 0) return i;

    TreeNode treenode = (TreeNode) _compToNode.get(modelRoot);
    if (treenode == null) return ERROR_ROOT_NOT_MANAGED;

    TreeNode[] treenodes = new TreeNode[_depth + 1];
    treenode.setNeighbors(treenodes);

    double d = 0.0;
    double d_85_ = 0.0;
    double d_86_ = 0.0;
    double d_87_ = 1.0;
    double d_88_ = 0.0;
    double[] ds = new double[_depth + 1];

    if (_method == 0) {
      double[] ds_89_ = new double[_depth + 1];
      double[] ds_90_ = new double[_depth + 1];
      treenode.calculatePosition(ds_89_, ds_90_);
      treenode.setEven();
      for (int i_91_ = 0; i_91_ <= _depth; i_91_++) d_86_ = Math.max(d_86_, ds_90_[i_91_]);
      if (_useObjectsSizes) {
        treenode.getMaximumWidths(ds);
        for (int i_92_ = 0; i_92_ <= _depth; i_92_++) {
          d_88_ = ds[i_92_];
          ds[i_92_] += d - 0.5 * d_88_;
          d += d_88_;
          d_85_ = Math.max(d_85_, ds_89_[i_92_]);
        }
      }
    } else {
      double[] ds_93_ = new double[1];
      double[] ds_94_ = new double[1];
      treenode.calculateSeparatePosition(ds_93_, ds_94_);
      d_86_ = ds_94_[0];
      if (_useObjectsSizes) {
        treenode.getMaximumWidths(ds);
        for (int i_95_ = 0; i_95_ <= _depth; i_95_++) {
          d_88_ = ds[i_95_];
          ds[i_95_] += d - 0.5 * d_88_;
          d += d_88_;
        }
        d_85_ = ds_93_[0];
      }
    }

    double d_96_ = 0.0;
    double d_97_ = 0.0;
    double d_98_ = this.getWidth();
    double d_99_ = this.getHeight();
    double d_100_ = this.getXOrigin();
    double d_101_ = this.getYOrigin();
    if (_useObjectsSizes) {
      d_96_ = 1.0;
      d_97_ = 1.0;
    }
    if (_orientation == ORIENTATION_ROOT_TOP || _orientation == ORIENTATION_ROOT_BOTTOM) {
      d_88_ = d_98_;
      d_98_ = d_99_;
      d_99_ = d_88_;
      d_88_ = d_100_;
      d_100_ = d_101_;
      d_101_ = d_88_;
    }
    if (_orientation == ORIENTATION_ROOT_RIGHT || _orientation == ORIENTATION_ROOT_BOTTOM) {
      d_100_ += d_98_;
      d_101_ += d_99_;
      d_96_ = -d_96_;
      d_97_ = -d_97_;
      d_87_ = -1.0;
    }
    if (_fixedSpacing) {
      if (_orientation == ORIENTATION_ROOT_TOP || _orientation == ORIENTATION_ROOT_BOTTOM) {
        d_98_ = d_87_ * _fixedYSpacing;
        d_99_ = d_87_ * _fixedXSpacing;
      } else {
        d_98_ = d_87_ * _fixedXSpacing;
        d_99_ = d_87_ * _fixedYSpacing;
      }
    } else {
      d_98_ = d_87_ * (d_98_ - d) / (_depth + 1);
      d_99_ = d_87_ * (d_99_ - d_85_) / d_86_;
    }
    d_100_ += 0.5 * d_98_;
    d_101_ -= 0.5 * d_99_;
    for (int i_102_ = 0; i_102_ <= _depth; i_102_++)
      ds[i_102_] = d_100_ + d_96_ * ds[i_102_] + d_98_ * i_102_;

    DiagramModelNode[] modelNodes = getNodeArray();
    int i_103_ = modelNodes.length;
    if (_orientation == ORIENTATION_ROOT_RIGHT || _orientation == ORIENTATION_ROOT_LEFT) {
      for (int i_104_ = 0; i_104_ < i_103_; i_104_++) {
        DiagramModelNode modelNode = modelNodes[i_104_];
        treenode = rawTreeNodes[i_104_];
        if (treenode._level != -1) {
          int newX = (int) ds[treenode._level];
          int newY =
              (int)
                  (treenode._absolutePosition * d_97_
                      + treenode._relativePosition * d_99_
                      + d_101_);
          modelNode.setCenterXY(newX, newY);
        }
      }
    } else {
      for (int i_105_ = 0; i_105_ < i_103_; i_105_++) {
        DiagramModelNode modelNode = modelNodes[i_105_];
        treenode = rawTreeNodes[i_105_];
        if (treenode._level != -1) {
          int newX = (int) ds[treenode._level];
          int newY =
              (int)
                  (treenode._absolutePosition * d_97_
                      + treenode._relativePosition * d_99_
                      + d_101_);
          modelNode.setCenterXY(newX, newY);
        }
      }
    }
    // if (this.getPropagate())
    // this.propagate();

    return SUCCESSFUL;
  }
Example #5
0
  private int buildTree() {
    _compToNode.clear();
    int i = this.getComponentCount();
    if (i == 0) return 0;
    DiagramModelNode[] modelNodes = getNodeArray();
    rawTreeNodes = new TreeNode[i];
    for (int iiNode = 0; iiNode < i; iiNode++) {
      DiagramModelNode modelNode = modelNodes[iiNode];
      rawTreeNodes[iiNode] = new TreeNode(modelNode);
      _compToNode.put(modelNode, rawTreeNodes[iiNode]);
    }

    if (_order == LIST_ORDER) {
      for (int i_107_ = 0; i_107_ < i; i_107_++) rawTreeNodes[i_107_]._orderVar = i_107_;
    } else if (_orientation == ORIENTATION_ROOT_LEFT) {
      for (int i_108_ = 0; i_108_ < i; i_108_++)
        rawTreeNodes[i_108_]._orderVar = modelNodes[i_108_].getCenterY();
    } else if (_orientation == ORIENTATION_ROOT_TOP) {
      for (int i_109_ = 0; i_109_ < i; i_109_++)
        rawTreeNodes[i_109_]._orderVar = modelNodes[i_109_].getCenterX();
    } else if (_orientation == ORIENTATION_ROOT_RIGHT) {
      for (int i_110_ = 0; i_110_ < i; i_110_++)
        rawTreeNodes[i_110_]._orderVar = -modelNodes[i_110_].getCenterY();
    } else {
      for (int i_111_ = 0; i_111_ < i; i_111_++)
        rawTreeNodes[i_111_]._orderVar = -modelNodes[i_111_].getCenterX();
    }

    if (_orientation == ORIENTATION_ROOT_LEFT || _orientation == ORIENTATION_ROOT_RIGHT) {
      for (int i_112_ = 0; i_112_ < i; i_112_++) {
        rawTreeNodes[i_112_]._width = modelNodes[i_112_].getWidth();
        rawTreeNodes[i_112_]._height = modelNodes[i_112_].getHeight();
      }
    } else {
      for (int i_113_ = 0; i_113_ < i; i_113_++) {
        rawTreeNodes[i_113_]._width = modelNodes[i_113_].getHeight();
        rawTreeNodes[i_113_]._height = modelNodes[i_113_].getWidth();
      }
    }

    for (int iiNode = 0; iiNode < i; iiNode++) {
      DiagramModelNode sourceNode = modelNodes[iiNode];
      Vector sourceConnections = sourceNode.getSourceConnections();
      TreeNode sourceTreeNode = (TreeNode) _compToNode.get(sourceNode);
      if (!sourceConnections.isEmpty()) {
        Iterator iter = sourceConnections.iterator();
        NodeConnectionModel nextConnection = null;
        while (iter.hasNext()) {
          nextConnection = (NodeConnectionModel) iter.next();
          TreeNode targetTreeNode = (TreeNode) _compToNode.get(nextConnection.getTargetNode());
          if (sourceTreeNode != null && targetTreeNode != null) {
            sourceTreeNode.addLinkToNode(targetTreeNode);
            targetTreeNode.addLinkToNode(sourceTreeNode);
          }
        }
      }
    }

    if (modelRoot == null) return ERROR_TREE_HAS_NO_ROOT;

    TreeNode treenode = (TreeNode) _compToNode.get(modelRoot);
    if (treenode == null) return ERROR_ROOT_NOT_MANAGED;

    _depth = -1;

    try {
      _depth = treenode.setParent(null);
    } catch (NotATreeException notatreeexception) {
      return ERROR_NOT_A_TREE;
    }

    return SUCCESSFUL;
  }
  /*
   *  (non-Javadoc)
   * @see com.metamatrix.modeler.diagram.ui.model.DiagramModelNode#addChild(com.metamatrix.modeler.diagram.ui.model.DiagramModelNode)
   */
  @Override
  public void addChild(DiagramModelNode child) {
    child.setParent(this);

    super.addChild(child);
  }