Search in sources :

Example 11 with CTextNode

use of com.google.security.zynamics.binnavi.disassembly.CTextNode in project binnavi by google.

the class PostgreSQLTextNodeLoader method load.

/**
   * Loads the text nodes of a view.
   * 
   * @param provider The connection to the database.
   * @param view The view whose text nodes are loaded.
   * @param nodes The loaded nodes are stored here.
   * 
   * @throws CouldntLoadDataException
   */
public static void load(final AbstractSQLProvider provider, final INaviView view, final List<INaviViewNode> nodes) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "IE02516: provider argument can not be null");
    Preconditions.checkNotNull(view, "IE02517: view argument can not be null");
    Preconditions.checkNotNull(nodes, "IE02518: nodes argument can not be null");
    final Map<Integer, INaviTextNode> commentIdToTextNode = new HashMap<Integer, INaviTextNode>();
    final String query = "SELECT id, comment_id, x, y, width, height, color, selected, visible " + " FROM " + CTableNames.NODES_TABLE + " JOIN " + CTableNames.TEXT_NODES_TABLE + " ON id = node_id " + " WHERE view_id = " + view.getConfiguration().getId();
    try {
        final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query);
        final ResultSet resultSet = statement.executeQuery();
        try {
            while (resultSet.next()) {
                final int nodeId = resultSet.getInt("id");
                Integer commentId = resultSet.getInt("comment_id");
                if (resultSet.wasNull()) {
                    commentId = null;
                }
                final double xPos = resultSet.getDouble("x");
                final double yPos = resultSet.getDouble("y");
                final double width = resultSet.getDouble("width");
                final double height = resultSet.getDouble("height");
                final Color color = new Color(resultSet.getInt("color"));
                final boolean selected = resultSet.getBoolean("selected");
                final boolean visible = resultSet.getBoolean("visible");
                final INaviTextNode textNode = new CTextNode(nodeId, xPos, yPos, width, height, color, selected, visible, new HashSet<CTag>(), null, provider);
                if (commentId != null) {
                    commentIdToTextNode.put(commentId, textNode);
                }
                nodes.add(textNode);
            }
        } finally {
            resultSet.close();
        }
        if (!commentIdToTextNode.isEmpty()) {
            final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToTextNode.keySet());
            for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
                commentIdToTextNode.get(commentIdToComment.getKey()).initializeComment(commentIdToComment.getValue());
            }
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Color(java.awt.Color) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode)

Example 12 with CTextNode

use of com.google.security.zynamics.binnavi.disassembly.CTextNode in project binnavi by google.

the class ZyGraphTest method testAddedTextNode.

@Test
public void testAddedTextNode() {
    assertEquals(7, m_graph.visibleNodeCount());
    assertEquals(89, NodeFunctions.getInvisibleNodes(m_graph).size());
    assertEquals(96, m_graph.getRawView().getNodeCount());
    final CTextNode textNode = m_graph.getRawView().getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Hannes")));
    assertEquals(8, m_graph.visibleNodeCount());
    assertEquals(89, NodeFunctions.getInvisibleNodes(m_graph).size());
    assertEquals(97, m_graph.getRawView().getNodeCount());
    final List<NaviNode> nodes = GraphHelpers.getNodes(m_graph);
    final NaviNode cnn = searchNode(nodes, textNode);
    assertTrue(textNode.isVisible());
    assertEquals(textNode.isVisible(), cnn.isVisible());
    textNode.setVisible(false);
    assertFalse(textNode.isVisible());
    assertEquals(textNode.isVisible(), cnn.isVisible());
    textNode.setVisible(true);
    assertTrue(textNode.isVisible());
    assertEquals(textNode.isVisible(), cnn.isVisible());
    assertFalse(textNode.isSelected());
    assertEquals(textNode.isSelected(), cnn.isSelected());
    textNode.setSelected(false);
    assertFalse(textNode.isSelected());
    assertEquals(textNode.isSelected(), cnn.isSelected());
    textNode.setSelected(true);
    assertTrue(textNode.isSelected());
    assertEquals(textNode.isSelected(), cnn.isSelected());
    assertEquals(textNode.getColor(), cnn.getRealizer().getFillColor());
    textNode.setColor(Color.GREEN);
    assertEquals(Color.GREEN, textNode.getColor());
    assertEquals(textNode.getColor(), cnn.getRealizer().getFillColor());
    textNode.setX(100);
    assertEquals(100, textNode.getX(), 0.1);
    assertEquals(textNode.getX(), cnn.getX(), 0.1);
    textNode.setY(200);
    assertEquals(200, textNode.getY(), 0.1);
    assertEquals(textNode.getY(), cnn.getY(), 0.1);
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) Test(org.junit.Test)

Aggregations

CTextNode (com.google.security.zynamics.binnavi.disassembly.CTextNode)12 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)5 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)5 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)4 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)4 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)4 Test (org.junit.Test)4 CGroupNode (com.google.security.zynamics.binnavi.disassembly.CGroupNode)3 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)3 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)3 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)3 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)3 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)3 ArrayList (java.util.ArrayList)3 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)2 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)2 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)2 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)2 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)2 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)2