Class GraphicCreator


  • public class GraphicCreator
    extends java.lang.Object
    This class came as an exercise to create Graphic objects from text without modifying the classes themselves, it was later used on Graphic Designer, and finally decided to add it to add it to the extras package.
    This class is pretty handy to create simple drawing based GUIs, since manipulating strings is orders of magnitude easier than using Graphics. This is not meant to be a programming language, it's simply a way of creating simple (and not so simple) graphics.
    • Constructor Summary

      Constructors 
      Constructor Description
      GraphicCreator()
      Creates a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      GArc arc​(java.lang.String[] args)  
      GArc arcc​(java.lang.String[] args)  
      GCircle circle​(java.lang.String[] args)  
      GClip clipadd​(java.lang.String[] args)  
      GClip clipoff​(java.lang.String[] args)  
      GClip clipsub​(java.lang.String[] args)  
      java.awt.Color color​(java.lang.String[] args)
      Set's the global color.
      java.awt.Color colorf​(java.lang.String[] args)
      Set's the global fill color.
      java.awt.Font font​(java.lang.String[] args)
      Sets a global font, if the argument is no then it will reset the global font
      Graphic for1​(java.lang.String[] args)  
      Graphic for2​(java.lang.String[] args)  
      Graphic for3​(java.lang.String[] args)  
      Graphic for4​(java.lang.String[] args)  
      int getErrorCount()
      Retrieves the number of errors encountered during the parsing of a given text.
      int getTotalLineCount()
      Total number of lines parsed
      java.awt.GradientPaint gradient​(java.lang.String[] args)
      Creates a linear gradient between color and colorf, so they need to be set before calling this method.
      The arguments should be x1, y1, x2, y2, that is, the coordinates of the first point of the gradient vector and the coordinates of the last point
      java.awt.GradientPaint gradient2​(java.lang.String[] args)
      Creates a linear cyclic gradient between color and colorf, so they need to be set before calling this method.
      The arguments should be x1, y1, x2, y2, that is, the coordinates of the first point of the gradient vector and the coordinates of the last point
      GGrid grid​(java.lang.String[] args)  
      GLine linec​(java.lang.String[] args)
      Creates a line based on cartesian coordinates.
      The arguments are x1, y1, x2, y2.
      GLine linep​(java.lang.String[] args)
      Creates a line based on polar coordinates.
      The arguments are x, y, l, a.
      GPath lpath​(java.lang.String[] args)  
      GOval oval​(java.lang.String[] args)  
      Graphic parse​(java.lang.String line)
      Creates a new Graphic based on the parsed line.
      Graphic parse​(java.lang.String... lines)
      Parses a String (that respects the documentation) into a Graphic
      GPoint point​(java.lang.String[] args)
      Creates a new point.
      The first two arguments should be x and y coordinates of the point.
      GRegPoly polyn​(java.lang.String[] args)  
      GPoly polyp​(java.lang.String[] args)  
      GRectangle rectc​(java.lang.String[] args)  
      GRectangle rectf​(java.lang.String[] args)  
      java.lang.Object reset​(java.lang.String[] args)
      Clears the global configurations color, colorf, stroke, paint and font
      GTransform rotate​(java.lang.String[] args)  
      GTransform scale​(java.lang.String[] args)  
      GString string​(java.lang.String[] args)  
      GString string2​(java.lang.String[] args)  
      java.awt.Stroke stroke​(java.lang.String[] args)  
      GTransform transoff​(java.lang.String[] args)  
      GTransform traslate​(java.lang.String[] args)  
      GVector vectc​(java.lang.String[] args)  
      GVector vectp​(java.lang.String[] args)  
      • Methods inherited from class java.lang.Object

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

      • GraphicCreator

        public GraphicCreator()
        Creates a new instance.
    • Method Detail

      • getErrorCount

        public int getErrorCount()
        Retrieves the number of errors encountered during the parsing of a given text.
        Returns:
        error count
      • getTotalLineCount

        public int getTotalLineCount()
        Total number of lines parsed
        Returns:
        number of lines
      • stroke

        public java.awt.Stroke stroke​(java.lang.String[] args)
      • reset

        public java.lang.Object reset​(java.lang.String[] args)
        Clears the global configurations color, colorf, stroke, paint and font
        Parameters:
        args - this are ignored
        Returns:
        null
      • font

        public java.awt.Font font​(java.lang.String[] args)
        Sets a global font, if the argument is no then it will reset the global font
        Parameters:
        args - the arguments will be used in Font.decode(String), so for further documentation, please refer to it
        Returns:
        Font
      • colorf

        public java.awt.Color colorf​(java.lang.String[] args)
        Set's the global fill color. I the argument is no then it will reset the fill color. If this color is set all GFillableE will be set to fill.
        This color is also used as the secondary color on gradients.
        • If 3 arguments are passed there should be: R[0-255] G[0-255] B[0-255],
        • if 4 arguments are passed the format should be: A[0-255] R[0-255] G[0-255] B[0-255]
        Parameters:
        args - color info
        Returns:
        Fill color
        See Also:
        color(String[]), gradient(String[]), gradient2(String[]), GFillableE.setFill(boolean)
      • color

        public java.awt.Color color​(java.lang.String[] args)
        Set's the global color. This color is also used as the primary color on gradients.
        • If 3 arguments are passed there should be: R[0-255] G[0-255] B[0-255],
        • if 4 arguments are passed the format should be: A[0-255] R[0-255] G[0-255] B[0-255]
        Parameters:
        args - color info
        Returns:
        Fill color
        See Also:
        colorf(String[]), gradient(String[]), gradient2(String[]), GFillableE.setFill(boolean)
      • gradient

        public java.awt.GradientPaint gradient​(java.lang.String[] args)
        Creates a linear gradient between color and colorf, so they need to be set before calling this method.
        The arguments should be x1, y1, x2, y2, that is, the coordinates of the first point of the gradient vector and the coordinates of the last point
        Parameters:
        args - vector arguments
        Returns:
        Linear gradient
        See Also:
        color(String[]), colorf(String[]), gradient2(String[])
      • gradient2

        public java.awt.GradientPaint gradient2​(java.lang.String[] args)
        Creates a linear cyclic gradient between color and colorf, so they need to be set before calling this method.
        The arguments should be x1, y1, x2, y2, that is, the coordinates of the first point of the gradient vector and the coordinates of the last point
        Parameters:
        args - vector arguments
        Returns:
        Linear cyclic gradient
        See Also:
        color(String[]), colorf(String[]), gradient(String[])
      • for1

        public Graphic for1​(java.lang.String[] args)
      • for2

        public Graphic for2​(java.lang.String[] args)
      • for3

        public Graphic for3​(java.lang.String[] args)
      • for4

        public Graphic for4​(java.lang.String[] args)
      • clipadd

        public GClip clipadd​(java.lang.String[] args)
      • clipsub

        public GClip clipsub​(java.lang.String[] args)
      • clipoff

        public GClip clipoff​(java.lang.String[] args)
      • scale

        public GTransform scale​(java.lang.String[] args)
      • rotate

        public GTransform rotate​(java.lang.String[] args)
      • traslate

        public GTransform traslate​(java.lang.String[] args)
      • transoff

        public GTransform transoff​(java.lang.String[] args)
                            throws java.awt.geom.NoninvertibleTransformException
        Throws:
        java.awt.geom.NoninvertibleTransformException
      • point

        public GPoint point​(java.lang.String[] args)
        Creates a new point.
        The first two arguments should be x and y coordinates of the point. The third optional argument is the cross size used to represent the point
        Parameters:
        args - point arguments
        Returns:
        point
        See Also:
        GPoint.cs
      • linec

        public GLine linec​(java.lang.String[] args)
        Creates a line based on cartesian coordinates.
        The arguments are x1, y1, x2, y2.
        Parameters:
        args - coordinates of the line
        Returns:
        Line
      • linep

        public GLine linep​(java.lang.String[] args)
        Creates a line based on polar coordinates.
        The arguments are x, y, l, a. With x, y being the initial point, l the length of the vector and a the angle in degrees.
        Parameters:
        args - coordinates of the line
        Returns:
        Line
      • lpath

        public GPath lpath​(java.lang.String[] args)
      • rectf

        public GRectangle rectf​(java.lang.String[] args)
      • rectc

        public GRectangle rectc​(java.lang.String[] args)
      • circle

        public GCircle circle​(java.lang.String[] args)
      • oval

        public GOval oval​(java.lang.String[] args)
      • polyp

        public GPoly polyp​(java.lang.String[] args)
      • polyn

        public GRegPoly polyn​(java.lang.String[] args)
      • vectc

        public GVector vectc​(java.lang.String[] args)
      • vectp

        public GVector vectp​(java.lang.String[] args)
      • arc

        public GArc arc​(java.lang.String[] args)
      • arcc

        public GArc arcc​(java.lang.String[] args)
      • string

        public GString string​(java.lang.String[] args)
      • string2

        public GString string2​(java.lang.String[] args)
      • grid

        public GGrid grid​(java.lang.String[] args)