org.graphstream.ui.swingViewer
Class Viewer

java.lang.Object
  extended by org.graphstream.ui.swingViewer.Viewer
All Implemented Interfaces:
ActionListener, EventListener

public class Viewer
extends Object
implements ActionListener

Set of views on a graphic graph.

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.


Nested Class Summary
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.
 
Field Summary
static String DEFAULT_VIEW_ID
          Name of the default view.
 
Constructor Summary
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.
 
Method Summary
 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.
 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.
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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_VIEW_ID

public static String DEFAULT_VIEW_ID
Name of the default view.

Constructor Detail

Viewer

public Viewer(ProxyPipe source)
The graph or source of graph events is in another thread or on another machine, but the pipe already exists. The graphic graph displayed by this viewer is created.

Parameters:
source - The source of graph events.

Viewer

public Viewer(GraphicGraph graph)
We draw a pre-existing graphic graph. The graphic graph is maintained by its creator.

Parameters:
graph - THe graph to draw.

Viewer

public Viewer(Graph graph,
              Viewer.ThreadingModel threadingModel)
New viewer on an existing graph. The viewer always run in the Swing thread, therefore, you must specify how it will take graph events from the graph you give. If the graph you give will be accessed only from the Swing thread use ThreadingModel.GRAPH_IN_SWING_THREAD. If the graph you use is accessed in another thread use ThreadingModel.GRAPH_IN_ANOTHER_THREAD. This last scheme is more powerful since it allows to run algorithms on the graph in parallel with the viewer.

Parameters:
graph - The graph to render.
threadingModel - The threading model.
Method Detail

close

public void close()
Close definitively this viewer and all its views.


newGraphRenderer

public static GraphRenderer newGraphRenderer()
Create a new instance of the default graph renderer. The default graph renderer class is given by the "org.graphstream.ui.renderer" system property. If the class indicated by this property is not usable (not in the class path, not of the correct type, etc.) or if the property is not present a SwingBasicGraphRenderer is returned.


getCloseFramePolicy

public Viewer.CloseFramePolicy getCloseFramePolicy()
What to do when a frame is closed.


newThreadProxyOnGraphicGraph

public ProxyPipe newThreadProxyOnGraphicGraph()
New proxy pipe on events coming from the viewer through a thread.

Returns:
The new proxy pipe.

newViewerPipe

public ViewerPipe newViewerPipe()
New viewer pipe on the events coming from the viewer through a thread.

Returns:
The new viewer pipe.

getGraphicGraph

public GraphicGraph getGraphicGraph()
The underlying graphic graph. Caution : Use the returned graph only in the Swing thread !!


getView

public View getView(String id)
The view that correspond to the given identifier.

Parameters:
id - The view identifier.
Returns:
A view or null if not found.

getDefaultView

public View getDefaultView()
The default view. This is a shortcut to a call to getView(String) with DEFAULT_VIEW_ID as parameter.

Returns:
The default view or null if no default view has been installed.

addDefaultView

public View addDefaultView(boolean openInAFrame)
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

public View addView(View view)
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

public View addView(String id,
                    GraphRenderer renderer)
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

public 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.

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

public void removeView(String id)
Remove a view.

Parameters:
id - The view identifier.

actionPerformed

public void actionPerformed(ActionEvent e)
Called on a regular basis by the timer. Checks if some events occurred from the graph pipe or from the layout pipe, and if the graph changed, triggers a repaint. Never call this method, it is called by a Swing Timer automatically.

Specified by:
actionPerformed in interface ActionListener

setCloseFramePolicy

public void setCloseFramePolicy(Viewer.CloseFramePolicy policy)
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 swing thread, this feature is always on.


enableAutoLayout

public void enableAutoLayout()
Launch an automatic layout process that will position nodes in the background.


enableAutoLayout

public void enableAutoLayout(Layout layoutAlgorithm)
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.



Copyright © 2012. All Rights Reserved.