ikayaki
Class Project

java.lang.Object
  extended by ikayaki.Project

public class Project
extends Object

Represents a measurement project file. Project is responsible for managing and storing the data that is recieved from the magnetometer measurements. Any changes made to the project will be written to file regularly (autosave).

Project is responsible for controlling the magnetometer through the SQUID API. Controlling the SQUID will be done in a private worker thread. Only one project at a time may access the SQUID.

All operations are thread-safe.

Author:
Esko Luontola

Nested Class Summary
private  class Project.DummyMeasurement
          A measurement that gives random data for testing purposes.
private  class Project.ManualDemag
          Runs a manual demag command and adds a new step to this project with the demag value.
private static class Project.ManualDemagAxel
           
private  class Project.ManualMeasure
          Runs a manual measure command and adds a new step to this project with the measurement data.
private  class Project.ManualMove
          Runs a manual move command.
private static class Project.ManualMovePosition
           
private  class Project.ManualRotate
          Runs a manual rotate command.
private  class Project.Measurement
          Runs the measurements and adds the measurement data to this project.
static class Project.Normalization
          The type of normalization to use for the measurement values.
static class Project.Orientation
          The orientation of the sample in the measurements.
static class Project.SampleType
          The type of a measured sample.
static class Project.State
          The state of the project's measurements.
static class Project.Type
          The type of the project.
 
Field Summary
static String AREA_PROPERTY
           
private  LastExecutor autosaveQueue
          Scheduler for automatically writing the modified project to file after a short delay.
private  Runnable autosaveRunnable
          Operation that will save the project to file.
private  boolean closed
          Tells if this project been closed with closeProject().
static String COMMENT_PROPERTY
           
private  MeasurementStep currentStep
          Current measurement step, or null if no measurement is running.
static String DATE_PROPERTY
           
private static boolean DEBUG
           
private  double dip
          Dip of the sample.
private  File file
          Location of the project file in the local file system.
static String LATITUDE_PROPERTY
           
private  EventListenerList listenerList
          Listeners for this project.
static String LONGITUDE_PROPERTY
           
private  double mass
          Mass of the sample, or a negative value if no mass is defined.
static String MEASUREMENT_TYPE_AUTO_VALUE
           
static String MEASUREMENT_TYPE_MANUAL_VALUE
           
static String MEASUREMENT_TYPE_PROPERTY
           
private  boolean modified
          true if the project has been modified, otherwise false.
private  Project.Normalization normalization
          The type of normalization to use.
static String OPERATOR_PROPERTY
           
private  Project.Orientation orientation
          Orientation of the sample.
private static Hashtable<File,Project> projectCache
          Caches the created and loaded Project objects to make sure that no more than one object will be created for each physical file.
private static Hashtable<File,Object> projectTypeCache
          Caches the types of the project files, as read by getType(Project).
private  Properties properties
          Custom properties of this project stored in a map.
static String ROCK_TYPE_PROPERTY
           
private  Project.SampleType sampleType
          Type of the sample.
private  MeasurementSequence sequence
          Measurement sequence of this project.
static String SITE_PROPERTY
           
private  Squid squid
          Pointer to the SQUID device interface, or null if this project is not its owner.
private  Project.State state
          Current state of the measurements.
private  double strike
          Strike of the sample.
private  double susceptibility
          Susceptibility of the sample, or a negative value if no susceptibility is defined.
private  javax.vecmath.Matrix3d transform
          Matrix for correcting the sample's orientation.
private  Project.Type type
          Type of the measurement project.
private  double volume
          Volume of the sample, or a negative value if no volume is defined.
 
Constructor Summary
private Project(File file, Document document)
          Creates a new project from the specified document.
private Project(File file, Project.Type type)
          Creates a new project of the specified type.
 
Method Summary
 void addMeasurementListener(MeasurementListener l)
          Adds a MeasurementListener to the project.
 void addProjectListener(ProjectListener l)
          Adds a ProjectListener to the project.
 boolean addSequence(MeasurementSequence append)
          Appends a sequence to this project's sequence.
 boolean addStep(int index, MeasurementStep step)
          Adds a step to the specified index of this project's sequence.
 boolean addStep(MeasurementStep step)
          Appends a step to this project's sequence.
static boolean closeProject(Project project)
          Ensures that the project file is saved and frees the resources taken by the project.
 MeasurementSequence copySequence(int... indices)
          Returns a copy of this project's sequence.
 MeasurementSequence copySequence(int start, int end)
          Returns a copy of this project's sequence.
