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

// $Id: SelectionTargetReasoner.java,v 1.5 2003/03/06 00:40:48 moltmans Exp $
// Time-stamp: <2000-03-16 21:08:30 moltmans>
package rec.core.reasoners;



import java.io.*;
import java.util.*;
import rec.util.*;
import rec.sys.*;
import rec.core.widgets.*;

public class SelectionTargetReasoner extends TargetReasoner
{
  public SelectionTargetReasoner()
  {
    super();
  }


  public Iterator getStrongerTypes()
  {
    Vector v = new Vector();

    v.addElement( "rec.core.widgets.WDeletion" );

    return v.iterator();
  }

  public Iterator getWeakerTypes()
  {
    Vector v = new Vector();

    v.addElement( "rec.core.widgets.WSelection" );
    v.addElement( "rec.sys.VisibleWidget" );
    v.addElement( "rec.core.widgets.WClick" );
    
    return v.iterator();
  }

  public boolean match( Surface s, Widget stronger, Widget weaker )
  {
    if ( !( weaker instanceof WSelection ) ) {
      return true;
    }
    
    WSelection sel = (WSelection)getTarget();
    WGroup selgrp = (WGroup)sel.getSelected();
    Collection grp1 = selgrp.getWidgets();
    WGroup selgrp2 = (WGroup)((WSelection)weaker).getSelected();

    // never elect a selection if the widget is already selected
    if ( grp1.containsAll( selgrp2.getWidgets() ) ) {
      return true;
    }
    else {
      return false;
    }
  }

}
