org.miv.pherd
Class ParticleBoxListenerProxy

java.lang.Object
  extended by org.miv.pherd.ParticleBoxListenerProxy
All Implemented Interfaces:
org.miv.mbox.MBoxListener, ParticleBoxListener

public class ParticleBoxListenerProxy
extends Object
implements ParticleBoxListener, org.miv.mbox.MBoxListener

Helper class that allows to listen at a particle box across thread boundaries.

Author:
Antoine Dutot

Field Summary
protected  org.miv.mbox.MBoxStandalone events
          The message box used to exchange messages between the two threads.
protected  ArrayList<ParticleBoxListener> listeners
          The listeners in another thread than this one.
 
Constructor Summary
ParticleBoxListenerProxy(ParticleBox box, boolean replay)
          New listener proxy.
 
Method Summary
 void addParticleBoxListener(ParticleBoxListener listener)
          Add a listener to the events of the input particle box.
 void checkEvents()
          This method must be called regularly to check if the particle box sent events.
 void connect(ParticleBox box, boolean replay)
           
 void disconnect(ParticleBox box)
           
 void particleAdded(Object id, double x, double y, double z)
          A new particle appeared at (x,y,z).
 void particleAttributeChanged(Object id, String attribute, Object newValue, boolean removed)
          One of the particle attributes changed value.
 void particleMoved(Object id, double x, double y, double z)
          A particle moved.
 void particleRemoved(Object id)
          A particle disappeared.
 void processMessage(String from, Object[] data)
           
 void removeParticleBoxListener(ParticleBoxListener listener)
          Remove a listener.
protected  void replayBox(ParticleBox box)
          Send events for all the particles already in the particle box as if these events where generated normally.
 void stepFinished(int time)
          All particles moved and a new step is about to begin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

events

protected org.miv.mbox.MBoxStandalone events
The message box used to exchange messages between the two threads.


listeners

protected ArrayList<ParticleBoxListener> listeners
The listeners in another thread than this one.

Constructor Detail

ParticleBoxListenerProxy

public ParticleBoxListenerProxy(ParticleBox box,
                                boolean replay)
New listener proxy. All events coming from the particle box will be buffered and be available in another thread as soon as checkEvents() is called.

Parameters:
box - The particle box to listen at.
replay - Send events for all the particles already in the particle box ?.
Method Detail

disconnect

public void disconnect(ParticleBox box)

connect

public void connect(ParticleBox box,
                    boolean replay)

replayBox

protected void replayBox(ParticleBox box)
Send events for all the particles already in the particle box as if these events where generated normally.

Parameters:
box - The particle box.

addParticleBoxListener

public void addParticleBoxListener(ParticleBoxListener listener)
Add a listener to the events of the input particle box.

Parameters:
listener - The listener to call for each event in the input graph.

removeParticleBoxListener

public void removeParticleBoxListener(ParticleBoxListener listener)
Remove a listener.

Parameters:
listener - The listener to remove.

checkEvents

public void checkEvents()
This method must be called regularly to check if the particle box sent events. If some event occurred, the listeners will be called.


processMessage

public void processMessage(String from,
                           Object[] data)
Specified by:
processMessage in interface org.miv.mbox.MBoxListener

particleAdded

public void particleAdded(Object id,
                          double x,
                          double y,
                          double z)
Description copied from interface: ParticleBoxListener
A new particle appeared at (x,y,z).

Specified by:
particleAdded in interface ParticleBoxListener
Parameters:
id - The particle unique identifier.
x - The particle abscissa.
y - The particle ordinate.
z - The particle depth.

particleAttributeChanged

public void particleAttributeChanged(Object id,
                                     String attribute,
                                     Object newValue,
                                     boolean removed)
Description copied from interface: ParticleBoxListener
One of the particle attributes changed value.

Specified by:
particleAttributeChanged in interface ParticleBoxListener
Parameters:
id - The particle identifier.
attribute - The attribute name.
newValue - The attribute new value (null if removed).
removed - If true the attribute is being removed.

particleMoved

public void particleMoved(Object id,
                          double x,
                          double y,
                          double z)
Description copied from interface: ParticleBoxListener
A particle moved.

Specified by:
particleMoved in interface ParticleBoxListener
Parameters:
id - The particle unique identifier.
x - The new abscissa.
y - The new ordinate.
z - The new depth.

particleRemoved

public void particleRemoved(Object id)
Description copied from interface: ParticleBoxListener
A particle disappeared.

Specified by:
particleRemoved in interface ParticleBoxListener
Parameters:
id - The particle unique identifier.

stepFinished

public void stepFinished(int time)
Description copied from interface: ParticleBoxListener
All particles moved and a new step is about to begin.

Specified by:
stepFinished in interface ParticleBoxListener
Parameters:
time - The finished step time.


Copyright © 2011. All Rights Reserved.