Class JaxoExtendedObject

java.lang.Object
net.sf.jaxodraw.object.JaxoObject
net.sf.jaxodraw.object.JaxoExtendedObject
All Implemented Interfaces:
Shape, PropertyChangeListener, Serializable, Cloneable, EventListener
Direct Known Subclasses:
JaxoFillObject, JaxoGroup, JaxoParticleObject, JaxoVertex

public abstract class JaxoExtendedObject extends JaxoObject
A JaxoObject with at least two points.
Since:
2.0
See Also:
  • Field Details

    • SELECT_DX

      public static final int SELECT_DX
      A point with coordinates (x,y2).
      See Also:
    • SELECT_DY

      public static final int SELECT_DY
      A point with coordinates (x2,y).
      See Also:
    • SELECT_P2

      public static final int SELECT_P2
      Second point (index 1).
      See Also:
  • Constructor Details

    • JaxoExtendedObject

      public JaxoExtendedObject()
  • Method Details

    • getPointCount

      public int getPointCount()
      Returns the number of points it takes to draw this object.
      Overrides:
      getPointCount in class JaxoObject
      Returns:
      2.
    • getX

      public int getX(int index)
      X coordinate of Point 0 <= index < getPointCount().
      Overrides:
      getX in class JaxoObject
      Parameters:
      index - The index of the point to get.
      Returns:
      The x coordinate of the point at the given index.
    • getY

      public int getY(int index)
      Y coordinate of Point 0 <= index < getPointCount().
      Overrides:
      getY in class JaxoObject
      Parameters:
      index - The index of the point to get.
      Returns:
      The y coordinate of the point at the given index.
    • setX

      public void setX(int index, int value)
      Set X coordinate of Point 0 <= index < getPointCount() to 'value'. Throws IllegalArgumentException if the index is not valid for the given object.
      Overrides:
      setX in class JaxoObject
      Parameters:
      index - The index of the point to set.
      value - The value to set.
    • setY

      public void setY(int index, int value)
      Set Y coordinate of Point 0 <= index < getPointCount() to 'value'. Throws IllegalArgumentException if the index is not valid for the given object.
      Overrides:
      setY in class JaxoObject
      Parameters:
      index - The index of the point to set.
      value - The value to set.
    • getX2

      public final int getX2()
      Returns the x2 coordinate of this object.
      Returns:
      The x2 coordinate of this object.
    • setX2

      public final void setX2(int newX2)
      Sets the x2 coordinate of this object.
      Parameters:
      newX2 - The x2 coordinate of this object.
    • getY2

      public final int getY2()
      Returns the y2 coordinate of this object.
      Returns:
      The y2 coordinate of this object.
    • setY2

      public final void setY2(int newY2)
      Sets the y2 coordinate of this object.
      Parameters:
      newY2 - The y2 coordinate of this object.
    • getStrokeWidth

      public final float getStrokeWidth()
      Returns the stroke width property of this particle object.
      Returns:
      The stroke width property of this particle object.
    • setStrokeWidth

      public void setStrokeWidth(float newStroke)
      Sets the stroke width property of this particle object.
      Parameters:
      newStroke - The stroke width property of this particle object.
    • getWidth

      public final int getWidth()
      Returns the width of this object.
      Overrides:
      getWidth in class JaxoObject
      Returns:
      The width of this object.
    • getHeight

      public final int getHeight()
      Returns the height of this object.
      Overrides:
      getHeight in class JaxoObject
      Returns:
      The height of this object.
    • getRelw

      public final int getRelw()
      Returns the relative width of this object.
      Returns:
      The relative width of this object.
    • getRelh

      public final int getRelh()
      Returns the relative height of this object.
      Returns:
      The relative height of this object.
    • setRelWAndH

      public final void setRelWAndH(int w, int h)
      Sets the relative width and height of this object.
      Parameters:
      w - The relative width of this object.
      h - The relative height of this object.
    • setRelativeWidth

      public final void setRelativeWidth(int w)
      Deprecated.
      unused. Use setX2(int) or setRelWAndH(int,int) instead.
      Sets the relative width of this object.
      Parameters:
      w - The relative width of this object.
    • setRelativeHeight

      public final void setRelativeHeight(int h)
      Deprecated.
      unused. Use setY2(int) or setRelWAndH(int,int) instead.
      Sets the relative height of this object.
      Parameters:
      h - The relative heigh of this object.
    • setRadius

      public void setRadius(float newRadius)
      Convenience method for setting the 'radius' of a 2 point object. This keeps the first point of this object fixed and adjusts the second point such that the distance between the two is newRadius.
      Parameters:
      newRadius - The radius to set.
    • getRadius

      public double getRadius()
      Convenience method for getting the radius of a 2 point object, ie the distance between the first two points.
      Returns:
      The radius.
    • setLocation

      public final void setLocation(int newX, int newY, int newX2, int newY2)
      Sets the position coordinates of this object.
      Parameters:
      newX - The x coordinate of this object.
      newY - The y coordinate of this object.
      newX2 - The x2 coordinate of this object.
      newY2 - The y2 coordinate of this object.
    • moveBy

      public void moveBy(int deltaX, int deltaY)
      Reset the coordinates of the object when it is moved by deltaX and deltaY.
      Overrides:
      moveBy in class JaxoObject
      Parameters:
      deltaX - The x displacement.
      deltaY - The y displacement.
    • getSize

      public final Dimension getSize()
      Returns the width and height of this object.
      Returns:
      A dimension with the size of the object.
    • getRelSize

      public final Dimension getRelSize()
      Returns the relative width and height of this object.
      Returns:
      A dimension with the relative size of the object.
    • isCopy

      public boolean isCopy(JaxoObject comp)
      Determines if this JaxoObject is a copy of the specified one.
      Overrides:
      isCopy in class JaxoObject
      Parameters:
      comp - The JaxoObject to compare against.
      Returns:
      True if the JaxoObjects are identical.
    • copyFrom

      public void copyFrom(JaxoExtendedObject 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 JaxoObject.copy().
      Overrides:
      setState in class JaxoObject
      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.
      Overrides:
      smallestDistanceTo in class JaxoObject
      Parameters:
      px - The x coordinate of the test point.
      py - The y coordinate of the test point.
      Returns:
      The smallest distance.
    • getGrabbedHandle

      public int getGrabbedHandle(int clickX, int clickY, JaxoHandle h)
      Determines which handle the user has selected to move/resize/edit an object.
      Overrides:
      getGrabbedHandle in class JaxoObject
      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.
    • paintHandles

      public void paintHandles(JaxoGraphics2D g2, JaxoHandle h, int editMode)
      Paints the handles of this JaxoObject that allow to move/resize/edit it.
      Specified by:
      paintHandles in class JaxoObject
      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 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.
      Specified by:
      canBeSelected in class JaxoObject
      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.
    • latexWidth

      public String latexWidth()
      The LaTeX command that sets the width for this JaxoObject, using the axodraw.sty package.
      Specified by:
      latexWidth in class JaxoObject
      Returns:
      The corresponding LaTeX command.
    • setPreferences

      public void setPreferences()
      Applies default values to this JaxoObject. All fields except location points are initialized with values taken from the preferences.
      Overrides:
      setPreferences in class JaxoObject
    • strokeIs

      public final boolean strokeIs(float comp)
      Compares the stroke of this JaxoExtendedObject to the given float, taking into account a 0.1% error margin.
      Parameters:
      comp - The float to compare to.
      Returns:
      True, if the stroke matches within 0.1%.
    • getStroke

      protected final BasicStroke getStroke()
      Returns the stroke of this particle object.
      Returns:
      The stroke of this particle object.
    • setStroke

      protected final void setStroke(BasicStroke newStroke)
      Sets the stroke of this particle object.
      Parameters:
      newStroke - The strokeof this particle object.
    • resetStroke

      protected void resetStroke()
      Resets the stroke to a default BasicStroke with current width. This should be overridden by objects that use a different stroke.