All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----jcsp.awt.event.ContainerEventHandler
_______________________ | | event | ContainerEventHandler |--->--- |_______________________|
The ContainerEventHandler class implements the ContainerListener interface and can be used for and component which allows the addition of a ContainerListener. When the Container is created a new instance of the ContainerEventHandler should be created and added as a ContainerListener to the Container. The process must be set running (either asynchronously using ProcessNetwork or as part of a Parallel construct).
The main body of this process waits to be notified by a component invoking the componentAdded() or componentRemoved() methods. The process then wakes up and sends the ContainerEvent object down the event Channel. Any further calls to the methods while the process is writing will be discarded so as not to block the main Java event Thread. When another process reads from the Channel this process loops round and waits to be notified again.
Input Channels | ||
---|---|---|
Output Channels | ||
event | ContainerEvent | The ContainerEvent generated by the Component. |
import java.awt.*; import jcsp.lang.*; import jcsp.awt.event.*; public class ChannelContainer extends Container implements CSProcess { ContainerEventHandler handler; public ChannelContainer() { } public void addContainerEventChannel(ChannelOutput event) { if (event !=null) { handler = new ContainerEventHandler(event); addContainerListener(handler); } } public void run() { if (handler != null) { handler.run(); } } }NOTE: This is in fact how the jcsp awt components add Channels for other event types.
import java.awt.*; import jcsp.awt.event.*; import jcsp.lang.*; : : { final Channel event = new One2OneChannel(); Container c = new Panel(); add(c); ContainerEventHandler handler = new ContainerEventHandler(event); c.addContainerListener(handler); new Parallel(new CSProcess[] { c, handler, new CSProcess() { public void run() { while (true) { Object o = event.read(); System.out.println("ContainerEvent '" + o); } } } }).run(); } }
public ContainerEventHandler(ChannelOutput event)
public void componentAdded(ContainerEvent e)
public void componentRemoved(ContainerEvent e)
public void run()
All Packages Class Hierarchy This Package Previous Next Index