org.opensourcephysics.display
Class InteractiveShape

java.lang.Object
  extended by org.opensourcephysics.display.AbstractInteractive
      extended by 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

Nested Class Summary
protected static class InteractiveShape.InteractiveShapeLoader
          A class to save and load InteractiveShape in an XMLControl.
 
Field Summary
 java.awt.Color edgeColor
           
protected  double height
           
protected  boolean pixelSized
           
protected  java.awt.Shape shape
           
protected  java.lang.String shapeClass
           
protected  double theta
           
protected  double width
           
protected  double xoff
           
protected  double yoff
           
 
Fields inherited from class org.opensourcephysics.display.AbstractInteractive
color, x, y
 
Constructor Summary
InteractiveShape(java.awt.Shape s)
          Constructs an InteractiveShape at the origin.
InteractiveShape(java.awt.Shape s, double _x, double _y)
          Constructs an InteractiveShape with the given coordinates.
 
Method Summary
 boolean contains(double x, double y)
          Tests if the specified coordinates are inside the boundary of the Shape.
static InteractiveShape createArrow(double x, double y, double w, double h)
          Creates an interactive arrow.
static InteractiveShape createCenteredArrow(double x, double y, double w, double h)
          Creates an interactive arrow.
static InteractiveShape createCircle(double x, double y, double d)
          Creates an interactive circle.
static InteractiveShape createEllipse(double x, double y, double w, double h)
          Creates an interactive ellipse.
static InteractiveShape createImage(java.awt.Image image, double x, double y)
          Creates an interactive image.
static InteractiveShape createRectangle(double x, double y, double w, double h)
          Creates an interactive rectangle.
static InteractiveShape createSquare(double x, double y, double w)
          Creates an interactive square.
static InteractiveShape createTextLine(double x, double y, java.lang.String text)
          Creates an interactive image.
static InteractiveShape createTriangle(double x, double y, double b, double h)
          Creates an interactive triangle with a base parallel to the x axis.
 void draw(DrawingPanel panel, java.awt.Graphics g)
          Draws the shape.
 double getHeight()
          Gets the height of this shape.
static XML.ObjectLoader getLoader()
          Gets the XML object loader for this class.
 java.awt.Shape getShape()
          Gets the Java shape that is being drawn.
 double getWidth()
          Gets the width of this shape.
 double getXMax()
          Implements measurable by getting the x center of the circle.
 double getXMin()
          Implements measurable by getting the x center of the circle.
 double getYMax()
          Implements measurable by getting the y center of the circle.
 double getYMin()
          Implements measurable by getting the y center of the circle.
 boolean isInside(DrawingPanel panel, int xpix, int ypix)
          Determines if the shape is enabled and if the given pixel coordinates are within the shape.
 boolean isMeasured()
          Determines if this circle should effect the scale of a drawing panel.
 void setHeight(double height)
          Sets the height of the shape to the given value.
 void setMarkerColor(java.awt.Color _fillColor, java.awt.Color _edgeColor)
          Sets the shape's drawing colors.
 void setMeasured(boolean _enableMeasure)
          Enables the measured flag so that this arrow effects the scale of a drawing panel.
 void setOffset(double xoffset, double yoffset)
          Sets the drawing offset; Fixed size shapes cannot be offset.
 void setPixelSized(boolean enable)
          Sets the pixelSized flag.
 void setTheta(double theta)
          Sets the rotation angle in radians.
 void setWidth(double width)
          Sets the width of the shape to the given value.
 void setX(double _x)
          Sets the x coordinate.
 void setXY(double _x, double _y)
          Sets the x and y coordinates.
 void setY(double _y)
          Sets the y coordinate.
 java.lang.String toString()
          Gets a description of this object.
 void tranform(double[][] mat)
          Transforms the shape using the given matrix.
 void transform(java.awt.geom.AffineTransform transformation)
          Transforms the shape.
 
Methods inherited from class org.opensourcephysics.display.AbstractInteractive
findInteractive, getX, getY, isEnabled, setEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

edgeColor

public java.awt.Color edgeColor

shape

protected java.awt.Shape shape

shapeClass

protected java.lang.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
Constructor Detail

InteractiveShape

public InteractiveShape(java.awt.Shape s,
                        double _x,
                        double _y)
Constructs an InteractiveShape with the given coordinates.

Parameters:
s -
_x - coordinate
_y - coordinate

InteractiveShape

public InteractiveShape(java.awt.Shape s)
Constructs an InteractiveShape at the origin.

Parameters:
s -
Method Detail

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(java.awt.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,
                                              java.lang.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(java.awt.geom.AffineTransform transformation)
Transforms the shape.

Parameters:
transformation - AffineTransform

draw

public void draw(DrawingPanel panel,
                 java.awt.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 java.awt.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(java.awt.Color _fillColor,
                           java.awt.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 java.lang.String toString()
Gets a description of this object.

Overrides:
toString in class java.lang.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