Class Graphic

java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.elements.Graphic
All Implemented Interfaces:
Cloneable, Iterable<GraphicE>
Direct Known Subclasses:
GFormula

public class Graphic extends GraphicE implements 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.
Author:
Federico Vera <[email protected]>
  • Field Summary

    Fields inherited from class com.dkt.graphics.elements.GraphicE

    STROKE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Graphic(int initialSize)
     
    Copy constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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.
     
    boolean
    Tells if a given GraphicE is contained on this Graphic.
    void
    Draws the component on the given graphics
    boolean
     
    void
    Flattens the structure of a Graphic, this method is very slow, but it will increase the performance of draw().
    int
    Retrieves the number of GraphicE components that compose this Graphic.
    int
     
    int
    Retrieves the index of a given element on the Graphic.
    boolean
    Tells if Graphic will be drawn in the canvas
     
    void
    move(int x, int y)
    Moves all the elements to a given location.
    This method tends to ruin graphics...
    boolean
    Removes a given GraphicE from this Graphic
    void
    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 class com.dkt.graphics.elements.GraphicE

    getPaint, getStroke, setPaint, setStroke

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • Graphic

      public Graphic()
    • Graphic

      public Graphic(int initialSize)
    • Graphic

      public Graphic(Graphic e)
      Copy constructor
      Parameters:
      e - Graphic to copy
      Throws:
      IllegalArgumentException - if e is null
  • Method Details

    • 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:
      IllegalArgumentException - if e is null
      InvalidArgumentException - if e is this same object
      See Also:
    • 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:
      IllegalArgumentException - if e is null
      See Also:
    • 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:
      IllegalArgumentException - if e is null
      See Also:
    • 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:
      IllegalArgumentException - if e is null
      See Also:
    • removeAll

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

      public void draw(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:
    • 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:
    • 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 Iterator<GraphicE> iterator()
      Specified by:
      iterator in interface Iterable<GraphicE>
    • clone

      public Graphic clone()
      Specified by:
      clone in class GraphicE
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class GraphicE
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class GraphicE