Class 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 (dale@cs.waikato.ac.nz), FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    addPSFontReplacement(String, String), m_PSFontReplacement
    • 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
      • m_PSFontReplacement

        protected static Hashtable<String,​String> m_PSFontReplacement
        the font replacement
    • 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 replace
        with - 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.
        Specified by:
        clearRect in class Graphics
        Parameters:
        x - starting x coord
        y - starting y coord
        width - rectangle width
        height - rectangle height
      • clipRect

        public void clipRect​(int x,
                             int y,
                             int width,
                             int height)
        Not implemented
        Specified by:
        clipRect in class Graphics
      • copyArea

        public void copyArea​(int x,
                             int y,
                             int width,
                             int height,
                             int dx,
                             int dy)
        Not implemented
        Specified by:
        copyArea in class Graphics
      • create

        public Graphics create()
        Clone a PostscriptGraphics object
        Specified by:
        create in class Graphics
      • dispose

        public void dispose()
        Not implemented
        Specified by:
        dispose in class Graphics
      • 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:
        draw3DRect in class Graphics2D
        Parameters:
        x - starting x coord
        y - starting y coord
        width - rectangle width
        height - rectangle height
        raised - True: appear raised, False: appear etched
      • drawArc

        public void drawArc​(int x,
                            int y,
                            int width,
                            int height,
                            int startAngle,
                            int arcAngle)
        Not implemented
        Specified by:
        drawArc in class Graphics
      • 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
        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)
        Not implemented
        Specified by:
        drawImage in class Graphics
      • drawLine

        public void drawLine​(int x1,
                             int y1,
                             int x2,
                             int y2)
        Draw a line in current pen color.
        Specified by:
        drawLine in class Graphics
        Parameters:
        x1 - starting x coord
        y1 - starting y coord
        x2 - ending x coord
        y2 - ending y coord
      • drawOval

        public void drawOval​(int x,
                             int y,
                             int width,
                             int height)
        Draw an Oval outline in current pen color.
        Specified by:
        drawOval in class Graphics
        Parameters:
        x - x-axis center of oval
        y - y-axis center of oval
        width - oval width
        height - oval height
      • drawPolygon

        public void drawPolygon​(int[] xPoints,
                                int[] yPoints,
                                int nPoints)
        Not implemented
        Specified by:
        drawPolygon in class Graphics
      • drawPolyline

        public void drawPolyline​(int[] xPoints,
                                 int[] yPoints,
                                 int nPoints)
        Not implemented
        Specified by:
        drawPolyline in class Graphics
      • drawRect

        public void drawRect​(int x,
                             int y,
                             int width,
                             int height)
        Draw an outlined rectangle in current pen color.
        Overrides:
        drawRect in class Graphics
        Parameters:
        x - starting x coord
        y - starting y coord
        width - rectangle width
        height - rectangle height
      • drawRoundRect

        public void drawRoundRect​(int x,
                                  int y,
                                  int width,
                                  int height,
                                  int arcWidth,
                                  int arcHeight)
        Not implemented
        Specified by:
        drawRoundRect in class Graphics
      • 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:
        drawString in class Graphics2D
        Parameters:
        str - Text to output
        x - starting x coord
        y - 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:
        fill3DRect in class Graphics2D
        Parameters:
        x - starting x coord
        y - starting y coord
        width - rectangle width
        height - rectangle height
        raised - True: appear raised, False: appear etched
      • fillArc

        public void fillArc​(int x,
                            int y,
                            int width,
                            int height,
                            int startAngle,
                            int arcAngle)
        Not implemented
        Specified by:
        fillArc in class Graphics
      • fillOval

        public void fillOval​(int x,
                             int y,
                             int width,
                             int height)
        Draw a filled Oval in current pen color.
        Specified by:
        fillOval in class Graphics
        Parameters:
        x - x-axis center of oval
        y - y-axis center of oval
        width - oval width
        height - oval height
      • fillPolygon

        public void fillPolygon​(int[] xPoints,
                                int[] yPoints,
                                int nPoints)
        Not implemented
        Specified by:
        fillPolygon in class Graphics
      • fillRect

        public void fillRect​(int x,
                             int y,
                             int width,
                             int height)
        Draw a filled rectangle in current pen color.
        Specified by:
        fillRect in class Graphics
        Parameters:
        x - starting x coord
        y - starting y coord
        width - rectangle width
        height - rectangle height
      • fillRoundRect

        public void fillRoundRect​(int x,
                                  int y,
                                  int width,
                                  int height,
                                  int arcWidth,
                                  int arcHeight)
        Not implemented
        Specified by:
        fillRoundRect in class Graphics
      • finalize

        public void finalize()
        Not implemented
        Overrides:
        finalize in class Graphics
      • getClipBounds

        public Rectangle getClipBounds()
        This returns the full current drawing area
        Specified by:
        getClipBounds in class Graphics
        Returns:
        full drawing area
      • getColor

        public Color getColor()
        Get current pen color.
        Specified by:
        getColor in class Graphics
        Returns:
        current pen color.
      • getFont

        public Font getFont()
        Get current font.
        Specified by:
        getFont in class Graphics
        Returns:
        current font.
      • setClip

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

        public void setClip​(Shape clip)
        Not implemented
        Specified by:
        setClip in class Graphics
      • setColor

        public void setColor​(Color c)
        Set current pen color. Default to black if null.
        Specified by:
        setColor in class Graphics
        Parameters:
        c - new pen color.
      • setFont

        public void setFont​(Font font)
        Set current font. Default to Plain Courier 11 if null.
        Specified by:
        setFont in class Graphics
        Parameters:
        font - new font.
      • setPaintMode

        public void setPaintMode()
        Not implemented
        Specified by:
        setPaintMode in class Graphics
      • 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:
        translate in class Graphics2D
        Parameters:
        x - the x coordinate.
        y - the y coordinate.
      • shear

        public void shear​(double d1,
                          double d2)
        Specified by:
        shear in class Graphics2D
      • scale

        public void scale​(double d1,
                          double d2)
        Specified by:
        scale in class Graphics2D
      • rotate

        public void rotate​(double d1,
                           double d2,
                           double d3)
        Specified by:
        rotate in class Graphics2D
      • rotate

        public void rotate​(double d1)
        Specified by:
        rotate in class Graphics2D
      • translate

        public void translate​(double d1,
                              double d2)
        Specified by:
        translate in class Graphics2D