FreeHEP API
Version v1.1

org.freehep.graphicsio
Class AbstractVectorGraphicsIO

java.lang.Object
  |
  +--java.awt.Graphics
        |
        +--java.awt.Graphics2D
              |
              +--org.freehep.graphics2d.VectorGraphics
                    |
                    +--org.freehep.graphics2d.AbstractVectorGraphics
                          |
                          +--org.freehep.graphicsio.VectorGraphicsIO
                                |
                                +--org.freehep.graphicsio.AbstractVectorGraphicsIO
All Implemented Interfaces:
VectorGraphicsConstants
Direct Known Subclasses:
CGMGraphics2D, DummyGraphics2D, EMFGraphics2D, PDFGraphics2D, PSGraphics2D, SVGGraphics2D, SWFGraphics2D

public abstract class AbstractVectorGraphicsIO
extends VectorGraphicsIO

This class provides an abstract VectorGraphicsIO class for specific output drivers.

Version:
$Id: AbstractVectorGraphicsIO.java,v 1.5 2002/09/04 21:59:38 duns Exp $
Author:
Charles Loomis, Mark Donszelmann

Field Summary
 
Fields inherited from interface org.freehep.graphics2d.VectorGraphicsConstants
NUMBER_OF_HORIZ_ALIGNMENTS, NUMBER_OF_SYMBOLS, NUMBER_OF_VERTICAL_ALIGNMENTS, SYMBOL_BOX, SYMBOL_CIRCLE, SYMBOL_CROSS, SYMBOL_DIAMOND, SYMBOL_DN_TRIANGLE, SYMBOL_HLINE, SYMBOL_PLUS, SYMBOL_STAR, SYMBOL_UP_TRIANGLE, SYMBOL_VLINE, TEXT_BASELINE, TEXT_BOTTOM, TEXT_CENTER, TEXT_LEFT, TEXT_RIGHT, TEXT_TOP
 
Constructor Summary
protected AbstractVectorGraphicsIO(AbstractVectorGraphicsIO graphics, boolean doRestoreOnDispose)
          Constructs a subgraphics context.
protected AbstractVectorGraphicsIO(Component component, boolean doRestoreOnDispose)
          Constructs a Graphics context with the following graphics state: Paint: The color of the component.
protected AbstractVectorGraphicsIO(Dimension size, boolean doRestoreOnDispose)
          Constructs a Graphics context with the following graphics state: Paint: black Font: Dailog, Plain, 12pt Stroke: Linewidth 1.0; No Dashing; Miter Join Style; Miter Limit 10; Square Endcaps; Transform: Identity Composite: AlphaComposite.SRC_OVER Clip: Rectangle(0, 0, size.width, size.height)
 
Method Summary
 void addRenderingHints(Map hints)
          Adds to table of rendering hints.
 void clearRect(double x, double y, double width, double height)
          Clears rectangle by painting it with the backgroundColor.
 void clip(Shape s)
          Clips using given shape.
 void clipRect(double x, double y, double width, double height)
          Clips rectangle.
 void clipRect(int x, int y, int width, int height)
          Clips rectangle.
abstract  void closeStream()
          Called to close the stream you are writing to.
protected  GeneralPath createShape(double[] xPoints, double[] yPoints, int nPoints, boolean close)
          Creates a polyline/polygon shape from a set of points.
 void dispose()
          Disposes of the graphics context.
 boolean drawImage(Image image, int x, int y, int width, int height, Color bgColor, ImageObserver observer)
          Draw (transparent) image.
 boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgColor, ImageObserver observer)
          Draw and resizes (transparent) image.
