org.concord.collisions.engine
Class JDaemon

java.lang.Object
  |
  +--org.concord.collisions.engine.JWorldElement
        |
        +--org.concord.collisions.engine.JDaemon
All Implemented Interfaces:
CCDraggable, CCMassive, java.util.EventListener, java.beans.PropertyChangeListener, java.io.Serializable
Direct Known Subclasses:
JBooster, JDisplDaemon, JImpulseDaemon, JMaxwellDaemon

public abstract class JDaemon
extends JWorldElement

Daemon elements in the world

Daemons are objects that, when active, affect other elements in the world when they collide.

By default, daemons are active all the time (non-timed daemons), but they can become timed daemons and be "programmed" to activate at specific times and durations (activation steps). Timed daemons can be looping, that means that after the last activation step, they start automatically again from the beginning. By default, daemons activate the first time automatically, as soon as the world starts, but they can be set non-automatic, so they require to be activated manually. Daemons can have a filter too, that filters the elements that are affected by it.

Author:
Ingrid Moncada, Dmitry Markman
See Also:
JWorldElement, Serialized Form

Field Summary
protected  java.util.Vector activationSteps
           
protected  java.awt.Color activeColor
           
protected  java.util.Vector collisionHistory
           
protected  int currentActivationStep
           
protected static int DEFAULT_PAINT_RADIUS
           
protected  boolean doCollisionsHistory
           
static float minDistance
           
protected  java.awt.Color timeColor
           
 
Fields inherited from class org.concord.collisions.engine.JWorldElement
acx, acy, areaListener, areaTables, collSensitive, controllable, DEFAULT_MAX_CONSTRAINT, DEFAULT_MIN_CONSTRAINT, doProjection, draggable, elementListeners, flashing, iconHeight, iconWidth, index, iviewer, mass, name, pressedState, propertyListeners, qtIcon, qtMovie, rectsForListener, scaleIcon, showAcceleration, showVelocity, showVelocityNumber, suggestedCollisionTime, swingIcon, vel_scale, vx, vy, wasLastStepCollision
 
Constructor Summary
JDaemon()
           
 
Method Summary
protected  void activate()
           
 void addActivationStep(org.concord.collisions.engine.DaemonActivationStep dStep)
          Add an activation step to the daemon
 void addActivationStep(float time)
          Add a time (in milliseconds) in which the daemon will activate.
 void addActivationStep(float time, float duration)
          Add a time and duration (in milliseconds) in which the daemon will activate
 void addDaemonListener(DaemonListener l)
          Add a daemon listener
 void applyForce(CCForce force)
          JDaemon doesn't support applying forces
protected  void checkingCollisionsSensitive()
           
 void clearConditionExpression()
          clear evaluation condition
 void clearFilter()
          Clears the filter of elements that will be affected after a collision.
 void closeEverything()
           
protected  void deactivate()
           
 void doDrag(CCCoordinateTuner tuner, int x, int y)
           
 void endDrag(CCCoordinateTuner tuner, int x, int y)
           
protected  boolean evaluateExpression(JWorldElement element)
           
 float getActivationStepTime()
          Retrieve the time (in SECONDS) when the daemon will activate next.
 float getActivationStepTime(int i)
          Retrieve the time (in SECONDS) when the daemon will activate in a given activation time.
 org.concord.collisions.engine.ElementCollisionInfo getActiveCollision(JWorldElement element)
          Retrieve the info of the active collision with an element
 java.awt.Color getActiveColor()
           
 float getCMPointX()
          calculates X coordinate of center of mass
 float getCMPointY()
          calculates Y coordinate of center of mass
 java.util.Vector getCollisionHistory()
          Get the collision history of the daemon
 java.awt.Color getColor()
           
 java.lang.String getConditionExpression()
          Returns expression used for evaluation condition of successful collision with daemon
 java.lang.Object getDraggableOwner()
           
 int getDragMode()
           
 float getEffectiveCollisionsRadius()
           
 float getHeight()
          Get the height of the daemon
 java.awt.Color getInactiveColor()
           
 JWorldElement getNuclearElement()
           
 float getWidth()
          Get the width of the daemon
 float getX()
          Get the x position of the daemon
 float getXPotentialEnergy()
           
 float getY()
          Get the y position of the daemon
 float getYPotentialEnergy()
           
 boolean hasCollided()
          Determine if the daemon has collided with any element at any time
 boolean hasCollidedWith(JWorldElement element)
          Determine if the daemon has collided with a given element at any time
 boolean hasCollidedWithAt(JWorldElement element, int indexActStep)
          Determine if the daemon has collided with a given element at a given activation step
 void initElement()
           
 boolean isActive()
          Determine if the daemon is active
 boolean isActiveCollision(JWorldElement element)
          Determine if the daemon is still colliding with a given element
 boolean isAlive()
          Determine if the daemon is alive
 boolean isAutomaticStart()
          Determine if it is an automatic daemon
