org.opensourcephysics.display
Class Dataset

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended byorg.opensourcephysics.display.Dataset
All Implemented Interfaces:
Drawable, Measurable, java.io.Serializable, javax.swing.table.TableModel
Direct Known Subclasses:
HighlightableDataset, HistogramDataset, Stripchart

public class Dataset
extends javax.swing.table.AbstractTableModel
implements Measurable

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.

See Also:
Serialized Form

Nested Class Summary
protected static class Dataset.Loader
          A class to save and load Dataset data in an XMLControl.
 
Field Summary
static int AREA
          Field AREA
static int BAR
          Field BAR
static int CIRCLE
          Field CIRCLE
static int CUSTOM
          Field POST
protected  java.awt.Shape customMarker
           
protected  int datasetID
          Field datasetID an integer ID that identifies this object
protected  java.util.ArrayList errorBars
           
protected  java.awt.geom.GeneralPath generalPath
           
protected  int index
           
protected  int maxPoints
           
static int NO_MARKER
          Field NO_MARKER
static int PIXEL
          Field PIXEL
static int POST
          Field POST
protected  boolean sorted
           
static int SQUARE
          Field SQUARE
protected  double xmax
           
protected  double xmin
           
protected  double[] xpoints
           
protected  double ymax
           
protected  double ymin
           
protected  double[] ypoints
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
Dataset()
          Dataset contructor.
Dataset(java.awt.Color _markerColor)
          Dataset contructor specifying the marker color.
Dataset(java.awt.Color markerColor, java.awt.Color _lineColor, boolean _connected)
          Dataset contructor 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.
protected  void drawFilledPlot(DrawingPanel drawingPanel, java.awt.Graphics2D g2)
          Fills the line connecting the data points.
protected  void drawLinePlot(DrawingPanel drawingPanel, java.awt.Graphics2D g2)
          Draw the lines connecting the data points.
protected  void drawScatterPlot(DrawingPanel drawingPanel, java.awt.Graphics2D g2)
          Draw the markers at the data points.
 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.
 java.lang.String getColumnName(int columnIndex)
          Gets the name of the colummn for rendering in a JTable
 java.awt.Color getEdgeColor()
          Gets the data point edge color.
 java.awt.Color getFillColor()
          Gets the data point fill color.
 int getID()
          Dets an id that can be used to identify the dataset.
 int getIndex()
          Gets the current index of the array.
 java.awt.Color getLineColor()
          Gets the line color.
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.
 double getXMax()
          Gets the x world coordinate for the right hand side of the panel.
 double getXMin()
          Gets the x world coordinate for the left hand side of the panel.
 double[] getXPoints()
          Gets a copy of the xpoints array.
 double getYMax()
          Gets y world coordinate for the top of the panel.
 double getYMin()
          Gets y world coordinate for the bottom of the panel.
 double[] getYPoints()
          Gets a copy of the ypoints array.
protected  void insertionSort()
          Perform an insertion sort of the data set.
 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.
protected  void moveDatum(int loc)
          Move an out-of-place datum into its correct position.
 void read(java.lang.String inputFile)
          Reads a file and appends the data contained in the file to this Dataset.
protected  void recalculatePath()
          Recalculate the general path.
 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 an id that can be used to identify the dataset.
 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 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

datasetID

protected int datasetID
Field datasetID an integer ID that identifies this object


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

xpoints

protected double[] xpoints

ypoints

protected double[] ypoints

generalPath

protected java.awt.geom.GeneralPath generalPath

xmax

protected double xmax

ymax

protected double ymax

xmin

protected double xmin

ymin

protected double ymin

index

protected int index

sorted

protected boolean sorted

maxPoints

protected int maxPoints

errorBars

protected java.util.ArrayList errorBars

customMarker

protected java.awt.Shape customMarker
Constructor Detail

Dataset

public Dataset()
Dataset contructor.


Dataset

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

Parameters:
_markerColor -

Dataset

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

Parameters:
markerColor -
_lineColor -
_connected -
Method Detail

setID

public void setID(int id)
Sets an id that can be used to identify the dataset.

Parameters:
id - int

getID

public int getID()
Dets an id that can be used to identify the dataset.

Returns:
the 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

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

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 -

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.

Returns:
String

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

getPoints

public double[][] getPoints()
Gets a data array containing both x and y values.

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

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
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
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.

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

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

insertionSort

protected void insertionSort()
Perform an insertion sort of the data set. Since data will be partially sorted this should be fast. Added by W. Christian.


recalculatePath

protected void recalculatePath()
Recalculate the general path.


moveDatum

protected void moveDatum(int loc)
Move an out-of-place datum into its correct position.

Parameters:
loc - the datum

drawLinePlot

protected void drawLinePlot(DrawingPanel drawingPanel,
                            java.awt.Graphics2D g2)
Draw the lines connecting the data points.

Parameters:
drawingPanel -
g2 -

drawFilledPlot

protected void drawFilledPlot(DrawingPanel drawingPanel,
                              java.awt.Graphics2D g2)
Fills the line connecting the data points.

Parameters:
drawingPanel -
g2 -

drawScatterPlot

protected void drawScatterPlot(DrawingPanel drawingPanel,
                               java.awt.Graphics2D g2)
Draw the markers at the data points.

Parameters:
drawingPanel -
g2 -

getLoader

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

Returns:
the object loader