Class InteractiveShape

java.lang.Object
org.opensourcephysics.display.AbstractInteractive
org.opensourcephysics.display.InteractiveShape
All Implemented Interfaces:
Drawable, Interactive, Measurable
Direct Known Subclasses:
BoundedShape, InteractiveImage, InteractiveTextLine

public class InteractiveShape extends AbstractInteractive implements Measurable
A shape that implements Interactive.
Version:
1.0
Author:
Wolfgang Christian
  • Field Details

    • edgeColor

      public Color edgeColor
    • shape

      protected Shape shape
    • shapeClass

      protected String shapeClass
    • theta

      protected double theta
    • width

      protected double width
    • height

      protected double height
    • xoff

      protected double xoff
    • yoff

      protected double yoff
    • pixelSized

      protected boolean pixelSized
    • toPixels

      protected AffineTransform toPixels
    • pixelPt

      protected Point2D.Double pixelPt
    • trIS

      protected AffineTransform trIS
  • Constructor Details

    • InteractiveShape

      public InteractiveShape(Shape s, double _x, double _y)
      Constructs an InteractiveShape with the given coordinates.
      Parameters:
      s -
      _x - coordinate
      _y - coordinate
    • InteractiveShape

      public InteractiveShape(Shape s)
      Constructs an InteractiveShape at the origin.
      Parameters:
      s -
  • Method Details

    • createEllipse

      public static InteractiveShape createEllipse(double x, double y, double w, double h)
      Creates an interactive ellipse.
      Parameters:
      x -
      y -
      w -
      h -
      Returns:
      InteractiveShape
    • createCircle

      public static InteractiveShape createCircle(double x, double y, double d)
      Creates an interactive circle.
      Parameters:
      x -
      y -
      d - the diameter
      Returns:
      the interactive circle
    • createRectangle

      public static InteractiveShape createRectangle(double x, double y, double w, double h)
      Creates an interactive rectangle.
      Parameters:
      x -
      y -
      w -
      h -
      Returns:
      the interactive rectangle
    • createTriangle

      public static InteractiveShape createTriangle(double x, double y, double b, double h)
      Creates an interactive triangle with a base parallel to the x axis.
      Parameters:
      x -
      y -
      b - base
      h - height
      Returns:
      the interactive triangle
    • createImage

      public static InteractiveShape createImage(Image image, double x, double y)
      Creates an interactive image.
      Parameters:
      x -
      y -
      image -
      Returns:
      the rectangle
    • createTextLine

      public static InteractiveShape createTextLine(double x, double y, String text)
      Creates an interactive image.
      Parameters:
      x -
      y -
      text -
      Returns:
      the rectangle
    • createArrow

      public static InteractiveShape createArrow(double x, double y, double w, double h)
      Creates an interactive arrow.
      Parameters:
      x -
      y -
      w - base
      h - height
      Returns:
      the arrow
    • createCenteredArrow

      public static InteractiveShape createCenteredArrow(double x, double y, double w, double h)
      Creates an interactive arrow.
      Parameters:
      x -
      y -
      w - base
      h - height
      Returns:
      the arrow
    • createSquare

      public static InteractiveShape createSquare(double x, double y, double w)
      Creates an interactive square.
      Parameters:
      x -
      y -
      w -
      Returns:
      the interactive square
    • transform

      public void transform(AffineTransform transformation)
      Transforms the shape.
      Parameters:
      transformation - AffineTransform
    • draw

      public void draw(DrawingPanel panel, Graphics g)
      Draws the shape.
      Specified by:
      draw in interface Drawable
      Specified by:
      draw in class AbstractInteractive
      Parameters:
      panel - the drawing panel
      g - the graphics context
    • contains

      public boolean contains(double x, double y)
      Tests if the specified coordinates are inside the boundary of the Shape.
      Parameters:
      x -
      y -
      Returns:
      true if the specified coordinates are inside the Shape boundary; false otherwise.
    • getShape

      public Shape getShape()
      Gets the Java shape that is being drawn.
      Returns:
      the shape
    • tranform

      public void tranform(double[][] mat)
      Transforms the shape using the given matrix.
      Parameters:
      mat - double[][]
    • isInside

      public boolean isInside(DrawingPanel panel, int xpix, int ypix)
      Determines if the shape is enabled and if the given pixel coordinates are within the shape.
      Specified by:
      isInside in class AbstractInteractive
      Parameters:
      panel - DrawingPanel
      xpix - int
      ypix - int
      Returns:
      boolean
    • setMarkerColor

      public void setMarkerColor(Color _fillColor, Color _edgeColor)
      Sets the shape's drawing colors. The error bar color is set equal to the edge color.
      Parameters:
      _fillColor -
      _edgeColor -
    • setTheta

      public void setTheta(double theta)
      Sets the rotation angle in radians.
      Parameters:
      theta - the new angle
    • setPixelSized

      public void setPixelSized(boolean enable)
      Sets the pixelSized flag. Pixel sized shapes use pixels for width and height.
      Parameters:
      enable - boolean
    • getWidth

      public double getWidth()
      Gets the width of this shape.
      Returns:
      double
    • setWidth

      public void setWidth(double width)
      Sets the width of the shape to the given value.
      Parameters:
      width - double
    • getHeight

      public double getHeight()
      Gets the height of this shape.
      Returns:
      double
    • setHeight

      public void setHeight(double height)
      Sets the height of the shape to the given value.
      Parameters:
      height - double
    • setOffset

      public void setOffset(double xoffset, double yoffset)
      Sets the drawing offset; Fixed size shapes cannot be offset.
      Parameters:
      xoffset - double
      yoffset - double
    • setXY

      public void setXY(double _x, double _y)
      Sets the x and y coordinates.
      Specified by:
      setXY in interface Interactive
      Overrides:
      setXY in class AbstractInteractive
      Parameters:
      _x -
      _y -
    • setX

      public void setX(double _x)
      Sets the x coordinate.
      Specified by:
      setX in interface Interactive
      Overrides:
      setX in class AbstractInteractive
      Parameters:
      _x -
    • setY

      public void setY(double _y)
      Sets the y coordinate.
      Specified by:
      setY in interface Interactive
      Overrides:
      setY in class AbstractInteractive
      Parameters:
      _y -
    • toString

      public String toString()
      Gets a description of this object.
      Overrides:
      toString in class Object
      Returns:
      String
    • setMeasured

      public void setMeasured(boolean _enableMeasure)
      Enables the measured flag so that this arrow effects the scale of a drawing panel.
    • isMeasured

      public boolean isMeasured()
      Determines if this circle should effect the scale of a drawing panel.
      Specified by:
      isMeasured in interface Measurable
      Overrides:
      isMeasured in class AbstractInteractive
      Returns:
      minimum
    • getXMin

      public double getXMin()
      Implements measurable by getting the x center of the circle.
      Specified by:
      getXMin in interface Measurable
      Overrides:
      getXMin in class AbstractInteractive
      Returns:
      minimum
    • getXMax

      public double getXMax()
      Implements measurable by getting the x center of the circle.
      Specified by:
      getXMax in interface Measurable
      Overrides:
      getXMax in class AbstractInteractive
      Returns:
      maximum
    • getYMin

      public double getYMin()
      Implements measurable by getting the y center of the circle.
      Specified by:
      getYMin in interface Measurable
      Overrides:
      getYMin in class AbstractInteractive
      Returns:
      minimum
    • getYMax

      public double getYMax()
      Implements measurable by getting the y center of the circle.
      Specified by:
      getYMax in interface Measurable
      Overrides:
      getYMax in class AbstractInteractive
      Returns:
      maximum
    • getLoader

      public static XML.ObjectLoader getLoader()
      Gets the XML object loader for this class.
      Returns:
      ObjectLoader
    • getPixelPt

      protected void getPixelPt(DrawingPanel panel)
    • getRotateInstance

      protected AffineTransform getRotateInstance(double theta)
    • getRotateInstance

      protected AffineTransform getRotateInstance(double theta, double x, double y)
    • getScaleInstance

      protected AffineTransform getScaleInstance(double sx, double sy)
    • getTranslateInstance

      protected AffineTransform getTranslateInstance(double tx, double ty)