All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----jcsp.awt.event.ComponentEventHandler
_______________________ | | event | ComponentEventHandler |--->--- |_______________________|
The ComponentEventHandler class implements the ComponentListener interface and can be used for any Component which allows the addition of a ComponentListener. When the Component is created a new instance of the ComponentEventHandler should be created and added as a ComponentListener 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 componentResized(), componentMoved(), componentShown() or componentHidden() methods. The process then wakes up and sends the ComponentEvent 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 | ComponentEvent | The ComponentEvent generated by the Component. |
import java.awt.*;
import jcsp.lang.*;
import jcsp.awt.event.*;
public class ChannelComponent extends Component implements CSProcess {
ComponentEventHanlder handler;
public ChannelComponent() {
}
public void addComponentEventChannel(ChannelOutput event) {
if (event !=null) {
handler = new ComponentEventHanlder(event);
addComponentListener(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);
ComponentEventHanlder handler = new ComponentEventHanlder(event);
c.addComponentListener(handler);
new Parallel(new CSProcess[] {
c,
handler,
new CSProcess() {
public void run() {
while (true) {
Object o = event.read();
System.out.println("ComponentEvent '" + o);
}
}
}
}).run();
}
}
public ComponentEventHandler(ChannelOutput event)
public void componentResized(ComponentEvent e)
public void componentMoved(ComponentEvent e)
public void componentShown(ComponentEvent e)
public void componentHidden(ComponentEvent e)
public void run()
All Packages Class Hierarchy This Package Previous Next Index