wheelsunh.users
Class Line

java.lang.Object
  extended by wheelsunh.etc.AbstractGraphic
      extended by wheelsunh.users.AbstractShape
          extended by wheelsunh.users.Shape
              extended by wheelsunh.users.Line
All Implemented Interfaces:
Colorable, CustomGraphic, Locatable, Rotatable, Sizeable

public class Line
extends Shape
implements Sizeable

Class that models a 2D line. Has methods allowing you to adjust the line's points, thickness, color, etc.


Field Summary
static int DEFAULT_LENGTH
           
 
Fields inherited from class wheelsunh.users.Shape
_c, _dp, _shape, DEFAULT_COLOR
 
Fields inherited from class wheelsunh.users.AbstractShape
_rot
 
Constructor Summary
Line()
          Creates a Line with default endpoints in the wheelsunh.users.Frame's DrawingPanel.
Line(DrawingPanel dp)
          Creates a Line with endpoints (0, 0) and (0, 0) in the specified DrawingPanel.
Line(DrawingPanel dp, int x1, int y1, int x2, int y2)
          Creates a Line with the specified endpoint coordinates in the specified DrawingPanel.
Line(DrawingPanel dp, java.awt.Point p1, java.awt.Point p2)
          Creates a Line with the specified endpoints in the specified DrawingPanel.
Line(int x1, int y1, int x2, int y2)
          Creates a Line with the specified coordinates in the wheelsunh.users.Frame's DrawingPanel.
Line(java.awt.Point p1, java.awt.Point p2)
          Creates a Line with the specified endpoints in the wheelsunh.users.Frame's DrawingPanel.
 
Method Summary
 void actualPaint(java.awt.Graphics2D g)
          Subclasses must define this to do the actual painting of the shape.
 java.awt.Rectangle getBounds()
          Returns the bounding rectangle of the line.
 int getHeight()
          Returns the Line's height.
 java.awt.Point getLocation()
          Returns the location of this Line's first point.
 java.awt.Point getP1()
          Returns the first endpoint.
 java.awt.Point getP2()
          Returns the second endpoint.
 java.awt.Dimension getSize()
          Returns the Line's size as an AWT Dimension.
 int getThickness()
          Returns the thickness of the stroke.
 int getWidth()
          Returns the Line's width.
 int getX1()
          Return the x coordinate of the first endpoint.
 int getX2()
          Return the x coordinate of the second endpoint.
 int getXLocation()
          Returns the x location of this Line's first point.
 int getY1()
          Returns the y coordinate of the first endpoint.
 int getY2()
          Returns the y coordinate of the second endpoint.
 int getYLocation()
          Returns the location of this Line's first point.
 void setLocation(int x, int y)
          Sets the location of this line such that its bounding box is located at (x, y)
 void setLocation(java.awt.Point p)
          Sets the location of this line such that its first point is located at the point p
 void setP1(int x, int y)
          Sets the coordinates of the first endpoint.
 void setP1(java.awt.Point p1)
          Set the first endpoint.
 void setP2(int x, int y)
          Sets the coordinates of the second endpoint.
 void setP2(java.awt.Point p2)
          Set the second endpoint.
 void setPoints(int x1, int y1, int x2, int y2)
          Sets the endpoints of the Line to the specified coordinates
 void setPoints(java.awt.Point p1, java.awt.Point p2)
          Sets the endpoints of the Line to the specified values.
 void setSize(java.awt.Dimension d)
          Sets the Line's size to the given Dimension.
 void setSize(int width, int height)
          Sets the Line's size to the given dimensions.
 void setThickness(int thickness)
          Sets the thickness of the stroke used to paint the line.
 
Methods inherited from class wheelsunh.users.Shape
contains, getColor, getRotation, hide, paint, setColor, setRotation, show
 
Methods inherited from class wheelsunh.users.AbstractShape
boundsIntersects, center, distance, getCenter, getCenterX, getCenterY, getIntersection, intersects, intersects, setCenter
 
Methods inherited from class wheelsunh.etc.AbstractGraphic
mouseClicked, mouseDragged, mousePressed, mouseReleased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LENGTH

public static final int DEFAULT_LENGTH
See Also:
Constant Field Values
Constructor Detail

Line

public Line()
Creates a Line with default endpoints in the wheelsunh.users.Frame's DrawingPanel.


Line

public Line(int x1,
            int y1,
            int x2,
            int y2)
Creates a Line with the specified coordinates in the wheelsunh.users.Frame's DrawingPanel.

Parameters:
x1 - the x value of the first endpoint
y1 - the y value of the first endpoint
x2 - the x value of the second endpoint
y2 - the y value of the second endpoint

Line

public Line(java.awt.Point p1,
            java.awt.Point p2)
Creates a Line with the specified endpoints in the wheelsunh.users.Frame's DrawingPanel.

Parameters:
p1 - the first endpoint
p2 - the second endpoint

Line

public Line(DrawingPanel dp)
Creates a Line with endpoints (0, 0) and (0, 0) in the specified DrawingPanel.


Line

public Line(DrawingPanel dp,
            int x1,
            int y1,
            int x2,
            int y2)
Creates a Line with the specified endpoint coordinates in the specified DrawingPanel.

Parameters:
dp - the DrawingPanel in which the line will be drawn
x1 - the x value of the first endpoint
y1 - the y value of the first endpoint
x2 - the x value of the second endpoint
y2 - the y value of the second endpoint

Line

public Line(DrawingPanel dp,
            java.awt.Point p1,
            java.awt.Point p2)
Creates a Line with the specified endpoints in the specified DrawingPanel.

Parameters:
dp - the DrawingPanel in which the line will be drawn
p1 - the first endpoint
p2 - the second endpoint
Method Detail

setPoints

public void setPoints(int x1,
                      int y1,
                      int x2,
                      int y2)
Sets the endpoints of the Line to the specified coordinates


setPoints

public void setPoints(java.awt.Point p1,
                      java.awt.Point p2)
Sets the endpoints of the Line to the specified values.


setP1

public void setP1(int x,
                  int y)
Sets the coordinates of the first endpoint.


setP1

public void setP1(java.awt.Point p1)
Set the first endpoint.


setP2

public void setP2(int x,
                  int y)
Sets the coordinates of the second endpoint.


setP2

public void setP2(java.awt.Point p2)
Set the second endpoint.


getP1

public java.awt.Point getP1()
Returns the first endpoint.


getX1

public int getX1()
Return the x coordinate of the first endpoint.


getY1

public int getY1()
Returns the y coordinate of the first endpoint.


getP2

public java.awt.Point getP2()
Returns the second endpoint.


getX2

public int getX2()
Return the x coordinate of the second endpoint.


getY2

public int getY2()
Returns the y coordinate of the second endpoint.


setThickness

public void setThickness(int thickness)
Sets the thickness of the stroke used to paint the line.


getThickness

public int getThickness()
Returns the thickness of the stroke.


getBounds

public java.awt.Rectangle getBounds()
Returns the bounding rectangle of the line.

Overrides:
getBounds in class Shape

actualPaint

public void actualPaint(java.awt.Graphics2D g)
Description copied from class: Shape
Subclasses must define this to do the actual painting of the shape. All calls to paint(java.awt.Graphics2D) will forward to this method.

Specified by:
actualPaint in class Shape
Parameters:
g - the instance of java.awt.Graphics2D that should be used to paint the shape

setLocation

public void setLocation(int x,
                        int y)
Sets the location of this line such that its bounding box is located at (x, y)

Specified by:
setLocation in interface Locatable
Specified by:
setLocation in class Shape

setLocation

public void setLocation(java.awt.Point p)
Sets the location of this line such that its first point is located at the point p

Specified by:
setLocation in interface Locatable
Specified by:
setLocation in class Shape

getLocation

public java.awt.Point getLocation()
Returns the location of this Line's first point.

Specified by:
getLocation in interface Locatable
Specified by:
getLocation in class Shape

getXLocation

public int getXLocation()
Returns the x location of this Line's first point.

Specified by:
getXLocation in interface Locatable
Specified by:
getXLocation in class Shape

getYLocation

public int getYLocation()
Returns the location of this Line's first point.

Specified by:
getYLocation in interface Locatable
Specified by:
getYLocation in class Shape

setSize

public void setSize(int width,
                    int height)
Sets the Line's size to the given dimensions.

Specified by:
setSize in interface Sizeable

setSize

public void setSize(java.awt.Dimension d)
Sets the Line's size to the given Dimension.

Specified by:
setSize in interface Sizeable

getSize

public java.awt.Dimension getSize()
Returns the Line's size as an AWT Dimension.

Specified by:
getSize in interface Sizeable

getWidth

public int getWidth()
Returns the Line's width.

Specified by:
getWidth in interface Sizeable
Specified by:
getWidth in class AbstractShape

getHeight

public int getHeight()
Returns the Line's height.

Specified by:
getHeight in interface Sizeable
Specified by:
getHeight in class AbstractShape