Class DOT


  • public final class DOT
    extends Object
    Utility class to simplify operating the GraphVIZ "dot" utility. Please note that all the provided methods require GraphVIZ to be installed on the system, and that the "dot" binary resides in the execution path.
    • Method Detail

      • setDotExe

        public static void setDotExe​(String dotExe)
        Explicitly sets the path to the DOT utility executable.
        Parameters:
        dotExe - the path to the DOT utility executable
      • checkUsable

        public static boolean checkUsable()
        Checks whether the DOT utility can be successfully invoked.
      • runDOT

        public static InputStream runDOT​(Reader r,
                                         String format,
                                         String... additionalOpts)
                                  throws IOException
        Invokes the GraphVIZ DOT utility for rendering graphs.
        Parameters:
        r - the reader from which the GraphVIZ description is obtained.
        format - the output format, as understood by the dot utility, e.g., png, ps, ...
        Returns:
        an input stream from which the image data can be read.
        Throws:
        IOException - if reading from the reader or the call to the DOT utility fails.
      • runDOT

        public static void runDOT​(File dotFile,
                                  String format,
                                  File out)
                           throws IOException
        Invokes the DOT utility on a file, producing an output file. Convenience method, see runDOT(Reader, String, File).
        Throws:
        IOException - if reading from the file, the call to the DOT utility, or writing to the file fails.
      • runDOT

        public static void runDOT​(Reader r,
                                  String format,
                                  File out)
                           throws IOException
        Invokes the GraphVIZ DOT utility for rendering graphs, writing output to the specified file.
        Parameters:
        r - the reader from which the GraphVIZ description is read.
        format - the output format to produce.
        out - the file to which the output is written.
        Throws:
        IOException - if reading from the reader, the call to the DOT utility, or writing to the file fails.
      • renderDOTExternal

        public static void renderDOTExternal​(File dotFile,
                                             String format)
                                      throws IOException
        Renders a GraphVIZ description from a file, using an external program for displaying. Convenience method, see renderDOTExternal(Reader, String).
        Throws:
        IOException - if reading from the file or the call to the DOT utility fails.
      • renderDOTExternal

        public static void renderDOTExternal​(Reader r,
                                             String format)
                                      throws IOException
        Renders a GraphVIZ description, using an external program for displaying. The program is determined by the system's file type associations, using the Desktop.open(File) method.
        Parameters:
        r - the reader from which the GraphVIZ description is read.
        format - the output format, as understood by the dot utility, e.g., png, ps, ...
        Throws:
        IOException - if reading from the reader or the call to the DOT utility fails.
      • renderDOT

        public static void renderDOT​(File dotFile,
                                     boolean modal)
                              throws IOException
        Renders a GraphVIZ description from a File and displays it in a Swing window. Convenience method, see renderDOT(Reader, boolean).
        Throws:
        IOException - if reading from the file or the call to the DOT utility fails.
      • renderDOT

        public static void renderDOT​(Reader r,
                                     boolean modal)
                              throws IOException
        Renders a GraphVIZ description from a Reader and displays it in a Swing window. Convenience method, see renderDOT(String, boolean).
        Throws:
        IOException - if reading from the reader or the call to the DOT utility fails.
      • renderDOT

        public static void renderDOT​(String dotText,
                                     boolean modal)
                              throws IOException
        Renders a GraphVIZ description and displays it in a Swing window.
        Parameters:
        dotText - the String from which the description is obtained.
        modal - whether the dialog should be modal.
        Throws:
        IOException - if the call to the DOT utility fails.
      • renderDOTStrings

        public static void renderDOTStrings​(List<Pair<String,​String>> dotTexts,
                                            boolean modal)
                                     throws IOException
        Renders multiple (named) GraphVIZ descriptions and displays them in a Swing window.
        Parameters:
        dotTexts - the Strings from which the description is obtained. The first element of the Pair should contain the name, the second element should contain the DOT code.
        modal - whether the dialog should be modal.
        Throws:
        IOException - if the calls to the DOT utility fail.
      • renderDOTImage

        public static BufferedImage renderDOTImage​(File dotFile)
                                            throws IOException
        Reads a DOT description from a file and returns the PNG rendering result as a BufferedImage.
        Parameters:
        dotFile - the file containing the DOT description
        Returns:
        the rendering result
        Throws:
        IOException - if reading from the file or the call to the DOT utility fails.
      • renderDOTImage

        public static BufferedImage renderDOTImage​(Reader dotReader)
                                            throws IOException
        Reads a DOT description from a reader and returns the PNG rendering result as a BufferedImage.
        Parameters:
        dotReader - the reader from which to read the description
        Returns:
        the rendering result
        Throws:
        IOException - if reading from the reader or the call to the DOT utility fails.
      • renderDOTImage

        public static BufferedImage renderDOTImage​(String dotText)
                                            throws IOException
        Reads a DOT description from a string and returns the PNG rendering result as a BufferedImage.
        Parameters:
        dotText - the DOT description
        Returns:
        the rendering result
        Throws:
        IOException - if the call to the DOT utility fails.