org.opensourcephysics.display
Class Dataset

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.opensourcephysics.display.Dataset
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel, Data, Drawable, LogMeasurable, Measurable
Direct Known Subclasses:
DataColumn, DataFunction, HighlightableDataset, HistogramDataset, Stripchart

public class Dataset
extends javax.swing.table.AbstractTableModel
implements Measurable, LogMeasurable, Data

Dataset stores and plots (x,y) points. Dataset is Drawable and can be rendered on a DrawingPanel. Dataset extends AbstractTableModel and can be rendered in a JTable.

Version:
1.0
Author:
Joshua Gould, Wolfgang Christian
See Also:
Serialized Form

Field Summary
static int AREA
          Field AREA
static int BAR
          Field BAR
static int CIRCLE
          Field CIRCLE
static int CUSTOM
          Field POST
static int NO_MARKER
          Field NO_MARKER
static int PIXEL
          Field PIXEL
static int POST
          Field POST
static int SQUARE
          Field SQUARE
 
Constructor Summary
Dataset()
          Dataset constructor.
Dataset(java.awt.Color _markerColor)
          Dataset constructor specifying the marker color.
Dataset(java.awt.Color markerColor, java.awt.Color _lineColor, boolean _connected)
          Dataset constructor specifying the marker color, line color, and whether points are connected.
 
Method Summary
 void append(double[] _xpoints, double[] _ypoints)
          Appends (x,y) arrays to the Dataset.
 void append(double[] xpoints, double[] ypoints, double[] delx, double[] dely)
          Appends arrays of data points and uncertainties to the Dataset.
 void append(double x, double y)
          Appends an (x,y) datum to the Dataset.
 void append(double x, double y, double delx, double dely)
          Appends a data point and its uncertainty to the Dataset.
 void clear()
          Clear all data from this Dataset.
static int convertTableColumnIndex(boolean[] visible, int columnIndex)
          Converts a table column in a table model to the appropriate table column.
static int countColumnsVisible(boolean[] visible)
          Counts the number of columns visible
 void draw(DrawingPanel drawingPanel, java.awt.Graphics g)
          Draw this Dataset in the drawing panel.
 java.lang.Class<?> getColumnClass(int columnIndex)
          Gets the type of object for JTable entry.
 int getColumnCount()
          Gets the number of columns for rendering in a JTable.
 int getColumnID()
          Returns the column ID.
 java.lang.String getColumnName(int columnIndex)
          Gets the name of the colummn for rendering in a JTable
 java.lang.String[] getColumnNames()
          The column names to be used in the data tool
 double[][] getData2D()
          Gets a data array containing both x and y values.
 double[][][] getData3D()
          Returns a null 3D array of data.
 java.util.List<Data> getDataList()
          Some Data objects (e.g., a Group) do not contain data, but a list of Data objects which do.
 java.util.ArrayList<Dataset> getDatasets()
          Returns a list containing this Dataset.
 java.awt.Color getEdgeColor()
          Gets the data point edge color.
 java.awt.Color getFillColor()
          Gets the data point fill color.
 java.awt.Color[] getFillColors()
          Fill colors for Data interface.
 int getID()
          Returns a unique identifier for this Data.
 int getIndex()
          Gets the current index of the array.
 java.awt.Color getLineColor()
          Gets the line color.
 java.awt.Color[] getLineColors()
          Line colors for Data interface.
static XML.ObjectLoader getLoader()
          Returns the XML.ObjectLoader for this class.
 int getMarkerShape()
          Gets the data point marker shape.
 int getMarkerSize()
          Gets the half-width of the data point marker.
 java.lang.String getName()
          Gets the dataset name.
 double[][] getPoints()
          Gets a data array containing both x and y values.
 int getRowCount()
          Gets the number of rows for rendering in a JTable.
 double[] getValidXPoints()
          Gets an array of valid xpoints.
 double[] getValidYPoints()
          Gets an array of valid ypoints.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Gets an x or y value for rendering in a JTable.
 boolean getVisible()
          Gets the visibility of this dataset in the DrawingPanel.
 java.lang.String getXColumnName()
          Gets the x column name.
 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()
          Gets a copy of the xpoints array.
 java.lang.String getYColumnName()
          Gets the y column name.
 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()
          Gets a copy of the ypoints array.
 boolean isConnected()
          Gets the data connected flag.
 boolean isMeasured()
          Gets the valid measure flag.
 boolean isSorted()
          Gets the sorted flag.
 boolean isXColumnVisible()
          Gets the visibility of the x column of this Dataset in a table view.
 boolean isYColumnVisible()
          Gets the visibility of the y column of this Dataset in a table view.
 void read(java.lang.String inputFile)
          Reads a file and appends the data contained in the file to this Dataset.
 void setColumnID(int id)
          Sets the column ID.
 void setConnected(boolean _connected)
          Sets the data connected flag.
 void setCustomMarker(java.awt.Shape marker)
          Sets a custom marker shape.
 void setID(int id)
          Sets the ID number of this Data.
 void setLineColor(java.awt.Color _lineColor)
          Sets the color of the lines connecting data points.
 void setMarkerColor(java.awt.Color markerColor)
          Sets the data point fill, edge, and error bar colors to the same color.
 void setMarkerColor(java.awt.Color _fillColor, java.awt.Color _edgeColor)
          Sets the data point marker colors.
 void setMarkerColor(java.awt.Color _fillColor, java.awt.Color _edgeColor, java.awt.Color _errorBarColor)
          Sets the data point marker colors.
 void setMarkerShape(int _markerShape)
          Sets the data point marker shape.
 void setMarkerSize(int _markerSize)
          Sets the half-width of the data point marker.
 void setMaximumPoints(int maxPoints)
          Sets the maximum number of allowed datapoints.
 void setName(java.lang.String name)
          Sets a name that can be used to identify the dataset.
 void setSorted(boolean _sorted)
          Sets the sorted flag.
 void setStride(int _stride)
          Sets the stride of this Dataset in a table view.
 void setVisible(boolean b)
          Sets the visibility of this Dataset in a DrawingPanel.
 void setXColumnVisible(boolean b)
          Sets the visibility of the x column of this Dataset in a table view.
 void setXYColumnNames(java.lang.String _xColumnName, java.lang.String _yColumnName)
          Sets the column names when rendering this dataset in a JTable.
 void setXYColumnNames(java.lang.String xColumnName, java.lang.String yColumnName, java.lang.String name)
          Sets the column names and the dataset name.
 void setYColumnVisible(boolean b)
          Sets the visibility of the y column of this Dataset in a table view.
 java.lang.String toString()
          Creates a string representation of the data.
 void write(java.lang.String outputFile)
          Writes data from this Dataset to a file.
 
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
 

Field Detail

NO_MARKER

public static final int NO_MARKER
Field NO_MARKER

See Also:
Constant Field Values

CIRCLE

public static final int CIRCLE
Field CIRCLE

See Also:
Constant Field Values

SQUARE

public static final int SQUARE
Field SQUARE

See Also:
Constant Field Values

AREA

public static final int AREA
Field AREA

See Also:
Constant Field Values

PIXEL

public static final int PIXEL
Field PIXEL

See Also:
Constant Field Values

BAR

public static final int BAR
Field BAR

See Also:
Constant Field Values

POST

public static final int POST
Field POST

See Also:
Constant Field Values

CUSTOM

public static final int CUSTOM
Field POST

See Also:
Constant Field Values
Constructor Detail

Dataset

public Dataset()
Dataset constructor.


Dataset

public Dataset(java.awt.Color _markerColor)
Dataset constructor specifying the marker color.

Parameters:
_markerColor -

Dataset

public Dataset(java.awt.Color markerColor,
               java.awt.Color _lineColor,
               boolean _connected)
Dataset constructor specifying the marker color, line color, and whether points are connected.

Parameters:
markerColor -
_lineColor -
_connected -
Method Detail

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

setColumnID

public void setColumnID(int id)
Sets the column ID.

Parameters:
id - the column ID

getColumnID

public int getColumnID()
Returns the column ID.

Returns:
the column ID

setSorted

public void setSorted(boolean _sorted)
Sets the sorted flag. Data is sorted by increasing x.

Parameters:
_sorted - true<\code> to sort

setConnected

public void setConnected(boolean _connected)
Sets the data connected flag. Points are connected by straight lines.

Parameters:
_connected - true<\code> if points are connected

setMarkerColor

public void setMarkerColor(java.awt.Color markerColor)
Sets the data point fill, edge, and error bar colors to the same color.

Parameters:
markerColor -

setMarkerColor

public void setMarkerColor(java.awt.Color _fillColor,
                           java.awt.Color _edgeColor)
Sets the data point marker colors. The error bar color is set equal to the edge color.

Parameters:
_fillColor -
_edgeColor -

setMarkerColor

public void setMarkerColor(java.awt.Color _fillColor,
                           java.awt.Color _edgeColor,
                           java.awt.Color _errorBarColor)
Sets the data point marker colors.

Parameters:
_fillColor -
_edgeColor -
_errorBarColor -

getFillColor

public java.awt.Color getFillColor()
Gets the data point fill color.

Returns:
the fill color

getFillColors

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

Specified by:
getFillColors in interface Data
Returns:

getEdgeColor

public java.awt.Color getEdgeColor()
Gets the data point edge color.

Returns:
the edge color

getLineColor

public java.awt.Color getLineColor()
Gets the line color.

Returns:
the line color

getLineColors

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

Specified by:
getLineColors in interface Data
Returns:

setCustomMarker

public void setCustomMarker(java.awt.Shape marker)
Sets a custom marker shape.

Parameters:
marker - Shape

setMarkerShape

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

Parameters:
_markerShape -

getMarkerShape

public int getMarkerShape()
Gets the data point marker shape.

Returns:
the marker shape

setMarkerSize

public void setMarkerSize(int _markerSize)
Sets the half-width of the data point marker.

Parameters:
_markerSize - in pixels

setMaximumPoints

public void setMaximumPoints(int maxPoints)
Sets the maximum number of allowed datapoints.

Parameters:
maxPoints - int

getMarkerSize

public int getMarkerSize()
Gets the half-width of the data point marker.

Returns:
the marker size in pixels

setLineColor

public void setLineColor(java.awt.Color _lineColor)
Sets the color of the lines connecting data points.

Parameters:
_lineColor -

setXYColumnNames

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

Parameters:
_xColumnName -
_yColumnName -

setXYColumnNames

public void setXYColumnNames(java.lang.String xColumnName,
                             java.lang.String yColumnName,
                             java.lang.String name)
Sets the column names and the dataset name.

Parameters:
xColumnName -
yColumnName -
name -

getXColumnName

public java.lang.String getXColumnName()
Gets the x column name.

Returns:
String

getYColumnName

public java.lang.String getYColumnName()
Gets the y column name.

Returns:
String

setName

public void setName(java.lang.String name)
Sets a name that can be used to identify the dataset.

Parameters:
name - String

getName

public java.lang.String getName()
Gets the dataset name.

Specified by:
getName in interface Data
Returns:
String

getDataList

public java.util.List<Data> getDataList()
Some Data objects (e.g., a Group) do not contain data, but a list of Data objects which 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 tool

Specified by:
getColumnNames in interface Data
Returns:

isMeasured

public boolean isMeasured()
Gets the valid measure flag. The measure is valid if the min and max values have been set.

Specified by:
isMeasured in interface Measurable
Returns:
true<\code> if measure is valid

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

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

getYMin

public double getYMin()
Gets y world coordinate for the bottom of the panel.

Specified by:
getYMin in interface Measurable
Returns:
ymin

getYMax

public double getYMax()
Gets y world coordinate for the top of the panel.

Specified by:
getYMax in interface Measurable
Returns:
ymax

getXMinLogscale

public double getXMinLogscale()
Gets the minimum x needed to draw this object on a log scale.

Specified by:
getXMinLogscale in interface LogMeasurable
Returns:
minimum

getXMaxLogscale

public double getXMaxLogscale()
Gets the maximum x needed to draw this object on a log scale.

Specified by:
getXMaxLogscale in interface LogMeasurable
Returns:
maximum

getYMinLogscale

public double getYMinLogscale()
Gets the minimum y needed to draw this object on a log scale.

Specified by:
getYMinLogscale in interface LogMeasurable
Returns:
minimum

getYMaxLogscale

public double getYMaxLogscale()
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

getPoints

public double[][] getPoints()
Gets a data array containing both x and y values. The data is arranged as an array of (x,y) pairs.

Returns:
a double[index][2] array of data

getData2D

public double[][] getData2D()
Gets a data array containing both x and y values. Implements Data. The data is arranged as a pair of separate x and y arrays.

Specified by:
getData2D in interface Data
Returns:
a double[2][index] array of data

getData3D

public double[][][] getData3D()
Returns a null 3D array of data. Implements Data.

Specified by:
getData3D in interface Data
Returns:
null

getDatasets

public java.util.ArrayList<Dataset> getDatasets()
Returns a list containing this Dataset. Implements Data.

Specified by:
getDatasets in interface Data
Returns:
ArrayList

getXPoints

public double[] getXPoints()
Gets a copy of the xpoints array.

Returns:
xpoints[]

getYPoints

public double[] getYPoints()
Gets a copy of the ypoints array.

Returns:
ypoints[]

getValidXPoints

public double[] getValidXPoints()
Gets an array of valid xpoints. A point is valid if the ypoint for that index is not Double.NaN.

Returns:
valid xpoints[]

getValidYPoints

public double[] getValidYPoints()
Gets an array of valid ypoints. A point is valid if the ypoint for that index is not Double.NaN.

Returns:
valid ypoints[]

isSorted

public boolean isSorted()
Gets the sorted flag.

Returns:
true<\code> if the data is sorted

isConnected

public boolean isConnected()
Gets the data connected flag.

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

getIndex

public int getIndex()
Gets the current index of the array. The index is equal to the number of data points that are currently stored. When data is appended, it will fill the xpoints and ypoints arrays starting at the current index.

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

getColumnName

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

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

getValueAt

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

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

getColumnClass

public java.lang.Class<?> 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(double x,
                   double y,
                   double delx,
                   double dely)
Appends a data point and its uncertainty to the Dataset.

Parameters:
x -
y -
delx -
dely -

append

public void append(double x,
                   double y)
Appends an (x,y) datum to the Dataset. A y value of Double.NaN is treated as null in plots and tables.

Parameters:
x -
y -

append

public void append(double[] xpoints,
                   double[] ypoints,
                   double[] delx,
                   double[] dely)
Appends arrays of data points and uncertainties to the Dataset.

Parameters:
xpoints -
ypoints -
delx -
dely -

append

public void append(double[] _xpoints,
                   double[] _ypoints)
Appends (x,y) arrays to the Dataset. Any y value of Double.NaN is treated as null in plots and tables.

Parameters:
_xpoints -
_ypoints -

read

public void read(java.lang.String inputFile)
Reads a file and appends the data contained in the file to this Dataset. The format of the file is x and y coordinates separated by tabs. Lines beginning with # are ignored.

Parameters:
inputFile -

write

public void write(java.lang.String outputFile)
Writes data from this Dataset to a file. The format of the file is x and y coordinates separated by tabs.

Parameters:
outputFile -

draw

public void draw(DrawingPanel drawingPanel,
                 java.awt.Graphics g)
Draw this Dataset in the drawing panel.

Specified by:
draw in interface Drawable
Parameters:
drawingPanel -
g -

clear

public void clear()
Clear all data from this Dataset.


toString

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

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

countColumnsVisible

public static int countColumnsVisible(boolean[] visible)
Counts the number of columns visible

Parameters:
visible - array of column visibilities
Returns:
number of visible columns

convertTableColumnIndex

public static int convertTableColumnIndex(boolean[] visible,
                                          int columnIndex)
Converts a table column in a table model to the appropriate table column. For example, if the x points are hidden in a Dataset, and the column index is 0, then this method will return 1.

Parameters:
visible - array of column visibilities
columnIndex - table column index to convert
Returns:
converted table column index

setXColumnVisible

public void setXColumnVisible(boolean b)
Sets the visibility of the x column of this Dataset in a table view.

Parameters:
b - new visibility

setYColumnVisible

public void setYColumnVisible(boolean b)
Sets the visibility of the y column of this Dataset in a table view.

Parameters:
b - new visibility

setVisible

public void setVisible(boolean b)
Sets the visibility of this Dataset in a DrawingPanel. Only visible panels affect autoscaled panels.

Parameters:
b - new visibility

getVisible

public boolean getVisible()
Gets the visibility of this dataset in the DrawingPanel.

Returns:
boolean

setStride

public void setStride(int _stride)
Sets the stride of this Dataset in a table view.

Parameters:
_stride - the stride

isXColumnVisible

public boolean isXColumnVisible()
Gets the visibility of the x column of this Dataset in a table view.

Returns:
the x column visibility

isYColumnVisible

public boolean isYColumnVisible()
Gets the visibility of the y column of this Dataset in a table view.

Returns:
the x column visibility

getLoader

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

Returns:
the object loader