static Project createAFProject(File file)
          Creates an AF project file.
static Project createCalibrationProject(File file)
          Creates a calibration project file.
static Project createProject(File file, Project.Type type)
          Creates a project file of the specified type.
static Project createThellierProject(File file)
          Creates a thellier project file.
static Project createThermalProject(File file)
          Creates a thermal project file.
 boolean doAbort()
          Aborts the currently running measurement.
 boolean doAutoStep()
          Starts an auto step measurement.
 boolean doManualDemagY(double amplitude)
          Demagnetizes the sample in Y direction with the specified amplitude.
 boolean doManualDemagZ(double amplitude)
          Demagnetizes the sample in Z direction with the specified amplitude.
 boolean doManualMeasure()
          Measures the X, Y and Z of the sample.
private  boolean doManualMove(Project.ManualMovePosition position)
          Moves the sample handler to the specified position.
 boolean doManualMoveBackground()
          Moves the sample handler to the Background position.
 boolean doManualMoveDegausserY()
          Moves the sample handler to the DegausserY position.
 boolean doManualMoveDegausserZ()
          Moves the sample handler to the DegausserZ position.
 boolean doManualMoveHome()
          Moves the sample handler to the Home position.
 boolean doManualMoveLeftLimit()
          Moves the sample handler to the LeftLimit position.
 boolean doManualMoveMeasurement()
          Moves the sample handler to the Measurement position.
 boolean doManualMoveRightLimit()
          Moves the sample handler to the RightLimit position.
 boolean doManualReset()
          Resets the X, Y and Z of the sample.
 boolean doManualRotate(int angle)
          Rotates the sample handler to the specified angle.
 boolean doManualStepDone()
          Marks the on-going manual measurement step as completed.
 boolean doPause()
          Pauses the currently running measurement.
 boolean doSingleStep()
          Starts a single step measurement.
 boolean exportToDAT(File file)
          Writes the project to a file in DAT format.
 boolean exportToSRM(File file)
          Writes the project to a file in SRM format.
 boolean exportToTDT(File file)
          Writes the project to a file in TDT format.
protected  void fireMeasurementEvent(MeasurementStep step, MeasurementEvent.Type type)
          Notifies all listeners that have registered for MeasurementEvents.
protected  void fireProjectEvent(ProjectEvent.Type type)
          Notifies all listeners that have registered for ProjectEvents.
static Project[] getCachedProjects()
          Returns an array containing all the projects that are in the project cache.
 int getCompletedSteps()
          Returns the number of completed steps in this project.
 MeasurementStep getCurrentStep()
          Returns the step that is currently being measured.
 double getDip()
          Returns the dip of the sample.
 Document getDocument()
          Exports this project to a DOM document.
 File getFile()
          Returns the project file of this project.
 double getMass()
          Returns the mass of the sample.
 String getName()
          Returns the name of this project.
 Project.Normalization getNormalization()
          Returns the normalization to be used for the measurement values.
 Project.Orientation getOrientation()
          Returns the orientation of the sample.
 String getProperty(String key)
          Returns a project information property.
 String getProperty(String key, String defaultValue)
          Returns a project information property.
 Project.SampleType getSampleType()
          Returns the type of the sample.
 Squid getSquid()
          Returns the Squid if this project is its owner, otherwise returns null.
 Project.State getState()
          Returns the current measurement state of this project.
 MeasurementStep getStep(int index)
          Returns a step from the sequence.
 int getSteps()
          Returns the number of steps in this project.
 double getStrike()
          Returns the strike of the sample.
 double getSusceptibility()
          Returns the susceptibility of the sample.
 Date getTimestamp()
          Returns the timestamp of the last completed measurement.
protected  javax.vecmath.Matrix3d getTransform()
          Returns the current transformation matrix for the sample.
 Project.Type getType()
          Returns the type of this project.
static Project.Type getType(File file)
          Returns the type of a project file.
<A> A
getValue(int index, MeasurementValue<A> algorithm)
          Calculates and returns a value from a measurement step.
 double getVolume()
          Returns the volume of the sample.
 boolean isAbortEnabled()
          Tells whether it is possible to abort the measurement.
 boolean isAutoStepEnabled()
          Tells whether it is allowed to do an auto step measurement.
 boolean isClosed()
          Returns true if this project has been closed with closeProject().
 boolean isDegaussingEnabled()
          Tells whether it is allowed to use the degausser in this project.
 boolean isHolderCalibration()
          Returns true if this project file has been set as the Sample Holder Calibration project in the program settings.
 boolean isManualControlEnabled()
          Tells whether it is allowed to control the Squid manually.
 boolean isModified()
          Tells whether the project has been modified and it needs to be saved.
 boolean isPauseEnabled()
          Tells whether it is possible to pause the measurement.
 boolean isSequenceEditEnabled()
          Tells whether it is allowed to edit the sequence.
 boolean isSingleStepEnabled()
          Tells whether it is allowed to do a single step measurement.
