public class DefaultCamera2D extends java.lang.Object implements Camera
Constructor and Description |
---|
DefaultCamera2D(GraphicGraph graph) |
Modifier and Type | Method and Description |
---|---|
java.util.Collection<GraphicElement> |
allGraphicElementsIn(GraphicGraph graph,
java.util.EnumSet<InteractiveElement> types,
double x1,
double y1,
double x2,
double y2) |
void |
autoFitView()
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(GraphicGraph graph) |
boolean |
edgeContains(GraphicElement elt,
double x,
double y) |
GraphicElement |
findGraphicElementAt(GraphicGraph graph,
java.util.EnumSet<InteractiveElement> types,
double x,
double y)
Search for the first GraphicElement among those specified.
|
double |
getGraphDimension()
A number in GU that gives the approximate graph size (often the diagonal of
the graph).
|
GraphMetrics |
getMetrics()
Get the
org.graphstream.ui.swingViewer.util.GraphMetrics object
linked to this Camera. |
Point3 |
getNodeOrSpritePositionGU(GraphicElement elt,
Point3 pos) |
Values |
getNodeOrSpriteSize(GraphicElement elt) |
Point3 |
getSpritePosition(GraphicSprite sprite,
Point3 pos,
StyleConstants.Units units)
Compute the real position of a sprite according to its eventual attachment in
graph units.
|
Point3 |
getSpritePositionEdge(GraphicSprite sprite,
Point3 position,
StyleConstants.Units units) |
Point3 |
getSpritePositionFree(GraphicSprite sprite,
Point3 position,
StyleConstants.Units units) |
Point3 |
getSpritePositionNode(GraphicSprite sprite,
Point3 position,
StyleConstants.Units units)
Compute the position of a sprite if attached to a node.
|
Point3 |
getViewCenter()
The view centre (a point in graph units).
|
double |
getViewPercent()
The portion of the graph visible.
|
double |
getViewRotation()
The current rotation angle.
|
double[] |
graphViewport() |
boolean |
isEdgeIn(GraphicEdge edge,
double X1,
double Y1,
double X2,
double Y2) |
boolean |
isEdgeVisible(GraphicEdge edge)
Check if an edge is visible in the current view port.
|
boolean |
isNodeIn(GraphicNode node,
double X1,
double Y1,
double X2,
double Y2)
Is the given node visible in the given area.
|
boolean |
isSpriteIn(GraphicSprite sprite,
double X1,
double Y1,
double X2,
double Y2)
Is the given sprite visible in the given area.
|
boolean |
isSpriteVisible(GraphicSprite sprite)
Check if a sprite is visible in the current view port.
|
boolean |
isTextVisible(GraphicElement element) |
boolean |
isVisible(GraphicElement element)
True if the element should be visible on screen.
|
boolean |
nodeContains(GraphicElement elt,
double x,
double y) |
double |
paddingXgu() |
double |
paddingXpx() |
double |
paddingYgu() |
double |
paddingYpx() |
void |
popView()
Restore the transform that was used before
#pushView() is used. |
void |
pushView(GraphicGraph graph)
Set the camera view in the given graphics and backup the previous transform
of the graphics.
|
void |
removeGraphViewport()
Remove the specified graph view port.
|
void |
resetView()
Reset the view to the automatic mode.
|
void |
setAutoFitView(boolean on)
Enable or disable automatic adjustment of the view to see the entire graph.
|
void |
setBackend(Backend backend) |
void |
setBounds(double minx,
double miny,
double minz,
double maxx,
double maxy,
double maxz)
Set the graphic graph bounds (the lowest and highest points).
|
void |
setBounds(GraphicGraph graph)
Set the graphic graph bounds from the graphic graph.
|
void |
setGraphViewport(double minx,
double miny,
double maxx,
double maxy)
Specify exactly the minimum and maximum points in GU that are visible (more
points may be visible due to aspect-ratio constraints).
|
void |
setPadding(GraphicGraph graph)
Set the graph padding.
|
void |
setViewCenter(double x,
double y,
double z)
Change the view centre.
|
void |
setViewCenter(Point3 p) |
void |
setViewPercent(double percent)
Zoom the view.
|
void |
setViewport(double x,
double y,
double viewportWidth,
double viewportHeight)
Set the output view port size in pixels.
|
void |
setViewRotation(double theta)
Rotate the view around its centre point by a given theta angles (in degrees).
|
void |
setZoom(double z)
Set the zoom (or percent of the graph visible), 1 means the graph is fully
visible.
|
boolean |
spriteContains(GraphicElement elt,
double x,
double y) |
Point3 |
spritePositionPx(GraphicSprite sprite) |
java.lang.String |
toString() |
Point3 |
transformGuToPx(double x,
double y,
double z)
Transform a point in graph units into pixels.
|
Point3 |
transformPxToGu(double x,
double y)
Return the given point in pixels converted in graph units (GU) using the
inverse transformation of the current projection matrix.
|
void |
userView()
Compute a transformation that pass from graph units (user space) to a pixel
units (device space) so that the view (zoom and center) requested by the user
is produced.
|
public DefaultCamera2D(GraphicGraph graph)
public Point3 getViewCenter()
Camera
getViewCenter
in interface Camera
public void setViewCenter(double x, double y, double z)
Camera
setViewCenter
in interface Camera
x
- The new abscissa.y
- The new ordinate.z
- The new depth.public void setViewCenter(Point3 p)
public double getViewPercent()
Camera
getViewPercent
in interface Camera
public void setViewPercent(double percent)
Camera
setViewPercent
in interface Camera
percent
- Percent of the graph visible.public void setZoom(double z)
z
- The zoom.public double getViewRotation()
Camera
getViewRotation
in interface Camera
public void setViewRotation(double theta)
Camera
setViewRotation
in interface Camera
theta
- The rotation angle in degrees.public void setViewport(double x, double y, double viewportWidth, double viewportHeight)
viewportWidth
- The width in pixels of the view port.viewportHeight
- The width in pixels of the view port.public double getGraphDimension()
Camera
getGraphDimension
in interface Camera
public boolean spriteContains(GraphicElement elt, double x, double y)
public Point3 spritePositionPx(GraphicSprite sprite)
public Point3 getSpritePosition(GraphicSprite sprite, Point3 pos, 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 Point3 getSpritePositionFree(GraphicSprite sprite, Point3 position, StyleConstants.Units units)
public Point3 getSpritePositionEdge(GraphicSprite sprite, Point3 position, StyleConstants.Units units)
public Point3 getSpritePositionNode(GraphicSprite sprite, Point3 position, StyleConstants.Units units)
sprite
- The sprite.position
- Where to stored the computed position, if null, the position is
created.units
- The units the computed position must be given into.public boolean nodeContains(GraphicElement elt, double x, double y)
public boolean edgeContains(GraphicElement elt, double x, double y)
public Values getNodeOrSpriteSize(GraphicElement elt)
public Point3 getNodeOrSpritePositionGU(GraphicElement elt, Point3 pos)
public void removeGraphViewport()
Camera
removeGraphViewport
in interface Camera
Camera.setGraphViewport(double, double, double, double)
public void setGraphViewport(double minx, double miny, double maxx, double maxy)
Camera
setGraphViewport
in interface Camera
minx
- The minimum abscissa visible.miny
- The minimum ordinate visible.maxx
- The maximum abscissa visible.maxy
- The maximum abscissa visible.Camera.removeGraphViewport()
public void resetView()
Camera
public void pushView(GraphicGraph graph)
popView()
to restore the saved transform. You
can only push one time the view.graph
- The graphic graph (used to check element visibility).public void popView()
#pushView()
is used.public void checkVisibility(GraphicGraph graph)
public boolean isNodeIn(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.public boolean isEdgeIn(GraphicEdge edge, double X1, double Y1, double X2, double Y2)
public void setPadding(GraphicGraph graph)
graph
- The graphic graph.public void autoFitView()
public void userView()
public double paddingXgu()
public double paddingYgu()
public double paddingXpx()
public double paddingYpx()
public void setBounds(double minx, double miny, double minz, double maxx, double maxy, double maxz)
public void setBounds(GraphicGraph graph)
public GraphMetrics getMetrics()
Camera
org.graphstream.ui.swingViewer.util.GraphMetrics
object
linked to this Camera. It can be used to convert pixels to graphic units and
vice versa.getMetrics
in interface Camera
public void setAutoFitView(boolean on)
setAutoFitView
in interface Camera
on
- If true, automatic adjustment is enabled.public void setBackend(Backend backend)
public Point3 transformGuToPx(double x, double y, double z)
transformGuToPx
in interface Camera
public Point3 transformPxToGu(double x, double y)
transformPxToGu
in interface Camera
x
- The source point abscissa in pixels.y
- The source point ordinate in pixels.public boolean isTextVisible(GraphicElement element)
public boolean isVisible(GraphicElement element)
public boolean isSpriteVisible(GraphicSprite sprite)
sprite
- The sprite to check.public boolean isSpriteIn(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.public boolean isEdgeVisible(GraphicEdge edge)
edge
- The edge to check.public GraphicElement findGraphicElementAt(GraphicGraph graph, java.util.EnumSet<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 Camera
graph
- The graph to search for.x
- The point abscissa.y
- The point ordinate.public double[] graphViewport()
public java.util.Collection<GraphicElement> allGraphicElementsIn(GraphicGraph graph, java.util.EnumSet<InteractiveElement> types, double x1, double y1, double x2, double y2)
allGraphicElementsIn
in interface Camera
public java.lang.String toString()
toString
in class java.lang.Object