ca.mcgill.cim.sre.cv4hci
Class Brick

java.lang.Object
  extended by ca.mcgill.cim.sre.cv4hci.Brick

public class Brick
extends java.lang.Object

Brick is a class visually representing a "brick" and its state. A brick has an x,y position, an angle, a state indicating whether it's "up" or not, it's shape (usually a rectangle) and its area. It also keeps in memory its previous state so it can do more interesting stuff (translation, etc.) when the doStuffWithSelectedShape method is called.

Note: This class is not optimized for object-oriented reuse, it is only a demo.

Since:
1.0

Field Summary
 double angle
          The current angle of the brick (in radian).
 double area
          The current area of the shape.
 boolean isUp
          The current "up" state of the brick.
 TransformedShape myShape
          The shape used to draw (with Java2D) the brick.
 double pickUpArea
          The update method uses the pickUpArea value to know when a brick is considered "up".
 java.awt.geom.Point2D position
          The current position of the brick.
 double previousAngle
          The previous angle of the brick (in radian).
 java.awt.geom.Point2D previousPosition
          The previous position of the brick.
 double putDownArea
          The update method uses the putDownArea value to know when a brick is considered "down".
 TransformedShape selectedShape
          The currently selected shape used by the doStuffWithSelectedShape method.
 boolean wasUp
          The previous up" state of the brick.
 
Constructor Summary
Brick()
          Brick constructor.
Brick(int width, int height)
          Brick constructor specifiying the width and the height (in pixels) of the shape (rectangle) to be drawn.
 
Method Summary
 void doStuffWithSelectedShape(Brick theOtherBrick)
          Manipulates the selectedShape according to the the movement of the brick.
 double getHeight()
          Gets the height of the shape of this brick.
 java.awt.geom.AffineTransform getUpdateTransform()
          Returns the necessary transform (rotation about the brick position then translation) to move a shape according to the new state of this brick minus its previous state
 double getWidth()
          Gets the width of the shape of this brick.
 void pickUpOrDropShape(java.util.LinkedList<TransformedShape> shapeList, java.util.LinkedList<TransformedShape> shapeMenuList)
          Picks up or drops shapes if wasPickedUp() is true.
 void setSize(int width, int height)
          Sets the width and the height of the shape (rectangle) to be drawn.
 void update(java.awt.geom.Point2D center, java.awt.geom.Dimension2D size, double angle, java.awt.Color color)
          Updates the current state of this brick with new information.
 boolean wasPickedUp()
          Returns true if !wasUp && isUp, that is if the brick was just picked up
 boolean wasPutDown()
          Returns true if wasUp && !isUp, that is if the brick was just put down
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

position

public java.awt.geom.Point2D position
The current position of the brick.


previousPosition

public java.awt.geom.Point2D previousPosition
The previous position of the brick.


previousAngle

public double previousAngle
The previous angle of the brick (in radian).


angle

public double angle
The current angle of the brick (in radian).


isUp

public boolean isUp
The current "up" state of the brick.


wasUp

public boolean wasUp
The previous up" state of the brick.


myShape

public TransformedShape myShape
The shape used to draw (with Java2D) the brick.


selectedShape

public TransformedShape selectedShape
The currently selected shape used by the doStuffWithSelectedShape method.


area

public double area
The current area of the shape. Used along with the pickUpArea and putDownArea values to set the "up" state


pickUpArea

public double pickUpArea
The update method uses the pickUpArea value to know when a brick is considered "up".


putDownArea

public double putDownArea
The update method uses the putDownArea value to know when a brick is considered "down".

Constructor Detail

Brick

public Brick()
Brick constructor.


Brick

public Brick(int width,
             int height)
Brick constructor specifiying the width and the height (in pixels) of the shape (rectangle) to be drawn.

Method Detail

setSize

public void setSize(int width,
                    int height)
Sets the width and the height of the shape (rectangle) to be drawn.

Parameters:
width - width in pixels
height - height in pixels

getWidth

public double getWidth()
Gets the width of the shape of this brick.

Returns:
the width of the shape in pixels

getHeight

public double getHeight()
Gets the height of the shape of this brick.

Returns:
the height of the shape in pixels

update

public void update(java.awt.geom.Point2D center,
                   java.awt.geom.Dimension2D size,
                   double angle,
                   java.awt.Color color)
Updates the current state of this brick with new information. Apart from the center, the size, the angle and the color, the "up" state is updated using the pickUpArea and putDownArea values by comparing them to size.wight*size.height. The previous state is also saved for use in the doStuffWithSelectedShape and other methods.

The size is only used for comparison with pickUpArea and putDownArea. It is NOT used for the size of the rectangular shape representing this brick in the drawing. To set this size, use the setSize method.

Parameters:
center - new x,y position of the brick in pixels
size - new width and height in pixels
angle - new angle in radian
color - new color

wasPickedUp

public boolean wasPickedUp()
Returns true if !wasUp && isUp, that is if the brick was just picked up

Returns:
true if the brick was just picked up

wasPutDown

public boolean wasPutDown()
Returns true if wasUp && !isUp, that is if the brick was just put down

Returns:
true if the brick was just put down

getUpdateTransform

public java.awt.geom.AffineTransform getUpdateTransform()
Returns the necessary transform (rotation about the brick position then translation) to move a shape according to the new state of this brick minus its previous state

Returns:
the transform related to the last update (rotation + translation)

pickUpOrDropShape

public void pickUpOrDropShape(java.util.LinkedList<TransformedShape> shapeList,
                              java.util.LinkedList<TransformedShape> shapeMenuList)
Picks up or drops shapes if wasPickedUp() is true. If wasPickedUp() is true, and selectedShape is null, checks if one of the shapes in shapeList or shapeMenuList is under this brick, and if so keeps a reference as selectedShape. If the shape is in shapeMenuList, makes a clone instead, and adds it to shapeList. If selectedShape is not null, drops that shape instead of selecting one.

Parameters:
shapeList - a list of working shapes
shapeMenuList - a list of shapes used as a menu, to produce working shapes

doStuffWithSelectedShape

public void doStuffWithSelectedShape(Brick theOtherBrick)
Manipulates the selectedShape according to the the movement of the brick. If the selectedShape of theOtherBrick is the same, then applies scaling to the selectedShape according to the movement of the brick. Otherwise, applies the rotation and translation returned by getUpdateTransform() to the selected shape.

Parameters:
theOtherBrick - the other brick used in concert with this one to do scaling