Package adams.gui.print
Class PostscriptGraphics
- java.lang.Object
-
- java.awt.Graphics
-
- java.awt.Graphics2D
-
- adams.gui.print.PostscriptGraphics
-
public class PostscriptGraphics extends Graphics2D
The PostscriptGraphics class extends the Graphics2D class to produce an encapsulated postscript file rather than on-screen display.Currently only a small (but useful) subset of Graphics methods have been implemented. To handle the ability to Clone a Graphics object, the graphics state of the eps is set from the graphics state of the local PostscriptGraphics before output. To use, create a PostscriptGraphics object, and pass it to the PaintComponent method of a JComponent.
If necessary additional font replacements can be inserted, since some fonts might be displayed incorrectly.
Based on weka.gui.visualize.PostscriptGraphics- Author:
- Dale Fletcher ([email protected]), FracPete (fracpete at waikato dot ac dot nz)
- See Also:
addPSFontReplacement(String, String),m_PSFontReplacement
-
-
Field Summary
Fields Modifier and Type Field Description protected static booleanDEBUGwhether to print some debug informationprotected Rectanglem_extentThe bounding box of the outputprotected adams.gui.print.PostscriptGraphics.GraphicsStatem_localGraphicsStateThe current local graphics state for this PostscriptGraphics objectprotected PrintStreamm_printstreamThe output fileprotected static Hashtable<String,String>m_PSFontReplacementthe font replacementprotected adams.gui.print.PostscriptGraphics.GraphicsStatem_psGraphicsStateThe current global PostScript graphics state for all cloned objects
-
Constructor Summary
Constructors Constructor Description PostscriptGraphics(int width, int height, OutputStream os)Constructor Creates a new PostscriptGraphics object, given dimensions and output file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddPSFontReplacement(String replace, String with)adds the PS font name to replace and its replacement in the replacement hashtablevoidaddRenderingHints(Map m)voidclearRect(int x, int y, int width, int height)Draw a filled rectangle with the background color.voidclip(Shape s)voidclipRect(int x, int y, int width, int height)Not implementedvoidcopyArea(int x, int y, int width, int height, int dx, int dy)Not implementedGraphicscreate()Clone a PostscriptGraphics objectvoiddispose()Not implementedvoiddraw(Shape s)voiddraw3DRect(int x, int y, int width, int height, boolean raised)Draw an outlined rectangle with 3D effect in current pen color.voiddrawArc(int x, int y, int width, int height, int startAngle, int arcAngle)Not implementedvoiddrawBytes(byte[] data, int offset, int length, int x, int y)simply calls drawString(String,int,int)voiddrawChars(char[] data, int offset, int length, int x, int y)simply calls drawString(String,int,int)voiddrawGlyphVector(GlyphVector gv, float f1, float f2)voiddrawImage(BufferedImage bi, BufferedImageOp bio, int i1, int i2)booleandrawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)Not implementedbooleandrawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)calls drawImage(Image,int,int,int,int,int,int,int,int,Color,ImageObserver) with Color.WHITE as background colorbooleandrawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)PS see http://astronomy.swin.edu.au/~pbourke/geomformats/postscript/ Java http://show.docjava.com:8086/book/cgij/doc/ip/graphics/SimpleImageFrame.java.htmlbooleandrawImage(Image img, int x, int y, int width, int height, ImageObserver observer)calls drawImage(Image,int,int,int,int,Color,ImageObserver) with the color WHITE as backgroundbooleandrawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)calls drawImage(Image,int,int,int,int,Color,ImageObserver)booleandrawImage(Image img, int x, int y, ImageObserver observer)calls drawImage(Image,int,int,Color,ImageObserver) with Color.WHITE as background colorbooleandrawImage(Image im, AffineTransform at, ImageObserver io)voiddrawLine(int x1, int y1, int x2, int y2)Draw a line in current pen color.voiddrawOval(int x, int y, int width, int height)Draw an Oval outline in current pen color.voiddrawPolygon(int[] xPoints, int[] yPoints, int nPoints)Not implementedvoiddrawPolyline(int[] xPoints, int[] yPoints, int nPoints)Not implementedvoiddrawRect(int x, int y, int width, int height)Draw an outlined rectangle in current pen color.voiddrawRenderableImage(RenderableImage ri, AffineTransform at)voiddrawRenderedImage(RenderedImage ri, AffineTransform af)voiddrawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)Not implementedvoiddrawString(String str, float x, float y)voiddrawString(String str, int x, int y)Draw text in current pen color.voiddrawString(AttributedCharacterIterator aci, float f1, float f2)voiddrawString(AttributedCharacterIterator iterator, int x, int y)Not implementedprotected Stringescape(String s)Escapes brackets in the string with backslashes.voidfill(Shape s)voidfill3DRect(int x, int y, int width, int height, boolean raised)Draw a filled rectangle with 3D effect in current pen color.voidfillArc(int x, int y, int width, int height, int startAngle, int arcAngle)Not implementedvoidfillOval(int x, int y, int width, int height)Draw a filled Oval in current pen color.voidfillPolygon(int[] xPoints, int[] yPoints, int nPoints)Not implementedvoidfillPolygon(Polygon p)Not implementedvoidfillRect(int x, int y, int width, int height)Draw a filled rectangle in current pen color.voidfillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)Not implementedvoidfinalize()Not implementedvoidfinished()Finalizes output file.ColorgetBackground()ShapegetClip()Not implementedRectanglegetClipBounds()This returns the full current drawing areaRectanglegetClipBounds(Rectangle r)This returns the full current drawing areaRectanglegetClipRect()Not implementedColorgetColor()Get current pen color.CompositegetComposite()GraphicsConfigurationgetDeviceConfiguration()FontgetFont()Get current font.FontMetricsgetFontMetrics(Font f)Get Font metricsFontRenderContextgetFontRenderContext()START overridden Graphics2D methodsPaintgetPaint()ObjectgetRenderingHint(RenderingHints.Key key)RenderingHintsgetRenderingHints()StrokegetStroke()AffineTransformgetTransform()booleanhit(Rectangle r, Shape s, boolean onstroke)voidrotate(double d1)voidrotate(double d1, double d2, double d3)voidscale(double d1, double d2)voidsetBackground(Color c)voidsetClip(int x, int y, int width, int height)Not implementedvoidsetClip(Shape clip)Not implementedvoidsetColor(Color c)Set current pen color.voidsetComposite(Composite c)voidsetFont(Font font)Set current font.voidsetPaint(Paint p)voidsetPaintMode()Not implementedvoidsetRenderingHint(RenderingHints.Key key, Object o)voidsetRenderingHints(Map m)voidsetStroke(Stroke s)voidsetTransform(AffineTransform at)voidsetXORMode(Color c1)Not implementedvoidshear(double d1, double d2)voidtransform(AffineTransform at)voidtranslate(double d1, double d2)voidtranslate(int x, int y)Translates the origin of the graphics context to the point (x, y) in the current coordinate system.-
Methods inherited from class java.awt.Graphics
create, drawPolygon, getFontMetrics, hitClip, toString
-
-
-
-
Field Detail
-
m_extent
protected Rectangle m_extent
The bounding box of the output
-
m_printstream
protected PrintStream m_printstream
The output file
-
m_psGraphicsState
protected adams.gui.print.PostscriptGraphics.GraphicsState m_psGraphicsState
The current global PostScript graphics state for all cloned objects
-
m_localGraphicsState
protected adams.gui.print.PostscriptGraphics.GraphicsState m_localGraphicsState
The current local graphics state for this PostscriptGraphics object
-
DEBUG
protected static final boolean DEBUG
whether to print some debug information- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PostscriptGraphics
public PostscriptGraphics(int width, int height, OutputStream os)Constructor Creates a new PostscriptGraphics object, given dimensions and output file.- Parameters:
width- The width of eps in points.height- The height of eps in points.os- File to send postscript to.
-
-
Method Detail
-
finished
public void finished()
Finalizes output file.
-
addPSFontReplacement
public static void addPSFontReplacement(String replace, String with)
adds the PS font name to replace and its replacement in the replacement hashtable- Parameters:
replace- the PS font name to replacewith- the PS font name to replace the font with
-
clearRect
public void clearRect(int x, int y, int width, int height)Draw a filled rectangle with the background color.
-
clipRect
public void clipRect(int x, int y, int width, int height)Not implemented
-
copyArea
public void copyArea(int x, int y, int width, int height, int dx, int dy)Not implemented
-
create
public Graphics create()
Clone a PostscriptGraphics object
-
draw3DRect
public void draw3DRect(int x, int y, int width, int height, boolean raised)Draw an outlined rectangle with 3D effect in current pen color. (Current implementation: draw simple outlined rectangle)- Overrides:
draw3DRectin classGraphics2D- Parameters:
x- starting x coordy- starting y coordwidth- rectangle widthheight- rectangle heightraised- True: appear raised, False: appear etched
-
drawArc
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)Not implemented
-
drawBytes
public void drawBytes(byte[] data, int offset, int length, int x, int y)simply calls drawString(String,int,int)- Overrides:
drawBytesin classGraphics- See Also:
drawString(String,int,int)
-
drawChars
public void drawChars(char[] data, int offset, int length, int x, int y)simply calls drawString(String,int,int)- Overrides:
drawCharsin classGraphics- See Also:
drawString(String,int,int)
-
drawImage
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
calls drawImage(Image,int,int,int,int,Color,ImageObserver)- Specified by:
drawImagein classGraphics- See Also:
drawImage(Image,int,int,int,int,Color,ImageObserver)
-
drawImage
public boolean drawImage(Image img, int x, int y, ImageObserver observer)
calls drawImage(Image,int,int,Color,ImageObserver) with Color.WHITE as background color- Specified by:
drawImagein classGraphics- See Also:
drawImage(Image,int,int,Color,ImageObserver),Color.WHITE
-
drawImage
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
PS see http://astronomy.swin.edu.au/~pbourke/geomformats/postscript/ Java http://show.docjava.com:8086/book/cgij/doc/ip/graphics/SimpleImageFrame.java.html
-
drawImage
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
calls drawImage(Image,int,int,int,int,Color,ImageObserver) with the color WHITE as background- Specified by:
drawImagein classGraphics- See Also:
drawImage(Image,int,int,int,int,Color,ImageObserver),Color.WHITE
-
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)
Not implemented
-
drawImage
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
calls drawImage(Image,int,int,int,int,int,int,int,int,Color,ImageObserver) with Color.WHITE as background color- Specified by:
drawImagein classGraphics- See Also:
drawImage(Image,int,int,int,int,int,int,int,int,Color,ImageObserver)
-
drawLine
public void drawLine(int x1, int y1, int x2, int y2)Draw a line in current pen color.
-
drawOval
public void drawOval(int x, int y, int width, int height)Draw an Oval outline in current pen color.
-
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)Not implemented- Specified by:
drawPolygonin classGraphics
-
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)Not implemented- Specified by:
drawPolylinein classGraphics
-
drawRect
public void drawRect(int x, int y, int width, int height)Draw an outlined rectangle in current pen color.
-
drawRoundRect
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)Not implemented- Specified by:
drawRoundRectin classGraphics
-
drawString
public void drawString(AttributedCharacterIterator iterator, int x, int y)
Not implemented- Specified by:
drawStringin classGraphics2D
-
escape
protected String escape(String s)
Escapes brackets in the string with backslashes.- Parameters:
s- the string to escape- Returns:
- the escaped string
-
drawString
public void drawString(String str, int x, int y)
Draw text in current pen color.- Specified by:
drawStringin classGraphics2D- Parameters:
str- Text to outputx- starting x coordy- starting y coord
-
fill3DRect
public void fill3DRect(int x, int y, int width, int height, boolean raised)Draw a filled rectangle with 3D effect in current pen color. (Current implementation: draw simple filled rectangle)- Overrides:
fill3DRectin classGraphics2D- Parameters:
x- starting x coordy- starting y coordwidth- rectangle widthheight- rectangle heightraised- True: appear raised, False: appear etched
-
fillArc
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)Not implemented
-
fillOval
public void fillOval(int x, int y, int width, int height)Draw a filled Oval in current pen color.
-
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)Not implemented- Specified by:
fillPolygonin classGraphics
-
fillPolygon
public void fillPolygon(Polygon p)
Not implemented- Overrides:
fillPolygonin classGraphics
-
fillRect
public void fillRect(int x, int y, int width, int height)Draw a filled rectangle in current pen color.
-
fillRoundRect
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)Not implemented- Specified by:
fillRoundRectin classGraphics
-
getClipBounds
public Rectangle getClipBounds()
This returns the full current drawing area- Specified by:
getClipBoundsin classGraphics- Returns:
- full drawing area
-
getClipBounds
public Rectangle getClipBounds(Rectangle r)
This returns the full current drawing area- Overrides:
getClipBoundsin classGraphics- Returns:
- full drawing area
-
getClipRect
public Rectangle getClipRect()
Not implemented- Overrides:
getClipRectin classGraphics
-
getColor
public Color getColor()
Get current pen color.
-
getFont
public Font getFont()
Get current font.
-
getFontMetrics
public FontMetrics getFontMetrics(Font f)
Get Font metrics- Specified by:
getFontMetricsin classGraphics- Parameters:
f- Font- Returns:
- Font metrics.
-
setClip
public void setClip(int x, int y, int width, int height)Not implemented
-
setColor
public void setColor(Color c)
Set current pen color. Default to black if null.
-
setFont
public void setFont(Font font)
Set current font. Default to Plain Courier 11 if null.
-
setPaintMode
public void setPaintMode()
Not implemented- Specified by:
setPaintModein classGraphics
-
setXORMode
public void setXORMode(Color c1)
Not implemented- Specified by:
setXORModein classGraphics
-
translate
public void translate(int x, int y)Translates the origin of the graphics context to the point (x, y) in the current coordinate system. Modifies this graphics context so that its new origin corresponds to the point (x, y) in this graphics context's original coordinate system. All coordinates used in subsequent rendering operations on this graphics context will be relative to this new origin.- Specified by:
translatein classGraphics2D- Parameters:
x- the x coordinate.y- the y coordinate.
-
getFontRenderContext
public FontRenderContext getFontRenderContext()
START overridden Graphics2D methods- Specified by:
getFontRenderContextin classGraphics2D
-
clip
public void clip(Shape s)
- Specified by:
clipin classGraphics2D
-
getStroke
public Stroke getStroke()
- Specified by:
getStrokein classGraphics2D
-
getBackground
public Color getBackground()
- Specified by:
getBackgroundin classGraphics2D
-
setBackground
public void setBackground(Color c)
- Specified by:
setBackgroundin classGraphics2D
-
getComposite
public Composite getComposite()
- Specified by:
getCompositein classGraphics2D
-
getPaint
public Paint getPaint()
- Specified by:
getPaintin classGraphics2D
-
getTransform
public AffineTransform getTransform()
- Specified by:
getTransformin classGraphics2D
-
setTransform
public void setTransform(AffineTransform at)
- Specified by:
setTransformin classGraphics2D
-
transform
public void transform(AffineTransform at)
- Specified by:
transformin classGraphics2D
-
shear
public void shear(double d1, double d2)- Specified by:
shearin classGraphics2D
-
scale
public void scale(double d1, double d2)- Specified by:
scalein classGraphics2D
-
rotate
public void rotate(double d1, double d2, double d3)- Specified by:
rotatein classGraphics2D
-
rotate
public void rotate(double d1)
- Specified by:
rotatein classGraphics2D
-
translate
public void translate(double d1, double d2)- Specified by:
translatein classGraphics2D
-
getRenderingHints
public RenderingHints getRenderingHints()
- Specified by:
getRenderingHintsin classGraphics2D
-
addRenderingHints
public void addRenderingHints(Map m)
- Specified by:
addRenderingHintsin classGraphics2D
-
setRenderingHints
public void setRenderingHints(Map m)
- Specified by:
setRenderingHintsin classGraphics2D
-
getRenderingHint
public Object getRenderingHint(RenderingHints.Key key)
- Specified by:
getRenderingHintin classGraphics2D
-
setRenderingHint
public void setRenderingHint(RenderingHints.Key key, Object o)
- Specified by:
setRenderingHintin classGraphics2D
-
setStroke
public void setStroke(Stroke s)
- Specified by:
setStrokein classGraphics2D
-
setPaint
public void setPaint(Paint p)
- Specified by:
setPaintin classGraphics2D
-
setComposite
public void setComposite(Composite c)
- Specified by:
setCompositein classGraphics2D
-
getDeviceConfiguration
public GraphicsConfiguration getDeviceConfiguration()
- Specified by:
getDeviceConfigurationin classGraphics2D
-
hit
public boolean hit(Rectangle r, Shape s, boolean onstroke)
- Specified by:
hitin classGraphics2D
-
fill
public void fill(Shape s)
- Specified by:
fillin classGraphics2D
-
drawGlyphVector
public void drawGlyphVector(GlyphVector gv, float f1, float f2)
- Specified by:
drawGlyphVectorin classGraphics2D
-
drawString
public void drawString(AttributedCharacterIterator aci, float f1, float f2)
- Specified by:
drawStringin classGraphics2D
-
drawString
public void drawString(String str, float x, float y)
- Specified by:
drawStringin classGraphics2D
-
drawRenderableImage
public void drawRenderableImage(RenderableImage ri, AffineTransform at)
- Specified by:
drawRenderableImagein classGraphics2D
-
drawRenderedImage
public void drawRenderedImage(RenderedImage ri, AffineTransform af)
- Specified by:
drawRenderedImagein classGraphics2D
-
drawImage
public void drawImage(BufferedImage bi, BufferedImageOp bio, int i1, int i2)
- Specified by:
drawImagein classGraphics2D
-
drawImage
public boolean drawImage(Image im, AffineTransform at, ImageObserver io)
- Specified by:
drawImagein classGraphics2D
-
draw
public void draw(Shape s)
- Specified by:
drawin classGraphics2D
-
-