net.sf.jaxodraw.object
Class JaxoObject

java.lang.Object
  extended by 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:
Serialized Form

Field Summary
static DecimalFormat D_FORMAT
          The decimal format used for numbers in LaTeX output.
static DecimalFormat GRAY_SCALE_FORMAT
          The decimal format used gray scales in LaTeX output.
static int SELECT_NONE
          An integer that indicates that the user did not grab any object.
static int SELECT_P1
          First point (index 0).
 
Constructor Summary
JaxoObject()
           
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          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 contains(Point2D p)
          Tests if the specified point is inside the boundary of this JaxoObject.
 boolean contains(Rectangle2D r)
          Tests if the specified rectangle is entirely inside the boundary of this JaxoObject.
 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.
 Rectangle2D getBounds2D()
          Return a high-precision bounding box of this JaxoObject.
 Rectangle2D getBoundsWithHandles(JaxoHandle h)
          Return a Rectangle that contains this object and all its handles.
 Color getColor()
          Returns the color of this object.
protected  GeneralPath getGeneralPath()
          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 getHeight()
          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.
 String getName()
          Returns the name of this JaxoObject.
 PathIterator getPathIterator(AffineTransform at)
          Returns an iterator that iterates along the the shape boundary of this JaxoObject.
 PathIterator getPathIterator(AffineTransform at, double flatness)
          Returns an iterator that iterates along the the shape boundary of this JaxoObject.
 int getPointCount()
          Returns the number of points it takes to draw this object.
 Point[] getPoints()
          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 intersects(Rectangle2D r)
          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.
 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 latexWidth()
          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 paintVisualAid(JaxoGraphics2D g2)
          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 propertyChange(PropertyChangeEvent evt)
          Set a new property.
 void removePropertyChangeListener(PropertyChangeListener listener)
          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.
 void setAsMarked(boolean mark)
          Sets this JaxoObject as element of a group.
 void setColor(Color c)
          Sets the color of this object.
 void setLocation(int newX, int newY)
          Sets the x and y coordinate of this object.
 void setParameter(String name, boolean value)
          Invokes a setter method for the given parameter name and value.
 void setParameter(String name, Class<?> type, Object value)
          Invokes a setter method for the given parameter name using reflection.
 void setParameter(String name, Class<?> type, Object value, boolean failOnError)
          Invokes a setter method for the given parameter name using reflection.
 void setParameter(String name, Color value)
          Invokes a setter method for the given parameter name and value.
 void setParameter(String name, float value)
          Invokes a setter method for the given parameter name and value.
 void setParameter(String name, int value)
          Invokes a setter method for the given parameter name and value.
 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 setPoints(Point[] value)
          Set all points; currently only used for bean creation of objects.
 void setPreferences()
          Applies default values to this JaxoObject.
 void setState(JaxoObject o)
          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. Use moveBy(int,int) instead.
 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. Use moveBy(int,int) instead.
 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 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_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 DecimalFormat D_FORMAT
The decimal format used for numbers in LaTeX output.


GRAY_SCALE_FORMAT

public static final DecimalFormat GRAY_SCALE_FORMAT
The decimal format used gray scales in LaTeX output.

Constructor Detail

JaxoObject

public JaxoObject()
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(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(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(String propertyName,
                                  Object oldValue,
                                  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(Class<?> c,
                                   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 as getPointCount().

Parameters:
value - The value to set.

getPoints

public Point[] getPoints()
All points, in order.

Returns:
The points of this object.
See Also:
getPointCount(), getX(int), getY(int)

setPoints

public void setPoints(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 Color getColor()
Returns the color of this object.

Returns:
The color of this object.

setColor

public void setColor(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 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. Use moveBy(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. Use moveBy(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 by copy().

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 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 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 the preferences.


getName

public final 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(String name,
                               Class<?> type,
                               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(String name,
                               Class<?> type,
                               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(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(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(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(String name,
                               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(String name,
                               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(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:
propertyChange in interface 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:
contains in interface Shape
Parameters:
x0 - the x coordinate to test.
y0 - the y coordinate to test.
Returns:
true if Shape.getBounds() contains the given point.
See Also:
Shape.contains(double,double).

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 interface 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.
See Also:
Shape.contains(double,double,double,double).

contains

public boolean contains(Point2D p)
Tests if the specified point is inside the boundary of this JaxoObject.

Specified by:
contains in interface Shape
Parameters:
p - the point to test.
Returns:
true if Shape.getBounds() contains the given point.
See Also:
Shape.contains(java.awt.geom.Point2D).

contains

public boolean contains(Rectangle2D r)
Tests if the specified rectangle is entirely inside the boundary of this JaxoObject.

Specified by:
contains in interface Shape
Parameters:
r - the rectangle to test.
Returns:
true if Shape.getBounds() contains the given rectangle.
See Also:
Shape.contains(java.awt.geom.Rectangle2D).

getBounds2D

public Rectangle2D getBounds2D()
Return a high-precision bounding box of this JaxoObject.

Specified by:
getBounds2D in interface Shape
Returns:
Rectangle2D
See Also:
Shape.getBounds2D().

getPathIterator

public PathIterator getPathIterator(AffineTransform at)
Returns an iterator that iterates along the the shape boundary of this JaxoObject.

Specified by:
getPathIterator in interface 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
See Also:
Shape.getPathIterator(java.awt.geom.AffineTransform).

getPathIterator

public PathIterator getPathIterator(AffineTransform at,
                                    double flatness)
Returns an iterator that iterates along the the shape boundary of this JaxoObject.

Specified by:
getPathIterator in interface 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
See Also:
Shape.getPathIterator(java.awt.geom.AffineTransform,double).

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 interface 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.
See Also:
Shape.intersects(double,double,double,double).

intersects

public boolean intersects(Rectangle2D r)
Test if the interior of this JaxoObject intersects the interior of the given rectangular area.

Specified by:
intersects in interface Shape
Parameters:
r - the rectangle to test.
Returns:
true if the shapes intersect.
See Also:
Shape.intersects(java.awt.geom.Rectangle2D).

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 String latexCommand(float scale,
                                    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 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.


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