spv.glue
Class PlottableSpectrum

java.lang.Object
  extended by java.util.Observable
      extended by spv.spectrum.SpectrumDecorator
          extended by spv.glue.PlottableSpectrum
All Implemented Interfaces:
java.lang.Cloneable, java.util.Observer, Spectrum, Plottable
Direct Known Subclasses:
PlottableEchelleSpectrum, PlottableMultiStyleSpectrum, PlottablePhotometrySpectrum, PlottableRangeSpectrum, PlottableSegmentedSpectrum

public class PlottableSpectrum
extends SpectrumDecorator
implements Plottable

This class acts as "glue" between the Spectrum and Plottable interfaces. It uses the Decorator design pattern to add Plottable responsibilities to a Spectrum object.

Perhaps the most fundamental mechanism implemented by this class is the units conversion from internal to display units. Delivered data arrays are always subjected to the units conversion; thus this class is effectively the single place in the entire application that is responsible for the implementation of the concept of "display units".

The independent plotting variable can be selected to be the wavelength, bin number, or any of the intensity and error arrays stored in the Spectrum object. The dependent variable is limited to the intensity and error arrays.

Version:
1.0 - 17Nov98
Author:
Ivo Busko (Space Telescope Science Institute)

Field Summary
private  int[] deldata
           
protected  Units display_xunits
           
protected  Units display_yunits
           
private  int[] dqdata
           
protected  boolean edited
           
private  double[] errdata
           
private static int HEIGHT
           
protected  int size
           
protected  Units spectrum_xunits
           
protected  Units spectrum_yunits
           
protected  java.awt.Stroke stroke
           
protected  Symbol symbol
           
(package private) static java.awt.Dimension TABLE_SIZE
           
protected  SpectrumVisualEditor visual_editor
           
private static int WIDTH
           
private  java.lang.String x_id
           
private  double[] xdata
           
private  java.lang.String y_id
           
private  double[] ydata
           
 
Fields inherited from class spv.spectrum.SpectrumDecorator
notify, sp
 
Fields inherited from interface spv.spectrum.Spectrum
REST_SUFFIX
 
Constructor Summary
PlottableSpectrum(Spectrum sp)
          Constructor.
 
Method Summary
 java.lang.Object clone()
          Creates a clone copy of this object.
protected  void finishDataSetBuild(Spectrum csp, java.lang.Object spid, DataSet ds)
           
 void forceSetChanged()
           
 java.lang.String getDefaultXID()
          Gets the array that is used by default as the source of the independet variable.
 int[] getDQ()
          Returns an array with data quality flags.
 java.util.Enumeration getDQList()
          Returns an Enumeration with the ids of all arrays that can be used as data quality.
 Command getDragProcessor()
           
 double[] getErrors()
          Returns an array with plottable error values.
 java.util.Map getGraphicsAttributes()
          Gets a map of graphics attributes associated with each element of the composite.
(package private)  java.awt.Stroke getLineType(java.lang.Object id)
          Gets the line type.
(package private)  LineTypeSelector getLineTypeSelector(java.lang.Object id)
          Gets a LineTypeSelector object appropriate for this.
 int getNBins()
          Returns the maximum number of plottable bins.
 java.lang.Object getRootObject()
          Returns a reference to the underlying Spectrum object that is decorated by PlottableSpectrum.
 java.lang.String getRootObjectCommonName()
          Returns a ID of the underlying object decorated by this interface, used to identify the object in the plot in a human-friendly way.
 java.lang.String getRootObjectID()
          Returns the ID of the underlying object decorated by this interface
 java.lang.String getSelectedDQID()
          Gets the ID of the array which is the source of the data quality flags.
private  double[] getSelectedXArray(Spectrum sp)
          Returns the X array.
 java.lang.String getSelectedXID()
          Gets the ID of the array which is the source of the independent variable.
 java.lang.String getSelectedYID()
          Gets the ID of the array which is the source of the dependent variable.
 Command getSpectrumNormalizer()
          Returns a Command object that implements a spectrum normalizer.
