Class Spring

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

public class Spring extends Object implements Measurable
Draws a coil spring in a drawing panel.
Version:
1.0
Author:
F. Esquembre, W. Christian
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Color
     
    protected Stroke
     
    protected boolean
     
    protected int
     
    protected int
     
    protected float
    The radius of the spring (normal to its direction)
    protected float
     
    protected float
     
    protected float
     
    protected boolean
     
    protected boolean
     
    protected float
     
    protected float
     
    protected boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a 0.1 radius Spring.
    Spring(double _radius)
    Special constructor that allows to specify the radius of the spring
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Implementation of Drawable.
     
     
    int
     
    int
     
    double
    Get the radius of the spring.
    double
    Gets the X size of the spring
    double
    Gets the Y size of the spring
    double
    Gets the X position of the origin of the spring
    double
    Gets the maximum x needed to draw this object.
    double
    Gets the minimum x needed to draw this object.
    double
    Gets the Y position of the origin of the spring
    double
    Gets the maximum y needed to draw this object.
    double
    Gets the minimum y needed to draw this object.
    boolean
    Determines if information is available to set min/max values.
    boolean
     
    void
     
    void
     
    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

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods 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 radius
      The radius of the spring (normal to its direction)
    • solenoid

      protected float solenoid
    • edgeColor

      protected Color edgeColor
    • edgeStroke

      protected Stroke 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 - 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(Color color)
    • getEdgeColor

      public Color getEdgeColor()
    • setEdgeStroke

      public void setEdgeStroke(Stroke stroke)
    • getEdgeStroke

      public 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, 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