Class PlotLive

  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by ptolemy.plot.PlotBox
                      extended by ptolemy.plot.Plot
                          extended by ptolemy.plot.PlotLive
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable,, java.lang.Runnable, javax.accessibility.Accessible

public abstract class PlotLive
extends Plot
implements java.lang.Runnable

Plot signals dynamically, where points can be added at any time and the display will be updated. This should be normally used with some finite persistence so that old points are erased as new points are added. Unfortunately, the most efficient way to erase old points is to draw graphics using the "exclusive or" mode, which introduces quite a number of artifacts. When lines are drawn between points, where they overlap the points the line becomes white. Moreover, if two lines or points overlap completely, they disappear.

This class is abstract, so it must be used by creating a derived class. To use it, create a derived class with an addPoints() method. Your class may also set graph parameters like titles and axis labels in the constructor by calling methods in the Plot or PlotBox classes (both of which are base classes). The addPoints() method should call addPoint() of the Plot base class to dynamically add points to the plot. This method is called within a thread separate from the applet thread, so the zooming mechanism and buttons remain live.

Ptolemy II 0.2
$Id: 57040 2010-01-27 20:52:32Z cxh $
Edward A. Lee, Christopher Brooks, Contributor: Jeff Lane
See Also:
Serialized Form
Accepted Rating:
Yellow (cxh)
Proposed Rating:
Yellow (cxh)

Nested Class Summary
(package private)  class PlotLive.StartButtonListener
(package private)  class PlotLive.StopButtonListener
Nested classes/interfaces inherited from class ptolemy.plot.PlotBox
PlotBox.ButtonListener, PlotBox.CommandListener, PlotBox.DragListener, PlotBox.ZoomListener
Nested classes/interfaces inherited from class javax.swing.JPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
Nested classes/interfaces inherited from class java.awt.Container
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
Field Summary
private  boolean _paused
private  java.lang.Thread _plotLiveThread
private  boolean _plotting
private  javax.swing.JButton _startButton
private  javax.swing.JButton _stopButton
Fields inherited from class ptolemy.plot.Plot
_currentdataset, _marks, _points
Fields inherited from class ptolemy.plot.PlotBox
_background, _bottomPadding, _colors, _documentBase, _foreground, _grid, _height, _leftPadding, _LOG10SCALE, _lrx, _lry, _originalXhigh, _originalXlow, _originalXRangeGiven, _originalYhigh, _originalYlow, _originalYRangeGiven, _padding, _plotImage, _preferredHeight, _preferredWidth, _rangesGivenByZooming, _rightPadding, _specifiedPlotRectangle, _topPadding, _ulx, _uly, _usecolor, _wrap, _wrapHigh, _wrapLow, _xBottom, _xhighgiven, _xlog, _xlowgiven, _xMax, _xMin, _xRangeGiven, _xscale, _xTop, _yBottom, _yhighgiven, _ylog, _ylowgiven, _yMax, _yMin, _yRangeGiven, _yscale, _yTop, PTPLOT_RELEASE
Fields inherited from class javax.swing.JComponent
Fields inherited from class java.awt.Component
Fields inherited from interface java.awt.print.Printable
Fields inherited from interface java.awt.image.ImageObserver
Constructor Summary
Method Summary
abstract  void addPoints()
          Redefine in derived classes to add points to the plot.
 void makeButtons()
 void pause()
          Pause the plot.
 void run()
          This is the body of a thread that repeatedly calls addPoints() if the plot is active.
 void setButtons(boolean visible)
          If the argument is true, make a start, stop, and fill button visible at the upper right.
 void start()
          Make the plot active.
 void stop()
          Stop the plot.
Methods inherited from class ptolemy.plot.Plot
_checkDatasetIndex, _drawBar, _drawErrorBar, _drawImpulse, _drawLine, _drawLine, _drawPlot, _drawPoint, _parseLine, _resetScheduledTasks, _scheduledRedraw, _setWidth, _writeOldSyntax, addLegend, addPoint, addPointWithErrorBars, clear, clear, erasePoint, fillPlot, getConnected, getImpulses, getLineStyles, getMarksStyle, getMaxDataSets, getNumDataSets, getReuseDatasets, markDisconnections, parseFile, read, samplePlot, setBars, setBars, setConnected, setConnected, setImpulses, setImpulses, setLineStyle, setLineStyles, setMarksStyle, setMarksStyle, setNumSets, setPointsPersistence, setReuseDatasets, setXPersistence, writeData, writeFormat
Methods inherited from class ptolemy.plot.PlotBox
_automaticRescale, _drawPlot, _help, _setButtonsVisibility, _setPadding, _timedRepaint, _zoom, _zoomBox, _zoomStart, addCaptionLine, addXTick, addYTick, clearCaptions, clearLegends, deferIfNecessary, destroy, export, exportImage, exportImage, exportImage, exportImage, getCaptions, getColor, getColorByName, getColors, getDataurl, getDocumentBase, getGrid, getLegend, getLegendDataset, getPlotRectangle, getPreferredSize, getTitle, getXAutoRange, getXLabel, getXLog, getXRange, getXTicks, getYAutoRange, getYLabel, getYLog, getYRange, getYTicks, init, paintComponent, parseFile, print, read, removeLegend, renameLegend, resetAxes, setAutomaticRescale, setBackground, setBounds, setCaptions, setColor, setColors, setDataurl, setDocumentBase, setForeground, setGrid, setLabelFont, setPlotRectangle, setSize, setTimedRepaint, setTitle, setTitleFont, setWrap, setXLabel, setXLog, setXRange, setYLabel, setYLog, setYRange, write, write, write, writeOldSyntax, zoom
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail


private java.lang.Thread _plotLiveThread


private boolean _plotting


private boolean _paused


private javax.swing.JButton _startButton


private javax.swing.JButton _stopButton
Constructor Detail


public PlotLive()
Method Detail


public abstract void addPoints()
Redefine in derived classes to add points to the plot. Adding many points at once will make the plot somewhat faster because the thread yields between calls to this method. However, the plot will also be somewhat less responsive to user inputs such as zooming, filling, or stopping. In the derived-class implementation, this method should probably be synchronized.

Jeff Lane points out that if the derived class version of addPoints() does not return quickly, and it seems like then you may want to experiment with addPoints() to not being synchronized.


public void makeButtons()

Make start and stop buttons. This method is deprecated. Use setButtons() instead.


public void pause()
Pause the plot. To resume, call start().


public void run()
This is the body of a thread that repeatedly calls addPoints() if the plot is active. To make the plot active, call start(). To pause the plot, call pause(). To stop the plot and destroy the thread, call stop(). The next time start() is called, a new thread will be started. Between calls to addPoints(), this method calls Thread.yield() so that the thread does not hog all the resources. This somewhat slows down execution, so derived classes may wish to plot quite a few points in their addPoints() method, if possible. However, plotting more points at once may also decrease the responsiveness of the user interface.

Specified by:
run in interface java.lang.Runnable


public void setButtons(boolean visible)
If the argument is true, make a start, stop, and fill button visible at the upper right. Otherwise, make the buttons invisible. NOTE: The buttons may infringe on the title space, if the title is long. In an application, it is preferable to provide a menu with the commands. This way, when printing the plot, the printed plot will not have spurious buttons. Thus, this method should be used only by applets, which normally do not have menus.

setButtons in class PlotBox
See Also:


public void start()
Make the plot active. Start a new thread if necessary.


public void stop()
Stop the plot. The plot thread exits. This should be called by an applet's stop() method.