Class DatasetManager

java.lang.Object
org.opensourcephysics.display.DataTable.DataModel
org.opensourcephysics.display.DatasetManager
All Implemented Interfaces:
Data, Drawable, LogMeasurable, Measurable

public class DatasetManager extends DataTable.DataModel implements Measurable, LogMeasurable, Data
DatasetManager maintains a list of datasets. Datasets are added automatically to this DatasetCollection by calling a method in this DatasetManager with a dataset index greater than the maximum value for the dataset index that has been used previously. For example the statements: DatasetManager datasetManager = new DatasetManager(); datasetManager.append(0,3,4); datasetManager.append(1,5,6); appends the point (3,4) to the 0th dataset (and creates this dataset automatically) and appends the point (5,6) to the 1-st dataset (and also creates this dataset automatically).
Version:
1.1
Author:
Joshua Gould, Wolfgang Christian
  • Field Details

  • Constructor Details

    • DatasetManager

      public DatasetManager()
      DatasetManager constructor.
    • DatasetManager

      public DatasetManager(boolean linked)
      DatasetManager constructor.
      Parameters:
      linked -
    • DatasetManager

      public DatasetManager(boolean _connected, boolean _sorted)
      DatasetManager constructor specifying whether points are connected and sorted.
      Parameters:
      _connected - Description of Parameter
      _sorted - Description of Parameter
    • DatasetManager

      public DatasetManager(boolean _connected, boolean _sorted, boolean _linked, int _markerShape)
      DatasetManager constructor specifying whether points are connected, sorted, and the marker shape.
      Parameters:
      _connected - Description of Parameter
      _sorted - Description of Parameter
      _linked -
      _markerShape - Description of Parameter
  • Method Details

    • setXPointsLinked

      public void setXPointsLinked(boolean _linked)
      Sets the linked flag. X data for datasets > 0 will not be shown in a table view.
      Parameters:
      _linked - The new value
    • isXPointsLinked

      public boolean isXPointsLinked()
      Gets the linked flag.
      Returns:
      true if linked
    • setSorted

      public void setSorted(int datasetIndex, boolean _sorted)
      Sets the sorted flag. Data is sorted by increasing x.
      Parameters:
      datasetIndex - The new sorted value
      _sorted - true<\code> to sort
    • setSorted

      public void setSorted(boolean _sorted)
      Sets the sorted flag for all datasets.
      Parameters:
      _sorted -
    • setConnected

      public void setConnected(int datasetIndex, boolean _connected)
      Sets the data connected flag. Points are connected by straight lines.
      Parameters:
      datasetIndex - The new connected value
      _connected - true<\code> if points are connected
    • setConnected

      public void setConnected(boolean _connected)
      Sets the connected flag for all datasets.
      Parameters:
      _connected - true if connected; false otherwise
    • setStride

      public void setStride(int datasetIndex, int stride)
      Sets the stride for the given dataset.
      Parameters:
      datasetIndex - The new markerColor value
      stride -
    • setStride

      public void setStride(int _stride)
      Sets the stride for all datasets.
      Parameters:
      _stride -
    • setMarkerColor

      public void setMarkerColor(int datasetIndex, Color _markerColor)
      Sets the data point marker color.
      Parameters:
      datasetIndex -
      _markerColor -
    • setMarkerColor

      public void setMarkerColor(int datasetIndex, Color fillColor, Color edgeColor)
      Sets the data point marker's fill and edge color.
      Parameters:
      datasetIndex -
      fillColor -
      edgeColor -
    • setMarkerShape

      public void setMarkerShape(int datasetIndex, int _markerShape)
      Sets the data point marker shape. Shapes are: NO_MARKER, CIRCLE, SQUARE, AREA, PIXEL, BAR, POST
      Parameters:
      datasetIndex -
      _markerShape -
    • setCustomMarker

      public void setCustomMarker(int datasetIndex, Shape marker)
      Sets a custom marker shape.
      Parameters:
      datasetIndex - int
      marker - Shape
    • setXColumnVisible

      public void setXColumnVisible(int datasetIndex, boolean visible)
      Sets the visibility of the x column in a table view.
      Parameters:
      datasetIndex -
      visible -
    • setYColumnVisible

      public void setYColumnVisible(int datasetIndex, boolean visible)
      Sets the visibility of the y column in a table view.
      Parameters:
      datasetIndex -
      visible -
    • setMarkerSize

      public void setMarkerSize(int datasetIndex, int _markerSize)
      Sets the half-width of the data point marker.
      Parameters:
      datasetIndex -
      _markerSize - in pixels
    • setLineColor

      public void setLineColor(int datasetIndex, Color _lineColor)
      Sets the color of the lines connecting data points.
      Parameters:
      datasetIndex -
      _lineColor -
    • getLineColors

      public Color[] getLineColors()
      Line colors for Data interface.
      Specified by:
      getLineColors in interface Data
      Returns:
      color array
    • getFillColors

      public Color[] getFillColors()
      Fill colors for Data interface.
      Specified by:
      getFillColors in interface Data
      Returns:
      color array
    • setXYColumnNames

      public void setXYColumnNames(int datasetIndex, String xColumnName, String yColumnName, String datsetName)
      Sets the column names when rendering this dataset in a JTable.
      Parameters:
      datasetIndex -
      xColumnName -
      yColumnName -
      datsetName -
    • setXYColumnNames

      public void setXYColumnNames(int datasetIndex, String xColumnName, String yColumnName)
      Sets the column names when rendering this dataset in a JTable.
      Parameters:
      datasetIndex -
      xColumnName -
      yColumnName -
    • isMeasured

      public boolean isMeasured()
      Gets the valid measure flag. The measure is valid if the min and max values have been set for at least one dataset.
      Specified by:
      isMeasured in interface Measurable
      Returns:
      true<\code> if measure is valid
    • setID

      public void setID(int id)
      Sets the ID number of this Data.
      Specified by:
      setID in interface Data
      Parameters:
      id - the ID number
    • getID

      public int getID()
      Returns a unique identifier for this Data.
      Specified by:
      getID in interface Data
      Returns:
      the ID number
    • getXMin

      public double getXMin()
      Gets the x world coordinate for the left hand side of the panel.
      Specified by:
      getXMin in interface Measurable
      Returns:
      xmin
    • getXMinLogscale

      public double getXMinLogscale()
      Description copied from interface: LogMeasurable
      Gets the minimum x needed to draw this object on a log scale.
      Specified by:
      getXMinLogscale in interface LogMeasurable
      Returns:
      minimum
    • getXMax

      public double getXMax()
      Gets the x world coordinate for the right hand side of the panel.
      Specified by:
      getXMax in interface Measurable
      Returns:
      xmax
    • getXMaxLogscale

      public double getXMaxLogscale()
      Description copied from interface: LogMeasurable
      Gets the maximum x needed to draw this object on a log scale.
      Specified by:
      getXMaxLogscale in interface LogMeasurable
      Returns:
      maximum
    • getYMin

      public double getYMin()
      Gets y world coordinate for the bottom of the panel.
      Specified by:
      getYMin in interface Measurable
      Returns:
      ymin
    • getYMinLogscale

      public double getYMinLogscale()
      Description copied from interface: LogMeasurable
      Gets the minimum y needed to draw this object on a log scale.
      Specified by:
      getYMinLogscale in interface LogMeasurable
      Returns:
      minimum
    • getYMax

      public double getYMax()
      Gets y world coordinate for the top of the panel.
      Specified by:
      getYMax in interface Measurable
      Returns:
      ymax
    • getYMaxLogscale

      public double getYMaxLogscale()
      Description copied from interface: LogMeasurable
      Gets the maximum y needed to draw this object on a log scale on a log scale.
      Specified by:
      getYMaxLogscale in interface LogMeasurable
      Returns:
      maximum
    • getXPoints

      public double[] getXPoints(int datasetIndex)
      Gets a copy of the xpoints array.
      Parameters:
      datasetIndex - Description of Parameter
      Returns:
      xpoints[]
    • getYPoints

      public double[] getYPoints(int datasetIndex)
      Gets a copy of the ypoints array.
      Parameters:
      datasetIndex - Description of Parameter
      Returns:
      ypoints[]
    • isSorted

      public boolean isSorted(int datasetIndex)
      Gets the sorted flag.
      Parameters:
      datasetIndex - Description of Parameter
      Returns:
      true<\code> if the data is sorted
    • isConnected

      public boolean isConnected(int datasetIndex)
      Gets the data connected flag.
      Parameters:
      datasetIndex - Description of Parameter
      Returns:
      true<\code> if points are connected
    • getColumnCount

      public int getColumnCount()
      Gets the number of columns for rendering in a JTable.
      Specified by:
      getColumnCount in class DataTable.DataModel
      Returns:
      the count
    • getRowCount

      public int getRowCount()
      Gets the number of rows for rendering in a JTable.
      Specified by:
      getRowCount in class DataTable.DataModel
      Returns:
      the count
    • getName

      public String getName()
      Gets the name of this data.
      Specified by:
      getName in interface Data
      Returns:
      name
    • setName

      public void setName(String name)
      Sets the name of this data.
      Parameters:
      name -
    • getColumnName

      public String getColumnName(int tableColumnIndex)
      Gets the name of the column for rendering in a JTable
      Specified by:
      getColumnName in class DataTable.DataModel
      Parameters:
      tableColumnIndex -
      Returns:
      the name
    • getValueAt

      public double getValueAt(int row, int col)
      Specified by:
      getValueAt in class DataTable.DataModel
    • append

      public void append(int datasetIndex, double x, double y)
      Appends an (x,y) datum to the Dataset with the given index.
      Parameters:
      x -
      y -
      datasetIndex - Description of Parameter
    • append

      public void append(int datasetIndex, double x, double y, double delx, double dely)
      Appends a data point and its uncertainty to the Dataset. (not used)
      Parameters:
      datasetIndex -
      x -
      y -
      delx -
      dely -
    • append

      public void append(int datasetIndex, double[] xpoints, double[] ypoints)
      Appends (x,y) arrays to the Dataset.
      Parameters:
      xpoints -
      ypoints -
      datasetIndex - Description of Parameter
    • append

      public void append(int datasetIndex, double[] xpoints, double[] ypoints, double[] delx, double[] dely)
      Appends arrays of data points and uncertainties to the Dataset.
      Parameters:
      datasetIndex -
      xpoints -
      ypoints -
      delx -
      dely -
    • draw

      public void draw(DrawingPanel drawingPanel, Graphics g)
      Draws this Dataset in the drawing panel.
      Specified by:
      draw in interface Drawable
      Parameters:
      drawingPanel -
      g -
    • clear

      public void clear(int datasetIndex)
      Clears all data from Dataset with the given datasetIndex.
      Parameters:
      datasetIndex - Description of Parameter
    • clear

      public void clear()
      Clears all data from all Datasets. Dataset properties are preserved because only the data is cleared.
    • removeDatasets

      public void removeDatasets()
      Removes all Datasets from the manager. New datasets will be created with default properties as needed.
    • getDataset

      public Dataset getDataset(int datasetIndex)
      Gets a dataset with the given index.
      Parameters:
      datasetIndex -
      Returns:
      the index
    • getDatasets

      public final ArrayList<Dataset> getDatasets()
      Gets a shallow clone of the dataset list. Implements Data.
      Specified by:
      getDatasets in interface Data
      Returns:
      cloned list
    • getDatasetsRaw

      public final ArrayList<Dataset> getDatasetsRaw()
    • getDataList

      public List<Data> getDataList()
      Some objects (eg, a Group) do not contain data, but a list of Data objects that do. This method is used by Data displaying tools to create as many pages as needed.
      Specified by:
      getDataList in interface Data
      Returns:
      a list of Data objects, or null if this object contains data
    • getColumnNames

      public String[] getColumnNames()
      The column names to be used in the data display tool
      Specified by:
      getColumnNames in interface Data
      Returns:
      string array
    • getData2D

      public double[][] getData2D()
      Gets a 2D array of data. Implements Data.
      Specified by:
      getData2D in interface Data
      Returns:
      double[][]
    • getData3D

      public double[][][] getData3D()
      Gets a 3D array of data. Implements Data.
      Specified by:
      getData3D in interface Data
      Returns:
      double[][][]
    • addDataset

      public int addDataset(Dataset dataset)
      Adds a dataset. Method added by Doug Brown 2007-1-15.
      Parameters:
      dataset - the Dataset to add
      Returns:
      the index of the added dataset
    • removeDataset

      public Dataset removeDataset(int index)
      Removes the dataset at the specified index. Method added by Doug Brown 1/15/2007.
      Parameters:
      index - the index
      Returns:
      the removed dataset, or null if none removed
    • getDatasetIndex

      public int getDatasetIndex(String yColumnName)
      Returns the index of the first dataset with the specified y column name. Method added by Doug Brown 1/15/2007.
      Parameters:
      yColumnName - the y column name
      Returns:
      the index, or -1 if none found
    • getConstantNames

      public ArrayList<String> getConstantNames()
    • getConstantValue

      public Double getConstantValue(String name)
      Returns the value of a constant. Added by Doug Brown 3/24/2011.
      Parameters:
      name - the name of the constant
      Returns:
      Double value of the constant, or null if not defined
    • getConstantExpression

      public String getConstantExpression(String name)
      Returns the expression of a constant. Added by Doug Brown 3/24/2011.
      Parameters:
      name - the name of the constant
      Returns:
      the expression, or null if not defined
    • getConstantDescription

      public String getConstantDescription(String name)
      Returns the description of a constant. Added by Doug Brown 11/23/14.
      Parameters:
      name - the name of the constant
      Returns:
      the description, or null if not defined
    • setConstant

      public void setConstant(String name, double val, String expression)
      Sets the value of a constant. Added by Doug Brown 3/24/2011. modified 11/23/14.
      Parameters:
      name - the name of the constant
      val - the value of the constant
      expression - the expression that defines the value
    • setConstant

      public void setConstant(String name, double val, String expression, String desc)
      Sets the value of a constant. Added by Doug Brown 11/23/14.
      Parameters:
      name - the name of the constant
      val - the value of the constant
      expression - the expression that defines the value
      desc - the description of the constant (may be null)
    • clearConstant

      public void clearConstant(String name)
      Clears a constant. Added by Doug Brown 3/24/2011, modified 11/23/14.
      Parameters:
      name - the name of the constant
    • toString

      public String toString()
      Create a string representation of the data.
      Overrides:
      toString in class Object
      Returns:
      a String of data
    • setXYColumnNames

      public void setXYColumnNames(String _xColumnName, String _yColumnName)
      Sets the column names for all datasets when rendering this dataset in a JTable.
      Parameters:
      _xColumnName -
      _yColumnName -
    • checkDatasetIndex

      protected void checkDatasetIndex(int datasetIndex)
      Ensures capacity
      Parameters:
      datasetIndex -
    • getLoader

      public static XML.ObjectLoader getLoader()
      Returns the XML.ObjectLoader for this class.
      Returns:
      the object loader
    • getFrameDataset

      public Dataset getFrameDataset()
    • isDuplicateName

      public boolean isDuplicateName(Dataset d, 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
    • getUniqueYColumnName

      public String getUniqueYColumnName(Component c, Dataset d, String proposed)
      Returns a column name that is provided by the user and is unique to this tab, contains no spaces, and is not reserved by the OSP parser.
      Parameters:
      d - the dataset
      proposed - the proposed name to be offered to the user, or null
      Returns:
      unique name
    • uniquifyColumnName

      public String uniquifyColumnName(Dataset d, String name)
    • get

      public double get(String var, int row, int col)