org.opensourcephysics.media.core
Class TPoint

java.lang.Object
  extended by java.awt.geom.Point2D
      extended by java.awt.geom.Point2D.Double
          extended by org.opensourcephysics.media.core.TPoint
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Drawable, Interactive, Measurable, Trackable
Direct Known Subclasses:
TShape

public class TPoint
extends java.awt.geom.Point2D.Double
implements Interactive, Trackable

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:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Point2D
java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Float
 
Field Summary
protected static VidCartesianCoordinateStringBuilder coordinateStrBuilder
           
protected  boolean coordsEditTrigger
           
protected static boolean coordsVisibleInMouseBox
           
protected  boolean enabled
           
protected  java.awt.Point screenPt
           
protected  boolean stepEditTrigger
           
protected  java.beans.PropertyChangeSupport support
           
protected  boolean trackEditTrigger
           
protected  java.awt.geom.Point2D worldPt
           
 
Fields inherited from class java.awt.geom.Point2D.Double
x, y
 
Constructor Summary
TPoint()
          Constructs a TPoint with image coordinates (0, 0).
TPoint(double x, double y)
          Constructs a TPoint with specified image coordinates.
TPoint(java.awt.geom.Point2D point)
          Constructs a TPoint with image coordinates specified by a Point2D (commonly another TPoint).
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener.
 void addPropertyChangeListener(java.lang.String property, java.beans.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(java.awt.geom.Point2D pt)
          Returns the angle measured ccw from the positive x-axis to a line that goes from this TPoint to the specified Point2D.
 void center(java.awt.geom.Point2D pt1, java.awt.geom.Point2D 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(java.awt.geom.Point2D 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 draw(DrawingPanel panel, java.awt.Graphics _g)
          Empty draw method.
 boolean equals(java.lang.Object object)
          Compares this to the specified object.
 Interactive findInteractive(DrawingPanel panel, int xpix, int ypix)
          Returns null.
 java.awt.Rectangle 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.
 java.awt.Point getScreenPosition(VideoPanel vidPanel)
          Gets the screen position of this TPoint on the specified VideoPanel.
 java.awt.geom.Point2D 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 isCoordsEditTrigger()
          Reports whether this is a coordsEditTrigger.
 boolean isEnabled()
          Gets whether this responds to mouse hits.
 boolean isMeasured()
          Reports whether information is available to set min/max values.
 boolean isStepEditTrigger()
          Reports whether this is a stepEditTrigger.
 boolean isTrackEditTrigger()
          Reports whether this is a trackEditTrigger.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener.
 void removePropertyChangeListener(java.lang.String property, java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener for a specified property.
 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, java.awt.event.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 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(java.awt.geom.Point2D pt)
          Returns the sine of the angle measured ccw from the positive x-axis to the line between this TPoint and the specified Point2D.
 java.lang.String 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
 

Field Detail

coordsVisibleInMouseBox

protected static boolean coordsVisibleInMouseBox

coordinateStrBuilder

protected static VidCartesianCoordinateStringBuilder coordinateStrBuilder

enabled

protected boolean enabled

trackEditTrigger

protected boolean trackEditTrigger

coordsEditTrigger

protected boolean coordsEditTrigger

stepEditTrigger

protected boolean stepEditTrigger

screenPt

protected java.awt.Point screenPt

worldPt

protected java.awt.geom.Point2D worldPt

support

protected java.beans.PropertyChangeSupport support
Constructor Detail

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 coordinate
y - the y coordinate

TPoint

public TPoint(java.awt.geom.Point2D point)
Constructs a TPoint with image coordinates specified by a Point2D (commonly another TPoint).

Parameters:
point - the Point2D
Method Detail

draw

public void draw(DrawingPanel panel,
                 java.awt.Graphics _g)
Empty draw method. This method should be overridden by subclasses.

Specified by:
draw in interface Drawable
Parameters:
panel - the drawing panel requesting the drawing
_g - the graphics context on which to draw

findInteractive

public Interactive findInteractive(DrawingPanel panel,
                                   int xpix,
                                   int ypix)
Returns null. This method should be overridden by subclasses.

Specified by:
findInteractive in interface Interactive
Parameters:
panel - the drawing panel
xpix - the x pixel position on the panel
ypix - 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 interface Interactive
Parameters:
x - the x position

setY

public void setY(double y)
Sets the y position in imagespace.

Specified by:
setY in interface Interactive
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 interface Interactive
Parameters:
x - the x position
y - the y position

setLocation

public void setLocation(double x,
                        double y)
Overrides Point2D.Double setLocation method.

Overrides:
setLocation in class java.awt.geom.Point2D.Double
Parameters:
x - the x position
y - the y position

getFrameNumber

public int getFrameNumber(VideoPanel vidPanel)
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

public java.awt.Point getScreenPosition(VideoPanel vidPanel)
Gets the screen position of this TPoint on the specified VideoPanel.

Parameters:
vidPanel - the video panel
Returns:
the screen point

setScreenPosition

public void setScreenPosition(int x,
                              int y,
                              VideoPanel vidPanel)
Sets the screen position of this TPoint on the specified VideoPanel.

Parameters:
x - the screen x coordinate
y - the screen y coordinate
vidPanel - the video panel

setScreenPosition

public void setScreenPosition(int x,
                              int y,
                              VideoPanel vidPanel,
                              java.awt.event.InputEvent e)
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 coordinate
y - the screen y coordinate
vidPanel - the video panel
e - the input event making the request

getWorldPosition

public java.awt.geom.Point2D getWorldPosition(VideoPanel vidPanel)
Gets the world position of this TPoint on the specified VideoPanel.

Parameters:
vidPanel - the video panel
Returns:
the world position

showCoordinates

public void showCoordinates(VideoPanel vidPanel)
Shows the world coordinates of this TPoint in the mouse box of the specified VideoPanel.

Parameters:
vidPanel - the video panel

setEnabled

public void setEnabled(boolean enabled)
Sets whether this responds to mouse hits.

Specified by:
setEnabled in interface Interactive
Parameters:
enabled - true if this responds to mouse hits.

isEnabled

public boolean isEnabled()
Gets whether this responds to mouse hits.

Specified by:
isEnabled in interface Interactive
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

public java.awt.Rectangle getBounds(VideoPanel vidPanel)
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 interface Measurable
Returns:
false

getXMin

public double getXMin()
Gets the minimum x needed to draw this object.

Specified by:
getXMin in interface Measurable
Returns:
minimum x

getXMax

public double getXMax()
Gets the maximum x needed to draw this object.

Specified by:
getXMax in interface Measurable
Returns:
maximum x

getYMin

public double getYMin()
Gets the minimum y needed to draw this object.

Specified by:
getYMin in interface Measurable
Returns:
minimum y

getYMax

public double getYMax()
Gets the maximum y needed to draw this object.

Specified by:
getYMax in interface Measurable
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 coordinate
y - the x coordinate
Returns:
the angle in radians

angle

public double angle(java.awt.geom.Point2D pt)
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 coordinate
y - the x coordinate
Returns:
the sine of the angle

sin

public double sin(java.awt.geom.Point2D pt)
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 coordinate
y - the x coordinate
Returns:
the cosine of the angle

cos

public double cos(java.awt.geom.Point2D pt)
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

public void center(java.awt.geom.Point2D pt1,
                   java.awt.geom.Point2D pt2)
Centers this TPoint between the two specified points. Note that this method does not call setXY.

Parameters:
pt1 - the first Point2D
pt2 - the second Point2D

translate

public void translate(double dx,
                      double dy)
Translates this TPoint by the specified displacement.

Parameters:
dx - the x displacement in imagespace
dy - the y displacement in imagespace

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener.

Parameters:
listener - the object requesting property change notification

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String property,
                                      java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener for a specified property.

Parameters:
property - the name of the property of interest to the listener
listener - the object requesting property change notification

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener.

Parameters:
listener - the listener requesting removal

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String property,
                                         java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener for a specified property.

Parameters:
property - the name of the property
listener - the listener to remove

toString

public java.lang.String toString()
Returns a String describing this.

Overrides:
toString in class java.awt.geom.Point2D.Double
Returns:
a descriptive string

equals

public boolean equals(java.lang.Object object)
Compares this to the specified object.

Overrides:
equals in class java.awt.geom.Point2D
Parameters:
object - the object
Returns:
true if this equals 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 position
yScreen - the y screen position
vidPanel - the videoPanel drawing this point
end1 - one end of the line
end2 - the other end of the line