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 DecimalFormatThe decimal format used for numbers in LaTeX output.static final DecimalFormatThe decimal format used gray scales in LaTeX output.static final intAn integer that indicates that the user did not grab any object.static final intFirst point (index 0). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a PropertyChangeListener to this object.abstract booleancanBeSelected(int handle, int mode) Determines if the object can be selected (moved, edited, etc) from the given point in a given edit mode.booleancontains(double x0, double y0) Tests if the specified coordinates are inside the boundary of this JaxoObject.booleancontains(double x0, double y0, double w, double h) Tests if the specified rectangular shape is entirely inside the boundary of this JaxoObject.booleanTests if the specified point is inside the boundary of this JaxoObject.booleanTests if the specified rectangle is entirely inside the boundary of this JaxoObject.copy()Returns an exact copy of the given JaxoObject.voidcopyFrom(JaxoObject temp) Sets all parameters from the given object to the current one.protected voidfirePropertyChange(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 GeneralPathReturns the GeneralPath that can be used while painting this JaxoObject.intgetGrabbedHandle(int clickX, int clickY, JaxoHandle h) Determines which handle the user has selected to move/resize/edit an object.intReturns the height of this object.protected Point2DgetLaTexLocation(float scaleFactor, int canvasHeight) Returns the latex (ie axodraw) coordinates of the first point of this JaxoObject.final StringgetName()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.intReturns the number of points it takes to draw this object.Point[]All points, in order.intgetWidth()Returns the width of this object.intgetX()Returns the x coordinate of this object.intgetX(int index) X coordinate of Point 0 invalid input: '<'= index invalid input: '<' getPointCount().intgetY()Returns the y coordinate of this object.intgetY(int index) Y coordinate of Point 0 invalid input: '<'= index invalid input: '<' getPointCount().booleanintersects(double x0, double y0, double w, double h) Test if the interior of this JaxoObject intersects the interior of the given rectangular area.booleanTest if the interior of this JaxoObject intersects the interior of the given rectangular area.booleanisAround(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.booleanisCopy(JaxoObject comp) Determines if this JaxoObject is a copy of the specified one.final booleanisMarked()Determines whether this JaxoObject is marked as an element of a group or not.abstract StringlatexCommand(float scale, Dimension canvasDim) The LaTeX command that is necessary to draw the given JaxoObject using the axodraw.sty package.abstract StringThe LaTeX command that sets the width for this JaxoObject, using the axodraw.sty package.voidmoveBy(int deltaX, int deltaY) Reset the coordinates of the object when it is moved by deltaX and deltaY.abstract voidpaint(JaxoGraphics2D g2) The method that paints the JaxoObject.abstract voidpaintHandles(JaxoGraphics2D g2, JaxoHandle h, int editMode) Paints the handles of this JaxoObject that allow to move/resize/edit it.voidPaints a visual aid for the user during dragging (moving or resizing) of this JaxoObject.abstract voidprepareEditPanel(JaxoObjectEditPanel editPanel) Initializes the given editPanel to edit properties of this JaxoObject.voidSet a new property.voidRemove the given PropertyChangeListener from this Object.abstract voidrescaleObject(int orx, int ory, float scale) Rescale this JaxoObject by the scale factor scale, keeping the point (orx, ory) fixed.final voidsetAsMarked(boolean mark) Sets this JaxoObject as element of a group.voidSets the color of this object.voidsetLocation(int newX, int newY) Sets the x and y coordinate of this object.final voidsetParameter(String name, boolean value) Invokes a setter method for the given parameter name and value.final voidsetParameter(String name, float value) Invokes a setter method for the given parameter name and value.final voidsetParameter(String name, int value) Invokes a setter method for the given parameter name and value.final voidsetParameter(String name, Color value) Invokes a setter method for the given parameter name and value.final voidsetParameter(String name, Class<?> type, Object value) Invokes a setter method for the given parameter name using reflection.final voidsetParameter(String name, Class<?> type, Object value, boolean failOnError) Invokes a setter method for the given parameter name using reflection.final voidsetParameter(String name, String value) Invokes a setter method for the given parameter name and value.voidsetPointCount(int value) Set point count; currently only used for bean creation of objects, where setPoints is used.voidSet all points; currently only used for bean creation of objects.voidApplies default values to this JaxoObject.voidRestore state to the values of 'o'.protected static voidsetTransient(Class<?> c, String[] propertyNames) Make all 'properties' in the bean info for class 'c' transient.voidsetX(int newX) Sets the x coordinate of this object.voidsetX(int index, int value) Set X coordinate of Point 0 invalid input: '<'= index invalid input: '<' getPointCount() to 'value'.voidsetXPosition(int newX) Deprecated.unused.voidsetY(int newY) Sets the y coordinate of this object.voidsetY(int index, int value) Set Y coordinate of Point 0 invalid input: '<'= index invalid input: '<' getPointCount() to 'value'.voidsetYPosition(int newY) Deprecated.unused.floatsmallestDistanceTo(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
-
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
-
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 invalid input: '<'= index invalid input: '<' 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 invalid input: '<'= index invalid input: '<' 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 invalid input: '<'= index invalid input: '<' 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 invalid input: '<'= index invalid input: '<' 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
-
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:
propertyChangein 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:
containsin 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:
containsin 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:
containsin 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:
containsin 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:
getBounds2Din interfaceShape- Returns:
- Rectangle2D
-
getPathIterator
Returns an iterator that iterates along the the shape boundary of this JaxoObject.- Specified by:
getPathIteratorin 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:
getPathIteratorin 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:
intersectsin 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:
intersectsin 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.
-