Package org.jcsp.plugNplay

# Class FramedButton

java.lang.Object
org.jcsp.plugNplay.FramedButton

All Implemented Interfaces:
  `CSProcess`

public final class FramedButton extends Object implements CSProcess
A free-standing button process in its own frame, with configure and event channels.

## Process Diagram

                                __________________
                               |                  |
                               |                  |
                               |                  |
                               |                  |
                     configure |                  |  event
                    ----->-----|   FramedButton   |----->-----
            (java.lang.String) |                  | (java.lang.String)
           (java.lang.Boolean) |                  |
      (ActiveButton.Configure) |                  |
                               |                  |
                               |__________________|

## Description

This process provides a free-standing button in its own frame. It is just an `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.

## Example

This runs a framed button in parallel with a simple application process (in-lined in the ``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 invalid input: '&' 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 ();

       }

     }

Author:
  P.H. Welch
See Also:
  - `ActiveButton`
  - `FramedButtonArray`
  - `FramedButtonGrid`
  - `FramedScrollbar`

## Constructor Summary

Constructors
Constructor
Description
`FramedButton(String title, int pixDown, int pixAcross, ChannelInput configure, ChannelOutput event)`
Construct a framed button process.

## Method Summary

Modifier and Type
Method
Description
`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 Details

### FramedButton

public FramedButton(String title, int pixDown, int pixAcross, ChannelInput configure, ChannelOutput event)
Construct a framed button process.

Parameters:
  `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 Details

### run

public void run()
The main body of this process.

Specified by:
  `run` in interface `CSProcess`