0N/A/*
2362N/A * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.awt;
0N/A
0N/Aimport java.awt.geom.Point2D;
243N/Aimport java.beans.Transient;
0N/A
0N/A/**
0N/A * A point representing a location in {@code (x,y)} coordinate space,
0N/A * specified in integer precision.
0N/A *
0N/A * @author Sami Shaio
0N/A * @since 1.0
0N/A */
0N/Apublic class Point extends Point2D implements java.io.Serializable {
0N/A /**
0N/A * The X coordinate of this <code>Point</code>.
0N/A * If no X coordinate is set it will default to 0.
0N/A *
0N/A * @serial
0N/A * @see #getLocation()
0N/A * @see #move(int, int)
0N/A * @since 1.0
0N/A */
0N/A public int x;
0N/A
0N/A /**
0N/A * The Y coordinate of this <code>Point</code>.
0N/A * If no Y coordinate is set it will default to 0.
0N/A *
0N/A * @serial
0N/A * @see #getLocation()
0N/A * @see #move(int, int)
0N/A * @since 1.0
0N/A */
0N/A public int y;
0N/A
0N/A /*
0N/A * JDK 1.1 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = -5276940640259749850L;
0N/A
0N/A /**
0N/A * Constructs and initializes a point at the origin
0N/A * (0,&nbsp;0) of the coordinate space.
0N/A * @since 1.1
0N/A */
0N/A public Point() {
0N/A this(0, 0);
0N/A }
0N/A
0N/A /**
0N/A * Constructs and initializes a point with the same location as
0N/A * the specified <code>Point</code> object.
0N/A * @param p a point
0N/A * @since 1.1
0N/A */
0N/A public Point(Point p) {
0N/A this(p.x, p.y);
0N/A }
0N/A
0N/A /**
0N/A * Constructs and initializes a point at the specified
0N/A * {@code (x,y)} location in the coordinate space.
0N/A * @param x the X coordinate of the newly constructed <code>Point</code>
0N/A * @param y the Y coordinate of the newly constructed <code>Point</code>
0N/A * @since 1.0
0N/A */
0N/A public Point(int x, int y) {
0N/A this.x = x;
0N/A this.y = y;
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.2
0N/A */
0N/A public double getX() {
0N/A return x;
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.2
0N/A */
0N/A public double getY() {
0N/A return y;
0N/A }
0N/A
0N/A /**
0N/A * Returns the location of this point.
0N/A * This method is included for completeness, to parallel the
0N/A * <code>getLocation</code> method of <code>Component</code>.
0N/A * @return a copy of this point, at the same location
0N/A * @see java.awt.Component#getLocation
0N/A * @see java.awt.Point#setLocation(java.awt.Point)
0N/A * @see java.awt.Point#setLocation(int, int)
0N/A * @since 1.1
0N/A */
243N/A @Transient
0N/A public Point getLocation() {
0N/A return new Point(x, y);
0N/A }
0N/A
0N/A /**
0N/A * Sets the location of the point to the specified location.
0N/A * This method is included for completeness, to parallel the
0N/A * <code>setLocation</code> method of <code>Component</code>.
0N/A * @param p a point, the new location for this point
0N/A * @see java.awt.Component#setLocation(java.awt.Point)
0N/A * @see java.awt.Point#getLocation
0N/A * @since 1.1
0N/A */
0N/A public void setLocation(Point p) {
0N/A setLocation(p.x, p.y);
0N/A }
0N/A
0N/A /**
0N/A * Changes the point to have the specified location.
0N/A * <p>
0N/A * This method is included for completeness, to parallel the
0N/A * <code>setLocation</code> method of <code>Component</code>.
0N/A * Its behavior is identical with <code>move(int,&nbsp;int)</code>.
0N/A * @param x the X coordinate of the new location
0N/A * @param y the Y coordinate of the new location
0N/A * @see java.awt.Component#setLocation(int, int)
0N/A * @see java.awt.Point#getLocation
0N/A * @see java.awt.Point#move(int, int)
0N/A * @since 1.1
0N/A */
0N/A public void setLocation(int x, int y) {
0N/A move(x, y);
0N/A }
0N/A
0N/A /**
0N/A * Sets the location of this point to the specified double coordinates.
0N/A * The double values will be rounded to integer values.
0N/A * Any number smaller than <code>Integer.MIN_VALUE</code>
0N/A * will be reset to <code>MIN_VALUE</code>, and any number
0N/A * larger than <code>Integer.MAX_VALUE</code> will be
0N/A * reset to <code>MAX_VALUE</code>.
0N/A *
0N/A * @param x the X coordinate of the new location
0N/A * @param y the Y coordinate of the new location
0N/A * @see #getLocation
0N/A */
0N/A public void setLocation(double x, double y) {
0N/A this.x = (int) Math.floor(x+0.5);
0N/A this.y = (int) Math.floor(y+0.5);
0N/A }
0N/A
0N/A /**
0N/A * Moves this point to the specified location in the
0N/A * {@code (x,y)} coordinate plane. This method
0N/A * is identical with <code>setLocation(int,&nbsp;int)</code>.
0N/A * @param x the X coordinate of the new location
0N/A * @param y the Y coordinate of the new location
0N/A * @see java.awt.Component#setLocation(int, int)
0N/A */
0N/A public void move(int x, int y) {
0N/A this.x = x;
0N/A this.y = y;
0N/A }
0N/A
0N/A /**
0N/A * Translates this point, at location {@code (x,y)},
0N/A * by {@code dx} along the {@code x} axis and {@code dy}
0N/A * along the {@code y} axis so that it now represents the point
0N/A * {@code (x+dx,y+dy)}.
0N/A *
0N/A * @param dx the distance to move this point
0N/A * along the X axis
0N/A * @param dy the distance to move this point
0N/A * along the Y axis
0N/A */
0N/A public void translate(int dx, int dy) {
0N/A this.x += dx;
0N/A this.y += dy;
0N/A }
0N/A
0N/A /**
0N/A * Determines whether or not two points are equal. Two instances of
0N/A * <code>Point2D</code> are equal if the values of their
0N/A * <code>x</code> and <code>y</code> member fields, representing
0N/A * their position in the coordinate space, are the same.
0N/A * @param obj an object to be compared with this <code>Point2D</code>
0N/A * @return <code>true</code> if the object to be compared is
0N/A * an instance of <code>Point2D</code> and has
0N/A * the same values; <code>false</code> otherwise.
0N/A */
0N/A public boolean equals(Object obj) {
0N/A if (obj instanceof Point) {
0N/A Point pt = (Point)obj;
0N/A return (x == pt.x) && (y == pt.y);
0N/A }
0N/A return super.equals(obj);
0N/A }
0N/A
0N/A /**
0N/A * Returns a string representation of this point and its location
0N/A * in the {@code (x,y)} coordinate space. This method is
0N/A * intended to be used only for debugging purposes, and the content
0N/A * and format of the returned string may vary between implementations.
0N/A * The returned string may be empty but may not be <code>null</code>.
0N/A *
0N/A * @return a string representation of this point
0N/A */
0N/A public String toString() {
0N/A return getClass().getName() + "[x=" + x + ",y=" + y + "]";
0N/A }
0N/A}