use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge in project binnavi by google.
the class CSearchResultsDialog method setResults.
/**
* Fills the search results table model with search results data.
*
* @param results The search results data.
*/
private void setResults(final List<SearchResult> results) {
final Object[][] data = new Object[results.size()][1];
int counter = 0;
for (final SearchResult result : results) {
if (result.getObject() instanceof NaviNode) {
final NaviNode node = (NaviNode) result.getObject();
final ZyLabelContent labelContent = node.getRealizer().getNodeContent();
final String lineText = labelContent.getLineContent(result.getLine()).getText();
data[counter++][0] = lineText;
} else if (result.getObject() instanceof NaviEdge) {
final NaviEdge edge = (NaviEdge) result.getObject();
final ZyLabelContent labelContent = edge.getLabelContent();
final String lineText = labelContent.getLineContent(result.getLine()).getText();
data[counter++][0] = lineText;
}
}
m_table.setModel(new CResultsTableModel(data, new String[] { "Result" }));
m_resultsLabel.setText(String.format("%d search results", data.length));
}
use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge in project binnavi by google.
the class GraphSearcher method search.
/**
* Searches through a list of nodes and edges while considering the active search settings.
*
* @param nodes The nodes to search through.
* @param edges The edges to search through.
* @param searchString The string to search for.
*/
public void search(final List<NaviNode> nodes, final List<NaviEdge> edges, final String searchString) {
m_lastSearchString = searchString;
clearResults();
final List<NaviNode> filteredNodes = CResultFilter.filteredNodes(nodes, m_settings.isOnlySelected(), m_settings.isOnlyVisible());
final List<NaviEdge> filteredEdges = CResultFilter.filteredEdges(edges, m_settings.isOnlySelected(), m_settings.isOnlyVisible());
searchAll(filteredNodes, filteredEdges, searchString);
Collections.sort(m_results, new CSearchResultComparator());
m_cursor.setResults(m_results);
}
use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge in project binnavi by google.
the class ZyEdgeBuilder method convertEdge.
/**
* Creates a graph node from a raw edge.
*
* @param edge The raw edge that provides the underlying data.
* @param sourceNode Source node of the edge.
* @param targetNode Target node of the edge.
* @param graph2D The graph object where the edge is created.
* @param adjustColors Flag that indicates whether the initial color of all edges should be
* recalculated according to their type.
*
* @return The created YNode/NaviNode pair.
*/
public static Pair<Edge, NaviEdge> convertEdge(final INaviEdge edge, final NaviNode sourceNode, final NaviNode targetNode, final Graph2D graph2D, final boolean adjustColors) {
// Build the edge label if necessary
final ZyLabelContent content = ZyEdgeBuilder.buildContent(edge);
// Create the edge realizer of the new edge
final ZyEdgeRealizer<NaviEdge> realizer = new ZyEdgeRealizer<NaviEdge>(content, new CEdgeUpdater(edge));
// Create the edge
final Edge g2dEdge = graph2D.createEdge(sourceNode.getNode(), targetNode.getNode(), realizer);
if (adjustColors) {
EdgeInitializer.adjustColor(edge);
}
EdgeInitializer.initializeEdgeType(edge, realizer);
graph2D.getRealizer(g2dEdge).setLineColor(edge.getColor());
// Associate user data with the edge
final NaviEdge zyEdge = new NaviEdge(sourceNode, targetNode, g2dEdge, realizer, edge);
NaviNode.link(sourceNode, targetNode);
final ZyEdgeData<NaviEdge> data = new ZyEdgeData<NaviEdge>(zyEdge);
realizer.setUserData(data);
return new Pair<Edge, NaviEdge>(g2dEdge, zyEdge);
}
use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge 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 com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge in project binnavi by google.
the class CSearchExecuter method startNewSearch.
/**
* Cycles through an existing search operation.
*
* @param parent Parent window used for dialogs.
* @param editor Combobox editor whose color is changed depending on the search result.
* @param graph Graph to search through.
* @param searcher Executes the search over the graph.
* @param searchString The string to search for.
* @param zoomToResult True, to zoom to a result. False, to move without zooming.
*/
private static void startNewSearch(final Window parent, final ComboBoxEditor editor, final ZyGraph graph, final GraphSearcher searcher, final String searchString, final boolean zoomToResult) {
try {
// Search for all occurrences
searcher.search(GraphHelpers.getNodes(graph), GraphHelpers.getEdges(graph), searchString);
if (searcher.getResults().isEmpty()) {
editor.getEditorComponent().setBackground(BACKGROUND_COLOR_FAIL);
} else {
editor.getEditorComponent().setBackground(BACKGROUND_COLOR_SUCCESS);
}
// Immediately display all search occurrences
for (final SearchResult result : searcher.getResults()) {
if (result.getObject() instanceof NaviNode) {
final NaviNode node = (NaviNode) result.getObject();
node.setBackgroundColor(result.getLine(), result.getPosition(), result.getLength(), Color.YELLOW);
} else if (result.getObject() instanceof NaviEdge) {
final NaviEdge edge = (NaviEdge) result.getObject();
edge.getLabelContent().getLineContent(result.getLine()).setBackgroundColor(result.getPosition(), result.getLength(), Color.YELLOW);
}
}
final SearchResult result = searcher.getCursor().current();
if (result != null) {
if (result.getObject() instanceof NaviNode) {
ZyGraphHelpers.centerNode(graph, (NaviNode) result.getObject(), zoomToResult);
} else if (result.getObject() instanceof NaviEdge) {
ZyGraphHelpers.centerEdgeLabel(graph, (NaviEdge) result.getObject(), zoomToResult);
}
}
graph.updateGraphViews();
} catch (final PatternSyntaxException exception) {
// Do not bother to log this
CMessageBox.showInformation(parent, String.format("Invalid Regular Expression '%s'", searchString));
}
}
Aggregations