Search in sources :

Example 11 with ZyLabelContent

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

the class CCursorKeyBehavior method handleNotShiftAndCtrl.

protected void handleNotShiftAndCtrl(final int xdelta, final int ydelta) {
    final ZyLabelContent labelContent = getLabelContent();
    int caretStartPos_X = getCaretStartPosX();
    int mousePressed_X = getCaretMousePressedX();
    final int mousePressed_Y = getCaretMousePressedY();
    int caretEndPos_X = getCaretEndPosX();
    int mouseReleased_X = getCaretMouseReleasedX();
    final int mouseReleased_Y = getCaretMouseReleasedY();
    if (xdelta != 0) {
        final ZyLineContent lineContent = labelContent.getLineContent(mouseReleased_Y);
        final String s = lineContent.getText() + " ";
        if (xdelta > 0) {
            final boolean firstIsSpace = s.charAt(caretEndPos_X) == ' ';
            int endindex = 0;
            for (int i = caretEndPos_X; i < s.length(); ++i) {
                endindex = i;
                if (firstIsSpace) {
                    if (s.charAt(i) != ' ') {
                        break;
                    }
                } else {
                    if (s.charAt(i) == ' ') {
                        break;
                    }
                }
            }
            if ((lineContent.getText().endsWith("\n") || lineContent.getText().endsWith("\r")) && (lineContent.getText().length() == endindex)) {
                endindex -= 1;
            }
            caretStartPos_X = endindex;
            mousePressed_X = endindex;
            mouseReleased_X = endindex;
            caretEndPos_X = endindex;
        } else if (xdelta < 0) {
            if (caretEndPos_X == 0) {
                return;
            }
            final boolean firstIsSpace = s.charAt(caretEndPos_X - 1) == ' ';
            int startindex = caretEndPos_X - 1;
            for (int i = caretEndPos_X - 1; i >= 0; --i) {
                if (firstIsSpace) {
                    if (s.charAt(i) != ' ') {
                        break;
                    }
                } else {
                    if (s.charAt(i) == ' ') {
                        break;
                    }
                }
                startindex = i;
            }
            caretStartPos_X = startindex;
            mousePressed_X = startindex;
            mouseReleased_X = startindex;
            caretEndPos_X = startindex;
        }
        mouseReleased_X = correctMouseReleasedX(mouseReleased_X, mouseReleased_Y, mousePressed_Y);
        setCaret(caretStartPos_X, mousePressed_X, mousePressed_Y, caretEndPos_X, mouseReleased_X, mouseReleased_Y);
    } else if (ydelta != 0) {
        handleNotShiftAndNotCtrl(0, ydelta);
    }
}
Also used : ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)

Example 12 with ZyLabelContent

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

the class CDefaultNodePressedLeftAction method execute.

@Override
public void execute(final CNodePressedLeftState<NodeType, EdgeType> state, final MouseEvent event) {
    final AbstractZyGraph<NodeType, EdgeType> graph = state.getGraph();
    final NodeType draggedNode = graph.getNode(state.getNode());
    if (draggedNode != null) {
        final ZyLabelContent labelContent = draggedNode.getRealizer().getNodeContent();
        if (graph.getEditMode().getLabelEventHandler().isActiveLabel(labelContent)) {
            CEditNodeHelper.setCaretStart(graph, state.getNode(), event);
            CEditNodeHelper.setCaretEnd(graph, state.getNode(), event);
        } else {
            CEditNodeHelper.removeCaret(graph);
        }
    } else {
        CEditNodeHelper.removeCaret(graph);
    }
}
Also used : ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent)

Example 13 with ZyLabelContent

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

the class ClipboardCopier method copyToClipboard.

/**
   * Copies the text content of a node to the clip board.
   * 
   * @param node The node to copy to the clip board.
   */
public static void copyToClipboard(final ZyGraphNode<?> node) {
    Preconditions.checkNotNull(node, "Error: Node argument can not be null");
    final IZyNodeRealizer realizer = node.getRealizer();
    final ZyLabelContent content = realizer.getNodeContent();
    if (content.isSelectable()) {
        final ZyLabelContent zyContent = content;
        final StringBuilder textBuilder = new StringBuilder();
        for (final ZyLineContent zyLineContent : zyContent) {
            textBuilder.append(zyLineContent.getText());
            //$NON-NLS-1$
            textBuilder.append("\n");
        }
        ClipboardHelpers.copyToClipboard(textBuilder.toString());
    }
}
Also used : ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) IZyNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.IZyNodeRealizer) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)

Example 14 with ZyLabelContent

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

the class CEndKeyBehavior method updateCaret.

@Override
protected void updateCaret() {
    if (!isShiftPressed() && !isCtrlPressed()) {
        final int yPos = getCaretMouseReleasedY();
        final int lastXPos = getLastLineXPos(yPos);
        setCaret(lastXPos, lastXPos, yPos, lastXPos, lastXPos, yPos);
    } else if (isShiftPressed() && !isCtrlPressed()) {
        final int ypos = getCaretMouseReleasedY();
        final int lastXPos = getLineContent(ypos).getTextLayout().getCharacterCount();
        int mouseReleased_X = lastXPos;
        final ZyLineContent lineContent = getLineContent(getCaretMouseReleasedY());
        final boolean noReturn = getCaretEndPosX() == lineContent.getText().length();
        final boolean withReturn = lineContent.getText().endsWith("\n") && (getCaretEndPosX() == (lineContent.getText().length() - 1));
        final boolean withCReturn = lineContent.getText().endsWith("\r") && (getCaretEndPosX() == (lineContent.getText().length() - 1));
        if (noReturn || withReturn || withCReturn) {
            mouseReleased_X = getMaxLineLength(getCaretMousePressedY(), getCaretMouseReleasedY());
        }
        if ((lineContent.getText().endsWith("\n") || lineContent.getText().endsWith("\r")) && (mouseReleased_X > 0)) {
            mouseReleased_X -= 1;
        }
        setCaret(getCaretStartPosX(), getCaretMousePressedX(), getCaretMousePressedY(), lastXPos, mouseReleased_X, ypos);
    } else if (!isShiftPressed() && isCtrlPressed()) {
        final ZyLabelContent labelContent = getLabelContent();
        final int lastXPos = labelContent.getLineContent(labelContent.getLineCount() - 1).getText().length();
        final int lastYPos = labelContent.getLineCount() - 1;
        setCaret(lastXPos, lastXPos, lastYPos, lastXPos, lastXPos, lastYPos);
    } else if (isShiftPressed() && isCtrlPressed()) {
        final int lastYPos = getLabelContent().getLineCount() - 1;
        final int lastXPos = getLabelContent().getLineContent(lastYPos).getText().length();
        setCaret(getCaretStartPosX(), getCaretMousePressedX(), getCaretMousePressedY(), lastXPos, lastXPos, lastYPos);
    }
}
Also used : ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)

Example 15 with ZyLabelContent

use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent 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);
}
Also used : ZyGraphViewSettings(com.google.security.zynamics.binnavi.ZyGraph.ZyGraphViewSettings) CallGraphSettingsConfigItem(com.google.security.zynamics.binnavi.config.CallGraphSettingsConfigItem) ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) Node(y.base.Node) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CModuleContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) LinkedHashMap(java.util.LinkedHashMap) View2D(com.google.security.zynamics.binnavi.yfileswrap.API.disassembly.View2D) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) ZyEdgeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) ZyNormalNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) ZyGraph2DView(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.ZyGraph2DView) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Edge(y.base.Edge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) Before(org.junit.Before)

Aggregations

ZyLabelContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent)33 IZyNodeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.IZyNodeRealizer)10 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)6 NaviEdge (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge)5 ZyLineContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)5 ZyEdgeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer)5 Edge (y.base.Edge)4 Node (y.base.Node)4 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)3 CTextNode (com.google.security.zynamics.binnavi.disassembly.CTextNode)3 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)3 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)3 CDefaultLabelEventHandler (com.google.security.zynamics.zylib.gui.zygraph.CDefaultLabelEventHandler)3 ZyNormalNodeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer)3 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)2 SearchResult (com.google.security.zynamics.binnavi.Gui.GraphWindows.Searchers.Text.Model.SearchResult)2 CallGraphSettingsConfigItem (com.google.security.zynamics.binnavi.config.CallGraphSettingsConfigItem)2 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)2 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)2 ZyGraph (com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph)2