All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class primitives.machines.Machine

java.lang.Object
   |
   +----primitives.machines.Machine

public abstract class Machine
extends Object
implements MachineListener
An abstract class which is ancestor to all machines. The class defines the information on the machine's joints and anchors. Provide common methods shared by all machine objects.


Variable Index

 o anchors
The integer location of the anchors.
 o barLength
The length of the rigid bar.
 o bendStates
Each joint can take to bending positions.
 o d
The dimension of the rectangle the machine is being drawn in.
 o dAnchors
The array of the location of the machine's anchors.
 o dJoints
The array of the location of the machine's joints.
 o joints
The integer location of the joints.
 o tempJoints
stores the last joints locations for if restore is needed.

Constructor Index

 o Machine(int, int, Dimension)

Method Index

 o drawAnchors(Graphics)
Draws the anchors of this machine.
 o drawJoints(Graphics)
Draws the machine's joints.
 o drawLine(Graphics, Point, Point)
Draws a line between to locations.
 o finalize()
Sets object fields to null.
 o integrizeAnchors()
Rounds the location of the anchors to the nearest integer location.
 o redraw(Graphics)
Implementation of the MachineListener interface.
 o restorePoints()
Restores the location of the joints by setting its location to the locations saved in tempJoints.
 o rotateJoint(Coordinate, Coordinate, double)
rotates specified joint c2 around joint c1 in dalpha radians.
 o savePoints()
sets the tempJoints array to the current location of the dJoints array.
 o switchBend(Coordinate, Coordinate, Coordinate)
Returns the second possible location of of mid.
 o updatePoints(Coordinate[], ExtPoint[])
copies the locations of array of Coordinate to an array of ExtPoint.

Variables

 o dJoints
 protected Coordinate dJoints[]
The array of the location of the machine's joints.

 o dAnchors
 protected Coordinate dAnchors[]
The array of the location of the machine's anchors.

 o tempJoints
 protected Coordinate tempJoints[]
stores the last joints locations for if restore is needed.

 o anchors
 public ExtPoint anchors[]
The integer location of the anchors. Used in the calls to the Graphic methods.

 o joints
 public ExtPoint joints[]
The integer location of the joints. Used in the calls to the Graphic methods.

 o barLength
 public int barLength
The length of the rigid bar. All bars are presumed to be of same length. machines with differnt bar length should define its own fields.

 o bendStates
 public int bendStates[]
Each joint can take to bending positions. These values should be only 1 and -1.

 o d
 protected Dimension d
The dimension of the rectangle the machine is being drawn in.

Constructors

 o Machine
 public Machine(int joints,
                int anchors,
                Dimension d)
Parameters:
joints - number of joints in the machine.
anchors - number of anchor in the machine.
d - the dimension of the rectangle the machine should be drawn in.

Methods

 o finalize
 public void finalize() throws Throwable
Sets object fields to null.

Throws: Throwable
.
Overrides:
finalize in class Object
 o integrizeAnchors
 protected void integrizeAnchors()
Rounds the location of the anchors to the nearest integer location. Since anchors do not change there position, there real location should be integral.

 o savePoints
 protected void savePoints()
sets the tempJoints array to the current location of the dJoints array.

 o restorePoints
 protected void restorePoints()
Restores the location of the joints by setting its location to the locations saved in tempJoints.

 o drawAnchors
 protected void drawAnchors(Graphics g)
Draws the anchors of this machine.

Parameters:
g - the graphic context to draw on.
 o redraw
 public void redraw(Graphics g)
Implementation of the MachineListener interface. Draws the joints and anchors of the machine.

 o rotateJoint
 protected double rotateJoint(Coordinate c1,
                              Coordinate c2,
                              double dalpha)
rotates specified joint c2 around joint c1 in dalpha radians.

Parameters:
c1 - the joint at the origin.
c2 - the joint to rotate.
dalpha - the angle to rotata.
Returns:
the new angle between c1 and c2.
 o updatePoints
 protected static void updatePoints(Coordinate src[],
                                    ExtPoint dst[])
copies the locations of array of Coordinate to an array of ExtPoint. The locations are rounded to the nearest integer values.

Parameters:
src - the source.
dst - the destination array of Point.
See Also:
redraw
 o drawJoints
 protected void drawJoints(Graphics g)
Draws the machine's joints.

Parameters:
g - the graphic context to draw on.
 o drawLine
 public static void drawLine(Graphics g,
                             Point p1,
                             Point p2)
Draws a line between to locations. The color of the line should be set before calling this method.

Parameters:
g - the graphic context to draw on.
p1, - p2 the endpoints of the line.
 o switchBend
 protected static Coordinate switchBend(Coordinate c1,
                                        Coordinate c2,
                                        Coordinate mid) throws ArithmeticException
Returns the second possible location of of mid. mid is supposed to be an adjacent joint of c1 and c2.

Throws: ArithmeticException
never throws this exception.

All Packages  Class Hierarchy  This Package  Previous  Next  Index