public class DefaultCamera
extends java.lang.Object
implements org.graphstream.ui.view.camera.Camera
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 ?".
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
autoFit
Automatic centring of the view.
|
protected org.graphstream.ui.geom.Point3 |
center
The camera centre of view.
|
protected org.graphstream.ui.graphicGraph.GraphicGraph |
graph
The graph.
|
protected double[] |
gviewport
The graph view port, if any.
|
protected double |
gviewportDiagonal |
protected org.graphstream.ui.view.util.GraphMetrics |
metrics
Information on the graph overall dimension and position.
|
protected java.util.HashSet<java.lang.String> |
nodeInvisible
Which node is visible.
|
protected java.awt.geom.AffineTransform |
oldTx
The previous affine transform.
|
protected org.graphstream.ui.graphicGraph.stylesheet.Values |
padding
Padding around the graph.
|
protected double |
rotation
The rotation angle.
|
protected java.awt.geom.AffineTransform |
Tx
The graph-space -> pixel-space transformation.
|
protected java.awt.geom.AffineTransform |
xT
The inverse transform of Tx.
|
protected double |
zoom
The camera zoom.
|
| Constructor and Description |
|---|
DefaultCamera(org.graphstream.ui.graphicGraph.GraphicGraph graph)
New camera.
|
| Modifier and Type | Method and 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) |
protected void |
autoFitView(java.awt.Graphics2D g2)
Compute a transformation matrix that pass from graph units (user space)
to pixel units (device space) so that the whole graph is visible.
|
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.
|
protected boolean |
edgeContains(org.graphstream.ui.graphicGraph.GraphicElement elt,
double x,
double y)
Check if an edge contains the given point (x,y).
|
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() |
protected double |
getPaddingXgu() |
protected double |
getPaddingXpx() |
protected double |
getPaddingYgu() |
protected double |
getPaddingYpx() |
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.
|
protected java.awt.geom.Point2D.Double |
getSpritePositionEdge(org.graphstream.ui.graphicGraph.GraphicSprite sprite,
java.awt.geom.Point2D.Double pos,
org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units)
Compute the position of a sprite if attached to an edge.
|
protected java.awt.geom.Point2D.Double |
getSpritePositionFree(org.graphstream.ui.graphicGraph.GraphicSprite sprite,
java.awt.geom.Point2D.Double pos,
org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units)
Compute the position of a sprite if it is not attached.
|
protected java.awt.geom.Point2D.Double |
getSpritePositionNode(org.graphstream.ui.graphicGraph.GraphicSprite sprite,
java.awt.geom.Point2D.Double pos,
org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units)
Compute the position of a sprite if attached to a node.
|
org.graphstream.ui.geom.Point3 |
getViewCenter() |
double |
getViewPercent() |
double |
getViewRotation() |
protected boolean |
isEdgeIn(org.graphstream.ui.graphicGraph.GraphicEdge edge,
double X1,
double Y1,
double X2,
double Y2)
Is the given sprite visible in the given area.
|
protected boolean |
isEdgeVisible(org.graphstream.ui.graphicGraph.GraphicEdge edge)
Check if an edge is visible in the current view port.
|
protected boolean |
isNodeIn(org.graphstream.ui.graphicGraph.GraphicNode node,
double X1,
double Y1,
double X2,
double Y2)
Is the given node visible in the given area.
|
protected boolean |
isSpriteIn(org.graphstream.ui.graphicGraph.GraphicSprite sprite,
double X1,
double Y1,
double X2,
double Y2)
Is the given sprite visible in the given area.
|
protected boolean |
isSpriteVisible(org.graphstream.ui.graphicGraph.GraphicSprite sprite)
Check if a sprite is visible in the current view port.
|
boolean |
isVisible(org.graphstream.ui.graphicGraph.GraphicElement element)
True if the element should be visible on screen.
|
protected boolean |
nodeContains(org.graphstream.ui.graphicGraph.GraphicElement elt,
double x,
double y)
Check if a node contains the given point (x,y).
|
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.
|
protected boolean |
spriteContains(org.graphstream.ui.graphicGraph.GraphicElement elt,
double x,
double y)
Check if a sprite contains the given point (x,y).
|
protected java.awt.geom.Point2D.Double |
spritePositionPx(org.graphstream.ui.graphicGraph.GraphicSprite sprite) |
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) |
protected void |
userView(java.awt.Graphics2D g2)
Compute a transformation that pass from graph units (user space) to a
pixel units (device space) so that the view (zoom and centre) requested
by the user is produced.
|
protected org.graphstream.ui.graphicGraph.GraphicGraph graph
protected org.graphstream.ui.view.util.GraphMetrics metrics
protected boolean autoFit
protected org.graphstream.ui.geom.Point3 center
protected double zoom
protected java.awt.geom.AffineTransform Tx
protected java.awt.geom.AffineTransform xT
protected java.awt.geom.AffineTransform oldTx
protected double rotation
protected org.graphstream.ui.graphicGraph.stylesheet.Values padding
protected java.util.HashSet<java.lang.String> nodeInvisible
protected double[] gviewport
protected double gviewportDiagonal
public DefaultCamera(org.graphstream.ui.graphicGraph.GraphicGraph graph)
public org.graphstream.ui.geom.Point3 getViewCenter()
getViewCenter in interface org.graphstream.ui.view.camera.Camerapublic void setViewCenter(double x,
double y,
double z)
setViewCenter in interface org.graphstream.ui.view.camera.Camerapublic void setViewCenter(double x,
double y)
public double getViewPercent()
getViewPercent in interface org.graphstream.ui.view.camera.Camerapublic void setViewPercent(double percent)
setViewPercent in interface org.graphstream.ui.view.camera.Camerapublic double getViewRotation()
getViewRotation in interface org.graphstream.ui.view.camera.Camerapublic org.graphstream.ui.view.util.GraphMetrics getMetrics()
getMetrics in interface org.graphstream.ui.view.camera.Camerapublic java.lang.String toString()
toString in class java.lang.Objectpublic void resetView()
resetView in interface org.graphstream.ui.view.camera.Camerapublic void setBounds(double minx,
double miny,
double minz,
double maxx,
double maxy,
double maxz)
setBounds in interface org.graphstream.ui.view.camera.Camerapublic double getGraphDimension()
getGraphDimension in interface org.graphstream.ui.view.camera.Camerapublic boolean isVisible(org.graphstream.ui.graphicGraph.GraphicElement element)
isVisible in interface org.graphstream.ui.view.camera.Cameraelement - The element to test.public org.graphstream.ui.geom.Point3 transformPxToGu(double x,
double y)
transformPxToGu in interface org.graphstream.ui.view.camera.Camerapublic org.graphstream.ui.geom.Point3 transformGuToPx(double x,
double y,
double z)
transformGuToPx in interface org.graphstream.ui.view.camera.Camerapublic void checkVisibility(org.graphstream.ui.graphicGraph.GraphicGraph graph)
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)
InteractiveElement.NODE > InteractiveElement.EDGE > InteractiveElement.SPRITE, (in that order) that contains the
point at coordinates (x, y).findGraphicElementAt in interface org.graphstream.ui.view.camera.Cameragraph - The graph to search for.x - The point abscissa.y - The point ordinate.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)
allGraphicElementsIn in interface org.graphstream.ui.view.camera.Camerapublic 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)
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).public double[] getGraphViewport()
public void setGraphViewport(double minx,
double miny,
double maxx,
double maxy)
setGraphViewport in interface org.graphstream.ui.view.camera.Camerapublic void removeGraphViewport()
removeGraphViewport in interface org.graphstream.ui.view.camera.Camerapublic void pushView(org.graphstream.ui.graphicGraph.GraphicGraph graph,
java.awt.Graphics2D g2)
popView(Graphics2D) to restore
the saved transform. You can only push one time the view.g2 - The Swing graphics to change.public void popView(java.awt.Graphics2D g2)
pushView(GraphicGraph, Graphics2D) is used.g2 - The Swing graphics to restore.protected void autoFitView(java.awt.Graphics2D g2)
g2 - The Swing graphics.protected void userView(java.awt.Graphics2D g2)
g2 - The Swing graphics.public void setAutoFitView(boolean on)
setAutoFitView in interface org.graphstream.ui.view.camera.Cameraon - If true, automatic adjustment is enabled.public void setZoom(double z)
z - The zoom.public void setViewRotation(double theta)
setViewRotation in interface org.graphstream.ui.view.camera.Cameratheta - The rotation angle in degrees.public void setViewport(double viewportX,
double viewportY,
double viewportWidth,
double viewportHeight)
viewportWidth - The width in pixels of the view port.viewportHeight - The width in pixels of the view port.public void setPadding(org.graphstream.ui.graphicGraph.GraphicGraph graph)
graph - The graphic graph.protected double getPaddingXgu()
protected double getPaddingYgu()
protected double getPaddingXpx()
protected double getPaddingYpx()
protected boolean isSpriteVisible(org.graphstream.ui.graphicGraph.GraphicSprite sprite)
sprite - The sprite to check.protected boolean isEdgeVisible(org.graphstream.ui.graphicGraph.GraphicEdge edge)
edge - The edge to check.protected boolean isNodeIn(org.graphstream.ui.graphicGraph.GraphicNode node,
double X1,
double Y1,
double X2,
double Y2)
node - The node to check.X1 - The min abscissa of the area.Y1 - The min ordinate of the area.X2 - The max abscissa of the area.Y2 - The max ordinate of the area.protected boolean isEdgeIn(org.graphstream.ui.graphicGraph.GraphicEdge edge,
double X1,
double Y1,
double X2,
double Y2)
edge - The edge to check.X1 - The min abscissa of the area.Y1 - The min ordinate of the area.X2 - The max abscissa of the area.Y2 - The max ordinate of the area.protected boolean isSpriteIn(org.graphstream.ui.graphicGraph.GraphicSprite sprite,
double X1,
double Y1,
double X2,
double Y2)
sprite - The sprite to check.X1 - The min abscissa of the area.Y1 - The min ordinate of the area.X2 - The max abscissa of the area.Y2 - The max ordinate of the area.protected java.awt.geom.Point2D.Double spritePositionPx(org.graphstream.ui.graphicGraph.GraphicSprite sprite)
protected boolean nodeContains(org.graphstream.ui.graphicGraph.GraphicElement elt,
double x,
double y)
elt - The node.x - The point abscissa.y - The point ordinate.protected boolean edgeContains(org.graphstream.ui.graphicGraph.GraphicElement elt,
double x,
double y)
elt - The edge.x - The point abscissa.y - The point ordinate.protected boolean spriteContains(org.graphstream.ui.graphicGraph.GraphicElement elt,
double x,
double y)
elt - The sprite.x - The point abscissa.y - The point ordinate.protected java.awt.geom.Point2D.Double getSpritePositionFree(org.graphstream.ui.graphicGraph.GraphicSprite sprite,
java.awt.geom.Point2D.Double pos,
org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units)
sprite - The sprite.pos - Where to stored the computed position, if null, the position
is created.units - The units the computed position must be given into.protected java.awt.geom.Point2D.Double getSpritePositionNode(org.graphstream.ui.graphicGraph.GraphicSprite sprite,
java.awt.geom.Point2D.Double pos,
org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units)
sprite - The sprite.pos - Where to stored the computed position, if null, the position
is created.units - The units the computed position must be given into.protected java.awt.geom.Point2D.Double getSpritePositionEdge(org.graphstream.ui.graphicGraph.GraphicSprite sprite,
java.awt.geom.Point2D.Double pos,
org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units units)
sprite - The sprite.pos - Where to stored the computed position, if null, the position
is created.units - The units the computed position must be given into.