Class DefaultView

All Implemented Interfaces:
ComponentListener, WindowListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, org.graphstream.ui.view.View

public class DefaultView extends ViewPanel implements WindowListener, ComponentListener
Base for constructing views.

This base view is an abstract class that provides mechanism that are necessary in any view :

  • the painting and repainting mechanism.
  • the optional frame handling.
  • the frame closing protocol.

This view also handle a current selection of nodes and sprites.

The painting mechanism

The main method to implement is render(Graphics2D). This method is called each time the graph needs to be rendered anew in the canvas.

The render(Graphics2D) is called only when a repainting is really needed.

All the painting, by default, is deferred to a GraphRenderer instance. This mechanism allows developers that do not want to mess with the viewer/view mechanisms to render a graph in any Swing surface.

The optional frame handling

This abstract view is able to create a frame that is added around this panel (each view is a JPanel instance). The frame can be removed at any time.

The frame closing protocol

This abstract view handles the closing protocol. This means that it will close the view if needed, or only hide it to allow reopening it later. Furthermore it adds the "ui.viewClosed" attribute to the graph when the view is closed or hidden, and removes it when the view is shown. The value of this graph attribute is the identifier of the view.

See Also:
  • Field Details

    • viewer

      protected org.graphstream.ui.view.Viewer viewer
      Parent viewer.
    • graph

      protected org.graphstream.ui.graphicGraph.GraphicGraph graph
      The graph to render, shortcut to the viewers reference.
    • frame

      protected JFrame frame
      The (optional) frame.
    • shortcuts

      protected org.graphstream.ui.view.util.ShortcutManager shortcuts
      Manager for events with the keyboard.
    • mouseClicks

      protected org.graphstream.ui.view.util.MouseManager mouseClicks
      Manager for events with the mouse.
    • renderer

      protected org.graphstream.ui.view.GraphRenderer renderer
      The graph renderer.
  • Constructor Details

    • DefaultView

      public DefaultView(org.graphstream.ui.view.Viewer viewer, String identifier, org.graphstream.ui.view.GraphRenderer renderer)
  • Method Details

    • getCamera

      public org.graphstream.ui.view.camera.Camera getCamera()
      Specified by:
      getCamera in interface org.graphstream.ui.view.View
    • display

      public void display(org.graphstream.ui.graphicGraph.GraphicGraph graph, boolean graphChanged)
      Specified by:
      display in interface org.graphstream.ui.view.View
    • paintComponent

      public void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • checkTitle

      protected void checkTitle()
    • close

      public void close(org.graphstream.ui.graphicGraph.GraphicGraph graph)
      Specified by:
      close in interface org.graphstream.ui.view.View
    • resizeFrame

      public void resizeFrame(int width, int height)
      Description copied from class: ViewPanel
      Set the size of the view frame, if any. If this view has been open in a frame, this changes the size of the frame containing it.
      Specified by:
      resizeFrame in class ViewPanel
      Parameters:
      width - The new width.
      height - The new height.
    • openInAFrame

      public void openInAFrame(boolean on)
      Specified by:
      openInAFrame in interface org.graphstream.ui.view.View
    • render

      public void render(Graphics2D g)
    • beginSelectionAt

      public void beginSelectionAt(double x1, double y1)
      Specified by:
      beginSelectionAt in interface org.graphstream.ui.view.View
    • selectionGrowsAt

      public void selectionGrowsAt(double x, double y)
      Specified by:
      selectionGrowsAt in interface org.graphstream.ui.view.View
    • endSelectionAt

      public void endSelectionAt(double x2, double y2)
      Specified by:
      endSelectionAt in interface org.graphstream.ui.view.View
    • windowActivated

      public void windowActivated(WindowEvent e)
      Specified by:
      windowActivated in interface WindowListener
    • windowClosed

      public void windowClosed(WindowEvent e)
      Specified by:
      windowClosed in interface WindowListener
    • windowClosing

      public void windowClosing(WindowEvent e)
      Specified by:
      windowClosing in interface WindowListener
    • windowDeactivated

      public void windowDeactivated(WindowEvent e)
      Specified by:
      windowDeactivated in interface WindowListener
    • windowDeiconified

      public void windowDeiconified(WindowEvent e)
      Specified by:
      windowDeiconified in interface WindowListener
    • windowIconified

      public void windowIconified(WindowEvent e)
      Specified by:
      windowIconified in interface WindowListener
    • windowOpened

      public void windowOpened(WindowEvent e)
      Specified by:
      windowOpened in interface WindowListener
    • componentHidden

      public void componentHidden(ComponentEvent e)
      Specified by:
      componentHidden in interface ComponentListener
    • componentMoved

      public void componentMoved(ComponentEvent e)
      Specified by:
      componentMoved in interface ComponentListener
    • componentResized

      public void componentResized(ComponentEvent e)
      Specified by:
      componentResized in interface ComponentListener
    • componentShown

      public void componentShown(ComponentEvent e)
      Specified by:
      componentShown in interface ComponentListener
    • allGraphicElementsIn

      public Collection<org.graphstream.ui.graphicGraph.GraphicElement> allGraphicElementsIn(EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x1, double y1, double x2, double y2)
      Specified by:
      allGraphicElementsIn in interface org.graphstream.ui.view.View
    • findGraphicElementAt

      public org.graphstream.ui.graphicGraph.GraphicElement findGraphicElementAt(EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x, double y)
      Specified by:
      findGraphicElementAt in interface org.graphstream.ui.view.View
    • moveElementAtPx

      public void moveElementAtPx(org.graphstream.ui.graphicGraph.GraphicElement element, double x, double y)
      Specified by:
      moveElementAtPx in interface org.graphstream.ui.view.View
    • freezeElement

      public void freezeElement(org.graphstream.ui.graphicGraph.GraphicElement element, boolean frozen)
      Specified by:
      freezeElement in interface org.graphstream.ui.view.View
    • setBackLayerRenderer

      public void setBackLayerRenderer(org.graphstream.ui.view.LayerRenderer<Graphics2D> renderer)
    • setForeLayoutRenderer

      public void setForeLayoutRenderer(org.graphstream.ui.view.LayerRenderer<Graphics2D> renderer)
    • setMouseManager

      public void setMouseManager(org.graphstream.ui.view.util.MouseManager manager)
      Specified by:
      setMouseManager in interface org.graphstream.ui.view.View
    • enableMouseOptions

      public void enableMouseOptions()
      This is a shortcut to a call setMouseManager with a MouseOverMouseManager instance and with (InteractiveElement.EDGE, InteractiveElement.NODE, InteractiveElement.SPRITE).
      Specified by:
      enableMouseOptions in interface org.graphstream.ui.view.View
      Specified by:
      enableMouseOptions in class ViewPanel
    • setShortcutManager

      public void setShortcutManager(org.graphstream.ui.view.util.ShortcutManager manager)
      Specified by:
      setShortcutManager in interface org.graphstream.ui.view.View
    • requireFocus

      public Object requireFocus()
      Specified by:
      requireFocus in interface org.graphstream.ui.view.View
    • addListener

      public <T, U> void addListener(T descriptor, U listener)
      Specified by:
      addListener in interface org.graphstream.ui.view.View
    • removeListener

      public <T, U> void removeListener(T descriptor, U listener)
      Specified by:
      removeListener in interface org.graphstream.ui.view.View