Package org.opensourcephysics.display
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
A shape that implements Interactive.
- Version:
- 1.0
- Author:
- Wolfgang Christian
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA class to save and load InteractiveShape in an XMLControl. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected doubleprotected Point2D.Doubleprotected booleanprotected Shapeprotected Stringprotected doubleprotected AffineTransformprotected AffineTransformprotected doubleprotected doubleprotected doubleFields inherited from class org.opensourcephysics.display.AbstractInteractive
color, x, y -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an InteractiveShape at the origin.InteractiveShape(Shape s, double _x, double _y) Constructs an InteractiveShape with the given coordinates. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(double x, double y) Tests if the specified coordinates are inside the boundary of theShape.static InteractiveShapecreateArrow(double x, double y, double w, double h) Creates an interactive arrow.static InteractiveShapecreateCenteredArrow(double x, double y, double w, double h) Creates an interactive arrow.static InteractiveShapecreateCircle(double x, double y, double d) Creates an interactive circle.static InteractiveShapecreateEllipse(double x, double y, double w, double h) Creates an interactive ellipse.static InteractiveShapecreateImage(Image image, double x, double y) Creates an interactive image.static InteractiveShapecreateRectangle(double x, double y, double w, double h) Creates an interactive rectangle.static InteractiveShapecreateSquare(double x, double y, double w) Creates an interactive square.static InteractiveShapecreateTextLine(double x, double y, String text) Creates an interactive image.static InteractiveShapecreateTriangle(double x, double y, double b, double h) Creates an interactive triangle with a base parallel to the x axis.voiddraw(DrawingPanel panel, Graphics g) Draws the shape.doubleGets the height of this shape.static XML.ObjectLoaderGets the XML object loader for this class.protected voidgetPixelPt(DrawingPanel panel) protected AffineTransformgetRotateInstance(double theta) protected AffineTransformgetRotateInstance(double theta, double x, double y) protected AffineTransformgetScaleInstance(double sx, double sy) getShape()Gets the Java shape that is being drawn.protected AffineTransformgetTranslateInstance(double tx, double ty) doublegetWidth()Gets the width of this shape.doublegetXMax()Implements measurable by getting the x center of the circle.doublegetXMin()Implements measurable by getting the x center of the circle.doublegetYMax()Implements measurable by getting the y center of the circle.doublegetYMin()Implements measurable by getting the y center of the circle.booleanisInside(DrawingPanel panel, int xpix, int ypix) Determines if the shape is enabled and if the given pixel coordinates are within the shape.booleanDetermines if this circle should effect the scale of a drawing panel.voidsetHeight(double height) Sets the height of the shape to the given value.voidsetMarkerColor(Color _fillColor, Color _edgeColor) Sets the shape's drawing colors.voidsetMeasured(boolean _enableMeasure) Enables the measured flag so that this arrow effects the scale of a drawing panel.voidsetOffset(double xoffset, double yoffset) Sets the drawing offset; Fixed size shapes cannot be offset.voidsetPixelSized(boolean enable) Sets the pixelSized flag.voidsetTheta(double theta) Sets the rotation angle in radians.voidsetWidth(double width) Sets the width of the shape to the given value.voidsetX(double _x) Sets the x coordinate.voidsetXY(double _x, double _y) Sets the x and y coordinates.voidsetY(double _y) Sets the y coordinate.toString()Gets a description of this object.voidtranform(double[][] mat) Transforms the shape using the given matrix.voidtransform(AffineTransform transformation) Transforms the shape.Methods inherited from class org.opensourcephysics.display.AbstractInteractive
findInteractive, getX, getY, isEnabled, setEnabledMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.opensourcephysics.display.Interactive
isInteractive
-
Field Details
-
edgeColor
-
shape
-
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
-
pixelPt
-
trIS
-
-
Constructor Details
-
InteractiveShape
Constructs an InteractiveShape with the given coordinates.- Parameters:
s-_x- coordinate_y- coordinate
-
InteractiveShape
Constructs an InteractiveShape at the origin.- Parameters:
s-
-
-
Method Details
-
createEllipse
Creates an interactive ellipse.- Parameters:
x-y-w-h-- Returns:
- InteractiveShape
-
createCircle
Creates an interactive circle.- Parameters:
x-y-d- the diameter- Returns:
- the interactive circle
-
createRectangle
Creates an interactive rectangle.- Parameters:
x-y-w-h-- Returns:
- the interactive rectangle
-
createTriangle
Creates an interactive triangle with a base parallel to the x axis.- Parameters:
x-y-b- baseh- height- Returns:
- the interactive triangle
-
createImage
Creates an interactive image.- Parameters:
x-y-image-- Returns:
- the rectangle
-
createTextLine
Creates an interactive image.- Parameters:
x-y-text-- Returns:
- the rectangle
-
createArrow
Creates an interactive arrow.- Parameters:
x-y-w- baseh- height- Returns:
- the arrow
-
createCenteredArrow
Creates an interactive arrow.- Parameters:
x-y-w- baseh- height- Returns:
- the arrow
-
createSquare
Creates an interactive square.- Parameters:
x-y-w-- Returns:
- the interactive square
-
transform
Transforms the shape.- Parameters:
transformation- AffineTransform
-
draw
Draws the shape.- Specified by:
drawin interfaceDrawable- Specified by:
drawin classAbstractInteractive- Parameters:
panel- the drawing panelg- the graphics context
-
contains
public boolean contains(double x, double y) Tests if the specified coordinates are inside the boundary of theShape.- Parameters:
x-y-- Returns:
trueif the specified coordinates are inside theShapeboundary;falseotherwise.
-
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
Determines if the shape is enabled and if the given pixel coordinates are within the shape.- Specified by:
isInsidein classAbstractInteractive- Parameters:
panel- DrawingPanelxpix- intypix- int- Returns:
- boolean
-
setMarkerColor
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- doubleyoffset- double
-
setXY
public void setXY(double _x, double _y) Sets the x and y coordinates.- Specified by:
setXYin interfaceInteractive- Overrides:
setXYin classAbstractInteractive- Parameters:
_x-_y-
-
setX
public void setX(double _x) Sets the x coordinate.- Specified by:
setXin interfaceInteractive- Overrides:
setXin classAbstractInteractive- Parameters:
_x-
-
setY
public void setY(double _y) Sets the y coordinate.- Specified by:
setYin interfaceInteractive- Overrides:
setYin classAbstractInteractive- Parameters:
_y-
-
toString
Gets a description of this object. -
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:
isMeasuredin interfaceMeasurable- Overrides:
isMeasuredin classAbstractInteractive- Returns:
- minimum
-
getXMin
public double getXMin()Implements measurable by getting the x center of the circle.- Specified by:
getXMinin interfaceMeasurable- Overrides:
getXMinin classAbstractInteractive- Returns:
- minimum
-
getXMax
public double getXMax()Implements measurable by getting the x center of the circle.- Specified by:
getXMaxin interfaceMeasurable- Overrides:
getXMaxin classAbstractInteractive- Returns:
- maximum
-
getYMin
public double getYMin()Implements measurable by getting the y center of the circle.- Specified by:
getYMinin interfaceMeasurable- Overrides:
getYMinin classAbstractInteractive- Returns:
- minimum
-
getYMax
public double getYMax()Implements measurable by getting the y center of the circle.- Specified by:
getYMaxin interfaceMeasurable- Overrides:
getYMaxin classAbstractInteractive- Returns:
- maximum
-
getLoader
Gets the XML object loader for this class.- Returns:
- ObjectLoader
-
getPixelPt
-
getRotateInstance
-
getRotateInstance
-
getScaleInstance
-
getTranslateInstance
-