org.miv.pherd.ntree
Class NTreeListenerProxy

java.lang.Object
  extended by org.miv.pherd.ntree.NTreeListenerProxy
All Implemented Interfaces:
org.miv.mbox.MBoxListener, NTreeListener

public class NTreeListenerProxy
extends Object
implements NTreeListener, org.miv.mbox.MBoxListener

Helper class that allows to listen at a n-tree 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<NTreeListener> listeners
          The listeners in another thread than this one.
 
Constructor Summary
NTreeListenerProxy(NTree tree, boolean replay)
          New listener proxy.
 
Method Summary
 void addNTreeListener(NTreeListener listener)
          Add a listener to the events of the input particle box.
 void cellAdded(Object id, Object parentId, Anchor lo, Anchor hi, int depth, int index)
          A new cell appeared.
 void cellData(Object id, String message, Object data)
          The cell data changed.
 void cellRemoved(Object id)
          A cell disappeared.
 void checkEvents()
          This method must be called regularly to check if the particle box sent events.
 void connect(NTree tree, boolean replay)
           
 void disconnect(NTree tree)
           
 void processMessage(String from, Object[] data)
           
 void removeNTReeListener(NTreeListener listener)
          Remove a listener.
protected  void replayTree(Cell cell)
          Recursively replay the n-tree.
protected  void replayTree(NTree tree)
          Send events for all the cells already in the tree as if these events where generated normally.
 
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<NTreeListener> listeners
The listeners in another thread than this one.

Constructor Detail

NTreeListenerProxy

public NTreeListenerProxy(NTree tree,
                          boolean replay)
New listener proxy. All events coming from the n-tree will be buffered and be available in another thread as soon as checkEvents() is called.

Parameters:
tree - The n-tree to listen at.
replay - Send events for all the n-tree cells already in the tree ?.
Method Detail

disconnect

public void disconnect(NTree tree)

connect

public void connect(NTree tree,
                    boolean replay)

replayTree

protected void replayTree(NTree tree)
Send events for all the cells already in the tree as if these events where generated normally.

Parameters:
tree - The n-tree.

replayTree

protected void replayTree(Cell cell)
Recursively replay the n-tree.

Parameters:
cell - The starting cell.

addNTreeListener

public void addNTreeListener(NTreeListener 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.

removeNTReeListener

public void removeNTReeListener(NTreeListener 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

cellAdded

public void cellAdded(Object id,
                      Object parentId,
                      Anchor lo,
                      Anchor hi,
                      int depth,
                      int index)
Description copied from interface: NTreeListener
A new cell appeared.

Specified by:
cellAdded in interface NTreeListener
Parameters:
id - The cell identifier.
parentId - The parent cell identifier.
lo - The cell space lowest point.
hi - The cell space highest point.
index - The cell index in its parent cell.

cellData

public void cellData(Object id,
                     String message,
                     Object data)
Description copied from interface: NTreeListener
The cell data changed. This method is here to allow cell data to send arbitrary messages to the listeners.

Specified by:
cellData in interface NTreeListener
Parameters:
id - The cell identifier.
message - The message.
data - The message data.

cellRemoved

public void cellRemoved(Object id)
Description copied from interface: NTreeListener
A cell disappeared.

Specified by:
cellRemoved in interface NTreeListener
Parameters:
id - The cell identifier.


Copyright © 2011. All Rights Reserved.