org.concord.collisions.engine
Class JImpulseDaemon

java.lang.Object
  |
  +--org.concord.collisions.engine.JWorldElement
        |
        +--org.concord.collisions.engine.JDaemon
              |
              +--org.concord.collisions.engine.JImpulseDaemon
All Implemented Interfaces:
CCDraggable, CCMassive, java.util.EventListener, ImpulseForceListener, java.beans.PropertyChangeListener, java.io.Serializable

public class JImpulseDaemon
extends JDaemon
implements ImpulseForceListener

Force daemon element in the world

A force daemon is a special daemon that affects only atoms when they collide with it.

A force daemon applies a specific force to all atoms that collide with it. An impulse daemon applies a specific impulse to the atom, which is a force that will act on the atom for a certain period of time.

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

Fields inherited from class org.concord.collisions.engine.JDaemon
activationSteps, activeColor, collisionHistory, currentActivationStep, DEFAULT_PAINT_RADIUS, doCollisionsHistory, minDistance, 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
JImpulseDaemon()
           
 
Method Summary
 void addImpulseForceListener(ImpulseForceListener l)
          Add an impulse listener
 void applyForce(CCForce f)
          JDaemon doesn't support applying forces
 void clearForces()
          remove all applied forces
protected  void convertSingleForceToMultiForcedDaemon()
           
static JImpulseDaemon createConstantForceDaemon(float x, float y, float width, float height, float forceX, float forceY)
          Creates a new constant force daemon
static JImpulseDaemon createImpulseDaemon(float x, float y, float width, float height, float forceX, float forceY, boolean doCorrectInitDelay, float forceDuration)
           
static JImpulseDaemon createImpulseDaemon(float x, float y, float width, float height, float forceX, float forceY, float forceDuration)
          Creates a new impulse daemon
static JImpulseDaemon createMultiConstantForceDaemon(float x, float y, float width, float height, float forceX, float forceY)
          Creates a new constant force daemon with ability to apply many forces
static JImpulseDaemon createMultiImpulseDaemon(float x, float y, float width, float height, float forceX, float forceY, boolean doCorrectInitDelay, float forceDuration)
           
static JImpulseDaemon createMultiImpulseDaemon(float x, float y, float width, float height, float forceX, float forceY, float forceDuration)
          Creates a new impulse daemon with ability to apply many forces
 void doDrag(CCCoordinateTuner tuner, int x, int y)
           
 CCDraggable findDraggable(float x, float y)
           
 float getActTime()
          For impulse daemons, gets the duration of the impulse in SECONDS
 float getDefaultActTime()
           
 int getDefaultForceDrawMode()
           
 float getDefaultInitDelay()
           
protected  CCConstantForce getFirstForce()
           
 CCConstantForce getForce()
          Returns the force associated with the daemon
protected  CCDraggable getForceDraggable(float x, float y)
           
 int getForceDrawMode()
           
 boolean getMakeSound()
          For impulse daemons, returns if the daemon will make a sound when it collides with the atom or not.
 float getXTemperature()
           
 float getYTemperature()
           
 void impulseActivated(ImpulseForceEvent evt)
           
 void impulseDeactivated(ImpulseForceEvent evt)
           
 boolean isImpulseDaemon()
          Returns if the daemon is an impulse daemon or not.
 boolean isPointInside(float px, float py)
          Returns if a specific world coordinates point is inside the element 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, java.awt.Graphics sg)
           
 void removeImpulseForceListener(ImpulseForceListener l)
          Remove an impulse listener
 void resetDefaultColors()
          Reset default colors for the daemon.
 void setActTime(float actTime)
          Sets the duration of the impulse in SECONDS
 void setForceDragMode(int m)
           
 void setForceDrawMode(int m)
           
 void setGeometry(java.lang.Object object)
           
 void setMakeSound(boolean b)
          For impulse daemons, sets if the daemon will make a sound when it collides with the atom or not.
 void setProperty(java.lang.String name, java.lang.Object val)
           
 void setSoundFileName(java.lang.String filename)
          For impulse daemons, sets the sound that the daemon will make when it collides with the atom.
 void setWorldModel(JPartWorld world)
          Method called by JPartWorld
 void startDrag(int x, int y)
           
 
Methods inherited from class org.concord.collisions.engine.JDaemon
activate, addActivationStep, addActivationStep, addActivationStep, addDaemonListener, checkingCollisionsSensitive, clearConditionExpression, clearFilter, closeEverything, deactivate, endDrag, evaluateExpression, getActivationStepTime, getActivationStepTime, getActiveCollision, getActiveColor, getCMPointX, getCMPointY, getCollisionHistory, getColor, getConditionExpression, getDraggableOwner, getDragMode, getEffectiveCollisionsRadius, getHeight, getInactiveColor, getNuclearElement, getWidth, getX, getXPotentialEnergy, getY, getYPotentialEnergy, hasCollided, hasCollidedWith, hasCollidedWithAt, initElement, isActive, isActiveCollision, isAlive, isAutomaticStart, isElemInDaemon, isLooping, isPointInsideCenter, isTimed, paint, paintIcon, paintSelection, panelInfoSupport, rememberCurrPosAsInit, rememberCurrVelAsInit, removeActivationStep, removeActivationStep, removeActivationStep, removeAllActivationSteps, removeDaemonListener, reset, resetCollisionsSensitive, setActivationStepTime, setActiveColor, setAutomaticStart, setCMPointX, setCMPointY, setColorFilter, setConditionExpression, setDragMode, setEffectiveCollisionsRadius, setFilter, setGeometry, setGeometry, setIcon, setInactiveColor, setInfoDrawer, setLooping, shift, shiftV, start, 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, clearIcon, createDefaultCalculator, 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, getY, getYacceleration, getYNeighbors, isCollisionSensitive, isConstraintsWasSet, isControllable, isDraggable, isEnabled, isFlashing, isMoveable, isPointInside, isPressedState, isSelected, isVisible, notifyAreaListener, notifyElementListeners, notifyMouseListeners, notifyPropertyListeners, 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, setIcon, setIcon, setIcon, setIconSize, setIndex, setMass, setName, setOwner, setPositionChanger, setPressedState, setQTIcon, setQTIcon, setQTMovie, setShowAcceleration, setShowVelocity, setVisible, setVx, setVy, setXConstraints, setYConstraints, unselect, wasCollision
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JImpulseDaemon

public JImpulseDaemon()
Method Detail

createImpulseDaemon

public static JImpulseDaemon createImpulseDaemon(float x,
                                                 float y,
                                                 float width,
                                                 float height,
                                                 float forceX,
                                                 float forceY,
                                                 float forceDuration)
Creates a new impulse daemon
Parameters:
x - daemon's x coordinate
y - daemon's y coordinate
w - daemon's graphical width (minimum 1)
h - daemon's graphical height (minimum 1)
forceX - x coordinate of the impulse force that will be applied to the atom
forceY - y coordinate of the impulse force that will be applied to the atom
forceDuration - duration of the impulse (in milliseconds)

createImpulseDaemon

public static JImpulseDaemon createImpulseDaemon(float x,
                                                 float y,
                                                 float width,
                                                 float height,
                                                 float forceX,
                                                 float forceY,
                                                 boolean doCorrectInitDelay,
                                                 float forceDuration)

createConstantForceDaemon

public static JImpulseDaemon createConstantForceDaemon(float x,
                                                       float y,
                                                       float width,
                                                       float height,
                                                       float forceX,
                                                       float forceY)
Creates a new constant force daemon
Parameters:
x - daemon's x coordinate
y - daemon's y coordinate
w - daemon's graphical width (minimum 1)
h - daemon's graphical height (minimum 1)
forceX - x coordinate of the force that will be applied to the atom
forceY - y coordinate of the force that will be applied to the atom

createMultiImpulseDaemon

public static JImpulseDaemon createMultiImpulseDaemon(float x,
                                                      float y,
                                                      float width,
                                                      float height,
                                                      float forceX,
                                                      float forceY,
                                                      float forceDuration)
Creates a new impulse daemon with ability to apply many forces
Parameters:
x - daemon's x coordinate
y - daemon's y coordinate
w - daemon's graphical width (minimum 1)
h - daemon's graphical height (minimum 1)
forceX - x coordinate of the impulse force that will be applied to the atom
forceY - y coordinate of the impulse force that will be applied to the atom
forceDuration - duration of the impulse (in milliseconds)

createMultiImpulseDaemon

public static JImpulseDaemon createMultiImpulseDaemon(float x,
                                                      float y,
                                                      float width,
                                                      float height,
                                                      float forceX,
                                                      float forceY,
                                                      boolean doCorrectInitDelay,
                                                      float forceDuration)

createMultiConstantForceDaemon

public static JImpulseDaemon createMultiConstantForceDaemon(float x,
                                                            float y,
                                                            float width,
                                                            float height,
                                                            float forceX,
                                                            float forceY)
Creates a new constant force daemon with ability to apply many forces
Parameters:
x - daemon's x coordinate
y - daemon's y coordinate
w - daemon's graphical width (minimum 1)
h - daemon's graphical height (minimum 1)
forceX - x coordinate of the force that will be applied to the atom
forceY - y coordinate of the force that will be applied to the atom

setMakeSound

public void setMakeSound(boolean b)
For impulse daemons, sets if the daemon will make a sound when it collides with the atom or not.

By default, the impulse daemon will make a motorcycle impulse sound. Applies only for impulse daemoms.

Parameters:
b - indicates if the daemon wil make a sound or not
See Also:
setSoundFileName(java.lang.String)

getMakeSound

public boolean getMakeSound()
For impulse daemons, returns if the daemon will make a sound when it collides with the atom or not.

Applies only for impulse daemoms.

Returns:
if the daemon will make a sound or not

setSoundFileName

public void setSoundFileName(java.lang.String filename)
For impulse daemons, sets the sound that the daemon will make when it collides with the atom.

The daemon will make this sound if it has been set to make sounds.

Applies only for impulse daemoms.

Parameters:
filename - filename(inside collisions.jar) or URL of the sound file
See Also:
setMakeSound(boolean)

setGeometry

public void setGeometry(java.lang.Object object)
                 throws java.lang.Exception
Overrides:
setGeometry in class JWorldElement

paint

public void paint(java.awt.Graphics g,
                  java.awt.Graphics sg)
Overrides:
paint in class JWorldElement

getXTemperature

public float getXTemperature()
Overrides:
getXTemperature in class JWorldElement

getYTemperature

public float getYTemperature()
Overrides:
getYTemperature in class JWorldElement

manageCollision

public boolean manageCollision(JWorldElement element)
This method is called by JPartWorld when the daemon collides with an element
Overrides:
manageCollision in class JDaemon
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
Overrides:
manageNoCollision in class JDaemon
Parameters:
element - element the daemon is colliding with

resetDefaultColors

public void resetDefaultColors()
Reset default colors for the daemon.

Sets the default colors for force daemons: Purple for inactive and magenta for active.


setWorldModel

public void setWorldModel(JPartWorld world)
Method called by JPartWorld
Overrides:
setWorldModel in class JWorldElement

startDrag

public void startDrag(int x,
                      int y)
Overrides:
startDrag in class JDaemon

doDrag

public void doDrag(CCCoordinateTuner tuner,
                   int x,
                   int y)
Overrides:
doDrag in class JDaemon

getForce

public CCConstantForce getForce()
Returns the force associated with the daemon

Returns:
the force of the daemon

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 JDaemon
Parameters:
px - world x coordinate of the point
py - world y coordinate of the point
See Also:
JDaemon.isPointInside(float, float)

getActTime

public float getActTime()
For impulse daemons, gets the duration of the impulse in SECONDS

Only for impulse daemons. If the daemon is a constant force daemon, it returns zero.

Returns:
the time the impulse will be activated after it is attached to an atom.

setActTime

public void setActTime(float actTime)
Sets the duration of the impulse in SECONDS

Parameters:
actTime - time the impulse will be activated after it is attached to an atom.

impulseActivated

public void impulseActivated(ImpulseForceEvent evt)
Specified by:
impulseActivated in interface ImpulseForceListener

impulseDeactivated

public void impulseDeactivated(ImpulseForceEvent evt)
Specified by:
impulseDeactivated in interface ImpulseForceListener

addImpulseForceListener

public void addImpulseForceListener(ImpulseForceListener l)
Add an impulse listener
Parameters:
l - impulse listener to add

removeImpulseForceListener

public void removeImpulseForceListener(ImpulseForceListener l)
Remove an impulse listener
Parameters:
l - impulse listener to remove

isImpulseDaemon

public boolean isImpulseDaemon()
Returns if the daemon is an impulse daemon or not.

It returns false when the daemon is just a constant force daemon

Returns:
true - if the daemon is an impulse daemon

false - if it is a constant force daemon


getFirstForce

protected CCConstantForce getFirstForce()

clearForces

public void clearForces()
Description copied from class: JWorldElement
remove all applied forces
Overrides:
clearForces in class JWorldElement

applyForce

public void applyForce(CCForce f)
Description copied from class: JDaemon
JDaemon doesn't support applying forces
Overrides:
applyForce in class JDaemon
Following copied from class: org.concord.collisions.engine.JDaemon
Throws:
CCUnsuppOperationException -  

convertSingleForceToMultiForcedDaemon

protected void convertSingleForceToMultiForcedDaemon()

findDraggable

public CCDraggable findDraggable(float x,
                                 float y)
Overrides:
findDraggable in class JWorldElement

getForceDraggable

protected CCDraggable getForceDraggable(float x,
                                        float y)

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object val)
Overrides:
setProperty in class JWorldElement

setForceDragMode

public void setForceDragMode(int m)

setForceDrawMode

public void setForceDrawMode(int m)

getForceDrawMode

public int getForceDrawMode()

getDefaultInitDelay

public float getDefaultInitDelay()

getDefaultActTime

public float getDefaultActTime()

getDefaultForceDrawMode

public int getDefaultForceDrawMode()