fluids
Class Tank

java.lang.Object
  extended by objectdraw.ObjectDrawObject
      extended by objectdraw.ObjectDrawShape
          extended by objectdraw.ObjectDrawRectangularShape
              extended by objectdraw.FramedRect
                  extended by fluids.FluidContainer
                      extended by fluids.Tank
All Implemented Interfaces:
Dependent, Drawable2DInterface, DrawableInterface, DrawableStrokeInterface, LocatableInterface, Resizable2DInterface

public class Tank
extends FluidContainer

A Tank represents a container that can fill up with liquid. The amount of liquid can be measured in two ways: the volume, in gallons, and the water level, the y coordinate on the screen of the surface of the liquid. For completeness, it permits the volume to be negative, but negative volume shows up in a different color (red, by default) to show that it is negative.

Author:
Russell Zahniser (russell@zahniser.net)

Field Summary
 
Fields inherited from interface objectdraw.DrawableStrokeInterface
CLICK_SIZE, DEFAULT_STROKE
 
Constructor Summary
Tank(String name, Background background)
          Create a new Tank.
 
Method Summary
 double getCapacity()
          Get the maximum volume that this tank can hold
 double getVolume()
          Get the volume of liquid present in this tank.
 double getWaterLevel()
          Get the water level in this tank.
 void setVolume(double v)
          Set the volume of liquid in this Tank.
 void setWaterLevel(double level)
          Set the water level of this tank.
 
Methods inherited from class fluids.FluidContainer
contains, getBackground, getNegativeColor, removeFromCanvas, setColor, setNegativeColor
 
Methods inherited from class objectdraw.FramedRect
addToCanvas, getCanvas, getColor, getDoubleHeight, getDoubleWidth, getDoubleX, getDoubleY, getHeight, getLineWidth, getLocation, getStroke, getWidth, getX, getY, hide, isHidden, makeShape, move, moveTo, moveTo, overlaps, sendBackward, sendForward, sendToBack, sendToFront, setHeight, setLineWidth, setSize, setStroke, setWidth, show, toString
 
Methods inherited from class objectdraw.ObjectDrawRectangularShape
getBounds
 
Methods inherited from class objectdraw.ObjectDrawShape
clearCanvas, draw, draw, getDrawables, getShape, removeCanvas, setMyShape, update
 
Methods inherited from class objectdraw.ObjectDrawObject
deferUpdates, depend, runUpdates, undepend
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface objectdraw.DrawableInterface
draw, getShape
 

Constructor Detail

Tank

public Tank(String name,
            Background background)
Create a new Tank. The dimensions of the tank will be set to reflect the area of the image where this tank's water may appear, and contains() will return true only for points within the liquid area of this tank.

Parameters:
name - Name of .png file to load from the model
background - Background which knows which model to load the image file from, and on which the water in this Tank will be drawn.
Method Detail

getCapacity

public double getCapacity()
Get the maximum volume that this tank can hold

Returns:
the maximum volume this tank can hold, in gallons

getVolume

public double getVolume()
Get the volume of liquid present in this tank.

Returns:
The volume in this tank, in gallons

getWaterLevel

public double getWaterLevel()
Get the water level in this tank. This will be the y coordinate on the screen of the water surface in the tank, and should be between tank.getY() (where volume = capacity) and tank.getY() + tank.getHeight() (where volume = 0), assuming the volume is positive. If the volume is negative, a water level below the bottom of the tank will be returned, calculated as if the tank were mirrored over its bottom edge.

Returns:
the y coordinate of this tank's water surface

setVolume

public void setVolume(double v)
Set the volume of liquid in this Tank. If the volume is greater than the capacity, or less than the negative of the capacity, the tank may overflow into the background.

Parameters:
v - new volume, in gallons

setWaterLevel

public void setWaterLevel(double level)
Set the water level of this tank. If the level provided is above the top of the tank, the tank will be set to be completely full, but will not overflow. If the water level is below the bottom of the tank, the tank will be given a negative volume.

Parameters:
level - New water level