/**
  *
  * See the end of the file for the log of changes.
  *
  * $Author: mtsezgin $
  * $Date: 2000/06/03 01:52:34 $
  * $Revision: 1.2 $
  * $Headers$
  * $Id: Pin.java,v 1.2 2000/06/03 01:52:34 mtsezgin Exp $
  * $Name:  $
  * $Locker:  $
  * $Source: /mit/mtsezgin/CVS/Repository/REC/Pin.java,v $
  *
  **/


import java.awt.Color;
import java.awt.Graphics;

import java.util.Vector;

/**
  *
  * A basic Pin with a round top and a cross.
  *
  **/

class      Pin
implements NonTerminal
{
    /**
    *
    * Original cross.
    *
    **/
    private Cross original_cross;
    
    /**
    *
    * Original circle
    *
    **/
    private Ellipse original_circle;
    
    /**
    *
    * Modified cross.
    *
    **/
    private Cross cross;
    
    /**
    *
    * Modified circle.
    *
    **/
    private Ellipse circle;

    /**
    *
    * children
    *
    **/
    private Vector children;

    /**
    *
    * Graphics context for this Geometric object.
    *
    **/
    public Graphics graphics;
    
    
    /**
    *
    * The constructor.
    *
    **/    
    Pin( Ellipse circle, Cross cross )
    {
        int r = (int)(circle.width+circle.height)/2;
        this.original_circle = circle;
        this.original_cross  = cross;
        this.circle          = new Ellipse( circle.x, 
                                            circle.y,
                                            r,
                                            r );
        this.cross           = 
            new Cross( 
                new Line( circle.x, 
                          circle.y + r/2,
                          circle.x + r,
                          circle.y + r/2 ),
                new Line( circle.x + r/2, 
                          circle.y ,
                          circle.x + r/2,
                          circle.y + r ) );

        children = new Vector();
        
        children.addElement( original_circle );
        children.addElement( original_cross  );
    }


    /**
    *
    * Draw the Pin.
    *
    **/
    public void
    paint()
    {
        if ( graphics == null ) // Draw only if g
            return;             // is valid
        graphics.setColor( Color.black );
        paint( graphics );
    }


    /**
    *
    * Draw the Pin
    *
    **/
    public void
    paint( Graphics g )
    {
        cross.paint( g );
        circle.paint( g );
    }


       /**
    *
    * Set graphics context for this Pin object.
    * Must be set at least once before doing any drawing.
    *
    **/
    public void
    setGraphicsContext( Graphics g )
    {
        graphics = g;
    }


    /**
    *
    * Implement Paintable 
    *
    **/    
    public String
    getType()
    {
        return "pin";
    }
    
    
    /**
    *
    * This method is used to paint the original data points that
    * forms this GeometricObject
    *
    **/
    public void
    paintOriginal( Graphics g )
    {
        original_circle.paintOriginal( g );
        original_cross.paintOriginal( g );
    }
    
    
    /**
    *
    * This method should return the Rectangular bounds of this 
    * non-terminal object.
    *
    **/
    public Rectangle
    getRectangularBounds()
    {
        return (circle.getRectangularBounds()).union( 
                    cross.getRectangularBounds() );
    }
    
    
    /**
    *
    * This method should return the polygonal array bounds of this 
    * non-terminal object. This is a rough approximation of the
    * constituents of the object. 
    *
    **/
    public Polygon[]
    getPolygonalBoundsArray()
    {
        Polygon[] polygonal_bounds_array = new Polygon[3];
        
        polygonal_bounds_array[0] = circle.getPolygonalBounds();
        polygonal_bounds_array[1] = (cross.getPolygonalBoundsArray())[0];
        polygonal_bounds_array[2] = (cross.getPolygonalBoundsArray())[1];
        
        return polygonal_bounds_array;
    }
    
    
    /**
    *
    * This method should return a vector containing the children of 
    * this object. Children are the Terminal or NonTerminal 
    * constituents of this object.
    *
    **/
    public Vector
    getChildren()
    {
        return children;
    }
}
