comirva.visu.epsgraphics
Class EpsGraphics2D

java.lang.Object
  extended by java.awt.Graphics
      extended by java.awt.Graphics2D
          extended by comirva.visu.epsgraphics.EpsGraphics2D

public class EpsGraphics2D
extends Graphics2D

This class provides postscript generation. Use this class just like the Graphics2D class to draw geometric figures. Usage: Process every drawing operation (except redrawing after resizing/restoring the window), coordinate system transformation, color or font setting, clipping, stroke type changing etc. that you perform on the standard graphics object (for screen output) on this class too. This class will save every information necessary for postscript output. Moreover, you can add comments to the postscript source file. If you want to generate the output just call either the toPS() or toEPS() method.


Constructor Summary
EpsGraphics2D()
           
 
Method Summary
 void addComment(String comment)
          Adds an eps comment.
 void addRenderingHints(Map<?,?> hints)
           
 void clearRect(int x, int y, int width, int height)
           
 void clip(Shape s)
           
 void clipRect(int x, int y, int width, int height)
           
 void copyArea(int x, int y, int width, int height, int dx, int dy)
           
 Graphics create()
           
 void dispose()
           
 void draw(Shape shp)
           
 void draw3DRect(int x, int y, int width, int height, boolean raised)
           
 void drawArc(int xpos, int ypos, int width, int height, int start, int extend)
           
 void drawBytes(byte[] data, int offset, int length, int x, int y)
           
 void drawChars(char[] data, int offset, int length, int x, int y)
           
 void drawGlyphVector(GlyphVector g, float x, float y)
           
 void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
           
 boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)
           
 boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
           
 boolean drawImage(Image img, int x, int y, ImageObserver obs)
           
 boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
           
 boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver obs)
           
 boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
           
 boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
           
 void drawLine(int x1, int y1, int x2, int y2)
           
 void drawOval(int x, int y, int width, int height)
           
 void drawPolygon(int[] x, int[] y, int n)
           
 void drawPolygon(Polygon p)
           
 void drawPolyline(int[] x, int[] y, int n)
           
 void drawRect(int x, int y, int width, int height)
           
 void drawRenderableImage(RenderableImage img, AffineTransform xform)
           
 void drawRenderedImage(RenderedImage img, AffineTransform xform)
           
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
           
 void drawString(AttributedCharacterIterator iterator, float x, float y)
           
 void drawString(AttributedCharacterIterator iterator, int x, int y)
           
 void drawString(String str, float x, float y)
           
 void drawString(String str, int x, int y)
           
 void fill(Shape shp)
           
 void fillArc(int xpos, int ypos, int width, int height, int start, int extend)
           
 void fillOval(int x, int y, int width, int height)
           
 void fillPolygon(int[] x, int[] y, int n)
           
 void fillRect(int x, int y, int width, int height)
           
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
           
 Color getBackground()
           
 Shape getClip()
           
 Rectangle getClipBounds()
           
 Color getColor()
           
 Composite getComposite()
           
 GraphicsConfiguration getDeviceConfiguration()
           
 Font getFont()
           
 FontMetrics getFontMetrics(Font f)
           
 FontRenderContext getFontRenderContext()
           
 Paint getPaint()
           
 Object getRenderingHint(RenderingHints.Key hintKey)
           
 RenderingHints getRenderingHints()
           
 Stroke getStroke()
           
 AffineTransform getTransform()
           
 Color getXORColor()
           
 boolean hit(Rectangle rect, Shape s, boolean onStroke)
           
 boolean paintMode()
           
 void rotate(double theta)
           
 void rotate(double theta, double x, double y)
           
 void rotateGrade(double theta)
          just the same as the rotate(double) method, except that the parameter is treated as degree value (0..360)
 void rotateGrade(double theta, double x, double y)
          just the same as the rotate(double, double, double) method, except that the angle parameter is treated as a degree value (0..360)
 void scale(double sx, double sy)
           
 void setBackground(Color bgcolor)
           
 void setClip(int x, int y, int width, int height)
           
 void setClip(Shape clip)
           
 void setColor(Color c)
          If no other operation has been performed since the last call to setColor(), the last color object will be replaced by that one given now.
 void setComposite(Composite comp)
           
 void setFamilyFont(Font f)
          sets the current font to f.
 void setFont(Font f)
           
 void setPaint(Paint paint)
           
 void setPaintMode()
           
 void setPSFont(Font f)
          sets the current font to f.
 void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
           
 void setRenderingHints(Map<?,?> hints)
           
 void setStroke(Stroke s)
           
 void setTransform(AffineTransform tx)
           
 void setXORMode(Color cl)
           
 void shear(double shx, double shy)
           
 String toEPS()
          Creates the eps code representing the current graphics.
 String toEPS(Rectangle boundingBox)
          Creates the eps code representing the current graphics.
 String toEPS(Rectangle boundingBox, Writer w)
          Creates the eps code representing the current graphics.
 String toEps(String title, Rectangle boundingBox)
          Creates the eps code representing the current graphics.
 String toEps(String title, Rectangle boundingBox, Writer w)
          Creates the eps code representing the current graphics.
 String toEPS(String title, String filename, Rectangle boundingBox)
          Creates the eps code representing the current graphics and using the given parameters
 String toEPS(String title, String filename, Rectangle boundingBox, Writer w)
          Constructs a string representing the current graphics as encapsulated postscript data.
 String toEPS(Writer w)
          Creates the eps code representing the current graphics.
 String toPS()
          Constructs PS string that represents the current graphics as postscript data.
 String toPS(Writer w)
          Constructs PS string that represents the current graphics as postscript data.
 void transform(AffineTransform tx)
           
 void translate(double x, double y)
           
 void translate(int x, int y)
           
 
