All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----jcsp.awt.event.AdjustmentEventHandler
________________________ | | event | AdjustmentEventHandler |--->--- |________________________|
The AdjustmentEventHandler class implements the AdjustmentListener interface and can be used for any component which allows the addition of AdjustmentListeners. When the component is created a new instance of the AdjustmentEventHandler should be created and added as an AdjustmentListeners 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 adjustmentValueChanged() method. The process then wakes up and sends a new Integer set to the current value of the component down the event Channel. Any further calls to adjustmentValueChanged() 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 | Integer | The Integer representing the current value of the Adjustable component that generated the event. |
import java.awt.*; import jcsp.lang.*; import jcsp.awt.event.*; public class ChannelScrollbar extends Scrollbar implements CSProcess { private AdjustmentEventHandler handler; public ChannelScrollbar(ChannelOutput event) { super(); if (event !=null) { handler = new AdjustmentEventHandler(event); addAdjustmentListener(handler); } } public void run() { if (handler != null) { handler.run(); } } }NOTE: This is in fact how the ActiveScrollbar class is implemented. Except it includes an extra CSProcess and Channel for configuring the Component.
import java.awt.*; import jcsp.awt.event.*; import jcsp.lang.*; : : { final Channel event = new One2OneChannel(); Scrollbar scrollbar = new Scrollbar(); add(scrollbar); AdjustmentEventHandler handler = new AdjustmentEventHandler(event); scrollbar.addAdjustmentListener(handler); new Parallel(new CSProcess[] { scrollbar, handler, new CSProcess() { public void run() { while (true) { Object o = event.read(); System.out.println("Scrollbar value='" + o); } } } }).run(); } }
public AdjustmentEventHandler(Channel event)
public void adjustmentValueChanged(AdjustmentEvent e)
public void run()
All Packages Class Hierarchy This Package Previous Next Index