jdraw.graphicalobjects
Class GraphicalObject

java.lang.Object
  |
  +--jdraw.graphicalobjects.GraphicalObject
Direct Known Subclasses:
Point, SizedGraphicalObject, TextArea

public abstract class GraphicalObject
extends Object

The abstract parent class of all graphical objects.


Field Summary
private  boolean bDragInProgress
          Flag indicating whether this graphical object is currently dragged.
private  Color colColor
          The color of this object.
private  int iX
          The abscissa of this object.
private  int iY
          The ordinate of this object.
private  ArrayList lstPropertyChangeListeners
           
private  Point ptDragAndDropStartPosition
          The position from where the drag and drop started.
private  Point ptInitialObjectPosition
          The position where this graphical object was at the beginning of the drag and drop.
private  Rectangle rectInitialBoundingBox
           
 
Constructor Summary
GraphicalObject(int iX, int iY, Color colColor)
          Creates a new GraphicalObject with specified position and color.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener pplListener)
          Adds a BoudingBoxListener to this graphical object.
 void commitDragAndDrop(int iMouseX, int iMouseY)
          Stops the drag and drop process, commiting changes.
 void drag(int iMouseX, int iMouseY)
          Updates this graphical object position, relatively to its position at the beginning of the drag and drop process.
protected  void fireBoudingBoxChange()
          Fires a BoudingBox property change event.
abstract  Rectangle getBoundingBox()
          Returns the bounding box of this graphical object.
 Color getColor()
          Returns the color of this graphical object.
abstract  Cursor getCursor()
          Returns the mouse cursor for this object.
 int getDistance(Point ptPoint)
          Returns the minimal distance between this object and the specified point.
static int getDistanceSq(double dblX1, double dblY1, double dblX2, double dblY2)
          Returns the square of the distance between two points, stated by their coordinates (doubles).
static int getDistanceSq(int iX1, int iY1, int iX2, int iY2)
          Returns the square of the distance between two points, stated by their coordinates (integers).
abstract  int getDistanceSq(Point ptPoint)
          Returns the square of the minimal distance between this object and the specified point.
abstract  String getFriendlyName()
          Returns the friendly name of this graphical object.
 GraphicalObjectProperties getPropertyDialog(Frame frmOwner)
          Returns a dialog box used to set the properties of this graphical object.
 int getX()
          Returns the abscissa of this graphical object.
 int getY()
          Returns the ordinate of this graphical object.
 boolean isDragInProgress()
          Indicates whether this graphical object is currently dragged.
protected  void moveTo_silent(int iNewX, int iNewY)
          Moves this graphical object to the specified position, without firing any event.
 void moveTo(int iNewX, int iNewY)
          Moves this graphical object to the specified position.
 void openPropertyDialog(Frame frmOwner)
          Opens a dialog box used to set the properties of this graphical object.
abstract  void paint(Graphics g)
          Paints this graphical object.
protected  void prepareBoudingBoxEvent()
          Prepares the firing of a BoudingBoxEvent by saving the current bounding box.
 void removePropertyChangeListener(PropertyChangeListener pplListener)
          Removes a BoudingBoxListener from this graphical object.
 void rollbackDragAndDrop()
          Stops the drag and drop process, cancelling changes.
protected  void setColor_silent(Color colNewColor)
          Sets the color of this graphical object, without firing any event.
 void setColor(Color colNewColor)
          Sets the color of this graphical object.
protected  void setX_silent(int iNewX)
          Sets the abscissa of this graphical object, without firing any event.
 void setX(int iNewX)
          Sets the abscissa of this graphical object.
protected  void setY_silent(int iNewY)
          Sets the ordinate of this graphical object, without firing any event.
 void setY(int iNewY)
          Sets the ordinate of this graphical object.
 void startDragAndDrop(int iMouseX, int iMouseY)
          Starts the drag and drop process.
 void suspendDragAndDrop()
          Suspends the drag and drop process.
protected  void updateCachedData()
          Invoked when cached data have to be updated.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

iX

private int iX
The abscissa of this object.

iY

private int iY
The ordinate of this object.

colColor

private Color colColor
The color of this object.

lstPropertyChangeListeners

private final ArrayList lstPropertyChangeListeners

rectInitialBoundingBox

private Rectangle rectInitialBoundingBox

bDragInProgress