Methods inherited from class java.awt.Graphics2D
fill3DRect
 
Methods inherited from class java.awt.Graphics
create, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EpsGraphics2D

public EpsGraphics2D()
Method Detail

draw3DRect

public void draw3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised)
Overrides:
draw3DRect in class Graphics2D

drawBytes

public void drawBytes(byte[] data,
                      int offset,
                      int length,
                      int x,
                      int y)
Overrides:
drawBytes in class Graphics

drawChars

public void drawChars(char[] data,
                      int offset,
                      int length,
                      int x,
                      int y)
Overrides:
drawChars in class Graphics

drawPolygon

public void drawPolygon(Polygon p)
Overrides:
drawPolygon in class Graphics

draw

public void draw(Shape shp)
Specified by:
draw in class Graphics2D

drawImage

public boolean drawImage(Image img,
                         AffineTransform xform,
                         ImageObserver obs)
Specified by:
drawImage in class Graphics2D

drawImage

public void drawImage(BufferedImage img,
                      BufferedImageOp op,
                      int x,
                      int y)
Specified by:
drawImage in class Graphics2D

drawRenderedImage

public void drawRenderedImage(RenderedImage img,
                              AffineTransform xform)
Specified by:
drawRenderedImage in class Graphics2D

drawRenderableImage

public void drawRenderableImage(RenderableImage img,
                                AffineTransform xform)
Specified by:
drawRenderableImage in class Graphics2D

drawString

public void drawString(String str,
                       int x,
                       int y)
Specified by:
drawString in class Graphics2D

drawString

public void drawString(String str,
                       float x,
                       float y)
Specified by:
drawString in class Graphics2D

drawString

public void drawString(AttributedCharacterIterator iterator,
                       int x,
                       int y)
Specified by:
drawString in class Graphics2D

drawString

public void drawString(AttributedCharacterIterator iterator,
                       float x,
                       float y)
Specified by:
drawString in class Graphics2D

drawGlyphVector

public void drawGlyphVector(GlyphVector g,
                            float x,
                            float y)
Specified by:
drawGlyphVector in class Graphics2D

fill

public void fill(Shape shp)
Specified by:
fill in class Graphics2D

hit

public boolean hit(Rectangle rect,
                   Shape s,
                   boolean onStroke)
Specified by:
hit in class Graphics2D

getDeviceConfiguration

public GraphicsConfiguration getDeviceConfiguration()
Specified by:
getDeviceConfiguration in class Graphics2D

setComposite

public void setComposite(Composite comp)
Specified by:
setComposite in class Graphics2D

setPaint

public void setPaint(Paint paint)
Specified by:
setPaint in class Graphics2D

setStroke

public void setStroke(Stroke s)
Specified by:
setStroke in class Graphics2D

setRenderingHints

public void setRenderingHints(Map<?,?> hints)
Specified by:
setRenderingHints in class Graphics2D

addRenderingHints

public void addRenderingHints(Map<?,?> hints)
Specified by:
addRenderingHints in class Graphics2D

getRenderingHints

public RenderingHints getRenderingHints()
Specified by:
getRenderingHints in class Graphics2D

translate

public void translate(int x,
                      int y)
Specified by:
translate in class Graphics2D

translate

public void translate(double x,
                      double y)
