yu.ac.bg.etf.javaqx.qswing.graphics
Class Rectangle

java.lang.Object
  extended byyu.ac.bg.etf.javaqx.qswing.graphics.RectangularShape
      extended byyu.ac.bg.etf.javaqx.qswing.graphics.Rectangle
All Implemented Interfaces:
Shape

public class Rectangle
extends RectangularShape

Rectangle Class.

NOTE: This class is immutable.

Version:
0.2.0
Author:
Slobodan Vrkacevic (slobodan.vrkacevic@gmail.com)

Nested Class Summary
protected static class Rectangle.RectanglePathIterator
          Rectangle Path Iterator.
 
Constructor Summary
Rectangle()
          Constructs new Rectangle object.
Rectangle(Dimension dimension)
          Constructs new Rectangle object.
Rectangle(int width, int height)
          Constructs new Rectangle object.
Rectangle(int x, int y, int width, int height)
          Constructs new Rectangle object.
Rectangle(Point location)
          Constructs new Rectangle object.
Rectangle(Point location, Dimension dimension)
          Constructs new Rectangle object.
Rectangle(Point topLeft, Point bottomRight)
          Constructs new Rectangle object.
 
Method Summary
 boolean contains(int x, int y)
          Returns true if the specified coordinates lie in the shape.
 boolean equals(java.lang.Object obj)
          
 Rectangle getBounds()
          Returns a rectangle that completely encloses the shape.
 int getHeight()
          Returns the height of the framing rectangle.
 Point getLocation()
          Returns location of the rectangle.
 PathIterator getPathIterator()
          Returns path iterator that traverses the geometry of the Shape.
 Dimension getSize()
          Returns dimension of the rectangle.
 int getWidth()
          Returns the width of the framing rectangle.
 int getX()
          Returns the x coordinate of the framing rectangle.
 int getY()
          Returns the y coordinate of the framing rectangle.
 int hashCode()
          
 Rectangle setLocation(int x, int y)
          Returns new rectangle with specified location and dimension of this rectangle.
 Rectangle setLocation(Point location)
          Returns new rectangle with specified location and dimension of this rectangle.
 Rectangle setSize(Dimension dimension)
          Returns new rectangle with specified dimension and location of this rectangle.
 Rectangle setSize(int width, int height)
          Returns new rectangle with specified dimension and location of this rectangle.
 java.lang.String toString()
          
 Rectangle translate(int dx, int dy)
          Returns translated rectangle at location (x + dx, y + dy).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rectangle

public Rectangle()
Constructs new Rectangle object.


Rectangle

public Rectangle(int x,
                 int y,
                 int width,
                 int height)
Constructs new Rectangle object.

Parameters:
x - the x coordinate of the rectangle
y - the y coordinate of the rectangle
width - the width of the rectangle
height - the height of the rectangle

Rectangle

public Rectangle(Point location,
                 Dimension dimension)
Constructs new Rectangle object.

Parameters:
location - the top-left corner of the rectangle
dimension - the dimension of the rectangle
Throws:
java.lang.IllegalArgumentException - if location or dimension is null

Rectangle

public Rectangle(Point location)
Constructs new Rectangle object.

Parameters:
location - the top-left corner of the rectangle

Rectangle

public Rectangle(Point topLeft,
                 Point bottomRight)
Constructs new Rectangle object.

Parameters:
topLeft - the top-left corner of the rectangle
bottomRight - the bottom-right corner of the rectangle
Throws:
java.lang.IllegalArgumentException - if topLeft is null, bottomRight is null or bottomRight is not bottom-right point.

Rectangle

public Rectangle(Dimension dimension)
Constructs new Rectangle object.

Parameters:
dimension - the dimension of the rectangle

Rectangle

public Rectangle(int width,
                 int height)
Constructs new Rectangle object.

Parameters:
width - the width of the rectangle
height - the height of the rectangle
Method Detail

getLocation

public Point getLocation()
Returns location of the rectangle.

Returns:
location of the rectangle

setLocation

public Rectangle setLocation(int x,
                             int y)
Returns new rectangle with specified location and dimension of this rectangle.

Parameters:
x - the x coordinate of the location
y - the y coordinate of the location
Returns:
new rectangle with specified location and dimension of this rectangle

setLocation

public Rectangle setLocation(Point location)
Returns new rectangle with specified location and dimension of this rectangle.

Parameters:
location - the location
Returns:
new rectangle with specified location and dimension of this rectangle

getSize

public Dimension getSize()
Returns dimension of the rectangle.

Returns:
dimension of the rectangle

setSize

public Rectangle setSize(int width,
                         int height)
Returns new rectangle with specified dimension and location of this rectangle.

Parameters:
width - the width
height - the height
Returns:
new rectangle with specified dimension and location of this rectangle

setSize

public Rectangle setSize(Dimension dimension)
Returns new rectangle with specified dimension and location of this rectangle.

Parameters:
dimension - the dimension
Returns:
new rectangle with specified dimension and location of this rectangle

translate

public Rectangle translate(int dx,
                           int dy)
Returns translated rectangle at location (x + dx, y + dy).

Parameters:
dx - the distance to move this rectangle along the x axis
dy - the distance to move this rectangle along the y axis
Returns:
translated rectangle

contains

public boolean contains(int x,
                        int y)
Returns true if the specified coordinates lie in the shape.

Parameters:
x - the x coordinate
y - the y coordinate
Returns:
true if the specified coordinates lie in the shape

getBounds

public Rectangle getBounds()
Returns a rectangle that completely encloses the shape.

Specified by:
getBounds in interface Shape
Overrides:
getBounds in class RectangularShape

getPathIterator

public PathIterator getPathIterator()
Returns path iterator that traverses the geometry of the Shape.

Returns:
path iterator that traverses the geometry of the Shape

equals

public boolean equals(java.lang.Object obj)


hashCode

public int hashCode()


toString

public java.lang.String toString()


getX

public int getX()
Returns the x coordinate of the framing rectangle.

Specified by:
getX in class RectangularShape
Returns:
the x coordinate of the framing rectangle

getY

public int getY()
Returns the y coordinate of the framing rectangle.

Specified by:
getY in class RectangularShape
Returns:
the y coordinate of the framing rectangle

getWidth

public int getWidth()
Returns the width of the framing rectangle.

Specified by:
getWidth in class RectangularShape
Returns:
the width of the framing rectangle

getHeight

public int getHeight()
Returns the height of the framing rectangle.

Specified by:
getHeight in class RectangularShape
Returns:
the height of the framing rectangle


Copyright © 2007 ETF and contributors. All Rights Reserved.