Package net.sf.jaxodraw.object
Class JaxoObject
java.lang.Object
net.sf.jaxodraw.object.JaxoObject
- All Implemented Interfaces:
Shape
,PropertyChangeListener
,Serializable
,Cloneable
,EventListener
- Direct Known Subclasses:
JaxoExtendedObject
,JaxoTextObject
public abstract class JaxoObject
extends Object
implements Serializable, Cloneable, Shape, PropertyChangeListener
A general JaxoObject.
- Since:
- 2.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DecimalFormat
The decimal format used for numbers in LaTeX output.static final DecimalFormat
The decimal format used gray scales in LaTeX output.static final int
An integer that indicates that the user did not grab any object.static final int
First point (index 0). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a PropertyChangeListener to this object.abstract 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.boolean
contains
(double x0, double y0) Tests if the specified coordinates are inside the boundary of this JaxoObject.boolean
contains
(double x0, double y0, double w, double h) Tests if the specified rectangular shape is entirely inside the boundary of this JaxoObject.boolean
Tests if the specified point is inside the boundary of this JaxoObject.boolean
Tests if the specified rectangle is entirely inside the boundary of this JaxoObject.copy()
Returns an exact copy of the given JaxoObject.void
copyFrom
(JaxoObject temp) Sets all parameters from the given object to the current one.protected void
firePropertyChange
(String propertyName, Object oldValue, Object newValue) Notify all registered listeners of a changed property.Return a high-precision bounding box of this JaxoObject.Return a Rectangle that contains this object and all its handles.getColor()
Returns the color of this object.protected final GeneralPath
Returns the GeneralPath that can be used while painting this JaxoObject.int
getGrabbedHandle
(int clickX, int clickY, JaxoHandle h) Determines which handle the user has selected to move/resize/edit an object.int
Returns the height of this object.protected Point2D
getLaTexLocation
(float scaleFactor, int canvasHeight) Returns the latex (ie axodraw) coordinates of the first point of this JaxoObject.final String
getName()
Returns the name of this JaxoObject.Returns an iterator that iterates along the the shape boundary of this JaxoObject.getPathIterator
(AffineTransform at, double flatness) Returns an iterator that iterates along the the shape boundary of this JaxoObject.int
Returns the number of points it takes to draw this object.Point[]
All points, in order.int
getWidth()
Returns the width of this object.int
getX()
Returns the x coordinate of this object.int
getX
(int index) X coordinate of Point 0 <= index < getPointCount().int
getY()
Returns the y coordinate of this object.int
getY
(int index) Y coordinate of Point 0 <= index < getPointCount().boolean
intersects
(double x0, double y0, double w, double h) Test if the interior of this JaxoObject intersects the interior of the given rectangular area.boolean
Test if the interior of this JaxoObject intersects the interior of the given rectangular area.boolean
isAround
(int select, int clickX, int clickY, JaxoHandle handle) Determines if the given coordinates are contained within the given handle at the given point of this object.boolean
isCopy
(JaxoObject comp) Determines if this JaxoObject is a copy of the specified one.final boolean
isMarked()
Determines whether this JaxoObject is marked as an element of a group or not.abstract String
latexCommand
(float scale, Dimension canvasDim) The LaTeX command that is necessary to draw the given JaxoObject using the axodraw.sty package.abstract String
The LaTeX command that sets the width for this JaxoObject, using the axodraw.sty package.void
moveBy
(int deltaX, int deltaY) Reset the coordinates of the object when it is moved by deltaX and deltaY.abstract void
paint
(JaxoGraphics2D g2) The method that paints the JaxoObject.abstract void
paintHandles
(JaxoGraphics2D g2, JaxoHandle h, int editMode) Paints the handles of this JaxoObject that allow to move/resize/edit it.void
Paints a visual aid for the user during dragging (moving or resizing) of this JaxoObject.abstract void
prepareEditPanel
(JaxoObjectEditPanel editPanel) Initializes the given editPanel to edit properties of this JaxoObject.void
Set a new property.void
Remove the given PropertyChangeListener from this Object.abstract void
rescaleObject
(int orx, int ory, float scale) Rescale this JaxoObject by the scale factor scale, keeping the point (orx, ory) fixed.final void
setAsMarked
(boolean mark) Sets this JaxoObject as element of a group.void
Sets the color of this object.void
setLocation
(int newX, int newY) Sets the x and y coordinate of this object.final void
setParameter
(String name, boolean value) Invokes a setter method for the given parameter name and value.final void
setParameter
(String name, float value) Invokes a setter method for the given parameter name and value.final void
setParameter
(String name, int value) Invokes a setter method for the given parameter name and value.final void
setParameter
(String name, Color value) Invokes a setter method for the given parameter name and value.final void
setParameter
(String name, Class<?> type, Object value) Invokes a setter method for the given parameter name using reflection.final void
setParameter
(String name, Class<?> type, Object value, boolean failOnError) Invokes a setter method for the given parameter name using reflection.final void
setParameter
(String name, String value) Invokes a setter method for the given parameter name and value.void
setPointCount
(int value) Set point count; currently only used for bean creation of objects, where setPoints is used.void
Set all points; currently only used for bean creation of objects.void
Applies default values to this JaxoObject.void
Restore state to the values of 'o'.protected static void
setTransient
(Class<?> c, String[] propertyNames) Make all 'properties' in the bean info for class 'c' transient.void
setX
(int newX) Sets the x coordinate of this object.void
setX
(int index, int value) Set X coordinate of Point 0 <= index < getPointCount() to 'value'.void
setXPosition
(int newX) Deprecated.unused.void
setY
(int newY) Sets the y coordinate of this object.void
setY
(int index, int value) Set Y coordinate of Point 0 <= index < getPointCount() to 'value'.void
setYPosition
(int newY) Deprecated.unused.float
smallestDistanceTo
(int px, int py) Determines the smallest distance of any of the handles of this JaxoObject from the given point.
-
Field Details
-
SELECT_NONE
public static final int SELECT_NONEAn integer that indicates that the user did not grab any object.- See Also:
-
SELECT_P1
public static final int SELECT_P1First point (index 0).- See Also:
-
D_FORMAT
The decimal format used for numbers in LaTeX output. -
GRAY_SCALE_FORMAT
The decimal format used gray scales in LaTeX output.
-
-
Constructor Details
-
JaxoObject
public JaxoObject()
-
-
Method Details
-
addPropertyChangeListener
Add a PropertyChangeListener to this object. Whenever a bound property changes, the listeners will get notified with an Event carrying the corresponding bean name as PropertyName. The same listener object may be added more than once, and will be called as many times as it is added. If listener is null, no exception is thrown and no action is taken.- Parameters:
listener
- a listener to add.
-
removePropertyChangeListener
Remove the given PropertyChangeListener from this Object. If listener is null, or was never added, no exception is thrown and no action is taken.- Parameters:
listener
- the listener to remove.
-
firePropertyChange
Notify all registered listeners of a changed property.- Parameters:
propertyName
- the name of the changed property. This should be equal to the corresponding bean name.oldValue
- the old value.newValue
- the new value.
-
setTransient
Make all 'properties' in the bean info for class 'c' transient.- Parameters:
c
- the class.propertyNames
- set of properties to make transient.
-
getPointCount
public int getPointCount()Returns the number of points it takes to draw this object.- Returns:
- 1.
-
setPointCount
public void setPointCount(int value) Set point count; currently only used for bean creation of objects, where setPoints is used. Throws IllegalArgumentException if 'value' is not the same asgetPointCount()
.- Parameters:
value
- The value to set.
-
getPoints
All points, in order.- Returns:
- The points of this object.
- See Also:
-
setPoints
Set all points; currently only used for bean creation of objects. This implementation is based on 'setPointCount' and 'setX'/'setY'.- Parameters:
value
- The points to set.
-
getX
public int getX(int index) X coordinate of Point 0 <= index < getPointCount().- 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().- 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.- 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.- Parameters:
index
- The index of the point to set.value
- The value to set.
-
getX
public int getX()Returns the x coordinate of this object.- Returns:
- The x coordinate of this object.
-
setX
public void setX(int newX) Sets the x coordinate of this object.- Parameters:
newX
- The x coordinate of this object.
-
getY
public int getY()Returns the y coordinate of this object.- Returns:
- The y coordinate of this object.
-
setY
public void setY(int newY) Sets the y coordinate of this object.- Parameters:
newY
- The y coordinate of this object.
-
getWidth
public int getWidth()Returns the width of this object.- Returns:
- Returns 0.
-
getHeight
public int getHeight()Returns the height of this object.- Returns:
- Returns 0.
-
getColor
Returns the color of this object.- Returns:
- The color of this object.
-
setColor
Sets the color of this object. A corresponding PropertyChangeEvent is fired to all registered Listeners.- Parameters:
c
- The color of this object.
-
setLocation
public void setLocation(int newX, int newY) Sets the x and y coordinate of this object.- Parameters:
newX
- The x coordinate of this object.newY
- The y coordinate of this object.
-
getGeneralPath
Returns the GeneralPath that can be used while painting this JaxoObject.- Returns:
- The GeneralPath of this JaxoObject.
-
setAsMarked
public final void setAsMarked(boolean mark) Sets this JaxoObject as element of a group.- Parameters:
mark
- A boolean variable indicating whether this JaxoObject should be set as an element of a group or not.
-
isMarked
public final boolean isMarked()Determines whether this JaxoObject is marked as an element of a group or not.- Returns:
- Boolean variable telling whether this JaxoObject is part of a group or not
-
moveBy
public void moveBy(int deltaX, int deltaY) Reset the coordinates of the object when it is moved by deltaX and deltaY.- Parameters:
deltaX
- The x displacement.deltaY
- The y displacement.
-
setXPosition
public void setXPosition(int newX) Deprecated.unused. UsemoveBy(int,int)
instead.Moves the object to the given x position. The first point of the object will move to the given position and the other points are translated accordingly.- Parameters:
newX
- the new x position.
-
setYPosition
public void setYPosition(int newY) Deprecated.unused. UsemoveBy(int,int)
instead.Moves the object to the given y position. The first point of the object will move to the given position and the other points are translated accordingly.- Parameters:
newY
- the new y position.
-
paintVisualAid
Paints a visual aid for the user during dragging (moving or resizing) of this JaxoObject.- Parameters:
g2
- The graphics context to paint the visual aid.
-
isCopy
Determines if this JaxoObject is a copy of the specified one.- Parameters:
comp
- The JaxoObject to compare against.- Returns:
- True if the JaxoObjects are identical.
-
copyFrom
Sets all parameters from the given object to the current one.- Parameters:
temp
- The object to copy from.
-
setState
Restore state to the values of 'o'. The object 'o' must be an object of the same "type" obtained bycopy()
.- Parameters:
o
- the object to copy from.
-
smallestDistanceTo
public float smallestDistanceTo(int px, int py) Determines the smallest distance of any of the handles of this JaxoObject from the given point.- Parameters:
px
- The x coordinate of the test point.py
- The y coordinate of the test point.- Returns:
- The smallest distance.
-
copy
Returns an exact copy of the given JaxoObject. This implementation uses Object.clone(), so the only thing to do in subclasses is to recursively clone mutable object properties.- Returns:
- The copy of the given JaxoObject.
-
isAround
Determines if the given coordinates are contained within the given handle at the given point of this object.- Parameters:
select
- One of the constants SELECT_* defined for this objects.clickX
- The x coordinate of the point.clickY
- The y coordinate of the point.handle
- The test handle.- Returns:
- True if (clickX, clickY) is within the handle at the selected point, false otherwise.
-
getGrabbedHandle
Determines which handle the user has selected to move/resize/edit an object.- 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.
-
getBoundsWithHandles
Return a Rectangle that contains this object and all its handles.- Parameters:
h
- the handle.- Returns:
- a bounding box for this object with all its handles.
-
getLaTexLocation
Returns the latex (ie axodraw) coordinates of the first point of this JaxoObject.- Parameters:
scaleFactor
- A scalefactor.canvasHeight
- The current height of the canvas.- Returns:
- A Point2D.
-
setPreferences
public void setPreferences()Applies default values to this JaxoObject. All fields except location points are initialized with values taken from thepreferences
. -
getName
Returns the name of this JaxoObject. This is equal to the class name without the package.- Returns:
- the name of this JaxoObject.
-
setParameter
Invokes a setter method for the given parameter name using reflection. The setter method is constructed via standard java bean rules, ie the first character of 'name' is capitalized and the String "set" is prepended.- Parameters:
name
- the name of the parameter to set. Must not be null or empty.type
- the class type of the parameter.value
- the object value of the parameter to set.failOnError
- false if any Exceptions should be swallowed.
-
setParameter
Invokes a setter method for the given parameter name using reflection. The setter method is constructed via standard java bean rules, ie the first character of 'name' is capitalized and the String "set" is prepended. This method throws an Exception if the current JaxoObject does not support the operation, eg if no setter exists for the given parameter.- Parameters:
name
- the name of the parameter to set.type
- the class type of the parameter.value
- the object value of the parameter to set.
-
setParameter
Invokes a setter method for the given parameter name and value. This method throws an Exception if the current JaxoObject does not support the operation, eg if no setter exists for the given parameter.- Parameters:
name
- the name of the parameter to set.value
- the object value of the parameter to set.- See Also:
-
setParameter
Invokes a setter method for the given parameter name and value. This method throws an Exception if the current JaxoObject does not support the operation, eg if no setter exists for the given parameter.- Parameters:
name
- the name of the parameter to set.value
- the object value of the parameter to set.- See Also:
-
setParameter
Invokes a setter method for the given parameter name and value. This method throws an Exception if the current JaxoObject does not support the operation, eg if no setter exists for the given parameter.- Parameters:
name
- the name of the parameter to set.value
- the object value of the parameter to set.- See Also:
-
setParameter
Invokes a setter method for the given parameter name and value. This method throws an Exception if the current JaxoObject does not support the operation, eg if no setter exists for the given parameter.- Parameters:
name
- the name of the parameter to set.value
- the object value of the parameter to set.- See Also:
-
setParameter
Invokes a setter method for the given parameter name and value. This method throws an Exception if the current JaxoObject does not support the operation, eg if no setter exists for the given parameter.- Parameters:
name
- the name of the parameter to set.value
- the object value of the parameter to set.- See Also:
-
propertyChange
Set a new property. The propertyName of the PropertyChangeEvent must match one of the bean properties of this object, otherwise the event is ignored.- Specified by:
propertyChange
in interfacePropertyChangeListener
- Parameters:
evt
- the PropertyChangeEvent.
-
contains
public boolean contains(double x0, double y0) Tests if the specified coordinates are inside the boundary of this JaxoObject.- Specified by:
contains
in interfaceShape
- Parameters:
x0
- the x coordinate to test.y0
- the y coordinate to test.- Returns:
- true if
Shape.getBounds()
contains the given point.
-
contains
public boolean contains(double x0, double y0, double w, double h) Tests if the specified rectangular shape is entirely inside the boundary of this JaxoObject.- Specified by:
contains
in interfaceShape
- Parameters:
x0
- the x coordinate to test.y0
- the y coordinate to test.w
- the width of the rectangle.h
- the height of the rectangle.- Returns:
- true if
Shape.getBounds()
contains the given rectangle.
-
contains
Tests if the specified point is inside the boundary of this JaxoObject.- Specified by:
contains
in interfaceShape
- Parameters:
p
- the point to test.- Returns:
- true if
Shape.getBounds()
contains the given point.
-
contains
Tests if the specified rectangle is entirely inside the boundary of this JaxoObject.- Specified by:
contains
in interfaceShape
- Parameters:
r
- the rectangle to test.- Returns:
- true if
Shape.getBounds()
contains the given rectangle.
-
getBounds2D
Return a high-precision bounding box of this JaxoObject.- Specified by:
getBounds2D
in interfaceShape
- Returns:
- Rectangle2D
-
getPathIterator
Returns an iterator that iterates along the the shape boundary of this JaxoObject.- Specified by:
getPathIterator
in interfaceShape
- Parameters:
at
- an optional AffineTransformation to be applied to be applied to the coordinates of this object, or null for untransformed coordinates.- Returns:
- PathIterator
-
getPathIterator
Returns an iterator that iterates along the the shape boundary of this JaxoObject.- Specified by:
getPathIterator
in interfaceShape
- Parameters:
at
- an optional AffineTransformation to be applied to be applied to the coordinates of this object, or null for untransformed coordinates.flatness
- the flatness parameter.- Returns:
- PathIterator
-
intersects
public boolean intersects(double x0, double y0, double w, double h) Test if the interior of this JaxoObject intersects the interior of the given rectangular area.- Specified by:
intersects
in interfaceShape
- Parameters:
x0
- the x-coordinate of the test rectangle.y0
- the y-coordinate of the test rectangle.w
- the width of the test rectangle.h
- the height of the test rectangle.- Returns:
- true if the shapes intersect.
-
intersects
Test if the interior of this JaxoObject intersects the interior of the given rectangular area.- Specified by:
intersects
in interfaceShape
- Parameters:
r
- the rectangle to test.- Returns:
- true if the shapes intersect.
-
paint
The method that paints the JaxoObject.- Parameters:
g2
- The graphics context where the object has to be painted.
-
paintHandles
Paints the handles of this JaxoObject that allow to move/resize/edit it.- 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.
-
canBeSelected
public abstract 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.- 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.
-
latexCommand
The LaTeX command that is necessary to draw the given JaxoObject using the axodraw.sty package.- Parameters:
scale
- A scale factor to translate Java coordinates to LaTeX coordinates.canvasDim
- The current dimension of the canvas.- Returns:
- The corresponding axodraw LaTeX command.
-
latexWidth
The LaTeX command that sets the width for this JaxoObject, using the axodraw.sty package.- Returns:
- The corresponding LaTeX command.
-
rescaleObject
public abstract void rescaleObject(int orx, int ory, float scale) Rescale this JaxoObject by the scale factor scale, keeping the point (orx, ory) fixed.- Parameters:
orx
- The x-coordinate of the fixed point.ory
- The y-coordinate of the fixed point.scale
- The scale parameter.
-
prepareEditPanel
Initializes the given editPanel to edit properties of this JaxoObject.- Parameters:
editPanel
- the panel to prepare.
-