Class LineItem

java.lang.Object
edu.cnu.mdi.item.AItem
edu.cnu.mdi.item.LineItem
All Implemented Interfaces:
IFeedbackProvider, IDrawable, EventListener

public class LineItem extends AItem
A simple AItem representing a world-coordinate line segment.

The line geometry is stored in AItem._line (world coordinates). Rendering and hit-testing are performed in screen space via the supplied IContainer transforms.

This item supports ItemModificationType DRAG and ItemModificationType RESIZE modifications. Rotation is currently a no-op (consistent with the prior implementation).

  • Constructor Details

    • LineItem

      public LineItem(Layer layer, Point2D.Double wp0, Point2D.Double wp1)
      Create a world line object.
      Parameters:
      layer - the layer this item is on.
      wp0 - start of the line.
      wp1 - end of the line of the line.
    • LineItem

      public LineItem(Layer layer, Point2D.Double wp0, Point2D.Double wp1, Object... keyVals)
      Create a world line object.
      Parameters:
      layer - the layer this item is on.
      wp0 - start of the line.
      wp1 - end of the line of the line.
      keyVals - optional key-value pairs to set on the item. For example, you could use this to set the display name, style, or other properties at construction time. The keys should be from the set of standard keys defined in PropertyUtils, or any custom keys recognized by this item or its style.
  • Method Details

    • 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.
    • 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.
    • getSelectionPoints

      public Point[] getSelectionPoints(IContainer container)
      Obtain the selection points used to indicate this item is selected.
      Overrides:
      getSelectionPoints in class AItem
      Parameters:
      container - the container rendering this item
      Returns:
      the selection points used to indicate this item is selected.
    • modify

      public void modify()
      A modification such as a drag, resize or rotate is continuing.
      Specified by:
      modify in class AItem
    • 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
    • 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.
    • 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