org.opensourcephysics.tools
Class DataToolTab

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 org.opensourcephysics.tools.DataToolTab
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.beans.PropertyChangeListener, java.io.Serializable, java.rmi.Remote, java.util.EventListener, javax.accessibility.Accessible, Tool
Direct Known Subclasses:
FourierToolTab

public class DataToolTab
extends javax.swing.JPanel
implements Tool, java.beans.PropertyChangeListener

This tab displays and analyzes a single Data object in a DataTool.

Version:
1.0
Author:
Douglas Brown
See Also:
Serialized Form

Nested Class Summary
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  javax.swing.JCheckBox areaCheckbox
           
protected  boolean areaVisible
           
protected  javax.swing.Action bottomPaneAction
           
protected  javax.swing.JCheckBox bottomPaneCheckbox
           
protected  int colorIndex
           
protected  DatasetCurveFitter curveFitter
           
protected  FunctionTool dataBuilder
           
protected  javax.swing.JButton dataBuilderButton
           
protected  DatasetManager dataManager
           
protected  DataToolTable dataTable
           
protected  DataTool dataTool
           
protected  java.lang.String fileName
           
protected  int fontLevel
           
protected  javax.swing.JButton helpButton
           
protected static java.lang.String helpName
           
protected  boolean isHorzVarPopup
           
protected  boolean isInitialized
           
protected  JobManager jobManager
           
protected  javax.swing.JButton newColumnButton
           
protected  int originatorID
           
protected  org.opensourcephysics.tools.DataToolTab.DataToolPlotter plot
           
protected  CartesianInteractive plotAxes
           
protected  boolean positionVisible
           
protected  javax.swing.Action propsAndStatsAction
           
protected  javax.swing.JCheckBox propsCheckbox
           
protected  javax.swing.JScrollPane propsScroller
           
protected  DataToolPropsTable propsTable
           
protected  javax.swing.JButton refreshDataButton
           
protected  javax.swing.Action setVarAction
           
protected  javax.swing.JCheckBox slopeCheckbox
           
protected  boolean slopeVisible
           
protected  javax.swing.JSplitPane[] splitPanes
           
protected  javax.swing.JCheckBox statsCheckbox
           
protected  javax.swing.JScrollPane statsScroller
           
protected  DataToolStatsTable statsTable
           
protected  javax.swing.JLabel statusLabel
           
protected  boolean tabChanged
           
protected  javax.swing.JToolBar toolbar
           
protected  javax.swing.undo.UndoManager undoManager
           
protected  javax.swing.undo.UndoableEditSupport undoSupport
           
protected  boolean userEditable
           
protected  javax.swing.JCheckBox valueCheckbox
           
protected  javax.swing.JPopupMenu varPopup
           
 
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
DataToolTab(Data data)
          Constructs a DataToolTab for the specified Data.
 
Method Summary
protected  void addColumn(DataColumn column)
          Adds a DataColumn to this tab.
protected  void addColumns(java.util.ArrayList<DataColumn> columns, boolean deletable, boolean addDuplicates, boolean postEdit)
          Adds DataColumns to this tab.
 void addColumns(Data source, boolean deletable, boolean addDuplicates, boolean postEdit)
          Adds new dataColumns to this tab.
 void addFitFunction(KnownFunction f, boolean addToFitBuilder)
          Adds a fit function.
 void clearData()
           
protected  void columnNameChanged(java.lang.String oldName, java.lang.String newName)
          Responds to a changed column name.
protected  Dataset copy(Dataset source, Dataset target, boolean includeDataAndID)
          Copies a dataset.
protected  void copyTableDataToClipboard()
          Copies the selected table data to the clipboard.
protected  DataColumn createDataColumn()
          Creates a new empty DataColumn.
protected  void createGUI()
          Creates the GUI.
 FunctionTool getDataBuilder()
          Gets the data builder for defining custom data functions.
static XML.ObjectLoader getLoader()
          Returns an ObjectLoader to save and load data for this class.
protected  java.lang.String getSelectedTableData()
          Gets the table cells selected by the user.
protected  java.lang.String getUniqueYColumnName(Dataset d, java.lang.String proposed, boolean askUser)
          Returns a column name that is unique to this tab, contains no spaces, and is not reserved by the OSP parser.
protected  org.opensourcephysics.tools.DataToolTable.WorkingDataset getWorkingData()
          Gets the working dataset.
protected  boolean isDeletable(Dataset data)
          Determines if a dataset is deletable.
protected  boolean isDuplicateColumn(java.lang.String name, double[] data)
          Returns true if the name and data duplicate an existing column.
protected  boolean isDuplicateName(Dataset d, java.lang.String name)
          Returns true if name is a duplicate of an existing dataset.
protected  boolean isOwnedBy(Data data)
          Returns true if (a) the Data ID is this tab owner's ID or (b) the Data name is this tab's name.
protected  boolean isReservedName(java.lang.String name)
          Returns true if name is reserved by the OSP parser.
 java.util.ArrayList<DataColumn> loadData(Data data)
          Loads data into this tab.
 void propertyChange(java.beans.PropertyChangeEvent e)
          Listens for property change "function".
protected  void refreshDataBuilder()
          Refreshes the data builder.
protected  void refreshGUI()
          Refreshes the GUI.
protected  void refreshPlot()
          Refreshes the plot.
protected  void refreshStatusBar()
          Refreshes the status bar.
protected  java.lang.String replaceSpacesWithUnderscores(java.lang.String name)
          Replaces spaces with underscores in a name.
protected  java.lang.String saveTableDataToFile()
          Saves the selected table data to a file.
 void send(Job job, Tool replyTo)
          Sends a job to this tool and specifies a tool to reply to.
protected  void setFontLevel(int level)
          Sets the font level.
 void setName(java.lang.String name)
          Overrides Component.setName();
 void setUserEditable(boolean editable)
          Sets the userEditable flag.
 void setWorkingColumns(java.lang.String xColName, java.lang.String yColName)
          Sets the x and y columns by name.
protected  void tabChanged(boolean changed)
          Sets the tabChanged flag.
 
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, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, 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, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, 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, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setSize, 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

helpName

protected static java.lang.String helpName

dataTool

protected DataTool dataTool

originatorID

protected int originatorID

dataManager

protected DatasetManager dataManager

splitPanes

protected javax.swing.JSplitPane[] splitPanes

plot

protected org.opensourcephysics.tools.DataToolTab.DataToolPlotter plot

dataTable

protected DataToolTable dataTable

statsTable

protected DataToolStatsTable statsTable

propsTable

protected DataToolPropsTable propsTable

statsScroller

protected javax.swing.JScrollPane statsScroller

propsScroller

protected javax.swing.JScrollPane propsScroller

toolbar

protected javax.swing.JToolBar toolbar

statsCheckbox

protected javax.swing.JCheckBox statsCheckbox

bottomPaneCheckbox

protected javax.swing.JCheckBox bottomPaneCheckbox

propsCheckbox

protected javax.swing.JCheckBox propsCheckbox

curveFitter

protected DatasetCurveFitter curveFitter

dataBuilderButton

protected javax.swing.JButton dataBuilderButton

newColumnButton

protected javax.swing.JButton newColumnButton

refreshDataButton

protected javax.swing.JButton refreshDataButton

valueCheckbox

protected javax.swing.JCheckBox valueCheckbox

slopeCheckbox

protected javax.swing.JCheckBox slopeCheckbox

areaCheckbox

protected javax.swing.JCheckBox areaCheckbox

bottomPaneAction

protected javax.swing.Action bottomPaneAction

propsAndStatsAction

protected javax.swing.Action propsAndStatsAction

fileName

protected java.lang.String fileName

helpButton

protected javax.swing.JButton helpButton

colorIndex

protected int colorIndex

tabChanged

protected boolean tabChanged

userEditable

protected boolean userEditable

undoSupport

protected javax.swing.undo.UndoableEditSupport undoSupport

undoManager

protected javax.swing.undo.UndoManager undoManager

dataBuilder

protected FunctionTool dataBuilder

fontLevel

protected int fontLevel

jobManager

protected JobManager jobManager

statusLabel

protected javax.swing.JLabel statusLabel

plotAxes

protected CartesianInteractive plotAxes

positionVisible

protected boolean positionVisible

slopeVisible

protected boolean slopeVisible

areaVisible

protected boolean areaVisible

varPopup

protected javax.swing.JPopupMenu varPopup

isHorzVarPopup

protected boolean isHorzVarPopup

setVarAction

protected javax.swing.Action setVarAction

isInitialized

protected boolean isInitialized
Constructor Detail

DataToolTab

public DataToolTab(Data data)
Constructs a DataToolTab for the specified Data.

Parameters:
data - the Data object
Method Detail

loadData

public java.util.ArrayList<DataColumn> loadData(Data data)
Loads data into this tab.

Parameters:
data - the data to load
Returns:
true if loaded

addColumns

public void addColumns(Data source,
                       boolean deletable,
                       boolean addDuplicates,
                       boolean postEdit)
Adds new dataColumns to this tab.

Parameters:
source - the Data source of the columns
deletable - true to allow added columns to be deleted
addDuplicates - true to add duplicate IDs
postEdit - true to post an undoable edit

addColumns

protected void addColumns(java.util.ArrayList<DataColumn> columns,
                          boolean deletable,
                          boolean addDuplicates,
                          boolean postEdit)
Adds DataColumns to this tab.

Parameters:
columns - the columns to add
deletable - true to allow added columns to be deleted
addDuplicates - true to add duplicate IDs
postEdit - true to post an undoable edit

addColumn

protected void addColumn(DataColumn column)
Adds a DataColumn to this tab.

Parameters:
column - the column to add

setWorkingColumns

