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 TPoint
protected boolean
protected static boolean
protected boolean
protected boolean
protected double
protected double
protected Point
protected boolean
protected PropertyChangeSupport
protected AffineTransform
protected boolean
protected Point2D.Double
protected static XYCoordinateStringBuilder
Fields inherited from class java.awt.geom.Point2D.Double
x, y
Fields 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 TypeMethodDescriptionvoid
Adds a PropertyChangeListener.void
addPropertyChangeListener
(String property, PropertyChangeListener listener) Adds a PropertyChangeListener for a specified property.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.double
angle
(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.boolean
Attaches this TPoint to another so it follows it.void
center
(Point2D.Double pt1, Point2D.Double pt2) Centers this TPoint between the two specified points.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.double
cos
(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.void
detach()
Detaches this TPoint.void
draw
(DrawingPanel panel, Graphics _g) Empty draw method.boolean
Compares this to the specified object.findInteractive
(DrawingPanel panel, int xpix, int ypix) Returns null.getBounds
(VideoPanel vidPanel) Gets the screen bounds of this object.int
getFrameNumber
(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.double
getXMax()
Gets the maximum x needed to draw this object.double
getXMin()
Gets the minimum x needed to draw this object.double
getYMax()
Gets the maximum y needed to draw this object.double
getYMin()
Gets the minimum y needed to draw this object.boolean
Gets the adjusting flag.boolean
Determines if this point is attached to another.boolean
Reports whether this is a coordsEditTrigger.boolean
Gets whether this responds to mouse hits.boolean
Reports whether information is available to set min/max values.boolean
Reports whether this is a stepEditTrigger.boolean
Reports whether this is a trackEditTrigger.void
Removes a PropertyChangeListener.void
removePropertyChangeListener
(String property, PropertyChangeListener listener) Removes a PropertyChangeListener for a specified property.void
setAdjusting
(boolean adjusting, MouseEvent e) Sets the adjusting flag.void
setCoordsEditTrigger
(boolean edit) Sets the coordsEditTrigger property.void
setEnabled
(boolean enabled) Sets whether this responds to mouse hits.void
setLocation
(double x, double y) Overrides Point2D.Double setLocation method.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.void
setScreenPosition
(int x, int y, VideoPanel vidPanel) Sets the screen position of this TPoint on the specified VideoPanel.void
setScreenPosition
(int x, int y, VideoPanel vidPanel, InputEvent e) Sets the screen position of this TPoint.void
setStepEditTrigger
(boolean stepEditTrigger) Sets the stepEditTrigger property.void
setTrackEditTrigger
(boolean edit) Sets the trackEditTrigger property.void
setWorldPosition
(double x, double y, VideoPanel vidPanel) Sets the world position of this TPoint on the specified VideoPanel.void
setX
(double x) Sets the x position in imagespace.void
setXY
(double x, double y) Sets the x and y positions in imagespace.void
setY
(double y) Sets the y position in imagespace.void
showCoordinates
(VideoPanel vidPanel) Shows the world coordinates of this TPoint in the mouse box of the specified VideoPanel.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.double
sin
(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.void
translate
(double dx, double dy) Translates this TPoint by the specified displacement.Methods inherited from class java.awt.geom.Point2D.Double
getX, getY
Methods inherited from class java.awt.geom.Point2D
clone, distance, distance, distance, distanceSq, distanceSq, distanceSq, hashCode, setLocation
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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:
findInteractive
in 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:
setX
in interfaceInteractive
- Parameters:
x
- the x position
-
setY
public void setY(double y) Sets the y position in imagespace.- Specified by:
setY
in interfaceInteractive
- Parameters:
y
- the y position
-
setXY
public void setXY(double x, double y) Sets the x and y positions in imagespace.- Specified by:
setXY
in interfaceInteractive
- Parameters:
x
- the x positiony
- the y position
-
setLocation
public void setLocation(double x, double y) Overrides Point2D.Double setLocation method.- Overrides:
setLocation
in 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:
setEnabled
in interfaceInteractive
- Parameters:
enabled
-true
if this responds to mouse hits.
-
isEnabled
public boolean isEnabled()Gets whether this responds to mouse hits.- Specified by:
isEnabled
in interfaceInteractive
- Returns:
true
if 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
-true
to make this a trackEditTrigger.
-
isTrackEditTrigger
public boolean isTrackEditTrigger()Reports whether this is a trackEditTrigger. A trackEditTrigger triggers undoable track edits when moved.- Returns:
true
if this is a trackEditTrigger.
-
setCoordsEditTrigger
public void setCoordsEditTrigger(boolean edit) Sets the coordsEditTrigger property. A coordsEditTrigger triggers undoable coords edits when moved.- Parameters:
edit
-true
to make this a coordsEditTrigger.
-
isCoordsEditTrigger
public boolean isCoordsEditTrigger()Reports whether this is a coordsEditTrigger. A coordsEditTrigger triggers undoable coords edits when moved.- Returns:
true
if this is a coordsEditTrigger.
-
setStepEditTrigger
public void setStepEditTrigger(boolean stepEditTrigger) Sets the stepEditTrigger property. A stepEditTrigger triggers undoable step edits when moved.- Parameters:
stepEditTrigger
-true
to make this a stepEditTrigger.
-
isStepEditTrigger
public boolean isStepEditTrigger()Reports whether this is a stepEditTrigger. A stepEditTrigger triggers undoable step edits when moved.- Returns:
true
if 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:
isMeasured
in interfaceMeasurable
- Returns:
false
-
getXMin
public double getXMin()Gets the minimum x needed to draw this object.- Specified by:
getXMin
in interfaceMeasurable
- Returns:
- minimum x
-
getXMax
public double getXMax()Gets the maximum x needed to draw this object.- Specified by:
getXMax
in interfaceMeasurable
- Returns:
- maximum x
-
getYMin
public double getYMin()Gets the minimum y needed to draw this object.- Specified by:
getYMin
in interfaceMeasurable
- Returns:
- minimum y
-
getYMax
public double getYMax()Gets the maximum y needed to draw this object.- Specified by:
getYMax
in 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:
toString
in 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
-