|
CSP for Java (JCSP) 1.1-rc4 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jcsp.plugNplay.FramedButtonArray
public final class FramedButtonArray
A free-standing array of button processes in their own frame, with configure and event channels.
FramedButton
.
Imagine here an array of these, each with individual configure and
event channels.
ActiveButton
s wrapped in
an ActiveClosingFrame
,
but save us the trouble of constructing them.
They may be displayed in a row or column.
Wire them to application processes with configure channels (for setting labels, enabling/disabling and all other configuration options) and event channels (on which the current label on any button is sent when that button is clicked). Note that all the events may be streamed to the same channel, provided an Any2*Channel is used (as in the example below).
Initially, all button labels are empty java.lang.Strings. To set a button label, send a java.lang.String down the appropriate configure channel.
Initially, all buttons are enabled. To disable a button, send java.lang.Boolean.FALSE down the appropriate configure channel. To enable, send java.lang.Boolean.TRUE.
For other configuration options, send objects implementing
the 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 = Channel.one2one (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).
All event channels from the buttons are mulitplexed through
an Any2OneChannel
to the application process.
The application configures the buttons with their labels, then reports
each time any of them is pressed.
The application ends when the button labelled `Goodbye World' is pressed.
import org.jcsp.lang.*; import org.jcsp.util.*; import org.jcsp.plugNplay.*; public class FramedButtonArrayExample { public static void main (String argv[]) { // labels for the array of buttons final String[] label = {"JCSP", "Rocket Science", "occam-pi", "Goodbye World"}; final int nButtons = label.length; // row or column? final boolean horizontal = true; // initial pixel sizes for the frame for the button array final int pixDown = 20 + (horizontal ? 120 : nButtons*120); final int pixAcross = horizontal ? nButtons*120 : 120; // all button events are wired (for this example) to the same channel ... final Any2OneChannel allEvents = Channel.any2one (new OverWriteOldestBuffer (10)); final Any2OneChannel[] event = new Any2OneChannel[nButtons]; for (int i = 0; i < nButtons; i++) { event[i] = allEvents; } // each button is given its own configuration channel ... final One2OneChannel[] configure = Channel.one2oneArray (nButtons); // make the array of buttons ... final FramedButtonArray buttons = new FramedButtonArray ( "FramedButtonArray Demo", nButtons, pixDown, pixAcross, horizontal, Channel.getInputArray (configure), Channel.getOutputArray (event) ); // testrig ... new Parallel ( new CSProcess[] { buttons, new CSProcess () { public void run () { for (int i = 0; i < nButtons; i++) { configure[i].out ().write (label[i]); } boolean running = true; while (running) { final String s = (String) allEvents.in ().read (); System.out.println ("Button `" + s + "' pressed ..."); running = (s != label[nButtons - 1]); } System.exit (0); } } } ).run (); } }
ActiveButton
,
FramedButton
,
FramedButtonGrid
,
FramedScrollbar
Constructor Summary | |
---|---|
FramedButtonArray(String title,
int nButtons,
int pixDown,
int pixAcross,
boolean horizontal,
ChannelInput[] configure,
ChannelOutput[] event)
Construct a framed button array process. |
Method Summary | |
---|---|
void |
run()
This defines the actions of the process. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FramedButtonArray(String title, int nButtons, int pixDown, int pixAcross, boolean horizontal, ChannelInput[] configure, ChannelOutput[] event)
title
- the title for the frame (must not be null)nButtons
- the number of buttons (must be at least 1)pixDown
- the pixel hieght of the frame (must be at least 100)pixAcross
- the pixel width of the frame (must be at least 100)horizontal
- true for a horizontal array of buttons, false for a vertical oneconfigure
- the configure channels for the buttons (must not be null)event
- the event channels from the buttons (must not be null)Method Detail |
---|
public void run()
CSProcess
run
in interface CSProcess
|
CSP for Java (JCSP) 1.1-rc4 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |