Class Viewer

java.lang.Object
org.graphstream.ui.view.Viewer

public abstract class Viewer
extends Object
Set of views on a graphic graph.

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.

  • Constructor Details

  • Method Details

    • getDefaultID

      public abstract String getDefaultID()
      Name of the default view.
    • newGGId

      public String newGGId()
      Create a new unique identifier for a graph.
      Returns:
      The new identifier.
    • init

      public abstract void init​(GraphicGraph graph, ProxyPipe ppipe, Source source)
      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

      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 UI 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.
    • newDefaultGraphRenderer

      public abstract GraphRenderer<?,​?> newDefaultGraphRenderer()
      Create a new instance of the default graph renderer.
    • 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. 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

      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 ui 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.
    • replayGraph

      public void replayGraph​(Graph graph)
      Dirty replay of the graph.