Trull

edu.luc.cs.trull
Class Cycle

java.lang.Object
  extended by edu.luc.cs.trull.EmptyComponent
      extended by edu.luc.cs.trull.TerminatingComponent
          extended by edu.luc.cs.trull.AbstractComponent
              extended by edu.luc.cs.trull.AbstractCombinator
                  extended by edu.luc.cs.trull.Cycle
All Implemented Interfaces:
Combinator, Component, PropertyChangeSource, Startable, Suspendable, Terminating, java.beans.PropertyChangeListener, java.util.EventListener
Direct Known Subclasses:
SetMode

public class Cycle
extends AbstractCombinator

A combinator that cycles round-robin among several components on any event from a given set of triggering events. It is largely equivalent to this nested Watching construct, but it does not cycle to the next component when the current component terminates.

 cycle c e1 ... en =
   loop
     do e1 watching c ->
       do e2 watching c ->
         ...
           do en watching c
 

See Also:
Loop, Watching

Nested Class Summary
protected  class Cycle.LocalListener
          A dedicated listener that forwards the event from the currently active child component to all external listeners.
 
Nested classes/interfaces inherited from class edu.luc.cs.trull.AbstractCombinator
AbstractCombinator.DefaultTerminationListener
 
Field Summary
private  int currentComponentIndex
          Theh index of the currently active component.
private  java.beans.PropertyChangeListener cycleAction
          The action to be invoked when switching to the next component.
private  java.util.Set cycleEvents
          The set of triggering events for cycling among components.
private  java.beans.PropertyChangeListener internalListener
          An internal listener that listens to the currently active child branch of this component and forwards events to the external listeners.
private static org.apache.log4j.Logger logger
           
 
Fields inherited from class edu.luc.cs.trull.AbstractCombinator
components
 
Constructor Summary
Cycle()
          Constructs an empty Cycle component.
Cycle(java.lang.String[] labels, Component[] branches)
          Cycle(labels, null, branches)
Cycle(java.lang.String[] labels, java.beans.PropertyChangeListener action, Component[] branches)
          Constructs a Cycle component.
Cycle(java.lang.String label, Component[] branches)
          Cycle(label, null, branches)
Cycle(java.lang.String label, java.beans.PropertyChangeListener action, Component[] branches)
          Cycle([label], action, branches)
 
Method Summary
protected  TerminationListener getChildTerminationListener()
          Returns null because this component ignores termination of its children.
protected  Component getCurrentComponent()
          Returns the currently active child component of this Cycle component.
 java.beans.PropertyChangeListener getCycleAction()
          Returns the action to be invoked when switching to the next component.
 java.lang.String[] getCycleEvents()
          Returns an array of triggering event labels for this component.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          This method forwards events received from external sources to the currently active child component.
 void removeComponent(Component c)
          This method removes a component from the cycle.
 void resume()
          Resumes this suspendable component.
 void setCycleAction(java.beans.PropertyChangeListener action)
          Sets the action to be invoked when switching to the next component.
 void setCycleEvent(java.lang.String label)
          Sets the triggering event label for this component to the given string.
 void setCycleEvents(java.util.Collection evts)
          Sets the triggering event labels for this component to the given collection.
 void setCycleEvents(java.lang.String[] labels)
          Sets the triggering event labels for this component to the given array.
 void start(java.beans.PropertyChangeEvent incoming)
          Starts this startable component.
protected  void startCurrent(java.beans.PropertyChangeEvent incoming)
          Starts the currently active component.
 void stop()
          Stops this startable component.
 void suspend()
          Suspends this suspendable component.
protected  void switchToFirstComponent()
          Switches (cycles) to the first child component.
protected  void switchToNextComponent()
          Switches (cycles) to the next child component.
 
Methods inherited from class edu.luc.cs.trull.AbstractCombinator
addComponent, addComponent, addComponent, getComponent, getComponentCount, getComponents, removeAllComponents, removeComponent
 
Methods inherited from class edu.luc.cs.trull.AbstractComponent
addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, getExternalListeners, getPropertyChangeListeners, removePropertyChangeListener
 
Methods inherited from class edu.luc.cs.trull.TerminatingComponent
fireTermination, getParent, getTermEvent, scheduleTermination, setTerminationListener
 
Methods inherited from class edu.luc.cs.trull.EmptyComponent
getTerminationListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.luc.cs.trull.PropertyChangeSource
addPropertyChangeListener, getPropertyChangeListeners, removePropertyChangeListener
 
Methods inherited from interface edu.luc.cs.trull.Terminating
getTerminationListener, setTerminationListener
 

Field Detail

currentComponentIndex

private int currentComponentIndex
Theh index of the currently active component.


cycleAction

private java.beans.PropertyChangeListener cycleAction
The action to be invoked when switching to the next component.


cycleEvents

private java.util.Set cycleEvents
The set of triggering events for cycling among components.


internalListener

private java.beans.PropertyChangeListener internalListener
An internal listener that listens to the currently active child branch of this component and forwards events to the external listeners.


logger

private static final org.apache.log4j.Logger logger
Constructor Detail

Cycle

public Cycle()
Constructs an empty Cycle component. Specific properties can be changed later.


Cycle

public Cycle(java.lang.String[] labels,
             Component[] branches)
Cycle(labels, null, branches)


Cycle

public Cycle(java.lang.String[] labels,
             java.beans.PropertyChangeListener action,
             Component[] branches)
Constructs a Cycle component.

Parameters:
labels - the array of String event labels triggering a switch.
action - the action invoked when a switch is triggered. May be null.
branches - the components among which this component cycles.

Cycle

public Cycle(java.lang.String label,
             Component[] branches)
Cycle(label, null, branches)


Cycle

public Cycle(java.lang.String label,
             java.beans.PropertyChangeListener action,
             Component[] branches)
Cycle([label], action, branches)

Method Detail

getChildTerminationListener

protected TerminationListener getChildTerminationListener()
Returns null because this component ignores termination of its children.

Specified by:
getChildTerminationListener in class AbstractCombinator
Returns:
null.

getCurrentComponent

protected Component getCurrentComponent()
Returns the currently active child component of this Cycle component.

Returns:
the currently active child component.

getCycleAction

public java.beans.PropertyChangeListener getCycleAction()
Returns the action to be invoked when switching to the next component.

Returns:
action the action to be invoked when switching to the next component.

getCycleEvents

public java.lang.String[] getCycleEvents()
Returns an array of triggering event labels for this component.

Returns:
label the array of triggering event labels.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
This method forwards events received from external sources to the currently active child component.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Overrides:
propertyChange in class EmptyComponent
Parameters:
evt - the event received.

removeComponent

public void removeComponent(Component c)
This method removes a component from the cycle.

Specified by:
removeComponent in interface Combinator
Overrides:
removeComponent in class AbstractCombinator
Parameters:
c - the component to be removed.

resume

public void resume()
Description copied from interface: Suspendable
Resumes this suspendable component.

Specified by:
resume in interface Suspendable
Overrides:
resume in class EmptyComponent

setCycleAction

public void setCycleAction(java.beans.PropertyChangeListener action)
Sets the action to be invoked when switching to the next component.

Parameters:
action - the action to be invoked when switching to the next component. May be null.

setCycleEvent

public void setCycleEvent(java.lang.String label)
Sets the triggering event label for this component to the given string.

Parameters:
label - the triggering event label.

setCycleEvents

public void setCycleEvents(java.util.Collection evts)
Sets the triggering event labels for this component to the given collection.

Parameters:
evts - the collection of triggering event labels.

setCycleEvents

public void setCycleEvents(java.lang.String[] labels)
Sets the triggering event labels for this component to the given array.

Parameters:
labels - the array of triggering event labels.

start

public void start(java.beans.PropertyChangeEvent incoming)
Description copied from interface: Startable
Starts this startable component.

Specified by:
start in interface Startable
Overrides:
start in class EmptyComponent
Parameters:
incoming - the event that triggered the invocation of this method. May be null.

startCurrent

protected void startCurrent(java.beans.PropertyChangeEvent incoming)
Starts the currently active component.

Parameters:
incoming - the triggering event.

stop

public void stop()
Description copied from interface: Startable
Stops this startable component.

Specified by:
stop in interface Startable
Overrides:
stop in class EmptyComponent

suspend

public void suspend()
Description copied from interface: Suspendable
Suspends this suspendable component.

Specified by:
suspend in interface Suspendable
Overrides:
suspend in class EmptyComponent

switchToFirstComponent

protected void switchToFirstComponent()
Switches (cycles) to the first child component.


switchToNextComponent

protected void switchToNextComponent()
Switches (cycles) to the next child component.


Trull

http://www.cs.luc.edu/trull/