utils.ptplot5_2.ptolemy.plot
Class Histogram

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--utils.ptplot5_2.ptolemy.plot.PlotBox
                                |
                                +--utils.ptplot5_2.ptolemy.plot.Histogram
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable

public class Histogram
extends PlotBox

A histogram plotter. The plot can be configured and data can be provided either through a file with commands or through direct invocation of the public methods of the class. To read a file or a URL, use the read() method.

When calling the public methods, in most cases the changes will not be visible until paint() has been called. To request that this be done, call repaint(). One exception is addPoint(), which makes the affect of the new point visible immediately (or nearly immediately) if the plot is visible on the screen.

The ASCII format for the file 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 those supported by the base class, plus a few more. The commands are case insensitive, but are usually capitalized. The number of data sets to be plotted does not need to be specified. Data sets are added as needed. Each dataset is identified with a color (see the base class).

The appearance of the histogram can be altered by the following commands:

 Bars: width
 Bars: width, offset
 
The width is a real number specifying the width of the bars as a fraction of the bin width. It usually has a value less than or equal to one, and defaults to 0.5. The offset is a real number specifying how much the bar of the i th data set is offset from the previous one. This allows bars to "peek out" from behind the ones in front. It defaults to 0.15. Note that the frontmost data set will be the first one.

The width of each bin of the histogram can be specified using:

 BinWidth: width
 
This is given in whatever units the data has. By default, each bin is centered at x = nw, where w is the width of the bin and n is an integer. That bin represents values in the range (x - w/2, x + w/2). The alignment of the bins can be changed with the following command:
 BinOffset: offset
 
If this method is used with argument o, then each bin is centered at x = nw + o, and represents values in the range (x - w/2 + o, x + w/2 + o). So for example, if o = w/2, then each bin represents values from nw to (n + 1)w) for some integer n. The default offset is 0.5, half the default bin width.

To specify data to be plotted, start a data set with the following command:

 DataSet: string
 
Here, string is a label that will appear in the legend. It is not necessary to enclose the string in quotation marks. To start a new dataset without giving it a name, use:
 DataSet:
 
In this case, no item will appear in the legend. New datasets are plotted behind the previous ones. The data itself is given by a sequence of numbers, one per line. The numbers are specified as strings that can be parsed by the Double parser in Java. It is also possible to specify the numbers using all the formats accepted by the Plot class, so that the same data may be plotted by both classes. The x data is ignored, and only the y data is used to calculate the histogram.

Since:
Ptolemy II 0.3
Version:
$Id: Histogram.html,v 1.1.1.1 2003/07/10 12:20:41 dsagnol Exp $
Author:
Edward A. Lee
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class utils.ptplot5_2.ptolemy.plot.PlotBox
PlotBox.DragListener, PlotBox.ZoomListener
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
 
Fields inherited from class utils.ptplot5_2.ptolemy.plot.PlotBox
_documentBase, PTPLOT_RELEASE
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Histogram()
           
 
Method Summary
 void addLegend(int dataset, java.lang.String legend)
          Add a legend (displayed at the upper right) for the specified data set with the specified string.
 void addPoint(int dataset, double value)
          In the specified data set, add the specified value to the histogram.
 void addPoint(int dataset, double x, double y, boolean connected)
          In the specified data set, add the specified y value to the histogram.
 void clear(boolean format)
          Clear the plot of all data points.
 void fillPlot()
          Rescale so that the data that is currently plotted just fits.
 void samplePlot()
          Create a sample plot.
 void setBars(double width, double offset)
          Set the width and offset of the bars.
 void setBinOffset(double offset)
          Set the offset of the bins, in whatever units the data are given.
 void setBinWidth(double width)
          Set the width of the bins, in whatever units the data are given.
 void writeData(java.io.PrintWriter output)
          Write plot data information to the specified output stream in PlotML.
 void writeFormat(java.io.PrintWriter output)
          Write plot format information to the specified output stream.
 