(package private)  Symbol getSymbol(java.lang.Object id)
          Gets the symbol.
(package private)  int getSymbolSize(java.lang.Object id)
          Gets the symbol size.
 Command getVisualEditor()
          Returns a Command object that implements a spectrum screen editor.
 double[] getX()
          Returns an array with plottable independent variable values.
 java.util.Enumeration getXList()
          Returns an Enumeration with the ids of all arrays that can be used as independent variable for plotting.
 double getXMax()
          Returns the maximum value of the independent variable.
 double getXMin()
          Returns the minimum value of the independent variable.
 Units getXUnits()
          Returns the current display units from the selected independent variable array.
 double[] getY()
          Returns an array with plottable dependent variable values.
 java.util.Enumeration getYList()
          Returns an Enumeration with the ids of all arrays that can be used as dependent variable for plotting.
 Units getYUnits()
          Returns the current display units from the selected dependent variable array.
 boolean isEvenlySampled()
          Returns true if the X array is evenly sampled, false otherwise.
private  void notifyListeners()
           
protected  DataSet prepareDataSet(double[] xval, double[] yval, double[] eval, Spectrum csp, java.util.Enumeration id_list)
          Execute routine activities when preparing a DataSet object to be plotted.
 void selectDQ(java.lang.String arrayid)
          Selects the array to be the source of data quality flags.
 void selectX(java.lang.String arrayid)
          Selects the array to be the source of the independent variable.
 void selectY(java.lang.String arrayid)
          Selects the array to be the source of the dependent variable.
 void setBothUnits(Units xunits, Units yunits)
          Sets the current display units in both arrays.
 void setGraphicsAttributes(java.util.Map attributes)
          Sets a list of graphics attributes.
(package private)  void setLineType(java.awt.Stroke stroke, java.lang.Object id)
          Sets the line type.
(package private)  void setSymbol(Symbol symbol, java.lang.Object id)
          Sets the symbol.
(package private)  void setSymbolSize(int size, java.lang.Object id)
          Sets the symbol size.
 void setXUnits(Units newunits)
          Sets the current display units in the currently selected independent variable array.
 void setXUnitsSilently(Units newunits)
          Sets the current display units in the curently selected independent variable array.
 void setYUnits(Units newunits)
          Sets the current display units in the currently selected dependent variable array.
 void setYUnitsSilently(Units newunits)
          Sets the current display units in the curently selected dependent variable array.
 void updateArrays()
          Builds the arrays that are returned by the get...
 java.util.ArrayList<DataSet> updateDataSets(java.util.ArrayList<DataSet> al)
          This method updates an ArrayList which stores data set objects, with additional objects built from the input arrays.
protected  void updateGraphicsAttributes(GraphicsAttributes pa, Spectrum sp, java.lang.Object id)
          Updates a GraphicsAttributes object.
 java.util.ArrayList updateValidDataRanges(java.util.ArrayList al)
          This method updates an ArrayList which stores range objects.
 
