public static <NodeType extends ZyGraphNode<?>> void zoomToNodes(
      final AbstractZyGraph<NodeType, ?> graph, final Collection<NodeType> nodes) {
    Preconditions.checkNotNull(nodes, "Error: nodes argument can not be null");

    if (nodes.size() == 0) {
      return;
    }

    final double oldZoom = graph.getView().getZoom();
    final Point2D oldViewPoint = graph.getView().getViewPoint2D();

    final Rectangle2D box = GraphHelpers.calculateBoundingBox(nodes);
    graph.getView().zoomToArea(box.getX(), box.getY(), box.getWidth(), box.getHeight());
    ZoomHelpers.keepZoomValid(graph.getView());
    graph.zoomOut();

    final double newZoom = graph.getView().getZoom();
    final Point2D newCenter = graph.getView().getCenter();

    graph.getView().setZoom(oldZoom);
    graph.getView().setViewPoint((int) oldViewPoint.getX(), (int) oldViewPoint.getY());

    graph
        .getView()
        .focusView(newZoom, newCenter, graph.getSettings().getLayoutSettings().getAnimateLayout());

    graph.updateViews();
  }
Zooms the graph so far that all nodes in the list are visible.

@param nodes List of nodes that should be displayed as big as possible.
java/zylib/src/main/java/com/google/security/zynamics/zylib/yfileswrap/gui/zygraph/functions/ZoomFunctions.java