org.concord.biologica.engine
Class SpeciesImageRow

java.lang.Object
  |
  +--org.xml.sax.HandlerBase
        |
        +--org.concord.biologica.engine.EngineObject
              |
              +--org.concord.biologica.engine.SpeciesImageRow
All Implemented Interfaces:
org.xml.sax.DocumentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, java.util.EventListener, java.beans.PropertyChangeListener, java.io.Serializable

public final class SpeciesImageRow
extends EngineObject
implements java.io.Serializable, java.beans.PropertyChangeListener

This class represents a row of a SpeciesImage. Specifically, this object maintains an understanding of what species characteristics are valid for this row of a SpeciesImage.

An object of this class will generate the following property change events:

Version:
$Revision: 1.1.1.1 $ $Date: 2001/04/28 00:39:15 $
Author:
$Author: ed $
See Also:
EngineProp.CHARACTERISTIC_ADDED_TO_ROW, EngineProp.CHARACTERISTIC_REMOVED_FROM_ROW, EngineProp.DELETED, EngineProp.ID, EngineProp.LOCKED_STATE, EngineProp.NAME, org.concord.biologica.engine.EngineProp#ROW_GENDER, EngineProp.XXSMALL_HOTSPOT, EngineProp.XSMALL_HOTSPOT, EngineProp.SMALL_HOTSPOT, EngineProp.MEDIUM_HOTSPOT, EngineProp.LARGE_HOTSPOT, EngineProp.XLARGE_HOTSPOT, PropertyChangeListener, Serialized Form

Fields inherited from class org.concord.biologica.engine.EngineObject
AUTOMATIC_LOCKED, AUTOMATIC_LOCKED_STRING, changes, deleted, FALSE, id, lockedState, MANUAL_AND_AUTOMATIC_LOCKED, MANUAL_AND_AUTOMATIC_LOCKED_STRING, MANUAL_LOCKED, MANUAL_LOCKED_STRING, NULL_ID, TRUE, UNLOCKED, UNLOCKED_STRING, xmlElementContext
 
Constructor Summary
SpeciesImageRow(SpeciesImage aSpeciesImage, java.lang.String aName)
          Creates a new species image row.
SpeciesImageRow(SpeciesImage aSpeciesImage, java.lang.String anElementName, int anElementID, com.sun.xml.parser.Parser anXMLParser, ImportContext importContext)
          Create a new SpeciesImageRow and start handling XML parsing events to set the properties of this object.
 
Method Summary
 void addCharacteristic(Characteristic aCharacteristic)
          Adds a characteristic to the row.
 void characters(char[] ch, int start, int length)
          Receive notification of character data.
 void delete()
          Delete this object, notifying parent objects and deleting any child objects.
 void delete(boolean notifyChange)
           
 void endElement(java.lang.String anElementName)
          Handle notification that the parsing of the given element has ended.
 java.util.Enumeration getCharacteristics()
          Returns an enumeration over the vector of characteristics in this row.
 int getGender()
          Return the gender of images in this row, which will be one of Species.FEMALE_AND_MALE, Species.FEMALE_ONLY or Species.MALE_ONLY.
 java.lang.String getGenderAsString()
          Return the gender of images in this row, which will be one of Species.FEMALE_AND_MALE_STRING, Species.FEMALE_ONLY_STRING or Species.MALE_ONLY_STRING.
 java.awt.Point getHotspot(int imageSize)
          Get the given hotspot location.
 java.awt.Point getLargeHotspot()
          Get the large hotspot location.
 java.awt.Point getMediumHotspot()
          Get the medium hotspot location.
 java.lang.String getName()
          Return the name of this species image row.
 int getNumberOfCharacteristics()
          Return the number of characteristics in this row.
 java.awt.Point getSmallHotspot()
          Get the small hotspot location.
 Species getSpecies()
          Return the Species of this object.
 SpeciesImage getSpeciesImage()
          Return the SpeciesImage of this object.
 World getWorld()
          Get the world containing this object.
 java.awt.Point getXLargeHotspot()
          Get the xLarge hotspot location.
 java.awt.Point getXSmallHotspot()
          Get the xSmall hotspot location.
 java.awt.Point getXXSmallHotspot()
          Get the xxSmall hotspot location.
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable white space character data.
 boolean isOnHotspot(int organismImageSize, int x, int y)
          Return whether the given coordinates are on the hotspot for this image row
 void propertyChange(java.beans.PropertyChangeEvent event)
          Handle property change events
 boolean removeCharacteristic(Characteristic aCharacteristic)
          Removes a characteristic from the row.
 void replaceCharacteristic(Characteristic oldCharacteristic, Characteristic newCharacteristic)
          Replace the given old Characteristic with the given new Characteristic.
 void setGender(int aGender)
          Set the gender of the images in this row.
 void setGenderAsString(java.lang.String aGenderString)
          Set the gender of the images in this row as a string.
 void setLargeHotspot(java.awt.Point aHotspot)
          Set the large hotspot location.
 void setMediumHotspot(java.awt.Point aHotspot)
          Set the medium hotspot location.
 void setName(java.lang.String aName)
          Set the name of this species image row.
 void setSmallHotspot(java.awt.Point aHotspot)
          Set the small hotspot location.
 void setXLargeHotspot(java.awt.Point aHotspot)
          Set the xLarge hotspot location.
 void setXSmallHotspot(java.awt.Point aHotspot)
          Set the xSmall hotspot location.
 void setXXSmallHotspot(java.awt.Point aHotspot)
          Set the xxSmall hotspot location.
 void startElement(java.lang.String anElementName, org.xml.sax.AttributeList amap)
          Handle notification that the parser has hit the start of a new element with the given name and attributes.
 java.lang.String toString()
          Return a string representation of this object.
 void writeToStream(java.io.PrintWriter stream)
          Writes this object to the given stream in XML format.
 
