Class SwingViewer

java.lang.Object
org.graphstream.ui.view.Viewer
org.graphstream.ui.swing_viewer.SwingViewer
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class SwingViewer
extends org.graphstream.ui.view.Viewer
implements java.awt.event.ActionListener
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 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 Viewer.addView(View), Viewer.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

    Nested classes/interfaces inherited from class org.graphstream.ui.view.Viewer

    org.graphstream.ui.view.Viewer.CloseFramePolicy, org.graphstream.ui.view.Viewer.ThreadingModel
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String DEFAULT_VIEW_ID
    Name of the default view.
  • Constructor Summary

    Constructors 
    Constructor Description
    SwingViewer​(org.graphstream.graph.Graph graph, org.graphstream.ui.view.Viewer.ThreadingModel threadingModel)
    New viewer on an existing graph.
    SwingViewer​(org.graphstream.stream.ProxyPipe source)
    The graph or source of graph events is in another thread or on another machine, but the pipe already exists.
    SwingViewer​(org.graphstream.ui.graphicGraph.GraphicGraph graph)
    We draw a pre-existing graphic graph.
  • Method Summary

    Modifier and Type Method Description
    void actionPerformed​(java.awt.event.ActionEvent arg0)
    Called on a regular basis by the timer.
    org.graphstream.ui.view.View addDefaultView​(boolean openInAFrame, org.graphstream.ui.view.GraphRenderer<?,​?> renderer)
    Build the default graph view and insert it.
    void close()
    Close definitively this viewer and all its views.
    java.lang.String getDefaultID()  
    void init​(org.graphstream.ui.graphicGraph.GraphicGraph graph, org.graphstream.stream.ProxyPipe ppipe, org.graphstream.stream.Source source)
    Initialise the viewer.
    org.graphstream.ui.view.GraphRenderer<?,​?> newDefaultGraphRenderer()
    Create a new instance of the default graph renderer.

    Methods inherited from class org.graphstream.ui.view.Viewer

    addDefaultView, addView, addView, addView, computeGraphMetrics, disableAutoLayout, enableAutoLayout, enableAutoLayout, enableXYZfeedback, getCloseFramePolicy, getDefaultView, getGraphicGraph, getView, newGGId, newThreadProxyOnGraphicGraph, newViewerPipe, removeView, replayGraph, setCloseFramePolicy

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_VIEW_ID

      public static java.lang.String DEFAULT_VIEW_ID
      Name of the default view.
  • Constructor Details

    • SwingViewer

      public SwingViewer​(org.graphstream.stream.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.
    • SwingViewer

      public SwingViewer​(org.graphstream.ui.graphicGraph.GraphicGraph graph)
      We draw a pre-existing graphic graph. The graphic graph is maintained by its creator.
      Parameters:
      graph - THe graph to draw.
    • SwingViewer

      public SwingViewer​(org.graphstream.graph.Graph graph, org.graphstream.ui.view.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_GUI_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 Details

    • getDefaultID

      public java.lang.String getDefaultID()
      Specified by:
      getDefaultID in class org.graphstream.ui.view.Viewer
    • init

      public void init​(org.graphstream.ui.graphicGraph.GraphicGraph graph, org.graphstream.stream.ProxyPipe ppipe, org.graphstream.stream.Source source)
      Initialise the viewer.
      Specified by:
      init in class org.graphstream.ui.view.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 void close()
      Close definitively this viewer and all its views.
      Specified by:
      close in class org.graphstream.ui.view.Viewer
    • newDefaultGraphRenderer

      public org.graphstream.ui.view.GraphRenderer<?,​?> newDefaultGraphRenderer()
      Create a new instance of the default graph renderer.
      Specified by:
      newDefaultGraphRenderer in class org.graphstream.ui.view.Viewer
    • addDefaultView

      public org.graphstream.ui.view.View addDefaultView​(boolean openInAFrame, org.graphstream.ui.view.GraphRenderer<?,​?> renderer)
      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:
      renderer -
      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.
    • actionPerformed

      public void actionPerformed​(java.awt.event.ActionEvent arg0)
      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 java.awt.event.ActionListener