ptolemy.plot
Class EditablePlot

java.lang.Object
  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.EditablePlot
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable, javax.accessibility.Accessible

public class EditablePlot
extends Plot

This extension of Plot permits interactive modification of plotted data, one dataset at a time. By default, you can modify dataset number zero (the first one given). To change this default, call setEditable(). To edit a plot, use the right mouse button. Click and drag to the left to trace out new values for the data. To read back the modified data, use getData(). To undo a change to the data, type Control-Z. To redo the change, type Control-Y. The undo history is infinite.

The style of editing is very particular. This class assumes the data specify a function of x. I.e., there there is exactly one y value for every x value. Thus, with the right mouse button, you are allowed to trace out new y values starting with some leftmost x value. You can only trace values to the right. This feature makes it easy to trace values with discontinuities. Just start at the left, and drag to the right to the point of the discontinuity, then drag to the left, then right again. You will have to try it... Notice that this style of editing probably does not make sense with error bars, since there is no mechanism for editing the error bars.

To be able to modify the data in a dataset, of course, there must be data in the dataset. Thus, you should create a dataset (for example by calling addPoint()) before editing it. Only the visible part of the dataset can be edited (that is, the portion of the dataset along the visible part of the horizontal axis). If you zoom in, then, you can edit particular points more precisely.

To be notified when the user sketches a new signal, create an object that implements the EditListener interface and add that listener using addEditListener().

Since:
Ptolemy II 0.4
Version:
$Id: EditablePlot.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Nested Class Summary
 class EditablePlot.EditMouseListener
           
 class EditablePlot.ModifyListener
           
 class EditablePlot.UndoListener
           
 
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
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  int _currentEditX
           
private  int _currentEditY
           
private  int _dataset
           
private static java.awt.Color _editColor
           
private  java.util.Vector _editListeners
           
private  boolean[] _editSpecSet
           
private  int[] _editSpecX
           
private  int[] _editSpecY
           
private  java.util.Stack _redoStack
           
private  java.util.Stack _undoStack
           
 
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
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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
EditablePlot()
          Constructor.
 
Method Summary
private  void _edit(int x, int y)
           
private  void _editPoint(int x, int y)
           
private  void _editStart(int x, int y)
           
private  void _notifyListeners(int dataset)
           
private  void _setData(int dataset, double[][] data)
           
 void addEditListener(EditListener listener)
          Add a listener to be informed when the user modifies a data set.
 double[][] getData(int dataset)
          Get the data in the specified dataset.
 void redo()
          Redo the latest signal editing operation that was undone by calling undo(), if there was one.
 void removeEditListener(EditListener listener)
          Unregister a edit listener.
 void setEditable(int dataset)
          Specify which dataset is editable.
 void undo()
          Undo the latest signal editing operation, if there was one.
 
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, setButtons, 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

_editSpecX

private int[] _editSpecX

_editSpecY

private int[] _editSpecY

_editSpecSet

private boolean[] _editSpecSet

_currentEditX

private int _currentEditX

_currentEditY

private int _currentEditY

_dataset

private int _dataset

_editColor

private static final java.awt.Color _editColor

_undoStack

private java.util.Stack _undoStack

_redoStack

private java.util.Stack _redoStack

_editListeners

private java.util.Vector _editListeners
Constructor Detail

EditablePlot

public EditablePlot()
Constructor.

Method Detail

addEditListener

public void addEditListener(EditListener listener)
Add a listener to be informed when the user modifies a data set.

Parameters:
listener - The listener.
See Also:
EditListener

getData

public double[][] getData(int dataset)
Get the data in the specified dataset. This is returned as a two-dimensional array, where the first index specifies X or Y data (index 0 or 1 respectively), and the second index specifies the point.

Returns:
The data in the specified dataset.

redo

public void redo()
Redo the latest signal editing operation that was undone by calling undo(), if there was one. Otherwise, do nothing.


removeEditListener

public void removeEditListener(EditListener listener)
Unregister a edit listener. If the specified listener has not been previously registered, then do nothing.

Parameters:
listener - The listener to remove from the list of listeners to which edit events are sent.

setEditable

public void setEditable(int dataset)
Specify which dataset is editable. By default, if this method is not called, dataset number zero is editable. If you call this method with a negative number, then no dataset will be editable.

Parameters:
dataset - The editable dataset.

undo

public void undo()
Undo the latest signal editing operation, if there was one. Otherwise, do nothing.


_edit

private void _edit(int x,
                   int y)

_editPoint

private void _editPoint(int x,
                        int y)

_editStart

private void _editStart(int x,
                        int y)

_notifyListeners

private void _notifyListeners(int dataset)

_setData

private void _setData(int dataset,
                      double[][] data)