Class DataToolTab

All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible, Tool

public class DataToolTab extends JPanel implements Tool, PropertyChangeListener
This tab displays and analyzes a single Data object in a DataTool.
Version:
1.0
Author:
Douglas Brown
See Also:
  • Field Details

    • correlationFormat

      protected static DecimalFormat correlationFormat
    • dataTool

      protected DataTool dataTool
    • originatorID

      protected int originatorID
    • dataManager

      protected DatasetManager dataManager
    • splitPanes

      protected JSplitPane[] splitPanes
    • plot

    • dataTable

      protected DataToolTable dataTable
    • statsTable

      protected DataToolStatsTable statsTable
    • propsTable

      protected DataToolPropsTable propsTable
    • dataScroller

      protected JScrollPane dataScroller
    • statsScroller

      protected JScrollPane statsScroller
    • propsScroller

      protected JScrollPane propsScroller
    • tableScroller

      protected JScrollPane tableScroller
    • toolbar

      protected JToolBar toolbar
    • statsCheckbox

      protected JCheckBoxMenuItem statsCheckbox
    • propsCheckbox

      protected JCheckBoxMenuItem propsCheckbox
    • fourierCheckbox

      protected JCheckBoxMenuItem fourierCheckbox
    • fourierPanel

      protected FourierPanel fourierPanel
    • fourierDialog

      protected JDialog fourierDialog
    • measureButton

      protected JButton measureButton
    • analyzeButton

      protected JButton analyzeButton
    • dataBuilderButton

      protected JButton dataBuilderButton
    • newColumnButton

      protected JButton newColumnButton
    • refreshDataButton

      protected JButton refreshDataButton
    • valueCheckbox

      protected JCheckBoxMenuItem valueCheckbox
    • slopeCheckbox

      protected JCheckBoxMenuItem slopeCheckbox
    • areaCheckbox

      protected JCheckBoxMenuItem areaCheckbox
    • showFitterAction

      protected Action showFitterAction
    • hideFitterAction

      protected Action hideFitterAction
    • propsAndStatsAction

      protected Action propsAndStatsAction
    • fitMenu

      protected JMenu fitMenu
    • fileName

      protected String fileName
    • ownerName

      protected String ownerName
    • ownedColumns

      protected Map<String,String[]> ownedColumns
    • helpButton

      protected JButton helpButton
    • editDataButton

      protected JButton editDataButton
    • colorIndex

      protected int colorIndex
    • tabChanged

      protected boolean tabChanged
    • userEditable

      protected boolean userEditable
    • undoSupport

      protected UndoableEditSupport undoSupport
    • undoManager

      protected UndoManager undoManager
    • dataBuilder

      protected FunctionTool dataBuilder
    • jobManager

      protected JobManager jobManager
    • statusLabel

      protected JLabel statusLabel
    • editableLabel

      protected JLabel editableLabel
    • plotAxes

      protected DataToolTab.DataToolAxes plotAxes
    • positionVisible

      protected boolean positionVisible
    • slopeVisible

      protected boolean slopeVisible
    • areaVisible

      protected boolean areaVisible
    • originShiftEnabled

      protected boolean originShiftEnabled
    • originShiftJustEnabled

      protected boolean originShiftJustEnabled
    • measureFit

      protected boolean measureFit
    • varPopup

      protected JPopupMenu varPopup
    • isHorzVarPopup

      protected boolean isHorzVarPopup
    • setVarAction

      protected Action setVarAction
    • isInitialized

      protected boolean isInitialized
    • constantsLoadedFromXML

      protected Object[][] constantsLoadedFromXML
    • replaceColumnsWithMatchingNames

      protected boolean replaceColumnsWithMatchingNames
    • measureFitCheckbox

      protected JCheckBoxMenuItem measureFitCheckbox
    • originShiftCheckbox

      protected JCheckBoxMenuItem originShiftCheckbox
    • prevShiftX

      protected double prevShiftX
    • prevShiftY

      protected double prevShiftY
    • shiftXField

      protected org.opensourcephysics.tools.DatasetCurveFitter.NumberField shiftXField
    • shiftYField

      protected org.opensourcephysics.tools.DatasetCurveFitter.NumberField shiftYField
    • selectedXField

      protected org.opensourcephysics.tools.DatasetCurveFitter.NumberField selectedXField
    • selectedYField

      protected org.opensourcephysics.tools.DatasetCurveFitter.NumberField selectedYField
    • shiftXSpinner

      protected JSpinner shiftXSpinner
    • shiftYSpinner

      protected JSpinner shiftYSpinner
    • shiftEditListener

      protected org.opensourcephysics.tools.DataToolTab.ShiftEditListener shiftEditListener
    • shiftXLabel

      protected JLabel shiftXLabel
    • shiftYLabel

      protected JLabel shiftYLabel
    • selectedXLabel

      protected JLabel selectedXLabel
    • selectedYLabel

      protected JLabel selectedYLabel
    • selectedDataIndex

      protected int selectedDataIndex
    • toggleMeasurement

      protected boolean toggleMeasurement
    • freezeMeasurement

      protected boolean freezeMeasurement
  • Constructor Details

    • DataToolTab

      public DataToolTab(Data data, DataTool tool)
      Constructs a DataToolTab for the specified Data.
      Parameters:
      data - the Data object
      tool - the DataTool
  • Method Details

    • getCurveFitter

      public DatasetCurveFitter getCurveFitter()
    • addNotify

      public void addNotify()
      Overrides:
      addNotify in class JComponent
    • checkGUI

      public void checkGUI()
    • loadData

      public ArrayList<DataColumn> loadData(Data data, boolean replaceIfSameName)
      Loads data into this tab.
      Parameters:
      data - the data to load
      replaceIfSameName - true to replace existing data, if any
      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(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
    • setWorkingColumns

      public void setWorkingColumns(String xColName, 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(String name)
      Overrides:
      setName in class Component
    • setUserEditable

      public void setUserEditable(boolean editable)
      Sets the userEditable flag.
      Parameters:
      editable - true to enable user editing
    • isUserEditable

      public boolean isUserEditable()
      Returns true if this tab is user editable.
      Returns:
      true if user editable
    • getDataBuilder

      public FunctionTool getDataBuilder()
      Gets the data builder for defining custom data functions.
      Returns:
      the data builder
    • propertyChange

      public void propertyChange(PropertyChangeEvent e)
      Listens for property change "function".
      Specified by:
      propertyChange in interface PropertyChangeListener
      Parameters:
      e - the event
    • send

      public void send(Job job, Tool replyTo)
      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)
    • 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(boolean postEdit)
      Clears all data.
      Parameters:
      postEdit - true to post an undoable edit
    • setReplaceColumnsWithMatchingNames

      public void setReplaceColumnsWithMatchingNames(boolean replace)
      Sets the replaceColumnsWithMatchingNames flag.
      Parameters:
      replace - true to replace columns with same name but different ID
    • isInterestedIn

      public boolean isInterestedIn(Data data)
      Returns true if this tab is interested in a Data object.
      Parameters:
      data - the Data object
      Returns:
      true if data is of interest
    • setOwnedColumnIDs

      public boolean setOwnedColumnIDs(String columnOwnerName, Data data)
      Sets DataColumn IDs to corresponding column owner IDs based on saved names. Call this after loading this tab from XML to set column IDs to column owner IDs.
      Parameters:
      columnOwnerName - the guest name
      data - the guest Data
      Returns:
      true if any column IDs were changed
    • saveOwnedColumnNames

      public void saveOwnedColumnNames(String columnOwnerName, Data data)
      Saves DataColumn names with associated column owner and Data object. Call this before saving this tab so owned columns will be saved in XML.
      Parameters:
      columnOwnerName - the guest name
      data - the guest Data
    • getColumnName

      public String getColumnName(int ID)
      Gets the column name for the first DataColumn with a given ID.
      Parameters:
      ID - the ID number of the desired column
      Returns:
      the tab column name, or null if not found
    • isOwnedBy

      public 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
    • setOwner

      public void setOwner(String name, Data data)
      Sets the owner of this tab. This method is used before saving and after loading this tab so the tab can refresh its data from a new owner.
      Parameters:
      name - the owner name
      data - the owner Data
    • getOwnerName

      public String getOwnerName()
      Gets the name of the owner of this tab. May return null, even if an owner exists.
      Returns:
      the name of the owner
    • refreshData

      public void refreshData()
      Refreshes the data by sending a request to the source. Note that this only works if the data was received from a DataRefreshTool.
    • addColumn

      protected void addColumn(DataColumn column)
      Adds a DataColumn to this tab.
      Parameters:
      column - the column to add
    • isDeletable

      protected boolean isDeletable(Dataset data)
      Determines if a dataset is deletable.
      Parameters:
      data - the dataset
      Returns:
      true if deletable
    • replaceSpacesWithUnderscores

      protected String replaceSpacesWithUnderscores(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)
    • columnNameChanged

      protected void columnNameChanged(String oldName, 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
    • saveTableDataToFile

      protected String saveTableDataToFile(boolean asFormatted)
      Saves the selected table data to a file selected with a fileChooser.
      Returns:
      the path of the saved file or null if failed
    • copyTableDataToClipboard

      protected void copyTableDataToClipboard(boolean asFormatted)
      Copies the selected table data to the clipboard.
    • getSelectedTableData

      protected String getSelectedTableData(boolean asFormatted, String delimiter)
      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.
      Parameters:
      asFormatted - true to return formatted data
      delimiter - the columns delimiter to use
      Returns:
      a String containing the data.
    • createGUI

      protected void createGUI()
      Creates the GUI.
    • columnOrderChanged

      protected void columnOrderChanged()
    • mouseDraggedAction

      protected void mouseDraggedAction(MouseEvent e, boolean controlDown, boolean shiftDown)
    • mouseReleasedAction

      protected void mouseReleasedAction(MouseEvent e, boolean controlDown, boolean shiftDown)
    • mousePressedAction

      protected void mousePressedAction(MouseEvent e, boolean controlDown, boolean shiftDown)
    • refreshGUI

      protected void refreshGUI()
      Refreshes the GUI.
    • refreshGUIAsync

      protected void refreshGUIAsync()
    • refreshDecimalSeparators

      protected void refreshDecimalSeparators()
      Refreshes the decimal separators.
    • buildVarPopup

      protected void buildVarPopup()
      Builds the axis variables popup menu.
    • isDuplicateColumn

      protected boolean isDuplicateColumn(String name, double[] data)
      Returns true if the name and data duplicate an existing column. Never called.
      Parameters:
      name - the name
      data - the data array
      Returns:
      true if a duplicate is found
    • getColumnMatchesByID

      protected Map<DataColumn,Dataset> getColumnMatchesByID(Data data)
      Gets datasets matching columns by ID in this tab.
      Parameters:
      data - Data object with datasets to match
      Returns:
      map of column to dataset
    • getColumnMatchesByName

      protected Map<DataColumn,Dataset> getColumnMatchesByName(Set<String> columnNames, Data data)
      Gets datasets matching columns by name in this tab.
      Parameters:
      columnNames - set of column names
      data - Data object with datasets to match
      Returns:
      map of column to dataset
    • getMatchByName

      protected Dataset getMatchByName(DataColumn column, ArrayList<Dataset> datasets)
      Gets a matching Dataset by name.
      Parameters:
      column - the DataColumn to match
      datasets - the Datasets to search
      Returns:
      the matching Dataset
    • getMatchByID

      protected Dataset getMatchByID(DataColumn column, ArrayList<Dataset> datasets)
      Gets a matching Dataset by ID.
      Parameters:
      column - the DataColumn to match
      datasets - the Datasets to search
      Returns:
      the matching Dataset
    • setDelimitedData

      protected boolean setDelimitedData(String dataString, String prevString) throws Exception
      Sets the table data to the specified delimited text. Posts an undoable edit if prevString is given.
      Parameters:
      dataString - the delimited text
      prevString - optional previous delimited text for undoable edit
      Returns:
      true if an undoable edit was posted
      Throws:
      Exception
    • setSelectedData

      protected void setSelectedData(Dataset selectedData, boolean dofit)
      Sets the selected data in the curve fitter and fourier panel.
      Parameters:
      selectedData - the Dataset to pass to the fitter and fourier panel
    • refreshPlot

      protected void refreshPlot()
    • refreshPlot

      protected void refreshPlot(boolean andFit)
      Refreshes the plot.
    • refreshStatusBar

      protected void refreshStatusBar(String hint)
      Refreshes the status bar.
      Parameters:
      hint - an optional hint to display (may be null)
    • getCorrelationString

      protected String getCorrelationString()
      Gets a correlation string to display in the status bar.
    • refreshShiftFields

      public double refreshShiftFields()
      Refreshes the origin shift fields.
      Returns:
      the current y-field shift
    • refreshAll

      public void refreshAll(int mode)
      Refreshes all.
    • refreshUndoItems

      protected void refreshUndoItems()
      Refreshes the undo and redo menu items.
    • postShiftEdit

      protected void postShiftEdit()
    • getLoader

      public static XML.ObjectLoader getLoader()
      Returns an ObjectLoader to save and load data for this class.
      Returns:
      the object loader
    • findNearestXIndex

      public static int findNearestXIndex(double x, double[] xpoints, double[] ypoints, int len, double min, double max)
      Far more efficient method of searching a sparse array. Just track the closest point, running linearly through the array. See test.PerformanceTests.findNearestXIndex.
      Parameters:
      x -
      xpoints -
      ypoints -
      len -
      min -
      max -
      Returns:
    • removeNotify

      public void removeNotify()
      This Component has been detacched from its parent. Presumption here is that it can be disposed.
      Overrides:
      removeNotify in class JComponent
    • dispose

      public void dispose()
    • finalize

      public void finalize()
      Overrides:
      finalize in class Object