Methods inherited from class spv.spectrum.SpectrumDecorator
addMetaParameter, addMetaParameter, addMetaParameter, addRadialVelocity, addSpectrum, enableNotifications, explodeSpectrum, getArrayDQBits, getArrayDQMask, getAverageDispersion, getAverageValue, getChild, getDecoratedSpectrum, getDQBits, getDQMask, getExtremumPosition, getFluxWeightedPosition, getFluxWeightedPositionError, getHeader, getIntegralError, getIntegrationBins, getIntensityList, getMaxWavelength, getMetaParameters, getMinWavelength, getName, getNewTableModel, getNumberOfSpectra, getOriginalUnits, getOriginalWavelengthUnits, getRadialVelocities, getRestWavelengths, getSelectedIntensityID, getSelectedRadialVelocity, getSigma, getSpectrum, getSpectrumList, getSpectrumListAsList, getTableModel, getTag, getTargetName, getUnits, getValues, getWavelengthID, getWavelengths, getWavelengthUnits, getX, initializeParametersFromMap, integrate, isEquallySpaced, isMultiSegment, isNormalizable, isRestWavelengths, isSpectrogram, maskAll, normalize, process, removeMetaParameter, removeRadialVelocity, removeSpectrum, renormalize, reorderWavelengths, resetArraySelection, saveAsSED, saveSpectrumParameters, selectIntensity, selectRadialVelocity, setChild, setDQBits, setDQMask, setDQMasks, setHeader, setMultiSegment, setName, setNormalizable, setRestWavelengthsFlag, setSpectrogram, setTargetName, setUnits, setWavelengthID, setWavelengths, setWavelengthUnits, supportsRadialVelocity, update
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface spv.spectrum.Spectrum
addObserver, deleteObserver
 

Field Detail

WIDTH

private static final int WIDTH
See Also:
Constant Field Values

HEIGHT

private static final int HEIGHT
See Also:
Constant Field Values

TABLE_SIZE

static final java.awt.Dimension TABLE_SIZE

visual_editor

protected SpectrumVisualEditor visual_editor

spectrum_xunits

protected Units spectrum_xunits

spectrum_yunits

protected Units spectrum_yunits

display_xunits

protected Units display_xunits

display_yunits

protected Units display_yunits

stroke

protected java.awt.Stroke stroke

symbol

protected Symbol symbol

size

protected int size

edited

protected boolean edited

x_id

private java.lang.String x_id

y_id

private java.lang.String y_id

xdata

private double[] xdata

ydata

private double[] ydata

errdata

private double[] errdata

dqdata

private int[] dqdata

deldata

private int[] deldata
Constructor Detail

PlottableSpectrum

public PlottableSpectrum(Spectrum sp)
Constructor.

The display units are initialized to the original units in the selected arrays. If these do not exist, they are initialized to the current units instead.

Parameters:
sp - the Spectrum instance to receive additional plotting responsibilities
Method Detail

getLineTypeSelector

LineTypeSelector getLineTypeSelector(java.lang.Object id)
Gets a LineTypeSelector object appropriate for this.

Parameters:
id - the id of the spectrum in a composite. Ignored in this class.
Returns:
the LineTypeSelector object

getRootObject

public java.lang.Object getRootObject()
Returns a reference to the underlying Spectrum object that is decorated by PlottableSpectrum.

Specified by:
getRootObject in interface Plottable
Returns:
the Spectrum object

getRootObjectID

public java.lang.String getRootObjectID()
Returns the ID of the underlying object decorated by this interface

Specified by:
getRootObjectID in interface Plottable
Returns:
the ID of the object decorated by this interface

getRootObjectCommonName

public java.lang.String getRootObjectCommonName()
Returns a ID of the underlying object decorated by this interface, used to identify the object in the plot in a human-friendly way.

Specified by:
getRootObjectCommonName in interface Plottable
Returns:
the plot ID of the object decorated by this interface

getNBins

public int getNBins()
Returns the maximum number of plottable bins.

Specified by:
getNBins in interface Spectrum
Specified by:
getNBins in interface Plottable
Overrides:
getNBins in class SpectrumDecorator
Returns:
the maximum number of plottable bins

getXList

public java.util.Enumeration getXList()
Returns an Enumeration with the ids of all arrays that can be used as independent variable for plotting.

The returned Enumeration has its first element set to whatever string is defined by method sp.getWavelengthID().

If the spectrum provides a non-null return from its getSelectedRadialVelocity()method, the second element will indicate a rest wavelength array by appending an appropriate suffix to the wavelength ID string used in the firts element.

The third element of the enumaration, or the second if there is no valid radial velocity object, will be the string defined by Units.BIN_NUMBER.toString(), but only if the spectrum is a member of the SingleSpectrum class.

