Class Polyline

All Implemented Interfaces:
IFigure
Direct Known Subclasses:
Polygon, PolylineConnection, PolylineDecoration

public class Polyline extends AbstractPointListShape
Renders a PointList as a series of line segments. A Polyline figure should be positioned by manipulating its points, NOT by calling Figure.setBounds(Rectangle).

A polyline's bounds will be calculated automatically based on its PointList. The bounds will be the smallest Rectangle large enough to render the line properly. Children should not be added to a Polyline and will not affect the bounds calculation.

  • Constructor Details

    • Polyline

      public Polyline()
  • Method Details

    • containsPoint

      public boolean containsPoint(int x, int y)
      Description copied from interface: IFigure
      Returns true if the point (x, y) is contained within this IFigure's bounds.
      Specified by:
      containsPoint in interface IFigure
      Overrides:
      containsPoint in class AbstractPointListShape
      Parameters:
      x - The X coordinate
      y - The Y coordinate
      Returns:
      true if the point (x,y) is contained in this IFigure's bounds
      See Also:
    • shapeContainsPoint

      protected boolean shapeContainsPoint(int x, int y)
      Description copied from class: AbstractPointListShape
      Returns true if the point (x, y) is contained within this figure.
      Specified by:
      shapeContainsPoint in class AbstractPointListShape
      Parameters:
      x - The X coordinate
      y - The Y coordinate
      Returns:
      true if the point (x,y) is contained in this figure
    • fillShape

      protected void fillShape(Graphics g)
      Null implementation for a line.
      Specified by:
      fillShape in class Shape
      Parameters:
      g - the graphics object
      See Also:
    • getBounds

      public Rectangle getBounds()
      Description copied from class: Figure
      Returns the smallest rectangle completely enclosing the figure. Implementors may return the Rectangle by reference. For this reason, callers of this method must not modify the returned Rectangle.
      Specified by:
      getBounds in interface IFigure
      Overrides:
      getBounds in class Figure
      Returns:
      The bounds of this Figure
      See Also:
    • isOpaque

      public boolean isOpaque()
      Description copied from interface: IFigure
      Returns true if this IFigure is opaque.
      Specified by:
      isOpaque in interface IFigure
      Overrides:
      isOpaque in class Figure
      Returns:
      false because Polyline's aren't filled
      See Also:
    • outlineShape

      protected void outlineShape(Graphics g)
      Description copied from class: Shape
      Outlines this shape using the foreground color.
      Specified by:
      outlineShape in class Shape
      Parameters:
      g - the graphics object
      See Also:
    • primTranslate

      public void primTranslate(int x, int y)
      Description copied from class: Figure
      Translates this Figure's bounds, without firing a move.
      Overrides:
      primTranslate in class Figure
      Parameters:
      x - The amount to translate horizontally
      y - The amount to translate vertically
      See Also:
    • removeAllPoints

      public void removeAllPoints()
      Erases the Polyline and removes all of its Points.
      Overrides:
      removeAllPoints in class AbstractPointListShape
      Since:
      2.0
    • setLineWidth

      public void setLineWidth(int w)
      Description copied from class: Shape
      Sets the line width to be used to outline the shape.
      Overrides:
      setLineWidth in class Shape
      Parameters:
      w - the new width
      See Also:
    • setPoints

      public void setPoints(PointList points)
      Sets the list of points to be used by this polyline connection. Removes any previously existing points. The polyline will hold onto the given list by reference.
      Overrides:
      setPoints in class AbstractPointListShape
      Parameters:
      points - new set of points
      Since:
      2.0
    • setTolerance

      public void setTolerance(int tolerance)
      Sets the tolerance
      Parameters:
      tolerance - the new tolerance value of the Polyline
    • repaint

      public void repaint()
      Description copied from interface: IFigure
      Repaints this IFigure.
      Specified by:
      repaint in interface IFigure
      Overrides:
      repaint in class Figure
      See Also: