ptolemy.plot
Class EPSGraphics

java.lang.Object
  extended byjava.awt.Graphics
      extended byptolemy.plot.EPSGraphics

public class EPSGraphics
extends java.awt.Graphics

Graphics class supporting EPS export from plots. If this is used from within an applet, then the output goes to the standard output. Unfortunately, with standard browsers, this is not useful. With MS Internet Explorer, standard output is not available. With Netscape Navigator, standard output is available in the Java console, but is limited to fewer lines than what is usually generated. Thus, we recommend using this within Sun's appletviewer, and redirecting its standard output to a file.

Since:
Ptolemy II 0.2
Version:
$Id: EPSGraphics.java,v 1.41 2006/03/30 16:36:39 cxh Exp $
Author:
Edward A. Lee
Accepted Rating:
Yellow (cxh)
Proposed Rating:
Yellow (cxh)

Constructor Summary
EPSGraphics(java.io.OutputStream out, int width, int height)
          Constructor for a graphics object that writes encapsulated PostScript to the specified output stream.
 
Method Summary
 void clearRect(int x, int y, int width, int height)
           
 void clipRect(int x, int y, int width, int height)
           
 void copyArea(int x, int y, int width, int height, int dx, int dy)
           
 java.awt.Graphics create()
           
 void dispose()
           
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
           
 boolean drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)
           
 void drawLine(int x1, int y1, int x2, int y2)
          Draw a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.
 void drawOval(int x, int y, int width, int height)
          Draw an oval bounded by the specified rectangle with the current color.
 void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Draw a closed polygon defined by arrays of x and y coordinates.
 void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
           
 void drawRect(int x, int y, int width, int height)
           
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
           
 void drawString(java.text.AttributedCharacterIterator iterator, int x, int y)
           
 void drawString(java.lang.String str, int x, int y)
          Draw a string. "(" is converted to "\(" and ")" is converted to "\) so as to avoid EPS Syntax errors.
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
           
 void fillOval(int x, int y, int width, int height)
          Fill an oval bounded by the specified rectangle with the current color.
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Draw a filled polygon defined by arrays of x and y coordinates.
 void fillRect(int x, int y, int width, int height)
          Fill the specified rectangle and draw a thin outline around it.
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
           
 java.awt.Shape getClip()
           
 java.awt.Rectangle getClipBounds()
           
 java.awt.Color getColor()
           
 java.awt.Font getFont()
           
 java.awt.FontMetrics getFontMetrics(java.awt.Font f)
           
 void setClip(int x, int y, int width, int height)
           
 void setClip(java.awt.Shape clip)
           
 void setColor(java.awt.Color c)
          Set the current color.
 void setFont(java.awt.Font font)
           
 void setPaintMode()
           
 void setXORMode(java.awt.Color c1)
           
 void showpage()
          Issue the PostScript showpage command, then write and flush the output.
 void translate(int x, int y)
           
 
Methods inherited from class java.awt.Graphics
create, draw3DRect, drawBytes, drawChars, drawPolygon, fill3DRect, 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

EPSGraphics

public EPSGraphics(java.io.OutputStream out,
                   int width,
                   int height)
Constructor for a graphics object that writes encapsulated PostScript to the specified output stream. If the out argument is null, then it writes to standard output (it would write it to the clipboard, but as of this writing, writing to the clipboard does not work in Java).

Parameters:
out - The stream to write to, or null to write to standard out.
width - The width of the plot graphic, in units of 1/72 inch.
height - The height of the plot graphic, in units of 1/72 inch.
Method Detail

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)

clipRect

public void clipRect(int x,
                     int y,
                     int width,
                     int height)

copyArea

public void copyArea(int x,
                     int y,
                     int width,
                     int height,
                     int dx,
                     int dy)

create

public java.awt.Graphics create()

dispose

public void dispose()

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         java.awt.image.ImageObserver observer)

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         java.awt.image.ImageObserver observer)

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver observer)

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver observer)

drawImage

public boolean drawImage(java.awt.Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         java.awt.image.ImageObserver observer)

drawImage

public boolean drawImage(java.awt.Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver observer)

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Draw a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.

Parameters:
x1 - the x coordinate of the first point.
y1 - the y coordinate of the first point.
x2 - the x coordinate of the second point.
y2 - the y coordinate of the second point.

drawPolyline

public void drawPolyline(int[] xPoints,
                         int[] yPoints,
                         int nPoints)

drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Draw a closed polygon defined by arrays of x and y coordinates. Each pair of (x, y) coordinates defines a vertex. The third argument gives the number of vertices. If the arrays are not long enough to define this many vertices, or if the third argument is less than three, then nothing is drawn.

Parameters:
xPoints - An array of x coordinates.
yPoints - An array of y coordinates.
nPoints - The total number of vertices.

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Draw an oval bounded by the specified rectangle with the current color.

Parameters:
x - The x coordinate of the upper left corner
y - The y coordinate of the upper left corner
width - The width of the oval to be filled.
height - The height of the oval to be filled.

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)

drawString

public void drawString(java.text.AttributedCharacterIterator iterator,
                       int x,
                       int y)

drawString

public void drawString(java.lang.String str,
                       int x,
                       int y)
Draw a string. "(" is converted to "\(" and ")" is converted to "\) so as to avoid EPS Syntax errors.

Parameters:
str - The string to draw.
x - The x location of the string.
y - The y location of the string.

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Draw a filled polygon defined by arrays of x and y coordinates. Each pair of (x, y) coordinates defines a vertex. The third argument gives the number of vertices. If the arrays are not long enough to define this many vertices, or if the third argument is less than three, then nothing is drawn.

Parameters:
xPoints - An array of x coordinates.
yPoints - An array of y coordinates.
nPoints - The total number of vertices.

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Fill an oval bounded by the specified rectangle with the current color.

Parameters:
x - The x coordinate of the upper left corner
y - The y coordinate of the upper left corner
width - The width of the oval to be filled.
height - The height of the oval to be filled.

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Fill the specified rectangle and draw a thin outline around it. The left and right edges of the rectangle are at x and x + width - 1. The top and bottom edges are at y and y + height - 1. The resulting rectangle covers an area width pixels wide by height pixels tall. The rectangle is filled using the brightness of the current color to set the level of gray.

Parameters:
x - The x coordinate of the top left corner.
y - The y coordinate of the top left corner.
width - The width of the rectangle.
height - The height of the rectangle.

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)

getClip

public java.awt.Shape getClip()

getClipBounds

public java.awt.Rectangle getClipBounds()

getColor

public java.awt.Color getColor()

getFont

public java.awt.Font getFont()

getFontMetrics

public java.awt.FontMetrics getFontMetrics(java.awt.Font f)

setFont

public void setFont(java.awt.Font font)

setClip

public void setClip(java.awt.Shape clip)

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)

setColor

public void setColor(java.awt.Color c)
Set the current color. Since we are generating gray scale postscript, set a line style. Set the gray level to zero (black).

Parameters:
c - The desired current color.

setPaintMode

public void setPaintMode()

setXORMode

public void setXORMode(java.awt.Color c1)

showpage

public void showpage()
Issue the PostScript showpage command, then write and flush the output. If the output argument of the constructor was null, then write to the clipboard.


translate

public void translate(int x,
                      int y)