Class PathBasedItem

java.lang.Object
edu.cnu.mdi.item.AItem
edu.cnu.mdi.item.PathBasedItem
All Implemented Interfaces:
IFeedbackProvider, IDrawable, EventListener
Direct Known Subclasses:
PolygonItem, PolylineItem

public class PathBasedItem extends AItem
Base class for items whose geometry is a Path2D.Double in world coordinates, stored in AItem._path.

Implements AItem.modify() for all three ItemModification.ModificationType kinds:

  • DRAG — translates the path (and the item's focus, if any) by the world-coordinate delta between the modification's start and current mouse points.
  • ROTATE — rotates the path about the modification's anchor point by the signed angle between the start and current mouse points (see threePointAngle(java.awt.Point, java.awt.Point, java.awt.Point)), and updates the item's azimuth.
  • RESIZE — delegates to scale() when shift/control is held or the item's ResizePolicy is SCALEONLY; otherwise delegates to reshape(), which subclasses may override to keep a type-specific shape (e.g. a rectangle item resizing without shearing into a general quadrilateral). The default reshape() just calls scale().

Concrete subclasses are expected to build _path in their own constructors/setters and typically only need to override reshape() (and occasionally getBounds(edu.cnu.mdi.container.IContainer)) to specialize resize behavior; drawItem(java.awt.Graphics2D, edu.cnu.mdi.container.IContainer), contains(edu.cnu.mdi.container.IContainer, java.awt.Point), modify(), and rotate(double) are already implemented generically in terms of _path.

  • Constructor Details

    • PathBasedItem

      public PathBasedItem(Layer layer)
      Create an object that is based on a java Path2D object.
      Parameters:
      layer - the z layer this item is on.
    • PathBasedItem

      public PathBasedItem(Layer layer, Object... keyVals)
      Create an object that is based on a java Path2D object.
      Parameters:
      layer - the z layer this item is on.
      keyVals - optional key value pairs to set properties of the item. See AItem(Layer, Object...) for details.
  • Method Details

    • drawItem

      public void drawItem(Graphics2D g2, IContainer container)
      Custom drawer for the item.
      Specified by:
      drawItem in class AItem
      Parameters:
      g2 - the graphics context.
      container - the graphical container being rendered.
    • shouldDraw

      public boolean shouldDraw(Graphics2D g2, IContainer container)
      Checks whether the item should be drawn. This is an additional check, beyond the simple visibility flag check. For example, it might check whether the item intersects the area being drawn.
      Specified by:
      shouldDraw in class AItem
      Parameters:
      g2 - the graphics context.
      container - the graphical container being rendered.
      Returns:
      true if the item passes any and all tests, and should be drawn.
    • contains

      public boolean contains(IContainer container, Point screenPoint)
      Check whether the (rendered) item contains the given screen point.
      Overrides:
      contains in class AItem
      Parameters:
      container - the graphical container rendering the item.
      screenPoint - a pixel location.
      Returns:
      true if the item, as rendered on the given container, contains the given screen point.
    • getBounds

      public Rectangle getBounds(IContainer container)
      get the bounding rect.
      Overrides:
      getBounds in class AItem
      Parameters:
      container - the container being rendered
      Returns:
      the bounding box.
    • getRotatePoint

      public Point getRotatePoint(IContainer container)
      Get the rotation point
      Overrides:
      getRotatePoint in class AItem
      Parameters:
      container - the container bing rendered
      Returns:
      the rotation point where rotations are initiated
    • modify

      public void modify()
      A modification such as a drag, resize or rotate is continuing.
      Specified by:
      modify in class AItem
    • rotate

      public void rotate(double angle)
      Rotate the item
      Parameters:
      angle - the angle in degrees
    • scale

      protected void scale()
      Simple scaling of the object.
    • reshape

      protected void reshape()
      Reshape the items based on the modification. This is type dependent-- for example a rectangle will want to keep looking like a rectangle. The default implementation is to scale
    • updateFocus

      protected void updateFocus()
      Description copied from class: AItem
      Hook called when geometry changes and the focus should be recomputed. The default implementation is a no-op.
      Overrides:
      updateFocus in class AItem
    • threePointAngle

      protected double threePointAngle(Point p1, Point vertex, Point p2)
      Give two points (presumably the start and current mouse positions) and a vertex (presumable the focus as a pixel point) this computes and angle. Give the assumptions above, it is how much the original path will need to be rotated.
      Parameters:
      p1 - one end point
      vertex - the vertex point
      p2 - the other end point
      Returns:
      the angle in degrees.
    • getWorldBounds

      public Rectangle2D.Double getWorldBounds()
      Get the world bounding rectangle of the item.
      Specified by:
      getWorldBounds in class AItem
      Returns:
      the world box containing the item.
    • singlePointBounds

      protected Rectangle singlePointBounds(IContainer container)
      Get the bounds if the path contains only a single point
      Parameters:
      container - the container being rendered.
      Returns:
      the bounds if the path contains only a single point
    • translateWorld

      public void translateWorld(double dx, double dy)
      Description copied from class: AItem
      Translate this item by (dx, dy) in world coordinates.
      Specified by:
      translateWorld in class AItem
      Parameters:
      dx - the world-coordinate offset along the X axis
      dy - the world-coordinate offset along the Y axis