public final class FramedButton extends java.lang.Object implements CSProcess
__________________ | | | | | | | |configure
| |event
----->-----| FramedButton |----->----- (java.lang.String) | | (java.lang.String) (java.lang.Boolean) | | (ActiveButton.Configure
) | | | | |__________________|
ActiveButton
wrapped in an 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 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).
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 org.jcsp.lang.*; import org.jcsp.util.*; import org.jcsp.plugNplay.*; public class FramedButtonExample { 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 = Channel.one2one (new OverWriteOldestBuffer (10)); // the configure channel is wired up to the button ... final One2OneChannel configure = Channel.one2one (); // make the framed button (connecting up its wires) ... final FramedButton button = new FramedButton ( "FramedButton Demo", pixDown, pixAcross, configure.in (), event.out () ); // testrig ... new Parallel ( new CSProcess[] { button, new CSProcess () { public void run () { int i = 0; while (true) { configure.out ().write (label[i]); i = (i + 1) % label.length; final String s = (String) event.in ().read (); System.out.println ("Button `" + s + "' pressed ..."); } } } } ).run (); } }
ActiveButton
,
FramedButtonArray
,
FramedButtonGrid
,
FramedScrollbar
Constructor and Description |
---|
FramedButton(java.lang.String title,
int pixDown,
int pixAcross,
ChannelInput configure,
ChannelOutput event)
Construct a framed button process.
|
Modifier and Type | Method and Description |
---|---|
void |
run()
The main body of this process.
|
public FramedButton(java.lang.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)Submit a bug or feature to jcsp-team@kent.ac.uk
Version 1.1-rc4 of the JCSP API Specification (Copyright 1997-2008 P.D.Austin and P.H.Welch - All Rights Reserved)
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.