public class Viewer extends Object implements ActionListener
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 Swing 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 swing 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.
|
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_VIEW_ID
Name of the default view.
|
Constructor and Description |
---|
Viewer(GraphicGraph graph)
We draw a pre-existing graphic graph.
|
Viewer(Graph graph,
Viewer.ThreadingModel threadingModel)
New viewer on an existing graph.
|
Viewer(ProxyPipe source)
The graph or source of graph events is in another thread or on another
machine, but the pipe already exists.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent e)
Called on a regular basis by the timer.
|
ViewPanel |
addDefaultView(boolean openInAFrame)
Build the default graph view and insert it.
|
ViewPanel |
addView(String id,
GraphRenderer renderer)
Add a new default view with a specific renderer.
|
ViewPanel |
addView(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.
|
void |
close()
Close definitively this viewer and all its views.
|
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.
|
ViewPanel |
getDefaultView()
The default view.
|
GraphicGraph |
getGraphicGraph()
The underlying graphic graph.
|
View |
getView(String id)
The view that correspond to the given identifier.
|
static GraphRenderer |
newGraphRenderer()
Create a new instance of the default graph renderer.
|
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 |
setCloseFramePolicy(Viewer.CloseFramePolicy policy)
What to do when the frame containing one or more views is closed.
|
public static String DEFAULT_VIEW_ID
public Viewer(ProxyPipe source)
source
- The source of graph events.public Viewer(GraphicGraph graph)
graph
- THe graph to draw.public Viewer(Graph graph, Viewer.ThreadingModel threadingModel)
graph
- The graph to render.threadingModel
- The threading model.public void close()
public static GraphRenderer newGraphRenderer()
public Viewer.CloseFramePolicy getCloseFramePolicy()
public ProxyPipe newThreadProxyOnGraphicGraph()
public ViewerPipe newViewerPipe()
public GraphicGraph getGraphicGraph()
public View getView(String id)
id
- The view identifier.public ViewPanel getDefaultView()
getView(String)
with DEFAULT_VIEW_ID
as parameter.public ViewPanel 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 ViewPanel addView(String id, GraphRenderer renderer)
id
- The new view identifier.renderer
- The renderer to use.public ViewPanel addView(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(String id)
id
- The view identifier.public void actionPerformed(ActionEvent e)
actionPerformed
in interface ActionListener
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()
Copyright © 2015. All rights reserved.