public class DefaultCamera extends Object implements 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 ?".
Constructor and Description |
---|
DefaultCamera(GraphicGraph graph)
New camera.
|
Modifier and Type | Method and Description |
---|---|
Collection<GraphicElement> |
allNodesOrSpritesIn(GraphicGraph graph,
double x1,
double y1,
double x2,
double y2)
Search for all the nodes and sprites contained inside the rectangle
(x1,y1)-(x2,y2).
|
void |
checkVisibility(GraphicGraph graph)
Process each node to check if it is in the actual view port, and mark
invisible nodes.
|
GraphicElement |
findNodeOrSpriteAt(GraphicGraph graph,
double x,
double y)
Search for the first node or sprite (in that order) that contains the
point at coordinates (x, y).
|
double |
getGraphDimension()
A number in GU that gives the approximate graph size (often the diagonal
of the graph).
|
double[] |
getGraphViewport() |
GraphMetrics |
getMetrics()
Get the
GraphMetrics object linked to this Camera. |
Point2D.Double |
getSpritePosition(GraphicSprite sprite,
Point2D.Double pos,
StyleConstants.Units units)
Compute the real position of a sprite according to its eventual
attachment in graph units.
|
Point3 |
getViewCenter()
The view centre (a point in graph units).
|
double |
getViewPercent()
The portion of the graph visible.
|
double |
getViewRotation()
The current rotation angle.
|
boolean |
isVisible(GraphicElement element)
True if the element should be visible on screen.
|
void |
popView(Graphics2D g2)
Restore the transform that was used before
pushView(GraphicGraph, Graphics2D) is used. |
void |
pushView(GraphicGraph graph,
Graphics2D g2)
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 |
setBounds(double minx,
double miny,
double minz,
double maxx,
double maxy,
double maxz)
Set the bounds of the graphic graph in GU.
|
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) |
void |
setViewCenter(double x,
double y,
double z)
Change the view centre.
|
void |
setViewPercent(double percent)
Zoom the view.
|
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.
|
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.
|
public DefaultCamera(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(double x, double y)
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 double getViewRotation()
Camera
getViewRotation
in interface Camera
public GraphMetrics getMetrics()
Camera
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 resetView()
Camera
public void setBounds(double minx, double miny, double minz, double maxx, double maxy, double maxz)
Camera
public double getGraphDimension()
Camera
getGraphDimension
in interface Camera
public boolean isVisible(GraphicElement element)
public Point3 transformPxToGu(double x, double y)
Camera
transformPxToGu
in interface Camera
x
- The source point abscissa in pixels.y
- The source point ordinate in pixels.public Point3 transformGuToPx(double x, double y, double z)
Camera
transformGuToPx
in interface Camera
public void checkVisibility(GraphicGraph graph)
public GraphicElement findNodeOrSpriteAt(GraphicGraph graph, double x, double y)
graph
- The graph to search for.x
- The point abscissa.y
- The point ordinate.public Collection<GraphicElement> allNodesOrSpritesIn(GraphicGraph graph, double x1, double y1, double x2, double y2)
graph
- The graph to search for.x1
- The rectangle lowest point abscissa.y1
- The rectangle lowest point ordinate.x2
- The rectangle highest point abscissa.y2
- The rectangle highest point ordinate.public Point2D.Double getSpritePosition(GraphicSprite sprite, Point2D.Double 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 double[] getGraphViewport()
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 removeGraphViewport()
Camera
removeGraphViewport
in interface Camera
Camera.setGraphViewport(double, double, double, double)
public void pushView(GraphicGraph graph, 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(Graphics2D g2)
pushView(GraphicGraph, Graphics2D)
is used.g2
- The Swing graphics to restore.public void setAutoFitView(boolean on)
setAutoFitView
in interface Camera
on
- If true, automatic adjustment is enabled.public void setZoom(double z)
z
- The zoom.public void setViewRotation(double theta)
setViewRotation
in interface Camera
theta
- 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(GraphicGraph graph)
graph
- The graphic graph.Copyright © 2015. All rights reserved.