abstract  void drawRenderedImage(RenderedImage image, AffineTransform transform)
          Draws a rendered image using a transform.
 void endExport()
           
 String fixedPrecision(double d)
           
 Shape getClip()
          Gets the current clip in form of a Shape (Rectangle).
 Rectangle getClipBounds()
          Gets the current clip in form of a Rectangle.
 Rectangle getClipBounds(Rectangle r)
          Gets the current clip in form of a Rectangle.
 Composite getComposite()
          Gets current composite.
 Font getFont()
          Gets the current font.
 FontMetrics getFontMetrics(Font font)
          Gets the fontmetrics.
 FontRenderContext getFontRenderContext()
          Gets the current font render context.
 Object getRenderingHint(RenderingHints.Key key)
          Gets a given rendering hint.
 RenderingHints getRenderingHints()
          Gets a copy of the rendering hints.
 Dimension getSize()
           
 Stroke getStroke()
          Get the current stroke.
 AffineTransform getTransform()
          Get the current transform.
protected  void handleException(Exception exception)
          Handles an exception which has been caught.
 void printComment(String comment)
           
protected  void resetClip(Rectangle clip)
           
 void rotate(double theta)
          Rotate the current transform over the Z-axis.
 void scale(double sx, double sy)
          Scales the current transform.
 void setClip(double x, double y, double width, double height)
          Clips rectangle.
 void setClip(int x, int y, int width, int height)
          Clips rectangle.
 void setClip(Shape shape)
          Clips shape.
 void setColor(Color color)
          Sets the current color and the current paint.
 void setComposite(Composite composite)
          Sets current composite.
 void setFont(Font font)
          Sets the current font.
 void setPaint(Paint paint)
          Sets the current paint.
 void setRenderingHint(RenderingHints.Key key, Object hint)
          Sets a given rendering hint.
 void setRenderingHints(Map hints)
          Sets table of rendering hints.
 void setStroke(Stroke stroke)
          Sets the current stroke.
 void setTransform(AffineTransform transform)
          Set the current transform.
 void shear(double shx, double shy)
          Shears the current transform.
 void startExport()
           
 void transform(AffineTransform transform)
          Transforms the current transform.
 void translate(double x, double y)
          Translates the current transform.
protected  void writeCap(int cap)
          Writes out the cap of the stroke.
protected  void writeClip(Rectangle rectangle)
          Write out Rectangle clip.
protected abstract  void writeClip(Rectangle2D rectangle)
          Write out Rectangle2D clip.
protected abstract  void writeClip(Shape shape)
          Write out Shape clip.
abstract  void writeComment(String comment)
          Called to Write out a comment.
protected  void writeDash(double[] dash, double phase)
          Writes out the dash of the stroke.
protected  void writeError(Exception exception)
          Writes out an error, by default the stack trace is printed.
protected abstract  void writeGraphicsRestore()
          Writes out the restore of a graphics context.
protected abstract  void writeGraphicsSave()
          Writes out the save of a graphics context for a later restore.
 void writeGraphicsState()
          Called to write the initial graphics state.
abstract  void writeHeader()
          Called to write the header part of the output.
protected abstract  boolean writeImage(Image image, int x, int y, int width, int height, boolean mask, ImageObserver observer)
          Writes out (transparent) image.
protected  void writeJoin(int join)
          Writes out the join of the stroke.
protected  void writeMiterLimit(float limit)
          Writes out the miter limit of the stroke.
protected abstract  void writePaint(Color color)
          Writes out paint as the given color.
protected abstract  void writePaint(GradientPaint paint)
          Writes out paint as the given gradient.
protected abstract  void writePaint(Paint paint)
          Writes out paint.
protected abstract  void writePaint(TexturePaint paint)
          Writes out paint as the given texture.
protected  void writeSetClip(Shape shape)
          Called to set a clip, no intersection made.
protected  void writeStroke(Stroke stroke)
          Writes the current stroke.
abstract  void writeTrailer()
          Called to write the trailing part of the output.
protected abstract  void writeTransform(AffineTransform transform)
          Writes out the transform as it needs to be concatenated to the internal transform of the output format.
protected  void writeWarning(Exception exception)
          Writes out a warning, by default to System.err.
protected  void writeWarning(String warning)
          Writes out a warning, by default to System.err.
protected  void writeWidth(float width)
          Writes out the width of the stroke.
 
Methods inherited from class org.freehep.graphicsio.VectorGraphicsIO
copyResourceTo, copyResourceTo
 
Methods inherited from class org.freehep.graphics2d.AbstractVectorGraphics
clearRect, createShape, drawArc, drawArc, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawLine, drawLine, drawOval, drawOval, drawPolygon, drawPolygon, drawPolyline, drawPolyline, drawRect, drawRect, drawRenderableImage, drawRoundRect, drawRoundRect, drawString, drawString, drawString, drawString, drawString, drawString, drawSymbol, drawSymbol, fillArc, fillArc, fillOval, fillOval, fillPolygon, fillPolygon, fillRect, fillRect, fillRoundRect, fillRoundRect, fillSymbol, fillSymbol, getBackground, getColor, getColorMode, getCreator, getPaint, getPrintColor, isDeviceIndependent, rotate, setBackground, setColorMode, setCreator, setDeviceIndependent, setLineWidth, setLineWidth, translate
 
Methods inherited from class org.freehep.graphics2d.VectorGraphics
copyArea, create, create, create, create, draw, drawGlyphVector, drawString, drawString, drawString, drawString, fill, fillAndDraw, getDeviceConfiguration, getSymbol, getTextAlignment, getXalignment, getYalignment, hit, setPaintMode, setXORMode, toString
 
Methods inherited from class java.awt.Graphics2D
draw3DRect, fill3DRect
 
Methods inherited from class java.awt.Graphics
drawBytes, drawChars, drawPolygon, fillPolygon, finalize, getClipRect, getFontMetrics, hitClip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractVectorGraphicsIO

protected AbstractVectorGraphicsIO(Dimension size,
                                   boolean doRestoreOnDispose)
Constructs a Graphics context with the following graphics state:

Parameters:
size - rectangle specifying the bounds of the image
doRestoreOnDispose - true if writeGraphicsRestore() should be called when this graphics context is disposed of.

AbstractVectorGraphicsIO

protected AbstractVectorGraphicsIO(Component component,
                                   boolean doRestoreOnDispose)
Constructs a Graphics context with the following graphics state:

Parameters:
component - to be used to initialize the values of the graphics state
doRestoreOnDispose - true if writeGraphicsRestore() should be called when this graphics context is disposed of.

AbstractVectorGraphicsIO

protected AbstractVectorGraphicsIO(AbstractVectorGraphicsIO graphics,
                                   boolean doRestoreOnDispose)
Constructs a subgraphics context.

Parameters:
graphics - context to clone from
doRestoreOnDispose - true if writeGraphicsRestore() should be called when this graphics context is disposed of.
Method Detail

getSize

public Dimension getSize()
Specified by:
getSize in class VectorGraphicsIO

startExport

public void startExport()
Specified by:
startExport in class VectorGraphics

endExport

public void endExport()
Specified by:
endExport in class VectorGraphics

writeHeader

public abstract void writeHeader()
                          throws IOException
Called to write the header part of the output.

IOException

writeGraphicsState

public void writeGraphicsState()
                        throws IOException
Called to write the initial graphics state.

IOException

writeTrailer

public abstract void writeTrailer()
                           throws IOException
Called to write the trailing part of the output.

IOException

closeStream

public abstract void closeStream()
                          throws IOException
Called to close the stream you are writing to.

IOException

printComment

public void printComment(String comment)
Specified by:
printComment in class VectorGraphicsIO

writeComment

public abstract void writeComment(String comment)
                           throws IOException
Called to Write out a comment.

Parameters:
comment - to be written
IOException

resetClip

protected void resetClip(Rectangle clip)

dispose

public void dispose()
Disposes of the graphics context. If on creation restoreOnDispose was true, writeGraphicsRestore() will be called.

Specified by:
dispose in class VectorGraphics

writeGraphicsSave

protected abstract void writeGraphicsSave()
                                   throws IOException
