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 class
A class to save and load InteractiveShape in an XMLControl. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double
protected Point2D.Double
protected boolean
protected Shape
protected String
protected double
protected AffineTransform
protected AffineTransform
protected double
protected double
protected double
Fields 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 TypeMethodDescriptionboolean
contains
(double x, double y) Tests if the specified coordinates are inside the boundary of theShape
.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
(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, 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, Graphics g) Draws the shape.double
Gets the height of this shape.static XML.ObjectLoader
Gets the XML object loader for this class.protected void
getPixelPt
(DrawingPanel panel) protected AffineTransform
getRotateInstance
(double theta) protected AffineTransform
getRotateInstance
(double theta, double x, double y) protected AffineTransform
getScaleInstance
(double sx, double sy) getShape()
Gets the Java shape that is being drawn.protected AffineTransform
getTranslateInstance
(double tx, double ty) 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
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
(Color _fillColor, 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.toString()
Gets a description of this object.void
tranform
(double[][] mat) Transforms the shape using the given matrix.void
transform
(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
Methods 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:
draw
in interfaceDrawable
- Specified by:
draw
in 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:
true
if the specified coordinates are inside theShape
boundary;false
otherwise.
-
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:
isInside
in 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:
setXY
in interfaceInteractive
- Overrides:
setXY
in classAbstractInteractive
- Parameters:
_x
-_y
-
-
setX
public void setX(double _x) Sets the x coordinate.- Specified by:
setX
in interfaceInteractive
- Overrides:
setX
in classAbstractInteractive
- Parameters:
_x
-
-
setY
public void setY(double _y) Sets the y coordinate.- Specified by:
setY
in interfaceInteractive
- Overrides:
setY
in 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:
isMeasured
in interfaceMeasurable
- Overrides:
isMeasured
in classAbstractInteractive
- Returns:
- minimum
-
getXMin
public double getXMin()Implements measurable by getting the x center of the circle.- Specified by:
getXMin
in interfaceMeasurable
- Overrides:
getXMin
in classAbstractInteractive
- Returns:
- minimum
-
getXMax
public double getXMax()Implements measurable by getting the x center of the circle.- Specified by:
getXMax
in interfaceMeasurable
- Overrides:
getXMax
in classAbstractInteractive
- Returns:
- maximum
-
getYMin
public double getYMin()Implements measurable by getting the y center of the circle.- Specified by:
getYMin
in interfaceMeasurable
- Overrides:
getYMin
in classAbstractInteractive
- Returns:
- minimum
-
getYMax
public double getYMax()Implements measurable by getting the y center of the circle.- Specified by:
getYMax
in interfaceMeasurable
- Overrides:
getYMax
in classAbstractInteractive
- Returns:
- maximum
-
getLoader
Gets the XML object loader for this class.- Returns:
- ObjectLoader
-
getPixelPt
-
getRotateInstance
-
getRotateInstance
-
getScaleInstance
-
getTranslateInstance
-