CSP for Java
(JCSP) 1.1-rc4

org.jcsp.plugNplay
Class FramedScrollbar

java.lang.Object
  extended by org.jcsp.plugNplay.FramedScrollbar
All Implemented Interfaces:
CSProcess

public final class FramedScrollbar
extends Object
implements CSProcess

A free-standing scrollbar process in its own frame, with configure and event channels.

Process Diagram

                               ___________________
                              |                   |
                              |                   |
                              |                   |
                              |                   |
                    configure |                   |  event
                   ----->-----|  FramedScrollbar  |----->-----
          (java.lang.Integer) |                   | (int)
          (java.lang.Boolean) |                   |
  (ActiveScrollbar.Configure) |                   |
                              |                   |
                              |___________________|  
 

Description

This process provides a free-standing scrollbar in its own frame. It is just an ActiveScrollbar wrapped in an ActiveClosingFrame, but saves us the trouble of constructing it.

Wire it to application processes with a configure channel (for setting its position, enabling/disabling and all other configuration options) and an event channel (on which the current position is sent whenever the button in the scrollbar is moved).

Initially, the button in the scrollbar is at its minimum position. An application process may change this by sending a java.lang.Integer (with value between the minimum and maximum defined for the scrollbar) 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 ActiveScrollbar.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 myScrollbarEvent =
     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 scrollbar in parallel with two simple application processes (in-lined in the Parallel below). One application process reports all movements of the scrollbar. The other disables the scrollbar for 5 seconds at 15 second intervals.
 import org.jcsp.lang.*;
 import org.jcsp.util.ints.*;
 import org.jcsp.plugNplay.*;
 
 public class FramedScrollbarExample {
 
   public static void main (String argv[]) {
   
     // initial pixel sizes for the scrollbar frame
     
     final boolean horizontal = true;
   
     final int pixDown = horizontal ? 300 : 400;
     final int pixAcross = horizontal ? 400 : 300;
   
     // the event channel is wired up to the scrollbar & reports all slider movements ...
 
     final One2OneChannelInt event =
       Channel.one2oneInt (new OverWriteOldestBufferInt (10));
 
     // the configure channel is wired up to the scrollbar  ...
 
     final One2OneChannel configure = Channel.one2one ();
 
     // make the framed scrollbar (connecting up its wires) ...
 
     final FramedScrollbar scrollbar =
       new FramedScrollbar (
         "FramedScrollbar Demo", pixDown, pixAcross,
         configure.in (), event.out (),
         horizontal, 0, 10, 0, 100
       );
 
     // testrig ...
 
     new Parallel (
     
       new CSProcess[] {
       
         scrollbar,
         
         new CSProcess () {        
           public void run () {            
             while (true) {
               final int n = event.in ().read ();
               System.out.println ("FramedScrollbar ==> " + n);
             }            
           }          
         },
         
         new CSProcess () {        
           public void run () {
             final int second = 1000;                // time is in millisecs
             final int enabledTime = 10*second;
             final int disabledCountdown = 5;
             final CSTimer tim = new CSTimer ();
             while (true) {
               tim.sleep (enabledTime);
               configure.out ().write (Boolean.FALSE);
               for (int i = disabledCountdown; i > 0; i--) {
                 System.out.println ("\t\t\t\tScrollbar disabled ... " + i);
                 tim.sleep (second);
               }
               configure.out ().write (Boolean.TRUE);
               System.out.println ("\t\t\t\tScrollbar enabled ...");
             }            
           }          
         }
         
       }
     ).run ();
 
   }
 
 }
 

Author:
P.H. Welch
See Also:
ActiveScrollbar, FramedButton, FramedButtonArray, FramedButtonGrid

Constructor Summary
FramedScrollbar(String title, int pixDown, int pixAcross, ChannelInput configure, ChannelOutputInt event, boolean horizontal, int value, int visible, int minimum, int maximum)
          Construct a framed scrollbar 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

FramedScrollbar

public FramedScrollbar(String title,
                       int pixDown,
                       int pixAcross,
                       ChannelInput configure,
                       ChannelOutputInt event,
                       boolean horizontal,
                       int value,
                       int visible,
                       int minimum,
                       int maximum)
Construct a framed scrollbar process.

Parameters:
title - the title for the frame (must not be null)
pixDown - the pixel hieght of the frame (must be at least 10 if horizontal, otherwise at least 100)
pixAcross - the pixel width of the frame ((must be at least 10 if vertical, otherwise at least 100)
configure - the configure channel for the scrollbar (may be null)
event - the event channel from the scrollbar (must not be null)
horizontal - true for a horizontal scrollbar, false for a vertical one
value - the initial position of the button in the scrollbar (must be between minimum and maximum inclusive)
visible - the size of the button in the scrollbar (must be at least 10)
minimum - the minimum position of the button in the scrollbar
maximum - the maximum position of the button in the scrollbar
Method Detail

run

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

Specified by:
run in interface CSProcess

CSP for Java
(JCSP) 1.1-rc4

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.