Methods inherited from class utils.ptplot5_2.ptolemy.plot.PlotBox
addXTick, addYTick, clearLegends, deferIfNecessary, export, exportImage, exportImage, exportImage, exportImage, getColor, getColorByName, getDataurl, getDocumentBase, getGrid, getLegend, getMaximumSize, getMinimumSize, getPreferredSize, getTitle, getXLabel, getXLog, getXRange, getXTicks, getYLabel, getYLog, getYRange, getYTicks, init, paintComponent, parseFile, parseFile, print, read, read, removeLegend, resetAxes, setBackground, setBounds, setButtons, setColor, setDataurl, setDocumentBase, setForeground, setGrid, setLabelFont, setSize, setTitle, setTitleFont, setWrap, setXLabel, setXLog, setXRange, setYLabel, setYLog, setYRange, write, write, write, writeOldSyntax, zoom
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Histogram

public Histogram()
Method Detail

addLegend

public void addLegend(int dataset,
                      java.lang.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.

Overrides:
addLegend in class PlotBox
Parameters:
dataset - The dataset index.
legend - The label for the dataset.

addPoint

public void addPoint(int dataset,
                     double value)
In the specified data set, add the specified value to the histogram. Data set indices begin with zero. If the data set does not exist, create it. The new point will visibly alter the histogram if the plot is visible on the screen. Otherwise, it will be drawn the next time the histogram is drawn on the screen.

In order to work well with swing and be thread safe, this method actually defers execution to the event dispatch thread, where all user interface actions are performed. Thus, the point will not be added immediately (unless you call this method from within the event dispatch thread). All the methods that do this deferring coordinate so that they are executed in the order that you called them.

Parameters:
dataset - The data set index.
value - The new value.

addPoint

public void addPoint(int dataset,
                     double x,
                     double y,
                     boolean connected)
In the specified data set, add the specified y value to the histogram. The x value and the connected arguments are ignored. Data set indices begin with zero. If the data set does not exist, create it.

Parameters:
dataset - The data set index.
x - Ignored.
y - The Y position of the new point.
connected - Ignored

clear

public void clear(boolean format)
Clear the plot of all data points. If the argument is true, then reset all parameters to their initial conditions, including the persistence, plotting format, and axes formats. For the change to take effect, you must call repaint().

In order to work well with swing and be thread safe, this method actually defers execution to the event dispatch thread, where all user interface actions are performed. Thus, the clear will not be executed immediately (unless you call this method from within the event dispatch thread). All the methods that do this deferring coordinate so that they are executed in the order that you called them.

Overrides:
clear in class PlotBox
Parameters:
format - If true, clear the format controls as well.

fillPlot

public void fillPlot()
Rescale so that the data that is currently plotted just fits. This overrides the base class method to ensure that the fill is actually performed in the event dispatch thread. In order to work well with swing and be thread safe, this method actually defers execution to the event dispatch thread, where all user interface actions are performed. Thus, the fill will not occur immediately (unless you call this method from within the event dispatch thread). All the methods that do this deferring coordinate so that they are executed in the order that you called them.

Overrides:
fillPlot in class PlotBox

samplePlot

public void samplePlot()
Create a sample plot.

Overrides:
samplePlot in class PlotBox

setBars

public void setBars(double width,
                    double offset)
Set the width and offset of the bars. Both are specified as a fraction of a bin width. The offset is the amount by which the i < sup>th data set is shifted to the right, so that it peeks out from behind the earlier data sets.

Parameters:
width - The width of the bars.
offset - The offset per data set.

setBinOffset

public void setBinOffset(double offset)
Set the offset of the bins, in whatever units the data are given. Without calling this, each bin is centered at x = nw, where w is the width of the bin and n is an integer. That bin represents values in the range (x - w/2, x + w/2). If this method is called with argument o, then each bin is centered at x = nw + o, and represents values in the range (x - w/2 + o, x + w/2 + o). So for example, if o = w/2, then each bin represents values from nw to (n + 1)w) for some integer n.

Parameters:
offset - The bin offset.

setBinWidth

public void setBinWidth(double width)
Set the width of the bins, in whatever units the data are given.

Parameters:
width - The width of the bins.

writeData

public void writeData(java.io.PrintWriter output)
Write plot data information to the specified output stream in PlotML.

Overrides:
writeData in class PlotBox
Parameters:
output - A buffered print writer.

writeFormat

public void writeFormat(java.io.PrintWriter output)
Write plot format information to the specified output stream.

Overrides:
writeFormat in class PlotBox
Parameters:
output - A buffered print writer.