Writes out the save of a graphics context for a later restore. Some implementations keep track of this by hand if the output format does not support it.

IOException

writeGraphicsRestore

protected abstract void writeGraphicsRestore()
                                      throws IOException
Writes out the restore of a graphics context. Some implementations keep track of this by hand if the output format does not support it.

IOException

drawImage

public boolean drawImage(Image image,
                         int x,
                         int y,
                         int width,
                         int height,
                         Color bgColor,
                         ImageObserver observer)
Draw (transparent) image. Calls writeImage(...).

Specified by:
drawImage in class VectorGraphics
Parameters:
image - image to be drawn
bgColor - background color
observer - for updates if image still incomplete
Returns:
true if successful

drawImage

public boolean drawImage(Image image,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         Color bgColor,
                         ImageObserver observer)
Draw and resizes (transparent) image. Calls writeImage(...).

Specified by:
drawImage in class VectorGraphics
Parameters:
image - image to be drawn
bgColor - background color
observer - for updates if image still incomplete
Returns:
true if successful

clearRect

public void clearRect(double x,
                      double y,
                      double width,
                      double height)
Clears rectangle by painting it with the backgroundColor.

Specified by:
clearRect in class VectorGraphics

drawRenderedImage

public abstract void drawRenderedImage(RenderedImage image,
                                       AffineTransform transform)
Draws a rendered image using a transform.

Specified by:
drawRenderedImage in class VectorGraphics
Parameters:
image - to be drawn
transform - transform to be used on the image

writeImage

protected abstract boolean writeImage(Image image,
                                      int x,
                                      int y,
                                      int width,
                                      int height,
                                      boolean mask,
                                      ImageObserver observer)
                               throws IOException
Writes out (transparent) image.

Parameters:
image - image to be written
mask - true if image masks background
observer - for updates if image still incomplete
Returns:
true if successful
IOException

getTransform

public AffineTransform getTransform()
Get the current transform.

Specified by:
getTransform in class VectorGraphics
Returns:
current transform

setTransform

public void setTransform(AffineTransform transform)
Set the current transform. Since most output formats do not implement this functionality, the inverse transform of the currentTransform is calculated and multiplied by the transform to be set. The result is then forwarded by a call to writeTransform(Transform).

Specified by:
setTransform in class VectorGraphics
Parameters:
transform - to be set

transform

public void transform(AffineTransform transform)
Transforms the current transform. Calls writeTransform(Transform)

Specified by:
transform in class VectorGraphics
Parameters:
transform - to be applied

translate

public void translate(double x,
                      double y)
Translates the current transform. Calls writeTransform(Transform)

Specified by:
translate in class VectorGraphics

rotate

public void rotate(double theta)
Rotate the current transform over the Z-axis. Calls writeTransform(Transform). Rotating with a positive angle theta rotates points on the positive x axis toward the positive y axis.

Specified by:
rotate in class VectorGraphics
Parameters:
theta - radians over which to rotate

scale

public void scale(double sx,
                  double sy)
Scales the current transform. Calls writeTransform(Transform).

Specified by:
scale in class VectorGraphics

shear

public void shear(double shx,
                  double shy)
Shears the current transform. Calls writeTransform(Transform).

Specified by:
shear in class VectorGraphics

writeTransform

protected abstract void writeTransform(AffineTransform transform)
                                throws IOException
Writes out the transform as it needs to be concatenated to the internal transform of the output format. If there is no implementation of an internal transform, then this method needs to do nothing, BUT all coordinates need to be transformed by the currentTransform before being written out.

Parameters:
transform - to be written
IOException

getClip

public Shape getClip()
Gets the current clip in form of a Shape (Rectangle).

Specified by:
getClip in class VectorGraphics
Returns:
current clip

getClipBounds

public Rectangle getClipBounds()
Gets the current clip in form of a Rectangle.

Specified by:
getClipBounds in class VectorGraphics
Returns:
current clip

