////////////////////////////////////////////////////////////////////////////////
//																			  //
// AUTHOR:      Tevfik Metin Sezgin	                        				  //
//				Massachusetts Institute of Technology						  //
//				Department of Electrical Engineering and Computer Science	  //
//				Artificial Intelligence Laboratory							  //
//																			  //
// E-MAIL:		mtsezgin@ai.mit.edu, mtsezgin@mit.edu						  //
//																			  //
// COPYRIGHT:   Tevfik Metin Sezgin                    						  //
//              All rights reserved. This code can not be copied, modified,   //
//              or distributed in whole or partially without the written 	  //
//				permission of the author. Also see the COPYRIGHT file.		  //
//																			  //
////////////////////////////////////////////////////////////////////////////////

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


import java.awt.Component;
import java.awt.Container;

import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.PathIterator;

import java.util.Vector;


/**
  *
  * Implements some methods not found in jdk 1.1
  *
  **/
public class
AWTUtil
{
    /**
    *
    * Get all the sub componets in this container.
    *
    **/
    public static Component[]
    getAllComponentsRecursively( Container container )
    {
		Component first_layer[];
		Vector    components = new Vector();
		
		first_layer = container.getComponents();
		for ( int i=0; i<first_layer.length; i++ ) {
			components.add( first_layer[i] );
			if ( first_layer[i] instanceof Container ) {
				Component second_layer[] = getAllComponentsRecursively(
					((Container)first_layer[i]) );
				for ( int j=0; j<second_layer.length; j++ ) {
					components.add( second_layer[j] );
				}
			}
		}
		
		Object    objects[] = components.toArray();
		Component result[]  = new Component[objects.length];
		for ( int i=0; i<objects.length; i++ ) {
			result[i] = (Component)objects[i];
		}
		
		return result;
    }


    /**
    *
    * Return the number of segments in a java.awt.GeneralPath 
	* object.
    *
    **/
    public static int
    getSegmentCount( GeneralPath general_path )
    {
		PathIterator path_iterator;
		
		path_iterator = general_path.getPathIterator( new AffineTransform() );
		
		int segments = 0;
		while ( !path_iterator.isDone() ) {
			path_iterator.next();
			segments++;
		}
		
		return segments;
    }
}


/** 
  * 
  * $Log: GraphicsUtil.java,v $
  * Revision 1.4  2000/06/03 01:52:33  mtsezgin
  * *** empty log message ***
  *
  * Revision 1.3  2000/04/28 04:45:03  mtsezgin
  *
  * Now each GeometricObject keeps the mouse input that was previously
  * discarded. User can switch between seeing the recognized mode and
  * the raw mode. setDataPoints( Polygon points ) and getDataPoints()
  * are added to GeometricObject, and all the implementors are modified
  * accordingly.
  *
  * Revision 1.2  2000/04/25 22:15:29  mtsezgin
  *
  * Added more utility functions.
  *
  * Revision 1.1.1.1  2000/04/01 03:07:07  mtsezgin
  * Imported sources
  *
  * Revision 1.2  2000/03/31 22:41:03  mtsezgin
  *
  * Started Log tracking.
  *
  *  
  **/
