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

// $Id: SelectionRecognizer.java,v 1.7 2003/03/06 00:40:47 moltmans Exp $
// Time-stamp: <2000-03-16 21:01:49 moltmans>
package rec.core.recognizers;



////////////////////////////////////////////////////////////////////////////
//
// FILE:	SelectionRecognizer.java
//
// AUTHOR:	Manoj D. Muzumdar
//		archon@ai.mit.edu
//
// DATE:	June, 1998
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:	Drawing recognition
//
// HISTORY:     September, 1998
//              MDM
//              modified to fit with new recognition model
//
/////////////////////////////////////////////////////////////////////////////


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

public class SelectionRecognizer extends Recognizer
{
  public SelectionRecognizer()
  {
  }

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

  public boolean recognize( Surface s, Widget w )
  {
    WClick c = (WClick)w;

    //    s.removeWidget( c );

    GeometryCalculator calc = new GeometryCalculator( s );
    
    //delete this line when i know it works...
    //    VisibleWidget vw =
    //  calc.findSelectedWithCheck( c.getLocation().getCenter(),
    //			  new NotRelatedFilter( w ) );

    // this line replaces the one above it
    VisibleWidget vw =
      calc.findSelectedOnSurface( c.getLocation().getCenter() );
    
    if( vw == null || vw instanceof WCircleGroup)
      return( false );

    Console.writeln( vw + " selected" );

    // make it a group, since selections take groups now.
    WGroup single = new WGroup();
    single.add( vw );
    WSelection sl = new WSelection( single, false );
    s.replaceWidget( w, sl );
    
    return( true );
  }

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

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

    return( v.iterator() );
  }

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

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

    return( v.iterator() );
  }
}

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