getClipBounds

public Rectangle getClipBounds(Rectangle r)
Gets the current clip in form of a Rectangle.

Specified by:
getClipBounds in class VectorGraphics
Returns:
current clip

clipRect

public void clipRect(int x,
                     int y,
                     int width,
                     int height)
Clips rectangle. Calls clip(Rectangle).

Specified by:
clipRect in class VectorGraphics

clipRect

public void clipRect(double x,
                     double y,
                     double width,
                     double height)
Clips rectangle. Calls clip(Rectangle2D).

Specified by:
clipRect in class VectorGraphics

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)
Clips rectangle. Calls clip(Rectangle).

Specified by:
setClip in class VectorGraphics

setClip

public void setClip(double x,
                    double y,
                    double width,
                    double height)
Clips rectangle. Calls clip(Rectangle2D).

Specified by:
setClip in class VectorGraphics

setClip

public void setClip(Shape shape)
Clips shape. Sets the userClip to shape and calls clip(Shape).

Specified by:
setClip in class VectorGraphics
Parameters:
shape - used for clipping

writeSetClip

protected void writeSetClip(Shape shape)
                     throws IOException
Called to set a clip, no intersection made. Calls clip(shape).

IOException

clip

public void clip(Shape s)
Clips using given shape. Dispatches to writeClip(Rectangle), writeClip(Rectangle2D) or writeClip(Shape).

Specified by:
clip in class VectorGraphics

writeClip

protected void writeClip(Rectangle rectangle)
                  throws IOException
Write out Rectangle clip. Calls writeClip(Rectangle2D).

Parameters:
rectangle - to be used for clipping
IOException

writeClip

protected abstract void writeClip(Rectangle2D rectangle)
                           throws IOException
Write out Rectangle2D clip.

Parameters:
rectangle - to be used for clipping
IOException

writeClip

protected abstract void writeClip(Shape shape)
                           throws IOException
Write out Shape clip.

Parameters:
shape - to be used for clipping
IOException

getStroke

public Stroke getStroke()
Get the current stroke.

Specified by:
getStroke in class VectorGraphics
Returns:
current stroke

setStroke

public void setStroke(Stroke stroke)
Sets the current stroke. If stroke is an instance of BasicStroke it will call writeWidth, writeCap, writeJoin, writeMiterLimit and writeDash, if any were different than the current stroke.

Specified by:
setStroke in class VectorGraphics
Parameters:
stroke - to be set

writeStroke

protected void writeStroke(Stroke stroke)
                    throws IOException
Writes the current stroke. If stroke is an instance of BasicStroke it will call writeWidth, writeCap, writeJoin, writeMiterLimit and writeDash, if any were different than the current stroke.

IOException

writeWidth

protected void writeWidth(float width)
                   throws IOException
Writes out the width of the stroke.

Parameters:
width - of the stroke
IOException

writeCap

protected void writeCap(int cap)
                 throws IOException
Writes out the cap of the stroke.

Parameters:
cap - of the stroke
IOException

writeJoin

protected void writeJoin(int join)
                  throws IOException
Writes out the join of the stroke.

Parameters:
join - of the stroke
IOException

writeMiterLimit

protected void writeMiterLimit(float limit)
                        throws IOException
Writes out the miter limit of the stroke.

IOException

writeDash

protected void writeDash(double[] dash,
                         double phase)
                  throws IOException
Writes out the dash of the stroke.

Parameters:
dash - dash pattern, empty array is solid line
phase - of the dash pattern
IOException

setColor

public void setColor(Color color)
Description copied from class: AbstractVectorGraphics
Sets the current color and the current paint. Calls writePaint(Color).

Overrides:
setColor in class AbstractVectorGraphics
Parameters:
color - to be set

setPaint

public void setPaint(Paint paint)
Sets the current paint. Dispatches to writePaint(Color), writePaint(GradientPaint), writePaint(TexturePaint paint) or writePaint(Paint). In the case paint is a Color the current color is also changed.

Overrides:
setPaint in class AbstractVectorGraphics
Parameters:
paint - to be set
Returns:
current paint

writePaint

protected abstract void writePaint(Color color)
                            throws IOException
Writes out paint as the given color.

Parameters:
color - to be written
IOException

writePaint

protected abstract void writePaint(GradientPaint paint)
                            throws IOException
Writes out paint as the given gradient.

Parameters:
paint - to be written
IOException

writePaint

protected abstract void writePaint(TexturePaint paint)
                            throws IOException
Writes out paint as the given texture.

Parameters:
paint - to be written
IOException

writePaint

protected abstract void writePaint(Paint paint)
                            throws IOException
Writes out paint.

Parameters:
paint - to be written
IOException

getFontRenderContext

public FontRenderContext getFontRenderContext()
Gets the current font render context. This returns an standard FontRenderContext with an upside down matrix, anti-aliasing and uses fractional metrics.

Specified by:
getFontRenderContext in class VectorGraphics
Returns:
current font render context

getFont

public Font getFont()
Gets the current font.

Specified by:
getFont in class VectorGraphics
Returns:
current font

getFontMetrics

public FontMetrics getFontMetrics(Font font)
Gets the fontmetrics.

Specified by:
getFontMetrics in class VectorGraphics
Parameters:
font - to be used for retrieving fontmetrics
Returns:
fontmetrics for given font

setFont

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

Specified by:
setFont in class VectorGraphics
Parameters:
font - to be set

getRenderingHints

public RenderingHints getRenderingHints()
Gets a copy of the rendering hints.

Specified by:
getRenderingHints in class VectorGraphics
Returns:
clone of table of rendering hints.

addRenderingHints

public void addRenderingHints(Map hints)
Adds to table of rendering hints.

Specified by:
addRenderingHints in class VectorGraphics
Parameters:
hints - table to be added

setRenderingHints

public void setRenderingHints(Map hints)
Sets table of rendering hints.

Specified by:
setRenderingHints in class VectorGraphics
Parameters:
hints - table to be set

getRenderingHint

public Object getRenderingHint(RenderingHints.Key key)
Gets a given rendering hint.

Specified by:
getRenderingHint in class VectorGraphics
Parameters:
key - hint key
Returns:
hint associated to key

setRenderingHint

public void setRenderingHint(RenderingHints.Key key,
                             Object hint)
Sets a given rendering hint.

Specified by:
setRenderingHint in class VectorGraphics
Parameters:
key - hint key
hint - to be associated with key

getComposite

public Composite getComposite()
Gets current composite.

Specified by:
getComposite in class VectorGraphics
Returns:
current composite

setComposite

public void setComposite(Composite composite)
Sets current composite.

Specified by:
setComposite in class VectorGraphics
Parameters:
composite - to be set

fixedPrecision

public String fixedPrecision(double d)

handleException

protected void handleException(Exception exception)
Handles an exception which has been caught. Dispatches exception to writeWarning for UnsupportedOperationExceptions and writeError for others

Parameters:
exception - to be handled

writeWarning

protected void writeWarning(Exception exception)
Writes out a warning, by default to System.err.

Parameters:
exception - warning to be written

writeWarning

protected void writeWarning(String warning)
Writes out a warning, by default to System.err.

Parameters:
warning - to be written

writeError

protected void writeError(Exception exception)
Writes out an error, by default the stack trace is printed.

Parameters:
exception - error to be reported

createShape

protected GeneralPath createShape(double[] xPoints,
                                  double[] yPoints,
                                  int nPoints,
                                  boolean close)
Description copied from class: AbstractVectorGraphics
Creates a polyline/polygon shape from a set of points. Needs to be defined in subclass because its implementations could be device specific

Specified by:
createShape in class AbstractVectorGraphics
Parameters:
close - is shape closed

FreeHEP API
Version v1.1

Copyright © 2000-2002 FreeHEP, All Rights Reserved.