Specified by:
translate in class Graphics2D

rotate

public void rotate(double theta)
Specified by:
rotate in class Graphics2D

rotateGrade

public void rotateGrade(double theta)
just the same as the rotate(double) method, except that the parameter is treated as degree value (0..360)

Parameters:
theta - angle in degree
See Also:
rotate(double)

rotate

public void rotate(double theta,
                   double x,
                   double y)
Specified by:
rotate in class Graphics2D

rotateGrade

public void rotateGrade(double theta,
                        double x,
                        double y)
just the same as the rotate(double, double, double) method, except that the angle parameter is treated as a degree value (0..360)

Parameters:
theta - angle in degree
x - the x position
y - the y position
See Also:
rotate(double, double, double)

scale

public void scale(double sx,
                  double sy)
Specified by:
scale in class Graphics2D

shear

public void shear(double shx,
                  double shy)
Specified by:
shear in class Graphics2D

transform

public void transform(AffineTransform tx)
Specified by:
transform in class Graphics2D

setTransform

public void setTransform(AffineTransform tx)
Specified by:
setTransform in class Graphics2D

getTransform

public AffineTransform getTransform()
Specified by:
getTransform in class Graphics2D

getPaint

public Paint getPaint()
Specified by:
getPaint in class Graphics2D

getComposite

public Composite getComposite()
Specified by:
getComposite in class Graphics2D

setBackground

public void setBackground(Color bgcolor)
Specified by:
setBackground in class Graphics2D

getBackground

public Color getBackground()
Specified by:
getBackground in class Graphics2D

getStroke

public Stroke getStroke()
Specified by:
getStroke in class Graphics2D

clip

public void clip(Shape s)
Specified by:
clip in class Graphics2D

getFontRenderContext

public FontRenderContext getFontRenderContext()
Specified by:
getFontRenderContext in class Graphics2D

create

public Graphics create()
Specified by:
create in class Graphics

getColor

public Color getColor()
Specified by:
getColor in class Graphics

setColor

public void setColor(Color c)
If no other operation has been performed since the last call to setColor(), the last color object will be replaced by that one given now.

Specified by:
setColor in class Graphics

setPaintMode

public void setPaintMode()
Specified by:
setPaintMode in class Graphics

setXORMode

public void setXORMode(Color cl)
Specified by:
setXORMode in class Graphics

getFont

public Font getFont()
Specified by:
getFont in class Graphics

setFont

public void setFont(Font f)
Specified by:
setFont in class Graphics

setPSFont

public void setPSFont(Font f)
sets the current font to f. In postscript output the PS Name (from Font.getPSName()) will be used in the findfont command.

Parameters:
f - the new font

setFamilyFont

public void setFamilyFont(Font f)
sets the current font to f. In postscript output the Font Family Name (from Font.getFamily()) will be used in the findfont command.

Parameters:
f - the new font

getFontMetrics

public FontMetrics getFontMetrics(Font f)
Specified by:
getFontMetrics in class Graphics

getClipBounds

public Rectangle getClipBounds()
Specified by:
getClipBounds in class Graphics

clipRect

public void clipRect(int x,
                     int y,
                     int width,
                     int height)
Specified by:
clipRect in class Graphics

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)
Specified by:
setClip in class Graphics

getClip

public Shape getClip()
Specified by:
getClip in class Graphics

setClip

public void setClip(Shape clip)
Specified by:
setClip in class Graphics

copyArea

public void copyArea(int x,
                     int y,
                     int width,
                     int height,
                     int dx,
                     int dy)
Specified by:
copyArea in class Graphics

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Specified by:
drawLine in class Graphics

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Specified by:
fillRect in class Graphics

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Specified by:
clearRect in class Graphics

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Specified by:
drawRoundRect in class Graphics

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Specified by:
fillRoundRect in class Graphics

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Specified by:
drawOval in class Graphics

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Specified by:
fillOval in class Graphics

drawArc

public void drawArc(int xpos,
                    int ypos,
                    int width,
                    int height,
                    int start,
                    int extend)
Specified by:
drawArc in class Graphics

fillArc

public void fillArc(int xpos,
                    int ypos,
                    int width,
                    int height,
                    int start,
                    int extend)
Specified by:
fillArc in class Graphics

drawPolyline

public void drawPolyline(int[] x,
                         int[] y,
                         int n)
Specified by:
drawPolyline in class Graphics

drawPolygon

public void drawPolygon(int[] x,
                        int[] y,
                        int n)
Specified by:
drawPolygon in class Graphics

fillPolygon

