use of y.base.Node in project binnavi by google.
the class View2DTest method setUp.
@Before
public void setUp() throws CouldntLoadDataException, LoadCancelledException, FileReadException {
ConfigManager.instance().read();
final MockDatabase database = new MockDatabase();
final CModule module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
database.getContent().addModule(module);
manager.addDatabase(database);
module.load();
m_view = module.getContent().getViewContainer().createView("name", "description");
final ZyGraphViewSettings settings = new ZyGraphViewSettings(new CallGraphSettingsConfigItem());
settings.getLayoutSettings().setDefaultGraphLayout(LayoutStyle.CIRCULAR);
final ZyGraph2DView g2dView = new ZyGraph2DView();
final LinkedHashMap<Node, NaviNode> nodeMap = new LinkedHashMap<Node, NaviNode>();
final LinkedHashMap<Edge, NaviEdge> edgeMap = new LinkedHashMap<Edge, NaviEdge>();
final Node node1 = g2dView.getGraph2D().createNode();
final CTextNode rawNode1 = m_view.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " TEXT NODE ")));
nodeMap.put(node1, new NaviNode(node1, new ZyNormalNodeRealizer<NaviNode>(new ZyLabelContent(null)), rawNode1));
final Node node2 = g2dView.getGraph2D().createNode();
final CTextNode rawNode2 = m_view.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " TEXT COMMENT ")));
nodeMap.put(node2, new NaviNode(node2, new ZyNormalNodeRealizer<NaviNode>(new ZyLabelContent(null)), rawNode2));
final Edge edge = g2dView.getGraph2D().createEdge(node1, node2);
final INaviEdge rawEdge = m_view.getContent().createEdge(rawNode1, rawNode2, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_CONDITIONAL_FALSE);
edgeMap.put(edge, new NaviEdge(nodeMap.get(node1), nodeMap.get(node2), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge));
final ZyGraph graph = new ZyGraph(m_view, nodeMap, edgeMap, settings, g2dView);
m_view2d = new View2D(database, new CModuleContainer(database, module), graph, pluginInterface);
}
use of y.base.Node in project binnavi by google.
the class CDefaultNodeClickedLeftAction method execute.
@Override
public void execute(final CNodeClickedLeftState<NodeType, EdgeType> state, final MouseEvent event) {
CMouseCursorHelper.setDefaultCursor(state.getGraph());
final AbstractZyGraph<NodeType, EdgeType> graph = state.getGraph();
final Node n = state.getNode();
final NodeType node = graph.getNode(n);
final double x = graph.getEditMode().translateX(event.getX());
final double y = graph.getEditMode().translateY(event.getY());
final CStateFactory<NodeType, EdgeType> factory = state.getStateFactory();
if (ProximityHelper.isProximityNode(state.getGraph().getGraph(), n)) {
CEditNodeHelper.removeCaret(graph);
final ZyProximityNode<?> proximityNode = ProximityHelper.getProximityNode(graph.getGraph(), n);
for (final IZyEditModeListener<NodeType, EdgeType> listener : factory.getListeners()) {
try {
listener.proximityBrowserNodeClicked(proximityNode, event, x, y);
} catch (final Exception exception) {
// TODO: (timkornau): implement logging here.
}
}
} else if ((node != null) && (node.getRawNode() instanceof IGroupNode)) {
CEditNodeHelper.removeCaret(graph);
final GroupNodeRealizer gnr = (GroupNodeRealizer) graph.getGraph().getRealizer(node.getNode());
final NodeLabel handle = gnr.getStateLabel();
if (handle.getBox().contains(x, y)) {
// Clicks on the X in the group node corner
toggleGroup(node);
} else if (SwingUtilities.isLeftMouseButton(event)) {
if ((event.getClickCount() == 2) && event.isControlDown()) {
// CTRL-LEFT-DOUBLECLICK
toggleGroup(node);
} else if (event.getClickCount() == 1) {
CGraphSelector.selectNode(graph, node, event.isShiftDown());
}
}
} else {
if (node != null) {
if (graph.getEditMode().getLabelEventHandler().isActiveLabel(node.getRealizer().getNodeContent())) {
CEditNodeHelper.setCaretEnd(graph, state.getNode(), event);
} else {
if (graph.getEditMode().getLabelEventHandler().isActive()) {
CEditNodeHelper.removeCaret(graph);
}
final Set<NodeType> selectedNodes = graph.getSelectedNodes();
if (event.isShiftDown() && (selectedNodes.size() >= 1)) {
CGraphSelector.selectPath(graph, new ArrayList<NodeType>(selectedNodes), node);
} else if (event.isControlDown()) {
graph.selectNode(node, !node.isSelected());
} else {
final Collection<NodeType> toUnselect = new ArrayList<NodeType>(graph.getNodes());
toUnselect.remove(node);
final Collection<NodeType> toSelect = new ArrayList<NodeType>();
toSelect.add(node);
graph.selectNodes(toSelect, toUnselect);
}
}
for (final IZyEditModeListener<NodeType, EdgeType> listener : factory.getListeners()) {
// ESCA-JAVA0166: Catch Exception because we are calling a listener function
try {
listener.nodeClicked(node, event, x, y);
} catch (final Exception exception) {
// TODO: (timkornau): implement logging here.
}
}
}
}
}
use of y.base.Node in project binnavi by google.
the class CDefaultNodeClickedRightAction method execute.
@Override
public void execute(final CNodeClickedRightState<NodeType, EdgeType> state, final MouseEvent event) {
CMouseCursorHelper.setDefaultCursor(state.getGraph());
final AbstractZyGraph<NodeType, EdgeType> graph = state.getGraph();
final Node yNode = state.getNode();
final NodeType node = graph.getNode(yNode);
final double x = graph.getEditMode().translateX(event.getX());
final double y = graph.getEditMode().translateY(event.getY());
if (graph.getEditMode().getLabelEventHandler().isActive() && graph.getEditMode().getLabelEventHandler().hasEmptySelection()) {
CEditNodeHelper.removeCaret(graph);
}
if (node == null) {
// Proximity node was clicked
final ZyProximityNode<?> proximityNode = ProximityHelper.getProximityNode(graph.getGraph(), yNode);
for (final IZyEditModeListener<NodeType, EdgeType> listener : state.getStateFactory().getListeners()) {
try {
listener.proximityBrowserNodeClicked(proximityNode, event, x, y);
} catch (final Exception exception) {
// TODO: (timkornau): implement logging here.
}
}
} else {
for (final IZyEditModeListener<NodeType, EdgeType> listener : state.getStateFactory().getListeners()) {
try {
listener.nodeClicked(node, event, x, y);
} catch (final Exception exception) {
// TODO: (timkornau): implement logging here.
}
}
}
}
use of y.base.Node in project binnavi by google.
the class CGraphSelector method selectPath.
/**
* Function which handles the selection of nodes in a path finding scenario. The function performs
* four BFS runs: BFS 1 searches for all successors of the start nodes. BFS 2 searches for all
* predecessors of the end nodes. BFS 2 searches for all predecessors of the start nodes. BFS 4
* searches for all successors of the end nodes.
*
* These four BFS runs are used in two sets: Set 1 is intersect of nodes reached through (BFS 1,
* BFS 2). Set 2 is intersect of nodes reached through (BFS 3, BFS 4).
*
* Therefore Set 1 represents all nodes on paths if the set of start nodes contains parents of the
* newly selected node and Set 2 represents all nodes on paths if the set of start nodes contains
* child nodes of the newly selected node.
*
*
* @param graph The graph in which the selection takes place.
* @param alreadySelectedNodes The List of nodes already selected.
* @param newlySelectedNode The node which is newly selected.
*/
@SuppressWarnings("unchecked")
public static <NodeType extends ZyGraphNode<?>> void selectPath(final AbstractZyGraph<NodeType, ?> graph, final ArrayList<NodeType> alreadySelectedNodes, final NodeType newlySelectedNode) {
final Function<NodeType, Node> function = new Function<NodeType, Node>() {
@Override
public Node apply(final NodeType input) {
return input.getNode();
}
};
final Collection<Node> foo = Collections2.transform(alreadySelectedNodes, function);
final NodeList startNodes = new NodeList(foo.iterator());
final NodeList endNodes = new NodeList(newlySelectedNode.getNode());
final Set<Node> startSuccSet = new HashSet<Node>();
final NodeList[] nodeListsStartSucc = Bfs.getLayers(graph.getGraph(), startNodes, Bfs.DIRECTION_SUCCESSOR, graph.getGraph().createNodeMap(), 0);
for (final NodeList nodeList : nodeListsStartSucc) {
startSuccSet.addAll(nodeList);
}
final Set<Node> endPredSet = new HashSet<Node>();
final NodeList[] nodeListsEndPred = Bfs.getLayers(graph.getGraph(), endNodes, Bfs.DIRECTION_PREDECESSOR, graph.getGraph().createNodeMap(), 0);
for (final NodeList nodeList : nodeListsEndPred) {
endPredSet.addAll(nodeList);
}
final SetView<Node> startBeforeEndSetView = Sets.intersection(startSuccSet, endPredSet);
if (!startBeforeEndSetView.isEmpty()) {
for (final Node node : startBeforeEndSetView) {
graph.getGraph().setSelected(node, true);
}
}
final Set<Node> startPredSet = new HashSet<Node>();
final NodeList[] nodeListsStartPred = Bfs.getLayers(graph.getGraph(), startNodes, Bfs.DIRECTION_PREDECESSOR, graph.getGraph().createNodeMap(), 0);
for (final NodeList nodeList : nodeListsStartPred) {
startPredSet.addAll(nodeList);
}
final Set<Node> endSuccSet = new HashSet<Node>();
final NodeList[] nodeListsEndSucc = Bfs.getLayers(graph.getGraph(), endNodes, Bfs.DIRECTION_SUCCESSOR, graph.getGraph().createNodeMap(), 0);
for (final NodeList nodeList : nodeListsEndSucc) {
endSuccSet.addAll(nodeList);
}
final SetView<Node> endBeforeStartSetView = Sets.intersection(startPredSet, endSuccSet);
if (!endBeforeStartSetView.isEmpty()) {
for (final Node node : endBeforeStartSetView) {
graph.getGraph().setSelected(node, true);
}
}
}
use of y.base.Node in project binnavi by google.
the class CNodeEditState method mousePressed.
@Override
public IMouseStateChange mousePressed(final MouseEvent event, final AbstractZyGraph<?, ?> graph) {
final double x = graph.getEditMode().translateX(event.getX());
final double y = graph.getEditMode().translateY(event.getY());
final HitInfo hitInfo = graph.getGraph().getHitInfo(x, y);
if (hitInfo.hasHitNodes()) {
final Node n = hitInfo.getHitNode();
if (SwingUtilities.isLeftMouseButton(event) && !event.isAltDown()) {
if (n == m_node) {
if (!m_isDragging) {
// Change caret
CEditNodeHelper.setCaretStart(graph, n, event);
} else {
m_isDragging = false;
}
return new CStateChange(this, false);
} else {
m_factory.createNodeEditExitState(m_node, event);
return new CStateChange(m_factory.createNodePressedLeftState(n, event), true);
}
} else if (SwingUtilities.isRightMouseButton(event)) {
if (n == m_node) {
return new CStateChange(this, false);
} else {
m_factory.createNodeEditExitState(m_node, event);
return new CStateChange(m_factory.createNodePressedRightState(n, event), true);
}
} else if (SwingUtilities.isMiddleMouseButton(event) || (event.isAltDown() && SwingUtilities.isLeftMouseButton(event))) {
if (n == m_node) {
if (!m_isDragging) {
// Change caret
CEditNodeHelper.setCaretStart(graph, n, event);
} else {
m_isDragging = false;
}
return new CStateChange(this, false);
} else {
m_factory.createNodeEditExitState(m_node, event);
return new CStateChange(m_factory.createNodePressedMiddleState(n, event), true);
}
} else {
return new CStateChange(this, false);
}
} else if (hitInfo.hasHitNodeLabels()) {
throw new IllegalStateException();
} else if (hitInfo.hasHitEdges()) {
m_factory.createNodeEditExitState(m_node, event);
return new CStateChange(m_factory.createEdgePressedLeftState(hitInfo.getHitEdge(), event), true);
} else if (hitInfo.hasHitEdgeLabels()) {
m_factory.createNodeEditExitState(m_node, event);
return new CStateChange(m_factory.createEdgePressedLeftState(hitInfo.getHitEdgeLabel().getEdge(), event), true);
} else if (hitInfo.hasHitBends()) {
m_factory.createNodeEditExitState(m_node, event);
return new CStateChange(m_factory.createBendPressedLeftState(hitInfo.getHitBend(), event), true);
} else if (hitInfo.hasHitPorts()) {
m_factory.createNodeEditExitState(m_node, event);
return new CStateChange(m_factory.createDefaultState(), true);
} else {
// User left-pressed the background.
m_factory.createNodeEditExitState(m_node, event);
return new CStateChange(m_factory.createBackgroundPressedLeftState(event), true);
}
}
Aggregations