01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: * Darrell Meyer <darrell@mygwt.net> - derived implementation
11: *******************************************************************************/package net.mygwt.ui.client.util;
12:
13: /**
14: * Instances of this class represent rectangular areas in an (x, y) coordinate
15: * system.
16: *
17: * @see Point
18: */
19: public class Rectangle {
20:
21: /**
22: * The x coordinate.
23: */
24: public int x;
25:
26: /**
27: * The y coordinate.
28: */
29: public int y;
30:
31: /**
32: * The width of the rectangle
33: */
34: public int width;
35:
36: /**
37: * The height of the rectangle
38: */
39: public int height;
40:
41: /**
42: * Create a new rectangle instance.
43: */
44: public Rectangle() {
45:
46: }
47:
48: /**
49: * Creates a new rectangle instance.
50: *
51: * @param x the x value
52: * @param y the y value
53: * @param width the rectangle's width
54: * @param height the rectangle's height
55: */
56: public Rectangle(int x, int y, int width, int height) {
57: this .x = x;
58: this .y = y;
59: this .width = width;
60: this .height = height;
61: }
62:
63: /**
64: * Returns <code>true</code> if the point specified by the arguments is
65: * inside the area specified by the receiver, and <code>false</code>
66: * otherwise.
67: *
68: * @param x the x coordinate of the point to test for containment
69: * @param y the y coordinate of the point to test for containment
70: * @return <code>true</code> if the rectangle contains the point and
71: * <code>false</code> otherwise
72: */
73: public boolean contains(int x, int y) {
74: return (x >= this .x) && (y >= this .y) && ((x - this .x) < width)
75: && ((y - this .y) < height);
76: }
77:
78: public boolean equals(Object object) {
79: if (object == this )
80: return true;
81: if (!(object instanceof Rectangle))
82: return false;
83: Rectangle r = (Rectangle) object;
84: return (r.x == this .x) && (r.y == this .y)
85: && (r.width == this .width) && (r.height == this .height);
86: }
87:
88: public String toString() {
89: return "left: " + x + " top: " + y + " width: " + width
90: + " height: " + height;
91: }
92:
93: }
|