All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class ptplot.PlotBox

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----ptplot.PlotBox

public class PlotBox
extends Panel
Construct 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. Zooming out stops automatically at the point where the data fills the drawing rectangle. The box can be configured either through a file with commands or through direct invocation of the public methods of the class. If a file is used, the file can be given as a URL through the setDataurl method. The file contains 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.

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.

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
 
All of the above commands can also be invoked directly by calling the the corresponding public methods from some Java procedure.

Version:
@(#)PlotBox.java 1.66 10/30/97
Author:
Edward A. Lee, Christopher Hylands

Variable Index

 o _background
 o _bottomPadding
 o _colors
 o _debug
 o _foreground
 o _graphics
 o _grid
 o _height
 o _leftPadding
 o _lrx
 o _lry
 o _rightPadding
 o _topPadding
 o _ulx
 o _uly
 o _usecolor
 o _width
 o _xBottom
 o _xMax
 o _xMin
 o _xRangeGiven
 o _xscale
 o _xTop
 o _yBottom
 o _yMax
 o _yMin
 o _yRangeGiven
 o _yscale
 o _yTop

Constructor Index

 o PlotBox()

Method Index

 o _drawPoint(Graphics, int, long, long, boolean)
Put a mark corresponding to the specified dataset at the specified x and y position.
 o _newFile()
Hook for child classes to do any file preprocessing
 o _parseBinaryStream(DataInputStream)
Hook to parse a binary stream.
 o _parseLine(String)
Parse a line that gives plotting information.
 o _setButtonsVisibility(boolean)
Set the visibility of the Fill button.
 o action(Event, Object)
Handle button presses to fill the plot. Deprecated.
 o addLegend(int, String)
Add a legend (displayed at the upper right) for the specified data set with the specified string.
 o addNotify()
Create the peer of the plot box.
 o addXTick(String, double)
Specify a tick mark for the X axis.
 o addYTick(String, double)
Specify a tick mark for the Y axis.
 o drawPlot(Graphics, boolean)
Draw the axes using the current range, label, and title information.
 o fillPlot()
Rescales so that the data that is currently plotted just fits.
 o fillPlot(Graphics)
Rescales so that the data that is currently plotted just fits.
 o getColorByName(String)
Convert a color name into a Color.
 o getDataurl()
Get the dataurl.
 o getDocumentBase()
Get the document base
 o getFontByName(String)
Get the Font by name. Deprecated.
 o getLegend(int)
Get the legend for a dataset.
 o getMinimumSize()
Get the minimum size of this component.
 o getPreferredSize()
Get the preferred size of this component.
 o init()
Initialize the component, creating the fill button and setting the colors.
 o minimumSize()
The minimum size. Deprecated.
 o mouseDown(Event, int, int)
Set the starting point for an interactive zoom box. Deprecated.
 o mouseDrag(Event, int, int)
Draw a box for an interactive zoom box. Deprecated.
 o mouseUp(Event, int, int)
Zoom in or out based on the box that has been drawn. Deprecated.
 o paint(Graphics)
Paint the component contents, which in this base class is only the axes.
 o parseFile(String)
Syntactic sugar for parseFile(dataurl, documentBase);
 o parseFile(String, URL)
Open up the input file, which could be stdin, a URL or a file.
 o preferredSize()
The preferred size. Deprecated.
 o reshape(int, int, int, int)
Reshape
 o resize(int, int)
Resize the plot. Deprecated.
 o setBackground(Color)
Set the background color.
 o setBinary(boolean)
Set the binary flag to true if we are reading pxgraph format binary data.
 o setDataurl(String)
Set the dataurl.
 o setDebug(int)
Set the debug value.
 o setDocumentBase(URL)
Set the document base so that we can find the dataurl.
 o setForeground(Color)
Set the foreground color.
 o setGrid(boolean)
Control whether the grid is drawn.
 o setLabelFont(String)
Set the label font, which is used for axis labels and legend labels.
 o setTitle(String)
Set the title of the graph.
 o setTitleFont(String)
Set the title font.
 o setXLabel(String)
Set the label for the X (horizontal) axis.
 o setXRange(double, double)
Set the X (horizontal) range of the plot.
 o setYLabel(String)
Set the label for the Y (vertical) axis.
 o setYRange(double, double)
Set the Y (vertical) range of the plot.

Variables

 o _debug
 protected int _debug
 o _graphics
 protected Graphics _graphics
 o _yMax
 protected double _yMax
 o _yMin
 protected double _yMin
 o _xMax
 protected double _xMax
 o _xMin
 protected double _xMin
 o _xRangeGiven
 protected boolean _xRangeGiven
 o _yRangeGiven
 protected boolean _yRangeGiven
 o _xBottom
 protected double _xBottom
 o _xTop
 protected double _xTop
 o _yBottom
 protected double _yBottom
 o _yTop
 protected double _yTop
 o _grid
 protected boolean _grid
 o _background
 protected Color _background
 o _foreground
 protected Color _foreground
 o _topPadding
 protected int _topPadding
 o _bottomPadding
 protected int _bottomPadding
 o _rightPadding
 protected int _rightPadding
 o _leftPadding
 protected int _leftPadding
 o _ulx
 protected int _ulx
 o _uly
 protected int _uly
 o _lrx
 protected int _lrx
 o _lry
 protected int _lry
 o _yscale
 protected double _yscale
 o _xscale
 protected double _xscale
 o _usecolor
 protected boolean _usecolor
 o _colors
 protected static Color _colors[]
 o _width
 protected int _width
 o _height
 protected int _height

Constructors

 o PlotBox
 public PlotBox()

Methods

 o action
 public boolean action(Event evt,
                       Object arg)
Note: action() is deprecated. As of JDK1.1 in java.awt.component but we need to compile under 1.0.2 for netscape3.x compatibility.

Handle button presses to fill the plot. This rescales so that the data that is currently plotted just fits.

Overrides:
action in class Component
 o addNotify
 public void addNotify()
Create the peer of the plot box.

Overrides:
addNotify in class Panel
 o addLegend
 public void addLegend(int dataset,
                       String legend)
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. You must call init() before calling this method.

 o addXTick
 public void addXTick(String label,
                      double position)
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.

 o addYTick
 public void addYTick(String label,
                      double position)
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.

 o drawPlot
 public synchronized void drawPlot(Graphics graphics,
                                   boolean clearfirst)
Draw the axes using the current range, label, and title information. If the argument is true, clear the display before redrawing.

 o fillPlot
 public synchronized void fillPlot()
Rescales so that the data that is currently plotted just fits.

 o fillPlot
 public synchronized void fillPlot(Graphics graphics)
Rescales so that the data that is currently plotted just fits.

 o getFontByName
 public Font getFontByName(String fullfontname)
Note: getFontByName() is deprecated. : As of JDK1.1, use Font.decode() instead. We need to compile under JDK1.0.2, so we use this method.

Get the Font by name.

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

 o getDataurl
 public String getDataurl()
Get the dataurl.

 o getDocumentBase
 public URL getDocumentBase()
Get the document base

 o getLegend
 public String getLegend(int dataset)
Get the legend for a dataset.

 o getMinimumSize
 public Dimension getMinimumSize()
Get the minimum size of this component.

Overrides:
getMinimumSize in class Container
 o getPreferredSize
 public Dimension getPreferredSize()
Get the preferred size of this component.

Overrides:
getPreferredSize in class Container
 o init
 public void init()
Initialize the component, creating the fill button and setting the colors. If the dataurl has been set, then parse that file.

 o minimumSize
 public Dimension minimumSize()
Note: minimumSize() is deprecated. As of JDK1.1 in java.awt.component, but we need to compile under 1.0.2 for netscape3.x compatibility.

The minimum size.

Overrides:
minimumSize in class Container
 o mouseDown
 public boolean mouseDown(Event evt,
                          int x,
                          int y)
Note: mouseDown() is deprecated. As of JDK1.1 in java.awt.component but we need to compile under 1.0.2 for netscape3.x compatibility.

Set the starting point for an interactive zoom box.

Overrides:
mouseDown in class Component
 o mouseDrag
 public synchronized boolean mouseDrag(Event evt,
                                       int x,
                                       int y)
Note: mouseDrag() is deprecated. As of JDK1.1 in java.awt.component but we need to compile under 1.0.2 for netscape3.x compatibility.

Draw a box for an interactive zoom box. Return a boolean indicating whether or not we have dealt with the event.

Overrides:
mouseDrag in class Component
 o mouseUp
 public synchronized boolean mouseUp(Event evt,
                                     int x,
                                     int y)
Note: mouseUp() is deprecated. As of JDK1.1 in java.awt.component but we need to compile under 1.0.2 for netscape3.x compatibility.

Zoom in or out based on the box that has been drawn.

Overrides:
mouseUp in class Component
 o paint
 public void paint(Graphics graphics)
Paint the component contents, which in this base class is only the axes.

Overrides:
paint in class Container
 o parseFile
 public void parseFile(String dataurl)
Syntactic sugar for parseFile(dataurl, documentBase);

 o parseFile
 public void parseFile(String dataurl,
                       URL documentBase)
Open up the input file, which could be stdin, a URL or a file. This code can be called from an application, which means that getDocumentBase() might fail.

 o preferredSize
 public Dimension preferredSize()
Note: preferredSize() is deprecated. As of JDK1.1 in java.awt.component, but we need to compile under 1.0.2 for netscape3.x compatibility.

The preferred size.

Overrides:
preferredSize in class Container
 o reshape
 public void reshape(int x,
                     int y,
                     int width,
                     int height)
Reshape

Overrides:
reshape in class Component
 o resize
 public void resize(int width,
                    int height)
Note: resize() is deprecated. As of JDK1.1 in java.awt.component, but we need to compile under 1.0.2 for netscape3.x compatibility.

Resize the plot.

Overrides:
resize in class Component
 o setBackground
 public void setBackground(Color background)
Set the background color.

Overrides:
setBackground in class Component
 o setDebug
 public void setDebug(int debug)
Set the debug value. The higher the integer, the greater the number of debugging messages printed to stdout. Useful values are 10 - argument parsing, 20 - legend parsing, 101 - data point debugging.

 o setForeground
 public void setForeground(Color foreground)
Set the foreground color.

Overrides:
setForeground in class Component
 o setBinary
 public void setBinary(boolean binary)
Set the binary flag to true if we are reading pxgraph format binary data.

 o setDataurl
 public void setDataurl(String dataurl)
Set the dataurl.

 o setDocumentBase
 public void setDocumentBase(URL documentBase)
Set the document base so that we can find the dataurl.

 o setGrid
 public void setGrid(boolean grid)
Control whether the grid is drawn.

 o setLabelFont
 public void setLabelFont(String fullfontname)
Set the label font, which is used for axis labels and legend labels.

 o setTitle
 public void setTitle(String title)
Set the title of the graph. The title will appear on the subsequent call to paint() or drawPlot().

 o setTitleFont
 public void setTitleFont(String fullfontname)
Set the title font.

 o setXLabel
 public void setXLabel(String label)
Set the label for the X (horizontal) axis. The label will appear on the subsequent call to paint() or drawPlot().

 o setXRange
 public void setXRange(double min,
                       double max)
Set the X (horizontal) range of the plot. If this is not done explicitly, then the range is computed automatically from data available when paint() or drawPlot() are called. If min and max are identical, then the range is arbitrarily spread by 1.

 o setYLabel
 public void setYLabel(String label)
Set the label for the Y (vertical) axis. The label will appear on the subsequent call to paint() or drawPlot().

 o setYRange
 public void setYRange(double min,
                       double max)
Set the Y (vertical) range of the plot. If this is not done explicitly, then the range is computed automatically from data available when paint() or drawPlot() are called. If min and max are identical, then the range is arbitrarily spread by 0.1.

 o _drawPoint
 protected 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. 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.

 o _newFile
 protected void _newFile()
Hook for child classes to do any file preprocessing

 o _parseBinaryStream
 protected void _parseBinaryStream(DataInputStream in) throws PlotDataException, IOException
Hook to parse a binary stream.

Throws: PlotDataException
if there is a serious data format problem.
Throws: IOException
if an I/O error occurs.
 o _parseLine
 protected boolean _parseLine(String line)
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.

 o _setButtonsVisibility
 protected void _setButtonsVisibility(boolean vis)
Set the visibility of the Fill button.


All Packages  Class Hierarchy  This Package  Previous  Next  Index