static Project loadProject(File file)
          Loads a saved project file.
private static String pad(String s, int length, int alignment)
          Adds spaces to a string until it is the right length.
 void removeMeasurementListener(MeasurementListener l)
          Removes a MeasurementListener from the project.
 void removeProjectListener(ProjectListener l)
          Removes a ProjectListener from the project.
 boolean removeStep(int index)
          Removes a step from this project's sequence.
 boolean removeStep(int start, int end)
          Removes a series of steps from this project's sequence.
private  void runMeasurement()
          Runs a measurement sequence until it is paused, aborted or there are no more steps to measure.
 void save()
          Invokes autosaving.
 boolean saveNow()
          Writes this project to its project file and waits for the operation to complete.
 void setDip(double dip)
          Sets the dip of the sample and calls updateTransforms().
 void setMass(double mass)
          Sets the mass of the sample.
 void setNormalization(Project.Normalization normalization)
          Sets the normalization to be used for the measurement values.
 void setOrientation(Project.Orientation orientation)
          Sets the orientation of the sample and calls updateTransforms().
 void setProperty(String key, String value)
          Sets a project information property.
 void setSampleType(Project.SampleType sampleType)
          Sets the type of the sample and calls updateTransforms().
 boolean setSquid(Squid squid)
          Sets this project the owner of the Squid.
private  void setState(Project.State state)
          Sets the state of this project.
 void setStrike(double strike)
          Sets the strike of the sample and calls updateTransforms().
 void setSusceptibility(double susceptibility)
          Sets the susceptibility of the sample.
 void setVolume(double volume)
          Sets the volume of the sample.
private  void updateTransforms()
          Recalculates the transformation matrix and updates all measurements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values

MEASUREMENT_TYPE_PROPERTY

public static final String MEASUREMENT_TYPE_PROPERTY
See Also:
Constant Field Values

MEASUREMENT_TYPE_AUTO_VALUE

public static final String MEASUREMENT_TYPE_AUTO_VALUE
See Also:
Constant Field Values

MEASUREMENT_TYPE_MANUAL_VALUE

public static final String MEASUREMENT_TYPE_MANUAL_VALUE
See Also:
Constant Field Values

OPERATOR_PROPERTY

public static final String OPERATOR_PROPERTY
See Also:
Constant Field Values

DATE_PROPERTY

public static final String DATE_PROPERTY
See Also:
Constant Field Values

ROCK_TYPE_PROPERTY

public static final String ROCK_TYPE_PROPERTY
See Also:
Constant Field Values

AREA_PROPERTY

public static final String AREA_PROPERTY
See Also:
Constant Field Values

SITE_PROPERTY

public static final String SITE_PROPERTY
See Also:
Constant Field Values

COMMENT_PROPERTY

public static final String COMMENT_PROPERTY
See Also:
Constant Field Values

LATITUDE_PROPERTY

public static final String LATITUDE_PROPERTY
See Also:
Constant Field Values

LONGITUDE_PROPERTY

public static final String LONGITUDE_PROPERTY
See Also:
Constant Field Values

projectCache

private static final Hashtable<File,Project> projectCache
Caches the created and loaded Project objects to make sure that no more than one object will be created for each physical file.


projectTypeCache

private static final Hashtable<File,Object> projectTypeCache
Caches the types of the project files, as read by getType(Project). The value is a Type for valid project files, or an Object for invalid or unknown files.


file

private final File file
Location of the project file in the local file system. Autosaving will save the project to this file.


type

private final Project.Type type
Type of the measurement project. This will affect which features of the project are enabled and disabled.


state

private Project.State state
Current state of the measurements. If no measurement is running, then state is IDLE. Only one measurement may be running at a time.


closed

private boolean closed
Tells if this project been closed with closeProject().


squid

private Squid squid
Pointer to the SQUID device interface, or null if this project is not its owner.


properties

private final Properties properties
Custom properties of this project stored in a map. The project is not interested in what properties are stored; it only saves them.


sequence

