All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----jcsp.awt.event.FocusEventHandler
___________________ | | event | FocusEventHandler |--->--- |___________________|
The FocusEventHandler class implements the FocusListener interface and can be used for any Component which allows the addition of a FocusListener. When the Component is created a new instance of the FocusEventHandler should be created and added as a FocusListener to the Component. 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 focusGained() or focusLost() methods. The process then wakes up and sends the FocusEvent 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 | FocusEvent | The FocusEvent generated by the Component. |
import java.awt.*; import jcsp.lang.*; import jcsp.awt.event.*; public class ChannelComponent extends Component implements CSProcess { FocusEventHanlder handler; public ChannelComponent() { } public void addFocusEventChannel(ChannelOutput event) { if (event !=null) { handler = new FocusEventHanlder(event); addFocusListener(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(); Component c = new Button("Active"); add(c); FocusEventHanlder handler = new FocusEventHanlder(event); c.addFocusListener(handler); new Parallel(new CSProcess[] { c, handler, new CSProcess() { public void run() { while (true) { Object o = event.read(); System.out.println("FocusEvent '" + o); } } } }).run(); } }
public FocusEventHandler(ChannelOutput event)
public void focusGained(FocusEvent e)
public void focusLost(FocusEvent e)
public void run()
All Packages Class Hierarchy This Package Previous Next Index