Package net.sf.jaxodraw.object.bezier
Class JaxoBezierObject
- java.lang.Object
-
- net.sf.jaxodraw.object.JaxoObject
-
- net.sf.jaxodraw.object.JaxoExtendedObject
-
- net.sf.jaxodraw.object.JaxoParticleObject
-
- net.sf.jaxodraw.object.Jaxo3PointObject
-
- net.sf.jaxodraw.object.bezier.JaxoBezierObject
-
- All Implemented Interfaces:
java.awt.Shape
,java.beans.PropertyChangeListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.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
Fields Modifier and Type Field Description 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
Constructors Constructor Description JaxoBezierObject()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description JaxoArrow.Coordinates
arrowCoordinates()
Returns the coordinates of the arrow of the current object.protected static java.lang.String
bezierLatexCommand(java.lang.String options, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D p3, java.awt.geom.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 java.lang.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 java.awt.geom.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 java.awt.geom.Point2D
getLatexPoint(java.awt.geom.Point2D p, float scaleFactor, int canvasHeight)
Returns the latex (ie axodraw) coordinates of the point passed of this JaxoObject.java.awt.geom.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 java.awt.geom.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.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
-
-
-
-
Field Detail
-
SELECT_P4
public static final int SELECT_P4
Fourth point (index 3).- See Also:
- Constant Field Values
-
-
Method Detail
-
getPointCount
public int getPointCount()
Returns the number of points it takes to draw this object.- Overrides:
getPointCount
in classJaxo3PointObject
- Returns:
- 4.
-
getX
public int getX(int index)
X coordinate of Point 0 <= index < getPointCount().- Overrides:
getX
in classJaxo3PointObject
- 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 classJaxo3PointObject
- 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 classJaxo3PointObject
- 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 classJaxo3PointObject
- 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. UsesetLocation(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 classJaxo3PointObject
- 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 byJaxoObject.copy()
.- Overrides:
setState
in classJaxoParticleObject
- 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 classJaxoObject
- 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 classJaxo3PointObject
- 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 classJaxo3PointObject
- 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 classJaxo3PointObject
- 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 classJaxo3PointObject
- 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 classJaxo3PointObject
- 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 classJaxo3PointObject
- Parameters:
orx
- The x-coordinate of the fixed point.ory
- The y-coordinate of the fixed point.scale
- The scale parameter.
-
getLatexPoint
protected static java.awt.geom.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 pointy
- the y coordinate of the pointscaleFactor
- A scalefactor.canvasHeight
- The current height of the canvas.- Returns:
- A Point2D.
-
getLatexPoint
protected static java.awt.geom.Point2D getLatexPoint(java.awt.geom.Point2D p, float scaleFactor, int canvasHeight)
Returns the latex (ie axodraw) coordinates of the point passed of this JaxoObject.- Parameters:
p
- the pointscaleFactor
- A scalefactor.canvasHeight
- The current height of the canvas.- Returns:
- A Point2D.
- Since:
- 2.1
-
bezierLatexCommand
protected static java.lang.String bezierLatexCommand(java.lang.String options, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D p3, java.awt.geom.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 java.lang.String getArrowCommand(float scale)
-
arrowCoordinates
public JaxoArrow.Coordinates arrowCoordinates()
Returns the coordinates of the arrow of the current object.- Specified by:
arrowCoordinates
in classJaxoParticleObject
- Returns:
- The coordinates of the arrow of the current object.
-
getPoint
public java.awt.geom.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 java.awt.geom.Point2D getPointOnCurve(double t)
Returns a point of this Bezier curve at a given parameter value. UnlikegetPoint(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 thepreferences
.- Overrides:
setPreferences
in classJaxoParticleObject
-
-