|
CSP for Java (JCSP) 1.1-rc1 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jcsp.plugNplay.FramedButton
public final class FramedButton
A free-standing button process in its own frame, with configure and event channels.
__________________ | | | | | | | |configure
| |event
----->-----| FramedButton |----->----- (java.lang.String) | | (java.lang.String) (java.lang.Boolean) | | (ActiveButton.Configure
) | | | | |__________________|
jcsp.awt.ActiveButton
wrapped in an jcsp.awt.ActiveClosingFrame
,
but saves us the trouble of constructing it.
Wire it to application processes with a configure channel (for setting its label, enabling/disabling and all other configuration options) and an event channel (on which the current label is sent when the button is clicked).
Initially, the button label is an empty java.lang.String. To set the button label, send a java.lang.String down the configure channel.
Initially, the button is enabled. To disable the button, send java.lang.Boolean.FALSE down the configure channel. To enable, send java.lang.Boolean.TRUE.
For other configuration options, send objects implementing
the jcsp.awt.ActiveButton.Configure
interface.
IMPORTANT: it is essential that event channels from this process are always serviced -- otherwise the Java Event Thread will be blocked and the GUI will stop responding. A simple way to guarantee this is to use channels configured with overwriting buffers. For example:
final One2OneChannel myButtonEvent = One2OneChannel.create (new OverWriteOldestBuffer (n));This will ensure that the Java Event Thread will never be blocked. Slow or inattentive readers may miss rapidly generated events, but the n most recent events will always be available.
Parallel
below).
The application process configures the button with the first of an array
of String labels, reporting and changing it each time the button
is pressed.
import jcsp.lang.*; import jcsp.util.*; import jcsp.plugNplay.*; public class FramedButtonTest { public static void main (String argv[]) { // initial pixel sizes for the button frame final int pixDown = 100; final int pixAcross = 250; // labels for the button final String[] label = {"JCSP", "Rocket Science", "occam-pi", "Goodbye World"}; // the event channel is wired up to the button & reports all button presses ... final One2OneChannel event = One2OneChannel.create (new OverWriteOldestBuffer (10)); // the configure channel is wired up to the button ... final One2OneChannel configure = new One2OneChannel (); // make the framed button (connecting up its wires) ... final FramedButton button = new FramedButton ("FramedButton Demo", pixDown, pixAcross, configure, event); // testrig ... new Parallel ( new CSProcess[] { button, new CSProcess () { public void run () { int i = 0; while (true) { configure.write (label[i]); i = (i + 1) % label.length; final String s = (String) event.read (); System.out.println ("Button `" + s + "' pressed ..."); } } } } ).run (); } }
jcsp.awt.ActiveButton
,
jcsp.plugNplay.FramedButtonArray
,
jcsp.plugNplay.FramedButtonGrid
,
jcsp.plugNplay.FramedScrollbar
Constructor Summary | |
---|---|
FramedButton(String title,
int pixDown,
int pixAcross,
ChannelInput configure,
ChannelOutput event)
Construct a framed button process. |
Method Summary | |
---|---|
void |
run()
The main body of this process. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FramedButton(String title, int pixDown, int pixAcross, ChannelInput configure, ChannelOutput event)
title
- the title for the frame (must not be null)pixDown
- the pixel hieght of the frame (must be at least 100)pixAcross
- the pixel width of the frame (must be at least 100)configure
- the configure channel for the button (must not be null)event
- the event channel from the button (must not be null)Method Detail |
---|
public void run()
run
in interface CSProcess
|
CSP for Java (JCSP) 1.1-rc1 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |