Main interface for accessing the graph structure and develop algorithms.
A graph object belongs to a graph model, which really contains the data. Graph objects are therefore only accessors, with all convinient methods to read and modify the structure. Hence, multiple Graph
objects can exists.
Get current graph
GraphController graphController = Lookup.getDefault().lookup(GraphController.class); GraphModel model = graphController.getModel(); Graph graph = model.getGraph();
Note: This shows how to get the complete graph, for getting only the currently visualized graph, call
model.getGraphVisible()
instead.
Graph Locking
Graph structure possess a locking mechanism that avoids multiple threads to modify the structure concurrently. However, several readers are allowed.
There is two different way to perform read locking:
- Manually by calling
readLock()
and readUnlock()
- Structure is automatically locked when you read the various
NodeIterable
and EdgeIterable
Be always sure you don't leave the structure blocked. use
readUnlockAll()
to release all the locks.
Note: Write locking is automatically done when modifying th graph (add, remove, ...).
@author Mathieu Bastian