Methods inherited from class org.concord.biologica.engine.EngineObject
addPropertyChangeListener, getID, getLockedState, getLockedStateAsString, isAutomaticLocked, isDeleted, isLocked, isManualLocked, notifySelected, release, removePropertyChangeListener, setAutomaticLocked, setID, setLockedState, setLockedStateAsString, setManualLocked
 
Methods inherited from class org.xml.sax.HandlerBase
endDocument, error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, startDocument, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpeciesImageRow

public SpeciesImageRow(SpeciesImage aSpeciesImage,
                       java.lang.String aName)
Creates a new species image row.

Parameters:
aSpeciesImage - SpeciesImage - the species image containing this object, may not be null
aName - String - the species image row name, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

SpeciesImageRow

public SpeciesImageRow(SpeciesImage aSpeciesImage,
                       java.lang.String anElementName,
                       int anElementID,
                       com.sun.xml.parser.Parser anXMLParser,
                       ImportContext importContext)
Create a new SpeciesImageRow and start handling XML parsing events to set the properties of this object.

Parameters:
aSpeciesImage - SpeciesImage - the enclosing species image for this new species image row
anElementName - String - the element name
anElementID - int - the element id
anXMLParser - com.sun.xml.parser.Parser - the element parser
importContext - ImportContext - import context for mapping ids from file to this world
Throws:
java.lang.IllegalArgumentException - - input arguments illegal
Method Detail

startElement

public void startElement(java.lang.String anElementName,
                         org.xml.sax.AttributeList amap)
                  throws org.xml.sax.SAXException
Handle notification that the parser has hit the start of a new element with the given name and attributes.

For internal elements (elements that are non-EngineObject instance variables of this object), call xmlElementContext.startElement() and xmlElementContext will receive the remaining element notifications. For external elements (elements that are EngineObject instance variables of this object), create an object of the appropriate class and that object will receive the remaining element notifications.

Overrides:
startElement in class org.xml.sax.HandlerBase
Parameters:
anElementName - String - name of element
amap - AttributeList - an attribute list

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Receive notification of character data.
Overrides:
characters in class org.xml.sax.HandlerBase
Parameters:
ch - char[] - characters
start - int - start of string
length - int - length of string

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Receive notification of ignorable white space character data.
Overrides:
ignorableWhitespace in class org.xml.sax.HandlerBase
Parameters:
ch - char[] - characters
start - int - start of string
length - int - length of string

endElement

public void endElement(java.lang.String anElementName)
                throws org.xml.sax.SAXException
