org.opensourcephysics.display
Class ComplexDataset

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

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

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.

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 contructor.
 
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
static XML.ObjectLoader getLoader()
          Returns the XML.ObjectLoader for this class.
 int getMarkerShape()
          Gets the marker shape.
 int getMarkerSize()
          Gets the marker size.
 double[][] getPoints()
          Gets a data array containing both x and y values.
 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 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 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.
 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 contructor.

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[]

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

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

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 -

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.

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

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