private MeasurementSequence sequence
Measurement sequence of this project. In the beginning are all completed measurement steps, and in the end are planned measurement steps. Completed measurements may NOT be deleted.


strike

private double strike
Strike of the sample. Will be used to create the transform matrix. The unit is degrees (0 to 360).


dip

private double dip
Dip of the sample. Will be used to create the transform matrix. The unit is degrees (0 to 180).


sampleType

private Project.SampleType sampleType
Type of the sample. Will be used to create the transform matrix.


orientation

private Project.Orientation orientation
Orientation of the sample. Will be used to create the transform matrix.


normalization

private Project.Normalization normalization
The type of normalization to use.


transform

private javax.vecmath.Matrix3d transform
Matrix for correcting the sample's orientation. The matrix will be updated whenever the strike, dip, sampleType or orientation is changed. After that the updated matrix will be applied to all measurements.


mass

private double mass
Mass of the sample, or a negative value if no mass is defined. The unit is gram.


volume

private double volume
Volume of the sample, or a negative value if no volume is defined. The unit is cm^3.


susceptibility

private double susceptibility
Susceptibility of the sample, or a negative value if no susceptibility is defined. The unit is 10^-6 SI.


currentStep

private MeasurementStep currentStep
Current measurement step, or null if no measurement is running.


listenerList

private final EventListenerList listenerList
Listeners for this project.


modified

private boolean modified
true if the project has been modified, otherwise false.


autosaveQueue

private final LastExecutor autosaveQueue
Scheduler for automatically writing the modified project to file after a short delay.


autosaveRunnable

private Runnable autosaveRunnable
Operation that will save the project to file.

Constructor Detail

Project

private Project(File file,
                Project.Type type)
Creates a new project of the specified type. This constructor will not write to file, so the user of this method should call the saveNow() method after the project is initialized.

Parameters:
file - path for this project file. The file should exist (may be empty) and be writable, but this constructor will not check it.
type - type of the project.
Throws:
NullPointerException - if any of the parameters is null.

Project

private Project(File file,
                Document document)
Creates a new project from the specified document. This constructor will assume that the specified file is the same from which the document was read.

Parameters:
file - path for this project file. The file should be the same from which document was read and be writable, but this constructor will not check it.
document - the document from which this project will be created.
Throws:
NullPointerException - if any of the parameters is null.
IllegalArgumentException - if the document was not in the right format.
Method Detail

createCalibrationProject

public static Project createCalibrationProject(File file)
Creates a calibration project file.

Parameters:
file - path for the new project file.
Returns:
the created project, or null if file was not writable or it already existed.
Throws:
NullPointerException - if file is null.

createAFProject

public static Project createAFProject(File file)
Creates an AF project file.

Parameters:
file - path for the new project file.
Returns:
the created project, or null if file was not writable or it already existed.
Throws:
NullPointerException - if file is null.

createThellierProject

public static Project createThellierProject(File file)
Creates a thellier project file.

Parameters:
file - path for the new project file.
Returns:
the created project, or null if file was not writable or it already existed.
Throws:
NullPointerException - if file is null.

createThermalProject

public static Project createThermalProject(File file)
Creates a thermal project file.

Parameters:
file - path for the new project file.
Returns:
the created project, or null if file was not writable or it already existed.
Throws:
NullPointerException - if file is null.

createProject

public static Project createProject(File file,
                                    Project.Type type)
Creates a project file of the specified type. Ensures that the project file has been written to disk. Adds the created Project object to projectCache.

Parameters:
file - path for the new project file.
type - type of the project.
Returns:
the created project, or null if file was not writable or it already existed.
Throws:
NullPointerException - if file or type is null.

loadProject

public static Project loadProject(File file)
Loads a saved project file. If the file has already been loaded, will return a reference to the existing Project object.

Parameters:
file - project file to be loaded.
Returns:
the loaded project, or null if file is not a valid project file or it was not readable.
Throws:
NullPointerException - if file is null.

closeProject

public static boolean closeProject(Project project)
Ensures that the project file is saved and frees the resources taken by the project. The closed project will automatically detach itself from the Squid. The closed project is removed from the projectCache.

A project should not be used after it has been closed – any further use of the object is undefined (will create an IllegalStateException if somebody tries to modify it). A project can not be closed if it has a measurement running.

Parameters:
project - project to be closed.
Returns:
true if the project has been closed, false if a measurement is running and the project can not be closed.
Throws:
NullPointerException - if the project is null.

getCachedProjects

public static Project[] getCachedProjects()
Returns an array containing all the projects that are in the project cache.


getType

