Package org.opensourcephysics.media.core
Class TPoint
java.lang.Object
java.awt.geom.Point2D
java.awt.geom.Point2D.Double
org.opensourcephysics.media.core.TPoint
- All Implemented Interfaces:
Serializable,Cloneable,Drawable,Interactive,Measurable,Trackable
- Direct Known Subclasses:
AutoTracker.ATObject,AutoTracker.Target,CalibrationStep.Position,CoordAxes.AnglePoint,CoordAxes.OriginPoint,DataToolTab.DataToolPlotter.XYAxes,OffsetOriginStep.Position,PerspectiveFilter.Corner,PerspectiveStep.Corner,PositionStep.Position,RGBRegion.VertexHandle,RGBStep.Position,TShape
This is a Point2D that implements the Interactive and Trackable interfaces
with additional utility methods. Classes that extend TPoint should interpret
the stored x and y values as image coordinates. TPoint has an empty draw
method.
- Version:
- 1.0
- Author:
- Douglas Brown
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.awt.geom.Point2D
Point2D.Double, Point2D.Float -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TPointprotected booleanprotected static booleanprotected booleanprotected booleanprotected doubleprotected doubleprotected Pointprotected booleanprotected PropertyChangeSupportprotected AffineTransformprotected booleanprotected Point2D.Doubleprotected static XYCoordinateStringBuilderFields inherited from class java.awt.geom.Point2D.Double
x, yFields inherited from interface org.opensourcephysics.media.core.Trackable
PROPERTY_ADJUSTING -
Constructor Summary
ConstructorsConstructorDescriptionTPoint()Constructs a TPoint with image coordinates (0, 0).TPoint(double x, double y) Constructs a TPoint with specified image coordinates.TPoint(Point2D.Double point) Constructs a TPoint with image coordinates specified by a Point2D (commonly another TPoint). -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a PropertyChangeListener.voidaddPropertyChangeListener(String property, PropertyChangeListener listener) Adds a PropertyChangeListener for a specified property.doubleangle(double x, double y) Returns the angle measured ccw from the positive x-axis to the line between this TPoint and the specified coordinates.doubleangle(Point2D.Double pt) Returns the angle measured ccw from the positive x-axis to a line that goes from this TPoint to the specified Point2D.booleanAttaches this TPoint to another so it follows it.voidcenter(Point2D.Double pt1, Point2D.Double pt2) Centers this TPoint between the two specified points.doublecos(double x, double y) Returns the cosine of the angle measured ccw from the positive x-axis to the line between this TPoint and the specified coordinates.doublecos(Point2D.Double pt) Returns the cosine of the angle measured ccw from the positive x-axis to the line between this TPoint and the specified Point2D.voiddetach()Detaches this TPoint.voiddraw(DrawingPanel panel, Graphics _g) Empty draw method.booleanCompares this to the specified object.findInteractive(DrawingPanel panel, int xpix, int ypix) Returns null.getBounds(VideoPanel vidPanel) Gets the screen bounds of this object.intgetFrameNumber(VideoPanel vidPanel) Gets the frame number this TPoint uses for coordinate system transforms and other identification.getScreenPosition(VideoPanel vidPanel) Gets the screen position of this TPoint on the specified VideoPanel.getWorldPosition(VideoPanel vidPanel) Gets the world position of this TPoint on the specified VideoPanel.doublegetXMax()Gets the maximum x needed to draw this object.doublegetXMin()Gets the minimum x needed to draw this object.doublegetYMax()Gets the maximum y needed to draw this object.doublegetYMin()Gets the minimum y needed to draw this object.booleanGets the adjusting flag.booleanDetermines if this point is attached to another.booleanReports whether this is a coordsEditTrigger.booleanGets whether this responds to mouse hits.booleanReports whether information is available to set min/max values.booleanReports whether this is a stepEditTrigger.booleanReports whether this is a trackEditTrigger.voidRemoves a PropertyChangeListener.voidremovePropertyChangeListener(String property, PropertyChangeListener listener) Removes a PropertyChangeListener for a specified property.voidsetAdjusting(boolean adjusting, MouseEvent e) Sets the adjusting flag.voidsetCoordsEditTrigger(boolean edit) Sets the coordsEditTrigger property.voidsetEnabled(boolean enabled) Sets whether this responds to mouse hits.voidsetLocation(double x, double y) Overrides Point2D.Double setLocation method.voidsetPositionOnLine(int xScreen, int yScreen, VideoPanel vidPanel, TPoint end1, TPoint end2) Sets the position of this point on the line between end1 and end2 nearest the specified screen position.voidsetScreenPosition(int x, int y, VideoPanel vidPanel) Sets the screen position of this TPoint on the specified VideoPanel.voidsetScreenPosition(int x, int y, VideoPanel vidPanel, InputEvent e) Sets the screen position of this TPoint.voidsetStepEditTrigger(boolean stepEditTrigger) Sets the stepEditTrigger property.voidsetTrackEditTrigger(boolean edit) Sets the trackEditTrigger property.voidsetWorldPosition(double x, double y, VideoPanel vidPanel) Sets the world position of this TPoint on the specified VideoPanel.voidsetX(double x) Sets the x position in imagespace.voidsetXY(double x, double y) Sets the x and y positions in imagespace.voidsetY(double y) Sets the y position in imagespace.voidshowCoordinates(VideoPanel vidPanel) Shows the world coordinates of this TPoint in the mouse box of the specified VideoPanel.doublesin(double x, double y) Returns the sine of the angle measured ccw from the positive x-axis to the line between this TPoint and the specified coordinates.doublesin(Point2D.Double pt) Returns the sine of the angle measured ccw from the positive x-axis to the line between this TPoint and the specified Point2D.toString()Returns a String describing this.voidtranslate(double dx, double dy) Translates this TPoint by the specified displacement.Methods inherited from class java.awt.geom.Point2D.Double
getX, getYMethods inherited from class java.awt.geom.Point2D
clone, distance, distance, distance, distanceSq, distanceSq, distanceSq, hashCode, setLocationMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.opensourcephysics.display.Interactive
getX, getY, isInteractive
-
Field Details
-
coordsVisibleInMouseBox
protected static boolean coordsVisibleInMouseBox -
xyStringBuilder
-
enabled
protected boolean enabled -
trackEditTrigger
protected boolean trackEditTrigger -
coordsEditTrigger
protected boolean coordsEditTrigger -
stepEditTrigger
protected boolean stepEditTrigger -
isAdjusting
protected boolean isAdjusting -
screenPt
-
worldPt
-
support
-
attachedTo
-
prevX
protected double prevX -
prevY
protected double prevY -
toScreen
-
-
Constructor Details
-
TPoint
public TPoint()Constructs a TPoint with image coordinates (0, 0). -
TPoint
public TPoint(double x, double y) Constructs a TPoint with specified image coordinates.- Parameters:
x- the x coordinatey- the y coordinate
-
TPoint
Constructs a TPoint with image coordinates specified by a Point2D (commonly another TPoint).- Parameters:
point- the Point2D
-
-
Method Details
-
draw
Empty draw method. This method should be overridden by subclasses. -
findInteractive
Returns null. This method should be overridden by subclasses.- Specified by:
findInteractivein interfaceInteractive- Parameters:
panel- the drawing panelxpix- the x pixel position on the panelypix- the y pixel position on the panel- Returns:
- null
-
setX
public void setX(double x) Sets the x position in imagespace.- Specified by:
setXin interfaceInteractive- Parameters:
x- the x position
-
setY
public void setY(double y) Sets the y position in imagespace.- Specified by:
setYin interfaceInteractive- Parameters:
y- the y position
-
setXY
public void setXY(double x, double y) Sets the x and y positions in imagespace.- Specified by:
setXYin interfaceInteractive- Parameters:
x- the x positiony- the y position
-
setLocation
public void setLocation(double x, double y) Overrides Point2D.Double setLocation method.- Overrides:
setLocationin classPoint2D.Double- Parameters:
x- the x positiony- the y position
-
getFrameNumber
Gets the frame number this TPoint uses for coordinate system transforms and other identification. Step-based subclasses can override this method to report their own frame number.- Parameters:
vidPanel- the video panel- Returns:
- the frame number
-
getScreenPosition
Gets the screen position of this TPoint on the specified VideoPanel.- Parameters:
vidPanel- the video panel- Returns:
- the screen point
-
setScreenPosition
Sets the screen position of this TPoint on the specified VideoPanel.- Parameters:
x- the screen x coordinatey- the screen y coordinatevidPanel- the video panel
-
setScreenPosition
Sets the screen position of this TPoint. This can be overridden by subclasses to change the behavior based on input event methods that report the state of keys like shift, control, alt, etc.- Parameters:
x- the screen x coordinatey- the screen y coordinatevidPanel- the video panele- the input event making the request
-
getWorldPosition
Gets the world position of this TPoint on the specified VideoPanel.- Parameters:
vidPanel- the video panel- Returns:
- the world position
-
setWorldPosition
Sets the world position of this TPoint on the specified VideoPanel.- Parameters:
x- the world x coordinatey- the world y coordinatevidPanel- the video panel
-
showCoordinates
Shows the world coordinates of this TPoint in the mouse box of the specified VideoPanel.- Parameters:
vidPanel- the video panel
-
attachTo
Attaches this TPoint to another so it follows it.- Parameters:
p- the point to attach to- Returns:
- true if a change has occurred
-
detach
public void detach()Detaches this TPoint. -
isAttached
public boolean isAttached()Determines if this point is attached to another.- Returns:
- true if attached
-
setEnabled
public void setEnabled(boolean enabled) Sets whether this responds to mouse hits.- Specified by:
setEnabledin interfaceInteractive- Parameters:
enabled-trueif this responds to mouse hits.
-
isEnabled
public boolean isEnabled()Gets whether this responds to mouse hits.- Specified by:
isEnabledin interfaceInteractive- Returns:
trueif this responds to mouse hits.
-
setTrackEditTrigger
public void setTrackEditTrigger(boolean edit) Sets the trackEditTrigger property. A trackEditTrigger triggers undoable track edits when moved.- Parameters:
edit-trueto make this a trackEditTrigger.
-
isTrackEditTrigger
public boolean isTrackEditTrigger()Reports whether this is a trackEditTrigger. A trackEditTrigger triggers undoable track edits when moved.- Returns:
trueif this is a trackEditTrigger.
-
setCoordsEditTrigger
public void setCoordsEditTrigger(boolean edit) Sets the coordsEditTrigger property. A coordsEditTrigger triggers undoable coords edits when moved.- Parameters:
edit-trueto make this a coordsEditTrigger.
-
isCoordsEditTrigger
public boolean isCoordsEditTrigger()Reports whether this is a coordsEditTrigger. A coordsEditTrigger triggers undoable coords edits when moved.- Returns:
trueif this is a coordsEditTrigger.
-
setStepEditTrigger
public void setStepEditTrigger(boolean stepEditTrigger) Sets the stepEditTrigger property. A stepEditTrigger triggers undoable step edits when moved.- Parameters:
stepEditTrigger-trueto make this a stepEditTrigger.
-
isStepEditTrigger
public boolean isStepEditTrigger()Reports whether this is a stepEditTrigger. A stepEditTrigger triggers undoable step edits when moved.- Returns:
trueif this is a stepEditTrigger.
-
getBounds
Gets the screen bounds of this object.- Parameters:
vidPanel- the video panel- Returns:
- the bounding rectangle
-
isMeasured
public boolean isMeasured()Reports whether information is available to set min/max values.- Specified by:
isMeasuredin interfaceMeasurable- Returns:
false
-
getXMin
public double getXMin()Gets the minimum x needed to draw this object.- Specified by:
getXMinin interfaceMeasurable- Returns:
- minimum x
-
getXMax
public double getXMax()Gets the maximum x needed to draw this object.- Specified by:
getXMaxin interfaceMeasurable- Returns:
- maximum x
-
getYMin
public double getYMin()Gets the minimum y needed to draw this object.- Specified by:
getYMinin interfaceMeasurable- Returns:
- minimum y
-
getYMax
public double getYMax()Gets the maximum y needed to draw this object.- Specified by:
getYMaxin interfaceMeasurable- Returns:
- maximum y
-
angle
public double angle(double x, double y) Returns the angle measured ccw from the positive x-axis to the line between this TPoint and the specified coordinates.- Parameters:
x- the x coordinatey- the x coordinate- Returns:
- the angle in radians
-
angle
Returns the angle measured ccw from the positive x-axis to a line that goes from this TPoint to the specified Point2D.- Parameters:
pt- the Point2D- Returns:
- the angle in radians
-
sin
public double sin(double x, double y) Returns the sine of the angle measured ccw from the positive x-axis to the line between this TPoint and the specified coordinates.- Parameters:
x- the x coordinatey- the x coordinate- Returns:
- the sine of the angle
-
sin
Returns the sine of the angle measured ccw from the positive x-axis to the line between this TPoint and the specified Point2D.- Parameters:
pt- the Point2D- Returns:
- the sine of the angle
-
cos
public double cos(double x, double y) Returns the cosine of the angle measured ccw from the positive x-axis to the line between this TPoint and the specified coordinates.- Parameters:
x- the x coordinatey- the x coordinate- Returns:
- the cosine of the angle
-
cos
Returns the cosine of the angle measured ccw from the positive x-axis to the line between this TPoint and the specified Point2D.- Parameters:
pt- the Point2D- Returns:
- the cosine of the angle
-
center
Centers this TPoint between the two specified points. Note that this method does not call setXY.- Parameters:
pt1- the first Point2Dpt2- the second Point2D
-
translate
public void translate(double dx, double dy) Translates this TPoint by the specified displacement.- Parameters:
dx- the x displacement in imagespacedy- the y displacement in imagespace
-
setAdjusting
Sets the adjusting flag. This is normally set by the mouse handler when this point is dragged or stops being dragged.- Parameters:
adjusting- true if being draggede- a MouseEvent, may be null
-
isAdjusting
public boolean isAdjusting()Gets the adjusting flag.- Returns:
- true if adjusting
-
addPropertyChangeListener
Adds a PropertyChangeListener.- Parameters:
listener- the object requesting property change notification
-
addPropertyChangeListener
Adds a PropertyChangeListener for a specified property.- Parameters:
property- the name of the property of interest to the listenerlistener- the object requesting property change notification
-
removePropertyChangeListener
Removes a PropertyChangeListener.- Parameters:
listener- the listener requesting removal
-
removePropertyChangeListener
Removes a PropertyChangeListener for a specified property.- Parameters:
property- the name of the propertylistener- the listener to remove
-
toString
Returns a String describing this.- Overrides:
toStringin classPoint2D.Double- Returns:
- a descriptive string
-
equals
Compares this to the specified object. -
setPositionOnLine
public void setPositionOnLine(int xScreen, int yScreen, VideoPanel vidPanel, TPoint end1, TPoint end2) Sets the position of this point on the line between end1 and end2 nearest the specified screen position.- Parameters:
xScreen- the x screen positionyScreen- the y screen positionvidPanel- the videoPanel drawing this pointend1- one end of the lineend2- the other end of the line
-