protected  boolean isElemInDaemon(JWorldElement el)
           
 boolean isLooping()
          Determine if it is a looping daemon
 boolean isPointInside(float px, float py)
          Returns if a specific world coordinates point is inside the element or not
 boolean isPointInsideCenter(float px, float py)
          Returns if a specific world coordinates point is inside the CENTER (only the core) of the element or not
 boolean isTimed()
          Returns if the daemon will activate with activation times (timed) or not.
 boolean manageCollision(JWorldElement element)
          This method is called by JPartWorld when the daemon collides with an element
 boolean manageNoCollision(JWorldElement element)
          This method is called by JPartWorld every step while the daemon is colliding with an element
 void paint(java.awt.Graphics g)
           
 void paintIcon(java.awt.Graphics g)
           
 void paintSelection(java.awt.Graphics g)
           
 boolean panelInfoSupport()
           
 void rememberCurrPosAsInit()
           
 void rememberCurrVelAsInit()
           
 void removeActivationStep(org.concord.collisions.engine.DaemonActivationStep dStep)
          Remove a specific activation step of the daemon
 void removeActivationStep(float time)
          Prevent a daemon to activate in the exact given time
 void removeActivationStep(int index)
          Remove a specific activation step of the daemon, given the index
 void removeAllActivationSteps()
          Remove all the activation steps of the daemon
 void removeDaemonListener(DaemonListener l)
          Remove a daemon listener
 void reset()
          Reset the daemon (kill it)
protected  void resetCollisionsSensitive()
           
 void setActivationStepTime(float time)
          Set a time (in SECONDS) in which the daemon will activate.
 void setActiveColor(java.awt.Color col)
          set color to show when the daemon is active
 void setAutomaticStart(boolean b)
          Set automatic daemon or not automatic daemon
 void setCMPointX(float x)
          set X coordinate of center of mass
 void setCMPointY(float y)
          set Y coordinate of center of mass
 void setColorFilter(boolean b)
          Turns off and on the color filter of the daemon.
 void setConditionExpression(java.lang.String expression)
          Set the expression used for evaluation condition of successful collision with daemon
 void setDragMode(int dragMode)
           
 void setEffectiveCollisionsRadius(float f)
          Sets the minimal distance to center of mass of daemon when collisions may occur
 void setFilter(JWorldElementFilter f)
          Sets the filter of elements that will be affected after a collision.
 void setGeometry(float x, float y)
          set geometry's parameters
 void setGeometry(float x, float y, float width, float height)
          set geometry's parameters
 void setIcon(java.lang.String url)
          Sets icon to show.
 void setInactiveColor(java.awt.Color col)
          set color to show when the daemon is inactive
 void setInfoDrawer(CCInfoDrawer infoDrawer)
           
 void setLooping(boolean b)
          Set looping daemon or not looping daemon
 void shift(float dt)
           
 void shiftV(float dt)
           
 void start()
          Start running the daemon
 void startDrag(int x, int y)
           
 void step(float worldTime)
          This method is called by JPartWorld every step
 
