Example #1
0
  /**
   * The graph was resize so the algorithm must be adapted to the new size. Then mark dirty.
   *
   * @param w new width
   * @param h new height
   */
  private void setGraphSize(int w, int h) {
    int oldWidth = width;
    int oldHeight = height;
    double relativeWidth, relativeHeight;
    int newX, newY;

    width = w;
    height = h;

    // Move the pinned nodes to adjust to the new size
    ArrayList<Node> pinnedNodes = controller.getGraphPinned();
    if (pinnedNodes != null) {
      for (Node n : pinnedNodes) {
        relativeWidth = (double) n.getX() / oldWidth;
        relativeHeight = (double) n.getY() / oldHeight;
        newX = (int) Math.round(width * relativeWidth);
        newY = (int) Math.round(height * relativeHeight);
        n.setX(newX);
        n.setY(newY);
      }
    }
  }