Subsequent enumeration elements will be taken from the enumeration provided by the getIntensityList() method in the component (decorated object). THIS FEATURE WAS REMOVED ON DEC 13, 2006.

The reason the "bin number" entry only appears if the input spectrum is an instance of the SingleSpectrum class is due partially to a design bug in the way the bin number concept was defined, and partially due to the questionable use of the bin number concept in spectra comprised of several "independent" stretches of data. Overplotting these stretches onto a common WCS canvas may be a sensible operation to perform, arguabily, only in wavelength space.

Specified by:
getXList in interface Plottable
Returns:
the list with ids of independent variable arrays

getYList

public java.util.Enumeration getYList()
Returns an Enumeration with the ids of all arrays that can be used as dependent variable for plotting.

Specified by:
getYList in interface Plottable
Returns:
the list with ids of dependent variable arrays

getDQList

public java.util.Enumeration getDQList()
Returns an Enumeration with the ids of all arrays that can be used as data quality.

Specified by:
getDQList in interface Spectrum
Specified by:
getDQList in interface Plottable
Overrides:
getDQList in class SpectrumDecorator
Returns:
the list with ids of data quality arrays

selectX

public void selectX(java.lang.String arrayid)
Selects the array to be the source of the independent variable.

Specified by:
selectX in interface Plottable
Parameters:
arrayid - the array identification name

selectY

public void selectY(java.lang.String arrayid)
Selects the array to be the source of the dependent variable.

Specified by:
selectY in interface Plottable
Parameters:
arrayid - the array identification name

selectDQ

public void selectDQ(java.lang.String arrayid)
Selects the array to be the source of data quality flags.

Specified by:
selectDQ in interface Spectrum
Specified by:
selectDQ in interface Plottable
Overrides:
selectDQ in class SpectrumDecorator
Parameters:
arrayid - the array identification name

getSelectedXID

public java.lang.String getSelectedXID()
Gets the ID of the array which is the source of the independent variable.

Specified by:
getSelectedXID in interface Plottable
Returns:
the array identification name

getDefaultXID

public java.lang.String getDefaultXID()
Gets the array that is used by default as the source of the independet variable.

Specified by:
getDefaultXID in interface Plottable
Returns:
the array identification name

getSelectedYID

public java.lang.String getSelectedYID()
Gets the ID of the array which is the source of the dependent variable.

Specified by:
getSelectedYID in interface Plottable
Returns:
the array identification name

getSelectedDQID

public java.lang.String getSelectedDQID()
Gets the ID of the array which is the source of the data quality flags.

Specified by:
getSelectedDQID in interface Spectrum
Specified by:
getSelectedDQID in interface Plottable
Overrides:
getSelectedDQID in class SpectrumDecorator
Returns:
the array identification name

getX

public double[] getX()
Returns an array with plottable independent variable values. The array is computed/updated by the updateArrays method.

Specified by:
getX in interface Plottable
Returns:
the array with plottable values

getY

public double[] getY()
Returns an array with plottable dependent variable values. The array is computed/updated by the updateArrays method.

Specified by:
getY in interface Plottable
Returns:
the array with plottable values

getDQ

public int[] getDQ()
Returns an array with data quality flags. These values are associated with the current dependent variable array. The array is computed/updated by the updateArrays method.

Specified by:
getDQ in interface Spectrum
Specified by:
getDQ in interface Plottable
Overrides:
getDQ in class SpectrumDecorator
Returns:
the array with plottable values. If no errors array exists, returns a IINDEF-filled array.

getErrors

public double[] getErrors()
Returns an array with plottable error values. These values are associated with the current dependent variable array. The array is computed/updated by the updateArrays method.

Specified by:
getErrors in interface Spectrum
Specified by:
getErrors in interface Plottable
Overrides:
getErrors in class SpectrumDecorator
Returns:
the array with plottable values. If no errors array exists, returns a NaN-filled array.