Methods inherited from class org.concord.collisions.engine.JWorldElement
addAreaListener, addAreaListener, addAreaListener, addAreaListener, addAreaToListen, addAreaToListen, addAreaToListen, addAreaToListen, addElementListener, addElemMouseListener, addNeighborX, addNeighborY, addPropertyChangeListener, assignIndNumber, clearConstraints, clearForces, clearIcon, createDefaultCalculator, findDraggable, getAccelerationKoeff, getCollidedParticle, getDoProjection, getDownConstraint, getFlashingColor, getFullEnergy, getFullXEnergy, getFullYEnergy, getGravityX, getGravityY, getIcon, getIconHeight, getIconWidth, getIndex, getIndNumber, getLeftConstraint, getMass, getName, getNthForce, getNumbAppliedForces, getOwner, getPositionChanger, getPotentialEnergy, getQTIcon, getQTMovie, getRightConstraint, getShowAcceleration, getShowVelocity, getTemperature, getUpConstraint, getVelScale, getVx, getVy, getWorldModel, getX, getXacceleration, getXNeighbors, getXTemperature, getY, getYacceleration, getYNeighbors, getYTemperature, isCollisionSensitive, isConstraintsWasSet, isControllable, isDraggable, isEnabled, isFlashing, isMoveable, isPointInside, isPressedState, isSelected, isVisible, notifyAreaListener, notifyElementListeners, notifyMouseListeners, notifyPropertyListeners, paint, paintSelection, propertyChange, rememberCurrAllAsInit, rememberCurrPropAsInit, rememberCurrPropAsInit, removeAreaListener, removeAreaToListen, removeAreaToListen, removeElementListener, removeElemMouseListener, removeForce, removeForce, removePositionChanger, removePropertyChangeListener, reverseVx, reverseVy, select, setAnimIcon, setCollidedParticle, setCollisionSensitive, setColor, setColor, setConstraints, setControllable, setDoProjection, setDraggable, setEnabled, setFlashing, setForceCalculator, setGeometry, setIcon, setIcon, setIcon, setIconSize, setIndex, setMass, setName, setOwner, setPositionChanger, setPressedState, setProperty, setQTIcon, setQTIcon, setQTMovie, setShowAcceleration, setShowVelocity, setVisible, setVx, setVy, setWorldModel, setXConstraints, setYConstraints, unselect, wasCollision
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PAINT_RADIUS

protected static final int DEFAULT_PAINT_RADIUS

activationSteps

protected java.util.Vector activationSteps

currentActivationStep

protected int currentActivationStep

activeColor

protected java.awt.Color activeColor

collisionHistory

protected java.util.Vector collisionHistory

minDistance

public static float minDistance

timeColor

protected java.awt.Color timeColor

doCollisionsHistory

protected boolean doCollisionsHistory
Constructor Detail

JDaemon

public JDaemon()
Method Detail

getDragMode

public int getDragMode()

setDragMode

public void setDragMode(int dragMode)

getXPotentialEnergy

public float getXPotentialEnergy()
Overrides:
getXPotentialEnergy in class JWorldElement

getYPotentialEnergy

public float getYPotentialEnergy()
Overrides:
getYPotentialEnergy in class JWorldElement

shift

public void shift(float dt)

shiftV

public void shiftV(float dt)

getX

public float getX()
Get the x position of the daemon
Overrides:
getX in class JWorldElement

getY

public float getY()
Get the y position of the daemon
Overrides:
getY in class JWorldElement

getWidth

public float getWidth()
Get the width of the daemon

getHeight

public float getHeight()
Get the height of the daemon

setGeometry

public void setGeometry(float x,
                        float y,
                        float width,
                        float height)
                 throws java.lang.Exception
set geometry's parameters
Parameters:
x - daemon's x coordinate
y - daemon's y coordinate
w - daemon's width (minimum 1)
h - daemon's height (minimum 1)

setGeometry

public void setGeometry(float x,
                        float y)
set geometry's parameters
Parameters:
x - daemon's x coordinate
y - daemon's y coordinate
w - daemon's width (minimum 1)
h - daemon's height (minimum 1)

isLooping

public boolean isLooping()
Determine if it is a looping daemon

setLooping

public void setLooping(boolean b)
Set looping daemon or not looping daemon

isAlive

public boolean isAlive()
Determine if the daemon is alive

isActive

public boolean isActive()
Determine if the daemon is active

start

public void start()
Start running the daemon

activate

protected void activate()

deactivate

protected void deactivate()

initElement

public void initElement()
Overrides:
initElement in class JWorldElement

rememberCurrPosAsInit

public void rememberCurrPosAsInit()
Overrides:
rememberCurrPosAsInit in class JWorldElement

rememberCurrVelAsInit

public void rememberCurrVelAsInit()
Overrides:
rememberCurrVelAsInit in class JWorldElement

reset

public void reset()
Reset the daemon (kill it)

isAutomaticStart

public boolean isAutomaticStart()
Determine if it is an automatic daemon

setAutomaticStart

public void setAutomaticStart(boolean b)
Set automatic daemon or not automatic daemon

addActivationStep

public void addActivationStep(float time)
                       throws java.lang.IllegalArgumentException
Add a time (in milliseconds) in which the daemon will activate. The daemon will activate for the minimum duration time

This method checks if the step is valid according to the list of steps the daemon already has

Parameters:
time - activation time of the step to add

addActivationStep

public void addActivationStep(float time,
                              float duration)
                       throws java.lang.IllegalArgumentException
Add a time and duration (in milliseconds) in which the daemon will activate

