Class Viewer
public abstract class Viewer extends Object
The viewer class is in charge of maintaining :
- A "graphic graph" (a special graph that internally stores the graph under the form of style sets of "graphic" elements, suitable to draw the graph, but not to adapted to used it as a general graph),
- The eventual proxy pipe from which the events come from (but graph events can come from any kind of source),
- A default view, and eventually more views on the graphic graph.
- A flag that allows to repaint the view only if the graphic graph changed.
The graphic graph can be created by the viewer or given at construction (to share it with another viewer).
Once created, the viewer runs in a loop inside the UI thread. You cannot
call methods on it directly if you are not in this thread. The only
operation that you can use in other threads is the constructor, the
addView(View)
, removeView(String)
and the close()
methods. Other methods are not protected from concurrent accesses.
Some constructors allow a ProxyPipe
as argument. If given, the
graphic graph is made listener of this pipe and the pipe is "pumped" during
the view loop. This allows to run algorithms on a graph in the main thread
(or any other thread) while letting the viewer run in the ui thread.
Be very careful: due to the nature of graph events in GraphStream, the viewer
is not aware of events that occured on the graph before its creation.
There is a special mechanism that replay the graph if you use a proxy pipe or
if you pass the graph directly. However, when you create the viewer by
yourself and only pass a Source
, the viewer will not display
the events that occured on the source before it is connected to it.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Viewer.CloseFramePolicy
What to do when a view frame is closed.static class
Viewer.ThreadingModel
How does the viewer synchronise its internal graphic graph with the graph displayed. -
Constructor Summary
Constructors Constructor Description Viewer()
-
Method Summary
Modifier and Type Method Description View
addDefaultView(boolean openInAFrame)
Build the default graph view and insert it.View
addView(String id, GraphRenderer<?,?> renderer)
Add a new default view with a specific renderer.View
addView(String id, GraphRenderer<?,?> renderer, boolean openInAFrame)
Same asaddView(String, GraphRenderer)
but allows to specify that the view uses a frame or not.View
addView(View view)
Add a view using its identifier.abstract void
close()
Close definitively this viewer and all its views.void
computeGraphMetrics()
Compute the overall bounds of the graphic graph according to the nodes and sprites positions.void
disableAutoLayout()
Disable the running automatic layout process, if any.void
enableAutoLayout()
Launch an automatic layout process that will position nodes in the background.void
enableAutoLayout(Layout layoutAlgorithm)
Launch an automatic layout process that will position nodes in the background.void
enableXYZfeedback(boolean on)
Enable or disable the "xyz" attribute change when a node is moved in the views.Viewer.CloseFramePolicy
getCloseFramePolicy()
What to do when a frame is closed.abstract String
getDefaultID()
Name of the default view.View
getDefaultView()
The default view.GraphicGraph
getGraphicGraph()
The underlying graphic graph.View
getView(String id)
The view that correspond to the given identifier.abstract void
init(GraphicGraph graph, ProxyPipe ppipe, Source source)
Initialise the viewer.abstract GraphRenderer<?,?>
newDefaultGraphRenderer()
Create a new instance of the default graph renderer.String
newGGId()
Create a new unique identifier for a graph.ProxyPipe
newThreadProxyOnGraphicGraph()
New proxy pipe on events coming from the viewer through a thread.ViewerPipe
newViewerPipe()
New viewer pipe on the events coming from the viewer through a thread.void
removeView(String id)
Remove a view.void
replayGraph(Graph graph)
Dirty replay of the graph.void
setCloseFramePolicy(Viewer.CloseFramePolicy policy)
What to do when the frame containing one or more views is closed.
-
Constructor Details
-
Viewer
public Viewer()
-
-
Method Details
-
getDefaultID
Name of the default view. -
newGGId
Create a new unique identifier for a graph.- Returns:
- The new identifier.
-
init
Initialise the viewer.- Parameters:
graph
- The graphic graph.ppipe
- The source of events from another thread or machine (null if source != null).source
- The source of events from this thread (null if ppipe != null).
-
close
public abstract void close()Close definitively this viewer and all its views. -
getCloseFramePolicy
What to do when a frame is closed. -
newThreadProxyOnGraphicGraph
New proxy pipe on events coming from the viewer through a thread.- Returns:
- The new proxy pipe.
-
newViewerPipe
New viewer pipe on the events coming from the viewer through a thread.- Returns:
- The new viewer pipe.
-
getGraphicGraph
The underlying graphic graph. Caution : Use the returned graph only in the UI thread !! -
getView
The view that correspond to the given identifier.- Parameters:
id
- The view identifier.- Returns:
- A view or null if not found.
-
getDefaultView
The default view. This is a shortcut to a call togetView(String)
with#DEFAULT_VIEW_ID
as parameter.- Returns:
- The default view or null if no default view has been installed.
-
newDefaultGraphRenderer
Create a new instance of the default graph renderer. -
addDefaultView
Build the default graph view and insert it. The view identifier is#DEFAULT_VIEW_ID
. You can request the view to be open in its own frame.- Parameters:
openInAFrame
- It true, the view is placed in a frame, else the view is only created and you must embed it yourself in your application.
-
addView
Add a view using its identifier. If there was already a view with this identifier, it is closed and returned (if different of the one added).- Parameters:
view
- The view to add.- Returns:
- The old view that was at the given identifier, if any, else null.
-
addView
Add a new default view with a specific renderer. If a view with the same id exists, it is removed and closed. By default the view is open in a frame.- Parameters:
id
- The new view identifier.renderer
- The renderer to use.- Returns:
- The created view.
-
addView
Same asaddView(String, GraphRenderer)
but allows to specify that the view uses a frame or not.- Parameters:
id
- The new view identifier.renderer
- The renderer to use.openInAFrame
- If true the view is open in a frame, else the returned view is a JPanel that can be inserted in a GUI.- Returns:
- The created view.
-
removeView
Remove a view. The view is not closed.- Parameters:
id
- The view identifier.
-
computeGraphMetrics
public void computeGraphMetrics()Compute the overall bounds of the graphic graph according to the nodes and sprites positions. We can only compute the graph bounds from the nodes and sprites centres since the node and graph bounds may in certain circumstances be computed according to the graph bounds. The bounds are stored in the graph metrics. -
setCloseFramePolicy
What to do when the frame containing one or more views is closed.- Parameters:
policy
- The close frame policy.
-
enableXYZfeedback
public void enableXYZfeedback(boolean on)Enable or disable the "xyz" attribute change when a node is moved in the views. By default the "xyz" attribute is changed. By default, each time a node of the graphic graph is moved, its "xyz" attribute is reset to follow the node position. This is useful only if someone listen at the graphic graph or use the graphic graph directly. But this operation is quite costly. Therefore by default if this viewer runs in its own thread, and the main graph is in another thread, xyz attribute change will be disabled until a listener is added. When the viewer is created to be used only in the ui thread, this feature is always on. -
enableAutoLayout
public void enableAutoLayout()Launch an automatic layout process that will position nodes in the background. -
enableAutoLayout
Launch an automatic layout process that will position nodes in the background.- Parameters:
layoutAlgorithm
- The algorithm to use (see Layouts.newLayoutAlgorithm() for the default algorithm).
-
disableAutoLayout
public void disableAutoLayout()Disable the running automatic layout process, if any. -
replayGraph
Dirty replay of the graph.
-