updateArrays

public void updateArrays()
Builds the arrays that are returned by the get... methods. Array building must be done in parallel to guarantee the binwise matching of all arrays. This method presumes that Spectrum objects can always return some non-null array from their getValues() method. getErrors() and getDQ() can return null though.

This method must be called prior to a sequence of calls to the getter methods to ensure consistency. This architecture leads to faster execution but is not thread-safe.

Specified by:
updateArrays in interface Plottable

getXUnits

public Units getXUnits()
Returns the current display units from the selected independent variable array. If the selected array is expressed in non-convertible units, these are returned instead.

Specified by:
getXUnits in interface Plottable
Returns:
the current display units

getYUnits

public Units getYUnits()
Returns the current display units from the selected dependent variable array. If the selected array is expressed in non-convertible units, these are returned instead.

Specified by:
getYUnits in interface Plottable
Returns:
the current display units

setXUnits

public void setXUnits(Units newunits)
Sets the current display units in the currently selected independent variable array.

Specified by:
setXUnits in interface Plottable
Parameters:
newunits - the new display units

setYUnits

public void setYUnits(Units newunits)
Sets the current display units in the currently selected dependent variable array.

Specified by:
setYUnits in interface Plottable
Parameters:
newunits - the new display units

setBothUnits

public void setBothUnits(Units xunits,
                         Units yunits)
Sets the current display units in both arrays.

Specified by:
setBothUnits in interface Plottable
Parameters:
xunits - the new X units
yunits - the new Y units

notifyListeners

private void notifyListeners()

setXUnitsSilently

public void setXUnitsSilently(Units newunits)
Sets the current display units in the curently selected independent variable array.

No notifications are sent to listeners.

Specified by:
setXUnitsSilently in interface Plottable
Parameters:
newunits - the new display units

setYUnitsSilently

public void setYUnitsSilently(Units newunits)
Sets the current display units in the curently selected dependent variable array.

No notifications are sent to listeners.

Specified by:
setYUnitsSilently in interface Plottable
Parameters:
newunits - the new display units

getXMin

public double getXMin()
Returns the minimum value of the independent variable.

Specified by:
getXMin in interface Plottable
Returns:
the independent variable minimum value

getXMax

public double getXMax()
Returns the maximum value of the independent variable.

Specified by:
getXMax in interface Plottable
Returns:
the independent variable maximum value

isEvenlySampled

public boolean isEvenlySampled()
Returns true if the X array is evenly sampled, false otherwise.

Specified by:
isEvenlySampled in interface Spectrum
Specified by:
isEvenlySampled in interface Plottable
Overrides:
isEvenlySampled in class SpectrumDecorator
Returns:
true if the X array is evenly sampled false otherwise.

getSelectedXArray

private double[] getSelectedXArray(Spectrum sp)
Returns the X array.

Parameters:
sp - the decorated component Spectrum
Returns:
the currently selected independent variable array

updateDataSets

public java.util.ArrayList<DataSet> updateDataSets(java.util.ArrayList<DataSet> al)
                                            throws ViewException
This method updates an ArrayList which stores data set objects, with additional objects built from the input arrays. Data sets are built from the DataSet class.

Specified by:
updateDataSets in interface Plottable
Parameters:
al - the ArrayList to be updated. If set to null, the method creates a new ArrayList instance.
Returns:
the updated ArrayList object
Throws:
ViewException

prepareDataSet

protected DataSet prepareDataSet(double[] xval,
                                 double[] yval,
                                 double[] eval,
                                 Spectrum csp,
                                 java.util.Enumeration id_list)
                          throws ViewException
Execute routine activities when preparing a DataSet object to be plotted. This method is responsible for setting the plot attributes of the data set, based on the type of spectral data supplied to it.

Parameters:
xval - array with independent variable values
yval - array with dependent variable values
eval - array with error values
csp - the original, possibly composite, spectrum
id_list - the enumeration with IDs. This enumeration is bumped by one element each time this method is called.
Returns:
the data set
Throws:
ViewException