public void setWorkingColumns(java.lang.String xColName,
                              java.lang.String yColName)
Sets the x and y columns by name.

Parameters:
xColName - the name of the horizontal axis variable
yColName - the name of the vertical axis variable

setName

public void setName(java.lang.String name)
Overrides Component.setName();

Overrides:
setName in class java.awt.Component
Parameters:
name - the name

setUserEditable

public void setUserEditable(boolean editable)
Sets the userEditable flag.

Parameters:
editable - true to enable user editing

isDeletable

protected boolean isDeletable(Dataset data)
Determines if a dataset is deletable.

Parameters:
data - the dataset
Returns:
true if deletable

getDataBuilder

public FunctionTool getDataBuilder()
Gets the data builder for defining custom data functions.


propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Listens for property change "function".

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
e - the event

send

public void send(Job job,
                 Tool replyTo)
          throws java.rmi.RemoteException
Sends a job to this tool and specifies a tool to reply to.

Specified by:
send in interface Tool
Parameters:
job - the Job
replyTo - the tool to notify when the job is complete (may be null)
Throws:
java.rmi.RemoteException

addFitFunction

public void addFitFunction(KnownFunction f,
                           boolean addToFitBuilder)
Adds a fit function. UserFunctions can optionally be added to the fit builder.

Parameters:
f - the fit function to add
addToFitBuilder - true to add a UserFunction to the fit builder

clearData

public void clearData()

replaceSpacesWithUnderscores

protected java.lang.String replaceSpacesWithUnderscores(java.lang.String name)
Replaces spaces with underscores in a name.

Parameters:
name - the name with spaces
Returns:
the name with underscores

refreshDataBuilder

protected void refreshDataBuilder()
Refreshes the data builder.


setFontLevel

protected void setFontLevel(int level)
Sets the font level.

Parameters:
level - the level

tabChanged

protected void tabChanged(boolean changed)
Sets the tabChanged flag.

Parameters:
changed - true if tab is changed

getWorkingData

protected org.opensourcephysics.tools.DataToolTable.WorkingDataset getWorkingData()
Gets the working dataset.

Returns:
the first two data columns in the datatable (x-y order)

getUniqueYColumnName

protected java.lang.String getUniqueYColumnName(Dataset d,
                                                java.lang.String proposed,
                                                boolean askUser)
Returns a column name that is unique to this tab, contains no spaces, and is not reserved by the OSP parser.

Parameters:
d - the dataset
proposed - the proposed name for the column
askUser - true to ask user to approve changes
Returns:
unique name

isDuplicateName

protected boolean isDuplicateName(Dataset d,
                                  java.lang.String name)
Returns true if name is a duplicate of an existing dataset.

Parameters:
d - the dataset
name - the proposed name for the dataset
Returns:
true if duplicate

isReservedName

protected boolean isReservedName(java.lang.String name)
Returns true if name is reserved by the OSP parser.

Parameters:
name - the proposed name
Returns:
true if reserved

columnNameChanged

protected void columnNameChanged(java.lang.String oldName,
                                 java.lang.String newName)
Responds to a changed column name.

Parameters:
oldName - the previous name
newName - the new name

createDataColumn

protected DataColumn createDataColumn()
Creates a new empty DataColumn.

Returns:
the column

copy

protected Dataset copy(Dataset source,
                       Dataset target,
                       boolean includeDataAndID)
Copies a dataset. If includeDataAndID is false, only the name and display properties are copied.

Parameters:
source - the source dataset
target - the target dataset (may be null)
includeDataAndID - true to copy data and ID
Returns:
the copy

saveTableDataToFile

protected java.lang.String saveTableDataToFile()
Saves the selected table data to a file.

Returns:
the path of the saved file or null if failed

copyTableDataToClipboard

protected void copyTableDataToClipboard()
Copies the selected table data to the clipboard.


getSelectedTableData

protected java.lang.String getSelectedTableData()
Gets the table cells selected by the user. The tab name and column names precede the data. Data rows are delimited by new lines ("\n"), columns by tabs.

Returns:
a String containing the data.

createGUI

protected void createGUI()
Creates the GUI.


refreshGUI

protected void refreshGUI()
Refreshes the GUI.


isDuplicateColumn

protected boolean isDuplicateColumn(java.lang.String name,
                                    double[] data)
Returns true if the name and data duplicate an existing column.

Parameters:
name - the name
data - the data array
Returns:
true if a duplicate is found

isOwnedBy

protected boolean isOwnedBy(Data data)
Returns true if (a) the Data ID is this tab owner's ID or (b) the Data name is this tab's name.

Parameters:
data - the Data object
Returns:
true if data owns this tab

refreshPlot

protected void refreshPlot()
Refreshes the plot.


refreshStatusBar

protected void refreshStatusBar()
Refreshes the status bar.


getLoader

public static XML.ObjectLoader getLoader()
Returns an ObjectLoader to save and load data for this class.

Returns:
the object loader