ptolemy.plot
Class EditablePlot

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--ptolemy.plot.PlotBox
                                |
                                +--ptolemy.plot.Plot
                                      |
                                      +--ptolemy.plot.EditablePlot
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
SpectrumPlot

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,v 1.4 2002/12/17 21:39:53 pjc Exp $
Author:
Edward A. Lee
See Also:
Serialized Form

Inner Class Summary
 class EditablePlot.UL
           
 
Inner classes inherited from class ptolemy.plot.PlotBox
PlotBox.DragListener, PlotBox.ZoomListener
 
Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
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, _padding, _preferredHeight, _preferredWidth, _rangesGivenByZooming, _rightPadding, _sizeHasBeenSet, _topPadding, _ulx, _uly, _usecolor, _width, _wrap, _wrapHigh, _wrapLow, _xBottom, _xExp, _xhighgiven, _xlog, _xlowgiven, _xMax, _xMin, _xRangeGiven, _xscale, _xTop, _yBottom, _yExp, _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.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
EditablePlot()
          Constructor.
 
Method Summary
 void addEditListener(EditListener listener)
          Add a listener to be informed when the user modifies a data set.
 void edit(int x, int y)
           
 void editPoint(int x, int y)
           
 void editStart(int x, int y)
           
 double[][] getData(int dataset)
          Get the data in the specified dataset.
 java.util.Vector getDataAsPlotPoints(int dataset)
           
 void redo()
          Redo the latest signal editing operation that was undone by calling undo(), if there was one.
 void removeDataset(int idx)
           
 void removeEditListener(EditListener listener)
          Unregister a edit listener.
 void setData(int dataset, double[][] data)
           
 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, _drawPlot, _drawPoint, _parseLine, _writeOldSyntax, addLegend, addPoint, addPointWithErrorBars, clear, clear, erasePoint, fillPlot, fillPlotX, fillPlotY, getConnected, getImpulses, getMarksStyle, getMaxDataSets, getNumDataSets, parseFile, samplePlot, setBars, setBars, setConnected, setConnected, setImpulses, setImpulses, setMarksStyle, setMarksStyle, setNumSets, setPointsPersistence, setReuseDatasets, setXPersistence, writeData, writeFormat
 
Methods inherited from class ptolemy.plot.PlotBox
_drawPlot, _help, _setButtonsVisibility, _setPadding, addXTick, addYTick, clearLegend, clearLegends, deferIfNecessary, 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, read, read, removeLegend, resetAxes, setBackground, setBounds, setButtons, setColor, setDataurl, setDocumentBase, setForeground, setGrid, setLabelFont, setSize, setTitle, setTitleFont, setWrap, setXLabel, setXLog, setXRange, setYLabel, setYLog, setYRange, updateLegend, write, write, write, writeOldSyntax, zoom
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, 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, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.

getDataAsPlotPoints

public java.util.Vector getDataAsPlotPoints(int 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.

editPoint

public void editPoint(int x,
                      int y)

editStart

public void editStart(int x,
                      int y)

edit

public void edit(int x,
                 int y)

setData

public void setData(int dataset,
                    double[][] data)

removeDataset

public void removeDataset(int idx)