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 |
---|---|
protected Viewer.CloseFramePolicy |
closeFramePolicy
What to do when a view frame is closed.
|
static String |
DEFAULT_VIEW_ID
Name of the default view.
|
protected int |
delay
Delay in milliseconds between frames.
|
protected GraphicGraph |
graph
The graph observed by the views.
|
protected boolean |
graphInAnotherThread
If true the graph we display is in another thread, the synchronisation
between the graph and the graphic graph must therefore use thread
proxies.
|
protected ProxyPipe |
layoutPipeIn
If there is a layout in another thread, this is the pipe coming from it.
|
protected LayoutRunner |
optLayout
Optional layout algorithm running in another thread.
|
protected ProxyPipe |
pumpPipe
If we have to pump events by ourself.
|
protected Source |
sourceInSameThread
If we take graph events from a source in this thread.
|
protected Timer |
timer
Timer in the Swing thread.
|
protected HashMap<String,View> |
views
The set of views.
|
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.
|
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 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.
|
protected 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.
|
View |
getDefaultView()
The default view.
|
GraphicGraph |
getGraphicGraph()
The underlying graphic graph.
|
View |
getView(String id)
The view that correspond to the given identifier.
|
protected void |
init(GraphicGraph graph,
ProxyPipe ppipe,
Source source)
Initialise the viewer.
|
protected String |
newGGId()
Create a new unique identifier for a graph.
|
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.
|
protected 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 static String DEFAULT_VIEW_ID
protected boolean graphInAnotherThread
protected GraphicGraph graph
protected Source sourceInSameThread
protected int delay
protected Viewer.CloseFramePolicy closeFramePolicy
protected LayoutRunner optLayout
protected ProxyPipe layoutPipeIn
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.protected String newGGId()
protected 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 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 View getDefaultView()
getView(String)
with DEFAULT_VIEW_ID
as parameter.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(String id, GraphRenderer renderer)
id
- The new view identifier.renderer
- The renderer to use.public View 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
protected 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()
protected void replayGraph(Graph graph)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses