Class Graphic

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Iterable<GraphicE>
    Direct Known Subclasses:
    GFormula

    public class Graphic
    extends GraphicE
    implements java.lang.Iterable<GraphicE>
    This class represents a Graphic made by a collection of GraphicE components.
    Note: this class is a GraphicE on itself, so you can add it to Graphics.
    • Field Summary

    • Constructor Summary

      Constructors 
      Constructor Description
      Graphic()
      Creates a new instance.
      Graphic​(int initialSize)
      Creates a new instance.
      Graphic​(Graphic e)
      Copy constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(GraphicE e)
      Adds a new GraphicE to this Graphic
      Note: all the elements that are added will be automatically traslated the same amount as the sum of the traslations up to this moment Note 2:This method doesn't check if the element is already contained on the Graphic, this mean, that you can add elements twice, the downside (or amazing feature, according to a couple of comments) is that the elements that are added twice will be traslated twice as much as the other elements.
      void addAll​(Graphic... graphics)
      This method adds all of the elements of a given set of Graphic components into the current element.
      void addCopyOfAll​(Graphic... graphics)
      This method adds all of the elements of a given set of Graphic components into the current element.
      Graphic clone()  
      boolean contains​(GraphicE e)
      Tells if a given GraphicE is contained on this Graphic.
      void draw​(java.awt.Graphics2D g)
      Draws the component on the given graphics
      boolean equals​(java.lang.Object obj)  
      void flatten()
      Flattens the structure of a Graphic, this method is very slow, but it will increase the performance of draw().
      int getCount()
      Retrieves the number of GraphicE components that compose this Graphic.
      int hashCode()  
      int indexOf​(GraphicE e)
      Retrieves the index of a given element on the Graphic.
      boolean isVisible()
      Tells if Graphic will be drawn in the canvas
      java.util.Iterator<GraphicE> iterator()  
      void move​(int x, int y)
      Moves all the elements to a given location.
      This method tends to ruin graphics...
      boolean remove​(GraphicE e)
      Removes a given GraphicE from this Graphic
      void removeAll()
      Clears all the components from this Graphic
      void setVisible​(boolean v)  
      void traslate​(int x, int y)
      Traslates this element on X and Y
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Graphic

        public Graphic()
        Creates a new instance.
      • Graphic

        public Graphic​(int initialSize)
        Creates a new instance.
        Parameters:
        initialSize - initial size of the list
      • Graphic

        public Graphic​(Graphic e)
        Copy constructor.
        Parameters:
        e - Graphic to copy
        Throws:
        java.lang.IllegalArgumentException - if e is null
    • Method Detail

      • getCount

        public int getCount()
        Retrieves the number of GraphicE components that compose this Graphic. This method will not count recursively.
        Returns:
        component count
      • add

        public void add​(GraphicE e)
        Adds a new GraphicE to this Graphic
        Note: all the elements that are added will be automatically traslated the same amount as the sum of the traslations up to this moment Note 2:This method doesn't check if the element is already contained on the Graphic, this mean, that you can add elements twice, the downside (or amazing feature, according to a couple of comments) is that the elements that are added twice will be traslated twice as much as the other elements.
        Parameters:
        e - element to add
        Throws:
        java.lang.IllegalArgumentException - if e is null
        InvalidArgumentException - if e is this same object
        See Also:
        traslate(int, int)
      • contains

        public boolean contains​(GraphicE e)
        Tells if a given GraphicE is contained on this Graphic.
        Parameters:
        e - element to test
        Returns:
        true if the element is contained and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if e is null
        See Also:
        flatten()
      • remove

        public boolean remove​(GraphicE e)
        Removes a given GraphicE from this Graphic
        Parameters:
        e - element to remove
        Returns:
        true if the element was contained and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if e is null
        See Also:
        flatten()
      • indexOf

        public int indexOf​(GraphicE e)
        Retrieves the index of a given element on the Graphic.
        Parameters:
        e - element
        Returns:
        The index number of the first occurrence of the element, or -1 if the element wasn't found
        Throws:
        java.lang.IllegalArgumentException - if e is null
        See Also:
        flatten()
      • removeAll

        public void removeAll()
        Clears all the components from this Graphic
      • draw

        public void draw​(java.awt.Graphics2D g)
        Description copied from class: GraphicE
        Draws the component on the given graphics
        Specified by:
        draw in class GraphicE
        Parameters:
        g - where to draw
      • traslate

        public void traslate​(int x,
                             int y)
        Description copied from class: GraphicE
        Traslates this element on X and Y
        Specified by:
        traslate in class GraphicE
        Parameters:
        x - size in px of the horizontal translation
        y - size in px of the vertical translation
      • move

        public void move​(int x,
                         int y)
        Moves all the elements to a given location.
        This method tends to ruin graphics... use it with care.
        Parameters:
        x - new X coordinate
        y - new Y coordinate
      • addAll

        public void addAll​(Graphic... graphics)
        This method adds all of the elements of a given set of Graphic components into the current element.
        Parameters:
        graphics - array of graphics to merge
        See Also:
        flatten()
      • addCopyOfAll

        public void addCopyOfAll​(Graphic... graphics)
        This method adds all of the elements of a given set of Graphic components into the current element.
        Parameters:
        graphics - array of graphics to merge
        See Also:
        flatten()
      • isVisible

        public boolean isVisible()
        Tells if Graphic will be drawn in the canvas
        Returns:
        true if the Graphic is visible and flase otherwise
      • setVisible

        public void setVisible​(boolean v)
        Parameters:
        v - true if the Graphic will visible and flase otherwise
      • flatten

        public void flatten()
        Flattens the structure of a Graphic, this method is very slow, but it will increase the performance of draw().
        This method is specially useful when you use the GraphicCreator, or when combining several Graphic. Consider trying to search for a specific element when having multiple Graphic objects... basically, you'll never be able to find them if you need to enter each and every Graphic object to check.
      • iterator

        public java.util.Iterator<GraphicE> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<GraphicE>
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class GraphicE