public void fillPolygon(int[] x,
                        int[] y,
                        int n)
Specified by:
fillPolygon in class Graphics

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         ImageObserver obs)
Specified by:
drawImage in class Graphics

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         ImageObserver obs)
Specified by:
drawImage in class Graphics

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         Color bgcolor,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         Color bgcolor,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics

drawImage

public boolean drawImage(Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics

drawImage

public boolean drawImage(Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         Color bgcolor,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics

dispose

public void dispose()
Specified by:
dispose in class Graphics

setRenderingHint

public void setRenderingHint(RenderingHints.Key hintKey,
                             Object hintValue)
Specified by:
setRenderingHint in class Graphics2D

getRenderingHint

public Object getRenderingHint(RenderingHints.Key hintKey)
Specified by:
getRenderingHint in class Graphics2D

addComment

public void addComment(String comment)
Adds an eps comment. It can be used for documentation purposes.

Parameters:
comment - The comment text. The comment indicator '%' is automatically added in every new line. You do not have to include it in the String parameter!

toPS

public String toPS()
            throws IOException
Constructs PS string that represents the current graphics as postscript data. The postscript commands are in the same order as the corresponding methods have been called.

Returns:
postscript code representing the graphics.
Throws:
IOException

toPS

public String toPS(Writer w)
            throws IOException
Constructs PS string that represents the current graphics as postscript data. The postscript commands are in the same order as the corresponding methods have been called.

Parameters:
w - the writer that the code should be printed to
Returns:
postscript code representing the graphics.
Throws:
IOException

toEPS

public String toEPS(String title,
                    String filename,
                    Rectangle boundingBox,
                    Writer w)
             throws IOException
Constructs a string representing the current graphics as encapsulated postscript data. Technically, the eps header is added before the postscript data returned by toEPS().

Parameters:
title - the Document title. If null an empty title is added
filename - the name of the file the code is going to be written to. If null no filename comment will be added
boundingBox - the bounding box information. If null, a DIN A4 page (612x792 mm) is assumed as bounding box.
Returns:
the eps representation of the current graphics
Throws:
IOException

toEPS

public String toEPS(String title,
                    String filename,
                    Rectangle boundingBox)
             throws IOException
Creates the eps code representing the current graphics and using the given parameters

Parameters:
title - graphics title
filename - the filename
boundingBox - the bounding box
Returns:
the code
Throws:
IOException

toEPS

public String toEPS(Writer w)
             throws IOException
Creates the eps code representing the current graphics. As BoundingBox a DIN A4 page is assumed

Parameters:
w - the output stream that the code should be printed to
Returns:
parts of the code but not all
Throws:
IOException

toEPS

public String toEPS()
             throws IOException
Creates the eps code representing the current graphics. As BoundingBox a DIN A4 page is assumed

Returns:
eps representation
Throws:
IOException
See Also:
toEPS(String title, String filename, Rectangle boundingBox)

toEPS

public String toEPS(Rectangle boundingBox)
             throws IOException
Creates the eps code representing the current graphics.

Parameters:
boundingBox - The bounding box of the graphics
Returns:
eps code
Throws:
IOException
See Also:
toEPS(String title, String filename, Rectangle boundingBox)

toEPS

public String toEPS(Rectangle boundingBox,
                    Writer w)
             throws IOException
Creates the eps code representing the current graphics.

Parameters:
boundingBox - The bounding box of the graphics
w - the outputstream that the code should be printed to
Returns:
eps code
Throws:
IOException
See Also:
toEPS(String title, String filename, Rectangle boundingBox)

toEps

public String toEps(String title,
                    Rectangle boundingBox)
             throws IOException
Creates the eps code representing the current graphics.

Parameters:
title - The title of the graphic
boundingBox - The bounding box
Returns:
eps code
Throws:
IOException
See Also:
toEPS(String title, String filename, Rectangle boundingBox)

toEps

public String toEps(String title,
                    Rectangle boundingBox,
                    Writer w)
             throws IOException
Creates the eps code representing the current graphics.

Parameters:
title - The title of the graphic
boundingBox - The bounding box
w - The outputstream the code should be printed to
Returns:
parts of the eps code
Throws:
IOException
See Also:
toEPS(String title, String filename, Rectangle boundingBox)

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
Overrides:
drawRect in class Graphics
See Also:
Graphics.drawRect(int, int, int, int)

getXORColor

public Color getXORColor()
Returns:
xor color

paintMode

public boolean paintMode()
Returns:
paint mode: true for standard paint mode false for xor mode.