public static Project.Type getType(File file)
Returns the type of a project file. Reads the type of the project from the specified file quickly, without fully loading the Project. The first request for each file reads from the file system, but after that the results are cached for an unspecified time.

Parameters:
file - the path of the project file.
Returns:
the type of the project, or null if the file was not a project file or it was not possible to read it.
Throws:
NullPointerException - if file is null.

getDocument

public Document getDocument()
Exports this project to a DOM document.

Returns:
the exported document, or null if there was a error.

isModified

public boolean isModified()
Tells whether the project has been modified and it needs to be saved.


save

public void save()
Invokes autosaving. This method will mark the project as modified and schedule a saving operation. After this method has not been called for a short while, the project will be written to file.

Throws:
IllegalStateException - if this project has already been closed.

saveNow

public boolean saveNow()
Writes this project to its project file and waits for the operation to complete. Clears any delaying autosave operations. Will do nothing if the project file has already been saved.

Returns:
true if the file has been saved, otherwise false.
Throws:
IllegalStateException - if this project has already been closed.

pad

private static String pad(String s,
                          int length,
                          int alignment)
Adds spaces to a string until it is the right length. Used when exporting to different file formats.

Parameters:
s - the string to be padded.
length - the desired length for the result string.
alignment - alignmet of the text. -1 for left, 0 for center and 1 for right align.
Returns:
the input string appended with spaces. Its length is equal or greater to the specified length.

exportToDAT

public boolean exportToDAT(File file)
Writes the project to a file in DAT format. Will overwrite the file if it already exists.

Parameters:
file - the file to write to.
Returns:
true if the file was successfully written, otherwise false.
Throws:
NullPointerException - if file is null.

exportToSRM

public boolean exportToSRM(File file)
Writes the project to a file in SRM format. Will overwrite the file if it already exists.

Parameters:
file - the file to write to.
Returns:
true if the file was successfully written, otherwise false.
Throws:
NullPointerException - if file is null.

exportToTDT

public boolean exportToTDT(File file)
Writes the project to a file in TDT format. Will overwrite the file if it already exists.

Parameters:
file - the file to write to.
Returns:
true if the file was successfully written, otherwise false.
Throws:
NullPointerException - if file is null.

getFile

public File getFile()
Returns the project file of this project.


getType

public Project.Type getType()
Returns the type of this project.


isHolderCalibration

public boolean isHolderCalibration()
Returns true if this project file has been set as the Sample Holder Calibration project in the program settings.


getState

public Project.State getState()
Returns the current measurement state of this project.

Returns:
the state of the project, or null if the project has been closed.

setState

private void setState(Project.State state)
Sets the state of this project. Fires state change events.

Parameters:
state - the new state to change to.

isClosed

public boolean isClosed()
Returns true if this project has been closed with closeProject(). If it has been closed, no modifications to the project will be allowed.


getName

public String getName()
Returns the name of this project. The name is equal to the name of the project file without the file extension.


getTimestamp

public Date getTimestamp()
Returns the timestamp of the last completed measurement. This is usually less than the last modified date of the file, because this is not affected by changing the project's properties.

Returns:
the timestamp of the last measurement, or null if no measurements are completed.

getSquid

public Squid getSquid()
Returns the Squid if this project is its owner, otherwise returns null.

(NOTE: Is public too unsafe? Maybe return a Proxy (see design patterns), so others can know where the handler is moving but not control it?)


setSquid

public boolean setSquid(Squid squid)
Sets this project the owner of the Squid. Tries to detach the previous owner of the squid. Uses the setOwner() method of the specified Squid.

Only one project may own the Squid at a time. The Squid must be first detached with "setSquid(null)" from its owner before it can be given to another project. Detaching the Squid is possible only when the project's state is IDLE.

Parameters:
squid - pointer to the SQUID interface, or null to detach this project from it.
Returns:
true if the operation was completed, false if the Squid has another owner or a measurement is running (in which case nothing was changed).

getProperty

public String getProperty(String key)
Returns a project information property.

Parameters:
key - the key which is associated with the property.
Returns:
the specified property, or null if the property is not set.

getProperty

public String getProperty(String key,
                          String defaultValue)
Returns a project information property.

Parameters:
key - the key which is associated with the property.
defaultValue - a default value
Returns:
the specified property, or defaultValue if the property is not set.

setProperty

public void setProperty(String key,
                        String value)
Sets a project information property.

Parameters:
key - the key which is associated with the property.
value - new value for the property, or null to remove the property.

getStrike

public double getStrike()
Returns the strike of the sample. The unit is degrees (0 to 360).


setStrike

public void setStrike(double strike)
Sets the strike of the sample and calls updateTransforms(). The unit is degrees (0 to 360).


getDip

public double getDip()
Returns the dip of the sample. The unit is degrees (0 to 180).


setDip

public void setDip(double dip)
Sets the dip of the sample and calls updateTransforms(). The unit is degrees (0 to 180).


getSampleType

public Project.SampleType getSampleType()
Returns the type of the sample.


setSampleType

public void setSampleType(Project.SampleType sampleType)
Sets the type of the sample and calls updateTransforms().

Throws:
NullPointerException - if sampleType is null.

getOrientation

public Project.Orientation getOrientation()
Returns the orientation of the sample.


setOrientation

public void setOrientation(Project.Orientation orientation)
Sets the orientation of the sample and calls updateTransforms().

Throws:
NullPointerException - if orientation is null.

getNormalization

public Project.Normalization getNormalization()
Returns the normalization to be used for the measurement values.


setNormalization

public void setNormalization(Project.Normalization normalization)
Sets the normalization to be used for the measurement values.

Throws:
NullPointerException - if normalization is null.

getTransform

protected javax.vecmath.Matrix3d getTransform()
Returns the current transformation matrix for the sample. For performance reasons, this method returns a reference to the internal data structure and not a copy of it.

WARNING!!! Absolutely NO modification of the data contained in this matrix should be made – if any such manipulation is necessary, it should be done on a copy of the matrix returned rather than the matrix itself.

Returns:
reference to the transformation matrix.

updateTransforms

private void updateTransforms()
Recalculates the transformation matrix and updates all measurements. This method is called automatically by the setStrike(), setDip() and setSampleType() methods.


getMass

public double getMass()
Returns the mass of the sample. The unit is gram.

Returns:
mass of the sample, or a negative number if no mass is specified.

setMass

public void setMass(double mass)
Sets the mass of the sample. The unit is gram.

Parameters:
mass - mass of the sample, or a negative number to clear it.

getVolume

public double getVolume()
Returns the volume of the sample. The unit is cm^3.

Returns:
volume of the sample, or a negative number if no volume is specified.

setVolume

public void setVolume(double volume)
Sets the volume of the sample. The unit is cm^3.

Parameters:
volume - volume of the sample, or a negative number to clear it.

getSusceptibility

public double getSusceptibility()
Returns the susceptibility of the sample. The unit is 10^-6 SI.

Returns:
susceptibility of the sample, or a negative number if no susceptibility is specified.

setSusceptibility

public void setSusceptibility(double susceptibility)
Sets the susceptibility of the sample. The unit is 10^-6 SI.

Parameters:
susceptibility - susceptibility of the sample, or a negative number to clear it.

addProjectListener

public void addProjectListener(ProjectListener l)
Adds a ProjectListener to the project.

Parameters:
l - the listener to be added.

removeProjectListener

public void removeProjectListener(ProjectListener l)
Removes a ProjectListener from the project.

Parameters:
l - the listener to be removed

fireProjectEvent

protected void fireProjectEvent(ProjectEvent.Type type)
Notifies all listeners that have registered for ProjectEvents.

Parameters:
type - type of the event.

addMeasurementListener

public void addMeasurementListener(MeasurementListener l)
Adds a MeasurementListener to the project.

Parameters:
l - the listener to be added.

removeMeasurementListener

public void removeMeasurementListener(MeasurementListener l)
Removes a MeasurementListener from the project.

Parameters:
l - the listener to be removed

fireMeasurementEvent

protected void fireMeasurementEvent(MeasurementStep step,
                                    MeasurementEvent.Type type)
Notifies all listeners that have registered for MeasurementEvents.

Parameters:
step - the measurement step that has generated the event.
type - the type of the event.

addSequence

public boolean addSequence(MeasurementSequence append)
Appends a sequence to this project's sequence. Only the stepValues will be copied from the specified sequence and added as new steps to this project.

If isSequenceEditEnabled() is false, nothing will be done.

Parameters:
append - the measurement sequence to be appended.
Returns:
true if the steps were added, or false if isSequenceEditEnabled() was false.
Throws:
NullPointerException - if sequence is null.

copySequence

public MeasurementSequence copySequence(int start,
                                        int end)
Returns a copy of this project's sequence. Only the stepValues will be copied from this project's sequence. The returned sequence will have no name.

