Package org.opensourcephysics.display
Class Spring
java.lang.Object
org.opensourcephysics.display.Spring
- All Implemented Interfaces:
Drawable,Measurable
Draws a coil spring in a drawing panel.
- Version:
- 1.0
- Author:
- F. Esquembre, W. Christian
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Colorprotected Strokeprotected booleanprotected intprotected intprotected floatThe radius of the spring (normal to its direction)protected floatprotected floatprotected floatprotected booleanprotected booleanprotected floatprotected floatprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddraw(DrawingPanel panel, Graphics g) Implementation of Drawable.intgetLoops()intdoubleGet the radius of the spring.doublegetSizeX()Gets the X size of the springdoublegetSizeY()Gets the Y size of the springdoublegetX()Gets the X position of the origin of the springdoublegetXMax()Gets the maximum x needed to draw this object.doublegetXMin()Gets the minimum x needed to draw this object.doublegetY()Gets the Y position of the origin of the springdoublegetYMax()Gets the maximum y needed to draw this object.doublegetYMin()Gets the minimum y needed to draw this object.booleanDetermines if information is available to set min/max values.booleanvoidsetEdgeColor(Color color) voidsetEdgeStroke(Stroke stroke) voidsetRadius(double radius) Set the radius of the spring.voidsetResolution(int nLoops, int nPointsPerLoop) Sets the number of spires and points per spire used to draw the springvoidsetSizeX(double sizeX) Sets the X size of the springvoidsetSizeXY(double sizeX, double sizeY) Sets the size of the springvoidsetSizeY(double sizeY) Sets the Y size of the springvoidsetSolenoid(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 springvoidsetThinExtremes(boolean thin) Whether the spring should show thin extremes.voidsetVisible(boolean visible) Sets the visibiliby of the springvoidsetX(double x) Sets the X position of the origin of the springvoidsetXY(double x, double y) Sets the position of the origin of the springvoidsetY(double y) Sets the Y position of the origin of the springMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opensourcephysics.display.Drawable
isInteractive
-
Field Details
-
thinExtremes
protected boolean thinExtremes -
visible
protected boolean visible -
loops
protected int loops -
pointsPerLoop
protected int pointsPerLoop -
x
protected float x -
y
protected float y -
sizex
protected float sizex -
sizey
protected float sizey -
radius
protected float radiusThe radius of the spring (normal to its direction) -
solenoid
protected float solenoid -
edgeColor
-
edgeStroke
-
hasChanged
protected boolean hasChanged -
zeroLength
protected boolean zeroLength
-
-
Constructor Details
-
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 Details
-
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- doubley- 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- doublesizeY- 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
-
getEdgeColor
-
setEdgeStroke
-
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- intnPointsPerLoop- 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
Implementation of Drawable. -
isMeasured
public boolean isMeasured()Description copied from interface:MeasurableDetermines if information is available to set min/max values. Objects that store data should return false if data is null.- Specified by:
isMeasuredin interfaceMeasurable- Returns:
- true if min/max values are valid
-
getXMin
public double getXMin()Description copied from interface:MeasurableGets the minimum x needed to draw this object.- Specified by:
getXMinin interfaceMeasurable- Returns:
- minimum
-
getXMax
public double getXMax()Description copied from interface:MeasurableGets the maximum x needed to draw this object.- Specified by:
getXMaxin interfaceMeasurable- Returns:
- maximum
-
getYMin
public double getYMin()Description copied from interface:MeasurableGets the minimum y needed to draw this object.- Specified by:
getYMinin interfaceMeasurable- Returns:
- minimum
-
getYMax
public double getYMax()Description copied from interface:MeasurableGets the maximum y needed to draw this object.- Specified by:
getYMaxin interfaceMeasurable- Returns:
- minimum
-