public abstract class Viewer
extends java.lang.Object
The viewer class is in charge of maintaining :
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.
Modifier and Type | Class and 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 and Description |
---|
Viewer() |
Modifier and Type | Method and Description |
---|---|
View |
addDefaultView(boolean openInAFrame)
Build the default graph view and insert it.
|
View |
addView(java.lang.String id,
GraphRenderer<?,?> renderer)
Add a new default view with a specific renderer.
|
View |
addView(java.lang.String id,
GraphRenderer<?,?> renderer,
boolean openInAFrame)
Same as
addView(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 java.lang.String |
getDefaultID()
Name of the default view.
|
View |
getDefaultView()
The default view.
|
GraphicGraph |
getGraphicGraph()
The underlying graphic graph.
|
View |
getView(java.lang.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.
|
java.lang.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(java.lang.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.
|
public abstract java.lang.String getDefaultID()
public java.lang.String newGGId()
public abstract void init(GraphicGraph graph, ProxyPipe ppipe, Source source)
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).public abstract void close()
public Viewer.CloseFramePolicy getCloseFramePolicy()
public ProxyPipe newThreadProxyOnGraphicGraph()
public ViewerPipe newViewerPipe()
public GraphicGraph getGraphicGraph()
public View getView(java.lang.String id)
id
- The view identifier.public View getDefaultView()
getView(String)
with #DEFAULT_VIEW_ID
as parameter.public abstract GraphRenderer<?,?> newDefaultGraphRenderer()
public View addDefaultView(boolean openInAFrame)
#DEFAULT_VIEW_ID
. You can request the view to be open in its own
frame.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.public View addView(View view)
view
- The view to add.public View addView(java.lang.String id, GraphRenderer<?,?> renderer)
id
- The new view identifier.renderer
- The renderer to use.public View addView(java.lang.String id, GraphRenderer<?,?> renderer, boolean openInAFrame)
addView(String, GraphRenderer)
but allows to specify that
the view uses a frame or not.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.public void removeView(java.lang.String id)
id
- The view identifier.public void computeGraphMetrics()
public void setCloseFramePolicy(Viewer.CloseFramePolicy policy)
policy
- The close frame policy.public void enableXYZfeedback(boolean on)
public void enableAutoLayout()
public void enableAutoLayout(Layout layoutAlgorithm)
layoutAlgorithm
- The algorithm to use (see Layouts.newLayoutAlgorithm() for the
default algorithm).public void disableAutoLayout()
public void replayGraph(Graph graph)