Parameters:
start - index of the first step in the sequence.
end - index of the last step in the sequence. If end < start, then an empty sequence will be returned.
Returns:
copy of the sequence with only stepValues and no results.
Throws:
IndexOutOfBoundsException - if the index is out of range (start < 0 || end >= getSteps()).

copySequence

public MeasurementSequence copySequence(int... indices)
Returns a copy of this project's sequence. Only the stepValues will be copied from this project's sequence. The returned sequence will have no name.

Parameters:
indices - indices of the steps to be included in the sequence. The steps will be included in the same order as their indices are listed.
Returns:
copy of the sequence with only stepValues and no results.
Throws:
IndexOutOfBoundsException - if any of the indices is out of range (index < 0 || index >= getSteps()).

addStep

public boolean addStep(MeasurementStep step)
Appends a step to this project's sequence. Only the stepValue will be copied from the specified step and added as a new step to this project.

Parameters:
step - the measurement step to be added.
Returns:
true, it is always possible to append a step.
Throws:
NullPointerException - if step is null.

addStep

public boolean addStep(int index,
                       MeasurementStep step)
Adds a step to the specified index of this project's sequence. Only the stepValue will be copied from the specified step and added as a new step to this project.

The index must be such, that the indices of the completed measurements will not change.

If isSequenceEditEnabled() is false, nothing will be done.

Parameters:
index - the index to which the step will be added.
step - the measurement step to be added.
Returns:
true if the step was added, or false if isSequenceEditEnabled() was false.
Throws:
IndexOutOfBoundsException - if the index is out of range (index < getCompletedSteps() || index > getSteps()).
NullPointerException - if step is null.

removeStep

public boolean removeStep(int index)
Removes a step from this project's sequence. Completed measurements can not be removed.

If isSequenceEditEnabled() is false, nothing will be done.

Parameters:
index - the index of the step to be removed.
Returns:
true if the step was removed, or false if isSequenceEditEnabled() was false.
Throws:
IndexOutOfBoundsException - if the index is out of range (index < getCompletedSteps() || index >= getSteps()).

removeStep

public boolean removeStep(int start,
                          int end)
Removes a series of steps from this project's sequence. Completed measurements can not be removed.

If isSequenceEditEnabled() is false, nothing will be done.

Parameters:
start - the first index to be removed.
end - the last index to be removed. If end < start, no steps will be removed.
Returns:
true if the steps were removed, or false if isSequenceEditEnabled() was false.
Throws:
IndexOutOfBoundsException - if the index is out of range (start < getCompletedSteps() || end >= getSteps()).

getSteps

public int getSteps()
Returns the number of steps in this project.


getCompletedSteps

public int getCompletedSteps()
Returns the number of completed steps in this project. Steps that are currently being measured, are included in this count. Completed steps are always first in the sequence.


getStep

public MeasurementStep getStep(int index)
Returns a step from the sequence.

Parameters:
index - the index of the step.
Returns:
the specified step.
Throws:
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= getSteps()).

getCurrentStep

public MeasurementStep getCurrentStep()
Returns the step that is currently being measured.

Returns:
the currently measured step, or null if no measurement is active.

getValue

public <A> A getValue(int index,
                      MeasurementValue<A> algorithm)
Calculates and returns a value from a measurement step. The specified MeasurementValue's algorithm will be used and the results returned.

Parameters:
index - the measurement step from which the value is calculated.
algorithm - the algorithm for calculating the desired value.
Returns:
the value returned by the algorithm, or null if it was not possible to calculate it.
Throws:
NullPointerException - if algorithm is null.
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= getSteps()).

runMeasurement

private void runMeasurement()
Runs a measurement sequence until it is paused, aborted or there are no more steps to measure. The project must be in a non-IDLE state before starting a measurement with this method. The measurement should be run in a worker thread and only one at a time.

Throws:
IllegalStateException - if the project's state is IDLE or it has no Squid.

isDegaussingEnabled

public boolean isDegaussingEnabled()
Tells whether it is allowed to use the degausser in this project. The returned value depends on the type and state of this project.


isSequenceEditEnabled

public boolean isSequenceEditEnabled()
Tells whether it is allowed to edit the sequence. The returned value depends on the type and state of this project.


isManualControlEnabled

public boolean isManualControlEnabled()
Tells whether it is allowed to control the Squid manually. The returned value depends on the type and state of this project.


isAutoStepEnabled

public boolean isAutoStepEnabled()
Tells whether it is allowed to do an auto step measurement. The returned value depends on the type and state of this project.


isSingleStepEnabled

