org.opensourcephysics.display
Class Spring

java.lang.Object
  extended by org.opensourcephysics.display.Spring
All Implemented Interfaces:
Drawable, Measurable

public class Spring
extends java.lang.Object
implements Measurable

Draws a coil spring in a drawing panel.

Version:
1.0
Author:
F. Esquembre, W. Christian

Constructor Summary
Spring()
          Constructs a 0.1 radius Spring.
Spring(double _radius)
          Special constructor that allows to specify the radius of the spring
 
Method Summary
 void draw(DrawingPanel panel, java.awt.Graphics g)
          Implementation of Drawable.
 java.awt.Color getEdgeColor()
           
 java.awt.Stroke getEdgeStroke()
           
 int getLoops()
           
 int getPointsPerLoop()
           
 double getRadius()
          Get the radius of the spring.
 double getSizeX()
          Gets the X size of the spring
 double getSizeY()
          Gets the Y size of the spring
 double getX()
          Gets the X position of the origin of the spring
 double getXMax()
          Gets the maximum x needed to draw this object.
 double getXMin()
          Gets the minimum x needed to draw this object.
 double getY()
          Gets the Y position of the origin of the spring
 double getYMax()
          Gets the maximum y needed to draw this object.
 double getYMin()
          Gets the minimum y needed to draw this object.
 boolean isMeasured()
          Determines if information is available to set min/max values.
 boolean isVisible()
           
 void setEdgeColor(java.awt.Color color)
           
 void setEdgeStroke(java.awt.Stroke stroke)
           
 void setRadius(double radius)
          Set the radius of the spring.
 void setResolution(int nLoops, int nPointsPerLoop)
          Sets the number of spires and points per spire used to draw the spring
 void setSizeX(double sizeX)
          Sets the X size of the spring
 void setSizeXY(double sizeX, double sizeY)
          Sets the size of the spring
 void setSizeY(double sizeY)
          Sets the Y size of the spring
 void setSolenoid(double factor)
          Sets a double factor that makes the spring look like a solenoid by causing the spires to go back and forth Default is 0, which makes a standard spring
 void setThinExtremes(boolean thin)
          Whether the spring should show thin extremes.
 void setVisible(boolean visible)
          Sets the visibiliby of the spring
 void setX(double x)
          Sets the X position of the origin of the spring
 void setXY(double x, double y)
          Sets the position of the origin of the spring
 void setY(double y)
          Sets the Y position of the origin of the spring
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Spring

public Spring()
Constructs a 0.1 radius Spring.


Spring

public Spring(double _radius)
Special constructor that allows to specify the radius of the spring

Parameters:
_radius - the radius of the spring (normal to its direction)
Method Detail

setX

public void setX(double x)
Sets the X position of the origin of the spring

Parameters:
x - double

getX

public double getX()
Gets the X position of the origin of the spring

Returns:
double

setY

public void setY(double y)
Sets the Y position of the origin of the spring

Parameters:
y - double

getY

public double getY()
Gets the Y position of the origin of the spring

Returns:
double

setXY

public void setXY(double x,
                  double y)
Sets the position of the origin of the spring

Parameters:
x - double
y - double

setSizeX

public void setSizeX(double sizeX)
Sets the X size of the spring

Parameters:
sizeX - double

getSizeX

public double getSizeX()
Gets the X size of the spring

Returns:
double

setSizeY

public void setSizeY(double sizeY)
Sets the Y size of the spring

Parameters:
sizeY - double

getSizeY

public double getSizeY()
Gets the Y size of the spring

Returns:
double

setSizeXY

public void setSizeXY(double sizeX,
                      double sizeY)
Sets the size of the spring

Parameters:
sizeX - double
sizeY - double

setRadius

public void setRadius(double radius)
Set the radius of the spring.

Parameters:
_radius - the radius of the spring (normal to its direction)

getRadius

public double getRadius()
Get the radius of the spring.


setVisible

public void setVisible(boolean visible)
Sets the visibiliby of the spring

Parameters:
_visible - boolean

isVisible

public boolean isVisible()

setEdgeColor

public void setEdgeColor(java.awt.Color color)

getEdgeColor

public java.awt.Color getEdgeColor()

setEdgeStroke

public void setEdgeStroke(java.awt.Stroke stroke)

getEdgeStroke

public java.awt.Stroke getEdgeStroke()

setResolution

public void setResolution(int nLoops,
                          int nPointsPerLoop)
Sets the number of spires and points per spire used to draw the spring

Parameters:
nLoops - int
nPointsPerLoop - int

getLoops

public int getLoops()

getPointsPerLoop

public int getPointsPerLoop()

setSolenoid

public void setSolenoid(double factor)
Sets a double factor that makes the spring look like a solenoid by causing the spires to go back and forth Default is 0, which makes a standard spring

Parameters:
factor - double

setThinExtremes

public void setThinExtremes(boolean thin)
Whether the spring should show thin extremes. Default is true

Parameters:
thin - boolean

draw

public void draw(DrawingPanel panel,
                 java.awt.Graphics g)
Implementation of Drawable.

Specified by:
draw in interface Drawable
Parameters:
panel - DrawingPanel
g - Graphics

isMeasured

public boolean isMeasured()
Description copied from interface: Measurable
Determines if information is available to set min/max values. Objects that store data should return false if data is null.

Specified by:
isMeasured in interface Measurable
Returns:
true if min/max values are valid

getXMin

public double getXMin()
Description copied from interface: Measurable
Gets the minimum x needed to draw this object.

Specified by:
getXMin in interface Measurable
Returns:
minimum

getXMax

public double getXMax()
Description copied from interface: Measurable
Gets the maximum x needed to draw this object.

Specified by:
getXMax in interface Measurable
Returns:
maximum

getYMin

public double getYMin()
Description copied from interface: Measurable
Gets the minimum y needed to draw this object.

Specified by:
getYMin in interface Measurable
Returns:
minimum

getYMax

public double getYMax()
Description copied from interface: Measurable
Gets the maximum y needed to draw this object.

Specified by:
getYMax in interface Measurable
Returns:
minimum