did.gui
Class DIDBaseRoi

java.lang.Object
  |
  +--java.awt.Polygon
        |
        +--did.gui.DIDBaseRoi
Direct Known Subclasses:
DIDPolyRoi, DIDRectRoi

public abstract class DIDBaseRoi
extends java.awt.Polygon
implements DIDRoiIFC

File:         DIDBaseROI.java
Version:      1.1
Description:  Abstract class from which all specialized ROI classes are derived.  This 
class implements the DIDRoiIFC interface and inherits from the Java Polygon class.  Any 
class derived from this one will thus inherit this implementation allowing universal 
access to all common methods and attributes of the ROI architecture.  This class also 
contains a reference to a DIDNode.  This DIDNode points to a specific portion of the 
TreeModel which serves as a starting point from which to set and get all persitable data.

Modification Log:
Date          Name    Comment
xx-xx-xxxx    XXX	   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

See Also:
DIDPolyRoi, DIDRectRoi, Serialized Form

Field Summary
protected  java.awt.geom.AffineTransform at
          Attribute that holds the current transform for this ROI.
protected static int CORNER_HEIGHT
          Integer used to dermine the size and location of the rectangle which marks a vertex.
protected static int CORNER_WIDTH
          Integer used to dermine the size and location of the rectangle which marks a vertex.
protected  boolean focus
          Attribute used to determine if the ROI has focus and therefore should be rendered distinctly.
protected  int myActiveVertex
          Attribute that points to the active vertex.
protected  java.awt.Color myActiveVertexColor
          Attribute used to determine the color of the active vertex.
 DIDNode myAnchorNode
          Attribute that references
protected  java.awt.Color myArrowColor
          Attribute used to determine the color of the arrow showing the logical relationship.
protected  boolean myDrawArrow
          if true, draw an arrow to the logically next ROI
protected  java.awt.Color myFillColor
          Attribute used to determine the color of the ROI's inside.
protected  java.awt.Color myFocusColor
          Attribute used to determine the color of the entire ROI when it does have focus.
protected static java.awt.Font myFont
          Attribute used to determine the type of font used to display coordinate information.
protected static java.awt.Color myFontColor
          Attribute used to determine the color used to display coordinate information.
protected static int myFontSize
          Attribute used to determine the size of the text used to display coordinate information.
protected  DIDBaseRoi myNextRoi
          the next logical node
protected  java.awt.Color myNoFocusColor
          Attribute used to determine the color of the entire ROI when it does not have focus.
protected  DIDBaseRoi myPrevRoi
          the previous logical node
protected  java.awt.Color mySelectedColor
          Attribute used to determine the color of the ROI when it is selected by search function.
protected  int myStatus
          Attribute used to determine the
protected  double myTheta
          Attribute that holds the current rotation factor.
protected  java.awt.Color myVertexColor
          Attribute used to determine the color of each rectangle that marks a vertex.
protected  java.awt.geom.PathIterator pi
          Attribure that hold the current iterator implementation for this ROI.
protected  boolean selected
          Attribute used to determine if the ROI has been searched and therefore should be rendered distinctly.
protected  boolean showCoordinates
          Attribute used to determine if coordinate information should be rendered next to each vertex.
protected static int X_OFFSET
          Integer used to dermine the size and location of the rectangle which marks a vertex.
protected static int Y_OFFSET
          Integer used to dermine the size and location of the rectangle which marks a vertex.
 
Fields inherited from class java.awt.Polygon
bounds, npoints, xpoints, ypoints
 
Fields inherited from interface did.gui.DIDRoiIFC
BASE, CHARACTER, CONSTRUCTING, LINE, MOVING, NORMAL, PAGE, POLYGON, RECTANGLE, RESIZING, ROTATING, UNDETERMINED, UNSPECIFIED, WAITING, WORD, ZONE
 
Constructor Summary
DIDBaseRoi()
          Method used to instatiate the class.
DIDBaseRoi(int x)
          Method used to instantitiate this class.
