com.rolemodelsoft.drawlet.basics
Class FigureRelativePoint

java.lang.Object
  |
  +--com.rolemodelsoft.drawlet.basics.AbstractLocator
        |
        +--com.rolemodelsoft.drawlet.basics.FigureRelativePoint
Direct Known Subclasses:
LineFigureRelativePoint

public class FigureRelativePoint
extends AbstractLocator
implements FigureHolder

This class implements Locator by providing x and y coordinates that are relative to a Figure. Although it is assumed that the normal use will have these locators within the bounds of the Figure, that is not necessary.

See Also:
Serialized Form

Field Summary
protected  Figure figure
          The figure from which we derive our coordinates
protected  int offsetX
          The x offset from the purely relative position.
protected  int offsetY
          The y offset from the purely relative position.
protected  double relativeX
          The relative x position from the top-left to bottom-right from which to derive our coordinates.
protected  double relativeY
          The relative y position from the top-left to bottom-right from which to derive our coordinates.
 
Constructor Summary
FigureRelativePoint(Figure figure)
          Constructs and initializes a new instance of a locator which is relative to a figure
FigureRelativePoint(Figure figure, double relativeX, double relativeY)
          Constructs and initializes a new instance of a locator which is relative to a figure
FigureRelativePoint(Figure figure, double relativeX, double relativeY, int offsetX, int offsetY)
          Constructs and initializes a new instance of a locator which is relative to a figure
FigureRelativePoint(Figure figure, int offsetX, int offsetY)
          Constructs and initializes a new instance of a locator which is relative to a figure
 
Method Summary
protected  int defaultOffsetX()
          Answer the default/initial value of offsetX.
protected  int defaultOffsetY()
          Answer the default/initial value of offsetY.
protected  double defaultRelativeX()
          Answer the default/initial value of relativeX.
protected  double defaultRelativeY()
          Answer the default/initial value of relativeY.
 java.lang.Object duplicate()
          Duplicates the receiver.
 java.lang.Object duplicateIn(java.util.Hashtable duplicates)
          Duplicates the receiver in the given Hashtable.
 Figure getFigure()
          Answer the figure to which the receiver is relative.
 void postDuplicate(java.util.Hashtable duplicates)
          After a series of Objects are duplicated, this can be sent to each of the duplicates to resolve any changes it might like to reconcile.
 void setFigure(Figure figure)
          Set the figure the receiver is holding.
 int x()
          Answer the x coordinate.
 int y()
          Answer the y coordinate.
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractLocator
r, theta, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

figure

protected Figure figure
The figure from which we derive our coordinates

relativeX

protected double relativeX
The relative x position from the top-left to bottom-right from which to derive our coordinates. These will most likely be between 0.0 and 1.0, but do not have to be.

relativeY

protected double relativeY
The relative y position from the top-left to bottom-right from which to derive our coordinates. These will most likely be between 0.0 and 1.0, but do not have to be.

offsetX

protected int offsetX
The x offset from the purely relative position.

offsetY

protected int offsetY
The y offset from the purely relative position.
Constructor Detail

FigureRelativePoint

public FigureRelativePoint(Figure figure)
Constructs and initializes a new instance of a locator which is relative to a figure
Parameters:
figure - the figure to which the instance will be relative
See Also:
defaultRelativeX(), defaultRelativeY(), defaultOffsetX(), defaultOffsetY()

FigureRelativePoint

public FigureRelativePoint(Figure figure,
                           double relativeX,
                           double relativeY)
Constructs and initializes a new instance of a locator which is relative to a figure
Parameters:
figure - the figure to which the instance will be relative
relativeX - the percentage of the width of the figure to determine X
relativeY - the percentage of the height of the figure to determine Y
See Also:
defaultOffsetX(), defaultOffsetY()

FigureRelativePoint

public FigureRelativePoint(Figure figure,
                           double relativeX,
                           double relativeY,
                           int offsetX,
                           int offsetY)
Constructs and initializes a new instance of a locator which is relative to a figure
Parameters:
figure - the figure to which the instance will be relative
relativeX - the percentage of the width of the figure to determine X
relativeY - the percentage of the height of the figure to determine Y
offsetX - the offset (added to relative X) in the x direction
offsetY - the offset (added to relative Y) in the y direction

FigureRelativePoint

public FigureRelativePoint(Figure figure,
                           int offsetX,
                           int offsetY)
Constructs and initializes a new instance of a locator which is relative to a figure
Parameters:
figure - the figure to which the instance will be relative
offsetX - the offset (added to relative X) in the x direction
offsetY - the offset (added to relative Y) in the y direction
See Also:
defaultRelativeX(), defaultRelativeY()
Method Detail

defaultOffsetX

protected int defaultOffsetX()
Answer the default/initial value of offsetX. Subclasses may wish to consider changing this from 0
Returns:
an integer representing the default/initial value of offsetX

defaultOffsetY

protected int defaultOffsetY()
Answer the default/initial value of offsetY. Subclasses may wish to consider changing this from 0
Returns:
an integer representing the default/initial value of offsetY

defaultRelativeX

protected double defaultRelativeX()
Answer the default/initial value of relativeX. Subclasses may wish to consider changing this from 0.0
Returns:
a double representing the default/initial value of relativeX

defaultRelativeY

protected double defaultRelativeY()
Answer the default/initial value of relativeY. Subclasses may wish to consider changing this from 0.0
Returns:
a double representing the default/initial value of relativeY

duplicate

public java.lang.Object duplicate()
Duplicates the receiver.
Overrides:
duplicate in class AbstractLocator
Returns:
an Object which is a duplicate of the receiver

duplicateIn

public java.lang.Object duplicateIn(java.util.Hashtable duplicates)
Duplicates the receiver in the given Hashtable.
Overrides:
duplicateIn in class AbstractLocator
Parameters:
duplicates - the Hashtable to put the new duplicate in
Returns:
an Object which is a duplicate of the receiver

getFigure

public Figure getFigure()
Answer the figure to which the receiver is relative.
Specified by:
getFigure in interface FigureHolder
Returns:
the Figure to which the receiver is relative

postDuplicate

public void postDuplicate(java.util.Hashtable duplicates)
After a series of Objects are duplicated, this can be sent to each of the duplicates to resolve any changes it might like to reconcile. In this case, get the duplicate of the current figure if there is one. Keep the original if not.
Overrides:
postDuplicate in class AbstractLocator
Parameters:
duplicates - a Hashtable where originals as keys and duplicates as elements

setFigure

public void setFigure(Figure figure)
Set the figure the receiver is holding.
Specified by:
setFigure in interface FigureHolder
Parameters:
figure - the Figure to hold

x

public int x()
Answer the x coordinate.
Overrides:
x in class AbstractLocator
Returns:
an integer representing the x coordinate

y

public int y()
Answer the y coordinate.
Overrides:
y in class AbstractLocator
Returns:
an integer representing the y coordinate