finishDataSetBuild

protected void finishDataSetBuild(Spectrum csp,
                                  java.lang.Object spid,
                                  DataSet ds)

updateGraphicsAttributes

protected void updateGraphicsAttributes(GraphicsAttributes pa,
                                        Spectrum sp,
                                        java.lang.Object id)
Updates a GraphicsAttributes object. This method does nothing here; it is up to the subclasses to implement custom behavior.

Parameters:
pa - the object to be updated
sp - the spectrum where to get information from
id - the id that identifies the subspectrum within a composite

setLineType

void setLineType(java.awt.Stroke stroke,
                 java.lang.Object id)
Sets the line type. In this class, this method does nothing. Subclasses should override it in case custom behavior is required.

Parameters:
stroke - the stroke to change to
id - the id that identifies the subspectrum within a composite

setSymbol

void setSymbol(Symbol symbol,
               java.lang.Object id)
Sets the symbol. In this class, this method does nothing. Subclasses should override it in case custom behavior is required.

Parameters:
symbol - the symbol to change to
id - the id that identifies the subspectrum within a composite

setSymbolSize

void setSymbolSize(int size,
                   java.lang.Object id)
Sets the symbol size. In this class, this method does nothing. Subclasses should override it in case custom behavior is required.

Parameters:
size - the symbol size to change to
id - the id that identifies the subspectrum within a composite

getLineType

java.awt.Stroke getLineType(java.lang.Object id)
Gets the line type. In this class, this method returns a continuous line. Subclasses should override it in case custom behavior is required.

Parameters:
id - the id that identifies the subspectrum within a composite
Returns:
always a continuous line

getSymbol

Symbol getSymbol(java.lang.Object id)
Gets the symbol. In this class, this method returns a null. Subclasses should override it in case custom behavior is required.

Parameters:
id - the id that identifies the subspectrum within a composite
Returns:
always null

getSymbolSize

int getSymbolSize(java.lang.Object id)
Gets the symbol size. In this class, this method returns a zero. Subclasses should override it in case custom behavior is required.

Parameters:
id - the id that identifies the subspectrum within a composite
Returns:
always zero

updateValidDataRanges

public java.util.ArrayList updateValidDataRanges(java.util.ArrayList al)
                                          throws ViewException
This method updates an ArrayList which stores range objects. In the case of a regular spectrum object, the concept of valid data ranges is meaningless, thus this method returns the unaltered input list.

Specified by:
updateValidDataRanges in interface Plottable
Parameters:
al - the ArrayList to be updated. If set to null, code>null is returned.
Returns:
the unchanged ArrayList input object
Throws:
ViewException

getGraphicsAttributes

public java.util.Map getGraphicsAttributes()
Gets a map of graphics attributes associated with each element of the composite. In this case, default GraphicsAttributes instances are built. It is up to the subclasses to implememnt custom behavior.

Specified by:
getGraphicsAttributes in interface Plottable
Returns:
a map of default graphics attributes instances

setGraphicsAttributes

public void setGraphicsAttributes(java.util.Map attributes)
Sets a list of graphics attributes. This method does nothing in this class.

Specified by:
setGraphicsAttributes in interface Plottable
Parameters:
attributes - ignored

getVisualEditor

public Command getVisualEditor()
Returns a Command object that implements a spectrum screen editor.

Specified by:
getVisualEditor in interface Plottable
Returns:
a command object

getSpectrumNormalizer

public Command getSpectrumNormalizer()
Returns a Command object that implements a spectrum normalizer.

Returns:
a command object

getDragProcessor

public Command getDragProcessor()

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates a clone copy of this object.

Specified by:
clone in interface Spectrum
Overrides:
clone in class SpectrumDecorator
Throws:
java.lang.CloneNotSupportedException

forceSetChanged

public void forceSetChanged()