Package net.sf.jaxodraw.object
Class JaxoObject
- java.lang.Object
-
- net.sf.jaxodraw.object.JaxoObject
-
- All Implemented Interfaces:
java.awt.Shape,java.beans.PropertyChangeListener,java.io.Serializable,java.lang.Cloneable,java.util.EventListener
- Direct Known Subclasses:
JaxoExtendedObject,JaxoTextObject
public abstract class JaxoObject extends java.lang.Object implements java.io.Serializable, java.lang.Cloneable, java.awt.Shape, java.beans.PropertyChangeListenerA general JaxoObject.- Since:
- 2.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.text.DecimalFormatD_FORMATThe decimal format used for numbers in LaTeX output.static java.text.DecimalFormatGRAY_SCALE_FORMATThe decimal format used gray scales in LaTeX output.static intSELECT_NONEAn integer that indicates that the user did not grab any object.static intSELECT_P1First point (index 0).
-
Constructor Summary
Constructors Constructor Description JaxoObject()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)Add 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.booleancontains(java.awt.geom.Point2D p)Tests if the specified point is inside the boundary of this JaxoObject.booleancontains(java.awt.geom.Rectangle2D r)Tests if the specified rectangle is entirely inside the boundary of this JaxoObject.JaxoObjectcopy()Returns an exact copy of the given JaxoObject.voidcopyFrom(JaxoObject temp)Sets all parameters from the given object to the current one.protected voidfirePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)Notify all registered listeners of a changed property.java.awt.geom.Rectangle2DgetBounds2D()Return a high-precision bounding box of this JaxoObject.java.awt.geom.Rectangle2DgetBoundsWithHandles(JaxoHandle h)Return a Rectangle that contains this object and all its handles.java.awt.ColorgetColor()Returns the color of this object.protected java.awt.geom.GeneralPathgetGeneralPath()Returns 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.intgetHeight()Returns the height of this object.protected java.awt.geom.Point2DgetLaTexLocation(float scaleFactor, int canvasHeight)Returns the latex (ie axodraw) coordinates of the first point of this JaxoObject.java.lang.StringgetName()Returns the name of this JaxoObject.java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at)Returns an iterator that iterates along the the shape boundary of this JaxoObject.java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at, double flatness)Returns an iterator that iterates along the the shape boundary of this JaxoObject.intgetPointCount()Returns the number of points it takes to draw this object.java.awt.Point[]getPoints()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 <= index < getPointCount().intgetY()Returns the y coordinate of this object.intgetY(int index)Y coordinate of Point 0 <= index < 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.booleanintersects(java.awt.geom.Rectangle2D r)Test 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.booleanisMarked()Determines whether this JaxoObject is marked as an element of a group or not.abstract java.lang.StringlatexCommand(float scale, java.awt.Dimension canvasDim)The LaTeX command that is necessary to draw the given JaxoObject using the axodraw.sty package.abstract java.lang.StringlatexWidth()The 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.voidpaintVisualAid(JaxoGraphics2D g2)Paints 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.voidpropertyChange(java.beans.PropertyChangeEvent evt)Set a new property.voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)Remove 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.voidsetAsMarked(boolean mark)Sets this JaxoObject as element of a group.voidsetColor(java.awt.Color c)Sets the color of this object.voidsetLocation(int newX, int newY)Sets the x and y coordinate of this object.voidsetParameter(java.lang.String name, boolean value)Invokes a setter method for the given parameter name and value.voidsetParameter(java.lang.String name, float value)Invokes a setter method for the given parameter name and value.voidsetParameter(java.lang.String name, int value)Invokes a setter method for the given parameter name and value.voidsetParameter(java.lang.String name, java.awt.Color value)Invokes a setter method for the given parameter name and value.voidsetParameter(java.lang.String name, java.lang.Class<?> type, java.lang.Object value)Invokes a setter method for the given parameter name using reflection.voidsetParameter(java.lang.String name, java.lang.Class<?> type, java.lang.Object value, boolean failOnError)Invokes a setter method for the given parameter name using reflection.voidsetParameter(java.lang.String name, java.lang.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.voidsetPoints(java.awt.Point[] value)Set all points; currently only used for bean creation of objects.voidsetPreferences()Applies default values to this JaxoObject.voidsetState(JaxoObject o)Restore state to the values of 'o'.protected static voidsetTransient(java.lang.Class<?> c, java.lang.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 <= index < 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 <= index < 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 Detail
-
SELECT_NONE
public static final int SELECT_NONE
An integer that indicates that the user did not grab any object.- See Also:
- Constant Field Values
-
SELECT_P1
public static final int SELECT_P1
First point (index 0).- See Also:
- Constant Field Values
-
D_FORMAT
public static final java.text.DecimalFormat D_FORMAT
The decimal format used for numbers in LaTeX output.
-
GRAY_SCALE_FORMAT
public static final java.text.DecimalFormat GRAY_SCALE_FORMAT
The decimal format used gray scales in LaTeX output.
-
-
Method Detail
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
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
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
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
protected void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)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
protected static void setTransient(java.lang.Class<?> c, java.lang.String[] propertyNames)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
public java.awt.Point[] getPoints()
All points, in order.- Returns:
- The points of this object.
- See Also:
getPointCount(),getX(int),getY(int)
-
setPoints
public void setPoints(java.awt.Point[] value)
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
public java.awt.Color getColor()
Returns the color of this object.- Returns:
- The color of this object.
-
setColor
public void setColor(java.awt.Color c)
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
protected final java.awt.geom.GeneralPath 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
public void paintVisualAid(JaxoGraphics2D g2)
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
public boolean isCopy(JaxoObject comp)
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
public void copyFrom(JaxoObject 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 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
public JaxoObject 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
public 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.- 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
public int getGrabbedHandle(int clickX, int clickY, JaxoHandle h)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
public java.awt.geom.Rectangle2D getBoundsWithHandles(JaxoHandle h)
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
protected java.awt.geom.Point2D getLaTexLocation(float scaleFactor, int canvasHeight)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
public final java.lang.String getName()
Returns the name of this JaxoObject. This is equal to the class name without the package.- Returns:
- the name of this JaxoObject.
-
setParameter
public final void setParameter(java.lang.String name, java.lang.Class<?> type, java.lang.Object value, boolean failOnError)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
public final void setParameter(java.lang.String name, java.lang.Class<?> type, java.lang.Object value)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
public final void setParameter(java.lang.String name, int value)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(String,Class,Object)
-
setParameter
public final void setParameter(java.lang.String name, float value)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(String,Class,Object)
-
setParameter
public final void setParameter(java.lang.String name, boolean value)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(String,Class,Object)
-
setParameter
public final void setParameter(java.lang.String name, java.awt.Color value)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(String,Class,Object)
-
setParameter
public final void setParameter(java.lang.String name, java.lang.String value)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(String,Class,Object)
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
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 interfacejava.beans.PropertyChangeListener- 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 interfacejava.awt.Shape- 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 interfacejava.awt.Shape- 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
public boolean contains(java.awt.geom.Point2D p)
Tests if the specified point is inside the boundary of this JaxoObject.- Specified by:
containsin interfacejava.awt.Shape- Parameters:
p- the point to test.- Returns:
- true if
Shape.getBounds()contains the given point.
-
contains
public boolean contains(java.awt.geom.Rectangle2D r)
Tests if the specified rectangle is entirely inside the boundary of this JaxoObject.- Specified by:
containsin interfacejava.awt.Shape- Parameters:
r- the rectangle to test.- Returns:
- true if
Shape.getBounds()contains the given rectangle.
-
getBounds2D
public java.awt.geom.Rectangle2D getBounds2D()
Return a high-precision bounding box of this JaxoObject.- Specified by:
getBounds2Din interfacejava.awt.Shape- Returns:
- Rectangle2D
-
getPathIterator
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
Returns an iterator that iterates along the the shape boundary of this JaxoObject.- Specified by:
getPathIteratorin interfacejava.awt.Shape- 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
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)Returns an iterator that iterates along the the shape boundary of this JaxoObject.- Specified by:
getPathIteratorin interfacejava.awt.Shape- 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 interfacejava.awt.Shape- 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
public boolean intersects(java.awt.geom.Rectangle2D r)
Test if the interior of this JaxoObject intersects the interior of the given rectangular area.- Specified by:
intersectsin interfacejava.awt.Shape- Parameters:
r- the rectangle to test.- Returns:
- true if the shapes intersect.
-
paint
public abstract void paint(JaxoGraphics2D g2)
The method that paints the JaxoObject.- Parameters:
g2- The graphics context where the object has to be painted.
-
paintHandles
public abstract void paintHandles(JaxoGraphics2D g2, JaxoHandle h, int editMode)
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
public abstract java.lang.String latexCommand(float scale, java.awt.Dimension canvasDim)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
public abstract java.lang.String 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
public abstract void prepareEditPanel(JaxoObjectEditPanel editPanel)
Initializes the given editPanel to edit properties of this JaxoObject.- Parameters:
editPanel- the panel to prepare.
-
-