1 /*****************************************************/
\r
2 /* This java file is a part of the */
\r
4 /* - Plouf's Java IRC Client - */
\r
6 /* Copyright (C) 2002 - 2004 Philippe Detournay */
\r
8 /* All contacts : theplouf@yahoo.com */
\r
10 /* PJIRC is free software; you can redistribute */
\r
11 /* it and/or modify it under the terms of the GNU */
\r
12 /* General Public License as published by the */
\r
13 /* Free Software Foundation; version 2 or later of */
\r
16 /* PJIRC is distributed in the hope that it will */
\r
17 /* be useful, but WITHOUT ANY WARRANTY; without */
\r
18 /* even the implied warranty of MERCHANTABILITY or */
\r
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
\r
20 /* General Public License for more details. */
\r
22 /* You should have received a copy of the GNU */
\r
23 /* General Public License along with PJIRC; if */
\r
24 /* not, write to the Free Software Foundation, */
\r
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
\r
26 /* MA 02111-1307 USA */
\r
28 /*****************************************************/
\r
35 public class StyledRectangle {
\r
57 * Create a new StyledRectangle.
\r
68 public StyledRectangle(int ax, int ay, int w, int h) {
\r
76 public boolean equals(Object o) {
\r
77 if (!(o instanceof StyledRectangle))
\r
79 StyledRectangle r = (StyledRectangle) o;
\r
80 return (r.x == x) && (r.y == y) && (r.width == width) && (r.height == height);
\r
84 public int hashCode() {
\r
85 return x + y + width + height;
\r
89 * Test wether the given point is inside the rectangle or not.
\r
92 * x coordinate of point to test.
\r
94 * y coordinate of point to test.
\r
95 * @return true if the point is inside the rectangle, false otherwise.
\r
97 public boolean contains(int px, int py) {
\r
98 return (px >= x) && (py >= y) && (px < x + width) && (py < y + height);
\r
101 private boolean noEmpty(int v1, int lv1, int v2, int lv2) {
\r
103 return v1 + lv1 > v2;
\r
104 return v2 + lv2 > v1;
\r
108 * Test wether the given rectangle is partially or fully inside the rectangle
\r
112 * rectangle to test.
\r
113 * @return true if r is partially or fully inside the rectangle, false
\r
116 public boolean hit(StyledRectangle r) {
\r
117 if (!noEmpty(r.x, r.width, x, width))
\r
119 return noEmpty(r.y, r.height, y, height);
\r
123 * Add the given rectangle to this rectangle. This rectangle will be the union
\r
124 * of the two rectangles.
\r
127 * the rectangle to add.
\r
129 public void add(StyledRectangle r) {
\r
131 width += (x - r.x);
\r
136 height += (y - r.y);
\r
140 if (r.width > width)
\r
142 if (r.height > height)
\r
147 public String toString() {
\r
148 return "StyledRectangle : " + x + "," + y + "," + width + "," + height;
\r