Back to index

wims  3.65+svn20090927
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
ptolemy.plot.EPSGraphics Class Reference

Graphics class supporting EPS export from plots. More...

Inheritance diagram for ptolemy.plot.EPSGraphics:
Inheritance graph
[legend]
Collaboration diagram for ptolemy.plot.EPSGraphics:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 EPSGraphics (OutputStream out, int width, int height)
 Constructor for a graphics object that writes encapsulated PostScript to the specified output stream.
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)
Graphics create ()
void dispose ()
void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle)
boolean drawImage (Image img, int x, int y, ImageObserver observer)
boolean drawImage (Image img, int x, int y, int width, int height, ImageObserver observer)
boolean drawImage (Image img, int x, int y, Color bgcolor, ImageObserver observer)
boolean drawImage (Image img, int x, int y, int width, int height, 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)
boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, 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 drawPolyline (int[] xPoints, int[] yPoints, int nPoints)
void drawPolygon (int[] xPoints, int[] yPoints, int nPoints)
 Draw a closed polygon defined by arrays of x and y coordinates.
void drawOval (int x, int y, int width, int height)
 Draw an oval bounded by the specified rectangle with the current color.
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 (String str, int x, int y)
 Draw a string.
void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle)
void fillPolygon (int[] xPoints, int[] yPoints, int nPoints)
 Draw a filled polygon defined by arrays of x and y coordinates.
void fillOval (int x, int y, int width, int height)
 Fill an oval bounded by the specified rectangle with the current color.
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)
Shape getClip ()
Rectangle getClipBounds ()
Color getColor ()
Font getFont ()
FontMetrics getFontMetrics (Font f)
void setFont (Font font)
void setClip (Shape clip)
void setClip (int x, int y, int width, int height)
void setColor (Color c)
 Set the current color.
void setPaintMode ()
void setXORMode (Color c1)
void showpage ()
 Issue the PostScript showpage command, then write and flush the output.
void translate (int x, int y)

Private Member Functions

Point _convert (int x, int y)
boolean _polygon (int[] xPoints, int[] yPoints, int nPoints)
void _fillPattern ()

Private Attributes

Color _currentColor = Color.black
Font _currentFont
int _width
int _height
Hashtable _linepattern = new Hashtable()
OutputStream _out
StringBuffer _buffer = new StringBuffer()
Clipboard _clipboard
int _patternIndex = 0

Static Private Attributes

static String[] _patterns

Detailed Description

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.

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

Definition at line 67 of file EPSGraphics.java.


Constructor & Destructor Documentation

ptolemy.plot.EPSGraphics.EPSGraphics ( OutputStream  out,
int  width,
int  height 
) [inline]

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:
outThe stream to write to, or null to write to standard out.
widthThe width of the plot graphic, in units of 1/72 inch.
heightThe height of the plot graphic, in units of 1/72 inch.

Definition at line 77 of file EPSGraphics.java.

                                                                {
        _width = width;
        _height = height;
        _out = out;
        _buffer.append("%!PS-Adobe-3.0 EPSF-3.0\n");
        _buffer.append("%%Creator: UC Berkeley Plot Package\n");
        _buffer.append("%%BoundingBox: 50 50 " + (50 + width) + " "
                + (50 + height) + "\n");
        _buffer.append("%%Pages: 1\n");
        _buffer.append("%%Page: 1 1\n");
        _buffer.append("%%LanguageLevel: 2\n");
    }

Here is the caller graph for this function:


Member Function Documentation

Point ptolemy.plot.EPSGraphics._convert ( int  x,
int  y 
) [inline, private]

Definition at line 423 of file EPSGraphics.java.

                                         {
        return new Point(x + 50, (_height + 50) - y);
    }

Here is the caller graph for this function:

void ptolemy.plot.EPSGraphics._fillPattern ( ) [inline, private]

Definition at line 448 of file EPSGraphics.java.

                                {
        // FIXME: We probably want a fill pattern rather than
        // just a gray scale.
        int red = _currentColor.getRed();
        int green = _currentColor.getGreen();
        int blue = _currentColor.getBlue();

        // Scaling constants so that fully saturated R, G, or B appear
        // different.
        double bluescale = 0.6; // darkest
        double redscale = 0.8;
        double greenscale = 1.0; // lightest
        double fullscale = Math.sqrt(255.0 * 255.0 * ((bluescale * bluescale)
                + (redscale * redscale) + (greenscale * greenscale)));
        double graylevel = Math.sqrt(((red * red * redscale * redscale)
                + (blue * blue * bluescale * bluescale) + (green * green
                * greenscale * greenscale)))
                / fullscale;
        _buffer.append("" + graylevel + " setgray\n");

        // NOTE -- for debugging, output color spec in comments
        _buffer.append("%---- rgb: " + red + " " + green + " " + blue + "\n");
    }

Here is the caller graph for this function:

boolean ptolemy.plot.EPSGraphics._polygon ( int[]  xPoints,
int[]  yPoints,
int  nPoints 
) [inline, private]

Definition at line 429 of file EPSGraphics.java.

                                                                        {
        if ((nPoints < 3) || (xPoints.length < nPoints)
                || (yPoints.length < nPoints)) {
            return false;
        }

        Point start = _convert(xPoints[0], yPoints[0]);
        _buffer.append("newpath " + start.x + " " + start.y + " moveto\n");

        for (int i = 1; i < nPoints; i++) {
            Point vertex = _convert(xPoints[i], yPoints[i]);
            _buffer.append("" + vertex.x + " " + vertex.y + " lineto\n");
        }

        return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.EPSGraphics.clearRect ( int  x,
int  y,
int  width,
int  height 
) [inline]

Definition at line 92 of file EPSGraphics.java.

                                                               {
    }
void ptolemy.plot.EPSGraphics.clipRect ( int  x,
int  y,
int  width,
int  height 
) [inline]

Definition at line 95 of file EPSGraphics.java.

                                                              {
    }
void ptolemy.plot.EPSGraphics.copyArea ( int  x,
int  y,
int  width,
int  height,
int  dx,
int  dy 
) [inline]

Definition at line 98 of file EPSGraphics.java.

                                                                              {
    }
Graphics ptolemy.plot.EPSGraphics.create ( ) [inline]

Definition at line 101 of file EPSGraphics.java.

                             {
        return new EPSGraphics(_out, _width, _height);
    }

Here is the call graph for this function:

Definition at line 105 of file EPSGraphics.java.

                          {
    }
void ptolemy.plot.EPSGraphics.drawArc ( int  x,
int  y,
int  width,
int  height,
int  startAngle,
int  arcAngle 
) [inline]

Definition at line 108 of file EPSGraphics.java.

                          {
    }
boolean ptolemy.plot.EPSGraphics.drawImage ( Image  img,
int  x,
int  y,
ImageObserver  observer 
) [inline]

Definition at line 112 of file EPSGraphics.java.

                                                                              {
        return true;
    }
boolean ptolemy.plot.EPSGraphics.drawImage ( Image  img,
int  x,
int  y,
int  width,
int  height,
ImageObserver  observer 
) [inline]

Definition at line 116 of file EPSGraphics.java.

                                    {
        return true;
    }
boolean ptolemy.plot.EPSGraphics.drawImage ( Image  img,
int  x,
int  y,
Color  bgcolor,
ImageObserver  observer 
) [inline]

Definition at line 121 of file EPSGraphics.java.

                                    {
        return true;
    }
boolean ptolemy.plot.EPSGraphics.drawImage ( Image  img,
int  x,
int  y,
int  width,
int  height,
Color  bgcolor,
ImageObserver  observer 
) [inline]

Definition at line 126 of file EPSGraphics.java.

                                                   {
        return true;
    }
boolean ptolemy.plot.EPSGraphics.drawImage ( Image  img,
int  dx1,
int  dy1,
int  dx2,
int  dy2,
int  sx1,
int  sy1,
int  sx2,
int  sy2,
ImageObserver  observer 
) [inline]

Definition at line 131 of file EPSGraphics.java.

                                                                        {
        return true;
    }
boolean ptolemy.plot.EPSGraphics.drawImage ( Image  img,
int  dx1,
int  dy1,
int  dx2,
int  dy2,
int  sx1,
int  sy1,
int  sx2,
int  sy2,
Color  bgcolor,
ImageObserver  observer 
) [inline]

Definition at line 136 of file EPSGraphics.java.

                                    {
        return true;
    }
void ptolemy.plot.EPSGraphics.drawLine ( int  x1,
int  y1,
int  x2,
int  y2 
) [inline]

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

Parameters:
x1the x coordinate of the first point.
y1the y coordinate of the first point.
x2the x coordinate of the second point.
y2the y coordinate of the second point.

Definition at line 149 of file EPSGraphics.java.

                                                         {
        Point start = _convert(x1, y1);
        Point end = _convert(x2, y2);
        _buffer.append("newpath " + start.x + " " + start.y + " moveto\n");
        _buffer.append("" + end.x + " " + end.y + " lineto\n");
        _buffer.append("stroke\n");
    }

Here is the call graph for this function:

void ptolemy.plot.EPSGraphics.drawOval ( int  x,
int  y,
int  width,
int  height 
) [inline]

Draw an oval bounded by the specified rectangle with the current color.

Parameters:
xThe x coordinate of the upper left corner
yThe y coordinate of the upper left corner
widthThe width of the oval to be filled.
heightThe height of the oval to be filled.

Definition at line 186 of file EPSGraphics.java.

                                                              {
        int radius = width / 2;
        Point center = _convert(x + radius, y + radius);
        _buffer.append("newpath " + center.x + " " + center.y + " " + radius
                + " 0 360 arc closepath stroke\n");
    }

Here is the call graph for this function:

void ptolemy.plot.EPSGraphics.drawPolygon ( int[]  xPoints,
int[]  yPoints,
int  nPoints 
) [inline]

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:
xPointsAn array of x coordinates.
yPointsAn array of y coordinates.
nPointsThe total number of vertices.

Definition at line 169 of file EPSGraphics.java.

                                                                       {
        if (!_polygon(xPoints, yPoints, nPoints)) {
            return;
        } else {
            _buffer.append("closepath stroke\n");
        }
    }

Here is the call graph for this function:

void ptolemy.plot.EPSGraphics.drawPolyline ( int[]  xPoints,
int[]  yPoints,
int  nPoints 
) [inline]

Definition at line 157 of file EPSGraphics.java.

                                                                        {
    }
void ptolemy.plot.EPSGraphics.drawRect ( int  x,
int  y,
int  width,
int  height 
) [inline]

Definition at line 193 of file EPSGraphics.java.

                                                              {
        Point start = _convert(x, y);
        _buffer.append("newpath " + start.x + " " + start.y + " moveto\n");
        _buffer.append("0 " + (-height) + " rlineto\n");
        _buffer.append("" + width + " 0 rlineto\n");
        _buffer.append("0 " + height + " rlineto\n");
        _buffer.append("" + (-width) + " 0 rlineto\n");
        _buffer.append("closepath stroke\n");
    }

Here is the call graph for this function:

void ptolemy.plot.EPSGraphics.drawRoundRect ( int  x,
int  y,
int  width,
int  height,
int  arcWidth,
int  arcHeight 
) [inline]

Definition at line 203 of file EPSGraphics.java.

                                         {
    }
void ptolemy.plot.EPSGraphics.drawString ( java.text.AttributedCharacterIterator  iterator,
int  x,
int  y 
) [inline]

Definition at line 207 of file EPSGraphics.java.

                          {
        // FIXME: This method is present in the graphics class in JDK1.2,
        // but not in JDK1.1.
        throw new RuntimeException(
                "Sorry, drawString(java.text.AttributedCharacterIterator, "
                        + "int , int) is not implemented in EPSGraphics");
    }
void ptolemy.plot.EPSGraphics.drawString ( String  str,
int  x,
int  y 
) [inline]

Draw a string.

"(" is converted to "(" and ")" is converted to ") so as to avoid EPS Syntax errors.

Parameters:
strThe string to draw.
xThe x location of the string.
yThe y location of the string.

Definition at line 222 of file EPSGraphics.java.

                                                     {
        Point start = _convert(x, y);
        _buffer.append("" + start.x + " " + start.y + " moveto\n");

        if ((str.indexOf("(") > -1) && (str.indexOf("\\(") == -1)) {
            str = StringUtilities.substitute(str, "(", "\\(");
        }

        if ((str.indexOf(")") > -1) && (str.indexOf("\\)") == -1)) {
            str = StringUtilities.substitute(str, ")", "\\)");
        }

        _buffer.append("(" + str + ") show\n");
    }

Here is the call graph for this function:

void ptolemy.plot.EPSGraphics.fillArc ( int  x,
int  y,
int  width,
int  height,
int  startAngle,
int  arcAngle 
) [inline]

Definition at line 237 of file EPSGraphics.java.

                          {
    }
void ptolemy.plot.EPSGraphics.fillOval ( int  x,
int  y,
int  width,
int  height 
) [inline]

Fill an oval bounded by the specified rectangle with the current color.

Parameters:
xThe x coordinate of the upper left corner
yThe y coordinate of the upper left corner
widthThe width of the oval to be filled.
heightThe height of the oval to be filled.

Definition at line 267 of file EPSGraphics.java.

                                                              {
        int radius = width / 2;
        Point center = _convert(x + radius, y + radius);
        _buffer.append("newpath " + center.x + " " + center.y + " " + radius
                + " 0 360 arc closepath fill\n");
    }

Here is the call graph for this function:

void ptolemy.plot.EPSGraphics.fillPolygon ( int[]  xPoints,
int[]  yPoints,
int  nPoints 
) [inline]

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:
xPointsAn array of x coordinates.
yPointsAn array of y coordinates.
nPointsThe total number of vertices.

Definition at line 250 of file EPSGraphics.java.

                                                                       {
        if (!_polygon(xPoints, yPoints, nPoints)) {
            return;
        } else {
            _buffer.append("closepath fill\n");
        }
    }

Here is the call graph for this function:

void ptolemy.plot.EPSGraphics.fillRect ( int  x,
int  y,
int  width,
int  height 
) [inline]

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:
xThe x coordinate of the top left corner.
yThe y coordinate of the top left corner.
widthThe width of the rectangle.
heightThe height of the rectangle.

Definition at line 285 of file EPSGraphics.java.

                                                              {
        Point start = _convert(x, y);
        _fillPattern();
        _buffer.append("newpath " + start.x + " " + start.y + " moveto\n");
        _buffer.append("0 " + (-height) + " rlineto\n");
        _buffer.append("" + width + " 0 rlineto\n");
        _buffer.append("0 " + height + " rlineto\n");
        _buffer.append("" + (-width) + " 0 rlineto\n");
        _buffer.append("closepath gsave fill grestore\n");
        _buffer.append("0.5 setlinewidth 0 setgray [] 0 setdash stroke\n");

        // reset the gray scale to black
        _buffer.append("1 setlinewidth\n");
    }

Here is the call graph for this function:

void ptolemy.plot.EPSGraphics.fillRoundRect ( int  x,
int  y,
int  width,
int  height,
int  arcWidth,
int  arcHeight 
) [inline]

Definition at line 300 of file EPSGraphics.java.

                                         {
    }

Definition at line 304 of file EPSGraphics.java.

                           {
        return null;
    }

Definition at line 308 of file EPSGraphics.java.

                                     {
        return null;
    }

Definition at line 312 of file EPSGraphics.java.

                            {
        return _currentColor;
    }

Definition at line 316 of file EPSGraphics.java.

                          {
        return _currentFont;
    }
FontMetrics ptolemy.plot.EPSGraphics.getFontMetrics ( Font  f) [inline]

Definition at line 320 of file EPSGraphics.java.

                                              {
        return null;
    }
void ptolemy.plot.EPSGraphics.setClip ( Shape  clip) [inline]

Definition at line 342 of file EPSGraphics.java.

                                    {
    }
void ptolemy.plot.EPSGraphics.setClip ( int  x,
int  y,
int  width,
int  height 
) [inline]

Definition at line 345 of file EPSGraphics.java.

                                                             {
    }
void ptolemy.plot.EPSGraphics.setColor ( Color  c) [inline]

Set the current color.

Since we are generating gray scale postscript, set a line style. Set the gray level to zero (black).

Parameters:
cThe desired current color.

Definition at line 352 of file EPSGraphics.java.

                                  {
        if (c == Color.black) {
            _buffer.append("0 setgray\n");
            _buffer.append("[] 0 setdash\n");
            _buffer.append("1 setlinewidth\n");
        } else if (c == Color.white) {
            _buffer.append("1 setgray\n");
            _buffer.append("[] 0 setdash\n");
            _buffer.append("1 setlinewidth\n");
        } else if (c == Color.lightGray) {
            _buffer.append("0.9 setgray\n");
            _buffer.append("[] 0 setdash\n");
            _buffer.append("0.5 setlinewidth\n");
        } else {
            if (_linepattern.containsKey(c)) {
                _buffer.append((String) _linepattern.get(c) + " 0 setdash\n");
                _buffer.append("1 setlinewidth\n");
            } else {
                _buffer.append("0 setgray\n");

                // construct a new line pattern.
                if (_patternIndex >= _patterns.length) {
                    _patternIndex = 0;
                }

                _buffer.append(_patterns[_patternIndex] + " 0 setdash\n");
                _buffer.append("1 setlinewidth\n");
                _linepattern.put(c, _patterns[_patternIndex]);
                _patternIndex++;
            }
        }

        _currentColor = c;
    }
void ptolemy.plot.EPSGraphics.setFont ( Font  font) [inline]

Definition at line 324 of file EPSGraphics.java.

                                   {
        if (font == null) {
            return;
        }

        int size = font.getSize();
        boolean bold = font.isBold();

        if (bold) {
            _buffer.append("/Helvetica-Bold findfont\n");
        } else {
            _buffer.append("/Helvetica findfont\n");
        }

        _buffer.append("" + size + " scalefont setfont\n");
        _currentFont = font;
    }

Definition at line 387 of file EPSGraphics.java.

                               {
    }
void ptolemy.plot.EPSGraphics.setXORMode ( Color  c1) [inline]

Definition at line 390 of file EPSGraphics.java.

                                     {
    }

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.

Definition at line 397 of file EPSGraphics.java.

                           {
        _buffer.append("showpage\n");

        if (_out != null) {
            PrintWriter output = new PrintWriter(new BufferedOutputStream(_out));

            output.println(_buffer.toString());
            output.flush();
        } else {
            // Write to clipboard instead
            // NOTE: This doesn't work at least with jdk 1.3beta
            if (_clipboard == null) {
                _clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            }

            StringSelection sel = new StringSelection(_buffer.toString());
            _clipboard.setContents(sel, sel);
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.EPSGraphics.translate ( int  x,
int  y 
) [inline]

Definition at line 417 of file EPSGraphics.java.

                                        {
    }

Member Data Documentation

StringBuffer ptolemy.plot.EPSGraphics._buffer = new StringBuffer() [private]

Definition at line 486 of file EPSGraphics.java.

Definition at line 488 of file EPSGraphics.java.

Definition at line 474 of file EPSGraphics.java.

Definition at line 476 of file EPSGraphics.java.

Definition at line 480 of file EPSGraphics.java.

Hashtable ptolemy.plot.EPSGraphics._linepattern = new Hashtable() [private]

Definition at line 482 of file EPSGraphics.java.

OutputStream ptolemy.plot.EPSGraphics._out [private]

Definition at line 484 of file EPSGraphics.java.

Definition at line 496 of file EPSGraphics.java.

String [] ptolemy.plot.EPSGraphics._patterns [static, private]
Initial value:
 { "[]", "[1 1]", "[4 4]", "[4 4 1 4]",
            "[2 2]", "[4 2 1 2 1 2]", "[5 3 2 3]", "[3 3]", "[4 2 1 2 2 2]",
            "[1 2 5 2 1 2 1 2]", "[4 1 2 1]", }

Definition at line 492 of file EPSGraphics.java.

Definition at line 478 of file EPSGraphics.java.


The documentation for this class was generated from the following file: