Back to index

wims  3.65+svn20090927
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Package Functions | Package Attributes | Private Member Functions | Private Attributes | Static Private Attributes
ptolemy.plot.PlotBox Class Reference

This class provides a labeled box within which to place a data plot. More...

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

List of all members.

Classes

class  ButtonListener
class  CommandListener
class  DragListener
class  ZoomListener

Public Member Functions

String ReadPlotApplet ()
 PlotBox ()
 Construct a plot box with a default configuration.
synchronized void addLegend (int dataset, String legend)
 Add a legend (displayed at the upper right) for the specified data set with the specified string.
synchronized void addXTick (String label, double position)
 Specify a tick mark for the X axis.
synchronized void addYTick (String label, double position)
 Specify a tick mark for the Y axis.
synchronized void clear (boolean axes)
 If the argument is true, clear the axes.
synchronized void clearLegends ()
 Clear all legends.
void deferIfNecessary (Runnable action)
 If this method is called in the event thread, then simply execute the specified action.
synchronized void export (OutputStream out)
 Export a description of the plot.
synchronized BufferedImage exportImage ()
 Create a BufferedImage and draw this plot to it.
synchronized BufferedImage exportImage (Rectangle rectangle)
 Create a BufferedImage the size of the given rectangle and draw this plot to it at the position specified by the rectangle.
synchronized BufferedImage exportImage (BufferedImage bufferedImage, Rectangle rectangle, RenderingHints hints, boolean transparent)
 Draw this plot onto the specified image at the position of the specified rectangle with the size of the specified rectangle.
synchronized BufferedImage exportImage (BufferedImage bufferedImage)
 Draw this plot onto the provided image.
synchronized void fillPlot ()
 Rescale so that the data that is currently plotted just fits.
boolean getColor ()
 Return whether the plot uses color.
Color[] getColors ()
 Get the point colors.
String getDataurl ()
 Get the file specification that was given by setDataurl.
URL getDocumentBase ()
 Get the document base that was set by setDocumentBase.
boolean getGrid ()
 Return whether the grid is drawn.
synchronized String getLegend (int dataset)
 Get the legend for a dataset, or null if there is none.
synchronized int getLegendDataset (String legend)
 Given a legend string, return the corresponding dataset or -1 if no legend was added with that legend string The legend would have been set by addLegend().
Rectangle getPlotRectangle ()
 If the size of the plot has been set by setSize(), then return that size.
synchronized Dimension getPreferredSize ()
 Get the preferred size of this component.
synchronized String getTitle ()
 Get the title of the graph, or an empty string if there is none.
synchronized double[] getXAutoRange ()
 Get the range for X values of the data points registered so far.
synchronized String getXLabel ()
 Get the label for the X (horizontal) axis, or null if none has been set.
boolean getXLog ()
 Return whether the X axis is drawn with a logarithmic scale.
synchronized double[] getXRange ()
 Get the X range.
synchronized Vector[] getXTicks ()
 Get the X ticks that have been specified, or null if none.
synchronized double[] getYAutoRange ()
 Get the range for Y values of the data points registered so far.
String getYLabel ()
 Get the label for the Y (vertical) axis, or null if none has been set.
boolean getYLog ()
 Return whether the Y axis is drawn with a logarithmic scale.
synchronized double[] getYRange ()
 Get the Y range.
synchronized Vector[] getYTicks ()
 Get the Y ticks that have been specified, or null if none.
void init ()
 Initialize the component, creating the fill button and parsing an input file, if one has been specified.
synchronized void paintComponent (Graphics graphics)
 Paint the component contents, which in this base class is only the axes.
void parseFile (String filespec)
 Syntactic sugar for parseFile(filespec, documentBase).
synchronized void parseFile (String filespec, URL documentBase)
 Open up the input file, which could be stdin, a URL, or a file.
synchronized int print (Graphics graphics, PageFormat format, int index) throws PrinterException
 Print the plot to a printer, represented by the specified graphics object.
synchronized void read (InputStream in) throws IOException
 Read commands and/or plot data from an input stream in the old (non-XML) file syntax.
synchronized void read (String command)
 Read a single line command provided as a string.
synchronized void removeLegend (int dataset)
 Remove the legend (displayed at the upper right) for the specified data set.
synchronized void renameLegend (int dataset, String newName)
 Rename a legend.
synchronized void resetAxes ()
 Reset the X and Y axes to the ranges that were first specified using setXRange() and setYRange().
void samplePlot ()
 Do nothing in this base class.
synchronized void setBackground (Color background)
 Set the background color.
synchronized void setBounds (int x, int y, int width, int height)
 Move and resize this component.
synchronized void setButtons (boolean visible)
 If the argument is true, make a fill button visible at the upper right.
synchronized void setColor (boolean useColor)
 If the argument is false, draw the plot without using color (in black and white).
synchronized void setColors (Color[] colors)
 Set the point colors.
void setDataurl (String filespec)
 Set the file to read when init() is called.
void setDocumentBase (URL documentBase)
 Set the document base to used when init() is called to read a URL.
synchronized void setForeground (Color foreground)
 Set the foreground color.
synchronized void setGrid (boolean grid)
 Control whether the grid is drawn.
synchronized void setLabelFont (String name)
 Set the label font, which is used for axis labels and legend labels.
synchronized void setPlotRectangle (Rectangle rectangle)
 Set the plot rectangle inside the axes.
synchronized void setSize (int width, int height)
 Set the size of the plot.
synchronized void setTitle (String title)
 Set the title of the graph.
synchronized void setTitleFont (String name)
 Set the title font.
synchronized void setWrap (boolean wrap)
 Specify whether the X axis is wrapped.
synchronized void setXLabel (String label)
 Set the label for the X (horizontal) axis.
synchronized void setXLog (boolean xlog)
 Specify whether the X axis is drawn with a logarithmic scale.
synchronized void setXRange (double min, double max)
 Set the X (horizontal) range of the plot.
synchronized void setYLabel (String label)
 Set the label for the Y (vertical) axis.
synchronized void setYLog (boolean ylog)
 Specify whether the Y axis is drawn with a logarithmic scale.
synchronized void setYRange (double min, double max)
 Set the Y (vertical) range of the plot.
void write (OutputStream out)
 Write the current data and plot configuration to the specified stream in PlotML syntax.
synchronized void write (OutputStream out, String dtd)
 Write the current data and plot configuration to the specified stream in PlotML syntax.
synchronized void write (Writer out, String dtd)
 Write the current data and plot configuration to the specified stream in PlotML syntax.
synchronized void writeData (PrintWriter output)
 Write plot data information to the specified output stream in PlotML.
synchronized void writeFormat (PrintWriter output)
 Write plot format information to the specified output stream in PlotML.
synchronized void writeOldSyntax (OutputStream out)
 Write the current data and plot configuration to the specified stream in the old PtPlot syntax.
synchronized void zoom (double lowx, double lowy, double highx, double highy)
 Zoom in or out to the specified rectangle.

Static Public Member Functions

static Color getColorByName (String name)
 Convert a color name into a Color.

Public Attributes

URL _documentBase = null
 Indicator that size has been set.

Static Public Attributes

static final String PTPLOT_RELEASE = "5.7"

Protected Member Functions

synchronized void _drawPlot (Graphics graphics, boolean clearfirst)
 Draw the axes using the current range, label, and title information.
synchronized void _drawPlot (Graphics graphics, boolean clearfirst, Rectangle drawRect)
 Draw the axes using the current range, label, and title information, at the size of the specified rectangle.
void _drawPoint (Graphics graphics, int dataset, long xpos, long ypos, boolean clip)
 Put a mark corresponding to the specified dataset at the specified x and y position.
void _help ()
 Display basic information in its own window.
boolean _parseLine (String line)
 Parse a line that gives plotting information.
void _setButtonsVisibility (boolean vis)
 Set the visibility of the Fill button.
void _setPadding (double padding)
 Set the padding multiple.
void _writeOldSyntax (PrintWriter output)
 Write plot information to the specified output stream in the old PtPlot syntax.

Protected Attributes

transient double _yMax = 0
transient double _yMin = 0
transient double _xMax = 0
transient double _xMin = 0
double _padding = 0.05
 The factor we pad by so that we don't plot points on the axes.
transient boolean _xRangeGiven = false
transient boolean _yRangeGiven = false
transient boolean _rangesGivenByZooming = false
double _xlowgiven
 The given X and Y ranges.
double _xhighgiven
 The given X and Y ranges.
double _ylowgiven
 The given X and Y ranges.
double _yhighgiven
 The given X and Y ranges.
double _xBottom = Double.MAX_VALUE
 The minimum X value registered so for, for auto ranging.
double _xTop = -Double.MAX_VALUE
 The maximum X value registered so for, for auto ranging.
double _yBottom = Double.MAX_VALUE
 The minimum Y value registered so for, for auto ranging.
double _yTop = -Double.MAX_VALUE
 The maximum Y value registered so for, for auto ranging.
boolean _xlog = false
 Whether to draw the axes using a logarithmic scale.
boolean _ylog = false
 Whether to draw the axes using a logarithmic scale.
boolean _grid = true
 Whether to draw a background grid.
boolean _wrap = false
 Whether to wrap the X axis.
double _wrapHigh
 The high range of the X axis for wrapping.
double _wrapLow
 The low range of the X axis for wrapping.
Color _background = Color.white
 Color of the background, settable from HTML.
Color _foreground = Color.black
 Color of the foreground, settable from HTML.
int _topPadding = 10
 Top padding.
int _bottomPadding = 5
 Bottom padding.
int _rightPadding = 10
 Right padding.
int _leftPadding = 10
 Left padding.
int _ulx = 1
 The x value of the upper left corner of the plot rectangle in pixels.
int _uly = 1
 The y value of the upper left corner of the plot rectangle in pixels.
int _lrx = 100
 The x value of the lower right corner of the plot rectangle in pixels.
int _lry = 100
 The y value of the lower right corner of the plot rectangle in pixels.
Rectangle _specifiedPlotRectangle = null
 User specified plot rectangle, null if none specified.
double _yscale = 1.0
 Scaling used for the vertical axis in plotting points.
double _xscale = 1.0
 Scaling used for the horizontal axis in plotting points.
boolean _usecolor = true
 Indicator whether to use _colors.
int _width = 500
 Width and height of component in pixels.
int _height = 300
 Width and height of component in pixels.
int _preferredWidth = 500
 Width and height of component in pixels.
int _preferredHeight = 300
 Width and height of component in pixels.
transient BufferedImage _plotImage = null

Static Protected Attributes

static final double _LOG10SCALE = 1 / Math.log(10)
static Color[] _colors

Package Functions

void _zoom (int x, int y)
void _zoomBox (int x, int y)
void _zoomStart (int x, int y)

Package Attributes

boolean _originalXRangeGiven = false
boolean _originalYRangeGiven = false
double _originalXlow = 0.0
double _originalXhigh = 0.0
double _originalYlow = 0.0
double _originalYhigh = 0.0

Private Member Functions

int _drawLegend (Graphics graphics, int urx, int ury)
synchronized void _executeDeferredActions ()
String _formatLogNum (double num, int numfracdigits)
String _formatNum (double num, int numfracdigits)
Vector _gridInit (double low, double step, boolean labeled, Vector oldgrid)
double _gridRoundUp (Vector grid, double pos)
double _gridStep (Vector grid, double pos, double step, boolean logflag)
void _measureFonts ()
int _numFracDigits (double num)
int _numIntDigits (double num)
void _parsePairs (String line, boolean xtick)
RenderingHints _defaultImageRenderingHints ()
 Return a default set of rendering hints for image export, which specifies the use of anti-aliasing.
double _roundUp (double val)
void _setXRange (double min, double max)
void _setYRange (double min, double max)

Private Attributes

boolean _actionsDeferred = false
 Indicator of whether actions are deferred.
List _deferredActions
 List of deferred actions.
String _filespec = null
 The file to be opened.
double _ytickMax = 0.0
 The range of the plot as labeled (multiply by 10^exp for actual range.
double _ytickMin = 0.0
 The range of the plot as labeled (multiply by 10^exp for actual range.
double _xtickMax = 0.0
 The range of the plot as labeled (multiply by 10^exp for actual range.
double _xtickMin = 0.0
 The range of the plot as labeled (multiply by 10^exp for actual range.
int _yExp = 0
 The power of ten by which the range numbers should be multiplied.
int _xExp = 0
 The power of ten by which the range numbers should be multiplied.
double _ytickscale = 0.0
 Scaling used in making tick marks.
double _xtickscale = 0.0
 Scaling used in making tick marks.
Font _labelFont = null
 Font information.
Font _superscriptFont = null
 Font information.
Font _titleFont = null
 Font information.
FontMetrics _labelFontMetrics = null
 FontMetric information.
FontMetrics _superscriptFontMetrics = null
 FontMetric information.
FontMetrics _titleFontMetrics = null
 FontMetric information.
transient int _gridCurJuke = 0
transient double _gridBase = 0.0
transient String[] _errorMsg
String _xlabel
 The title and label strings.
String _ylabel
 The title and label strings.
String _title
 The title and label strings.
Vector _legendStrings = new Vector()
 Legend information.
Vector _legendDatasets = new Vector()
 Legend information.
Vector _xticks = null
 If XTicks or YTicks are given/
Vector _xticklabels = null
 If XTicks or YTicks are given/
Vector _yticks = null
 If XTicks or YTicks are given/
Vector _yticklabels = null
 If XTicks or YTicks are given/
transient JButton _fillButton = null
transient JButton _formatButton = null
transient JButton _printButton = null
transient JButton _resetButton = null
transient int _zoomx = -1
transient int _zoomy = -1
transient int _zoomxn = -1
transient int _zoomyn = -1
transient boolean _zoomin = false
transient boolean _zoomout = false
transient boolean _drawn = false
transient boolean _zooming = false

Static Private Attributes

static final Color _boxColor = Color.orange

Detailed Description

This class provides a labeled box within which to place a data plot.

A title, X and Y axis labels, tick marks, and a legend are all supported. Zooming in and out is supported. To zoom in, drag the mouse downwards to draw a box. To zoom out, drag the mouse upward.

The box can be configured either through a file with commands or through direct invocation of the public methods of the class.

When calling the methods, in most cases the changes will not be visible until paintComponent() has been called. To request that this be done, call repaint().

A small set of key bindings are provided for convenience. They are:

These commands are provided in a menu by the PlotFrame class. Note that exporting to the clipboard is not allowed in applets (it used to be), so this will result in an error message.

At this time, the two export commands produce encapsulated postscript tuned for black-and-white printers. In the future, more formats may supported. Exporting to the clipboard and to standard output, in theory, is allowed for applets, unlike writing to a file. Thus, these key bindings provide a simple mechanism to obtain a high-resolution image of the plot from an applet, suitable for incorporation in a document. However, in some browsers, exporting to standard out triggers a security violation. You can use the JDK appletviewer instead.

To read commands from a file or URL, the preferred technique is to use one of the classes in the plotml package. That package supports both PlotML, an XML extension for plots, and a historical file format specific to ptplot. The historical file format is understood by the read() method in this class. The syntax of the historical format, documented below, is rudimentary, and will probably not be extended as ptplot evolves. Nonetheless, we document it here since it is directly supported by this class.

The historical format for the file allows any number commands, one per line. Unrecognized commands and commands with syntax errors are ignored. Comments are denoted by a line starting with a pound sign "#". The recognized commands include:

 TitleText: string
 XLabel: string
 YLabel: string
 

These commands provide a title and labels for the X (horizontal) and Y (vertical) axes. A string is simply a sequence of characters, possibly including spaces. There is no need here to surround them with quotation marks, and in fact, if you do, the quotation marks will be included in the labels.

The ranges of the X and Y axes can be optionally given by commands like:

 XRange: min, max
 YRange: min, max
 

The arguments min and max are numbers, possibly including a sign and a decimal point. If they are not specified, then the ranges are computed automatically from the data and padded slightly so that datapoints are not plotted on the axes.

The tick marks for the axes are usually computed automatically from the ranges. Every attempt is made to choose reasonable positions for the tick marks regardless of the data ranges (powers of ten multiplied by 1, 2, or 5 are used). However, they can also be specified explicitly using commands like:

 XTicks: label position, label position, ...
 YTicks: label position, label position, ...
 

A label is a string that must be surrounded by quotation marks if it contains any spaces. A position is a number giving the location of the tick mark along the axis. For example, a horizontal axis for a frequency domain plot might have tick marks as follows:

 XTicks: -PI -3.14159, -PI/2 -1.570795, 0 0, PI/2 1.570795, PI 3.14159
 

Tick marks could also denote years, months, days of the week, etc.

The X and Y axes can use a logarithmic scale with the following commands:

 XLog: on
 YLog: on
 

The grid labels represent powers of 10. Note that if a logarithmic scale is used, then the values must be positive. Non-positive values will be silently dropped. Note further that when using logarithmic axes that the log of input data is taken as the data is added to the plot. This means that

XLog: on

or

YLog: on

should appear before any data. Also, the value of the XTicks, YTicks, XRange or YRange directives should be in log units. So,

XTicks: 1K 3

will display the string

1K

at the 1000 mark.

By default, tick marks are connected by a light grey background grid. This grid can be turned off with the following command:

 Grid: off
 

It can be turned back on with

 Grid: on
 

Also, by default, the first ten data sets are shown each in a unique color. The use of color can be turned off with the command:

 Color: off
 

It can be turned back on with

 Color: on
 

Finally, the rather specialized command

 Wrap: on
 

enables wrapping of the X (horizontal) axis, which means that if a point is added with X out of range, its X value will be modified modulo the range so that it lies in range. This command only has an effect if the X range has been set explicitly. It is designed specifically to support oscilloscope-like behavior, where the X value of points is increasing, but the display wraps it around to left. A point that lands on the right edge of the X range is repeated on the left edge to give a better sense of continuity. The feature works best when points do land precisely on the edge, and are plotted from left to right, increasing in X.

All of the above commands can also be invoked directly by calling the the corresponding public methods from some Java procedure.

This class uses features of JDK 1.2, and hence if used in an applet, it can only be viewed by a browser that supports JDK 1.2, or a plugin.

Author:
Edward A. Lee, Christopher Brooks, Contributors: Jun Wu (jwu@i.nosp@m.nin..nosp@m.com.a.nosp@m.u), William Wu, Robert Kroeger
Version:
Id:
PlotBox.java,v 1.283.4.3 2008/04/01 01:19:02 cxh Exp
Since:
Ptolemy II 0.2 .ProposedRating Yellow (cxh) .AcceptedRating Yellow (cxh)

Definition at line 244 of file PlotBox.java.


Constructor & Destructor Documentation

Construct a plot box with a default configuration.

Definition at line 256 of file PlotBox.java.

                     {
        // If we make this transparent, the background shows through.
        // However, we assume that the user will set the background.
        // NOTE: A component is transparent by default (?).
        // setOpaque(false);
        setOpaque(true);

        // Create a right-justified layout with spacing of 2 pixels.
        setLayout(new FlowLayout(FlowLayout.RIGHT, 2, 2));
        addMouseListener(new ZoomListener());
        addKeyListener(new CommandListener());
        addMouseMotionListener(new DragListener());

        // This is something we want to do only once...
        _measureFonts();

        // Request the focus so that key events are heard.
        // NOTE: no longer needed?
        // requestFocus();
    }

Here is the call graph for this function:


Member Function Documentation

RenderingHints ptolemy.plot.PlotBox._defaultImageRenderingHints ( ) [inline, private]

Return a default set of rendering hints for image export, which specifies the use of anti-aliasing.

Definition at line 3477 of file PlotBox.java.

                                                         {
        RenderingHints hints = new RenderingHints(null);
        hints.put(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        return hints;
    }

Here is the caller graph for this function:

int ptolemy.plot.PlotBox._drawLegend ( Graphics  graphics,
int  urx,
int  ury 
) [inline, private]

Definition at line 2993 of file PlotBox.java.

                                                                 {
        // Ignore if there is no graphics object to draw on.
        if (graphics == null) {
            return 0;
        }

        // FIXME: consolidate all these for efficiency
        Font previousFont = graphics.getFont();
        graphics.setFont(_labelFont);

        int spacing = _labelFontMetrics.getHeight();

        Enumeration v = _legendStrings.elements();
        Enumeration i = _legendDatasets.elements();
        int ypos = ury + spacing;
        int maxwidth = 0;

        while (v.hasMoreElements()) {
            String legend = (String) v.nextElement();

            // NOTE: relies on _legendDatasets having the same num. of entries.
            int dataset = ((Integer) i.nextElement()).intValue();

            if (dataset >= 0) {
                if (_usecolor) {
                    // Points are only distinguished up to the number of colors
                    int color = dataset % _colors.length;
                    graphics.setColor(_colors[color]);
                }

                _drawPoint(graphics, dataset, urx - 3, ypos - 3, false);

                graphics.setColor(_foreground);

                int width = _labelFontMetrics.stringWidth(legend);

                if (width > maxwidth) {
                    maxwidth = width;
                }

                graphics.drawString(legend, urx - 15 - width, ypos);
                ypos += spacing;
            }
        }

        graphics.setFont(previousFont);
        return 22 + maxwidth; // NOTE: subjective spacing parameter.
    }

Here is the call graph for this function:

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox._drawPlot ( Graphics  graphics,
boolean  clearfirst 
) [inline, protected]

Draw the axes using the current range, label, and title information.

If the second argument is true, clear the display before redrawing. This method is called by paintComponent(). To cause it to be called you would normally call repaint(), which eventually causes paintComponent() to be called.

Note that this is synchronized so that points are not added by other threads while the drawing is occurring. This method should be called only from the event dispatch thread, consistent with swing policy.

Parameters:
graphicsThe graphics context.
clearfirstIf true, clear the plot before proceeding.

Reimplemented in ptolemy.plot.Histogram.

Definition at line 1814 of file PlotBox.java.

                                                                                 {
        Rectangle bounds = getBounds();
        _drawPlot(graphics, clearfirst, bounds);
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox._drawPlot ( Graphics  graphics,
boolean  clearfirst,
Rectangle  drawRect 
) [inline, protected]

Draw the axes using the current range, label, and title information, at the size of the specified rectangle.

If the second argument is true, clear the display before redrawing. This method is called by paintComponent(). To cause it to be called you would normally call repaint(), which eventually causes paintComponent() to be called.

Note that this is synchronized so that points are not added by other threads while the drawing is occurring. This method should be called only from the event dispatch thread, consistent with swing policy.

Parameters:
graphicsThe graphics context.
clearfirstIf true, clear the plot before proceeding.
drawRectA specification of the size.

Reimplemented in ptolemy.plot.Plot.

Definition at line 1834 of file PlotBox.java.

                                                    {
        // Ignore if there is no graphics object to draw on.
        if (graphics == null) {
            return;
        }

        graphics.setPaintMode();

        /* NOTE: The following seems to be unnecessary with Swing...
         if (clearfirst) {
         // NOTE: calling clearRect() here permits the background
         // color to show through, but it messes up printing.
         // Printing results in black-on-black title and axis labels.
         graphics.setColor(_background);
         graphics.drawRect(0, 0, drawRect.width, drawRect.height);
         graphics.setColor(Color.black);
         }
         */

        // If an error message has been set, display it and return.
        if (_errorMsg != null) {
            int fheight = _labelFontMetrics.getHeight() + 2;
            int msgy = fheight;
            graphics.setColor(Color.black);

            for (int i = 0; i < _errorMsg.length; i++) {
                graphics.drawString(_errorMsg[i], 10, msgy);
                msgy += fheight;
                System.err.println(_errorMsg[i]);
            }

            return;
        }

        // Make sure we have an x and y range
        if (!_xRangeGiven) {
            if (_xBottom > _xTop) {
                // have nothing to go on.
                _setXRange(0, 0);
            } else {
                _setXRange(_xBottom, _xTop);
            }
        }

        if (!_yRangeGiven) {
            if (_yBottom > _yTop) {
                // have nothing to go on.
                _setYRange(0, 0);
            } else {
                _setYRange(_yBottom, _yTop);
            }
        }

        // If user specified a plot rectangle, compute
        // a working plot rectangle which lies inside the
        // drawRect at the user specified coordinates
        Rectangle workingPlotRectangle = null;

        if (_specifiedPlotRectangle != null) {
            workingPlotRectangle = new Rectangle(Math.max(0,
                    _specifiedPlotRectangle.x), Math.max(0,
                    _specifiedPlotRectangle.y), Math.min(drawRect.width,
                    _specifiedPlotRectangle.width), Math.min(drawRect.height,
                    _specifiedPlotRectangle.height));
        }

        // Vertical space for title, if appropriate.
        // NOTE: We assume a one-line title.
        int titley = 0;
        int titlefontheight = _titleFontMetrics.getHeight();

        if (_title == null) {
            // NOTE: If the _title is null, then set it to the empty
            // string to solve the problem where the fill button overlaps
            // the legend if there is no title.  The fix here would
            // be to modify the legend printing text so that it takes
            // into account the case where there is no title by offsetting
            // just enough for the button.
            _title = "";
        }

        if ((_title != null) || (_yExp != 0)) {
            titley = titlefontheight + _topPadding;
        }

        // Number of vertical tick marks depends on the height of the font
        // for labeling ticks and the height of the window.
        Font previousFont = graphics.getFont();
        graphics.setFont(_labelFont);
        graphics.setColor(_foreground); // foreground color not set here  --Rob.

        int labelheight = _labelFontMetrics.getHeight();
        int halflabelheight = labelheight / 2;

        // Draw scaling annotation for x axis.
        // NOTE: 5 pixel padding on bottom.
        int ySPos = drawRect.height - 5;
        int xSPos = drawRect.width - _rightPadding;

        if (_xlog) {
            _xExp = (int) Math.floor(_xtickMin);
        }

        if ((_xExp != 0) && (_xticks == null)) {
            String superscript = Integer.toString(_xExp);
            xSPos -= _superscriptFontMetrics.stringWidth(superscript);
            graphics.setFont(_superscriptFont);

            if (!_xlog) {
                graphics
                        .drawString(superscript, xSPos, ySPos - halflabelheight);
                xSPos -= _labelFontMetrics.stringWidth("x10");
                graphics.setFont(_labelFont);
                graphics.drawString("x10", xSPos, ySPos);
            }

            // NOTE: 5 pixel padding on bottom
            _bottomPadding = ((3 * labelheight) / 2) + 5;
        }

        // NOTE: 5 pixel padding on the bottom.
        if ((_xlabel != null) && (_bottomPadding < (labelheight + 5))) {
            _bottomPadding = labelheight + 5;
        }

        // Compute the space needed around the plot, starting with vertical.
        // NOTE: padding of 5 pixels below title.
        if (workingPlotRectangle != null) {
            _uly = workingPlotRectangle.y;
        } else {
            _uly = titley + 5;
        }

        // NOTE: 3 pixels above bottom labels.
        if (workingPlotRectangle != null) {
            _lry = workingPlotRectangle.y + workingPlotRectangle.height;
        } else {
            _lry = drawRect.height - labelheight - _bottomPadding - 3;
        }

        int height = _lry - _uly;
        _yscale = height / (_yMax - _yMin);
        _ytickscale = height / (_ytickMax - _ytickMin);

        // Number of y tick marks.
        // NOTE: subjective spacing factor.
        int ny = 2 + (height / (labelheight + 10));

        // Compute y increment.
        double yStep = _roundUp((_ytickMax - _ytickMin) / ny);

        // Compute y starting point so it is a multiple of yStep.
        double yStart = yStep * Math.ceil(_ytickMin / yStep);

        // NOTE: Following disables first tick.  Not a good idea?
        // if (yStart == _ytickMin) yStart += yStep;
        // Define the strings that will label the y axis.
        // Meanwhile, find the width of the widest label.
        // The labels are quantized so that they don't have excess resolution.
        int widesty = 0;

        // These do not get used unless ticks are automatic, but the
        // compiler is not smart enough to allow us to reference them
        // in two distinct conditional clauses unless they are
        // allocated outside the clauses.
        String[] ylabels = new String[ny];
        int[] ylabwidth = new int[ny];

        int ind = 0;

        if (_yticks == null) {
            Vector ygrid = null;

            if (_ylog) {
                ygrid = _gridInit(yStart, yStep, true, null);
            }

            // automatic ticks
            // First, figure out how many digits after the decimal point
            // will be used.
            int numfracdigits = _numFracDigits(yStep);

            // NOTE: Test cases kept in case they are needed again.
            // System.out.println("0.1 with 3 digits: " + _formatNum(0.1, 3));
            // System.out.println("0.0995 with 3 digits: " +
            //                    _formatNum(0.0995, 3));
            // System.out.println("0.9995 with 3 digits: " +
            //                    _formatNum(0.9995, 3));
            // System.out.println("1.9995 with 0 digits: " +
            //                    _formatNum(1.9995, 0));
            // System.out.println("1 with 3 digits: " + _formatNum(1, 3));
            // System.out.println("10 with 0 digits: " + _formatNum(10, 0));
            // System.out.println("997 with 3 digits: " + _formatNum(997, 3));
            // System.out.println("0.005 needs: " + _numFracDigits(0.005));
            // System.out.println("1 needs: " + _numFracDigits(1));
            // System.out.println("999 needs: " + _numFracDigits(999));
            // System.out.println("999.0001 needs: "+_numFracDigits(999.0001));
            // System.out.println("0.005 integer digits: " +
            //                    _numIntDigits(0.005));
            // System.out.println("1 integer digits: " + _numIntDigits(1));
            // System.out.println("999 integer digits: " + _numIntDigits(999));
            // System.out.println("-999.0001 integer digits: " +
            //                    _numIntDigits(999.0001));
            double yTmpStart = yStart;

            if (_ylog) {
                yTmpStart = _gridStep(ygrid, yStart, yStep, _ylog);
            }

            for (double ypos = yTmpStart; ypos <= _ytickMax; ypos = _gridStep(
                    ygrid, ypos, yStep, _ylog)) {
                // Prevent out of bounds exceptions
                if (ind >= ny) {
                    break;
                }

                String yticklabel;

                if (_ylog) {
                    yticklabel = _formatLogNum(ypos, numfracdigits);
                } else {
                    yticklabel = _formatNum(ypos, numfracdigits);
                }

                ylabels[ind] = yticklabel;

                int lw = _labelFontMetrics.stringWidth(yticklabel);
                ylabwidth[ind++] = lw;

                if (lw > widesty) {
                    widesty = lw;
                }
            }
        } else {
            // explicitly specified ticks
            Enumeration nl = _yticklabels.elements();

            while (nl.hasMoreElements()) {
                String label = (String) nl.nextElement();
                int lw = _labelFontMetrics.stringWidth(label);

                if (lw > widesty) {
                    widesty = lw;
                }
            }
        }

        // Next we do the horizontal spacing.
        if (workingPlotRectangle != null) {
            _ulx = workingPlotRectangle.x;
        } else {
            if (_ylabel != null) {
                _ulx = widesty + _labelFontMetrics.stringWidth("W")
                        + _leftPadding;
            } else {
                _ulx = widesty + _leftPadding;
            }
        }

        int legendwidth = _drawLegend(graphics, drawRect.width - _rightPadding,
                _uly);

        if (workingPlotRectangle != null) {
            _lrx = workingPlotRectangle.x + workingPlotRectangle.width;
        } else {
            _lrx = drawRect.width - legendwidth - _rightPadding;
        }

        int width = _lrx - _ulx;
        _xscale = width / (_xMax - _xMin);

        _xtickscale = width / (_xtickMax - _xtickMin);

        // Background for the plotting rectangle.
        // Always use a white background because the dataset colors
        // were designed for a white background.
        graphics.setColor(Color.white);
        graphics.fillRect(_ulx, _uly, width, height);

        graphics.setColor(_foreground);
        graphics.drawRect(_ulx, _uly, width, height);

        // NOTE: subjective tick length.
        int tickLength = 5;
        int xCoord1 = _ulx + tickLength;
        int xCoord2 = _lrx - tickLength;

        if (_yticks == null) {
            // auto-ticks
            Vector ygrid = null;
            double yTmpStart = yStart;

            if (_ylog) {
                ygrid = _gridInit(yStart, yStep, true, null);
                yTmpStart = _gridStep(ygrid, yStart, yStep, _ylog);
                ny = ind;
            }

            ind = 0;

            // Set to false if we don't need the exponent
            boolean needExponent = _ylog;

            for (double ypos = yTmpStart; ypos <= _ytickMax; ypos = _gridStep(
                    ygrid, ypos, yStep, _ylog)) {
                // Prevent out of bounds exceptions
                if (ind >= ny) {
                    break;
                }

                int yCoord1 = _lry - (int) ((ypos - _ytickMin) * _ytickscale);

                // The lowest label is shifted up slightly to avoid
                // colliding with x labels.
                int offset = 0;

                if ((ind > 0) && !_ylog) {
                    offset = halflabelheight;
                }

                graphics.drawLine(_ulx, yCoord1, xCoord1, yCoord1);
                graphics.drawLine(_lrx, yCoord1, xCoord2, yCoord1);

                if (_grid && (yCoord1 != _uly) && (yCoord1 != _lry)) {
                    graphics.setColor(Color.lightGray);
                    graphics.drawLine(xCoord1, yCoord1, xCoord2, yCoord1);
                    graphics.setColor(_foreground);
                }

                // Check to see if any of the labels printed contain
                // the exponent.  If we don't see an exponent, then print it.
                if (_ylog && (ylabels[ind].indexOf('e') != -1)) {
                    needExponent = false;
                }

                // NOTE: 4 pixel spacing between axis and labels.
                graphics.drawString(ylabels[ind], _ulx - ylabwidth[ind++] - 4,
                        yCoord1 + offset);
            }

            if (_ylog) {
                // Draw in grid lines that don't have labels.
                Vector unlabeledgrid = _gridInit(yStart, yStep, false, ygrid);

                if (unlabeledgrid.size() > 0) {
                    // If the step is greater than 1, clamp it to 1 so that
                    // we draw the unlabeled grid lines for each
                    //integer interval.
                    double tmpStep = (yStep > 1.0) ? 1.0 : yStep;

                    for (double ypos = _gridStep(unlabeledgrid, yStart,
                            tmpStep, _ylog); ypos <= _ytickMax; ypos = _gridStep(
                            unlabeledgrid, ypos, tmpStep, _ylog)) {
                        int yCoord1 = _lry
                                - (int) ((ypos - _ytickMin) * _ytickscale);

                        if (_grid && (yCoord1 != _uly) && (yCoord1 != _lry)) {
                            graphics.setColor(Color.lightGray);
                            graphics.drawLine(_ulx + 1, yCoord1, _lrx - 1,
                                    yCoord1);
                            graphics.setColor(_foreground);
                        }
                    }
                }

                if (needExponent) {
                    // We zoomed in, so we need the exponent
                    _yExp = (int) Math.floor(yTmpStart);
                } else {
                    _yExp = 0;
                }
            }

            // Draw scaling annotation for y axis.
            if (_yExp != 0) {
                graphics.drawString("x10", 2, titley);
                graphics.setFont(_superscriptFont);
                graphics.drawString(Integer.toString(_yExp), _labelFontMetrics
                        .stringWidth("x10") + 2, titley - halflabelheight);
                graphics.setFont(_labelFont);
            }
        } else {
            // ticks have been explicitly specified
            Enumeration nt = _yticks.elements();
            Enumeration nl = _yticklabels.elements();

            while (nl.hasMoreElements()) {
                String label = (String) nl.nextElement();
                double ypos = ((Double) (nt.nextElement())).doubleValue();

                if ((ypos > _yMax) || (ypos < _yMin)) {
                    continue;
                }

                int yCoord1 = _lry - (int) ((ypos - _yMin) * _yscale);
                int offset = 0;

                if (ypos < (_lry - labelheight)) {
                    offset = halflabelheight;
                }

                graphics.drawLine(_ulx, yCoord1, xCoord1, yCoord1);
                graphics.drawLine(_lrx, yCoord1, xCoord2, yCoord1);

                if (_grid && (yCoord1 != _uly) && (yCoord1 != _lry)) {
                    graphics.setColor(Color.lightGray);
                    graphics.drawLine(xCoord1, yCoord1, xCoord2, yCoord1);
                    graphics.setColor(_foreground);
                }

                // NOTE: 3 pixel spacing between axis and labels.
                graphics.drawString(label, _ulx
                        - _labelFontMetrics.stringWidth(label) - 3, yCoord1
                        + offset);
            }
        }

        int yCoord1 = _uly + tickLength;
        int yCoord2 = _lry - tickLength;
        int charwidth = _labelFontMetrics.stringWidth("8");

        if (_xticks == null) {
            // auto-ticks
            // Number of x tick marks.
            // Need to start with a guess and converge on a solution here.
            int nx = 10;
            double xStep = 0.0;
            int numfracdigits = 0;

            if (_xlog) {
                // X axes log labels will be at most 6 chars: -1E-02
                nx = 2 + (width / ((charwidth * 6) + 10));
            } else {
                // Limit to 10 iterations
                int count = 0;

                while (count++ <= 10) {
                    xStep = _roundUp((_xtickMax - _xtickMin) / nx);

                    // Compute the width of a label for this xStep
                    numfracdigits = _numFracDigits(xStep);

                    // Number of integer digits is the maximum of two endpoints
                    int intdigits = _numIntDigits(_xtickMax);
                    int inttemp = _numIntDigits(_xtickMin);

                    if (intdigits < inttemp) {
                        intdigits = inttemp;
                    }

                    // Allow two extra digits (decimal point and sign).
                    int maxlabelwidth = charwidth
                            * (numfracdigits + 2 + intdigits);

                    // Compute new estimate of number of ticks.
                    int savenx = nx;

                    // NOTE: 10 additional pixels between labels.
                    // NOTE: Try to ensure at least two tick marks.
                    nx = 2 + (width / (maxlabelwidth + 10));

                    if (((nx - savenx) <= 1) || ((savenx - nx) <= 1)) {
                        break;
                    }
                }
            }

            xStep = _roundUp((_xtickMax - _xtickMin) / nx);
            numfracdigits = _numFracDigits(xStep);

            // Compute x starting point so it is a multiple of xStep.
            double xStart = xStep * Math.ceil(_xtickMin / xStep);

            // NOTE: Following disables first tick.  Not a good idea?
            // if (xStart == _xMin) xStart += xStep;
            Vector xgrid = null;
            double xTmpStart = xStart;

            if (_xlog) {
                xgrid = _gridInit(xStart, xStep, true, null);

                //xgrid = _gridInit(xStart, xStep);
                xTmpStart = _gridRoundUp(xgrid, xStart);
            }

            // Set to false if we don't need the exponent
            boolean needExponent = _xlog;

            // Label the x axis.  The labels are quantized so that
            // they don't have excess resolution.
            for (double xpos = xTmpStart; xpos <= _xtickMax; xpos = _gridStep(
                    xgrid, xpos, xStep, _xlog)) {
                String xticklabel;

                if (_xlog) {
                    xticklabel = _formatLogNum(xpos, numfracdigits);

                    if (xticklabel.indexOf('e') != -1) {
                        needExponent = false;
                    }
                } else {
                    xticklabel = _formatNum(xpos, numfracdigits);
                }

                xCoord1 = _ulx + (int) ((xpos - _xtickMin) * _xtickscale);
                graphics.drawLine(xCoord1, _uly, xCoord1, yCoord1);
                graphics.drawLine(xCoord1, _lry, xCoord1, yCoord2);

                if (_grid && (xCoord1 != _ulx) && (xCoord1 != _lrx)) {
                    graphics.setColor(Color.lightGray);
                    graphics.drawLine(xCoord1, yCoord1, xCoord1, yCoord2);
                    graphics.setColor(_foreground);
                }

                int labxpos = xCoord1
                        - (_labelFontMetrics.stringWidth(xticklabel) / 2);

                // NOTE: 3 pixel spacing between axis and labels.
                graphics
                        .drawString(xticklabel, labxpos, _lry + 3 + labelheight);
            }

            if (_xlog) {
                // Draw in grid lines that don't have labels.
                // If the step is greater than 1, clamp it to 1 so that
                // we draw the unlabeled grid lines for each
                // integer interval.
                double tmpStep = (xStep > 1.0) ? 1.0 : xStep;

                // Recalculate the start using the new step.
                xTmpStart = tmpStep * Math.ceil(_xtickMin / tmpStep);

                Vector unlabeledgrid = _gridInit(xTmpStart, tmpStep, false,
                        xgrid);

                if (unlabeledgrid.size() > 0) {
                    for (double xpos = _gridStep(unlabeledgrid, xTmpStart,
                            tmpStep, _xlog); xpos <= _xtickMax; xpos = _gridStep(
                            unlabeledgrid, xpos, tmpStep, _xlog)) {
                        xCoord1 = _ulx
                                + (int) ((xpos - _xtickMin) * _xtickscale);

                        if (_grid && (xCoord1 != _ulx) && (xCoord1 != _lrx)) {
                            graphics.setColor(Color.lightGray);
                            graphics.drawLine(xCoord1, _uly + 1, xCoord1,
                                    _lry - 1);
                            graphics.setColor(_foreground);
                        }
                    }
                }

                if (needExponent) {
                    _xExp = (int) Math.floor(xTmpStart);
                    graphics.setFont(_superscriptFont);
                    graphics.drawString(Integer.toString(_xExp), xSPos, ySPos
                            - halflabelheight);
                    xSPos -= _labelFontMetrics.stringWidth("x10");
                    graphics.setFont(_labelFont);
                    graphics.drawString("x10", xSPos, ySPos);
                } else {
                    _xExp = 0;
                }
            }
        } else {
            // ticks have been explicitly specified
            Enumeration nt = _xticks.elements();
            Enumeration nl = _xticklabels.elements();

            // Code contributed by Jun Wu (jwu@inin.com.au)
            double preLength = 0.0;

            while (nl.hasMoreElements()) {
                String label = (String) nl.nextElement();
                double xpos = ((Double) (nt.nextElement())).doubleValue();

                // If xpos is out of range, ignore.
                if ((xpos > _xMax) || (xpos < _xMin)) {
                    continue;
                }

                // Find the center position of the label.
                xCoord1 = _ulx + (int) ((xpos - _xMin) * _xscale);

                // Find  the start position of x label.
                int labxpos = xCoord1
                        - (_labelFontMetrics.stringWidth(label) / 2);

                // If the labels are not overlapped, proceed.
                if (labxpos > preLength) {
                    // calculate the length of the label
                    preLength = xCoord1
                            + (_labelFontMetrics.stringWidth(label) / 2) + 10;

                    // Draw the label.
                    // NOTE: 3 pixel spacing between axis and labels.
                    graphics.drawString(label, labxpos, _lry + 3 + labelheight);

                    // Draw the label mark on the axis
                    graphics.drawLine(xCoord1, _uly, xCoord1, yCoord1);
                    graphics.drawLine(xCoord1, _lry, xCoord1, yCoord2);

                    // Draw the grid line
                    if (_grid && (xCoord1 != _ulx) && (xCoord1 != _lrx)) {
                        graphics.setColor(Color.lightGray);
                        graphics.drawLine(xCoord1, yCoord1, xCoord1, yCoord2);
                        graphics.setColor(_foreground);
                    }
                }
            }
        }

        // Center the title and X label over the plotting region, not
        // the window.
        graphics.setColor(_foreground);

        if (_title != null) {
            graphics.setFont(_titleFont);

            int titlex = _ulx
                    + ((width - _titleFontMetrics.stringWidth(_title)) / 2);
            graphics.drawString(_title, titlex, titley);
        }

        graphics.setFont(_labelFont);

        if (_xlabel != null) {
            int labelx = _ulx
                    + ((width - _labelFontMetrics.stringWidth(_xlabel)) / 2);
            graphics.drawString(_xlabel, labelx, ySPos);
        }

        int charcenter = 2 + (_labelFontMetrics.stringWidth("W") / 2);

        if (_ylabel != null) {
            int yl = _ylabel.length();

            if (graphics instanceof Graphics2D) {
                int starty = (_uly + ((_lry - _uly) / 2) + (_labelFontMetrics
                        .stringWidth(_ylabel) / 2))
                        - charwidth;
                Graphics2D g2d = (Graphics2D) graphics;

                // NOTE: Fudge factor so label doesn't touch axis labels.
                int startx = (charcenter + halflabelheight) - 2;
                g2d.rotate(Math.toRadians(-90), startx, starty);
                g2d.drawString(_ylabel, startx, starty);
                g2d.rotate(Math.toRadians(90), startx, starty);
            } else {
                // Not graphics 2D, no support for rotation.
                // Vertical label is fairly complex to draw.
                int starty = (_uly + ((_lry - _uly) / 2))
                        - (yl * halflabelheight) + labelheight;

                for (int i = 0; i < yl; i++) {
                    String nchar = _ylabel.substring(i, i + 1);
                    int cwidth = _labelFontMetrics.stringWidth(nchar);
                    graphics.drawString(nchar, charcenter - (cwidth / 2),
                            starty);
                    starty += labelheight;
                }
            }
        }

        graphics.setFont(previousFont);
    }

Here is the call graph for this function:

void ptolemy.plot.PlotBox._drawPoint ( Graphics  graphics,
int  dataset,
long  xpos,
long  ypos,
boolean  clip 
) [inline, protected]

Put a mark corresponding to the specified dataset at the specified x and y position.

The mark is drawn in the current color. In this base class, a point is a filled rectangle 6 pixels across. Note that marks greater than about 6 pixels in size will not look very good since they will overlap axis labels and may not fit well in the legend. The clip argument, if true, states that the point should not be drawn if it is out of range.

Note that this method is not synchronized, so the caller should be. Moreover this method should always be called from the event thread when being used to write to the screen.

Parameters:
graphicsThe graphics context.
datasetThe index of the data set.
xposThe X position.
yposThe Y position.
clipIf true, do not draw if out of range.

Reimplemented in ptolemy.plot.Plot.

Definition at line 2524 of file PlotBox.java.

                                     {
        // Ignore if there is no graphics object to draw on.
        if (graphics == null) {
            return;
        }

        boolean pointinside = (ypos <= _lry) && (ypos >= _uly)
                && (xpos <= _lrx) && (xpos >= _ulx);

        if (!pointinside && clip) {
            return;
        }

        graphics.fillRect((int) xpos - 6, (int) ypos - 6, 6, 6);
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox._executeDeferredActions ( ) [inline, private]

Definition at line 3049 of file PlotBox.java.

                                                        {
        try {
            Iterator actions = _deferredActions.iterator();

            while (actions.hasNext()) {
                Runnable action = (Runnable) actions.next();
                action.run();
            }
        } finally {
            _actionsDeferred = false;
            _deferredActions.clear();
        }
    }

Here is the caller graph for this function:

String ptolemy.plot.PlotBox._formatLogNum ( double  num,
int  numfracdigits 
) [inline, private]

Definition at line 3072 of file PlotBox.java.

                                                                {
        String results;
        int exponent = (int) num;

        // Determine the exponent, prepending 0 or -0 if necessary.
        if ((exponent >= 0) && (exponent < 10)) {
            results = "0" + exponent;
        } else {
            if ((exponent < 0) && (exponent > -10)) {
                results = "-0" + (-exponent);
            } else {
                results = Integer.toString(exponent);
            }
        }

        // Handle the mantissa.
        if (num >= 0.0) {
            if ((num - (int) (num)) < 0.001) {
                results = "1e" + results;
            } else {
                results = _formatNum(Math.pow(10.0, (num - (int) num)),
                        numfracdigits);
            }
        } else {
            if ((-num - (int) (-num)) < 0.001) {
                results = "1e" + results;
            } else {
                results = _formatNum(Math.pow(10.0, (num - (int) num)) * 10,
                        numfracdigits);
            }
        }

        return results;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

String ptolemy.plot.PlotBox._formatNum ( double  num,
int  numfracdigits 
) [inline, private]

Definition at line 3115 of file PlotBox.java.

                                                             {
        // When java.text.NumberFormat works under Netscape,
        // uncomment the next block of code and remove
        // the code after it.
        // Ptplot developers at UCB can access a test case at:
        // http://ptolemy.eecs.berkeley.edu/~ptII/ptIItree/ptolemy/plot/adm/trunc/trunc-jdk11.html
        // The plot will show two 0.7 values on the x axis if the bug
        // continues to exist.
        //if (_numberFormat == null) {
        //   // Cache the number format so that we don't have to get
        //    // info about local language etc. from the OS each time.
        //    _numberFormat = NumberFormat.getInstance();
        //}
        //_numberFormat.setMinimumFractionDigits(numfracdigits);
        //_numberFormat.setMaximumFractionDigits(numfracdigits);
        //return _numberFormat.format(num);
        // The section below is from Ptplot1.3
        // First, round the number.
        double fudge = 0.5;

        if (num < 0.0) {
            fudge = -0.5;
        }

        String numString = Double.toString(num
                + (fudge * Math.pow(10.0, -numfracdigits)));

        // Next, find the decimal point.
        int dpt = numString.lastIndexOf(".");
        StringBuffer result = new StringBuffer();

        if (dpt < 0) {
            // The number we are given is an integer.
            if (numfracdigits <= 0) {
                // The desired result is an integer.
                result.append(numString);
                return result.toString();
            }

            // Append a decimal point and some zeros.
            result.append(".");

            for (int i = 0; i < numfracdigits; i++) {
                result.append("0");
            }

            return result.toString();
        } else {
            // There are two cases.  First, there may be enough digits.
            int shortby = numfracdigits - (numString.length() - dpt - 1);

            if (shortby <= 0) {
                int numtocopy = dpt + numfracdigits + 1;

                if (numfracdigits == 0) {
                    // Avoid copying over a trailing decimal point.
                    numtocopy -= 1;
                }

                result.append(numString.substring(0, numtocopy));
                return result.toString();
            } else {
                result.append(numString);

                for (int i = 0; i < shortby; i++) {
                    result.append("0");
                }

                return result.toString();
            }
        }
    }

Here is the caller graph for this function:

Vector ptolemy.plot.PlotBox._gridInit ( double  low,
double  step,
boolean  labeled,
Vector  oldgrid 
) [inline, private]

Definition at line 3192 of file PlotBox.java.

                            {
        // How log axes work:
        // _gridInit() creates a vector with the values to use for the
        // log axes.  For example, the vector might contain
        // {0.0 0.301 0.698}, which could correspond to
        // axis labels {1 1.2 1.5 10 12 15 100 120 150}
        //
        // _gridStep() gets the proper value.  _gridInit is cycled through
        // for each integer log value.
        //
        // Bugs in log axes:
        // * Sometimes not enough grid lines are displayed because the
        // region is small.  This bug is present in the oriignal xgraph
        // binary, which is the basis of this code.  The problem is that
        // as ratio gets closer to 1.0, we need to add more and more
        // grid marks.
        Vector grid = new Vector(10);

        //grid.addElement(Double.valueOf(0.0));
        double ratio = Math.pow(10.0, step);
        int ngrid = 1;

        if (labeled) {
            // Set up the number of grid lines that will be labeled
            if (ratio <= 3.5) {
                if (ratio > 2.0) {
                    ngrid = 2;
                } else if (ratio > 1.26) {
                    ngrid = 5;
                } else if (ratio > 1.125) {
                    ngrid = 10;
                } else {
                    ngrid = (int) Math.rint(1.0 / step);
                }
            }
        } else {
            // Set up the number of grid lines that will not be labeled
            if (ratio > 10.0) {
                ngrid = 1;
            } else if (ratio > 3.0) {
                ngrid = 2;
            } else if (ratio > 2.0) {
                ngrid = 5;
            } else if (ratio > 1.125) {
                ngrid = 10;
            } else {
                ngrid = 100;
            }

            // Note: we should keep going here, but this increases the
            // size of the grid array and slows everything down.
        }

        int oldgridi = 0;

        for (int i = 0; i < ngrid; i++) {
            double gridval = (i * 1.0) / ngrid * 10;
            double logval = _LOG10SCALE * Math.log(gridval);

            if (logval == Double.NEGATIVE_INFINITY) {
                logval = 0.0;
            }

            // If oldgrid is not null, then do not draw lines that
            // were already drawn in oldgrid.  This is necessary
            // so we avoid obliterating the tick marks on the plot borders.
            if ((oldgrid != null) && (oldgridi < oldgrid.size())) {
                // Cycle through the oldgrid until we find an element
                // that is equal to or greater than the element we are
                // trying to add.
                while ((oldgridi < oldgrid.size())
                        && (((Double) oldgrid.elementAt(oldgridi))
                                .doubleValue() < logval)) {
                    oldgridi++;
                }

                if (oldgridi < oldgrid.size()) {
                    // Using == on doubles is bad if the numbers are close,
                    // but not exactly equal.
                    if (Math.abs(((Double) oldgrid.elementAt(oldgridi))
                            .doubleValue()
                            - logval) > 0.00001) {
                        grid.addElement(Double.valueOf(logval));
                    }
                } else {
                    grid.addElement(Double.valueOf(logval));
                }
            } else {
                grid.addElement(Double.valueOf(logval));
            }
        }

        // _gridCurJuke and _gridBase are used in _gridStep();
        _gridCurJuke = 0;

        if (low == -0.0) {
            low = 0.0;
        }

        _gridBase = Math.floor(low);

        double x = low - _gridBase;

        // Set gridCurJuke so that the value in grid is greater than
        // or equal to x.  This sets us up to process the first point.
        for (_gridCurJuke = -1; ((_gridCurJuke + 1) < grid.size())
                && (x >= ((Double) grid.elementAt(_gridCurJuke + 1))
                        .doubleValue()); _gridCurJuke++) {
        }

        return grid;
    }

Here is the caller graph for this function:

double ptolemy.plot.PlotBox._gridRoundUp ( Vector  grid,
double  pos 
) [inline, private]

Definition at line 3309 of file PlotBox.java.

                                                         {
        double x = pos - Math.floor(pos);
        int i;

        for (i = 0; (i < grid.size())
                && (x >= ((Double) grid.elementAt(i)).doubleValue()); i++) {
        }

        if (i >= grid.size()) {
            return pos;
        } else {
            return Math.floor(pos) + ((Double) grid.elementAt(i)).doubleValue();
        }
    }

Here is the caller graph for this function:

double ptolemy.plot.PlotBox._gridStep ( Vector  grid,
double  pos,
double  step,
boolean  logflag 
) [inline, private]

Definition at line 3334 of file PlotBox.java.

                             {
        if (logflag) {
            if (++_gridCurJuke >= grid.size()) {
                _gridCurJuke = 0;
                _gridBase += Math.ceil(step);
            }

            if (_gridCurJuke >= grid.size()) {
                return pos + step;
            }

            return _gridBase
                    + ((Double) grid.elementAt(_gridCurJuke)).doubleValue();
        } else {
            return pos + step;
        }
    }

Here is the caller graph for this function:

void ptolemy.plot.PlotBox._help ( ) [inline, protected]

Display basic information in its own window.

Definition at line 2543 of file PlotBox.java.

                           {
        String message = "Ptolemy plot package\n"
                + "By: Edward A. Lee\n"
                + "and Christopher Brooks\n"
                + "Version "
                + PTPLOT_RELEASE
                + ", Build: $Id: PlotBox.java,v 1.283.4.3 2008/04/01 01:19:02 cxh Exp $\n\n"
                + "Key bindings:\n"
                + "   Cntrl-c:  copy plot to clipboard (EPS format), if permitted\n"
                + "   D: dump plot data to standard out\n"
                + "   E: export plot to standard out (EPS format)\n"
                + "   F: fill plot\n"
                + "   H or ?: print help message (this message)\n"
                + "   Cntrl-D or Q: quit\n" + "For more information, see\n"
                + "http://ptolemy.eecs.berkeley.edu/java/ptplot\n";
        JOptionPane.showMessageDialog(this, message,
                "Ptolemy Plot Help Window", JOptionPane.INFORMATION_MESSAGE);
    }

Here is the caller graph for this function:

void ptolemy.plot.PlotBox._measureFonts ( ) [inline, private]

Definition at line 3356 of file PlotBox.java.

                                 {
        // We only measure the fonts once, and we do it from addNotify().
        if (_labelFont == null) {
            _labelFont = new Font("Helvetica", Font.PLAIN, 12);
        }

        if (_superscriptFont == null) {
            _superscriptFont = new Font("Helvetica", Font.PLAIN, 9);
        }

        if (_titleFont == null) {
            _titleFont = new Font("Helvetica", Font.BOLD, 14);
        }

        _labelFontMetrics = getFontMetrics(_labelFont);
        _superscriptFontMetrics = getFontMetrics(_superscriptFont);
        _titleFontMetrics = getFontMetrics(_titleFont);
    }

Here is the caller graph for this function:

int ptolemy.plot.PlotBox._numFracDigits ( double  num) [inline, private]

Definition at line 3380 of file PlotBox.java.

                                           {
        int numdigits = 0;

        while ((numdigits <= 15) && (num != Math.floor(num))) {
            num *= 10.0;
            numdigits += 1;
        }

        return numdigits;
    }

Here is the caller graph for this function:

int ptolemy.plot.PlotBox._numIntDigits ( double  num) [inline, private]

Definition at line 3396 of file PlotBox.java.

                                          {
        int numdigits = 0;

        while ((numdigits <= 15) && ((int) num != 0.0)) {
            num /= 10.0;
            numdigits += 1;
        }

        return numdigits;
    }

Here is the caller graph for this function:

boolean ptolemy.plot.PlotBox._parseLine ( String  line) [inline, protected]

Parse a line that gives plotting information.

In this base class, only lines pertaining to the title and labels are processed. Everything else is ignored. Return true if the line is recognized. It is not synchronized, so its caller should be.

Parameters:
lineA line of text.

Reimplemented in ptolemy.plot.Plot, and ptolemy.plot.Histogram.

Definition at line 2568 of file PlotBox.java.

                                              {
        // If you modify this method, you should also modify write()
        // We convert the line to lower case so that the command
        // names are case insensitive.
        String lcLine = line.toLowerCase();

        if (lcLine.startsWith("#")) {
            // comment character
            return true;
        } else if (lcLine.startsWith("titletext:")) {
            setTitle((line.substring(10)).trim());
            return true;
        } else if (lcLine.startsWith("title:")) {
            // Tolerate alternative tag.
            setTitle((line.substring(6)).trim());
            return true;
        } else if (lcLine.startsWith("xlabel:")) {
            setXLabel((line.substring(7)).trim());
            return true;
        } else if (lcLine.startsWith("ylabel:")) {
            setYLabel((line.substring(7)).trim());
            return true;
        } else if (lcLine.startsWith("xrange:")) {
            int comma = line.indexOf(",", 7);

            if (comma > 0) {
                String min = (line.substring(7, comma)).trim();
                String max = (line.substring(comma + 1)).trim();

                try {
                    Double dmin = Double.valueOf(min);
                    Double dmax = Double.valueOf(max);
                    setXRange(dmin.doubleValue(), dmax.doubleValue());
                } catch (NumberFormatException e) {
                    // ignore if format is bogus.
                }
            }

            return true;
        } else if (lcLine.startsWith("yrange:")) {
            int comma = line.indexOf(",", 7);

            if (comma > 0) {
                String min = (line.substring(7, comma)).trim();
                String max = (line.substring(comma + 1)).trim();

                try {
                    Double dmin = Double.valueOf(min);
                    Double dmax = Double.valueOf(max);
                    setYRange(dmin.doubleValue(), dmax.doubleValue());
                } catch (NumberFormatException e) {
                    // ignore if format is bogus.
                }
            }

            return true;
        } else if (lcLine.startsWith("xticks:")) {
            // example:
            // XTicks "label" 0, "label" 1, "label" 3
            _parsePairs(line.substring(7), true);
            return true;
        } else if (lcLine.startsWith("yticks:")) {
            // example:
            // YTicks "label" 0, "label" 1, "label" 3
            _parsePairs(line.substring(7), false);
            return true;
        } else if (lcLine.startsWith("xlog:")) {
            if (lcLine.indexOf("off", 5) >= 0) {
                _xlog = false;
            } else {
                _xlog = true;
            }

            return true;
        } else if (lcLine.startsWith("ylog:")) {
            if (lcLine.indexOf("off", 5) >= 0) {
                _ylog = false;
            } else {
                _ylog = true;
            }

            return true;
        } else if (lcLine.startsWith("grid:")) {
            if (lcLine.indexOf("off", 5) >= 0) {
                _grid = false;
            } else {
                _grid = true;
            }

            return true;
        } else if (lcLine.startsWith("wrap:")) {
            if (lcLine.indexOf("off", 5) >= 0) {
                _wrap = false;
            } else {
                _wrap = true;
            }

            return true;
        } else if (lcLine.startsWith("color:")) {
            if (lcLine.indexOf("off", 6) >= 0) {
                _usecolor = false;
            } else {
                _usecolor = true;
            }

            return true;
        }

        return false;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotBox._parsePairs ( String  line,
boolean  xtick 
) [inline, private]

Definition at line 3415 of file PlotBox.java.

                                                         {
        // Clear current ticks first.
        if (xtick) {
            _xticks = null;
            _xticklabels = null;
        } else {
            _yticks = null;
            _yticklabels = null;
        }

        int start = 0;
        boolean cont = true;

        while (cont) {
            int comma = line.indexOf(",", start);
            String pair = null;

            if (comma > start) {
                pair = (line.substring(start, comma)).trim();
            } else {
                pair = (line.substring(start)).trim();
                cont = false;
            }

            int close = -1;
            int open = 0;

            if (pair.startsWith("\"")) {
                close = pair.indexOf("\"", 1);
                open = 1;
            } else {
                close = pair.indexOf(" ");
            }

            if (close > 0) {
                String label = pair.substring(open, close);
                String index = (pair.substring(close + 1)).trim();

                try {
                    double idx = (Double.valueOf(index)).doubleValue();

                    if (xtick) {
                        addXTick(label, idx);
                    } else {
                        addYTick(label, idx);
                    }
                } catch (NumberFormatException e) {
                    System.err.println("Warning from PlotBox: "
                            + "Unable to parse ticks: " + e.getMessage());

                    // ignore if format is bogus.
                }
            }

            start = comma + 1;
            comma = line.indexOf(",", start);
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

double ptolemy.plot.PlotBox._roundUp ( double  val) [inline, private]

Definition at line 3490 of file PlotBox.java.

                                        {
        int exponent = (int) Math.floor(Math.log(val) * _LOG10SCALE);
        val *= Math.pow(10, -exponent);

        if (val > 5.0) {
            val = 10.0;
        } else if (val > 2.0) {
            val = 5.0;
        } else if (val > 1.0) {
            val = 2.0;
        }

        val *= Math.pow(10, exponent);
        return val;
    }

Here is the caller graph for this function:

void ptolemy.plot.PlotBox._setButtonsVisibility ( boolean  vis) [inline, protected]

Set the visibility of the Fill button.

This is deprecated. Use setButtons().

Deprecated:

Definition at line 2683 of file PlotBox.java.

                                                      {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _printButton.setVisible(vis);
        _fillButton.setVisible(vis);
        _formatButton.setVisible(vis);
        _resetButton.setVisible(vis);
    }
void ptolemy.plot.PlotBox._setPadding ( double  padding) [inline, protected]

Set the padding multiple.

The plot rectangle can be "padded" in each direction -x, +x, -y, and +y. If the padding is set to 0.05 (and the padding is used), then there is 10% more length on each axis than set by the setXRange() and setYRange() methods, 5% in each direction.

Parameters:
paddingThe padding multiple.

Definition at line 2700 of file PlotBox.java.

                                               {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _padding = padding;
    }
void ptolemy.plot.PlotBox._setXRange ( double  min,
double  max 
) [inline, private]

Definition at line 3510 of file PlotBox.java.

                                                    {
        // We check to see if the original range has been given here
        // because if we check in setXRange(), then we will not catch
        // the case where we have a simple plot file that consists of just
        // data points
        //
        // 1. Create a file that consists of two data points
        //   1 1
        //   2 3
        // 2. Start up plot on it
        // $PTII/bin/ptplot foo.plt
        // 3. Zoom in
        // 4. Hit reset axes
        // 5. The bug is that the axes do not reset to the initial settings
        // Changing the range means we have to replot.
        _plotImage = null;

        if (!_originalXRangeGiven) {
            _originalXlow = min;
            _originalXhigh = max;
            _originalXRangeGiven = true;
        }

        // If values are invalid, try for something reasonable.
        if (min > max) {
            min = -1.0;
            max = 1.0;
        } else if (min == max) {
            min -= 1.0;
            max += 1.0;
        }

        //if (_xRangeGiven) {
        // The user specified the range, so don't pad.
        //    _xMin = min;
        //    _xMax = max;
        //} else {
        // Pad slightly so that we don't plot points on the axes.
        _xMin = min - ((max - min) * _padding);
        _xMax = max + ((max - min) * _padding);

        //}
        // Find the exponent.
        double largest = Math.max(Math.abs(_xMin), Math.abs(_xMax));
        _xExp = (int) Math.floor(Math.log(largest) * _LOG10SCALE);

        // Use the exponent only if it's larger than 2 in magnitude.
        if ((_xExp > 2) || (_xExp < -2)) {
            double xs = 1.0 / Math.pow(10.0, _xExp);
            _xtickMin = _xMin * xs;
            _xtickMax = _xMax * xs;
        } else {
            _xtickMin = _xMin;
            _xtickMax = _xMax;
            _xExp = 0;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotBox._setYRange ( double  min,
double  max 
) [inline, private]

Definition at line 3572 of file PlotBox.java.

                                                    {
        // See comment in _setXRange() about why this is necessary.
        // Changing the range means we have to replot.
        _plotImage = null;

        if (!_originalYRangeGiven) {
            _originalYlow = min;
            _originalYhigh = max;
            _originalYRangeGiven = true;
        }

        // If values are invalid, try for something reasonable.
        if (min > max) {
            min = -1.0;
            max = 1.0;
        } else if (min == max) {
            min -= 0.1;
            max += 0.1;
        }

        //if (_yRangeGiven) {
        // The user specified the range, so don't pad.
        //    _yMin = min;
        //    _yMax = max;
        //} else {
        // Pad slightly so that we don't plot points on the axes.
        _yMin = min - ((max - min) * _padding);
        _yMax = max + ((max - min) * _padding);

        //}
        // Find the exponent.
        double largest = Math.max(Math.abs(_yMin), Math.abs(_yMax));
        _yExp = (int) Math.floor(Math.log(largest) * _LOG10SCALE);

        // Use the exponent only if it's larger than 2 in magnitude.
        if ((_yExp > 2) || (_yExp < -2)) {
            double ys = 1.0 / Math.pow(10.0, _yExp);
            _ytickMin = _yMin * ys;
            _ytickMax = _yMax * ys;
        } else {
            _ytickMin = _yMin;
            _ytickMax = _yMax;
            _yExp = 0;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotBox._writeOldSyntax ( PrintWriter  output) [inline, protected]

Write plot information to the specified output stream in the old PtPlot syntax.

Derived classes should override this method to first call the parent class method, then add whatever additional information they wish to add to the stream. It is not synchronized, so its caller should be.

Parameters:
outputA buffered print writer.
Deprecated:

Reimplemented in ptolemy.plot.Plot.

Definition at line 2716 of file PlotBox.java.

                                                       {
        output.println("# Ptolemy plot, version 2.0");

        if (_title != null) {
            output.println("TitleText: " + _title);
        }

        if (_xlabel != null) {
            output.println("XLabel: " + _xlabel);
        }

        if (_ylabel != null) {
            output.println("YLabel: " + _ylabel);
        }

        if (_xRangeGiven) {
            output.println("XRange: " + _xlowgiven + ", " + _xhighgiven);
        }

        if (_yRangeGiven) {
            output.println("YRange: " + _ylowgiven + ", " + _yhighgiven);
        }

        if ((_xticks != null) && (_xticks.size() > 0)) {
            output.print("XTicks: ");

            int last = _xticks.size() - 1;

            for (int i = 0; i < last; i++) {
                output.print("\"" + (String) _xticklabels.elementAt(i) + "\" "
                        + _xticks.elementAt(i) + ", ");
            }

            output.println("\"" + (String) _xticklabels.elementAt(last) + "\" "
                    + _xticks.elementAt(last));
        }

        if ((_yticks != null) && (_yticks.size() > 0)) {
            output.print("YTicks: ");

            int last = _yticks.size() - 1;

            for (int i = 0; i < last; i++) {
                output.print("\"" + (String) _yticklabels.elementAt(i) + "\" "
                        + _yticks.elementAt(i) + ", ");
            }

            output.println("\"" + (String) _yticklabels.elementAt(last) + "\" "
                    + _yticks.elementAt(last));
        }

        if (_xlog) {
            output.println("XLog: on");
        }

        if (_ylog) {
            output.println("YLog: on");
        }

        if (!_grid) {
            output.println("Grid: off");
        }

        if (_wrap) {
            output.println("Wrap: on");
        }

        if (!_usecolor) {
            output.println("Color: off");
        }
    }

Here is the caller graph for this function:

void ptolemy.plot.PlotBox._zoom ( int  x,
int  y 
) [inline, package]

Definition at line 3626 of file PlotBox.java.

                             {
        // FIXME: This is friendly because Netscape 4.0.3 cannot access it if
        // it is private!
        // NOTE: Due to a bug in JDK 1.1.7B, the BUTTON1_MASK does
        // not work on mouse drags, thus we have to use this variable
        // to determine whether we are actually zooming. It is used only
        // in _zoomBox, since calling this method is properly masked.
        _zooming = false;

        Graphics graphics = getGraphics();

        // Ignore if there is no graphics object to draw on.
        if (graphics == null) {
            return;
        }

        if ((_zoomin == true) && (_drawn == true)) {
            if ((_zoomxn != -1) || (_zoomyn != -1)) {
                // erase previous rectangle.
                int minx = Math.min(_zoomx, _zoomxn);
                int maxx = Math.max(_zoomx, _zoomxn);
                int miny = Math.min(_zoomy, _zoomyn);
                int maxy = Math.max(_zoomy, _zoomyn);
                graphics.setXORMode(_boxColor);
                graphics.drawRect(minx, miny, maxx - minx, maxy - miny);
                graphics.setPaintMode();

                // constrain to be in range
                if (y > _lry) {
                    y = _lry;
                }

                if (y < _uly) {
                    y = _uly;
                }

                if (x > _lrx) {
                    x = _lrx;
                }

                if (x < _ulx) {
                    x = _ulx;
                }

                // NOTE: ignore if total drag less than 5 pixels.
                if ((Math.abs(_zoomx - x) > 5) && (Math.abs(_zoomy - y) > 5)) {
                    double a = _xMin + ((_zoomx - _ulx) / _xscale);
                    double b = _xMin + ((x - _ulx) / _xscale);

                    // NOTE: It used to be that it was problematic to set
                    // the X range here because it conflicted with the wrap
                    // mechanism.  But now the wrap mechanism saves the state
                    // of the X range when the setWrap() method is called,
                    // so this is safe.
                    // EAL 6/12/00.
                    if (a < b) {
                        setXRange(a, b);
                    } else {
                        setXRange(b, a);
                    }

                    a = _yMax - ((_zoomy - _uly) / _yscale);
                    b = _yMax - ((y - _uly) / _yscale);

                    if (a < b) {
                        setYRange(a, b);
                    } else {
                        setYRange(b, a);
                    }
                }

                repaint();
            }
        } else if ((_zoomout == true) && (_drawn == true)) {
            // Erase previous rectangle.
            graphics.setXORMode(_boxColor);

            int x_diff = Math.abs(_zoomx - _zoomxn);
            int y_diff = Math.abs(_zoomy - _zoomyn);
            graphics.drawRect(_zoomx - 15 - x_diff, _zoomy - 15 - y_diff,
                    30 + (x_diff * 2), 30 + (y_diff * 2));
            graphics.setPaintMode();

            // Calculate zoom factor.
            double a = (Math.abs(_zoomx - x)) / 30.0;
            double b = (Math.abs(_zoomy - y)) / 30.0;
            double newx1 = _xMax + ((_xMax - _xMin) * a);
            double newx2 = _xMin - ((_xMax - _xMin) * a);

            // NOTE: To limit zooming out to the fill area, uncomment this...
            // if (newx1 > _xTop) newx1 = _xTop;
            // if (newx2 < _xBottom) newx2 = _xBottom;
            double newy1 = _yMax + ((_yMax - _yMin) * b);
            double newy2 = _yMin - ((_yMax - _yMin) * b);

            // NOTE: To limit zooming out to the fill area, uncomment this...
            // if (newy1 > _yTop) newy1 = _yTop;
            // if (newy2 < _yBottom) newy2 = _yBottom;
            zoom(newx2, newy2, newx1, newy1);
            repaint();
        } else if (_drawn == false) {
            repaint();
        }

        _drawn = false;
        _zoomin = _zoomout = false;
        _zoomxn = _zoomyn = _zoomx = _zoomy = -1;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotBox._zoomBox ( int  x,
int  y 
) [inline, package]

Definition at line 3746 of file PlotBox.java.

                                {
        // FIXME: This is friendly because Netscape 4.0.3 cannot access it if
        // it is private!
        // NOTE: Due to a bug in JDK 1.1.7B, the BUTTON1_MASK does
        // not work on mouse drags, thus we have to use this variable
        // to determine whether we are actually zooming.
        if (!_zooming) {
            return;
        }

        Graphics graphics = getGraphics();

        // Ignore if there is no graphics object to draw on.
        if (graphics == null) {
            return;
        }

        // Bound the rectangle so it doesn't go outside the box.
        if (y > _lry) {
            y = _lry;
        }

        if (y < _uly) {
            y = _uly;
        }

        if (x > _lrx) {
            x = _lrx;
        }

        if (x < _ulx) {
            x = _ulx;
        }

        // erase previous rectangle, if there was one.
        if (((_zoomx != -1) || (_zoomy != -1))) {
            // Ability to zoom out added by William Wu.
            // If we are not already zooming, figure out whether we
            // are zooming in or out.
            if ((_zoomin == false) && (_zoomout == false)) {
                if (y < _zoomy) {
                    _zoomout = true;

                    // Draw reference box.
                    graphics.setXORMode(_boxColor);
                    graphics.drawRect(_zoomx - 15, _zoomy - 15, 30, 30);
                } else if (y > _zoomy) {
                    _zoomin = true;
                }
            }

            if (_zoomin == true) {
                // Erase the previous box if necessary.
                if (((_zoomxn != -1) || (_zoomyn != -1)) && (_drawn == true)) {
                    int minx = Math.min(_zoomx, _zoomxn);
                    int maxx = Math.max(_zoomx, _zoomxn);
                    int miny = Math.min(_zoomy, _zoomyn);
                    int maxy = Math.max(_zoomy, _zoomyn);
                    graphics.setXORMode(_boxColor);
                    graphics.drawRect(minx, miny, maxx - minx, maxy - miny);
                }

                // Draw a new box if necessary.
                if (y > _zoomy) {
                    _zoomxn = x;
                    _zoomyn = y;

                    int minx = Math.min(_zoomx, _zoomxn);
                    int maxx = Math.max(_zoomx, _zoomxn);
                    int miny = Math.min(_zoomy, _zoomyn);
                    int maxy = Math.max(_zoomy, _zoomyn);
                    graphics.setXORMode(_boxColor);
                    graphics.drawRect(minx, miny, maxx - minx, maxy - miny);
                    _drawn = true;
                    return;
                } else {
                    _drawn = false;
                }
            } else if (_zoomout == true) {
                // Erase previous box if necessary.
                if (((_zoomxn != -1) || (_zoomyn != -1)) && (_drawn == true)) {
                    int x_diff = Math.abs(_zoomx - _zoomxn);
                    int y_diff = Math.abs(_zoomy - _zoomyn);
                    graphics.setXORMode(_boxColor);
                    graphics.drawRect(_zoomx - 15 - x_diff, _zoomy - 15
                            - y_diff, 30 + (x_diff * 2), 30 + (y_diff * 2));
                }

                if (y < _zoomy) {
                    _zoomxn = x;
                    _zoomyn = y;

                    int x_diff = Math.abs(_zoomx - _zoomxn);
                    int y_diff = Math.abs(_zoomy - _zoomyn);
                    graphics.setXORMode(_boxColor);
                    graphics.drawRect(_zoomx - 15 - x_diff, _zoomy - 15
                            - y_diff, 30 + (x_diff * 2), 30 + (y_diff * 2));
                    _drawn = true;
                    return;
                } else {
                    _drawn = false;
                }
            }
        }

        graphics.setPaintMode();
    }

Here is the caller graph for this function:

void ptolemy.plot.PlotBox._zoomStart ( int  x,
int  y 
) [inline, package]

Definition at line 3862 of file PlotBox.java.

                                  {
        // FIXME: This is friendly because Netscape 4.0.3 cannot access it if
        // it is private!
        // constrain to be in range
        if (y > _lry) {
            y = _lry;
        }

        if (y < _uly) {
            y = _uly;
        }

        if (x > _lrx) {
            x = _lrx;
        }

        if (x < _ulx) {
            x = _ulx;
        }

        _zoomx = x;
        _zoomy = y;
        _zooming = true;
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.addLegend ( int  dataset,
String  legend 
) [inline]

Add a legend (displayed at the upper right) for the specified data set with the specified string.

Short strings generally fit better than long strings. If the string is empty, or the argument is null, then no legend is added.

Parameters:
datasetThe dataset index.
legendThe label for the dataset.
See also:
renameLegend(int, String)

Reimplemented in ptolemy.plot.Plot, and ptolemy.plot.Histogram.

Definition at line 288 of file PlotBox.java.

                                                                   {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        if ((legend == null) || legend.equals("")) {
            return;
        }

        _legendStrings.addElement(legend);
        _legendDatasets.addElement(Integer.valueOf(dataset));
    }
synchronized void ptolemy.plot.PlotBox.addXTick ( String  label,
double  position 
) [inline]

Specify a tick mark for the X axis.

The label given is placed on the axis at the position given by position. If this is called once or more, automatic generation of tick marks is disabled. The tick mark will appear only if it is within the X range.

Parameters:
labelThe label for the tick mark.
positionThe position on the X axis.

Definition at line 308 of file PlotBox.java.

                                                                     {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        if (_xticks == null) {
            _xticks = new Vector();
            _xticklabels = new Vector();
        }

        _xticks.addElement(Double.valueOf(position));
        _xticklabels.addElement(label);
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.addYTick ( String  label,
double  position 
) [inline]

Specify a tick mark for the Y axis.

The label given is placed on the axis at the position given by position. If this is called once or more, automatic generation of tick marks is disabled. The tick mark will appear only if it is within the Y range.

Parameters:
labelThe label for the tick mark.
positionThe position on the Y axis.

Definition at line 329 of file PlotBox.java.

                                                                     {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        if (_yticks == null) {
            _yticks = new Vector();
            _yticklabels = new Vector();
        }

        _yticks.addElement(Double.valueOf(position));
        _yticklabels.addElement(label);
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.clear ( boolean  axes) [inline]

If the argument is true, clear the axes.

I.e., set all parameters controlling the axes to their initial conditions. For the change to take effect, call repaint(). If the argument is false, do nothing.

Parameters:
axesIf true, clear the axes parameters.

Definition at line 348 of file PlotBox.java.

                                                 {
        // We need to repaint the offscreen buffer.
        _plotImage = null;

        _xBottom = Double.MAX_VALUE;
        _xTop = -Double.MAX_VALUE;
        _yBottom = Double.MAX_VALUE;
        _yTop = -Double.MAX_VALUE;

        if (axes) {
            // Protected members first.
            _yMax = 0;
            _yMin = 0;
            _xMax = 0;
            _xMin = 0;
            _xRangeGiven = false;
            _yRangeGiven = false;
            _originalXRangeGiven = false;
            _originalYRangeGiven = false;
            _rangesGivenByZooming = false;
            _xlog = false;
            _ylog = false;
            _grid = true;
            _wrap = false;
            _usecolor = true;

            // Private members next...
            _filespec = null;
            _xlabel = null;
            _ylabel = null;
            _title = null;
            _legendStrings = new Vector();
            _legendDatasets = new Vector();
            _xticks = null;
            _xticklabels = null;
            _yticks = null;
            _yticklabels = null;
        }
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.clearLegends ( ) [inline]

Clear all legends.

This will show up on the next redraw.

Definition at line 390 of file PlotBox.java.

                                            {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _legendStrings = new Vector();
        _legendDatasets = new Vector();
    }
void ptolemy.plot.PlotBox.deferIfNecessary ( Runnable  action) [inline]

If this method is called in the event thread, then simply execute the specified action.

Otherwise, if there are already deferred actions, then add the specified one to the list. Otherwise, create a list of deferred actions, if necessary, and request that the list be processed in the event dispatch thread.

Note that it does not work nearly as well to simply schedule the action yourself on the event thread because if there are a large number of actions, then the event thread will not be able to keep up. By grouping these actions, we avoid this problem.

This method is not synchronized, so the caller should be.

Parameters:
actionThe Runnable object to execute.

Definition at line 413 of file PlotBox.java.

                                                  {
        // In swing, updates to showing graphics must be done in the
        // event thread.  If we are in the event thread, then proceed.
        // Otherwise, queue a request or add to a pending request.
        if (EventQueue.isDispatchThread()) {
            action.run();
        } else {
            if (_deferredActions == null) {
                _deferredActions = new LinkedList();
            }

            // Add the specified action to the list of actions to perform.
            _deferredActions.add(action);

            // If it hasn't already been requested, request that actions
            // be performed in the event dispatch thread.
            if (!_actionsDeferred) {
                Runnable doActions = new Runnable() {
                    public void run() {
                        _executeDeferredActions();
                    }
                };

                try {
                    // NOTE: Using invokeAndWait() here risks causing
                    // deadlock.  Don't do it!
                    SwingUtilities.invokeLater(doActions);
                } catch (Exception ex) {
                    // Ignore InterruptedException.
                    // Other exceptions should not occur.
                }

                _actionsDeferred = true;
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.export ( OutputStream  out) [inline]

Export a description of the plot.

Currently, only EPS is supported. But in the future, this may cause a dialog box to open to allow the user to select a format. If the argument is null, then the description goes to the clipboard. Otherwise, it goes to the specified file. To send it to standard output, use System.out as an argument.

Parameters:
outAn output stream to which to send the description.

Definition at line 459 of file PlotBox.java.

                                                      {
        try {
            EPSGraphics g = new EPSGraphics(out, _width, _height);
            _drawPlot(g, false);
            g.showpage();
        } catch (RuntimeException ex) {
            String message = "Export failed: " + ex.getMessage();
            JOptionPane.showMessageDialog(this, message,
                    "Ptolemy Plot Message", JOptionPane.ERROR_MESSAGE);

            // Rethrow the exception so that we don't report success,
            // and so the stack trace is displayed on standard out.
            throw (RuntimeException) ex.fillInStackTrace();
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

synchronized BufferedImage ptolemy.plot.PlotBox.exportImage ( ) [inline]

Create a BufferedImage and draw this plot to it.

The size of the returned image matches the current size of the plot. This method can be used, for example, by a servlet to produce an image, rather than requiring an applet to instantiate a PlotBox.

Returns:
An image filled by the plot.

Definition at line 490 of file PlotBox.java.

                                                    {
        Rectangle rectangle = new Rectangle(_preferredWidth, _preferredHeight);
        return exportImage(new BufferedImage(rectangle.width, rectangle.height,
                BufferedImage.TYPE_INT_ARGB), rectangle,
                _defaultImageRenderingHints(), false);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

synchronized BufferedImage ptolemy.plot.PlotBox.exportImage ( Rectangle  rectangle) [inline]

Create a BufferedImage the size of the given rectangle and draw this plot to it at the position specified by the rectangle.

The plot is rendered using anti-aliasing.

Parameters:
rectangleThe size of the plot. This method can be used, for example, by a servlet to produce an image, rather than requiring an applet to instantiate a PlotBox.
Returns:
An image containing the plot.

Definition at line 505 of file PlotBox.java.

                                                                       {
        return exportImage(new BufferedImage(rectangle.width, rectangle.height,
                BufferedImage.TYPE_INT_ARGB), rectangle,
                _defaultImageRenderingHints(), false);
    }

Here is the call graph for this function:

synchronized BufferedImage ptolemy.plot.PlotBox.exportImage ( BufferedImage  bufferedImage,
Rectangle  rectangle,
RenderingHints  hints,
boolean  transparent 
) [inline]

Draw this plot onto the specified image at the position of the specified rectangle with the size of the specified rectangle.

The plot is rendered using anti-aliasing. This can be used to paint a number of different plots onto a single buffered image. This method can be used, for example, by a servlet to produce an image, rather than requiring an applet to instantiate a PlotBox.

Parameters:
bufferedImageImage onto which the plot is drawn.
rectangleThe size and position of the plot in the image.
hintsRendering hints for this plot.
transparentIndicator that the background of the plot should not be painted.
Returns:
The modified bufferedImage.

Definition at line 525 of file PlotBox.java.

                                                                            {
        Graphics2D graphics = bufferedImage.createGraphics();
        graphics.addRenderingHints(_defaultImageRenderingHints());

        if (!transparent) {
            graphics.setColor(Color.white); // set the background color
            graphics.fill(rectangle);
        }

        _drawPlot(graphics, false, rectangle);
        return bufferedImage;
    }

Here is the call graph for this function:

synchronized BufferedImage ptolemy.plot.PlotBox.exportImage ( BufferedImage  bufferedImage) [inline]

Draw this plot onto the provided image.

This method does not paint the background, so the plot is transparent. The plot fills the image, and is rendered using anti-aliasing. This method can be used to overlay multiple plots on the same image, although you must use care to ensure that the axes and other labels are identical. Hence, it is usually better to simply combine data sets into a single plot.

Parameters:
bufferedImageThe image onto which to render the plot.
Returns:
The modified bufferedImage.

Definition at line 550 of file PlotBox.java.

                                                                               {
        return exportImage(bufferedImage, new Rectangle(bufferedImage
                .getWidth(), bufferedImage.getHeight()),
                _defaultImageRenderingHints(), true);
    }

Here is the call graph for this function:

synchronized void ptolemy.plot.PlotBox.fillPlot ( ) [inline]

Rescale so that the data that is currently plotted just fits.

This is done based on the protected variables _xBottom, _xTop, _yBottom, and _yTop. It is up to derived classes to ensure that variables are valid. This method calls repaint(), which eventually causes the display to be updated.

Reimplemented in ptolemy.plot.Plot, and ptolemy.plot.Histogram.

Definition at line 563 of file PlotBox.java.

                                        {
        // NOTE: These used to be _setXRange() and _setYRange() to avoid
        // confusing this with user-specified ranges.  But we want to treat
        // a fill command as a user specified range.
        // EAL, 6/12/00.
        setXRange(_xBottom, _xTop);
        setYRange(_yBottom, _yTop);
        repaint();

        // Reacquire the focus so that key bindings work.
        // NOTE: no longer needed?
        // requestFocus();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Return whether the plot uses color.

Returns:
True if the plot uses color.

Definition at line 580 of file PlotBox.java.

                              {
        return _usecolor;
    }

Here is the caller graph for this function:

static Color ptolemy.plot.PlotBox.getColorByName ( String  name) [inline, static]

Convert a color name into a Color.

Currently, only a very limited set of color names is supported: black, white, red, green, and blue.

Parameters:
nameA color name, or null if not found.
Returns:
An instance of Color.

Definition at line 597 of file PlotBox.java.

                                                    {
        try {
            // Check to see if it is a hexadecimal
            if (name.startsWith("#")) {
                name = name.substring(1);
            }

            Color col = new Color(Integer.parseInt(name, 16));
            return col;
        } catch (NumberFormatException e) {
        }

        // FIXME: This is a poor excuse for a list of colors and values.
        // We should use a hash table here.
        // Note that Color decode() wants the values to start with 0x.
        String[][] names = { { "black", "00000" }, { "white", "ffffff" },
                { "red", "ff0000" }, { "green", "00ff00" },
                { "blue", "0000ff" } };

        for (int i = 0; i < names.length; i++) {
            if (name.equals(names[i][0])) {
                try {
                    Color col = new Color(Integer.parseInt(names[i][1], 16));
                    return col;
                } catch (NumberFormatException e) {
                }
            }
        }

        return null;
    }

Here is the caller graph for this function:

Color [] ptolemy.plot.PlotBox.getColors ( ) [inline]

Get the point colors.

Returns:
Array of colors
See also:
setColors(Color[])

Definition at line 588 of file PlotBox.java.

                               {
        return _colors;
    }
String ptolemy.plot.PlotBox.getDataurl ( ) [inline]

Get the file specification that was given by setDataurl.

This method is deprecated. Use read() instead.

Deprecated:

Definition at line 633 of file PlotBox.java.

                               {
        return _filespec;
    }

Get the document base that was set by setDocumentBase.

This method is deprecated. Use read() instead.

Deprecated:

Definition at line 641 of file PlotBox.java.

                                 {
        return _documentBase;
    }

Return whether the grid is drawn.

Returns:
True if a grid is drawn.

Definition at line 648 of file PlotBox.java.

                             {
        return _grid;
    }

Here is the caller graph for this function:

synchronized String ptolemy.plot.PlotBox.getLegend ( int  dataset) [inline]

Get the legend for a dataset, or null if there is none.

The legend would have been set by addLegend().

Parameters:
datasetThe dataset index.
Returns:
The legend label, or null if there is none.

Definition at line 657 of file PlotBox.java.

                                                      {
        int idx = _legendDatasets.indexOf(Integer.valueOf(dataset), 0);

        if (idx != -1) {
            return (String) _legendStrings.elementAt(idx);
        } else {
            return null;
        }
    }

Here is the caller graph for this function:

synchronized int ptolemy.plot.PlotBox.getLegendDataset ( String  legend) [inline]

Given a legend string, return the corresponding dataset or -1 if no legend was added with that legend string The legend would have been set by addLegend().

Parameters:
legendThe String naming the legend
Returns:
The legend dataset, or -1 if not found.
Since:
Ptplot 5.2p1

Definition at line 674 of file PlotBox.java.

                                                            {
        int index = _legendStrings.indexOf(legend);

        if (index == -1) {
            return -1;
        }

        return ((Integer) _legendDatasets.get(index)).intValue();
    }
Rectangle ptolemy.plot.PlotBox.getPlotRectangle ( ) [inline]

If the size of the plot has been set by setSize(), then return that size.

Otherwise, return what the superclass returns (which is undocumented, but apparently imposes no maximum size). Currently (JDK 1.3), only BoxLayout pays any attention to this.

Returns:
The maximum desired size. Get the minimum size of this component. This is simply the dimensions specified by setSize(), if this has been called. Otherwise, return whatever the base class returns, which is undocumented.
The minimum size. Get the current plot rectangle. Note that Rectangle returned by this method is calculated from the values of _ulx, _uly, _lrx and _lry. The value passed in by setPlotRectangle() is not directly used, thus calling getPlotRectangle() may not return the same rectangle that was passed in with setPlotRectangle().
Rectangle
See also:
setPlotRectangle(Rectangle)

Definition at line 722 of file PlotBox.java.

                                        {
        return new Rectangle(_ulx, _uly, _lrx - _ulx, _lry - _uly);
    }
synchronized Dimension ptolemy.plot.PlotBox.getPreferredSize ( ) [inline]

Get the preferred size of this component.

This is simply the dimensions specified by setSize(), if this has been called, or the default width and height otherwise (500 by 300).

Returns:
The preferred size.

Definition at line 732 of file PlotBox.java.

                                                     {
        return new Dimension(_preferredWidth, _preferredHeight);
    }
synchronized String ptolemy.plot.PlotBox.getTitle ( ) [inline]

Get the title of the graph, or an empty string if there is none.

Returns:
The title.

Definition at line 739 of file PlotBox.java.

                                          {
        if (_title == null) {
            return "";
        }

        return _title;
    }

Here is the caller graph for this function:

synchronized double [] ptolemy.plot.PlotBox.getXAutoRange ( ) [inline]

Get the range for X values of the data points registered so far.

Usually, derived classes handle managing the range by checking each new point against the current range.

Returns:
An array of two doubles where the first element is the minimum and the second element is the maximum.
See also:
getXRange()

Definition at line 754 of file PlotBox.java.

                                                 {
        double[] result = new double[2];
        result[0] = _xBottom;
        result[1] = _xTop;
        return result;
    }
synchronized String ptolemy.plot.PlotBox.getXLabel ( ) [inline]

Get the label for the X (horizontal) axis, or null if none has been set.

Returns:
The X label.

Definition at line 765 of file PlotBox.java.

                                           {
        return _xlabel;
    }

Here is the caller graph for this function:

Return whether the X axis is drawn with a logarithmic scale.

Returns:
True if the X axis is logarithmic.

Definition at line 772 of file PlotBox.java.

                             {
        return _xlog;
    }
synchronized double [] ptolemy.plot.PlotBox.getXRange ( ) [inline]

Get the X range.

If setXRange(double, double) has been called, then this method returns the values passed in as arguments to setXRange(double, double). If setXRange(double, double) has not been called, then this method returns the range of the data to be plotted, which might not be all of the data due to zooming.

Returns:
An array of two doubles where the first element is the minimum and the second element is the maximum.
See also:
getXAutoRange()

Definition at line 786 of file PlotBox.java.

                                             {
        double[] result = new double[2];

        if (_xRangeGiven) {
            result[0] = _xlowgiven;
            result[1] = _xhighgiven;
        } else {
            // Have to first correct for the padding.
            result[0] = _xMin + ((_xMax - _xMin) * _padding);
            result[1] = _xMax - ((_xMax - _xMin) * _padding);
            ;
        }

        return result;
    }

Here is the caller graph for this function:

synchronized Vector [] ptolemy.plot.PlotBox.getXTicks ( ) [inline]

Get the X ticks that have been specified, or null if none.

The return value is an array with two vectors, the first of which specifies the X tick locations (as instances of Double), and the second of which specifies the corresponding labels.

Returns:
The X ticks.

Definition at line 808 of file PlotBox.java.

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

        Vector[] result = new Vector[2];
        result[0] = _xticks;
        result[1] = _xticklabels;
        return result;
    }

Here is the caller graph for this function:

synchronized double [] ptolemy.plot.PlotBox.getYAutoRange ( ) [inline]

Get the range for Y values of the data points registered so far.

Usually, derived classes handle managing the range by checking each new point against the range.

Returns:
An array of two doubles where the first element is the minimum and the second element is the maximum.
See also:
getYRange()

Definition at line 826 of file PlotBox.java.

                                                 {
        double[] result = new double[2];
        result[0] = _yBottom;
        result[1] = _yTop;
        return result;
    }
String ptolemy.plot.PlotBox.getYLabel ( ) [inline]

Get the label for the Y (vertical) axis, or null if none has been set.

Returns:
The Y label.

Definition at line 837 of file PlotBox.java.

                              {
        return _ylabel;
    }

Here is the caller graph for this function:

Return whether the Y axis is drawn with a logarithmic scale.

Returns:
True if the Y axis is logarithmic.

Definition at line 844 of file PlotBox.java.

                             {
        return _ylog;
    }
synchronized double [] ptolemy.plot.PlotBox.getYRange ( ) [inline]

Get the Y range.

If setYRange(double, double) has been called, then this method returns the values passed in as arguments to setYRange(double, double). If setYRange(double, double) has not been called, then this method returns the range of the data to be plotted, which might not be all of the data due to zooming.

Returns:
An array of two doubles where the first element is the minimum and the second element is the maximum.
See also:
getYAutoRange()

Definition at line 858 of file PlotBox.java.

                                             {
        double[] result = new double[2];

        if (_yRangeGiven) {
            result[0] = _ylowgiven;
            result[1] = _yhighgiven;
        } else {
            // Have to first correct for the padding.
            result[0] = _yMin + ((_yMax - _yMin) * _padding);
            result[1] = _yMax - ((_yMax - _yMin) * _padding);
            ;
        }

        return result;
    }

Here is the caller graph for this function:

synchronized Vector [] ptolemy.plot.PlotBox.getYTicks ( ) [inline]

Get the Y ticks that have been specified, or null if none.

The return value is an array with two vectors, the first of which specifies the Y tick locations (as instances of Double), and the second of which specifies the corresponding labels.

Returns:
The Y ticks.

Definition at line 880 of file PlotBox.java.

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

        Vector[] result = new Vector[2];
        result[0] = _yticks;
        result[1] = _yticklabels;
        return result;
    }

Here is the caller graph for this function:

void ptolemy.plot.PlotBox.init ( ) [inline]

Initialize the component, creating the fill button and parsing an input file, if one has been specified.

This is deprecated. Call setButtons() and read() instead.

Deprecated:

Definition at line 896 of file PlotBox.java.

                       {
        setButtons(true);

        if (_filespec != null) {
            parseFile(_filespec, _documentBase);
        }
    }

Here is the call graph for this function:

synchronized void ptolemy.plot.PlotBox.paintComponent ( Graphics  graphics) [inline]

Paint the component contents, which in this base class is only the axes.

Parameters:
graphicsThe graphics context.

Definition at line 908 of file PlotBox.java.

                                                               {
        //  super.paintComponent(graphics);
        //         _drawPlot(graphics, true);
        BufferedImage newPlotImage = _plotImage;

        if (newPlotImage == null) {
            Rectangle bounds = getBounds();
            newPlotImage = new BufferedImage(bounds.width, bounds.height,
                    BufferedImage.TYPE_3BYTE_BGR);
            _plotImage = newPlotImage;

            Graphics2D offScreenGraphics = newPlotImage.createGraphics();
            super.paintComponent(offScreenGraphics);
            _drawPlot(offScreenGraphics, true);
        }

        // Blit the offscreen image onto the screen.
        graphics.drawImage(newPlotImage, 0, 0, null);

        // Acquire the focus so that key bindings work.
        // NOTE: no longer needed?
        // requestFocus();
    }

Here is the call graph for this function:

void ptolemy.plot.PlotBox.parseFile ( String  filespec) [inline]

Syntactic sugar for parseFile(filespec, documentBase).

This method is deprecated. Use read() to read the old file format, or use one of the classes in the plotml package to read the XML-based file format.

Deprecated:

Definition at line 938 of file PlotBox.java.

                                           {
        parseFile(filespec, (URL) null);
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.parseFile ( String  filespec,
URL  documentBase 
) [inline]

Open up the input file, which could be stdin, a URL, or a file.

Deprecated:
This method is deprecated. Use read() instead.

Reimplemented in ptolemy.plot.Plot.

Definition at line 945 of file PlotBox.java.

                                                                          {
        DataInputStream in = null;

        if ((filespec == null) || (filespec.length() == 0)) {
            // Open up stdin
            in = new DataInputStream(System.in);
        } else {
            try {
                URL url = null;

                if ((documentBase == null) && (_documentBase != null)) {
                    documentBase = _documentBase;
                }

                if (documentBase == null) {
                    url = new URL(filespec);
                } else {
                    try {
                        url = new URL(documentBase, filespec);
                    } catch (NullPointerException e) {
                        // If we got a NullPointerException, then perhaps we
                        // are calling this as an application, not as an applet
                        url = new URL(filespec);
                    }
                }

                in = new DataInputStream(url.openStream());
            } catch (MalformedURLException e) {
                try {
                    // Just try to open it as a file.
                    in = new DataInputStream(new FileInputStream(filespec));
                } catch (FileNotFoundException me) {
                    _errorMsg = new String[2];
                    _errorMsg[0] = "File not found: " + filespec;
                    _errorMsg[1] = me.getMessage();
                    return;
                } catch (SecurityException me) {
                    _errorMsg = new String[2];
                    _errorMsg[0] = "Security Exception: " + filespec;
                    _errorMsg[1] = me.getMessage();
                    return;
                }
            } catch (IOException ioe) {
                _errorMsg = new String[3];
                _errorMsg[0] = "Failure opening URL: ";
                _errorMsg[1] = " " + filespec;
                _errorMsg[2] = ioe.getMessage();
                return;
            }
        }

        // At this point, we've opened the data source, now read it in
        try {
            BufferedReader din = new BufferedReader(new InputStreamReader(in));
            String line = din.readLine();

            while (line != null) {
                _parseLine(line);
                line = din.readLine();
            }
        } catch (MalformedURLException e) {
            _errorMsg = new String[2];
            _errorMsg[0] = "Malformed URL: " + filespec;
            _errorMsg[1] = e.getMessage();
            return;
        } catch (IOException e) {
            _errorMsg = new String[2];
            _errorMsg[0] = "Failure reading data: " + filespec;
            _errorMsg[1] = e.getMessage();
            _errorMsg[1] = e.getMessage();
        } finally {
            try {
                in.close();
            } catch (IOException me) {
            }
        }
    }

Here is the call graph for this function:

synchronized int ptolemy.plot.PlotBox.print ( Graphics  graphics,
PageFormat  format,
int  index 
) throws PrinterException [inline]

Print the plot to a printer, represented by the specified graphics object.

Parameters:
graphicsThe context into which the page is drawn.
formatThe size and orientation of the page being drawn.
indexThe zero based index of the page to be drawn.
Returns:
PAGE_EXISTS if the page is rendered successfully, or NO_SUCH_PAGE if pageIndex specifies a non-existent page.
Exceptions:
PrinterExceptionIf the print job is terminated.

Definition at line 1032 of file PlotBox.java.

                                               {

        if (graphics == null) {
            return Printable.NO_SUCH_PAGE;
        }

        // We only print on one page.
        if (index >= 1) {
            return Printable.NO_SUCH_PAGE;
        }

        Graphics2D graphics2D = (Graphics2D) graphics;

        // Scale the printout to fit the pages.
        // Contributed by Laurent ETUR, Schlumberger Riboud Product Center
        double scalex = format.getImageableWidth() / getWidth();
        double scaley = format.getImageableHeight() / getHeight();
        double scale = Math.min(scalex, scaley);
        graphics2D.translate((int) format.getImageableX(), (int) format
                .getImageableY());
        graphics2D.scale(scale, scale);
        _drawPlot(graphics, true);
        return Printable.PAGE_EXISTS;
    }

Here is the call graph for this function:

synchronized void ptolemy.plot.PlotBox.read ( InputStream  in) throws IOException [inline]

Read commands and/or plot data from an input stream in the old (non-XML) file syntax.

To update the display, call repaint(), or make the plot visible with setVisible(true).

To read from standard input, use:

     read(System.in);
  

To read from a url, use:

     read(url.openStream());
  

To read a URL from within an applet, use:

     URL url = new URL(getDocumentBase(), urlSpec);
     read(url.openStream());
  

Within an application, if you have an absolute URL, use:

     URL url = new URL(urlSpec);
     read(url.openStream());
  

To read from a file, use:

     read(new FileInputStream(filename));
  
Parameters:
inThe input stream.
Exceptions:
IOExceptionIf the stream cannot be read.

Reimplemented in ptolemy.plot.Plot.

Definition at line 1088 of file PlotBox.java.

                                                                     {
        try {
            // NOTE: I tried to use exclusively the jdk 1.1 Reader classes,
            // but they provide no support like DataInputStream, nor
            // support for URL accesses.  So I use the older classes
            // here in a strange mixture.
            BufferedReader din = new BufferedReader(new InputStreamReader(in));

            try {
                String line = din.readLine();

                while (line != null) {
                    _parseLine(line);
                    line = din.readLine();
                }
            } finally {
                din.close();
            }
        } catch (IOException e) {
            _errorMsg = new String[2];
            _errorMsg[0] = "Failure reading input data.";
            _errorMsg[1] = e.getMessage();
            throw e;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.read ( String  command) [inline]

Read a single line command provided as a string.

The commands can be any of those in the ASCII file format.

Parameters:
commandA command.

Definition at line 1118 of file PlotBox.java.

                                                  {
        _parseLine(command);
    }

Here is the call graph for this function:

Definition at line 246 of file PlotBox.java.

                                  {                                                                                                        
        String reply="error\nReadApplet() not implemented\nNO SENSIBLE USER INTERACTION PRESENT";                                          
        return reply;                                                                                                                      
    }                                                                                                                                      

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.removeLegend ( int  dataset) [inline]

Remove the legend (displayed at the upper right) for the specified data set.

If the dataset is not found, nothing will occur. The PlotBox must be repainted in order for this to take effect.

Parameters:
datasetThe dataset index.

Definition at line 1127 of file PlotBox.java.

                                                       {
        final int len = _legendDatasets.size();
        int foundIndex = -1;
        boolean found = false;

        for (int i = 0; (i < len) && !found; ++i) {
            if (((Integer) _legendDatasets.get(i)).intValue() == dataset) {
                foundIndex = i;
                found = true;
            }
        }

        if (found) {
            _legendDatasets.remove(foundIndex);
            _legendStrings.remove(foundIndex);
        }
    }
synchronized void ptolemy.plot.PlotBox.renameLegend ( int  dataset,
String  newName 
) [inline]

Rename a legend.

Parameters:
datasetThe dataset of the legend to be renamed. If there is no dataset with this value, then nothing happens.
newNameThe new name of legend.
See also:
addLegend(int, String)

Definition at line 1151 of file PlotBox.java.

                                                                       {
        int index = _legendDatasets.indexOf(Integer.valueOf(dataset), 0);

        if (index != -1) {
            _legendStrings.setElementAt(newName, index);

            // Changing legend means we need to repaint the offscreen buffer.
            _plotImage = null;
        }
    }
synchronized void ptolemy.plot.PlotBox.resetAxes ( ) [inline]

Reset the X and Y axes to the ranges that were first specified using setXRange() and setYRange().

If these methods have not been called, then reset to the default ranges. This method calls repaint(), which eventually causes the display to be updated.

Definition at line 1168 of file PlotBox.java.

Here is the call graph for this function:

Here is the caller graph for this function:

Do nothing in this base class.

Derived classes might want to override this class to give an example of their use.

Reimplemented in ptolemy.plot.Plot, and ptolemy.plot.Histogram.

Definition at line 1177 of file PlotBox.java.

                             {
        // Empty default implementation.
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.setBackground ( Color  background) [inline]

Set the background color.

Parameters:
backgroundThe background color.

Definition at line 1184 of file PlotBox.java.

                                                             {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _background = background;
        super.setBackground(_background);
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.setBounds ( int  x,
int  y,
int  width,
int  height 
) [inline]

Move and resize this component.

The new location of the top-left corner is specified by x and y, and the new size is specified by width and height. This overrides the base class method to make a record of the new size.

Parameters:
xThe new x-coordinate of this component.
yThe new y-coordinate of this component.
widthThe new width of this component.
heightThe new height of this component.

Definition at line 1201 of file PlotBox.java.

                                                                            {
        _width = width;
        _height = height;

        // Resizing the component means we need to redraw the buffer.
        _plotImage = null;

        super.setBounds(x, y, _width, _height);
    }
synchronized void ptolemy.plot.PlotBox.setButtons ( boolean  visible) [inline]

If the argument is true, make a fill button visible at the upper right.

This button auto-scales the plot. NOTE: The button may infringe on the title space, if the title is long. In an application, it is preferable to provide a menu with the fill command. This way, when printing the plot, the printed plot will not have a spurious button. Thus, this method should be used only by applets, which normally do not have menus. This method should only be called from within the event dispatch thread, since it interacts with swing.

Reimplemented in ptolemy.plot.PlotLive.

Definition at line 1221 of file PlotBox.java.

                                                         {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        if (_printButton == null) {
            // Load the image by using the absolute path to the gif.
            URL img = null;
            try {
                // FindBugs: Usage of GetResource may be unsafe if
                // class is extended
                img = FileUtilities.nameToURL(
                        "$CLASSPATH/ptolemy/plot/img/print.gif", null, null);
            } catch (IOException ex) {
                ex.printStackTrace();
            }

            if (img != null) {
                ImageIcon printIcon = new ImageIcon(img);
                _printButton = new JButton(printIcon);
                _printButton.setBorderPainted(false);
            } else {
                // Backup in case something goes wrong with the
                // class loader.
                _printButton = new JButton("P");
            }

            // FIXME: If we failed to get an image, then the letter "P"
            // Is not likely to fit into a 20x20 button.
            _printButton.setPreferredSize(new Dimension(20, 20));
            _printButton.setToolTipText("Print the plot.");
            _printButton.addActionListener(new ButtonListener());
            add(_printButton);
        }

        _printButton.setVisible(visible);

        if (_resetButton == null) {
            // Load the image by using the absolute path to the gif.
            URL img = null;
            try {
                // FindBugs: Usage of GetResource may be unsafe if
                // class is extended
                img = FileUtilities.nameToURL(
                        "$CLASSPATH/ptolemy/plot/img/reset.gif", null, null);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            if (img != null) {
                ImageIcon resetIcon = new ImageIcon(img);
                _resetButton = new JButton(resetIcon);
                _resetButton.setBorderPainted(false);
            } else {
                // Backup in case something goes wrong with the
                // class loader.
                _resetButton = new JButton("R");
            }

            // FIXME: If we failed to get an image, then the letter "R"
            // Is not likely to fit into a 20x20 button.
            _resetButton.setPreferredSize(new Dimension(20, 20));
            _resetButton
                    .setToolTipText("Reset X and Y ranges to their original values");
            _resetButton.addActionListener(new ButtonListener());
            add(_resetButton);
        }

        _resetButton.setVisible(visible);

        if (_formatButton == null) {
            // Load the image by using the absolute path to the gif.
            URL img = null;
            try {
                // FindBugs: Usage of GetResource may be unsafe if
                // class is extended
                img = FileUtilities.nameToURL(
                        "$CLASSPATH/ptolemy/plot/img/format.gif", null, null);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            if (img != null) {
                ImageIcon formatIcon = new ImageIcon(img);
                _formatButton = new JButton(formatIcon);
                _formatButton.setBorderPainted(false);
            } else {
                // Backup in case something goes wrong with the
                // class loader.
                _formatButton = new JButton("S");
            }

            // FIXME: If we failed to get an image, then the letter "S"
            // Is not likely to fit into a 20x20 button.
            _formatButton.setPreferredSize(new Dimension(20, 20));
            _formatButton.setToolTipText("Set the plot format");
            _formatButton.addActionListener(new ButtonListener());
            add(_formatButton);
        }

        _formatButton.setVisible(visible);

        if (_fillButton == null) {
            // Load the image by using the absolute path to the gif.
            URL img = null;
            try {
                // FindBugs: Usage of GetResource may be unsafe if
                // class is extended
                img = FileUtilities.nameToURL(
                        "$CLASSPATH/ptolemy/plot/img/fill.gif", null, null);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            if (img != null) {
                ImageIcon fillIcon = new ImageIcon(img);
                _fillButton = new JButton(fillIcon);
                _fillButton.setBorderPainted(false);
            } else {
                // Backup in case something goes wrong with the
                // class loader.
                _fillButton = new JButton("F");
            }

            // FIXME: If we failed to get an image, then the letter "F"
            // Is not likely to fit into a 20x20 button.
            _fillButton.setPreferredSize(new Dimension(20, 20));
            _fillButton.setToolTipText("Rescale the plot to fit the data");
            _fillButton.addActionListener(new ButtonListener());
            add(_fillButton);
        }

        _fillButton.setVisible(visible);

        // Request the focus so that key events are heard.
        // NOTE: no longer needed?
        // requestFocus();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.setColor ( boolean  useColor) [inline]

If the argument is false, draw the plot without using color (in black and white).

Otherwise, draw it in color (the default).

Parameters:
useColorFalse to draw in back and white.

Definition at line 1360 of file PlotBox.java.

                                                        {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _usecolor = useColor;
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.setColors ( Color[]  colors) [inline]

Set the point colors.

Note that the default colors have been carefully selected to maximize readability and that it is easy to use colors that result in a very ugly plot.

Parameters:
colorsArray of colors to use in succession for data sets.
See also:
getColors()

Definition at line 1373 of file PlotBox.java.

                                                       {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _colors = colors;
    }
void ptolemy.plot.PlotBox.setDataurl ( String  filespec) [inline]

Set the file to read when init() is called.

This method is deprecated. Use read() instead.

Deprecated:

Definition at line 1384 of file PlotBox.java.

                                            {
        _filespec = filespec;
    }
void ptolemy.plot.PlotBox.setDocumentBase ( URL  documentBase) [inline]

Set the document base to used when init() is called to read a URL.

This method is deprecated. Use read() instead.

Deprecated:

Definition at line 1392 of file PlotBox.java.

                                                  {
        _documentBase = documentBase;
    }
synchronized void ptolemy.plot.PlotBox.setForeground ( Color  foreground) [inline]

Set the foreground color.

Parameters:
foregroundThe foreground color.

Definition at line 1399 of file PlotBox.java.

                                                             {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _foreground = foreground;
        super.setForeground(_foreground);
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.setGrid ( boolean  grid) [inline]

Control whether the grid is drawn.

Parameters:
gridIf true, a grid is drawn.

Definition at line 1410 of file PlotBox.java.

                                                   {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _grid = grid;
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.setLabelFont ( String  name) [inline]

Set the label font, which is used for axis labels and legend labels.

The font names understood are those understood by java.awt.Font.decode().

Parameters:
nameA font name.

Definition at line 1422 of file PlotBox.java.

                                                       {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _labelFont = Font.decode(name);
        _labelFontMetrics = getFontMetrics(_labelFont);
    }
synchronized void ptolemy.plot.PlotBox.setPlotRectangle ( Rectangle  rectangle) [inline]

Set the plot rectangle inside the axes.

This method can be used to create two plots that share the same axes.

Parameters:
rectangleRectangle space inside axes.
See also:
getPlotRectangle()

Definition at line 1435 of file PlotBox.java.

                                                                   {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _specifiedPlotRectangle = rectangle;
    }
synchronized void ptolemy.plot.PlotBox.setSize ( int  width,
int  height 
) [inline]

Set the size of the plot.

This overrides the base class to make it work. In particular, it records the specified size so that getMinimumSize() and getPreferredSize() return the specified value. However, it only works if the plot is placed in its own JPanel. This is because the JPanel asks the contained component for its preferred size before determining the size of the panel. If the plot is placed directly in the content pane of a JApplet, then, mysteriously, this method has no effect.

Parameters:
widthThe width, in pixels.
heightThe height, in pixels.

Definition at line 1453 of file PlotBox.java.

                                                            {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _width = width;
        _height = height;
        _preferredWidth = width;
        _preferredHeight = height;

        //_sizeHasBeenSet = true;
        super.setSize(width, height);
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.setTitle ( String  title) [inline]

Set the title of the graph.

Parameters:
titleThe title.

Definition at line 1469 of file PlotBox.java.

                                                    {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _title = title;
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.setTitleFont ( String  name) [inline]

Set the title font.

The font names understood are those understood by java.awt.Font.decode().

Parameters:
nameA font name.

Definition at line 1481 of file PlotBox.java.

                                                       {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _titleFont = Font.decode(name);
        _titleFontMetrics = getFontMetrics(_titleFont);
    }
synchronized void ptolemy.plot.PlotBox.setWrap ( boolean  wrap) [inline]

Specify whether the X axis is wrapped.

If it is, then X values that are out of range are remapped to be in range using modulo arithmetic. The X range is determined by the most recent call to setXRange() (or the most recent zoom). If the X range has not been set, then use the default X range, or if data has been plotted, then the current fill range.

Parameters:
wrapIf true, wrapping of the X axis is enabled.

Definition at line 1497 of file PlotBox.java.

                                                   {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _wrap = wrap;

        if (!_xRangeGiven) {
            if (_xBottom > _xTop) {
                // have nothing to go on.
                setXRange(0, 0);
            } else {
                setXRange(_xBottom, _xTop);
            }
        }

        _wrapLow = _xlowgiven;
        _wrapHigh = _xhighgiven;
    }

Here is the call graph for this function:

synchronized void ptolemy.plot.PlotBox.setXLabel ( String  label) [inline]

Set the label for the X (horizontal) axis.

Parameters:
labelThe label.

Definition at line 1519 of file PlotBox.java.

                                                     {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _xlabel = label;
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.setXLog ( boolean  xlog) [inline]

Specify whether the X axis is drawn with a logarithmic scale.

If you would like to have the X axis drawn with a logarithmic axis, then setXLog(true) should be called before adding any data points.

Parameters:
xlogIf true, logarithmic axis is used.

Definition at line 1532 of file PlotBox.java.

                                                   {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _xlog = xlog;
    }
synchronized void ptolemy.plot.PlotBox.setXRange ( double  min,
double  max 
) [inline]

Set the X (horizontal) range of the plot.

If this is not done explicitly, then the range is computed automatically from data available when the plot is drawn. If min and max are identical, then the range is arbitrarily spread by 1.

Parameters:
minThe left extent of the range.
maxThe right extent of the range.

Definition at line 1546 of file PlotBox.java.

                                                               {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _xRangeGiven = true;
        _xlowgiven = min;
        _xhighgiven = max;
        _setXRange(min, max);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.setYLabel ( String  label) [inline]

Set the label for the Y (vertical) axis.

Parameters:
labelThe label.

Definition at line 1559 of file PlotBox.java.

                                                     {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _ylabel = label;
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.setYLog ( boolean  ylog) [inline]

Specify whether the Y axis is drawn with a logarithmic scale.

If you would like to have the Y axis drawn with a logarithmic axis, then setYLog(true) should be called before adding any data points.

Parameters:
ylogIf true, logarithmic axis is used.

Definition at line 1572 of file PlotBox.java.

                                                   {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _ylog = ylog;
    }
synchronized void ptolemy.plot.PlotBox.setYRange ( double  min,
double  max 
) [inline]

Set the Y (vertical) range of the plot.

If this is not done explicitly, then the range is computed automatically from data available when the plot is drawn. If min and max are identical, then the range is arbitrarily spread by 0.1.

Parameters:
minThe bottom extent of the range.
maxThe top extent of the range.

Definition at line 1586 of file PlotBox.java.

                                                               {
        // Changing legend means we need to repaint the offscreen buffer.
        _plotImage = null;

        _yRangeGiven = true;
        _ylowgiven = min;
        _yhighgiven = max;
        _setYRange(min, max);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotBox.write ( OutputStream  out) [inline]

Write the current data and plot configuration to the specified stream in PlotML syntax.

PlotML is an XML extension for plot data. The written information is standalone, in that it includes the DTD (document type definition). This makes is somewhat verbose. To get smaller files, use the two argument version of write(). The output is buffered, and is flushed and closed before exiting. Derived classes should override writeFormat and writeData rather than this method.

Parameters:
outAn output stream.

Definition at line 1607 of file PlotBox.java.

                                        {
        write(out, null);
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.write ( OutputStream  out,
String  dtd 
) [inline]

Write the current data and plot configuration to the specified stream in PlotML syntax.

PlotML is an XML scheme for plot data. The URL (relative or absolute) for the DTD is given as the second argument. If that argument is null, then the PlotML PUBLIC DTD is referenced, resulting in a file that can be read by a PlotML parser without any external file references, as long as that parser has local access to the DTD. The output is buffered, and is flushed and closed before exiting. Derived classes should override writeFormat and writeData rather than this method.

Parameters:
outAn output stream.
dtdThe reference (URL) for the DTD, or null to use the PUBLIC DTD.

Definition at line 1625 of file PlotBox.java.

                                                                 {
        write(new OutputStreamWriter(out), dtd);
    }

Here is the call graph for this function:

synchronized void ptolemy.plot.PlotBox.write ( Writer  out,
String  dtd 
) [inline]

Write the current data and plot configuration to the specified stream in PlotML syntax.

PlotML is an XML scheme for plot data. The URL (relative or absolute) for the DTD is given as the second argument. If that argument is null, then the PlotML PUBLIC DTD is referenced, resulting in a file that can be read by a PlotML parser without any external file references, as long as that parser has local access to the DTD. The output is buffered, and is flushed before exiting.

Parameters:
outAn output writer.
dtdThe reference (URL) for the DTD, or null to use the PUBLIC DTD.

Reimplemented in ptolemy.plot.Histogram.

Definition at line 1641 of file PlotBox.java.

                                                           {
        // Auto-flush is disabled.
        PrintWriter output = new PrintWriter(new BufferedWriter(out), false);

        if (dtd == null) {
            output.println("<?xml version=\"1.0\" standalone=\"yes\"?>");
            output
                    .println("<!DOCTYPE plot PUBLIC \"-//UC Berkeley//DTD PlotML 1//EN\"");
            output
                    .println("    \"http://ptolemy.eecs.berkeley.edu/xml/dtd/PlotML_1.dtd\">");
        } else {
            output.println("<?xml version=\"1.0\" standalone=\"no\"?>");
            output.println("<!DOCTYPE plot SYSTEM \"" + dtd + "\">");
        }

        output.println("<plot>");
        output.println("<!-- Ptolemy plot, version " + PTPLOT_RELEASE
                + " , PlotML format. -->");
        writeFormat(output);
        writeData(output);
        output.println("</plot>");
        output.flush();

        // NOTE: We used to close the stream, but if this is part
        // of an exportMoML operation, that is the wrong thing to do.
        // if (out != System.out) {
        //    output.close();
        // }
    }

Here is the call graph for this function:

synchronized void ptolemy.plot.PlotBox.writeData ( PrintWriter  output) [inline]

Write plot data information to the specified output stream in PlotML.

In this base class, there is no data to write, so this method returns without doing anything.

Parameters:
outputA buffered print writer.

Reimplemented in ptolemy.plot.Plot, and ptolemy.plot.Histogram.

Definition at line 1676 of file PlotBox.java.

                                                           {
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.writeFormat ( PrintWriter  output) [inline]

Write plot format information to the specified output stream in PlotML.

Derived classes should override this method to first call the parent class method, then add whatever additional format information they wish to add to the stream.

Parameters:
outputA buffered print writer.

Reimplemented in ptolemy.plot.Plot, and ptolemy.plot.Histogram.

Definition at line 1685 of file PlotBox.java.

                                                             {
        // NOTE: If you modify this, you should change the _DTD variable
        // accordingly.
        if (_title != null) {
            output.println("<title>" + _title + "</title>");
        }

        if (_xlabel != null) {
            output.println("<xLabel>" + _xlabel + "</xLabel>");
        }

        if (_ylabel != null) {
            output.println("<yLabel>" + _ylabel + "</yLabel>");
        }

        if (_xRangeGiven) {
            output.println("<xRange min=\"" + _xlowgiven + "\" max=\""
                    + _xhighgiven + "\"/>");
        }

        if (_yRangeGiven) {
            output.println("<yRange min=\"" + _ylowgiven + "\" max=\""
                    + _yhighgiven + "\"/>");
        }

        if ((_xticks != null) && (_xticks.size() > 0)) {
            output.println("<xTicks>");

            int last = _xticks.size() - 1;

            for (int i = 0; i <= last; i++) {
                output.println("  <tick label=\""
                        + (String) _xticklabels.elementAt(i) + "\" position=\""
                        + _xticks.elementAt(i) + "\"/>");
            }

            output.println("</xTicks>");
        }

        if ((_yticks != null) && (_yticks.size() > 0)) {
            output.println("<yTicks>");

            int last = _yticks.size() - 1;

            for (int i = 0; i <= last; i++) {
                output.println("  <tick label=\""
                        + (String) _yticklabels.elementAt(i) + "\" position=\""
                        + _yticks.elementAt(i) + "\"/>");
            }

            output.println("</yTicks>");
        }

        if (_xlog) {
            output.println("<xLog/>");
        }

        if (_ylog) {
            output.println("<yLog/>");
        }

        if (!_grid) {
            output.println("<noGrid/>");
        }

        if (_wrap) {
            output.println("<wrap/>");
        }

        if (!_usecolor) {
            output.println("<noColor/>");
        }
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotBox.writeOldSyntax ( OutputStream  out) [inline]

Write the current data and plot configuration to the specified stream in the old PtPlot syntax.

The output is buffered, and is flushed and closed before exiting. Derived classes should override _writeOldSyntax() rather than this method.

Parameters:
outAn output stream.
Deprecated:

Definition at line 1767 of file PlotBox.java.

                                                              {
        // Auto-flush is disabled.
        PrintWriter output = new PrintWriter(new BufferedOutputStream(out),
                false);
        _writeOldSyntax(output);
        output.flush();

        // Avoid closing standard out.
        if (out != System.out) {
            output.close();
        }
    }

Here is the call graph for this function:

synchronized void ptolemy.plot.PlotBox.zoom ( double  lowx,
double  lowy,
double  highx,
double  highy 
) [inline]

Zoom in or out to the specified rectangle.

This method calls repaint().

Parameters:
lowxThe low end of the new X range.
lowyThe low end of the new Y range.
highxThe high end of the new X range.
highyThe high end of the new Y range.

Definition at line 1787 of file PlotBox.java.

                          {
        setXRange(lowx, highx);
        setYRange(lowy, highy);
        repaint();
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Indicator of whether actions are deferred.

Definition at line 3891 of file PlotBox.java.

Color of the background, settable from HTML.

Definition at line 2885 of file PlotBox.java.

Bottom padding.

Derived classes can increment these to make space around the plot.

Definition at line 2898 of file PlotBox.java.

final Color ptolemy.plot.PlotBox._boxColor = Color.orange [static, private]

Definition at line 3903 of file PlotBox.java.

Color [] ptolemy.plot.PlotBox._colors [static, protected]
Initial value:
 { new Color(0xff0000), 
            new Color(0x0000ff), 
            new Color(0x00aaaa), 
            new Color(0x000000), 
            new Color(0xffa500), 
            new Color(0x53868b), 
            new Color(0xff7f50), 
            new Color(0x45ab1f), 
            new Color(0x90422d), 
            new Color(0xa0a0a0), 
            new Color(0x14ff14), 
    }

Definition at line 2949 of file PlotBox.java.

List of deferred actions.

Definition at line 3894 of file PlotBox.java.

Indicator that size has been set.

The document base we use to find the _filespec. NOTE: Use of this variable is deprecated. But it is made available to derived classes for backward compatibility. FIXME: Sun's appletviewer gives an exception if this is protected. Why?? So we make it temporarily public.

Definition at line 2983 of file PlotBox.java.

transient boolean ptolemy.plot.PlotBox._drawn = false [private]

Definition at line 4046 of file PlotBox.java.

transient String [] ptolemy.plot.PlotBox._errorMsg [private]

Definition at line 3969 of file PlotBox.java.

String ptolemy.plot.PlotBox._filespec = null [private]

The file to be opened.

Definition at line 3897 of file PlotBox.java.

transient JButton ptolemy.plot.PlotBox._fillButton = null [private]

Definition at line 3999 of file PlotBox.java.

Color of the foreground, settable from HTML.

Definition at line 2888 of file PlotBox.java.

transient JButton ptolemy.plot.PlotBox._formatButton = null [private]

Definition at line 4002 of file PlotBox.java.

Whether to draw a background grid.

Definition at line 2873 of file PlotBox.java.

transient double ptolemy.plot.PlotBox._gridBase = 0.0 [private]

Definition at line 3966 of file PlotBox.java.

transient int ptolemy.plot.PlotBox._gridCurJuke = 0 [private]

Definition at line 3963 of file PlotBox.java.

int ptolemy.plot.PlotBox._height = 300 [protected]

Width and height of component in pixels.

Definition at line 2966 of file PlotBox.java.

Font ptolemy.plot.PlotBox._labelFont = null [private]

Font information.

Definition at line 3942 of file PlotBox.java.

FontMetrics ptolemy.plot.PlotBox._labelFontMetrics = null [private]

FontMetric information.

Definition at line 3951 of file PlotBox.java.

int ptolemy.plot.PlotBox._leftPadding = 10 [protected]

Left padding.

Derived classes can increment these to make space around the plot.

Definition at line 2908 of file PlotBox.java.

Vector ptolemy.plot.PlotBox._legendDatasets = new Vector() [private]

Legend information.

Definition at line 3984 of file PlotBox.java.

Vector ptolemy.plot.PlotBox._legendStrings = new Vector() [private]

Legend information.

Definition at line 3981 of file PlotBox.java.

final double ptolemy.plot.PlotBox._LOG10SCALE = 1 / Math.log(10) [static, protected]

Definition at line 2870 of file PlotBox.java.

int ptolemy.plot.PlotBox._lrx = 100 [protected]

The x value of the lower right corner of the plot rectangle in pixels.

Definition at line 2921 of file PlotBox.java.

int ptolemy.plot.PlotBox._lry = 100 [protected]

The y value of the lower right corner of the plot rectangle in pixels.

Definition at line 2925 of file PlotBox.java.

double ptolemy.plot.PlotBox._originalXhigh = 0.0 [package]

Definition at line 4014 of file PlotBox.java.

double ptolemy.plot.PlotBox._originalXlow = 0.0 [package]

Definition at line 4011 of file PlotBox.java.

Definition at line 4005 of file PlotBox.java.

double ptolemy.plot.PlotBox._originalYhigh = 0.0 [package]

Definition at line 4020 of file PlotBox.java.

double ptolemy.plot.PlotBox._originalYlow = 0.0 [package]

Definition at line 4017 of file PlotBox.java.

Definition at line 4008 of file PlotBox.java.

double ptolemy.plot.PlotBox._padding = 0.05 [protected]

The factor we pad by so that we don't plot points on the axes.

Definition at line 2810 of file PlotBox.java.

transient BufferedImage ptolemy.plot.PlotBox._plotImage = null [protected]

Definition at line 4023 of file PlotBox.java.

Width and height of component in pixels.

Definition at line 2972 of file PlotBox.java.

int ptolemy.plot.PlotBox._preferredWidth = 500 [protected]

Width and height of component in pixels.

Definition at line 2969 of file PlotBox.java.

transient JButton ptolemy.plot.PlotBox._printButton = null [private]

Definition at line 4026 of file PlotBox.java.

Definition at line 2817 of file PlotBox.java.

transient JButton ptolemy.plot.PlotBox._resetButton = null [private]

Definition at line 4029 of file PlotBox.java.

int ptolemy.plot.PlotBox._rightPadding = 10 [protected]

Right padding.

Derived classes can increment these to make space around the plot.

Definition at line 2903 of file PlotBox.java.

Rectangle ptolemy.plot.PlotBox._specifiedPlotRectangle = null [protected]

User specified plot rectangle, null if none specified.

See also:
setPlotRectangle(Rectangle)

Definition at line 2930 of file PlotBox.java.

Font information.

Definition at line 3945 of file PlotBox.java.

FontMetrics ptolemy.plot.PlotBox._superscriptFontMetrics = null [private]

FontMetric information.

Definition at line 3954 of file PlotBox.java.

String ptolemy.plot.PlotBox._title [private]

The title and label strings.

Definition at line 3978 of file PlotBox.java.

Font ptolemy.plot.PlotBox._titleFont = null [private]

Font information.

Definition at line 3948 of file PlotBox.java.

FontMetrics ptolemy.plot.PlotBox._titleFontMetrics = null [private]

FontMetric information.

Definition at line 3957 of file PlotBox.java.

int ptolemy.plot.PlotBox._topPadding = 10 [protected]

Top padding.

Derived classes can increment these to make space around the plot.

Definition at line 2893 of file PlotBox.java.

int ptolemy.plot.PlotBox._ulx = 1 [protected]

The x value of the upper left corner of the plot rectangle in pixels.

Definition at line 2914 of file PlotBox.java.

int ptolemy.plot.PlotBox._uly = 1 [protected]

The y value of the upper left corner of the plot rectangle in pixels.

Definition at line 2917 of file PlotBox.java.

Indicator whether to use _colors.

Definition at line 2943 of file PlotBox.java.

int ptolemy.plot.PlotBox._width = 500 [protected]

Width and height of component in pixels.

Definition at line 2963 of file PlotBox.java.

Whether to wrap the X axis.

Definition at line 2876 of file PlotBox.java.

double ptolemy.plot.PlotBox._wrapHigh [protected]

The high range of the X axis for wrapping.

Definition at line 2879 of file PlotBox.java.

double ptolemy.plot.PlotBox._wrapLow [protected]

The low range of the X axis for wrapping.

Definition at line 2882 of file PlotBox.java.

double ptolemy.plot.PlotBox._xBottom = Double.MAX_VALUE [protected]

The minimum X value registered so for, for auto ranging.

Definition at line 2852 of file PlotBox.java.

int ptolemy.plot.PlotBox._xExp = 0 [private]

The power of ten by which the range numbers should be multiplied.

Definition at line 3933 of file PlotBox.java.

The given X and Y ranges.

If they have been given the top and bottom of the x and y ranges. This is different from _xMin and _xMax, which actually represent the range of data that is plotted. This represents the range specified (which may be different due to zooming).

Definition at line 2833 of file PlotBox.java.

String ptolemy.plot.PlotBox._xlabel [private]

The title and label strings.

Definition at line 3972 of file PlotBox.java.

Whether to draw the axes using a logarithmic scale.

Definition at line 2864 of file PlotBox.java.

double ptolemy.plot.PlotBox._xlowgiven [protected]

The given X and Y ranges.

If they have been given the top and bottom of the x and y ranges. This is different from _xMin and _xMax, which actually represent the range of data that is plotted. This represents the range specified (which may be different due to zooming).

Definition at line 2825 of file PlotBox.java.

transient double ptolemy.plot.PlotBox._xMax = 0 [protected]

Definition at line 2801 of file PlotBox.java.

transient double ptolemy.plot.PlotBox._xMin = 0 [protected]

Definition at line 2806 of file PlotBox.java.

Definition at line 2813 of file PlotBox.java.

double ptolemy.plot.PlotBox._xscale = 1.0 [protected]

Scaling used for the horizontal axis in plotting points.

The units are pixels/unit, where unit is the units of the X axis.

Definition at line 2940 of file PlotBox.java.

Vector ptolemy.plot.PlotBox._xticklabels = null [private]

If XTicks or YTicks are given/

Definition at line 3990 of file PlotBox.java.

double ptolemy.plot.PlotBox._xtickMax = 0.0 [private]

The range of the plot as labeled (multiply by 10^exp for actual range.

Definition at line 3918 of file PlotBox.java.

double ptolemy.plot.PlotBox._xtickMin = 0.0 [private]

The range of the plot as labeled (multiply by 10^exp for actual range.

Definition at line 3923 of file PlotBox.java.

Vector ptolemy.plot.PlotBox._xticks = null [private]

If XTicks or YTicks are given/

Definition at line 3987 of file PlotBox.java.

double ptolemy.plot.PlotBox._xtickscale = 0.0 [private]

Scaling used in making tick marks.

Definition at line 3939 of file PlotBox.java.

double ptolemy.plot.PlotBox._xTop = -Double.MAX_VALUE [protected]

The maximum X value registered so for, for auto ranging.

Definition at line 2855 of file PlotBox.java.

double ptolemy.plot.PlotBox._yBottom = Double.MAX_VALUE [protected]

The minimum Y value registered so for, for auto ranging.

Definition at line 2858 of file PlotBox.java.

int ptolemy.plot.PlotBox._yExp = 0 [private]

The power of ten by which the range numbers should be multiplied.

Definition at line 3928 of file PlotBox.java.

The given X and Y ranges.

If they have been given the top and bottom of the x and y ranges. This is different from _xMin and _xMax, which actually represent the range of data that is plotted. This represents the range specified (which may be different due to zooming).

Definition at line 2849 of file PlotBox.java.

String ptolemy.plot.PlotBox._ylabel [private]

The title and label strings.

Definition at line 3975 of file PlotBox.java.

Whether to draw the axes using a logarithmic scale.

Definition at line 2867 of file PlotBox.java.

double ptolemy.plot.PlotBox._ylowgiven [protected]

The given X and Y ranges.

If they have been given the top and bottom of the x and y ranges. This is different from _xMin and _xMax, which actually represent the range of data that is plotted. This represents the range specified (which may be different due to zooming).

Definition at line 2841 of file PlotBox.java.

transient double ptolemy.plot.PlotBox._yMax = 0 [protected]

Definition at line 2791 of file PlotBox.java.

transient double ptolemy.plot.PlotBox._yMin = 0 [protected]

Definition at line 2796 of file PlotBox.java.

Definition at line 2815 of file PlotBox.java.

double ptolemy.plot.PlotBox._yscale = 1.0 [protected]

Scaling used for the vertical axis in plotting points.

The units are pixels/unit, where unit is the units of the Y axis.

Definition at line 2935 of file PlotBox.java.

Vector ptolemy.plot.PlotBox._yticklabels = null [private]

If XTicks or YTicks are given/

Definition at line 3996 of file PlotBox.java.

double ptolemy.plot.PlotBox._ytickMax = 0.0 [private]

The range of the plot as labeled (multiply by 10^exp for actual range.

Definition at line 3908 of file PlotBox.java.

double ptolemy.plot.PlotBox._ytickMin = 0.0 [private]

The range of the plot as labeled (multiply by 10^exp for actual range.

Definition at line 3913 of file PlotBox.java.

Vector ptolemy.plot.PlotBox._yticks = null [private]

If XTicks or YTicks are given/

Definition at line 3993 of file PlotBox.java.

double ptolemy.plot.PlotBox._ytickscale = 0.0 [private]

Scaling used in making tick marks.

Definition at line 3936 of file PlotBox.java.

double ptolemy.plot.PlotBox._yTop = -Double.MAX_VALUE [protected]

The maximum Y value registered so for, for auto ranging.

Definition at line 2861 of file PlotBox.java.

Definition at line 4042 of file PlotBox.java.

Definition at line 4048 of file PlotBox.java.

Definition at line 4044 of file PlotBox.java.

transient int ptolemy.plot.PlotBox._zoomx = -1 [private]

Definition at line 4033 of file PlotBox.java.

transient int ptolemy.plot.PlotBox._zoomxn = -1 [private]

Definition at line 4037 of file PlotBox.java.

transient int ptolemy.plot.PlotBox._zoomy = -1 [private]

Definition at line 4035 of file PlotBox.java.

transient int ptolemy.plot.PlotBox._zoomyn = -1 [private]

Definition at line 4039 of file PlotBox.java.

final String ptolemy.plot.PlotBox.PTPLOT_RELEASE = "5.7" [static]

Definition at line 1796 of file PlotBox.java.


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