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

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



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

/**
 * Find all widgets which are related to the passed widget, and then
 * kill them and the passed widget itself.  Also sever all links going
 * from any of these doomed widgets to any hale and hearty untouched
 * widgets.
 *
 * Some links internal to the doomed widgets may be cut as well--so do
 * not count on their existance.
 */
public class DieTransition extends DoTransition
{
  protected Widget m_Widget;
  private Collection m_DeadWidgets;
  private DoTransition m_SeverTransition;
  private DoTransition m_ExpungeTransition;
  
  /**
   * use this to create the DoTransition
   */
  public DieTransition( Surface s, Widget w )
  {
    super( s );
    m_Widget = w;
    // just in case undo gets called before do
    m_DeadWidgets = new HashSet();
  }


  protected Collection killBadWidgets()
  {
    return m_Widget.uproot();
  }

  /**
   * perform the transition 
   */
  public void doDo() 
  {
    m_DeadWidgets = killBadWidgets();
    //m_SeverTransition = new SeverTransition( m_Surface, m_DeadWidgets );

    //m_SeverTransition.doDo();
    m_ExpungeTransition = m_Surface.expunge();
    
  }

  /**
   * undoes the transition 
   */
  public void doUndo() 
  {
    m_ExpungeTransition.doUndo();
    //m_SeverTransition.doUndo();
    Iterator it = m_DeadWidgets.iterator();
    while ( it.hasNext() ) {
      ((Widget)it.next()).revive();
    }
  }

  /**
   * 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()
  {
    return( "make widget " + m_Widget + " and affected folks die" );
  }

  ////////////////////////////////////////////////////////////////////////////

}

//////////////////////////////////////////////////////////////////////////////
