Documentation of 'edu.rit.draw.item.Line' Java class
Line
edu.rit.draw.item

Class Line

  • All Implemented Interfaces:
    java.io.Externalizable, java.io.Serializable


    public class Line
    extends OutlinedItem
    implements java.io.Externalizable
    Class Line provides a DrawingItem that consists of one or more straight line segments. The line may have an Arrow at either or both ends. The line may have sharp corners or round corners. The line has an outline but no filled interior.

    If the line has round corners, the round corner distance gives the distance from where the (sharp) corner would normally be to the starting and ending points of the round corner arc, as shown in the adjoining diagram. (The round corner distance is d.) A round corner distance of 0 results in a sharp corner. In a particular line, the same round corner distance is used for every corner; that is, either all the corners are sharp or all the corners are rounded the same amount. Different lines can have different round corner distances.

    The static defaultStartArrow(), defaultEndArrow(), and defaultRound() methods are provided to set the default starting arrow, ending arrow, and round corner distance. If the starting arrow, ending arrow, or round corner distance is not specified, the current default starting arrow, ending arrow, or round corner distance is used.

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      Line()
      Construct a new line.
      Line(Line theLine)
      Construct a new line with the same points, outline, starting arrow, ending arrow, and round corner distance as the given line.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      Line add()
      Add this line to the end of the default drawing's sequence of drawing items.
      Line add(Drawing theDrawing)
      Add this line to the end of the given drawing's sequence of drawing items.
      Line addFirst()
      Add this line to the beginning of the default drawing's sequence of drawing items.
      Line addFirst(Drawing theDrawing)
      Add this line to the beginning of the given drawing's sequence of drawing items.
      Line by(double dx, double dy)
      Add a line segment to this line.
      Line by(Size theSize)
      Add a line segment to this line.
      Line clear()
      Clear this line.
      static Arrow defaultEndArrow()
      Returns the default ending arrow.
      static void defaultEndArrow(Arrow theArrow)
      Set the default ending arrow.
      static double defaultRound()
      Returns the default round corner distance.
      static void defaultRound(double theRound)
      Set the default round corner distance.
      static Arrow defaultStartArrow()
      Returns the default starting arrow.
      static void defaultStartArrow(Arrow theArrow)
      Set the default starting arrow.
      void draw(java.awt.Graphics2D g2d)
      Draw this drawing item in the given graphics context.
      Arrow endArrow()
      Returns this line's ending arrow.
      Line endArrow(Arrow theArrow)
      Set this line's ending arrow.
      Line hby(double dx)
      Add a horizontal line segment to this line.
      Line hby(Size theSize)
      Add a horizontal line segment to this line.
      double height()
      Returns the height of this drawing item's bounding box.
      Line hto(double x)
      Add a horizontal line segment to this line.
      Line hto(Point thePoint)
      Add a horizontal line segment to this line.
      Point nw()
      Returns the northwest corner point of this drawing item's bounding box.
      Line outline(Outline theOutline)
      Set this line's outline.
      void readExternal(java.io.ObjectInput in)
      Read this line from the given object input stream.
      double round()
      Returns this line's round corner distance.
      Line round(double theRound)
      Set this line's round corner distance.
      Size size()
      Returns the size of this drawing item's bounding box.
      Arrow startArrow()
      Returns this line's starting arrow.
      Line startArrow(Arrow theArrow)
      Set this line's starting arrow.
      Line to(double x, double y)
      Add a line segment to this line.
      Line to(Point thePoint)
      Add a line segment to this line.
      Line vby(double dy)
      Add a vertical line segment to this line.
      Line vby(Size theSize)
      Add a vertical line segment to this line.
      Line vto(double y)
      Add a vertical line segment to this line.
      Line vto(Point thePoint)
      Add a vertical line segment to this line.
      double width()
      Returns the width of this drawing item's bounding box.
      void writeExternal(java.io.ObjectOutput out)
      Write this line to the given object output stream.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NORMAL_START_ARROW

        public static final Arrow NORMAL_START_ARROW
        The normal starting arrow: None.
      • NORMAL_END_ARROW

        public static final Arrow NORMAL_END_ARROW
        The normal ending arrow: None.
      • NORMAL_ROUND

        public static final double NORMAL_ROUND
        The normal round corner distance (0), signifying sharp corners.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Line

        public Line()
        Construct a new line. The line has no points initially. The default outline, starting arrow, ending arrow, and round corner distance are used.
      • Line

        public Line(Line theLine)
        Construct a new line with the same points, outline, starting arrow, ending arrow, and round corner distance as the given line.
        Parameters:
        theLine - Line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theLine is null.
    • Method Detail

      • defaultStartArrow

        public static Arrow defaultStartArrow()
        Returns the default starting arrow.
        Returns:
        Default starting arrow.
      • defaultStartArrow

        public static void defaultStartArrow(Arrow theArrow)
        Set the default starting arrow. Before calling this method the first time, the default starting arrow is Arrow.NONE.
        Parameters:
        theArrow - Default starting arrow.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theArrow is null.
      • defaultEndArrow

        public static Arrow defaultEndArrow()
        Returns the default ending arrow.
        Returns:
        Default ending arrow.
      • defaultEndArrow

        public static void defaultEndArrow(Arrow theArrow)
        Set the default ending arrow. Before calling this method the first time, the default ending arrow is Arrow.NONE.
        Parameters:
        theArrow - Default ending arrow.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theArrow is null.
      • defaultRound

        public static double defaultRound()
        Returns the default round corner distance. A value of 0 signifies sharp corners.
        Returns:
        Default round corner distance.
      • defaultRound

        public static void defaultRound(double theRound)
        Set the default round corner distance. A value of 0 signifies sharp corners. Before calling this method the first time, the default round corner distance is 0.
        Parameters:
        theRound - Default round corner distance.
        Throws:
        java.lang.IllegalArgumentException - (unchecked exception) Thrown if theRound is less than 0.
      • size

        public Size size()
        Returns the size of this drawing item's bounding box.
        Overrides:
        size in class DrawingItem
        Returns:
        Size.
      • width

        public double width()
        Returns the width of this drawing item's bounding box.
        Specified by:
        width in class DrawingItem
        Returns:
        Width.
      • height

        public double height()
        Returns the height of this drawing item's bounding box.
        Specified by:
        height in class DrawingItem
        Returns:
        Height.
      • nw

        public Point nw()
        Returns the northwest corner point of this drawing item's bounding box.
        Specified by:
        nw in class DrawingItem
        Returns:
        Northwest corner point.
      • outline

        public Line outline(Outline theOutline)
        Set this line's outline.
        Overrides:
        outline in class OutlinedItem
        Parameters:
        theOutline - Outline, or Outline.NONE.
        Returns:
        This line.
      • clear

        public Line clear()
        Clear this line. All of this point's line segments are removed.
        Returns:
        This line.
      • to

        public Line to(double x,
                       double y)
        Add a line segment to this line. The new endpoint is (x, y). If this line has no line segments, the to() method specifies this line's starting endpoint.
        Parameters:
        x - Endpoint's X coordinate.
        y - Endpoint's Y coordinate.
        Returns:
        This line.
      • to

        public Line to(Point thePoint)
        Add a line segment to this line. The new endpoint is thePoint. If this line has no line segments, the to() method specifies this line's starting endpoint.
        Parameters:
        thePoint - Endpoint.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null.
      • hto

        public Line hto(double x)
        Add a horizontal line segment to this line. The new endpoint is (x, previous endpoint's Y coordinate).
        Parameters:
        x - Endpoint's X coordinate.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if there is no previous endpoint.
      • hto

        public Line hto(Point thePoint)
        Add a horizontal line segment to this line. The new endpoint is (thePoint's X coordinate, previous endpoint's Y coordinate).
        Parameters:
        thePoint - Endpoint.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null. Thrown if there is no previous endpoint.
      • vto

        public Line vto(double y)
        Add a vertical line segment to this line. The new endpoint is (previous endpoint's X coordinate, y).
        Parameters:
        y - Endpoint's Y coordinate.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if there is no previous endpoint.
      • vto

        public Line vto(Point thePoint)
        Add a vertical line segment to this line. The new endpoint is (previous endpoint's X coordinate, thePoint's Y coordinate).
        Parameters:
        thePoint - Endpoint.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null. Thrown if there is no previous endpoint.
      • by

        public Line by(double dx,
                       double dy)
        Add a line segment to this line. The new endpoint is (previous endpoint's X coordinate + dx, previous endpoint's Y coordinate + dy).
        Parameters:
        dx - X distance.
        dy - Y distance.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if there is no previous endpoint.
      • by

        public Line by(Size theSize)
        Add a line segment to this line. The new endpoint is (previous endpoint's X coordinate + theSize.width(), previous endpoint's Y coordinate + theSize.height()).
        Parameters:
        theSize - Distance.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.
      • hby

        public Line hby(double dx)
        Add a horizontal line segment to this line. The new endpoint is (previous endpoint's X coordinate + dx, previous endpoint's Y coordinate).
        Parameters:
        dx - X distance.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if there is no previous endpoint.
      • hby

        public Line hby(Size theSize)
        Add a horizontal line segment to this line. The new endpoint is (previous endpoint's X coordinate + theSize.width(), previous endpoint's Y coordinate).
        Parameters:
        theSize - Distance.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.
      • vby

        public Line vby(double dy)
        Add a vertical line segment to this line. The new endpoint is (previous endpoint's X coordinate, previous endpoint's Y coordinate + dy).
        Parameters:
        dy - Y distance.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if there is no previous endpoint.
      • vby

        public Line vby(Size theSize)
        Add a vertical line segment to this line. The new endpoint is (previous endpoint's X coordinate, previous endpoint's Y coordinate + theSize.height()).
        Parameters:
        theSize - Distance.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.
      • startArrow

        public Arrow startArrow()
        Returns this line's starting arrow.
        Returns:
        Starting arrow.
      • startArrow

        public Line startArrow(Arrow theArrow)
        Set this line's starting arrow.
        Parameters:
        theArrow - Starting arrow.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theArrow is null.
      • endArrow

        public Arrow endArrow()
        Returns this line's ending arrow.
        Returns:
        Ending arrow.
      • endArrow

        public Line endArrow(Arrow theArrow)
        Set this line's ending arrow.
        Parameters:
        theArrow - Ending arrow.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theArrow is null.
      • round

        public double round()
        Returns this line's round corner distance. A value of 0 signifies sharp corners.
        Returns:
        Round corner distance.
      • round

        public Line round(double theRound)
        Set this line's round corner distance. A value of 0 signifies sharp corners.
        Parameters:
        theRound - Round corner distance.
        Returns:
        This line.
        Throws:
        java.lang.IllegalArgumentException - (unchecked exception) Thrown if theRound is less than 0.
      • add

        public Line add()
        Add this line to the end of the default drawing's sequence of drawing items.
        Overrides:
        add in class OutlinedItem
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if there is no default drawing.
        See Also:
        Drawing.defaultDrawing()
      • add

        public Line add(Drawing theDrawing)
        Add this line to the end of the given drawing's sequence of drawing items.
        Overrides:
        add in class OutlinedItem
        Parameters:
        theDrawing - Drawing.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theDrawing is null.
      • addFirst

        public Line addFirst()
        Add this line to the beginning of the default drawing's sequence of drawing items.
        Overrides:
        addFirst in class OutlinedItem
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if there is no default drawing.
        See Also:
        Drawing.defaultDrawing()
      • addFirst

        public Line addFirst(Drawing theDrawing)
        Add this line to the beginning of the given drawing's sequence of drawing items.
        Overrides:
        addFirst in class OutlinedItem
        Parameters:
        theDrawing - Drawing.
        Returns:
        This line.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theDrawing is null.
      • writeExternal

        public void writeExternal(java.io.ObjectOutput out)
                           throws java.io.IOException
        Write this line to the given object output stream.
        Specified by:
        writeExternal in interface java.io.Externalizable
        Overrides:
        writeExternal in class OutlinedItem
        Parameters:
        out - Object output stream.
        Throws:
        java.io.IOException - Thrown if an I/O error occurred.
      • readExternal

        public void readExternal(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Read this line from the given object input stream.
        Specified by:
        readExternal in interface java.io.Externalizable
        Overrides:
        readExternal in class OutlinedItem
        Parameters:
        in - Object input stream.
        Throws:
        java.io.IOException - Thrown if an I/O error occurred.
        java.lang.ClassNotFoundException - Thrown if any class needed to deserialize this line cannot be found.
      • draw

        public void draw(java.awt.Graphics2D g2d)
        Draw this drawing item in the given graphics context. This method is allowed to change the graphics context's paint, stroke, and transform, and it doesn't have to change them back.
        Overrides:
        draw in class DrawingItem
        Parameters:
        g2d - 2-D graphics context.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.