net.sf.jaxodraw.object.bezier
Class JaxoBezierObject

java.lang.Object
  extended by net.sf.jaxodraw.object.JaxoObject
      extended by net.sf.jaxodraw.object.JaxoExtendedObject
          extended by net.sf.jaxodraw.object.JaxoParticleObject
              extended by net.sf.jaxodraw.object.Jaxo3PointObject
                  extended by net.sf.jaxodraw.object.bezier.JaxoBezierObject
All Implemented Interfaces:
Shape, PropertyChangeListener, Serializable, Cloneable, EventListener
Direct Known Subclasses:
JaxoDashBezier, JaxoFBezier, JaxoGlBezier, JaxoPBezier

public abstract class JaxoBezierObject
extends Jaxo3PointObject

Abstract class for the implementation of a bezier curve.

Since:
2.0
See Also:
Serialized Form

Field Summary
static int SELECT_P4
          Fourth point (index 3).
 
Fields inherited from class net.sf.jaxodraw.object.Jaxo3PointObject
SELECT_P3
 
Fields inherited from class net.sf.jaxodraw.object.JaxoParticleObject
GHOST_DASH, GLUON_FREQ, PHOTON_FREQ, SCALAR_DASH
 
Fields inherited from class net.sf.jaxodraw.object.JaxoExtendedObject
SELECT_DX, SELECT_DY, SELECT_P2
 
Fields inherited from class net.sf.jaxodraw.object.JaxoObject
D_FORMAT, GRAY_SCALE_FORMAT, SELECT_NONE, SELECT_P1
 
Constructor Summary
JaxoBezierObject()
           
 
Method Summary
 JaxoArrow.Coordinates arrowCoordinates()
          Returns the coordinates of the arrow of the current object.
protected static String bezierLatexCommand(String options, Point2D p1, Point2D p2, Point2D p3, Point2D p4)
          Return a latex Bezier command.
 boolean canBeSelected(int handle, int mode)
          Determines if the object can be selected (moved, edited, etc) from the given point in a given edit mode.
 void copyFrom(JaxoBezierObject temp)
          Sets all parameters from the given object to the current one.
protected  String getArrowCommand(float scale)
           
 double getBezierLength()
          Returns the approximate length of this Bezier curve.
 int getGrabbedHandle(int clickX, int clickY, JaxoHandle h)
          Determines which handle the user has selected to move/resize/edit an object.
protected static Point2D getLatexPoint(double x, double y, float scaleFactor, int canvasHeight)
          Returns the latex (ie axodraw) coordinates of the point passed of this JaxoObject.
protected static Point2D getLatexPoint(Point2D p, float scaleFactor, int canvasHeight)
          Returns the latex (ie axodraw) coordinates of the point passed of this JaxoObject.
 Point2D getPoint(double u)
          Returns a point of this Bezier curve at parameter u.
 int getPointCount()
          Returns the number of points it takes to draw this object.
protected  Point2D getPointOnCurve(double t)
          Returns a point of this Bezier curve at a given parameter value.
 int getX(int index)
          X coordinate of Point 0 <= index < getPointCount().
 int getX4()
          Returns the x coordinate of the fourth click point of this Bezier.
 int getY(int index)
          Y coordinate of Point 0 <= index < getPointCount().
 int getY4()
          Returns the y coordinate of the fourth click point of this Bezier.
 boolean isCopy(JaxoObject comp)
          Determines if this JaxoObject is a copy of the specified one.
 boolean isNoFreqStretching()
          Returns the frequency stretching property of this Bezier.
 void moveBy(int deltaX, int deltaY)
          Reset the coordinates of the object when it is moved by deltaX and deltaY.
 void paintHandles(JaxoGraphics2D g2, JaxoHandle h, int editMode)
          Paints the handles of this JaxoObject that allow to move/resize/edit it.
 void paintVisualAid(JaxoGraphics2D g2)
          Paints a visual aid for the user during dragging (moving or resizing) of this JaxoObject.
 void rescaleObject(int orx, int ory, float scale)
          Rescale this JaxoObject by the scale factor scale, keeping the point (orx, ory) fixed.
 void setBezierPts(int sx1, int sy1, int sx2, int sy2, int sx3, int sy3, int sx4, int sy4)
          Deprecated. unused. Use setLocation(int,int,int,int,int,int,int,int) instead.
 void setLocation(int sx1, int sy1, int sx2, int sy2, int sx3, int sy3, int sx4, int sy4)
          Sets the points of this Bezier.
 void setNoFreqStretching(boolean nofs)
          Sets the frequency stretching property of this Bezier.
 void setPreferences()
          Applies default values to this JaxoObject.
 void setState(JaxoObject o)
          Restore state to the values of 'o'.
 void setX(int index, int value)
          Set X coordinate of Point 0 <= index < getPointCount() to 'value'.
 void setX4(int newx4)
          Sets the x coordinate of the fourth click point of this Bezier.
 void setY(int index, int value)
          Set Y coordinate of Point 0 <= index < getPointCount() to 'value'.
 void setY4(int newy4)
          Sets the y coordinate of the fourth click point of this Bezier.
 double slope(double u)
          Returns the first derivative of this Bezier curve at parameter u.
 float smallestDistanceTo(int px, int py)
          Determines the smallest distance of any of the handles of this JaxoObject from the given point.
 
Methods inherited from class net.sf.jaxodraw.object.Jaxo3PointObject
copyFrom, getX3, getY3, isOneLine, set3Pts, setLocation, setX3, setY3
 
Methods inherited from class net.sf.jaxodraw.object.JaxoParticleObject
arrowPositionIs, copy, copyFrom, dashIs, dlSepIs, getAmp, getArrow, getArrowPosition, getDash, getDLSeparation, getWiggles, isDoubleLine, isFlip, isPaintArrow, paintArrow, setAmp, setArrow, setArrowPosition, setDash, setDLSeparation, setDoubleLine, setFlip, setPaintArrow, setWiggles
 
Methods inherited from class net.sf.jaxodraw.object.JaxoExtendedObject
copyFrom, getHeight, getRadius, getRelh, getRelSize, getRelw, getSize, getStroke, getStrokeWidth, getWidth, getX2, getY2, latexWidth, resetStroke, setLocation, setRadius, setRelativeHeight, setRelativeWidth, setRelWAndH, setStroke, setStrokeWidth, setX2, setY2, strokeIs
 
Methods inherited from class net.sf.jaxodraw.object.JaxoObject
addPropertyChangeListener, contains, contains, contains, contains, copyFrom, firePropertyChange, getBounds2D, getBoundsWithHandles, getColor, getGeneralPath, getLaTexLocation, getName, getPathIterator, getPathIterator, getPoints, getX, getY, intersects, intersects, isAround, isMarked, latexCommand, paint, prepareEditPanel, propertyChange, removePropertyChangeListener, setAsMarked, setColor, setLocation, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setPointCount, setPoints, setTransient, setX, setXPosition, setY, setYPosition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.awt.Shape
getBounds
 

Field Detail

SELECT_P4

public static final int SELECT_P4
Fourth point (index 3).

See Also:
Constant Field Values
Constructor Detail

JaxoBezierObject

public JaxoBezierObject()
Method Detail

getPointCount

public int getPointCount()
Returns the number of points it takes to draw this object.

Overrides:
getPointCount in class Jaxo3PointObject
Returns:
4.

getX

public int getX(int index)
X coordinate of Point 0 <= index < getPointCount().

Overrides:
getX in class Jaxo3PointObject
Parameters:
index - The index of the point to get.
Returns:
The x coordinate of the point at the given index.

getY

public int getY(int index)
Y coordinate of Point 0 <= index < getPointCount().

Overrides:
getY in class Jaxo3PointObject
Parameters:
index - The index of the point to get.
Returns:
The y coordinate of the point at the given index.

setX

public void setX(int index,
                 int value)
Set X coordinate of Point 0 <= index < getPointCount() to 'value'. Throws IllegalArgumentException if the index is not valid for the given object.

Overrides:
setX in class Jaxo3PointObject
Parameters:
index - The index of the point to set.
value - The value to set.

setY

public void setY(int index,
                 int value)
Set Y coordinate of Point 0 <= index < getPointCount() to 'value'. Throws IllegalArgumentException if the index is not valid for the given object.

Overrides:
setY in class Jaxo3PointObject
Parameters:
index - The index of the point to set.
value - The value to set.

setNoFreqStretching

public final void setNoFreqStretching(boolean nofs)
Sets the frequency stretching property of this Bezier.

Parameters:
nofs - True if this Bezier is not frequency stretched.

isNoFreqStretching

public final boolean isNoFreqStretching()
Returns the frequency stretching property of this Bezier.

Returns:
True if this Bezier is not frequency stretched.

setX4

public final void setX4(int newx4)
Sets the x coordinate of the fourth click point of this Bezier.

Parameters:
newx4 - The x coordinate of the fourth click point of this Bezier.

getX4

public final int getX4()
Returns the x coordinate of the fourth click point of this Bezier.

Returns:
The x coordinate of the fourth click point of this Bezier.

setY4

public final void setY4(int newy4)
Sets the y coordinate of the fourth click point of this Bezier.

Parameters:
newy4 - The y coordinate of the fourth click point of this Bezier.

getY4

public final int getY4()
Returns the y coordinate of the fourth click point of this Bezier.

Returns:
The y coordinate of the fourth click point of this Bezier.

setBezierPts

public final void setBezierPts(int sx1,
                               int sy1,
                               int sx2,
                               int sy2,
                               int sx3,
                               int sy3,
                               int sx4,
                               int sy4)
Deprecated. unused. Use setLocation(int,int,int,int,int,int,int,int) instead.

Sets the points of this Bezier.

Parameters:
sx1 - The x coordinate of the first click point of this Bezier.
sy1 - The y coordinate of the first click point of this Bezier.
sx2 - The x coordinate of the second click point of this Bezier.
sy2 - The y coordinate of the second click point of this Bezier.
sx3 - The x coordinate of the third click point of this Bezier.
sy3 - The y coordinate of the third click point of this Bezier.
sx4 - The x coordinate of the fourth click point of this Bezier.
sy4 - The y coordinate of the fourth click point of this Bezier.

setLocation

public final void setLocation(int sx1,
                              int sy1,
                              int sx2,
                              int sy2,
                              int sx3,
                              int sy3,
                              int sx4,
                              int sy4)
Sets the points of this Bezier.

Parameters:
sx1 - The x coordinate of the first click point of this Bezier.
sy1 - The y coordinate of the first click point of this Bezier.
sx2 - The x coordinate of the second click point of this Bezier.
sy2 - The y coordinate of the second click point of this Bezier.
sx3 - The x coordinate of the third click point of this Bezier.
sy3 - The y coordinate of the third click point of this Bezier.
sx4 - The x coordinate of the fourth click point of this Bezier.
sy4 - The y coordinate of the fourth click point of this Bezier.

isCopy

public boolean isCopy(JaxoObject comp)
Determines if this JaxoObject is a copy of the specified one.

Overrides:
isCopy in class Jaxo3PointObject
Parameters:
comp - The JaxoObject to compare against.
Returns:
True if the JaxoObjects are identical.

copyFrom

public void copyFrom(JaxoBezierObject temp)
Sets all parameters from the given object to the current one.

Parameters:
temp - The object to copy from.

setState

public void setState(JaxoObject o)
Restore state to the values of 'o'. The object 'o' must be an object of the same "type" obtained by JaxoObject.copy().

Overrides:
setState in class JaxoParticleObject
Parameters:
o - the object to copy from.

paintVisualAid

public final void paintVisualAid(JaxoGraphics2D g2)
Paints a visual aid for the user during dragging (moving or resizing) of this JaxoObject.

Overrides:
paintVisualAid in class JaxoObject
Parameters:
g2 - The graphics context to paint the visual aid.

paintHandles

public final void paintHandles(JaxoGraphics2D g2,
                               JaxoHandle h,
                               int editMode)
Paints the handles of this JaxoObject that allow to move/resize/edit it.

Overrides:
paintHandles in class Jaxo3PointObject
Parameters:
g2 - The corresponding graphics context.
h - A handle object to be used for painting.
editMode - The edit mode that the handles are being painted in.

smallestDistanceTo

public final float smallestDistanceTo(int px,
                                      int py)
Determines the smallest distance of any of the handles of this JaxoObject from the given point.

Overrides:
smallestDistanceTo in class Jaxo3PointObject
Parameters:
px - The x coordinate of the test point.
py - The y coordinate of the test point.
Returns:
The smallest distance.

getGrabbedHandle

public int getGrabbedHandle(int clickX,
                            int clickY,
                            JaxoHandle h)
Determines which handle the user has selected to move/resize/edit an object.

