use of y.view.NodeRealizer in project binnavi by google.
the class ZyGroupNodeRealizer method moveNodes.
private void moveNodes(final Graph2D graph, final NodeCursor nodes, final double dx, final double dy) {
for (; nodes.ok(); nodes.next()) {
final NodeRealizer nr = graph.getRealizer(nodes.node());
if ((nr.getAutoBoundsFeature() != null) && nr.getAutoBoundsFeature().isAutoBoundsEnabled()) {
continue;
}
// Only move the node, if it doesn't have the auto resize feature
// (enabled).
nr.moveBy(dx, dy);
}
}
use of y.view.NodeRealizer in project binnavi by google.
the class MoveFunctions method centerNode.
/**
* Centers the graph on a single node.
*
* Note that the node must be visible. Otherwise the centering operation has no effect.
*
* @param node The node in question.
*/
public static <NodeType extends ZyGraphNode<?> & ISelectableNode & IViewableNode & IYNode & IRawNodeAccessible, EdgeType extends ZyGraphEdge<?, ?, ?>> void centerNode(final AbstractZyGraph<NodeType, ?> graph, final NodeType node) {
Preconditions.checkNotNull(node, "Error: Node argument can't be null");
final NodeRealizer realizer = graph.getGraph().getRealizer(node.getNode());
if (realizer.isVisible()) {
graph.getView().focusView(graph.getView().getZoom(), new Point2D.Double(realizer.getCenterX(), realizer.getCenterY()), graph.getSettings().getLayoutSettings().getAnimateLayout());
graph.updateViews();
}
}
use of y.view.NodeRealizer in project binnavi by google.
the class ZoomFunctions method zoomToNode.
/**
* Zooms to a single node.
*
* @param node The node in question.
*/
public static <NodeType extends ZyGraphNode<?>> void zoomToNode(final AbstractZyGraph<NodeType, ?> graph, final NodeType node) {
Preconditions.checkNotNull(node, "Error: Node argument can't be null");
final NodeRealizer realizer = graph.getGraph().getRealizer(node.getNode());
Preconditions.checkNotNull(realizer, "Error: Node does not belong to the graph");
if (!node.isVisible()) {
graph.showNode(node, true);
}
final double oldZoom = graph.getView().getZoom();
final Point2D oldViewPoint = graph.getView().getViewPoint2D();
graph.getView().zoomToArea(realizer.getCenterX() - realizer.getWidth(), realizer.getCenterY() - realizer.getHeight(), realizer.getWidth() * 2, realizer.getHeight() * 2);
ZoomHelpers.keepZoomValid(graph.getView());
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();
}
use of y.view.NodeRealizer in project binnavi by google.
the class ZyGraphDefaultRenderer method bringNodeToFront.
public void bringNodeToFront(final Node node) {
final Graph2D g = (Graph2D) node.getGraph();
final NodeRealizer r = g.getRealizer(node);
if (r.isSelected()) {
// This does not work properly! Why? NH
for (final NodeCursor nc = g.selectedNodes(); nc.ok(); nc.next()) {
m_nodesInDrawingOrder.remove(nc.node());
m_nodesInDrawingOrder.add(nc.node());
}
} else {
// This seems to work correctly.
m_nodesInDrawingOrder.remove(node);
m_nodesInDrawingOrder.add(node);
}
}
use of y.view.NodeRealizer 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);
}
}
Aggregations