|
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.FramedScrollbar
public final class FramedScrollbar
A free-standing scrollbar process in its own frame, with configure and event channels.
___________________ | | | | | | | |configure
| |event
----->-----| FramedScrollbar |----->----- (java.lang.Integer) | | (int) (java.lang.Boolean) | | (ActiveScrollbar.Configure
) | | | | |___________________|
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.
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 (); } }
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 |
---|
public FramedScrollbar(String title, int pixDown, int pixAcross, ChannelInput configure, ChannelOutputInt event, boolean horizontal, int value, int visible, int minimum, int maximum)
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 onevalue
- 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 scrollbarmaximum
- the maximum position of the button in the scrollbarMethod Detail |
---|
public void run()
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 |