Handle notification that the parsing of the given element has ended.
Overrides:
endElement in class org.xml.sax.HandlerBase
Parameters:
anElementName - String - the element name

delete

public void delete()
Delete this object, notifying parent objects and deleting any child objects.

When this method is successful, a property change event is generated for the property named EngineProp.DELETED.

Overrides:
delete in class EngineObject

delete

public void delete(boolean notifyChange)

toString

public java.lang.String toString()
Return a string representation of this object.

Overrides:
toString in class EngineObject
Returns:
String - string representation of object

getSpeciesImage

public SpeciesImage getSpeciesImage()
Return the SpeciesImage of this object.

Returns:
SpeciesImage - SpeciesImage of this object, never null

getSpecies

public Species getSpecies()
Return the Species of this object.

Returns:
Species - the species of this object, never null

getWorld

public World getWorld()
Get the world containing this object.

Overrides:
getWorld in class EngineObject
Returns:
World - the world containing this object, never null.

getName

public java.lang.String getName()
Return the name of this species image row. May be null.

Returns:
String - name of this species image row, may not be null.

setName

public void setName(java.lang.String aName)
Set the name of this species image row.

When this method is successful, a property change event is fired for the property named EngineProp.NAME.

Parameters:
aName - String - the new name of this species image row, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument illegal
ObjectDeletedException - - object is deleted and cannot be modified
ObjectLockedException - - object is locked and cannot be modified

getGender

public int getGender()
Return the gender of images in this row, which will be one of Species.FEMALE_AND_MALE, Species.FEMALE_ONLY or Species.MALE_ONLY.

Returns:
int - gender aspect of this species image row
See Also:
Species.FEMALE_AND_MALE, Species.FEMALE_ONLY, Species.MALE_ONLY

getGenderAsString

public java.lang.String getGenderAsString()
Return the gender of images in this row, which will be one of Species.FEMALE_AND_MALE_STRING, Species.FEMALE_ONLY_STRING or Species.MALE_ONLY_STRING. Returns a string.

Returns:
int - gender aspect of this species image row
See Also:
Species.FEMALE_AND_MALE_STRING, Species.FEMALE_ONLY_STRING, Species.MALE_ONLY_STRING

setGender

public void setGender(int aGender)
Set the gender of the images in this row.

The new gender must be one of Species.FEMALE_AND_MALE, Species.FEMALE_ONLY or Species.MALE_ONLY.

When this method is successful, a property change event is fired for the property named EngineProp.ROW_GENDER.

Parameters:
aGender - int - the new gender of this species image row
Throws:
java.lang.IllegalArgumentException - - input argument illegal
ObjectDeletedException - - object is deleted and cannot be modified
ObjectLockedException - - object is locked and cannot be modified
See Also:
Species.FEMALE_AND_MALE, Species.FEMALE_ONLY, Species.MALE_ONLY

setGenderAsString

public void setGenderAsString(java.lang.String aGenderString)
Set the gender of the images in this row as a string.

The new gender must be one of Species.FEMALE_AND_MALE_STRING, Species.FEMALE_ONLY_STRING or Species.MALE_ONLY_STRING.

When this method is successful, a property change event is fired for the property named EngineProp.ROW_GENDER.

Parameters:
aGenderString - String - the new gender of this species image row as a string
Throws:
java.lang.IllegalArgumentException - - input argument illegal
ObjectDeletedException - - object is deleted and cannot be modified
ObjectLockedException - - object is locked and cannot be modified
See Also:
Species.FEMALE_AND_MALE, Species.FEMALE_ONLY, Species.MALE_ONLY

getCharacteristics

public java.util.Enumeration getCharacteristics()
Returns an enumeration over the vector of characteristics in this row.

Returns:
Enumeration - an enumeration over the characteristics in this row

getNumberOfCharacteristics

public int getNumberOfCharacteristics()
Return the number of characteristics in this row.

Returns:
int - the number of characteristics in this row

addCharacteristic

public void addCharacteristic(Characteristic aCharacteristic)
Adds a characteristic to the row.

Parameters:
aCharacteristic - Characteristic - a new characteristic, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument illegal

removeCharacteristic

public boolean removeCharacteristic(Characteristic aCharacteristic)
Removes a characteristic from the row.

