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/Point.java

/**
 * This class represents a Point displayed by Diagrammer.
 * Geometric Objects use Point as arguments.
 * File: Point.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.*;

public class Point extends GeometricObject {

	// the x and y coordinates of this Point
	protected double x,y;

	/**
	 * A constructor for Point.
	 *
	 */
	public Point()
	{
		super();
		lineThickness = 5;
 	}

	/**
	 * A constructor for Point.
	 *
	 * @param x the x value for this Point
	 * @param y the y value for this Point
	 */
	public Point(double x, double y)
	{
		this();
		this.x = x;
		this.y = y;
	}

    /**
     * A constructor for Point.
     *
     * @author Christopher Mathenia
     *
     * @param x the x value for this Point
     * @param y the y value for this Point
     * @param visible sets the visibility of this Point. true if visisble,
     *                                                   false if not visisble
     */
    public Point(double x, double y, boolean visible)
	{
		this(x, y);
        this.visible = visible;
	}

	/**
	 * Draws a Point using the Graphics2D parameter.
	 *
	 * @param g the Object used to draw an Arc
	 */
	public void draw(Graphics2D g)
	{
		// draws a Point only if visible
		if(this.visible)
		{
			// 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);
			}

			g.fillArc((int)(x - lineThickness),
					  (int)(y - lineThickness),
					  lineThickness * 2,
					  lineThickness * 2,
					  0,
					  360);

			// Draws the Label for this Point if it is initilized and visible
			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(this.x + this.lineThickness + EPSILON,
						                   this.y + this.lineThickness + EPSILON));

				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)
	{
		return Math.sqrt((x - this.x) * (x - this.x) + (y - this.y) * (y - this.y)) < (EPSILON + this.lineThickness);
	}

	/**
	 * Sets the x value of this Point.
	 *
	 * @param x the new value for x
	 */
	public void setX(double x)
	{
		this.x = x;
	}

	/**
	 * Returns the x value of this Point
	 *
	 * @author Christopher Mathenia
	 *
	 * @return the current value of x
	 */
    public double getX()
    {
    	return this.x;
    }

	/**
	 * Sets the y of the Point.
	 *
	 * @author Christopher Mathenia
	 *
	 * @param y the new value for y
	 */
	public void setY(double y)
	{
		this.y = y;
	}

	/**
	 * Returns the y value of this Point
	 *
	 * @return the current value of y
	 */
    public double getY()
    {
    	return this.y;
    }

    /**
     * Checks of a Geometric Object is equal to this Point.
     *
     * @param obj the Geometric Object to be checked against.
     * @return true if obj is equal to this Point, false if they are not equal.
     */
    public boolean equals(GeometricObject obj)
    {
    	Point p;

    	if(obj instanceof Point)
    	{
    		p = (Point)obj;
    		return p.x == this.x && p.y == this.y;
    	}
    	else return false;
    }
}

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