Class DefaultCamera

java.lang.Object
org.graphstream.ui.swing_viewer.util.DefaultCamera
All Implemented Interfaces:
org.graphstream.ui.view.camera.Camera

public class DefaultCamera
extends java.lang.Object
implements org.graphstream.ui.view.camera.Camera
Define how the graph is viewed.

The camera is in charge of projecting the graph spaces in graph units (GU) into user spaces (often in pixels). It defines the transformation (an affine matrix) to passe from the first to the second. It also contains the graph metrics, a set of values that give the overall dimensions of the graph in graph units, as well as the view port, the area on the screen (or any rendering surface) that will receive the results in pixels (or rendering units).

The camera defines a centre at which it always points. It can zoom on the graph, pan in any direction and rotate along two axes.

Knowing the transformation also allows to provide services like "what element is not invisible ?" (not in the camera view) or "on what element is the mouse cursor actually ?".

  • Constructor Summary

    Constructors 
    Constructor Description
    DefaultCamera​(org.graphstream.ui.graphicGraph.GraphicGraph graph)
    New camera.
  • Method Summary

    Modifier and Type Method Description
    java.util.Collection<org.graphstream.ui.graphicGraph.GraphicElement> allGraphicElementsIn​(org.graphstream.ui.graphicGraph.GraphicGraph graph, java.util.EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x1, double y1, double x2, double y2)  
    void checkVisibility​(org.graphstream.ui.graphicGraph.GraphicGraph graph)
    Process each node to check if it is in the actual view port, and mark invisible nodes.
    org.graphstream.ui.graphicGraph.GraphicElement findGraphicElementAt​(org.graphstream.ui.graphicGraph.GraphicGraph graph, java.util.EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x, double y)
    Search for the first GraphicElement among those specified.
    double getGraphDimension()  
    double[] getGraphViewport()  
    org.graphstream.ui.view.util.GraphMetrics getMetrics()  
    java.awt.geom.Point2D.Double getSpritePosition​(org.graphstream.ui.graphicGraph.GraphicSprite sprite, java.awt.geom.Point2D.Double pos, org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units)
    Compute the real position of a sprite according to its eventual attachment in graph units.
    org.graphstream.ui.geom.Point3 getViewCenter()  
    double getViewPercent()  
    double getViewRotation()  
    boolean isVisible​(org.graphstream.ui.graphicGraph.GraphicElement element)
    True if the element should be visible on screen.
    void popView​(java.awt.Graphics2D g2)
    Restore the transform that was used before pushView(GraphicGraph, Graphics2D) is used.
    void pushView​(org.graphstream.ui.graphicGraph.GraphicGraph graph, java.awt.Graphics2D g2)
    Set the camera view in the given graphics and backup the previous transform of the graphics.
    void removeGraphViewport()  
    void resetView()  
    void setAutoFitView​(boolean on)
    Enable or disable automatic adjustment of the view to see the entire graph.
    void setBounds​(double minx, double miny, double minz, double maxx, double maxy, double maxz)  
    void setGraphViewport​(double minx, double miny, double maxx, double maxy)  
    void setPadding​(org.graphstream.ui.graphicGraph.GraphicGraph graph)
    Set the graph padding.
    void setViewCenter​(double x, double y)  
    void setViewCenter​(double x, double y, double z)  
    void setViewPercent​(double percent)  
    void setViewport​(double viewportX, double viewportY, double viewportWidth, double viewportHeight)
    Set the output view port size in pixels.
    void setViewRotation​(double theta)
    Set the rotation angle around the centre.
    void setZoom​(double z)
    Set the zoom (or percent of the graph visible), 1 means the graph is fully visible.
    java.lang.String toString()  
    org.graphstream.ui.geom.Point3 transformGuToPx​(double x, double y, double z)  
    org.graphstream.ui.geom.Point3 transformPxToGu​(double x, double y)  

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • DefaultCamera

      public DefaultCamera​(org.graphstream.ui.graphicGraph.GraphicGraph graph)
      New camera.
  • Method Details

    • getViewCenter

      public org.graphstream.ui.geom.Point3 getViewCenter()
      Specified by:
      getViewCenter in interface org.graphstream.ui.view.camera.Camera
    • setViewCenter

      public void setViewCenter​(double x, double y, double z)
      Specified by:
      setViewCenter in interface org.graphstream.ui.view.camera.Camera
    • setViewCenter

      public void setViewCenter​(double x, double y)
    • getViewPercent

      public double getViewPercent()
      Specified by:
      getViewPercent in interface org.graphstream.ui.view.camera.Camera
    • setViewPercent

      public void setViewPercent​(double percent)
      Specified by:
      setViewPercent in interface org.graphstream.ui.view.camera.Camera
    • getViewRotation

      public double getViewRotation()
      Specified by:
      getViewRotation in interface org.graphstream.ui.view.camera.Camera
    • getMetrics

      public org.graphstream.ui.view.util.GraphMetrics getMetrics()
      Specified by:
      getMetrics in interface org.graphstream.ui.view.camera.Camera
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • resetView

      public void resetView()
      Specified by:
      resetView in interface org.graphstream.ui.view.camera.Camera
    • setBounds

      public void setBounds​(double minx, double miny, double minz, double maxx, double maxy, double maxz)
      Specified by:
      setBounds in interface org.graphstream.ui.view.camera.Camera
    • getGraphDimension

      public double getGraphDimension()
      Specified by:
      getGraphDimension in interface org.graphstream.ui.view.camera.Camera
    • isVisible

      public boolean isVisible​(org.graphstream.ui.graphicGraph.GraphicElement element)
      True if the element should be visible on screen. The method used is to transform the center of the element (which is always in graph units) using the camera actual transformation to put it in pixel units. Then to look in the style sheet the size of the element and to test if its enclosing rectangle intersects the view port. For edges, its two nodes are used. As a speed-up by default if the camera is in automatic fitting mode, all element should be visible, and the test always returns true.
      Specified by:
      isVisible in interface org.graphstream.ui.view.camera.Camera
      Parameters:
      element - The element to test.
      Returns:
      True if the element is visible and therefore must be rendered.
    • transformPxToGu

      public org.graphstream.ui.geom.Point3 transformPxToGu​(double x, double y)
      Specified by:
      transformPxToGu in interface org.graphstream.ui.view.camera.Camera
    • transformGuToPx

      public org.graphstream.ui.geom.Point3 transformGuToPx​(double x, double y, double z)
      Specified by:
      transformGuToPx in interface org.graphstream.ui.view.camera.Camera
    • checkVisibility

      public void checkVisibility​(org.graphstream.ui.graphicGraph.GraphicGraph graph)
      Process each node to check if it is in the actual view port, and mark invisible nodes. This method allows for fast node, sprite and edge visibility checking when drawing. This must be called before each rendering (if the view port changed).
    • findGraphicElementAt

      public org.graphstream.ui.graphicGraph.GraphicElement findGraphicElementAt​(org.graphstream.ui.graphicGraph.GraphicGraph graph, java.util.EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x, double y)
      Search for the first GraphicElement among those specified. Multiple elements are resolved by priority- InteractiveElement.NODE > InteractiveElement.EDGE > InteractiveElement.SPRITE, (in that order) that contains the point at coordinates (x, y).
      Specified by:
      findGraphicElementAt in interface org.graphstream.ui.view.camera.Camera
      Parameters:
      graph - The graph to search for.
      x - The point abscissa.
      y - The point ordinate.
      Returns:
      The first node or sprite at the given coordinates or null if nothing found.
    • allGraphicElementsIn

      public java.util.Collection<org.graphstream.ui.graphicGraph.GraphicElement> allGraphicElementsIn​(org.graphstream.ui.graphicGraph.GraphicGraph graph, java.util.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.camera.Camera
    • getSpritePosition

      public java.awt.geom.Point2D.Double getSpritePosition​(org.graphstream.ui.graphicGraph.GraphicSprite sprite, java.awt.geom.Point2D.Double pos, org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units)
      Compute the real position of a sprite according to its eventual attachment in graph units.
      Parameters:
      sprite - The sprite.
      pos - Receiver for the sprite 2D position, can be null.
      units - The units in which the position must be computed (the sprite already contains units).
      Returns:
      The same instance as the one given by parameter pos or a new one if pos was null, containing the computed position in the given units.
    • getGraphViewport

      public double[] getGraphViewport()
    • setGraphViewport

      public void setGraphViewport​(double minx, double miny, double maxx, double maxy)
      Specified by:
      setGraphViewport in interface org.graphstream.ui.view.camera.Camera
    • removeGraphViewport

      public void removeGraphViewport()
      Specified by:
      removeGraphViewport in interface org.graphstream.ui.view.camera.Camera
    • pushView

      public void pushView​(org.graphstream.ui.graphicGraph.GraphicGraph graph, java.awt.Graphics2D g2)
      Set the camera view in the given graphics and backup the previous transform of the graphics. Call popView(Graphics2D) to restore the saved transform. You can only push one time the view.
      Parameters:
      g2 - The Swing graphics to change.
    • popView

      public void popView​(java.awt.Graphics2D g2)
      Restore the transform that was used before pushView(GraphicGraph, Graphics2D) is used.
      Parameters:
      g2 - The Swing graphics to restore.
    • setAutoFitView

      public void setAutoFitView​(boolean on)
      Enable or disable automatic adjustment of the view to see the entire graph.
      Specified by:
      setAutoFitView in interface org.graphstream.ui.view.camera.Camera
      Parameters:
      on - If true, automatic adjustment is enabled.
    • setZoom

      public void setZoom​(double z)
      Set the zoom (or percent of the graph visible), 1 means the graph is fully visible.
      Parameters:
      z - The zoom.
    • setViewRotation

      public void setViewRotation​(double theta)
      Set the rotation angle around the centre.
      Specified by:
      setViewRotation in interface org.graphstream.ui.view.camera.Camera
      Parameters:
      theta - The rotation angle in degrees.
    • setViewport

      public void setViewport​(double viewportX, double viewportY, double viewportWidth, double viewportHeight)
      Set the output view port size in pixels.
      Parameters:
      viewportWidth - The width in pixels of the view port.
      viewportHeight - The width in pixels of the view port.
    • setPadding

      public void setPadding​(org.graphstream.ui.graphicGraph.GraphicGraph graph)
      Set the graph padding.
      Parameters:
      graph - The graphic graph.