This method checks if the step is valid according to the list of steps the daemon already has

Parameters:
time - activation time of the step to add
duration - duration time of the step to add

addActivationStep

public void addActivationStep(org.concord.collisions.engine.DaemonActivationStep dStep)
                       throws java.lang.IllegalArgumentException
Add an activation step to the daemon

This method checks if the step is valid according to the list of steps the daemon already has

Parameters:
dStep - DaemonActivationStep object to add

removeAllActivationSteps

public void removeAllActivationSteps()
Remove all the activation steps of the daemon

removeActivationStep

public void removeActivationStep(int index)
Remove a specific activation step of the daemon, given the index

If the index is out of range, it does not throw any exception

Parameters:
index - index of the step to remove

removeActivationStep

public void removeActivationStep(float time)
Prevent a daemon to activate in the exact given time

This method removes a specific activation step of the daemon, given the exact activation time

Parameters:
time - activation time of the step to remove

removeActivationStep

public void removeActivationStep(org.concord.collisions.engine.DaemonActivationStep dStep)
Remove a specific activation step of the daemon
Parameters:
dStep - DaemonActivationStep object to remove

step

public void step(float worldTime)
This method is called by JPartWorld every step
Parameters:
worldTime - current world time

checkingCollisionsSensitive

protected void checkingCollisionsSensitive()

resetCollisionsSensitive

protected void resetCollisionsSensitive()

manageCollision

public boolean manageCollision(JWorldElement element)
This method is called by JPartWorld when the daemon collides with an element
Parameters:
element - element the daemon collided with

manageNoCollision

public boolean manageNoCollision(JWorldElement element)
This method is called by JPartWorld every step while the daemon is colliding with an element
Parameters:
element - element the daemon stopped colliding with

getCollisionHistory

public java.util.Vector getCollisionHistory()
Get the collision history of the daemon

hasCollided

public boolean hasCollided()
Determine if the daemon has collided with any element at any time

hasCollidedWith

public boolean hasCollidedWith(JWorldElement element)
Determine if the daemon has collided with a given element at any time

hasCollidedWithAt

public boolean hasCollidedWithAt(JWorldElement element,
                                 int indexActStep)
Determine if the daemon has collided with a given element at a given activation step

isActiveCollision

public boolean isActiveCollision(JWorldElement element)
Determine if the daemon is still colliding with a given element

getActiveCollision

public org.concord.collisions.engine.ElementCollisionInfo getActiveCollision(JWorldElement element)
Retrieve the info of the active collision with an element

addDaemonListener

public void addDaemonListener(DaemonListener l)
Add a daemon listener
Parameters:
l - daemon listener to add

closeEverything

public void closeEverything()
Overrides:
closeEverything in class JWorldElement

removeDaemonListener

public void removeDaemonListener(DaemonListener l)
Remove a daemon listener
Parameters:
l - daemon listener to remove

getActiveColor

public java.awt.Color getActiveColor()
Returns:
the color the daemon has when it is active

setActiveColor

public void setActiveColor(java.awt.Color col)
set color to show when the daemon is active
Parameters:
color - to be set

setInactiveColor

public void setInactiveColor(java.awt.Color col)
set color to show when the daemon is inactive
Parameters:
color - to be set

getEffectiveCollisionsRadius

public float getEffectiveCollisionsRadius()
Returns:
minimal distance to center of mass of daemon when collisions may occur
See Also:
CCMassive.getCMPointX(), CCMassive.getCMPointY()

setEffectiveCollisionsRadius

public void setEffectiveCollisionsRadius(float f)
Sets the minimal distance to center of mass of daemon when collisions may occur
See Also:
CCMassive.getCMPointX(), CCMassive.getCMPointY()

getInactiveColor

public java.awt.Color getInactiveColor()
Returns:
the color the daemon has when it is inactive

getColor

public java.awt.Color getColor()
Overrides:
getColor in class JWorldElement
Returns:
the current color of the daemon (depending if it is active or inactive)

paintSelection

public void paintSelection(java.awt.Graphics g)
Overrides:
paintSelection in class JWorldElement

paint

public void paint(java.awt.Graphics g)

paintIcon

public void paintIcon(java.awt.Graphics g)

startDrag

public void startDrag(int x,
                      int y)

doDrag

public void doDrag(CCCoordinateTuner tuner,
                   int x,
                   int y)

endDrag

public void endDrag(CCCoordinateTuner tuner,
                    int x,
                    int y)

getDraggableOwner

public java.lang.Object getDraggableOwner()

panelInfoSupport

public boolean panelInfoSupport()

setInfoDrawer

public void setInfoDrawer(CCInfoDrawer infoDrawer)

applyForce

public void applyForce(CCForce force)
JDaemon doesn't support applying forces
Overrides:
applyForce in class JWorldElement
Throws:
CCUnsuppOperationException -  

getActivationStepTime

public float getActivationStepTime()
Retrieve the time (in SECONDS) when the daemon will activate next. If it is a non-timed daemon, it returns 0

Of all the activation steps, this method returns the inmediate next time the daemon will activate.


getActivationStepTime

public float getActivationStepTime(int i)
Retrieve the time (in SECONDS) when the daemon will activate in a given activation time. If it is a non-timed daemon, it returns 0


setActivationStepTime

public void setActivationStepTime(float time)
Set a time (in SECONDS) in which the daemon will activate. This will be the first activation of the daemon. The daemon will activate for the minimum duration time.

This method adds (if there were no activation steps) or replaces an activation step at the beginning of all the activation steps that the daemon already has.

Usually this method is used if working with a daemon that activates only one time. Calling this method with time 0 may turn the daemon into a non-timed daemon, if it had only one activation step before

Parameters:
time - activation time

isTimed

public boolean isTimed()
Returns if the daemon will activate with activation times (timed) or not.

Timed daemons will activate according to their activation steps. Non-timed daemons will activate from the beginning (if they are automatic) and will remain always active


setFilter

public void setFilter(JWorldElementFilter f)
Sets the filter of elements that will be affected after a collision.
See Also:
JWorldElementFilter

clearFilter

public void clearFilter()
Clears the filter of elements that will be affected after a collision.

setColorFilter

public void setColorFilter(boolean b)
Turns off and on the color filter of the daemon. If the color filter is on, only the elements that have the exact same color of the active daemon will be affected by the daemon.
See Also:
setFilter(org.concord.collisions.engine.JWorldElementFilter)

setIcon

public void setIcon(java.lang.String url)
Sets icon to show.

By default the icon is as big as the daemon.

Parameters:
url - url of the icon file

getCMPointX

public float getCMPointX()
calculates X coordinate of center of mass
Returns:
x coordinate of booster's center of mass

getCMPointY

public float getCMPointY()
calculates Y coordinate of center of mass
Returns:
y coordinate of booster's center of mass

setCMPointX

public void setCMPointX(float x)
                 throws CCUnimplOperationException
Description copied from interface: CCMassive
set X coordinate of center of mass
Following copied from interface: org.concord.collisions.engine.CCMassive
Parameters:
x - desired X coordinate of center of mass

setCMPointY

public void setCMPointY(float y)
                 throws CCUnimplOperationException
Description copied from interface: CCMassive
set Y coordinate of center of mass
Following copied from interface: org.concord.collisions.engine.CCMassive
Parameters:
y - desired Y coordinate of center of mass

isPointInside

public boolean isPointInside(float px,
                             float py)
Returns if a specific world coordinates point is inside the element or not
Overrides:
isPointInside in class JWorldElement
Parameters:
px - world x coordinate of the point
py - world y coordinate of the point
See Also:
JWorldElement.isPointInside(java.awt.Point)

isElemInDaemon

protected boolean isElemInDaemon(JWorldElement el)

isPointInsideCenter

public boolean isPointInsideCenter(float px,
                                   float py)
Returns if a specific world coordinates point is inside the CENTER (only the core) of the element or not
Parameters:
px - world x coordinate of the point
py - world y coordinate of the point
See Also:
isPointInside(float, float)

getNuclearElement

public JWorldElement getNuclearElement()

getConditionExpression

public java.lang.String getConditionExpression()
Returns expression used for evaluation condition of successful collision with daemon
Returns:
expression used for evaluation condition

setConditionExpression

public void setConditionExpression(java.lang.String expression)
Set the expression used for evaluation condition of successful collision with daemon
Parameters:
expression - evaluation expression exprerssion could contain:
vx - element's vx velocity
vy - element's vy velocity
v - element's absolute value of the velocity
ax - element's ax acceleration
ay - element's ay acceleration
a - element's absolute value of the acceleration
Gx - x projection of the gravitation
Gy - y projection of the gravitation
G - absolute value of the gravitation
m - element's mass
r - atom's mass
c - element's color (integer)

clearConditionExpression

public void clearConditionExpression()
clear evaluation condition

evaluateExpression

protected boolean evaluateExpression(JWorldElement element)