scenic
Class ScenicGraphics

java.lang.Object
  extended by scenic.ScenicGraphics

public class ScenicGraphics
extends java.lang.Object

ScenicGraphics class offers an easy to use interface for creating scene trees. Instead of creating scene graphs directly, Graphics class has a more traditional method-based interface. The Graphics class transforms the method calls into appropriate scene graphs. Paths can be created using methods that create lines, curves, arcs and rectangles These paths can then be either stroked, filled or clipped to. Text can also be drawn using simple method calls. The current affine transformation can easily be changed using different methods which translate, scale or rotate the current transformation. The Graphics object also has a stack which can be used to store and restore the state of the Graphics object.


Constructor Summary
ScenicGraphics(SceneContainer scene)
          Constructs a new Graphics object using the given SceneContainer as the root node.
ScenicGraphics(SceneContainer scene, java.awt.geom.AffineTransform transform)
          Constructs a new Graphics object using the given SceneContainer as the root node.
ScenicGraphics(ScenicGraphics parent)
          Construct a new ScenicGraphics object that inherits the state of the given ScenicGraphics object.
 
Method Summary
 void add(SceneNode node)
          Adds a scene node to the scene.
 void arc(double x, double y, double xRadius, double yRadius, double rotation, double startAngle, double stopAngle)
          Draws an elliptic arc starting from the given position.
 void arcTo(double xRadius, double yRadius, double rotation, double startAngle, double stopAngle)
          Draws an elliptic arc starting from the current position.
 void clear()
          Clears the current scene.
 void clip()
          Clips to the area inside the current path.
 void clipTo(SceneNode clipScene)
          Clips graphics using the given clip scene.
 void close()
          Closes the current subpath.
 ScenicGraphics create()
          Creates a copy of this graphics object.
 void curveTo(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
          Draws a quadratic Bezier-curve using the given control points.
 void curveTo(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D p3)
          Draws a cubic Bezier-curve using the given control points.
 void drawGlyphs(int[] glyphCodes, float[] positions)
          Draws the given glyphs using the current font, fill color and other settings.
 void drawImage(ScenicImage img)
          Draws an image.
 void drawImage(ScenicImage img, java.awt.geom.Rectangle2D sourceRect)
          Draws the given part of an image.
 void drawText(java.lang.String text)
          Draws the given text using the current font, fill color and other settings.
 void drawText(java.lang.String text, float[] positions)
          Draws the given text using the current font, fill color and other settings.
 void fill()
          Fills the current path.
 void fillAndStroke()
          Fills and strokes the current path.
 Path getPath()
          Gets a Path object that contains the current path.
 double getPixelSize()
          Gets the square root of the area of a 1 by 1 rectangle when transformed into screen coordinates.
 java.awt.geom.Rectangle2D getTextLogicalBounds(java.lang.String text)
          Returns the logical bounds of the given text.
 java.awt.geom.AffineTransform getTransform()
          Gets the total transformation of the current scene node.
 void lineTo(double x, double y)
          Draws a straight line to the given position.
 void moveTo(double x, double y)
          Begins a new subpath from the given position.
 void pop()
          Pops the state from the stack.
 void push()
          Pushes the state of this object into the stack.
 void rectangle(double x, double y, double width, double height)
          Draws a rectangle.
 void rotate(double angle)
          Rotates the current transformation by the given angle.
 void rotate(double angle, double pivotX, double pivotY)
          Rotates the current transformation around the given pivot point by the given angle.
 void roundedRectangle(double x, double y, double width, double height, double radius)
          Draws a rectangle with rounded edges.
 void scale(double x, double y)
          Scales the current transformation matrix by the given amount.
 void setAntialias(boolean aa)
          Sets antialiasing.
 void setAntialiasingFilter(Filter filter)
          Sets the filter that is used for antialiasing.
 void setDashArray(float[] lineDashLengths)
          Sets the line dash pattern.
 void setDashPhase(double lineDashPhase)
          Sets the phase of the line dash pattern.
 void setEndCap(int lineCap)
          Sets the line cap style.
 void setFillBrush(SceneNode brush)
          Sets the brush used for filling paths and drawing text.
 void setFillColor(ScenicColor c)
          Sets the color that is used for filling paths and drawing text.
 void setFont(java.awt.Font font)
          Sets the current font.
 void setLineJoin(int lineJoin)
          Sets the line join style.
 void setLineWidth(double width)
          Sets the line width.
 void setMiterLimit(double miterLimit)
          Sets the miter limit.
 void setStrokeBrush(SceneNode brush)
          Sets the brush used for stroking paths.
 void setStrokeColor(ScenicColor c)
          Sets the color that is used for stroking paths.
 void setTextPosition(double x, double y)
          Sets the text position.
 void setUsesFractionalFontMetrics(boolean b)
          Sets whatever fractional metrics are used to calculate glyph bounds.
 void shear(double x, double y)
          Shears the current transformation matrix by the given amount.
 void stroke()
          Strokes the current path.
 void transform(java.awt.geom.AffineTransform m)
          Multiplies the current transformation matrix with the given affine transform.
 void translate(double dx, double dy)
          Translates the current transformation matrix by the given displacement.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScenicGraphics

public ScenicGraphics(SceneContainer scene,
                      java.awt.geom.AffineTransform transform)
Constructs a new Graphics object using the given SceneContainer as the root node. The transformation matrix of the root node is also given. This matrix is used to position hinted glyphs properly.

Parameters:
scene - The root node into which graphics is drawn.
transform - The transformation matrix of the root node.

ScenicGraphics

public ScenicGraphics(SceneContainer scene)
Constructs a new Graphics object using the given SceneContainer as the root node.

Parameters:
scene - The root node into which graphics is drawn.

ScenicGraphics

public ScenicGraphics(ScenicGraphics parent)
Construct a new ScenicGraphics object that inherits the state of the given ScenicGraphics object.

Parameters:
parent - the parent object
Method Detail

create

public ScenicGraphics create()
Creates a copy of this graphics object.

Returns:
the copy

clear

public void clear()
Clears the current scene.


push

public void push()
Pushes the state of this object into the stack. The state includes the entire internal state of the Graphics object excluding the current path.


pop

public void pop()
Pops the state from the stack.


transform

public void transform(java.awt.geom.AffineTransform m)
Multiplies the current transformation matrix with the given affine transform.

Parameters:
m - the affine transform

translate

public void translate(double dx,
                      double dy)
Translates the current transformation matrix by the given displacement.

Parameters:
dx - x coordinate of the translation
dy - y coordinate of the translation

scale

public void scale(double x,
                  double y)
Scales the current transformation matrix by the given amount.

Parameters:
x - x coordinate of the scale factor
y - y coordinate of the scale factor

rotate

public void rotate(double angle)
Rotates the current transformation by the given angle.

Parameters:
angle - rotation in degrees.

rotate

public void rotate(double angle,
                   double pivotX,
                   double pivotY)
Rotates the current transformation around the given pivot point by the given angle.

Parameters:
angle - rotation in degrees.
pivotX - x coordinate of the pivot point.
pivotY - y coordinate of the pivot point.

shear

public void shear(double x,
                  double y)
Shears the current transformation matrix by the given amount.

Parameters:
x - x coordinate of the shear factor
y - y coordinate of the shear factor

getTransform

public java.awt.geom.AffineTransform getTransform()
Gets the total transformation of the current scene node.

Returns:
the total transformation.

getPixelSize

public double getPixelSize()
Gets the square root of the area of a 1 by 1 rectangle when transformed into screen coordinates.

Returns:
the pixel size.

setStrokeColor

public void setStrokeColor(ScenicColor c)
Sets the color that is used for stroking paths.

Parameters:
c - stroke color.

setStrokeBrush

public void setStrokeBrush(SceneNode brush)
Sets the brush used for stroking paths.

Parameters:
brush - brush used for stroking.

setFillColor

public void setFillColor(ScenicColor c)
Sets the color that is used for filling paths and drawing text.

Parameters:
c - fill color.

setFillBrush

public void setFillBrush(SceneNode brush)
Sets the brush used for filling paths and drawing text.

Parameters:
brush - brush used for filling.

setFont

public void setFont(java.awt.Font font)
Sets the current font.

Parameters:
font - the font.

setTextPosition

public void setTextPosition(double x,
                            double y)
Sets the text position. The text position defines the start point for drawing text in logical coordinates.

Parameters:
x - x coordinate of the text position.
y - y coordinate of the text position.

setLineWidth

public void setLineWidth(double width)
Sets the line width. The line width is given in logical coordinates.

Parameters:
width - the line width.

setEndCap

public void setEndCap(int lineCap)
Sets the line cap style. The line cap style determines how the ends of paths are drawn.

Parameters:
lineCap - the line cap style.

setLineJoin

public void setLineJoin(int lineJoin)
Sets the line join style. The line join style determines how joints between lines are drawn.

Parameters:
lineJoin - the line join style.

setMiterLimit

public void setMiterLimit(double miterLimit)
Sets the miter limit. The miter limit determines the cutoff length of the spikes when using miter join.

Parameters:
miterLimit - the miter limit.

setDashArray

public void setDashArray(float[] lineDashLengths)
Sets the line dash pattern. The dash pattern is defined using an array which contains the lengths of consecutive visible and non-visible portions of the dash pattern. The lenths are given in logical units.

Parameters:
lineDashLengths - the line dash pattern.

setDashPhase

public void setDashPhase(double lineDashPhase)
Sets the phase of the line dash pattern. The phase defines the starting position of the line dash pattern.

Parameters:
lineDashPhase - the line dash phase.

setAntialias

public void setAntialias(boolean aa)
Sets antialiasing. The antialiasing affects all graphics, including lines, polygons an text.

Parameters:
aa - the antialiasing setting.

setAntialiasingFilter

public void setAntialiasingFilter(Filter filter)
Sets the filter that is used for antialiasing.

Parameters:
filter - antialiasing filter

setUsesFractionalFontMetrics

public void setUsesFractionalFontMetrics(boolean b)
Sets whatever fractional metrics are used to calculate glyph bounds. This parameter affects only the positioning of characters but does not change their appearance. This parameter also affects the bounds returned by getTextLogialBounds.

Parameters:
b - the fractional metrics setting.

drawText

public void drawText(java.lang.String text)
Draws the given text using the current font, fill color and other settings.

Parameters:
text - the text to be drawn.

drawText

public void drawText(java.lang.String text,
                     float[] positions)
Draws the given text using the current font, fill color and other settings. The positions of the characters are given as an array of floats. Each position is given as two numbers the x-position and y-position.

Parameters:
text - the text to be drawn.
positions - the positions of the characters.

drawGlyphs

public void drawGlyphs(int[] glyphCodes,
                       float[] positions)
Draws the given glyphs using the current font, fill color and other settings. The positions of the glyphs are given as an array of floats. Each position is given as two numbers the x-position and y-position.

Parameters:
glyphCodes - the glyph codes.
positions - the positions of the characters.

getTextLogicalBounds

public java.awt.geom.Rectangle2D getTextLogicalBounds(java.lang.String text)
Returns the logical bounds of the given text.

Parameters:
text - the text.
Returns:
the logical bounds of the text.

moveTo

public void moveTo(double x,
                   double y)
Begins a new subpath from the given position.


lineTo

public void lineTo(double x,
                   double y)
Draws a straight line to the given position.


curveTo

public void curveTo(java.awt.geom.Point2D p1,
                    java.awt.geom.Point2D p2)
Draws a quadratic Bezier-curve using the given control points. The first control point is the current position.

Parameters:
p1 - the second control point.
p2 - the third control point.

curveTo

public void curveTo(java.awt.geom.Point2D p1,
                    java.awt.geom.Point2D p2,
                    java.awt.geom.Point2D p3)
Draws a cubic Bezier-curve using the given control points. The first control point is the current position.

Parameters:
p1 - the second control point.
p2 - the third control point.
p3 - the fourth control point.

arcTo

public void arcTo(double xRadius,
                  double yRadius,
                  double rotation,
                  double startAngle,
                  double stopAngle)
Draws an elliptic arc starting from the current position.

Parameters:
xRadius - the x radius of the ellipse.
yRadius - the y radius of the ellipse.
rotation - the rotation of the ellipse in degrees.
startAngle - the start angle of the arc in degrees.
stopAngle - the stop angle of the arc in degrees.

arc

public void arc(double x,
                double y,
                double xRadius,
                double yRadius,
                double rotation,
                double startAngle,
                double stopAngle)
Draws an elliptic arc starting from the given position.

Parameters:
x - the x-coordinate of the starting point of the arc.
y - the y-coordinate of the starting point of the arc.
xRadius - the x radius of the ellipse.
yRadius - the y radius of the ellipse.
rotation - the rotation of the ellipse in degrees.
startAngle - the start angle of the arc in degrees.
stopAngle - the stop angle of the arc in degrees.

rectangle

public void rectangle(double x,
                      double y,
                      double width,
                      double height)
Draws a rectangle.

Parameters:
x - the left side of the rectangle.
y - the top of the rectangle.
width - the width of the rectangle.
height - the height of the rectangle.

roundedRectangle

public void roundedRectangle(double x,
                             double y,
                             double width,
                             double height,
                             double radius)
Draws a rectangle with rounded edges.

Parameters:
x - the left side of the rectangle.
y - the top of the rectangle.
width - the width of the rectangle.
height - the height of the rectangle.
radius - the radius of the rounded edges.

close

public void close()
Closes the current subpath.


stroke

public void stroke()
Strokes the current path.


fill

public void fill()
Fills the current path.


fillAndStroke

public void fillAndStroke()
Fills and strokes the current path.


clip

public void clip()
Clips to the area inside the current path.


drawImage

public void drawImage(ScenicImage img)
Draws an image.

Parameters:
img - the image.

drawImage

public void drawImage(ScenicImage img,
                      java.awt.geom.Rectangle2D sourceRect)
Draws the given part of an image.

Parameters:
img - the image.
sourceRect - the part of the image that is displayed.

getPath

public Path getPath()
Gets a Path object that contains the current path.

Returns:
the current path.

add

public void add(SceneNode node)
Adds a scene node to the scene.

Parameters:
node - the scene node top be added.

clipTo

public void clipTo(SceneNode clipScene)
Clips graphics using the given clip scene.

Parameters:
clipScene - the scene node that is used for clipping.