Sindbad~EG File Manager

Current Path : /usr/home/beeson/public_html/dynamicgeometry/org/dynamicgeometry/diagrammer/
Upload File :
Current File : /usr/home/beeson/public_html/dynamicgeometry/org/dynamicgeometry/diagrammer/Circle.java

/**
 * This is a Geometric Object representing a Circle.
 * File: Circle.java
 *
 * This code is in the public domain.
 *
 * @author Brian Chan
 */
// 12.24.06  Beeson changed color to GREEN

package org.dynamicgeometry.diagrammer;

import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.Point2D;

public class Circle extends GeometricObject {

	/**
	 * A constructor of Circle
	 *
	 */
	public Circle()
	{
		// calls the constructor of Geometric Object
		super();
	}

	/**
	 * A constructor of Circle
	 *
	 * @param C the Point used as the center of the Circle
	 * @param P the Point used to determine the radius of the Circle
	 */
	public Circle(Point C, Point P)
	{
		// calls the constructor of Geometric Object
		this();
        Arguments.add(C);
        Arguments.add(P);
	}

	/**
	 * Draws a Circle using the Graphics2D parameter.
	 *
	 * @param g the Object used to draw a Circle
	 */
	public void draw(Graphics2D g)
	{
		Point center, end;

		// Checks if Arguments contains the proper values to draw a Circle
		//  draw if visible
		if(this.visible &&
		   this.Arguments.size() == 2 &&
		   (center = (Point)Arguments.get(0)) instanceof Point &&
		   (end = (Point)Arguments.get(1)) instanceof Point)
		{
			double radius = Math.sqrt( (center.x - end.x) * (center.x - end.x) +
					                   (center.y - end.y) * (center.y - end.y));

			// if this Object is input
			if(this.isInput != 0)
			{
				// if this Object is selected and is input
				if(this.selected)
					g.setColor(Color.GREEN);

				// if this Object is not selected but is input
				else
					g.setColor(Color.BLUE);
			}

			// if this Object is not input
			else
			{
				// if this Object is selected and is input
				if(this.selected)
					g.setColor(Color.RED);

				// if this Object is not selected but is input
				else
					g.setColor(Color.BLACK);
			}

			// set the line thickness
			g.setStroke( new BasicStroke(lineThickness) );

			g.drawArc( (int)(center.x - radius),
					   (int)(center.y - radius),
					   (int)(radius * 2),
					   (int)(radius * 2),
					   0,
					   360);

			// Draws the Label of this Circe if it has one set
			if(this.label != null && this.label.getVisible())
			{
				FontRenderContext frc = g.getFontRenderContext();
				TextLayout layout = new TextLayout( this.label.toString(),
						                            this.label.getFont(),
						                            frc);

				this.label.setLocation(
						new Point2D.Double(
								radius + center.x - 4 * EPSILON * this.label.toString().length(),
						        center.y) );

				layout.draw(g,
						    (float)this.label.getLocation().getX(),
						    (float)this.label.getLocation().getY() );
			}
		}
	}

	/**
	 * Determines if a mouse click is "close" enough to constitute a mouse
	 * click for this Object.
	 *
	 * @param x the x coordinate of the mouse click
	 * @param y the y coordinate of this mouse click
	 * @return true if this Object was clicked, false if this Object was not clicked
	 */
	public boolean clickedOn(double x, double y)
	{
		Point center,
		      end;

        // Checks if Arguments contains the proper values to draw a Circle
		if(this.visible &&
		   this.Arguments.size() == 2 &&
		   (center = (Point)Arguments.get(0)) instanceof Point &&
		   (end = (Point)Arguments.get(1)) instanceof Point)
		{
			double distance = Math.sqrt( (center.x - x) * (center.x - x) +
					                     (center.y - y) * (center.y - y) );

			double radius = Math.sqrt( (center.x - end.x) * (center.x - end.x) +
					                   (center.y - end.y) * (center.y - end.y) );

			return Math.abs(distance - radius) < (EPSILON + this.lineThickness);
		}
		else return false;
	}

	/**
	 * Returns the center of the Circle
	 *
	 * @return the center of the Circle from Arguments index 0
	 */
    public Point getCenter()
    {
        return (Point)Arguments.get(0);
    }

    /**
     * Returns the Point that lies on the Circle
     *
     * @return the Point that lies on the Circle from Argument index 1
     */
    public Point getEnd()
    {
        return (Point)Arguments.get(1);
    }
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists