org.opensourcephysics.display
Class DatasetManager

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.opensourcephysics.display.DatasetManager
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel, Data, Drawable, LogMeasurable, Measurable

public class DatasetManager
extends javax.swing.table.AbstractTableModel
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
See Also:
Serialized Form

Constructor Summary
DatasetManager()
          DatasetManager constructor.
DatasetManager(boolean linked)
          DatasetManager constructor.
DatasetManager(boolean _connected, boolean _sorted)
          DatasetManager constructor specifying whether points are connected and sorted.
DatasetManager(boolean _connected, boolean _sorted, boolean _linked, int _markerShape)
          DatasetManager constructor specifying whether points are connected, sorted, and the marker shape.
 
Method Summary
 int addDataset(Dataset dataset)
          Adds a dataset.
 void append(int datasetIndex, double[] xpoints, double[] ypoints)
          Appends (x,y) arrays to the Dataset.
 void append(int datasetIndex, double[] xpoints, double[] ypoints, double[] delx, double[] dely)
          Appends arrays of data points and uncertainties to the Dataset.
 void append(int datasetIndex, double x, double y)
          Appends an (x,y) datum to the Dataset with the given index.
 void append(int datasetIndex, double x, double y, double delx, double dely)
          Appends a data point and its uncertainty to the Dataset.
 void clear()
          Clears all data from all Datasets.
 void clear(int datasetIndex)
          Clears all data from Dataset with the given datasetIndex.
 void clearConstant(java.lang.String name)
          Clears a constant.
 void draw(DrawingPanel drawingPanel, java.awt.Graphics g)
          Draws this Dataset in the drawing panel.
 java.lang.Class<java.lang.Double> getColumnClass(int columnIndex)
          Gets the type of object for JTable entry.
 int getColumnCount()
          Gets the number of columns for rendering in a JTable.
 java.lang.String getColumnName(int tableColumnIndex)
          Gets the name of the column for rendering in a JTable
 java.lang.String[] getColumnNames()
          The column names to be used in the data display tool
 java.lang.String getConstantExpression(java.lang.String name)
          Returns the expression of a constant.
 java.lang.String[] getConstantNames()
          Returns the constant names.
 java.lang.Double getConstantValue(java.lang.String name)
          Returns the value of a constant.
 double[][] getData2D()
          Gets a 2D array of data.
 double[][][] getData3D()
          Gets a 3D array of data.
 java.util.List<Data> getDataList()
          Some objects (eg, a Group) do not contain data, but a list of Data objects that do.
 Dataset getDataset(int datasetIndex)
          Gets a dataset with the given index.
 int getDatasetIndex(java.lang.String yColumnName)
          Returns the index of the first dataset with the specified y column name.
 java.util.ArrayList<Dataset> getDatasets()
          Gets a shallow clone of the dataset list.
 java.awt.Color[] getFillColors()
          Fill colors for Data interface.
 int getID()
          Returns a unique identifier for this Data.
 java.awt.Color[] getLineColors()
          Line colors for Data interface.
static XML.ObjectLoader getLoader()
          Returns the XML.ObjectLoader for this class.
 java.lang.String getName()
          Gets the name of this data.
 int getRowCount()
          Gets the number of rows for rendering in a JTable.
 java.lang.Object getValueAt(int rowIndex, int tableColumnIndex)
          Gets an x or y value for rendering in a JTable.
 double getXMax()
          Gets the x world coordinate for the right hand side of the panel.
 double getXMaxLogscale()
          Gets the maximum x needed to draw this object on a log scale.
 double getXMin()
          Gets the x world coordinate for the left hand side of the panel.
 double getXMinLogscale()
          Gets the minimum x needed to draw this object on a log scale.
 double[] getXPoints(int datasetIndex)
          Gets a copy of the xpoints array.
 double getYMax()
          Gets y world coordinate for the top of the panel.
 double getYMaxLogscale()
          Gets the maximum y needed to draw this object on a log scale on a log scale.
 double getYMin()
          Gets y world coordinate for the bottom of the panel.
 double getYMinLogscale()
          Gets the minimum y needed to draw this object on a log scale.
 double[] getYPoints(int datasetIndex)
          Gets a copy of the ypoints array.
 boolean isConnected(int datasetIndex)
          Gets the data connected flag.
 boolean isMeasured()
          Gets the valid measure flag.
 boolean isSorted(int datasetIndex)
          Gets the sorted flag.
 boolean isXPointsLinked()
          Gets the linked flag.
 Dataset removeDataset(int index)
          Removes the dataset at the specified index.
 void removeDatasets()
          Removes all Datasets from the manager.
 void setConnected(boolean _connected)
          Sets the connected flag for all datasets.
 void setConnected(int datasetIndex, boolean _connected)
          Sets the data connected flag.
 void setConstant(java.lang.String name, double val, java.lang.String expression)
          Sets the value of a constant.
 void setCustomMarker(int datasetIndex, java.awt.Shape marker)
          Sets a custom marker shape.
 void setID(int id)
          Sets the ID number of this Data.
 void setLineColor(int datasetIndex, java.awt.Color _lineColor)
          Sets the color of the lines connecting data points.
 void setMarkerColor(int datasetIndex, java.awt.Color _markerColor)
          Sets the data point marker color.
 void setMarkerColor(int datasetIndex, java.awt.Color fillColor, java.awt.Color edgeColor)
          Sets the data point marker's fill and edge color.
 void setMarkerShape(int datasetIndex, int _markerShape)
          Sets the data point marker shape.
 void setMarkerSize(int datasetIndex, int _markerSize)
          Sets the half-width of the data point marker.
 void setName(java.lang.String name)
          Sets the name of this data.
 void setSorted(boolean _sorted)
          Sets the sorted flag for all datasets.
 void setSorted(int datasetIndex, boolean _sorted)
          Sets the sorted flag.
 void setStride(int _stride)
           
 void setStride(int datasetIndex, int stride)
          Sets the stride for the given dataset.
 void setXColumnVisible(int datasetIndex, boolean visible)
          Sets the visibility of the x column in a table view.
 void setXPointsLinked(boolean _linked)
          Sets the linked flag.
 void setXYColumnNames(int datasetIndex, java.lang.String xColumnName, java.lang.String yColumnName)
          Sets the column names when rendering this dataset in a JTable.
 void setXYColumnNames(int datasetIndex, java.lang.String xColumnName, java.lang.String yColumnName, java.lang.String datsetName)
          Sets the column names when rendering this dataset in a JTable.
 void setXYColumnNames(java.lang.String _xColumnName, java.lang.String _yColumnName)
          Sets the column names for all datasets when rendering this dataset in a JTable.
 void setYColumnVisible(int datasetIndex, boolean visible)
          Sets the visibility of the y column in a table view.
 java.lang.String toString()
          Create a string representation of the data.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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 Detail

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)

setMarkerColor

public void setMarkerColor(int datasetIndex,
                           java.awt.Color _markerColor)
Sets the data point marker color.

Parameters:
datasetIndex -
_markerColor -

setMarkerColor

public void setMarkerColor(int datasetIndex,
                           java.awt.Color fillColor,
                           java.awt.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,
                            java.awt.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,
                         java.awt.Color _lineColor)
Sets the color of the lines connecting data points.

Parameters:
datasetIndex -
_lineColor -

getLineColors

public java.awt.Color[] getLineColors()
Line colors for Data interface.

Specified by:
getLineColors in interface Data
Returns:

getFillColors

public java.awt.Color[] getFillColors()
Fill colors for Data interface.

Specified by:
getFillColors in interface Data
Returns:

setXYColumnNames

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

Parameters:
datasetIndex -
xColumnName -
yColumnName -
datsetName -

setXYColumnNames

public void setXYColumnNames(int datasetIndex,
                             java.lang.String xColumnName,
                             java.lang.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 interface javax.swing.table.TableModel
Returns:
the count

getRowCount

public int getRowCount()
Gets the number of rows for rendering in a JTable.

Specified by:
getRowCount in interface javax.swing.table.TableModel
Returns:
the count

getName

public java.lang.String getName()
Gets the name of this data.

Specified by:
getName in interface Data
Returns:
name

setName

public void setName(java.lang.String name)
Sets the name of this data.


getColumnName

public java.lang.String getColumnName(int tableColumnIndex)
Gets the name of the column for rendering in a JTable

Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Parameters:
tableColumnIndex -
Returns:
the name

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int tableColumnIndex)
Gets an x or y value for rendering in a JTable.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
rowIndex -
tableColumnIndex -
Returns:
the datum

getColumnClass

public java.lang.Class<java.lang.Double> getColumnClass(int columnIndex)
Gets the type of object for JTable entry.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Parameters:
columnIndex -
Returns:
the class

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.

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,
                 java.awt.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 java.util.ArrayList<Dataset> getDatasets()
Gets a shallow clone of the dataset list. Implements Data.

Specified by:
getDatasets in interface Data
Returns:
cloned list

getDataList

public java.util.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 java.lang.String[] getColumnNames()
The column names to be used in the data display tool

Specified by:
getColumnNames in interface Data
Returns:

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(java.lang.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 java.lang.String[] getConstantNames()
Returns the constant names. Added by Doug Brown 3/24/2011.

Returns:
array of constant names

getConstantValue

public java.lang.Double getConstantValue(java.lang.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 java.lang.String getConstantExpression(java.lang.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

setConstant

public void setConstant(java.lang.String name,
                        double val,
                        java.lang.String expression)
Sets the value of a constant. Added by Doug Brown 3/24/2011.

Parameters:
name - the name of the constant
val - the value of the constant

clearConstant

public void clearConstant(java.lang.String name)
Clears a constant. Added by Doug Brown 3/24/2011.

Parameters:
name - the name of the constant

toString

public java.lang.String toString()
Create a string representation of the data.

Overrides:
toString in class java.lang.Object
Returns:
the data

setXYColumnNames

public void setXYColumnNames(java.lang.String _xColumnName,
                             java.lang.String _yColumnName)
Sets the column names for all datasets when rendering this dataset in a JTable.

Parameters:
_xColumnName -
_yColumnName -

getLoader

public static XML.ObjectLoader getLoader()
Returns the XML.ObjectLoader for this class.

Returns:
the object loader