Search in sources :

Example 1 with AbstractZyGraphSettings

use of com.google.security.zynamics.zylib.gui.zygraph.AbstractZyGraphSettings in project binnavi by google.

the class CEdgeClickHandler method zoomEdgeNode.

/**
   * Zooms to the source or target of an edge depending on what is farther away from the visible
   * part of the graph.
   * 
   * @param graph The graph the edge belongs to.
   * @param edge The edge that provides the potential zoom targets.
   */
private static void zoomEdgeNode(final AbstractZyGraph<?, ?> graph, final Edge edge, final double mouseX, final double mouseY) {
    assert edge != null;
    final AbstractZyGraphSettings settings = graph.getSettings();
    final boolean animate = settings.getLayoutSettings().getAnimateLayout();
    final EdgeRealizer realizer = graph.getGraph().getRealizer(edge);
    final NodeRealizer sourceRealizer = graph.getGraph().getRealizer(edge.source());
    final NodeRealizer targetRealizer = graph.getGraph().getRealizer(edge.target());
    final double srcPortX = realizer.getSourcePort().getX(sourceRealizer);
    final double srcPortY = realizer.getSourcePort().getY(sourceRealizer);
    final double tarPortX = realizer.getSourcePort().getX(targetRealizer);
    final double tarPortY = realizer.getSourcePort().getY(targetRealizer);
    final double srcLengthA = Math.abs(srcPortX - mouseX);
    final double srcHeightB = Math.abs(srcPortY - mouseY);
    final double tarLengthA = Math.abs(tarPortX - mouseX);
    final double tarHeightB = Math.abs(tarPortY - mouseY);
    final double srcLengthC = Math.sqrt(Math.pow(srcLengthA, 2) + Math.pow(srcHeightB, 2));
    final double tarLengthC = Math.sqrt(Math.pow(tarLengthA, 2) + Math.pow(tarHeightB, 2));
    if (srcLengthC > tarLengthC) {
        final Point2D.Double center = new Point2D.Double(sourceRealizer.getCenterX(), sourceRealizer.getCenterY());
        graph.getView().focusView(graph.getView().getZoom(), center, animate);
    } else {
        final Point2D.Double center = new Point2D.Double(targetRealizer.getCenterX(), targetRealizer.getCenterY());
        graph.getView().focusView(graph.getView().getZoom(), center, animate);
    }
}
Also used : AbstractZyGraphSettings(com.google.security.zynamics.zylib.gui.zygraph.AbstractZyGraphSettings) Point2D(java.awt.geom.Point2D) NodeRealizer(y.view.NodeRealizer) EdgeRealizer(y.view.EdgeRealizer)

Aggregations

AbstractZyGraphSettings (com.google.security.zynamics.zylib.gui.zygraph.AbstractZyGraphSettings)1 Point2D (java.awt.geom.Point2D)1 EdgeRealizer (y.view.EdgeRealizer)1 NodeRealizer (y.view.NodeRealizer)1