// (c) MIT 2003.  All rights reserved.

// $Id: GroupTransition.java,v 1.3 2003/03/06 00:40:40 moltmans Exp $
// Time-stamp: <2000-03-11 18:59:36 moltmans>
package rec.sys;


import java.util.*;
import rec.util.*;

public class GroupTransition extends DoTransition
{

  Vector m_Transitions;
  
  /**
   * use this to create the DoTransition
   */
  public GroupTransition( Surface s )
  {
    super( s );
    m_Transitions = new Vector();
  }

  public void addTransition( DoTransition dt )
  {
    m_Transitions.add( dt );
  }
  
  /**
   * perform the transition
   */
  public void doDo()
  {
    ListIterator li = m_Transitions.listIterator( );
    while ( li.hasNext() ) {
      ((DoTransition)li.next()).doDo();
    } 
   
  }

  /**
   * undoes the transition 
   */
  public void doUndo() 
  {
    ListIterator li = m_Transitions.listIterator( m_Transitions.size() );
    while ( li.hasPrevious() ) {
      ((DoTransition)li.previous()).doUndo();
    } 
  }

  /* get the effects of the action without performing the do */
  // for now this is just a string, soon it will be an action object
  // that can be more easily reasoned about.
  public String getAction()
  {
    String s = "group [";
    Iterator it = m_Transitions.iterator();
    while( it.hasNext() )
      {
	s += "" + it.next();
	if ( it.hasNext() )
	  s += ", ";
      }

    s += "]";
    return s;
  }


}

