Class GraphicCreator

java.lang.Object
com.dkt.graphics.extras.GraphicCreator

public class GraphicCreator extends 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.
Author:
Federico Vera <[email protected]>
  • Constructor Details

    • GraphicCreator

      public GraphicCreator()
  • Method Details

    • clear

      public void clear()
    • parse

      public Graphic parse(String line)
    • parse

      public Graphic parse(String... lines)
      Parses a String (that respects the documentation) into a Graphic
      Parameters:
      lines - String representation of the graphic
      Returns:
      Graphic object
    • getErrorCount

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

      public int getTotalLineCount()
    • stroke

      public Stroke stroke(String[] args)
    • reset

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

      public Font font(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 Color colorf(String[] args)
      Set's the global fill color. If 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

      public Color color(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:
    • gradient

      public GradientPaint gradient(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:
    • gradient2

      public GradientPaint gradient2(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:
    • for1

      public Graphic for1(String[] args)
    • for2

      public Graphic for2(String[] args)
    • for3

      public Graphic for3(String[] args)
    • for4

      public Graphic for4(String[] args)
    • clipadd

      public GClip clipadd(String[] args)
    • clipsub

      public GClip clipsub(String[] args)
    • clipoff

      public GClip clipoff(String[] args)
    • scale

      public GTransform scale(String[] args)
    • rotate

      public GTransform rotate(String[] args)
    • traslate

      public GTransform traslate(String[] args)
    • transoff

      public GTransform transoff(String[] args) throws NoninvertibleTransformException
      Throws:
      NoninvertibleTransformException
    • point

      public GPoint point(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
    • linec

      public GLine linec(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(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(String[] args)
    • rectf

      public GRectangle rectf(String[] args)
    • rectc

      public GRectangle rectc(String[] args)
    • circle

      public GCircle circle(String[] args)
    • oval

      public GOval oval(String[] args)
    • polyp

      public GPoly polyp(String[] args)
    • polyn

      public GRegPoly polyn(String[] args)
    • vectc

      public GVector vectc(String[] args)
    • vectp

      public GVector vectp(String[] args)
    • arc

      public GArc arc(String[] args)
    • arcc

      public GArc arcc(String[] args)
    • string

      public GString string(String[] args)
    • string2

      public GString string2(String[] args)
    • grid

      public GGrid grid(String[] args)