org.opensourcephysics.display
Class ComplexDataset

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

public class ComplexDataset
extends javax.swing.table.AbstractTableModel
implements Drawable, Measurable, Data

ComplexDataset stores and plots a complex dataset (x,z) where the dependent variable has real and imaginary parts, z=(real, imaginary). In Re_Im mode, both the real and imaginary parts are shown as separate curves. In Phase mode, the vertical coordinate represents magnitude and color represents phase. ComplexDataset is Drawable and can be rendered on a DrawingPanel. ComplexDataset extends AbstractTableModel and can be rendered in a JTable.

Version:
1.0
Author:
Wolfgang Christian
See Also:
Serialized Form

Field Summary
static int AMP_CURVE
          AMP height equal to |z|..
protected  double[] amp_points
           
protected  double[] im_points
           
protected  int index
           
static int PHASE_BAR
          PHASE_BAR the phase is shown as the bar's color
static int PHASE_CURVE
          PHASE_CURVE the phase is shown as color.
static int PHASE_POST
          Field POST
static int RE_IM_CURVE
          RE_IM real and imaginary curves.
protected  double[] re_points
           
protected  double[] xpoints
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
ComplexDataset()
          Dataset constructor.
 
Method Summary
 void append(double[] _xpoints, double[] _zpoints)
          Appends x and z data to the Dataset.
 void append(double[] _xpoints, double[] _repoints, double[] _impoints)
          Appends x, real, and imaginary arrays to the Dataset.
 void append(double x, double re, double im)
          Appends (x, re, im) datum to the Dataset.
 void clear()
          Clear all data from this Dataset.
 void draw(DrawingPanel drawingPanel, java.awt.Graphics g)
          Draw this Dataset in the drawing panel.
protected  void drawLinePlot(DrawingPanel drawingPanel, java.awt.Graphics2D g2)
          Draw the lines connecting the data points.
protected  void drawPhaseBars(DrawingPanel drawingPanel, java.awt.Graphics2D g2)
          Draw the phase as a colored bar.
protected  void drawPhaseCurve(DrawingPanel drawingPanel, java.awt.Graphics2D g2)
          Draw the phase as color.
protected  void drawPhasePosts(DrawingPanel drawingPanel, java.awt.Graphics2D g2)
          Draw the phase as a colored post.
protected  void drawReImPlot(DrawingPanel drawingPanel, java.awt.Graphics2D g2)
          Draw the lines connecting 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.lang.String[] getColumnNames()
          The column names to be used in the data display tool
 double[][] getData2D()
          Gets a 2D array of data.
 double[][][] getData3D()
          Gets a 3D array of data.
 java.util.List<Data> getDataList()
          Some elements (a Group, for instance) do not contain data, but a list of subelements which do.
 java.util.ArrayList<Dataset> getDatasets()
          Gets a list of OSP Datasets.
 java.awt.Color getFillColor()
          Fill color to use for this data
 java.awt.Color[] getFillColors()
          Fill colors to Data interface.
 int getID()
          Returns a unique identifier for this Data.
 double[] getImPoints()
          Gets a copy of the imaginary points 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 marker shape.
 int getMarkerSize()
          Gets the marker size.
 java.lang.String getName()
          Gets the name.
 double[][] getPoints()
          Gets a data array containing both x and y values.
 double[] getRePoints()
          Gets a copy of the real points array.
 int getRowCount()
          Gets the number of rows for rendering in a JTable.
 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.
protected  void moveDatum(int loc)
          Move an out-of-place datum into its correct position.
protected  void recalculatePath()
          Recalcualte the general path.
 void setCentered(boolean _centered)
          Sets the centered flag.
 void setConnected(boolean _connected)
          Sets the data connected flag.
 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 setLineColor(java.awt.Color reColor, java.awt.Color imColor)
          Sets the color of the lines connecting data points.
 void setMarkerShape(int _markerShape)
          Sets the data point marker.
 void setMarkerSize(int size)
          Sets the marker size.
 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 data stride for table view.
 void setXYColumnNames(java.lang.String _xColumnName, java.lang.String _reColumnName, java.lang.String _imColumnName)
          Sets the column names when rendering this dataset in a JTable.
 void setXYColumnNames(java.lang.String _xColumnName, java.lang.String _reColumnName, java.lang.String _imColumnName, java.lang.String datasetName)
          Sets the column names when rendering this dataset in a JTable.
 javax.swing.JFrame showLegend()
          Shows the phase legend.
 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

AMP_CURVE

public static final int AMP_CURVE
AMP height equal to |z|..

See Also:
Constant Field Values

RE_IM_CURVE

public static final int RE_IM_CURVE
RE_IM real and imaginary curves.

See Also:
Constant Field Values

PHASE_CURVE

public static final int PHASE_CURVE
PHASE_CURVE the phase is shown as color.

See Also:
Constant Field Values

PHASE_BAR

public static final int PHASE_BAR
PHASE_BAR the phase is shown as the bar's color

See Also:
Constant Field Values

PHASE_POST

public static final int PHASE_POST
Field POST

See Also:
Constant Field Values

xpoints

protected double[] xpoints

re_points

protected double[] re_points

im_points

protected double[] im_points

amp_points

protected double[] amp_points

index

protected int index
Constructor Detail

ComplexDataset

public ComplexDataset()
Dataset constructor.

Method Detail

showLegend

public javax.swing.JFrame showLegend()
Shows the phase legend.


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

getXPoints

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

Returns:
xpoints[]

getRePoints

public double[] getRePoints()
Gets a copy of the real points array.

Returns:
repoints[]

getImPoints

public double[] getImPoints()
Gets a copy of the imaginary points array.

Returns:
impoints[]

getYPoints

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

Returns:
ypoints[]

getPoints

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

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

setMarkerShape

public void setMarkerShape(int _markerShape)
Sets the data point marker. Shapes are: AMP_CURVE RE_IM_CURVE PHASE_CURVE PHASE_BAR PHASE_POST

Parameters:
_markerShape -

getMarkerShape

public int getMarkerShape()
Gets the marker shape.

Returns:
int

getMarkerSize

public int getMarkerSize()
Gets the marker size.

Returns:
int

setMarkerSize

public void setMarkerSize(int size)
Sets the marker size.

Parameters:
size - int

setSorted

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

Parameters:
_sorted - true<\code> to sort

setStride

public void setStride(int _stride)
Sets the data stride for table view. A stride of i will show every i-th point.

Parameters:
_stride -

isSorted

public boolean isSorted()
Gets the sorted flag.

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

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

setCentered

public void setCentered(boolean _centered)
Sets the centered flag. Centered complex numbers are shown extending above and below the y axis.

Parameters:
_centered - true<\code> if data is centered

isConnected

public boolean isConnected()
Gets the data connected flag.

Returns:
true<\code> if points are connected

setLineColor

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

Parameters:
_lineColor -

setLineColor

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

Parameters:
reColor - the real component color
imColor - the imaginary component color

getLineColors

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

Specified by:
getLineColors in interface Data
Returns:

getLineColor

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

Returns:
the line color

getFillColors

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

Specified by:
getFillColors in interface Data
Returns:

getFillColor

public java.awt.Color getFillColor()
Fill color to use for this data

Returns:

setXYColumnNames

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

Parameters:
_xColumnName - String
_reColumnName - String
_imColumnName - String

setXYColumnNames

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

Parameters:
_xColumnName - String
_reColumnName - String
_imColumnName - String
datasetName - String

append

public void append(double x,
                   double re,
                   double im)
Appends (x, re, im) datum to the Dataset.

Parameters:
x - double
re - double
im - double

append

public void append(double[] _xpoints,
                   double[] _repoints,
                   double[] _impoints)
Appends x, real, and imaginary arrays to the Dataset.

Parameters:
_xpoints -
_repoints -
_impoints -

append

public void append(double[] _xpoints,
                   double[] _zpoints)
Appends x and z data to the Dataset. Z array has length twice that of x array.
    Re(z) = z[2*i]
    Im(z) = z[2*i + 1]

Parameters:
_xpoints -
_zpoints -

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

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()
Create a string representation of the data.

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

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

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

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()
Recalcualte 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 -

drawReImPlot

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

Parameters:
drawingPanel -
g2 -

drawPhaseCurve

protected void drawPhaseCurve(DrawingPanel drawingPanel,
                              java.awt.Graphics2D g2)
Draw the phase as color.

Parameters:
drawingPanel -
g2 -

drawPhaseBars

protected void drawPhaseBars(DrawingPanel drawingPanel,
                             java.awt.Graphics2D g2)
Draw the phase as a colored bar.

Parameters:
drawingPanel -
g2 -

drawPhasePosts

protected void drawPhasePosts(DrawingPanel drawingPanel,
                              java.awt.Graphics2D g2)
Draw the phase as a colored post.

Parameters:
drawingPanel -
g2 -

getLoader

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

Returns:
the object loader

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

Specified by:
getName in interface Data
Returns:
String

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()
Description copied from interface: Data
Gets a 2D array of data. The first column, double[0][] often contains x-values; Remaining columns often contain y values. May return null if data not yet generated or object does not support 2D data.

Specified by:
getData2D in interface Data
Returns:
double[][]

getData3D

public double[][][] getData3D()
Description copied from interface: Data
Gets a 3D array of data. May return null if data not yet generated or object does not support 3D data.

Specified by:
getData3D in interface Data
Returns:
double[][][]

getDatasets

public java.util.ArrayList<Dataset> getDatasets()
Description copied from interface: Data
Gets a list of OSP Datasets. May return null if data not yet generated or object does not support Datasets.

Specified by:
getDatasets in interface Data
Returns:
list of Datasets

getDataList

public java.util.List<Data> getDataList()
Some elements (a Group, for instance) do not contain data, but a list of subelements 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 DataInformation elements, null if the element itself is a DataInformation