Parameters:
aCharacteristic - Characteristic - a characteristic, may not be null
Returns:
boolean indicating whether or not the characteristic was found and removed
Throws:
java.lang.IllegalArgumentException - - input argument illegal

replaceCharacteristic

public void replaceCharacteristic(Characteristic oldCharacteristic,
                                  Characteristic newCharacteristic)
Replace the given old Characteristic with the given new Characteristic. The key here is that we should maintain the position, so the old and new characteristics have the same order in this object.

If the oldCharacteristic is null or not found, then we just add the newCharacteristic on to the end of the list of characteristics.

If the newCharacteristic is null, then we just remove the oldCharacteristic.

If both the oldCharacteristic and the newCharacteristic are null or not found, do nothing.

Parameters:
Characteristic - oldCharacteristic - characteristic to remove, may be null
Characteristic - newCharacteristic - characteristic to add, may be null

getHotspot

public java.awt.Point getHotspot(int imageSize)
Get the given hotspot location.

Parameters:
imageSize - int - image size
Returns:
Point - hotspot location, null if imageSize wasn't a legal one

getXXSmallHotspot

public java.awt.Point getXXSmallHotspot()
Get the xxSmall hotspot location.

Returns:
Point - xxSmall hotspot location, never null

setXXSmallHotspot

public void setXXSmallHotspot(java.awt.Point aHotspot)
Set the xxSmall hotspot location.

Parameters:
aHotspot - Point - a new hotspot location, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

getXSmallHotspot

public java.awt.Point getXSmallHotspot()
Get the xSmall hotspot location.

Returns:
Point - xSmall hotspot location, never null

setXSmallHotspot

public void setXSmallHotspot(java.awt.Point aHotspot)
Set the xSmall hotspot location.

Parameters:
aHotspot - Point - a new hotspot location, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

getSmallHotspot

public java.awt.Point getSmallHotspot()
Get the small hotspot location.

Returns:
Point - small hotspot location, never null

setSmallHotspot

public void setSmallHotspot(java.awt.Point aHotspot)
Set the small hotspot location.

Parameters:
aHotspot - Point - a new hotspot location, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

getMediumHotspot

public java.awt.Point getMediumHotspot()
Get the medium hotspot location.

Returns:
Point - medium hotspot location, never null

setMediumHotspot

public void setMediumHotspot(java.awt.Point aHotspot)
Set the medium hotspot location.

Parameters:
aHotspot - Point - a new hotspot location, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

getLargeHotspot

public java.awt.Point getLargeHotspot()
Get the large hotspot location.

Returns:
Point - large hotspot location, never null

setLargeHotspot

public void setLargeHotspot(java.awt.Point aHotspot)
Set the large hotspot location.

Parameters:
aHotspot - Point - a new hotspot location, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

getXLargeHotspot

public java.awt.Point getXLargeHotspot()
Get the xLarge hotspot location.

Returns:
Point - xLarge hotspot location, never null

setXLargeHotspot

public void setXLargeHotspot(java.awt.Point aHotspot)
Set the xLarge hotspot location.

Parameters:
aHotspot - Point - a new hotspot location, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

isOnHotspot

public boolean isOnHotspot(int organismImageSize,
                           int x,
                           int y)
Return whether the given coordinates are on the hotspot for this image row
Parameters:
organismImageSize - int - organism image size
x - int - x coordinate
y - int - y coordinate
Returns:
boolean - coordinates are on (true) or not on (false) hotspot

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent event)
Handle property change events
Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
event - PropertyChangeEvent - the property change event

writeToStream

public void writeToStream(java.io.PrintWriter stream)
                   throws java.io.IOException
Writes this object to the given stream in XML format. Usually this method is used to write the object to a file for saving it, but that is potentially not the only use.

We could supply a default implementation that knows how to write the id value. But that convenience is not chosen because it's never correct to use just this implementation of these methods, so I'd rather have a compilation fail if a derived class fails to implement this method.

The inverse of this method is a constructor that takes a org.xml.sax.Parser argument and other arguments.

Overrides:
writeToStream in class EngineObject
Parameters:
stream - PrintWriter - print stream
Throws:
java.lang.IllegalArgumentException - - input arguments illegal
java.io.IOException - - an IO error occurred in java libraries