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);
}
}
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);
}
Aggregations