All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----jcsp.awt.event.MouseMotionEventHandler
_________________________ | | event | MouseMotionEventHandler |--->--- |_________________________|
The MouseMotionEventHandler class implements the MouseMotionListener interface and can be used for any Component which allows the addition of a MouseMotionListener. When the Component is created a new instance of the MouseMotionEventHandler should be created and added as a MouseMotionListener 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 mouseDragged() or mouseMoved() methods. The process then wakes up and sends the MouseEvent 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 | MouseMotionEvent | The MouseMotionEvent 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 addMouseMotionEventChannel(ChannelOutput event) { if (event !=null) { handler = new MouseMotionEventHanlder(event); addMouseMotionListener(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); MouseMotionEventHanlder handler = new MouseMotionEventHanlder(event); c.addMouseMotionListener(handler); new Parallel(new CSProcess[] { c, handler, new CSProcess() { public void run() { while (true) { Object o = event.read(); System.out.println("MouseEvent '" + o); } } } }).run(); } }
public MouseMotionEventHandler(ChannelOutput event)
public void mouseDragged(MouseEvent e)
public void mouseMoved(MouseEvent e)
public synchronized void run()
All Packages Class Hierarchy This Package Previous Next Index