
//This class represents the specific model

import java.awt.*  ;
import java.util.* ;

public class SpecModel extends Panel {

   Comentry comentry ;
	private Font font ;
   private FontMetrics fm ;

   public int xpos ;
   public int ypos ;

   public Vector Attributes = null;

   public SpecModel(){
      this.setBackground( Color.white ) ;
      font = new Font ( "Helvetica", Font.BOLD, 12  );
      this.setFont( font ) ;
   }

   public SpecModel( Comentry comentry ){
      this.setBackground( Color.white ) ;
      this.comentry = comentry ;
      font = new Font ( "Helvetica", Font.BOLD, 12  );
      this.setFont( font ) ;
   }


   public void ProcessSample( Sample e ){

      //if this is the first Sample seen
      if ( Attributes == null ){
       Vector atts = new Vector ();
         for ( int count = 0 ; count < e.Attributes.length ; count ++){
          	atts.addElement( e.Attributes[count] ) ;
         }
         Attributes = atts ;
      }


     Attribute at ;
     String atName ;
     String atValue ;
     //replace the values that do not match with a "?"
// Corrected by Goto and Sakurai
//     for ( int count = 1 ; count < Attributes.size() -1 ; count ++ )
     for ( int count = 0 ; count < Attributes.size()  ; count ++ )
       {
       	at = ( Attribute ) Attributes.elementAt(count) ;
         atName = at.index ;
         atValue = e.getAttribute(atName).value ;
         if ( !(at.value.equals(atValue)) ){
            comentry.appendText( "One of the attribute values in the specific model does not match the corresponding value "+
                                            "in this positive sample, "  + at.value + " != " + atValue + "."+
                                            "\nThe specific model is generalised accordingly by replacing this " + "value with a ?"  ) ;
          	at.value = "?" ;
         }
     }

   }

  //Returns the longest attribute to aid drawing.
  public String longestAttribute ( ){

      String longest = ""  ;

  		Attribute att ;
      for ( Enumeration en = Attributes.elements ( ) ; en.hasMoreElements ( ) ; ) {
      	att = ( Attribute ) en.nextElement ( ) ;
         if ( ( att.index + " : " + att.value ).length ( ) > longest.length ( ) ) longest = att.index +" : "+ att.value ;
      }
      return longest ;
  }

	public Vector getAttributes(){
   	return Attributes  ;
   }

}