All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----jcsp.awt.event.TextEventHandler
__________________ | | event | TextEventHandler |--->--- |__________________|
The TextEventHandler class implements the TextListener interface and can be used for any component which allows the addition of TextListeners. When the component is created a new instance of the TextEventHandler should be created and added as an TextListener 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 textValueChanged() method. The process then wakes up and sends the String representing the Text down the event Channel. Any further calls to textValueChanged() 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 | String | The String representing the TextEvent from the component that generated the event. |
import java.awt.*; import jcsp.lang.*; import jcsp.awt.event.*; public class ChannelTextField extends TextField implements CSProcess { private TextEventHanlder handler; public ChannelTextField(ChannelOutput event, String label) { super(s); if (event !=null) { handler = new TextEventHandler(event); addTextListener(handler); } } public void run() { if (handler != null) { handler.run(); } } }NOTE: This is in fact how the ActiveTextField and ActiveTextArea classes are implemented. Except they include an extra CSProcess and Channel for configuring the Component.
import java.awt.*; import jcsp.awt.event.*; import jcsp.lang.*; : : { final Channel event = new One2OneChannel(); TextField text = new TextField("Active"); add(text); TextEventHandler handler = new TextEventHandler(event); text.addTextListener(handler); new Parallel(new CSProcess[] { text, handler, new CSProcess() { public void run() { while (true) { Object o = event.read(); System.out println("TextField '" + o + "' Changed"); } } } }).run(); } }
public TextEventHandler(ChannelOutput event)
public void textValueChanged(TextEvent e)
public void run()
All Packages Class Hierarchy This Package Previous Next Index