001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Denis M. Kishenko
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.awt.geom.Point2D;
023: import java.io.Serializable;
024:
025: public class Point extends Point2D implements Serializable {
026:
027: private static final long serialVersionUID = -5276940640259749850L;
028:
029: public int x;
030: public int y;
031:
032: public Point() {
033: setLocation(0, 0);
034: }
035:
036: public Point(int x, int y) {
037: setLocation(x, y);
038: }
039:
040: public Point(Point p) {
041: setLocation(p.x, p.y);
042: }
043:
044: @Override
045: public boolean equals(Object obj) {
046: if (obj == this ) {
047: return true;
048: }
049: if (obj instanceof Point) {
050: Point p = (Point) obj;
051: return x == p.x && y == p.y;
052: }
053: return false;
054: }
055:
056: @Override
057: public String toString() {
058: return getClass().getName() + "[x=" + x + ",y=" + y + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
059: }
060:
061: @Override
062: public double getX() {
063: return x;
064: }
065:
066: @Override
067: public double getY() {
068: return y;
069: }
070:
071: public Point getLocation() {
072: return new Point(x, y);
073: }
074:
075: public void setLocation(Point p) {
076: setLocation(p.x, p.y);
077: }
078:
079: public void setLocation(int x, int y) {
080: this .x = x;
081: this .y = y;
082: }
083:
084: @Override
085: public void setLocation(double x, double y) {
086: x = x < Integer.MIN_VALUE ? Integer.MIN_VALUE
087: : x > Integer.MAX_VALUE ? Integer.MAX_VALUE : x;
088: y = y < Integer.MIN_VALUE ? Integer.MIN_VALUE
089: : y > Integer.MAX_VALUE ? Integer.MAX_VALUE : y;
090: setLocation((int) Math.round(x), (int) Math.round(y));
091: }
092:
093: public void move(int x, int y) {
094: setLocation(x, y);
095: }
096:
097: public void translate(int dx, int dy) {
098: x += dx;
099: y += dy;
100: }
101:
102: }
|