com.ajc.esim.core
Class Charge

java.lang.Object
  extended by com.ajc.esim.core.Charge
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable
Direct Known Subclasses:
LineCharge, PointCharge

public abstract class Charge
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

Defines a basic charge, stores location, shape and charge.

See Also:
sci.core.PointCharge, sci.core.LineCharge, Serialized Form

Nested Class Summary
static class Charge.ChargeType
          ChargeType of Charge.
 
Field Summary
 boolean isSel
          true if this is selected in the MainWindow window
protected  java.awt.Shape myShape
          Shape for drawing, used by paint, must be initialized by implementing sub-classes
 
Constructor Summary
Charge()
          Default Constructor
Charge(double x, double y, double c)
          Location and Charge constructor
 
Method Summary
 boolean checkClick(java.awt.event.MouseEvent e)
          Checks to see if this was clicked on.
 int compareTo(java.lang.Object obj)
          Compares this to another charge by comparing charge values
 void drawOutline(java.awt.Graphics g)
          Draws the shape.
 double getCharge()
          Returns the charge of this Charge object.
 java.lang.String getChargeText()
          Gets the charge in text form.
 double getHeight()
          Gets the height of the charge, default is 1/2 of getSize(), can be overridden
 double getLength()
          Gets the length of the charge, default is 1/2 of getSize(), can be overridden
 int getPaintX()
          Gets the X Location as used for painting
 int getPaintY()
          Gets the Y Location as used for painting
 double getSize()
          Size of charge for painting, currently set at 16.
 Charge.ChargeType getType()
           
 double getX()
           
 double getY()
           
abstract  boolean isInside(double x, double y)
          Needs to be overridden by implementing classes
abstract  void paint(java.awt.Graphics g)
          Paint method, to be overridden by implementing classes
abstract  void reBuildShape()
          Builder for shape object, to be overridden by implementing classes
 void setCharge(double charge)
           
protected  void setType(Charge.ChargeType type)
           
 void setX(double X)
           
 void setY(double Y)
           
 java.lang.String toStringShort()
          A shorter version of toString();
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isSel

public boolean isSel
true if this is selected in the MainWindow window


myShape

protected java.awt.Shape myShape
Shape for drawing, used by paint, must be initialized by implementing sub-classes

Constructor Detail

Charge

public Charge()
Default Constructor


Charge

public Charge(double x,
              double y,
              double c)
Location and Charge constructor

Parameters:
x - X Location (in pixels)
y - Y Location (in pixels)
c - charger (in columbs)
Method Detail

checkClick

public boolean checkClick(java.awt.event.MouseEvent e)
Checks to see if this was clicked on.

Parameters:
e - MouseEvent, passed from Launcher.win
Returns:
true if moused clicked on this, otherwise, false

compareTo

public int compareTo(java.lang.Object obj)
Compares this to another charge by comparing charge values

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - Object, must be type Charge
Returns:
difference in charges

drawOutline

public void drawOutline(java.awt.Graphics g)
Draws the shape. For use while dragging the charge

Parameters:
g - Graphics for painting.

getCharge

public double getCharge()
Returns the charge of this Charge object.

Returns:
Returns the electric charge value.

getChargeText

public java.lang.String getChargeText()
Gets the charge in text form.

Returns:
String formatted for display on screen.

getHeight

public double getHeight()
Gets the height of the charge, default is 1/2 of getSize(), can be overridden

Returns:
double height
See Also:
getSize()

getLength

public double getLength()
Gets the length of the charge, default is 1/2 of getSize(), can be overridden

Returns:
double length
See Also:
getSize()

getPaintX

public int getPaintX()
Gets the X Location as used for painting

Returns:
int, x location in pixels

getPaintY

public int getPaintY()
Gets the Y Location as used for painting

Returns:
int, y location in pixels

getSize

public double getSize()
Size of charge for painting, currently set at 16.

Returns:
double, size of charge

getType

public Charge.ChargeType getType()
Returns:
Returns the type of this charge.

getX

public double getX()
Returns:
Returns the x location.

getY

public double getY()
Returns:
Returns the y location.

isInside

public abstract boolean isInside(double x,
                                 double y)
Needs to be overridden by implementing classes

Parameters:
x - X location of point to check
y - Y location of point to check
Returns:
boolean True if point (X,Y) is covered by the charge when displayed on screen

paint

public abstract void paint(java.awt.Graphics g)
Paint method, to be overridden by implementing classes

Parameters:
g - Graphics object for painting

reBuildShape

public abstract void reBuildShape()
Builder for shape object, to be overridden by implementing classes

See Also:
myShape

setCharge

public void setCharge(double charge)
Parameters:
charge - sets charge value

setX

public void setX(double X)
Parameters:
X - sets the x location value min val of -1600, max val of 1600

setY

public void setY(double Y)
Parameters:
Y - sets the y location value and rebuilds the shape min val of -1600, max val of 1600

toStringShort

public java.lang.String toStringShort()
A shorter version of toString();

Returns:
String

setType

protected void setType(Charge.ChargeType type)
Parameters:
type - The type to set.