All Packages Class Hierarchy This Package Previous Next Index
Class jcsp.awt.event.WindowEventHandler
java.lang.Object
|
+----jcsp.awt.event.WindowEventHandler
- public class WindowEventHandler
- extends Object
- implements CSProcess, WindowListener
Process Diagram
____________________
| | event
| WindowEventHandler |--->---
|____________________|
Description
The WindowEventHandler class is not intended to be used by software
constructors, instead it is used in the construction of new Active AWT
Components that generate WindowEvents (i.e. ActiveWindow, ActiveFrame).
The WindowEventHandler class implements the WindowListener interface and
can be used for any Component which allows the addition of a WindowListener.
When the Component is created a new instance of the WindowEventHandler
should be created and added as a WindowListener 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 windowOpened(), windowClosing(), windowClosed(), windowIconified(),
windowDeiconified(), windowActivated() or windowDeactivated()
methods. The process then wakes up and sends the WindowEvent 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.
Channel Protocols
Input Channels |
|
|
|
Output Channels |
event |
WindowEvent |
The WindowEvent generated by the Component. |
Example
Extending an Existing Component
import java.awt.*;
import jcsp.lang.*;
import jcsp.awt.event.*;
public class ChannelFrame extends Frame implements CSProcess {
WindowEventHanlder handler;
public ChannelComponent() {
}
public void addWindowEventChannel(ChannelOutput event) {
if (event !=null) {
handler = new WindowEventHanlder(event);
addWindowListener(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.
Listening to a Component
import java.awt.*;
import jcsp.awt.event.*;
import jcsp.lang.*;
:
:
{
final Channel event = new One2OneChannel();
Window c = new Frame("Active");
add(c);
WindowEventHanlder handler = new WindowEventHanlder(event);
c.addWindowListener(handler);
new Parallel(new CSProcess[] {
c,
handler,
new CSProcess() {
public void run() {
while (true) {
Object o = event.read();
System.out.println("WindowEvent '" + o);
}
}
}
}).run();
}
}
- Author:
- P.D.Austin
-
WindowEventHandler(ChannelOutput)
- constructs a new WindowEventHandler with the specified output Channel.
-
run()
- The main body of the process.
-
windowActivated(WindowEvent)
- Invoked when the Component the event handler is listening to has the window
activated.
-
windowClosed(WindowEvent)
- Invoked when the Component the event handler is listening to has the window
closed.
-
windowClosing(WindowEvent)
- Invoked when the Component the event handler is listening to has the window
start to close.
-
windowDeactivated(WindowEvent)
- Invoked when the Component the event handler is listening to has the window
deactivated.
-
windowDeiconified(WindowEvent)
- Invoked when the Component the event handler is listening to has the window
deiconified.
-
windowIconified(WindowEvent)
- Invoked when the Component the event handler is listening to has the window
iconified.
-
windowOpened(WindowEvent)
- Invoked when the Component the event handler is listening to has the window
opened.
WindowEventHandler
public WindowEventHandler(ChannelOutput event)
- constructs a new WindowEventHandler with the specified output Channel.
- Parameters:
- event - The Channel to send the event notification down
windowOpened
public void windowOpened(WindowEvent e)
- Invoked when the Component the event handler is listening to has the window
opened. Notifies the event process that a WindowEvent has
occurred by sending the WindowEvent Object. Some notifications will be
lost so there are no guarantees that all events generated will be
processed.
- Parameters:
- e - The parameters associated with this event
windowClosing
public void windowClosing(WindowEvent e)
- Invoked when the Component the event handler is listening to has the window
start to close. Notifies the event process that a WindowEvent has
occurred by sending the WindowEvent Object. Some notifications will be
lost so there are no guarantees that all events generated will be
processed.
- Parameters:
- e - The parameters associated with this event
windowClosed
public void windowClosed(WindowEvent e)
- Invoked when the Component the event handler is listening to has the window
closed. Notifies the event process that a WindowEvent has
occurred by sending the WindowEvent Object. Some notifications will be
lost so there are no guarantees that all events generated will be
processed.
- Parameters:
- e - The parameters associated with this event
windowIconified
public void windowIconified(WindowEvent e)
- Invoked when the Component the event handler is listening to has the window
iconified. Notifies the event process that a WindowEvent has
occurred by sending the WindowEvent Object. Some notifications will be
lost so there are no guarantees that all events generated will be
processed.
- Parameters:
- e - The parameters associated with this event
windowDeiconified
public void windowDeiconified(WindowEvent e)
- Invoked when the Component the event handler is listening to has the window
deiconified. Notifies the event process that a WindowEvent has
occurred by sending the WindowEvent Object. Some notifications will be
lost so there are no guarantees that all events generated will be
processed.
- Parameters:
- e - The parameters associated with this event
windowActivated
public void windowActivated(WindowEvent e)
- Invoked when the Component the event handler is listening to has the window
activated. Notifies the event process that a WindowEvent has
occurred by sending the WindowEvent Object. Some notifications will be
lost so there are no guarantees that all events generated will be
processed.
- Parameters:
- e - The parameters associated with this event
windowDeactivated
public void windowDeactivated(WindowEvent e)
- Invoked when the Component the event handler is listening to has the window
deactivated. Notifies the event process that a WindowEvent has
occurred by sending the WindowEvent Object. Some notifications will be
lost so there are no guarantees that all events generated will be
processed.
- Parameters:
- e - The parameters associated with this event
run
public void run()
- The main body of the process. Executes the functionality described above.
All Packages Class Hierarchy This Package Previous Next Index