Overrides:
getGrabbedHandle in class Jaxo3PointObject
Parameters:
clickX - The x coordinate where the mouse click has ocurred.
clickY - The y coordinate where the mouse click has ocurred.
h - A handle object.
Returns:
One of the static variables SELECT_* defined for this JaxoObject that specifies the handle which the user has clicked.

canBeSelected

public boolean canBeSelected(int handle,
                             int mode)
Determines if the object can be selected (moved, edited, etc) from the given point in a given edit mode.

Overrides:
canBeSelected in class Jaxo3PointObject
Parameters:
handle - One of the static variables SELECT_* defined for this JaxoObject.
mode - The current edit mode.
Returns:
True if the object may be selected from the given point, false otherwise.

moveBy

public final void moveBy(int deltaX,
                         int deltaY)
Reset the coordinates of the object when it is moved by deltaX and deltaY.

Overrides:
moveBy in class Jaxo3PointObject
Parameters:
deltaX - The x displacement.
deltaY - The y displacement.

rescaleObject

public final void rescaleObject(int orx,
                                int ory,
                                float scale)
Rescale this JaxoObject by the scale factor scale, keeping the point (orx, ory) fixed.

Overrides:
rescaleObject in class Jaxo3PointObject
Parameters:
orx - The x-coordinate of the fixed point.
ory - The y-coordinate of the fixed point.
scale - The scale parameter.

getLatexPoint

protected static Point2D getLatexPoint(double x,
                                       double y,
                                       float scaleFactor,
                                       int canvasHeight)
Returns the latex (ie axodraw) coordinates of the point passed of this JaxoObject.

Parameters:
x - the x coordinate of the point
y - the y coordinate of the point
scaleFactor - A scalefactor.
canvasHeight - The current height of the canvas.
Returns:
A Point2D.

getLatexPoint

protected static Point2D getLatexPoint(Point2D p,
                                       float scaleFactor,
                                       int canvasHeight)
Returns the latex (ie axodraw) coordinates of the point passed of this JaxoObject.

Parameters:
p - the point
scaleFactor - A scalefactor.
canvasHeight - The current height of the canvas.
Returns:
A Point2D.
Since:
2.1

bezierLatexCommand

protected static String bezierLatexCommand(String options,
                                           Point2D p1,
                                           Point2D p2,
                                           Point2D p3,
                                           Point2D p4)
Return a latex Bezier command.

Parameters:
options - the latex options for the command.
p1 - the first control point of the Bezier.
p2 - the second control point of the Bezier.
p3 - the third control point of the Bezier.
p4 - the fourth control point of the Bezier.
Returns:
a latex (axodraw4j) Bezier command.
Since:
2.1

getArrowCommand

protected String getArrowCommand(float scale)

arrowCoordinates

public JaxoArrow.Coordinates arrowCoordinates()
Returns the coordinates of the arrow of the current object.

Specified by:
arrowCoordinates in class JaxoParticleObject
Returns:
The coordinates of the arrow of the current object.

getPoint

public Point2D getPoint(double u)
Returns a point of this Bezier curve at parameter u.

Parameters:
u - the parameter value, needs to be between 0 and 1.
Returns:
A Point2D.

getPointOnCurve

protected Point2D getPointOnCurve(double t)
Returns a point of this Bezier curve at a given parameter value. Unlike getPoint(double), the parameter may be outside the interval [0:1]. If it lies outside, the closest end-point of the Bezier curve is returned, i.e. the returned Point is always a point of the Bezier curve. This method should only be used to avoid rounding errors at the end points.

Parameters:
t - the curve parameter. If t < 0 then the Point at t=0 will be returned. If t > 1 then the Point at t=1 will be returned.
Returns:
a Point of the Bezier curve at given parameter value.
Since:
2.1

slope

public double slope(double u)
Returns the first derivative of this Bezier curve at parameter u.

Parameters:
u - the parameter value, needs to be between 0 and 1.
Returns:
the slope (in radians) at t.

getBezierLength

public final double getBezierLength()
Returns the approximate length of this Bezier curve.

Returns:
The length of the Bezier curve.

setPreferences

public void setPreferences()
Applies default values to this JaxoObject. All fields except location points are initialized with values taken from the preferences.

Overrides:
setPreferences in class JaxoParticleObject


Copyright © 2003-2011 The JaxoDraw team. All Rights Reserved.