geometri
Interface GeometricalForm

All Superinterfaces:
java.lang.Comparable<GeometricalForm>
All Known Implementing Classes:
AbstractForm, Circle, Line, Oval, Point, Rectangle, Square

public interface GeometricalForm
extends java.lang.Comparable<GeometricalForm>

This interface describes drawable geometrical forms. Each form contains of: A rectangle surrounding the form as narrow as possible defined by its width and height, the position of the upper left corner of the surrounding rectangle, and a colour given as an object of java.awt.Color.

Furthermore the forms may be compared. First the areas of the forms are compared and if the areas are equal then the the perimeters are compared. The area and the perimeter of a Point are 0. The area of a Line is 0 and its perimeter is the length of the line.

The forms may be moved, but may not be modyfied in any other way. Only positive x och y coordinates are allowed for the position. Negative values for the coordinates gives an IllegalPositionException, which is declared in this package.

Finally, the forms may be compared for equality, where all components except the positions of the forms are compared.


Method Summary
 int compareTo(GeometricalForm f)
          The method compareTo compares the area and perimeter of the forms to decide if the given geometrical form is less or greater than this object.
 void fill(java.awt.Graphics g)
          Fill the area of the form at the position of the form with the color of the form.
 int getArea()
          Get the area of this form rounded to closest integer.
 java.awt.Color getColor()
          Get the colour of this form.
 int getHeight()
          Get the height of the surrounding rectangle of this form.
 int getPerimeter()
          Get the perimeter of this form rounded to closest integer.
 int getWidth()
          Get the width of the surrounding rectangle of this form.
 int getX()
          Get the x coordinate of the position of this form.
 int getY()
          Give the y coordinate of the position of this form.
 void move(int dx, int dy)
          Move the form the given distances.
 void place(int x, int y)
          Place the form on given coordinates.
 

Method Detail

getArea

int getArea()
Get the area of this form rounded to closest integer.

Returns:
the computed area.

compareTo

int compareTo(GeometricalForm f)
The method compareTo compares the area of the forms to decide if the given geometrical form is less or greater than this object. If they have the same area, the perimeter decides.

Specified by:
compareTo in interface java.lang.Comparable<GeometricalForm>
Parameters:
f - The geometrical form to compare with.
Returns:
An integer smaller than 0 if this form is smaller than the form given as argument, 0 if the sizes are equal, and a positive integer otherwise.

fill

void fill(java.awt.Graphics g)
Fill the forms area at the forms position with the forms color.

Parameters:
g - A graphic pen to draw with.

getColor

java.awt.Color getColor()
Get the colour of this form.

Returns:
the colour of this form.

getWidth

int getWidth()
Get the width of the surrounding rectangle of this form.

Returns:
the width.

getHeight

int getHeight()
Get the height of the surrounding rectangle of this form.

Returns:
the x coordinate.

getX

int getX()
Get the x coordinate of the position of this form.

Returns:
the x coordinate.

getY

int getY()
Get the y coordinate of the position of this form.

Returns:
the y coordinate.

move

void move(int dx,
          int dy)
          throws IllegalPositionException
Move the form the given distances. Check if the new coordinates are legal and if they are, set the position to the new coordinates. Otherwise an IllegalPositionException is thrown. Origo is (0,0) and only positive coordinates are legal.

Parameters:
dx - move the form dx points to the right.
dy - move the form dy points down.
Throws:
IllegalPositionException - if any coordinate becomes negative.

getPerimeter

int getPerimeter()
Get the perimeter of this form rounded to closest integer.

Returns:
the computed perimeter.

place

void place(int x,
           int y)
           throws IllegalPositionException
Place the form on given coordinates. Check if the coordinates are legal. Origo is (0,0) and only positive coordinates are legal. If they are legal, update the position with the new coordinates. Otherwise an IllegalPositionException is thrown.

Parameters:
x - Distance right from origo.
y - Distance down from origo.
Throws:
IllegalPositionException - if any coordinate is negative.
IllegalPositionException