|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.javaranch.common.IRect
A very lean serialized rectangle type made of ints.
- - - - - - - - - - - - - - - - -
Copyright (c) 1998-2004 Paul Wheaton
You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...
My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.
The original source can be found at JavaRanch
- - - - - - - - - - - - - - - - -
Constructor Summary | |
IRect()
Create an IRect object at 0,0 with a width of 0 and a height of 0. |
|
IRect(int x,
int y,
int width,
int height)
Create an IRect object with a specific X, Y, Width and Height. |
|
IRect(IPoint p)
Create an IRect object with a specified location, a width of zero and a height of zero. |
|
IRect(IPoint p,
int width,
int height)
Create an IRect object with a specific point, Width and Height. |
|
IRect(IPoint p1,
IPoint p2)
Create an IRect object from two opposing points. |
|
IRect(IRect r)
Create an IRect object with the same size and location as another IRect object. |
|
IRect(java.awt.Rectangle r)
Create an IRect object with the same size and location as a java.awt.Rectangle object. |
Method Summary | |
void |
adjust(int x,
int y,
int width,
int height)
Adjust all possible attributes of this object. |
boolean |
equals(IRect r)
Are the two IRect objects at the same location and the same size. |
boolean |
equals(java.lang.Object obj)
|
int |
getBottom()
Get the Y value of the bottom edge of the rectangle. |
IPoint |
getBottomLeft()
Get the point that represents the bottom, left corner of the rectangle. |
IPoint |
getBottomRight()
Get the point that represents the bottom, right corner of the rectangle. |
int |
getHeight()
|
int |
getLeft()
Get the X value of the left edge of the rectangle. |
java.awt.Rectangle |
getRectangle()
Convert the IRect format to a java.awt.Rectangle object. |
int |
getRight()
Get the X value of the right edge of the rectangle. |
int |
getTop()
Get the Y value of the top edge of the rectangle. |
IPoint |
getTopLeft()
Get the point that represents the top, left corner of the rectangle. |
IPoint |
getTopRight()
Get the point that represents the top, right corner of the rectangle. |
int |
getWidth()
|
int |
getX()
The left edge. |
int |
getY()
The top edge. |
void |
inc(IPoint p)
Move the object without changing the width or height. |
void |
incHeight(int val)
Change the height without changing the top edge. |
void |
incWidth(int val)
Change the width without changing the left edge. |
void |
incX(int val)
Change the left edge without changing the width. |
void |
incY(int val)
Change the top edge without changing the height. |
static boolean |
PointOnRect(IPoint p,
IRect r)
Does the given point touch the given rectangle. |
static boolean |
RectOnRect(IRect r1,
IRect r2)
Do these two rectangles touch. |
void |
set(IPoint p)
Move the top left corner of this object to a specific point. |
void |
set(IRect r)
Set this object to be equal to another IRect object. |
void |
setBottom(int b)
Change the height of this object so that the bottom edge will line up to a specific position. |
void |
setHeight(int newHeight)
Move the bottom edge of this object to accomidate the new height. |
void |
setRight(int r)
Change the width of this object so that the right edge will line up to a specific position. |
void |
setWidth(int newWidth)
Move the right edge of this object to accomidate the new width. |
void |
setX(int newX)
Move this object so the left edge will will line up with a specific position. |
void |
setY(int newY)
Move this object so the top edge will will line up with a specific position. |
void |
shrink(int val)
Change the rectangle to be a slightly smaller rectangle centered within the old rectangle. |
void |
swell(int val)
Change the rectangle to be a slightly larger rectangle. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public IRect()
public IRect(IRect r)
public IRect(int x, int y, int width, int height)
x
- The left edge. y
- The top edge. public IRect(java.awt.Rectangle r)
public IRect(IPoint p, int width, int height)
p
- The top left corner. public IRect(IPoint p1, IPoint p2)
public IRect(IPoint p)
Method Detail |
public boolean equals(IRect r)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int getX()
public int getY()
public int getWidth()
public int getHeight()
public int getLeft()
public int getTop()
public int getRight()
public int getBottom()
public IPoint getTopLeft()
public IPoint getTopRight()
public IPoint getBottomLeft()
public IPoint getBottomRight()
public java.awt.Rectangle getRectangle()
public void set(IRect r)
public void set(IPoint p)
Width and height are not changed.
public void setRight(int r)
public void setBottom(int b)
public void setX(int newX)
Width is not changed.
public void setY(int newY)
Height is not changed.
public void setWidth(int newWidth)
public void setHeight(int newHeight)
public void inc(IPoint p)
Positive values in p.x will move this object to the right. Negative values to the left.
Positive values in p.y will move this object down. Negative values up.
public void adjust(int x, int y, int width, int height)
x
- Change the left edge without changing the width. y
- Change the top edge without changing the height. width
- Change the width without changing the left edge. height
- Change the height without changing the top edge. public void incX(int val)
public void incY(int val)
public void incWidth(int val)
public void incHeight(int val)
public void shrink(int val)
Calling shrink(1) will make this rectangle fit exactly within the old rectangle. The left edge will be one pixel further right than it was. The right edge will be one pixel to the left of where it was. The top edge will be one pixel lower and the bottom edge will be one pixel higher.
val
- how many pixels to shrink. public void swell(int val)
Calling swell(1) will make this rectangle wrap exactly around the old rectangle. The left edge will be one pixel further left than it was. The right edge will be one pixel to the right of where it was. The top edge will be one pixel higher and the bottom edge will be one pixel lower.
val
- how many pixels to swell. public static boolean PointOnRect(IPoint p, IRect r)
public static boolean RectOnRect(IRect r1, IRect r2)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |