Class Line

  • All Implemented Interfaces:
    Animatable

    public class Line
    extends Drawable<Line>
    A line: with a startpoint and an endpoint
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.awt.Point endOffset
      The offset of the endpoint from the startpoint (x, y)
    • Constructor Summary

      Constructors 
      Constructor Description
      Line​(int x1, int y1, int x2, int y2)
      Create a new Line element.
      Line​(int x1, int y1, int x2, int y2, java.awt.Color color)
      Create a new Line element.
      Line​(int x1, int y1, int x2, int y2, java.lang.String color)
      Create a new Line element colored a certain color by name (see Hue for list of all valid names)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.Point center​(java.awt.Graphics g)
      Get the object's centerpoint
      protected void drawFilled​(java.awt.Graphics2D gc)
      the color is set to `color`
      protected void drawOutline​(java.awt.Graphics2D gc)
      the color is set to `outlineColor`, the stroke is set to `outlineStroke`
      java.awt.Point getEndpoint()
      Get the endpoint of the line
      java.awt.Point getStartpoint()
      Get the startpoint of the line
      protected Line getThis()  
      Line setEndpoint​(int x, int y)
      Set the endpoint of the line
      Line setFilled​(boolean filled)
      DO NOT USE, Overridden
      Line setOutline​(int thickness, java.awt.Color color)
      Sets the parameters for the outline of the shape
      Line setStartpoint​(int x, int y)
      Get the startpoint of the line
      Line setStroke​(java.awt.Stroke stroke)
      Set the stroke of the line
      Line setThickness​(int thickness)
      Set the thickness of the line
      • Methods inherited from class paintingcanvas.drawable.Drawable

        Modifier and Type Method Description
        AnimationBuilder animate()
        Start animating this object.
        java.awt.Point center​(java.awt.Graphics g)
        Get the object's centerpoint
        Drawable<?> drawable()
        Get the Drawable element from this Animatable.
        protected abstract void drawFilled​(java.awt.Graphics2D gc)
        the color is set to `color`
        protected abstract void drawOutline​(java.awt.Graphics2D gc)
        the color is set to `outlineColor`, the stroke is set to `outlineStroke`
        void erase()
        Erase this object from the canvas.
        java.awt.Color getColor()
        Get the current color of an element as a Color
        java.awt.Color getOutlineColor()
        Gets the outline color
        java.awt.Stroke getOutlineStroke()
        Gets the outline stroke
        java.awt.Point getPos()
        Get the position of the element
        double getRotation()
        Get an elements rotation
        protected abstract T getThis()  
        int getX()
        Get the X-position of the element
        int getY()
        Get the Y-position of the element.
        T hide()
        Hide the Object.
        T move​(int x, int y)
        Moves this drawable by the specified x and y.
        T moveHorizontal​(int x)
        Moves this drawable by the specified x and y.
        T moveVertical​(int y)
        Moves this drawable by the specified x and y.
        T removeOutline()
        Removes the outline from the shape
        void render​(java.awt.Graphics g)
        Actually render the object itself
        T rotate​(double rotation)
        Rotate this element by rotation°.
        T setColor​(int hex)
        Set the color of the object with a 8-bit RGB hex literal.
        T setColor​(int r, int g, int b)
        Set the color of the element with RGB.
        T setColor​(java.awt.Color color)
        Set the color of the object with a Color object.
        T setColor​(java.lang.String color)
        Set the color of the object with a certain color by name (see Hue for list of all valid names)
        T setFilled​(boolean filled)
        Set whether this object is filled or not
        T setOutline​(int thickness)
        Sets the parameters for the outline of the shape, with the color defaulting to black
        T setOutline​(int thickness, java.awt.Color color)
        Sets the parameters for the outline of the shape
        T setOutline​(java.awt.Color color)
        Sets the outline color of the shape
        T setPos​(int x, int y)
        Set the position of the element.
        T setRotation​(double rotation)
        Set an elements rotation to rotation°.
        T setX​(int x)
        Set the X-position of the object
        T setY​(int y)
        Set the Y-position of the element
        T show()
        Show the Object
      • Methods inherited from class java.lang.Object

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

      • endOffset

        public java.awt.Point endOffset
        The offset of the endpoint from the startpoint (x, y)
    • Constructor Detail

      • Line

        public Line​(int x1,
                    int y1,
                    int x2,
                    int y2)
        Create a new Line element.
        
         // Create a new Line from (100, 100) to (200, 200)
         Line line = new Line(100, 100, 200, 200);
         
        Parameters:
        x1 - The X-position of the startpoint
        y1 - The Y-position of the startpoint
        x2 - The X-position of the endpoint
        y2 - The Y-position of the endpoint
      • Line

        public Line​(int x1,
                    int y1,
                    int x2,
                    int y2,
                    java.awt.Color color)
        Create a new Line element.
        
         // Create a new Line from (100, 100) to (200, 200)
         Line line = new Line(100, 100, 200, 200, new Color(255, 0, 0));
         
        Parameters:
        x1 - The X-position of the startpoint
        y1 - The Y-position of the startpoint
        x2 - The X-position of the endpoint
        y2 - The Y-position of the endpoint
        color - The color of the line
      • Line

        public Line​(int x1,
                    int y1,
                    int x2,
                    int y2,
                    java.lang.String color)
        Create a new Line element colored a certain color by name (see Hue for list of all valid names)
        
         // Create a new Line from (100, 100) to (200, 200)
         Line line = new Line(100, 100, 200, 200, "red");
         
        Parameters:
        x1 - The X-position of the startpoint
        y1 - The Y-position of the startpoint
        x2 - The X-position of the endpoint
        y2 - The Y-position of the endpoint
        color - The name of the color (case-insensitive)
    • Method Detail

      • setOutline

        public Line setOutline​(int thickness,
                               java.awt.Color color)
        Description copied from class: Drawable
        Sets the parameters for the outline of the shape
        
         // the circle is red outlined by a black outline
         Circle c = new Circle(100, 100, 50);
         c.setOutline(5);
         c.setColor(Color.RED);
        
         // now just the outline is rendered
         c.setFilled(false);
         
        Overrides:
        setOutline in class Drawable<Line>
        Parameters:
        thickness - the thickness of the outline
        color - the color of the outline
        Returns:
        The original object to allow method chaining
      • setStroke

        public Line setStroke​(java.awt.Stroke stroke)
        Set the stroke of the line
        Parameters:
        stroke - a Stroke object to define this line's stroke
        Returns:
        The original object to allow method chaining
      • setThickness

        public Line setThickness​(int thickness)
        Set the thickness of the line
        Parameters:
        thickness - The thickness of the line in pixels
        Returns:
        The original object to allow method chaining
      • getEndpoint

        public java.awt.Point getEndpoint()
        Get the endpoint of the line
        
         import java.awt.Point;
        
         Point p = line.getEndpoint();
         int x = p.x;
         int y = p.y;
         
        Returns:
        a Point object representing the startpoint of the line
      • getStartpoint

        public java.awt.Point getStartpoint()
        Get the startpoint of the line
        
         import java.awt.Point;
        
         Point p = line.getStartpoint();
         int x = p.x;
         int y = p.y;
         
        Returns:
        a Point object representing the startpoint of the line
      • setStartpoint

        public Line setStartpoint​(int x,
                                  int y)
        Get the startpoint of the line
        Parameters:
        x - The new X-position of the startpoint
        y - The new Y-position of the startpoint
        Returns:
        The original object to allow method chaining
      • setEndpoint

        public Line setEndpoint​(int x,
                                int y)
        Set the endpoint of the line
        Parameters:
        x - The new X-position of the endpoint
        y - The new Y-position of the endpoint
        Returns:
        The original object to allow method chaining
      • drawFilled

        protected void drawFilled​(java.awt.Graphics2D gc)
        Description copied from class: Drawable
        the color is set to `color`
        Specified by:
        drawFilled in class Drawable<Line>
        Parameters:
        gc - The graphics context to draw the object with
      • drawOutline

        protected void drawOutline​(java.awt.Graphics2D gc)
        Description copied from class: Drawable
        the color is set to `outlineColor`, the stroke is set to `outlineStroke`
        Specified by:
        drawOutline in class Drawable<Line>
        Parameters:
        gc - The graphics context to draw the object with
      • center

        public java.awt.Point center​(java.awt.Graphics g)
        Description copied from class: Drawable
        Get the object's centerpoint
        
         import java.awt.Point;
        
         Point p = drawable.getStartpoint();
         int x = p.x;
         int y = p.y;
         
        Overrides:
        center in class Drawable<Line>
        Parameters:
        g - Graphics context
        Returns:
        The object's center-point