private boolean bDragInProgress
Flag indicating whether this graphical object is currently dragged.

ptInitialObjectPosition

private final Point ptInitialObjectPosition
The position where this graphical object was at the beginning of the drag and drop.

ptDragAndDropStartPosition

private final Point ptDragAndDropStartPosition
The position from where the drag and drop started.
Constructor Detail

GraphicalObject

public GraphicalObject(int iX,
                       int iY,
                       Color colColor)
Creates a new GraphicalObject with specified position and color.
Method Detail

getBoundingBox

public abstract Rectangle getBoundingBox()
Returns the bounding box of this graphical object.

getCursor

public abstract Cursor getCursor()
Returns the mouse cursor for this object.

getFriendlyName

public abstract String getFriendlyName()
Returns the friendly name of this graphical object.

getPropertyDialog

public GraphicalObjectProperties getPropertyDialog(Frame frmOwner)
Returns a dialog box used to set the properties of this graphical object. This dialog box is packed and ready to be set visible.

openPropertyDialog

public void openPropertyDialog(Frame frmOwner)
Opens a dialog box used to set the properties of this graphical object.

paint

public abstract void paint(Graphics g)
Paints this graphical object.

getDistance

public int getDistance(Point ptPoint)
Returns the minimal distance between this object and the specified point.

getDistanceSq

public abstract int getDistanceSq(Point ptPoint)
Returns the square of the minimal distance between this object and the specified point.

getDistanceSq

public static int getDistanceSq(int iX1,
                                int iY1,
                                int iX2,
                                int iY2)
Returns the square of the distance between two points, stated by their coordinates (integers).
Parameters:
iX1 - the abscissa of the first point
iY1 - the ordinate of the first point
iX2 - the abscissa of the second point
iY2 - the ordinate of the second point

getDistanceSq

public static int getDistanceSq(double dblX1,
                                double dblY1,
                                double dblX2,
                                double dblY2)
Returns the square of the distance between two points, stated by their coordinates (doubles).
Parameters:
dblX1 - the abscissa of the first point
dblY1 - the ordinate of the first point
dblX2 - the abscissa of the second point
dblY2 - the ordinate of the second point

getX

public int getX()
Returns the abscissa of this graphical object.

setX

public void setX(int iNewX)
Sets the abscissa of this graphical object.

setX_silent

protected void setX_silent(int iNewX)
Sets the abscissa of this graphical object, without firing any event.

getY

public int getY()
Returns the ordinate of this graphical object.

setY

public void setY(int iNewY)
Sets the ordinate of this graphical object.

setY_silent

protected void setY_silent(int iNewY)
Sets the ordinate of this graphical object, without firing any event.

moveTo

public void moveTo(int iNewX,
                   int iNewY)
Moves this graphical object to the specified position.

moveTo_silent

protected void moveTo_silent(int iNewX,
                             int iNewY)
Moves this graphical object to the specified position, without firing any event.

getColor

public Color getColor()
Returns the color of this graphical object.

setColor

public void setColor(Color colNewColor)
Sets the color of this graphical object.

setColor_silent

protected void setColor_silent(Color colNewColor)
Sets the color of this graphical object, without firing any event.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener pplListener)
Adds a BoudingBoxListener to this graphical object.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener pplListener)
Removes a BoudingBoxListener from this graphical object.

prepareBoudingBoxEvent

protected void prepareBoudingBoxEvent()
Prepares the firing of a BoudingBoxEvent by saving the current bounding box.

fireBoudingBoxChange

protected void fireBoudingBoxChange()
Fires a BoudingBox property change event.

updateCachedData

protected void updateCachedData()
Invoked when cached data have to be updated.

isDragInProgress

public boolean isDragInProgress()
Indicates whether this graphical object is currently dragged.

startDragAndDrop

public void startDragAndDrop(int iMouseX,
                             int iMouseY)
Starts the drag and drop process.

drag

public void drag(int iMouseX,
                 int iMouseY)
Updates this graphical object position, relatively to its position at the beginning of the drag and drop process.

suspendDragAndDrop

public void suspendDragAndDrop()
Suspends the drag and drop process.

commitDragAndDrop

public void commitDragAndDrop(int iMouseX,
                              int iMouseY)
Stops the drag and drop process, commiting changes.

rollbackDragAndDrop

public void rollbackDragAndDrop()
Stops the drag and drop process, cancelling changes.