Search in sources :

Example 1 with ZyProximityNode

use of com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode 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.
                }
            }
        }
    }
}
Also used : GroupNodeRealizer(y.view.hierarchy.GroupNodeRealizer) Set(java.util.Set) IGroupNode(com.google.security.zynamics.zylib.gui.zygraph.nodes.IGroupNode) ZyGraphNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode) Node(y.base.Node) IGroupNode(com.google.security.zynamics.zylib.gui.zygraph.nodes.IGroupNode) ZyProximityNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode) ArrayList(java.util.ArrayList) IZyEditModeListener(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.IZyEditModeListener) NodeLabel(y.view.NodeLabel)

Example 2 with ZyProximityNode

use of com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode 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.
            }
        }
    }
}
Also used : ZyGraphNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode) Node(y.base.Node) ZyProximityNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode)

Example 3 with ZyProximityNode

use of com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode in project binnavi by google.

the class CSelectionMode method selectionBoxAction.

@Override
protected void selectionBoxAction(final Rectangle rect, final boolean shiftMode) {
    m_graph.getGraph().firePreEvent();
    final NodeList selectedNodes = new NodeList();
    for (final NodeCursor node = m_graph.getGraph().nodes(); node.ok(); node.next()) {
        final NodeType zyNode = m_graph.getNode(node.node());
        if ((zyNode == null) || (zyNode instanceof ZyProximityNode<?>)) {
            continue;
        }
        if (belongsToSelection(node.node(), rect)) {
            selectedNodes.add(node.node());
        }
    }
    if (((getLastDragEvent().getModifiersEx() & InputEvent.CTRL_DOWN_MASK) == 0) && ((getLastDragEvent().getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == 0)) {
        m_graph.getGraph().unselectAll();
    }
    for (final Object nodeObject : selectedNodes) {
        final Node node = (Node) nodeObject;
        m_graph.getGraph().setSelected(node, true);
    }
    for (final EdgeCursor ec = m_graph.getGraph().selectedEdges(); ec.ok(); ec.next()) {
        final Edge e = ec.edge();
        final Node src = e.source();
        final Node dst = e.target();
        if (!m_graph.getGraph().getRealizer(src).isSelected() && !m_graph.getGraph().getRealizer(dst).isSelected()) {
            m_graph.getGraph().getRealizer(e).setSelected(false);
        }
    }
    m_graph.getGraph().firePostEvent();
    m_graph.getGraph().updateViews();
}
Also used : EdgeCursor(y.base.EdgeCursor) NodeList(y.base.NodeList) ZyGraphNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode) Node(y.base.Node) ZyProximityNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode) NodeCursor(y.base.NodeCursor) Edge(y.base.Edge) ZyProximityNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode)

Aggregations

ZyGraphNode (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode)3 ZyProximityNode (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode)3 Node (y.base.Node)3 IGroupNode (com.google.security.zynamics.zylib.gui.zygraph.nodes.IGroupNode)1 IZyEditModeListener (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.IZyEditModeListener)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Edge (y.base.Edge)1 EdgeCursor (y.base.EdgeCursor)1 NodeCursor (y.base.NodeCursor)1 NodeList (y.base.NodeList)1 NodeLabel (y.view.NodeLabel)1 GroupNodeRealizer (y.view.hierarchy.GroupNodeRealizer)1