public boolean isSingleStepEnabled()
Tells whether it is allowed to do a single step measurement. The returned value depends on the type and state of this project.


isPauseEnabled

public boolean isPauseEnabled()
Tells whether it is possible to pause the measurement. The returned value depends on the type and state of this project.


isAbortEnabled

public boolean isAbortEnabled()
Tells whether it is possible to abort the measurement. The returned value depends on the type and state of this project.


doAutoStep

public boolean doAutoStep()
Starts an auto step measurement. If isAutoStepEnabled() is false but is isSingleStepEnabled() is true, will start a single step measurement. Will do nothing if both are false. If there are no unmeasured steps in the sequence, will add one for a measurement without demagnetization.

The measurement will run in its own thread, and this method will not wait for it to finish.

Returns:
true if the measurement was started, otherwise false.

doSingleStep

public boolean doSingleStep()
Starts a single step measurement. Will do nothing if isSingleStepEnabled() is false.

The measurement will run in its own thread, and this method will not wait for it to finish.

Returns:
true if the measurement was started, otherwise false.

doPause

public boolean doPause()
Pauses the currently running measurement. A paused measurement will halt after it finishes the current measurement step. Will do nothing if isPauseEnabled() is false. Will work even if isPauseEnabled() is false.

This method will notify the measurement thread to pause, but will not wait for it to finish.

Returns:
true if the measurement will pause, otherwise false.

doAbort

public boolean doAbort()
Aborts the currently running measurement. An aborted measurement will halt immediately and leave the handler where it was (enables manual control). Will do nothing if isAbortEnabled() is false.

This method will notify the measurement thread to abort, but will not wait for it to finish.

Returns:
true if the measurement will abort, otherwise false.

doManualMove

private boolean doManualMove(Project.ManualMovePosition position)
Moves the sample handler to the specified position. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Parameters:
position - the position to move the handler to.
Returns:
true if the operation was started, otherwise false.

doManualMoveDegausserY

public boolean doManualMoveDegausserY()
Moves the sample handler to the DegausserY position. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Returns:
true if the operation was started, otherwise false.

doManualMoveDegausserZ

public boolean doManualMoveDegausserZ()
Moves the sample handler to the DegausserZ position. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Returns:
true if the operation was started, otherwise false.

doManualMoveBackground

public boolean doManualMoveBackground()
Moves the sample handler to the Background position. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Returns:
true if the operation was started, otherwise false.

doManualMoveMeasurement

public boolean doManualMoveMeasurement()
Moves the sample handler to the Measurement position. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Returns:
true if the operation was started, otherwise false.

doManualMoveHome

public boolean doManualMoveHome()
Moves the sample handler to the Home position. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Returns:
true if the operation was started, otherwise false.

doManualMoveRightLimit

public boolean doManualMoveRightLimit()
Moves the sample handler to the RightLimit position. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Returns:
true if the operation was started, otherwise false.

doManualMoveLeftLimit

public boolean doManualMoveLeftLimit()
Moves the sample handler to the LeftLimit position. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Returns:
true if the operation was started, otherwise false.

doManualRotate

public boolean doManualRotate(int angle)
Rotates the sample handler to the specified angle. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Parameters:
angle - the angle to rotate the handler to.
Returns:
true if the operation was started, otherwise false.

doManualMeasure

public boolean doManualMeasure()
Measures the X, Y and Z of the sample. Adds the results as a new measurement step to the project. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Returns:
true if the operation was started, otherwise false.

doManualReset

public boolean doManualReset()
Resets the X, Y and Z of the sample. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Returns:
true if the operation was started, otherwise false.

doManualDemagZ

public boolean doManualDemagZ(double amplitude)
Demagnetizes the sample in Z direction with the specified amplitude. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Parameters:
amplitude - the amplitude to demagnetize in mT.
Returns:
true if the operation was started, otherwise false.

doManualDemagY

public boolean doManualDemagY(double amplitude)
Demagnetizes the sample in Y direction with the specified amplitude. Will do nothing if isManualControlEnabled() is false.

The operation will run in its own thread, and this method will not wait for it to finish.

Parameters:
amplitude - the amplitude to demagnetize in mT.
Returns:
true if the operation was started, otherwise false.

doManualStepDone

public boolean doManualStepDone()
Marks the on-going manual measurement step as completed. If there is a manual measurement going on, the project has one on-going measurement step event though the project's state is IDLE. Calling this method when no other manual operation is active, will set that step completed.

Returns:
true if the operation was successful, in which case no measurement step is anymore on-going.