コード例 #1
0
  public void actionPerformed(ActionEvent e) {

    // sum of coordinates
    double sx = 0;
    double sy = 0;

    // coordinates of center of graph
    double cx = 0;
    double cy = 0;

    // coordinates with graph centered at (0,0)
    double nx;
    double ny;

    CyNetworkView parent = Cytoscape.getCurrentNetworkView();
    // loop through each node to add up all x and all y coordinates
    for (Iterator i = parent.getNodeViewsIterator(); i.hasNext(); ) {
      NodeView nodeView = (NodeView) i.next();
      // get coordinates of node
      double ax = nodeView.getXPosition();
      double ay = nodeView.getYPosition();
      // sum up coordinates of all the nodes
      sx += ax;
      sy += ay;
    }

    // set new coordinates of each node at center (0,0), shrink, then return to
    // original center at (cx, cy)
    for (Iterator i = parent.getNodeViewsIterator(); i.hasNext(); ) {
      NodeView nodeView = (NodeView) i.next();
      nodeView.setXPosition(m * ((nodeView.getXPosition()) - cx) + cx);
      nodeView.setYPosition(m * ((nodeView.getYPosition()) - cy) + cy);
    }

    // remove bends
    for (Iterator i = parent.getEdgeViewsIterator(); i.hasNext(); ) {
      EdgeView edgeView = (EdgeView) i.next();
      edgeView.getBend().removeAllHandles();
    }
  } // Action Performed
コード例 #2
0
  /**
   * Method to determine whether a node is an ancestor of another node.
   *
   * @param ancestor GO term node which may or may not be an ancestor of 'child'.
   * @param child GO term node with may or may not be a child of 'ancestor'.
   * @return true if 'ancestor' is an ancestor of 'child', false otherwise.
   */
  private boolean isAncestorNode(Node ancestor, Node child) {

    DGraphView view = (DGraphView) Cytoscape.getCurrentNetworkView();

    // Loop through the outgoing edges of child node (to parent nodes), and check if 'target' is the
    // parent node.
    // Then recursively call method on each of the parent nodes.
    int[] outgoingEdges =
        Cytoscape.getCurrentNetwork()
            .getAdjacentEdgeIndicesArray(child.getRootGraphIndex(), false, false, true);
    for (int outgoingEdge : outgoingEdges) {
      EdgeView ev = view.getEdgeView(outgoingEdge);
      Node parentNode = ev.getEdge().getTarget();
      if (ancestor.equals(parentNode)) {
        return true;
      }
      if (isAncestorNode(ancestor, parentNode)) {
        return true;
      }
    }
    return false;
  }