DIDBaseRoi(int[] tmpX, int[] tmpY, int tmpN)
          Constructor used to initalize the object.
 
Method Summary
abstract  void draw(java.awt.Graphics2D g2d)
          This method renders the object onto whatever graphics object is passed to it as a parameter.
abstract  void draw(java.awt.Graphics2D g2d, float scale)
           
 void drawArrow(java.awt.Graphics2D g2d, float scale)
           
 void drawTriangle(java.awt.Graphics2D g2d, java.awt.Point p1, java.awt.Point p2, int len)
           
 void finalizeROI()
          Method used to finalize and ROI.
 DIDNode getAnchorNode()
          Method used to return a reference to the corresponding DIDNode.
 java.awt.Rectangle getBounds()
           
 java.awt.Point getCenterPoint(float scale)
           
 boolean getDrawArrow()
          Method used to return a value of myDrawArrow.
 java.awt.Color getFillColor()
          Method used to get the color of the ROI's inside.
 java.awt.Color getFocusColor()
          Method used to get the color of the ROI when it has the focus.
 DIDBaseRoi getNextRoi()
          Method used to return a reference to the next ROI.
 int getNodeType()
          Method used to return the type of data this ROI is reprsenting (Zone, Line, Character).
 java.awt.Color getNoFocusColor()
          Method used to get the color of the ROI when it doesn't have the focus.
 java.awt.geom.PathIterator getPathIterator()
          Method used to return the current PathIterator implementation for this class.
 DIDBaseRoi getPrevRoi()
          /*********************************************************************** Method used to return a reference to the previous ROI.
 int getStatus()
          Method used to get the Status of the ROI.
 int getType()
          Method used to get the type (Rectangle, Polygon) of a particular implementation of this class.
 int getVertexCount()
          Method used determine the number of verticies this ROI contains.
 boolean hasFocus()
          Method used to determine if an ROI has the focus.
 void init()
          Method used to initialize the ROI.
 boolean isOriginVertex(int x, int y)
          Method used to dertermine if a set of coordinates is within the bounds of the first vertex of the ROI.
protected  void modifyPoint(int n, int x, int y)
          Method used to safely modify an element in the base polygons coordinate arrays( xpoints, ypoints).
 void rotate(double myAmount)
          Method used to rotate the ROI.
 boolean setActiveVertex(int x, int y)
          Method used to set the active vertex.
 void setActiveVertexCoord(int x, int y)
          Method used to move the active vertex to the specified coordinate.
 void setAnchorNode(DIDNode newAnchorNode)
          Method used to set a reference to the corresponding DIDNode which the ROI is representing.
 void setAnchorNode(DIDNode newAnchorNode, java.lang.String color)
          Method used to set a reference to the corresponding DIDNode which the ROI is representing.
 void setCoordDisp(boolean myValue)
          Method used to determine whether coordinate information is to be displayed next to each vertex in the ROI.
 void setDrawArrow(boolean da)
          Method used to set a value of myDrawArrow.
 void setFillColor(java.awt.Color c)
          Method used to set the color of the ROI's inside.
 void setFocus(boolean state)
          Method used to set the focus of a single instance of a ROI.
 void setFocusColor(java.awt.Color c)
          Method used to set the color of the ROI when it has the focus.
 void setNextRoi(DIDBaseRoi nextRoi)
          Method used to set a value of the next ROI.
 void setNoFocusColor(java.awt.Color c)
          Method used to set the color of the ROI when it doesn't have the focus.
 void setPrevRoi(DIDBaseRoi prevRoi)
          Method used to set a value of the previous ROI.
 void setSelected(boolean state)
          Method used to indicate a ROI is selected by search function.
 void setStatus(int s)
          Method used to set the status of the ROI.
 void setTranslation(int x, int y)
          Convenience method used move the entire ROI to a new location.
 void syncData()
          Method used to synchronize coordinate data between the ROI class and the TreeModel (XML).
 java.lang.String toString()
          Method used to convert ROI statistics into a string that can be returned when the ROI is dumbed to an output stream.
 
Methods inherited from class java.awt.Polygon
addPoint, contains, contains, contains, contains, contains, contains, getBoundingBox, getBounds2D, getPathIterator, getPathIterator, inside, intersects, intersects, translate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myFontSize

protected static int myFontSize
Attribute used to determine the size of the text used to display coordinate information.

myFont

protected static java.awt.Font myFont
Attribute used to determine the type of font used to display coordinate information.

myFontColor

protected static java.awt.Color myFontColor
Attribute used to determine the color used to display coordinate information.

myVertexColor

protected java.awt.Color myVertexColor
Attribute used to determine the color of each rectangle that marks a vertex.

myActiveVertexColor

protected java.awt.Color myActiveVertexColor
Attribute used to determine the color of the active vertex.

myFocusColor

protected java.awt.Color myFocusColor
Attribute used to determine the color of the entire ROI when it does have focus.

myNoFocusColor

protected java.awt.Color myNoFocusColor
Attribute used to determine the color of the entire ROI when it does not have focus.

myFillColor

protected java.awt.Color myFillColor
Attribute used to determine the color of the ROI's inside.

mySelectedColor

protected java.awt.Color mySelectedColor
Attribute used to determine the color of the ROI when it is selected by search function.

myArrowColor

protected java.awt.Color myArrowColor
Attribute used to determine the color of the arrow showing the logical relationship.

CORNER_WIDTH

protected static int CORNER_WIDTH
Integer used to dermine the size and location of the rectangle which marks a vertex.

CORNER_HEIGHT

protected static int CORNER_HEIGHT
Integer used to dermine the size and location of the rectangle which marks a vertex.

X_OFFSET

protected static int X_OFFSET
Integer used to dermine the size and location of the rectangle which marks a vertex.

Y_OFFSET

protected static int Y_OFFSET
Integer used to dermine the size and location of the rectangle which marks a vertex.

myTheta

protected double myTheta
Attribute that holds the current rotation factor.

myActiveVertex

protected int myActiveVertex
Attribute that points to the active vertex. Since the Polygon class stores coordinates in two integer arrays (xpoints and ypoints), the value of this attribute is used to point to a specific element in each array thus making it the active vertex.

myStatus

protected int myStatus
Attribute used to determine the

at

protected java.awt.geom.AffineTransform at
Attribute that holds the current transform for this ROI. The AffineTransform class represents a 2D affine transform that performs a linear mapping from 2D coordinates to other 2D coordinates that preserves the "straightness" and "parallelness" of lines.

pi

protected java.awt.geom.PathIterator pi
Attribure that hold the current iterator implementation for this ROI. The PathIterator interface provides the mechanism for objects that implement the Shape interface to return the geometry of their boundary by allowing a caller to retrieve the path of that boundary a segment at a time.

showCoordinates

protected boolean showCoordinates
Attribute used to determine if coordinate information should be rendered next to each vertex.

focus

protected boolean focus
Attribute used to determine if the ROI has focus and therefore should be rendered distinctly.

selected

protected boolean selected
Attribute used to determine if the ROI has been searched and therefore should be rendered distinctly.

myDrawArrow

protected boolean myDrawArrow
if true, draw an arrow to the logically next ROI

myNextRoi

protected DIDBaseRoi myNextRoi
the next logical node

myPrevRoi

protected DIDBaseRoi myPrevRoi
the previous logical node

myAnchorNode

public DIDNode myAnchorNode
Attribute that references
Constructor Detail

DIDBaseRoi

public DIDBaseRoi(int[] tmpX,
                  int[] tmpY,
                  int tmpN)
Constructor used to initalize the object. Initializes the ROI from the specified parameters.
Parameters:
tmpX - An array of integers corresponding to all the x corrdinates for this ROI.
tmpY - An array of integers corresponding to all the y corrdinates for this ROI.
tmpN - The number of verticies this ROI should contain.

DIDBaseRoi

public DIDBaseRoi(int x)
Method used to instantitiate this class. This constructor takes one argument, x, which preinitializes the number of verticies this ROI should contain.
Parameters:
x - The number of verticies this instance of this class should contain.

DIDBaseRoi

public DIDBaseRoi()
Method used to instatiate the class.
Method Detail

init

public void init()
Method used to initialize the ROI. Initialization involves setting the focus to true, creating a new bounding rectangle (important to ensure proper bounds detection) and loading the vertex rectangle dimensions from the properties file.

getPathIterator

public java.awt.geom.PathIterator getPathIterator()
Method used to return the current PathIterator implementation for this class. The iterator is crucial to the rendering of the ROI as it allows for the application of a transformation to a shape and returns the geometry of the shapes boundary by allowing a caller to retrieve the path of that boundary a segment at a time. This transforamtion does not affect the internal coordinate arrays.
Returns:
The current PathIterator implementation for this class.

draw

public abstract void draw(java.awt.Graphics2D g2d)
This method renders the object onto whatever graphics object is passed to it as a parameter.
Specified by:
draw in interface DIDRoiIFC
Parameters:
g2d - A reference to a specific Graphics2D object onto which this ROI should render itself.

draw

public abstract void draw(java.awt.Graphics2D g2d,
                          float scale)
Specified by:
draw in interface DIDRoiIFC

getBounds

public java.awt.Rectangle getBounds()
Overrides:
getBounds in class java.awt.Polygon

getCenterPoint

public java.awt.Point getCenterPoint(float scale)

drawTriangle

public void drawTriangle(java.awt.Graphics2D g2d,
                         java.awt.Point p1,
                         java.awt.Point p2,
                         int len)

drawArrow

public void drawArrow(java.awt.Graphics2D g2d,
                      float scale)

rotate

public void rotate(double myAmount)
Method used to rotate the ROI. The attribute myTheta is incremented by the value of parameter myAmount. Rotation is accomplished by setting the rotation factor of the affinetransform used to render the ROI. NOTE: Rotation does NOT change the internal data representation of the ROI. Only a call to finalizeROI will reset the Polygon's internal data. As continuous calls to finalizeROI() will destort the ROI due to the internal coordinate structure only being stored as integers instead of doubles it is recommended that the coordinated be finalized only on a user click.
Specified by:
rotate in interface DIDRoiIFC
Parameters:
myAmount - The amount by which the ROI should rotated. Negative values rotate to the left and positive to the right.

isOriginVertex

public boolean isOriginVertex(int x,
                              int y)
Method used to dertermine if a set of coordinates is within the bounds of the first vertex of the ROI. This method is used in the creation process to signify to completion of ROI creation.
Parameters:
x - X coordinate to be tested.
y - Y coordinate to be tested.
Returns:
True if parameters x & y fall inside the bounds of the first vertex, false if it is not.
See Also:
DIDCreationHandler.mouseClicked(java.awt.event.MouseEvent)

setActiveVertexCoord

public void setActiveVertexCoord(int x,
                                 int y)
Method used to move the active vertex to the specified coordinate.
Specified by:
setActiveVertexCoord in interface DIDRoiIFC
Parameters:
x - New x position for the active vertex.
y - New y position for the active vertex.

setActiveVertex

public boolean setActiveVertex(int x,
                               int y)
Method used to set the active vertex. This method should determine if the coordinates passed into it lay within one of the ROIs verticies. If so, make that vertex the active one and return true, else return false.
Specified by:
setActiveVertex in interface DIDRoiIFC
Parameters:
x - X coordinate to be iterrigated to see if it lies within the active vertex bounds.
y - Y coordinate to be iterrigated to see if it lies within the active vertex bounds.
Returns:
True if the x,y parameters are within a vertex handle, false if they are not.

setTranslation

public void setTranslation(int x,
                           int y)
Convenience method used move the entire ROI to a new location. Should be constrained to the active vertex.
Specified by:
setTranslation in interface DIDRoiIFC
Parameters:
x - Integer representing the x coordinate to which the ROI should be moved.
y - Integer representing the y coordinate to which the ROI should be moved.

finalizeROI

public void finalizeROI()
Method used to finalize and ROI. Finalizing means that any pending transforms relating to this ROI (stored in the 'at' attribute) are calculated and a PathIterator is used to enumertate the shape and set the ROI's internal coordinate structure to the appropriate values (based on the transform).
Specified by:
finalizeROI in interface DIDRoiIFC
See Also:
at, pi

toString

public java.lang.String toString()
Method used to convert ROI statistics into a string that can be returned when the ROI is dumbed to an output stream.
Specified by:
toString in interface DIDRoiIFC
Overrides:
toString in class java.lang.Object
Returns:
A string that details the ROI's properties.

getType

public int getType()
Method used to get the type (Rectangle, Polygon) of a particular implementation of this class. Since this class is abstract the DIDRoiIFC.BASE value should never be returned.
Specified by:
getType in interface DIDRoiIFC
Returns:
An integer repesenting the type of ROI (Rectangle, Polygon).

setCoordDisp

public void setCoordDisp(boolean myValue)
Method used to determine whether coordinate information is to be displayed next to each vertex in the ROI.
Specified by:
setCoordDisp in interface DIDRoiIFC
Parameters:
myValue - True if coordinate info is to be displayed next to each vertex, false if no information is to be displayed.

setFocus

public void setFocus(boolean state)
Method used to set the focus of a single instance of a ROI. Only one ROI at a time can have the focus and it is denoted by a different color.
Specified by:
setFocus in interface DIDRoiIFC
Parameters:
state - A boolean primitive used to determine if the current instance of the ROI should get the focus.

setSelected

public void setSelected(boolean state)
Method used to indicate a ROI is selected by search function. selected ROI is denoted by a different color.
Specified by:
setSelected in interface DIDRoiIFC
Parameters:
state - A boolean primitive used to determine if the current instance of the ROI is selected.

hasFocus

public boolean hasFocus()
Method used to determine if an ROI has the focus. Returns the value of attribute focus.
Specified by:
hasFocus in interface DIDRoiIFC
Returns:
True if this ROI has the focus, false if it does not.

setStatus

public void setStatus(int s)
Method used to set the status of the ROI. Status is mainly used in the creation of ROIs.
Specified by:
setStatus in interface DIDRoiIFC
Parameters:
s - An integer that specifies the state of the ROI. WAITING=-1,CONSTRUCTING=0, MOVING=1,RESIZING=2,ROTATING=3,NORMAL=4;
See Also:
DIDCreationHandler

getStatus

public int getStatus()
Method used to get the Status of the ROI.
Specified by:
getStatus in interface DIDRoiIFC
Returns:
An integer that specifies the state of the ROI.
See Also:
DIDRoiIFC.WAITING

setFocusColor

public void setFocusColor(java.awt.Color c)
Method used to set the color of the ROI when it has the focus.
Specified by:
setFocusColor in interface DIDRoiIFC
Parameters:
c - A color object to which the ROI who has the focus should be set.

getFocusColor

public java.awt.Color getFocusColor()
Method used to get the color of the ROI when it has the focus.
Specified by:
getFocusColor in interface DIDRoiIFC
Returns:
A color object representing the color of the ROI with the focus.

setNoFocusColor

public void setNoFocusColor(java.awt.Color c)
Method used to set the color of the ROI when it doesn't have the focus.
Specified by:
setNoFocusColor in interface DIDRoiIFC
Parameters:
c - A color object to which the ROI who doesn't have the focus should be set.

getNoFocusColor

public java.awt.Color getNoFocusColor()
Method used to get the color of the ROI when it doesn't have the focus.
Specified by:
getNoFocusColor in interface DIDRoiIFC
Returns:
A color object representing the color of the ROI with out the focus.

setFillColor

public void setFillColor(java.awt.Color c)
Method used to set the color of the ROI's inside.
Specified by:
setFillColor in interface DIDRoiIFC
Parameters:
A - color object to which the color of the ROI's inside should be set.

getFillColor

public java.awt.Color getFillColor()
Method used to get the color of the ROI's inside.
Specified by:
getFillColor in interface DIDRoiIFC
Returns:
A color object representing the color of the ROI's inside.

setAnchorNode

public void setAnchorNode(DIDNode newAnchorNode)
Method used to set a reference to the corresponding DIDNode which the ROI is representing. This implementation also sets the focus color of the ROI based on the type of data the anchorNode contains.
Specified by:
setAnchorNode in interface DIDRoiIFC
Parameters:
newAnchorNode - A reference to the corresponding DIDNode.
See Also:
#stringToColor

setAnchorNode

public void setAnchorNode(DIDNode newAnchorNode,
                          java.lang.String color)
Method used to set a reference to the corresponding DIDNode which the ROI is representing. This implementation also sets the focus color of the ROI.
Specified by:
setAnchorNode in interface DIDRoiIFC
Parameters:
newAnchorNode - A reference to the corresponding DIDNode.
See Also:
#stringToColor

getAnchorNode

public DIDNode getAnchorNode()
Method used to return a reference to the corresponding DIDNode.
Specified by:
getAnchorNode in interface DIDRoiIFC
Returns:
DIDNode referenced in attribute list and which this ROI is visually representing.

setDrawArrow

public void setDrawArrow(boolean da)
Method used to set a value of myDrawArrow.
Specified by:
setDrawArrow in interface DIDRoiIFC
Tags copied from interface: DIDRoiIFC
Parameters:
myValue - True if an arrow is to be displayed. if false, no information is to be displayed.

getDrawArrow

public boolean getDrawArrow()
Method used to return a value of myDrawArrow.
Returns:
boolean myDrawArrow.

setNextRoi

public void setNextRoi(DIDBaseRoi nextRoi)
Method used to set a value of the next ROI.
Specified by:
setNextRoi in interface DIDRoiIFC

getNextRoi

public DIDBaseRoi getNextRoi()
Method used to return a reference to the next ROI.
Specified by:
getNextRoi in interface DIDRoiIFC
Returns:
DIDBaseRoi which is the logically next ROI.

setPrevRoi

public void setPrevRoi(DIDBaseRoi prevRoi)
Method used to set a value of the previous ROI.
Specified by:
setPrevRoi in interface DIDRoiIFC

getPrevRoi

public DIDBaseRoi getPrevRoi()
/*********************************************************************** Method used to return a reference to the previous ROI.
Specified by:
getPrevRoi in interface DIDRoiIFC
Returns:
DIDBaseRoi which is the logically previous ROI.

syncData

public void syncData()
Method used to synchronize coordinate data between the ROI class and the TreeModel (XML). This method traverses the TreeModel starting from the point of the anchorNode. From here is looks for all nodes whose name begins "Vertex" and whose parent node's name begins with the type of data this ROI represents and ends with "Corner". Once a node is found, the nodes under this node are exposed and if their name begins with "x" their value is set to the current x coordinate and vice versa for those that start with "y". A counter keeps track of where the method is in the internal coordinate structure.
Specified by:
syncData in interface DIDRoiIFC

getNodeType

public int getNodeType()
Method used to return the type of data this ROI is reprsenting (Zone, Line, Character).
Specified by:
getNodeType in interface DIDRoiIFC
Returns:
An integer (should be a DIDRoiIFC constant) denoting the type of data this ROI represents.

modifyPoint

protected void modifyPoint(int n,
                           int x,
                           int y)
Method used to safely modify an element in the base polygons coordinate arrays( xpoints, ypoints). NOTE: This class should ALWAYS be used to modify the internal arrays. Never modify them directly as doing so will not correctly update the bounding rectangle thus causing the contains() method to act in unpredictable ways.
Parameters:
n - References the element in the x & y coordinate arrays which are to be modified.
x - New x coordinate.
y - New y coordinate.

getVertexCount

public int getVertexCount()
Method used determine the number of verticies this ROI contains. This number is obtained from the superclass's attribure npoints.
Specified by:
getVertexCount in interface DIDRoiIFC
Returns:
An integer representing the number of verticies this ROI contains.