Search in sources :

Example 1 with YRectangle

use of y.geom.YRectangle in project binnavi by google.

the class MoveFunctions method centerEdgeLable.

public static <EdgeType extends ZyGraphEdge<?, ?, ?>> void centerEdgeLable(final AbstractZyGraph<?, EdgeType> graph, final EdgeType edge) {
    Preconditions.checkNotNull(edge, "Error: Edge can't be null.");
    if (edge.isVisible()) {
        final YRectangle box = edge.getRealizer().getLabel().getBox();
        final double x = box.x + (box.width / 2);
        final double y = box.y + (box.height / 2);
        graph.getView().focusView(graph.getView().getZoom(), new Point2D.Double(x, y), graph.getSettings().getLayoutSettings().getAnimateLayout());
        graph.updateViews();
    } else {
        throw new IllegalStateException("Error: Edge does not belong to graph.");
    }
}
Also used : Point2D(java.awt.geom.Point2D) YRectangle(y.geom.YRectangle)

Example 2 with YRectangle

use of y.geom.YRectangle in project binnavi by google.

the class ZoomFunctions method zoomToEdgeLabel.

public static <EdgeType extends ZyGraphEdge<?, ?, ?>> void zoomToEdgeLabel(final AbstractZyGraph<?, EdgeType> graph, final EdgeType edge) {
    final EdgeLabel label = edge.getRealizer().getLabel();
    final YRectangle labelBounds = label.getBox();
    final Rectangle viewBounds = graph.getView().getBounds();
    final double widthZoom = viewBounds.getWidth() / labelBounds.getWidth();
    final double heightZoom = viewBounds.getHeight() / labelBounds.getHeight();
    final double oldZoom = graph.getView().getZoom();
    graph.getView().setZoom(0.8 * Math.min(widthZoom, heightZoom));
    ZoomHelpers.keepZoomValid(graph.getView());
    final double newZoom = graph.getView().getZoom();
    graph.getView().setZoom(oldZoom);
    final Point2D newCenter = new Point2D.Double(labelBounds.getX() + (0.5 * labelBounds.getWidth()), labelBounds.getY() + (0.5 * labelBounds.getHeight()));
    graph.getView().focusView(newZoom, newCenter, true);
    graph.updateViews();
}
Also used : Point2D(java.awt.geom.Point2D) YRectangle(y.geom.YRectangle) EdgeLabel(y.view.EdgeLabel) Rectangle(java.awt.Rectangle) YRectangle(y.geom.YRectangle)

Aggregations

Point2D (java.awt.geom.Point2D)2 YRectangle (y.geom.YRectangle)2 Rectangle (java.awt.Rectangle)1 EdgeLabel (y.view.EdgeLabel)1