package rec.simulate.widgets;

import rec.util.*;
import rec.geo.*;
import rec.sys.*;
import rec.core.widgets.*;
import java.io.*;
import java.awt.*;
import java.lang.*;
import java.util.*;

public abstract class WSimGear extends WSimBody
{
    protected GCircle m_circle;
    protected WCircle m_wcircle;
    protected WSimGearTrain m_train;

    public WSimGear(WSimGear gear){
	m_Name = "Gear" + getId();
	setDefaultColor("gear", "gear");
	setEnglishName("Gear");

	m_circle = new GCircle(gear.getCenter(),
			       gear.getRadius());

    }

    public WSimGear(WCircle newCircle){
    
	m_Name = "Gear" + getId();
	setDefaultColor("gear", "gear");
	setEnglishName("Gear");

	m_circle = newCircle.getCircle();
	m_wcircle = newCircle;

    }

    public void die(){
	super.die();
	getTrain().killGear(this);
    }
    
    public void trainDies(WSimGearTrain train){
    }

    public void setTrain(WSimGearTrain train){
	m_train = train;
    }

    public boolean isMyCircle(WCircle circle){
	return (m_wcircle == circle);
    }

    public WSimGearTrain getTrain(){
	return m_train;
    }

    public GPoint getCenter(){
	return m_circle.getCenter();
    }

    public double getRadius(){
	return m_circle.getRadius();
    }

    public GShape getShape(){
	return m_circle;
    }

    public void draw( Graphics g )
    {
	m_circle.display( g );
    }

    public boolean includes( GPoint gp, double offset )
    {
	if ( m_circle.includes( gp, offset ) ){
		return true;
	}
	return false;
    }

    public GCircle getCircle()
    {
	return m_circle;
    }

    public boolean contains( GPoint gp, double offset )
    {
	if ( m_circle.contains( gp, offset ) ){
		return true;
	}
	return false;
    }

    public boolean contains( GPoint gp )
    {
	if ( m_circle.contains( gp ) ){
		return true;
	}
	return false;
    }


    public Rectangle getBounds()
    {
	return m_circle.getBounds();
    }

    public Location getLocation()
    {
	return( new Location(getBounds()));
    }

    public void move( GPoint gp )
    {
	
	GPoint center = getLocation().getCenter();
	    
	m_circle.translate(center, gp);

    }
}
