OutputManager
Date: 2019-10-22

org.jmol.viewer

## Class OutputManager

- java.lang.Object
- - org.jmol.viewer.OutputManager

- Direct Known Subclasses:
    OutputManagerAwt, OutputManagerJS

      abstract class OutputManager
      extends java.lang.Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected double` | `privateKey`
    `protected static java.lang.String` | `SCENE_TAG`
    `protected Viewer` | `vwr`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `OutputManager()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `private java.lang.String` | `addPngFileBytes(java.lang.String name, byte[] ret, int iFile, java.util.Hashtable<java.lang.Object,java.lang.String> crcMap, boolean isSparDir, java.lang.String newName, int ptSlash, javajs.util.Lst<java.lang.Object> v)`
    `(package private) abstract java.lang.String` | `clipImageOrPasteText(java.lang.String text)`
    `protected abstract java.lang.String` | `createSceneSet(java.lang.String sceneFile, java.lang.String type, int width, int height)`
    `private boolean` | `createTheImage(java.lang.Object objImage, java.lang.String type, javajs.util.OC out, java.util.Map<java.lang.String,java.lang.Object> params, java.lang.String[] errRet)`
    `private java.lang.String` | `createZipSet(java.lang.String script, java.lang.String[] scripts, boolean includeRemoteFiles, javajs.util.OC out, java.lang.String pngjName)`
    `private int[]` | `encodeImage(int width, int height, java.lang.Object objImage)` general image encoder, allows for BufferedImage, int[], or HTML5 2D canvas
    `(package private) abstract java.lang.String` | `getClipboardText()`
    `(package private) byte[]` | `getImageAsBytes(java.lang.String type, int width, int height, int quality, java.lang.String[] errMsg)` Called when a simple image is required -- from x=getProperty("image") or for a simple preview PNG image for inclusion in a ZIP file from write xxx.zip or xxx.jmol, or for a PNGJ or PNG image that is being posted because of a URL that contains "?POST?_PNG_" or ?POST?_PNGJ_" or ?POST?_PNGJBIN_".
    `private static int` | `getInt(java.util.Map<java.lang.String,java.lang.Object> params, java.lang.String key, int def)`
    `protected abstract java.lang.String` | `getLogPath(java.lang.String fileName)`
    `private java.lang.Object` | `getOrSaveImage(java.util.Map<java.lang.String,java.lang.Object> params)` Creates an image of params.type form -- PNG, PNGJ, PNGT, JPG, JPG64, PDF, PPM, GIF, GIFT.
    `(package private) javajs.util.OC` | `getOutputChannel(java.lang.String fileName, java.lang.String[] fullPath)`
    `private java.lang.String` | `getOutputFileNameFromDialog(java.lang.String fileName, int quality, java.util.Map<java.lang.String,java.lang.Object> params)`
    `(package private) java.lang.String` | `getOutputFromExport(java.util.Map<java.lang.String,java.lang.Object> params)`
    `private static java.lang.Object` | `getRootExt(java.lang.String fileName, java.lang.String[] rootExt, int n)`
    `(package private) java.lang.Object` | `getWrappedState(java.lang.String pngjName, java.lang.String[] scripts, java.lang.Object objImage, javajs.util.OC pgjOut)`
    `protected java.lang.String` | `handleOutputToFile(java.util.Map<java.lang.String,java.lang.Object> params, boolean doCheck)` general routine for creating an image or writing data to a file passes request to statusManager to pass along to app or applet jmolStatusListener interface
    `(package private) void` | `logToFile(java.lang.String data)`
    `(package private) abstract javajs.util.OC` | `openOutputChannel(double privateKey, java.lang.String fileName, boolean asWriter, boolean asAppend)`
    `(package private) java.lang.String` | `outputToFile(java.util.Map<java.lang.String,java.lang.Object> params)`
    `private java.lang.String` | `processMultiFrameOutput(java.lang.String fileName, javajs.util.BS bsFrames, int nVibes, java.util.Map<java.lang.String,java.lang.Object> params)`
    `(package private) java.lang.String` | `processWriteOrCapture(java.util.Map<java.lang.String,java.lang.Object> params)`
    `private java.lang.String` | `setFullPath(java.util.Map<java.lang.String,java.lang.Object> params, java.lang.String fileName)`
    `(package private) java.lang.String` | `setLogFile(java.lang.String value)`
    `(package private) OutputManager` | `setViewer(Viewer vwr, double privateKey)`
    `protected java.lang.String` | `wrapPathForAllFiles(java.lang.String cmd, java.lang.String strCatch)`
    `(package private) java.lang.String` | `writeFileData(java.lang.String fileName, java.lang.String type, int modelIndex, java.lang.Object[] plotParameters)` Generates file data and passes it on either to a FileOuputStream (Java) or via POSTing to a url using a ByteOutputStream (JavaScript)
    `private boolean` | `writeFrame(int n, java.lang.String[] rootExt, java.util.Map<java.lang.String,java.lang.Object> params, javajs.util.SB sb)`
    `private java.lang.String` | `writeToOutputChannel(java.util.Map<java.lang.String,java.lang.Object> params)` From handleOutputToFile, write text, byte[], or image data to a file;
    `private java.lang.String` | `writeZipFile(javajs.util.OC out, javajs.util.Lst<java.lang.Object> fileNamesAndByteArrays, java.lang.String msg, java.lang.String pngjName)` generic method to create a zip file based on http://www.exampledepot.com/egs/java.util.zip/CreateZip.html

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### vwr

          protected Viewer vwr

    - #### privateKey

          protected double privateKey

    - #### SCENE_TAG

          protected static final java.lang.String SCENE_TAG

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### OutputManager

          OutputManager()

  - ### Method Detail

    - #### getLogPath

          protected abstract java.lang.String getLogPath(java.lang.String fileName)

    - #### clipImageOrPasteText

          abstract java.lang.String clipImageOrPasteText(java.lang.String text)

    - #### getClipboardText

          abstract java.lang.String getClipboardText()

    - #### openOutputChannel

          abstract javajs.util.OC openOutputChannel(double privateKey,
                                                    java.lang.String fileName,
                                                    boolean asWriter,
                                                    boolean asAppend)
                                             throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### createSceneSet

          protected abstract java.lang.String createSceneSet(java.lang.String sceneFile,
                                                             java.lang.String type,
                                                             int width,
                                                             int height)

    - #### setViewer

          OutputManager setViewer(Viewer vwr,
                                  double privateKey)

    - #### writeToOutputChannel

          private java.lang.String writeToOutputChannel(java.util.Map<java.lang.String,java.lang.Object> params)

      From handleOutputToFile, write text, byte[], or image data to a file;
      Parameters:
        `params` -
      Returns:
        null (canceled) or byte[] or String message starting with OK or an error message; in the case of params.image != null, return the fileName

    - #### getOrSaveImage

          private java.lang.Object getOrSaveImage(java.util.Map<java.lang.String,java.lang.Object> params)
                                           throws java.lang.Exception

      Creates an image of params.type form -- PNG, PNGJ, PNGT, JPG, JPG64, PDF, PPM, GIF, GIFT. From createImage and getImageAsBytes
      Parameters:
        `params` - include fileName, type, text, bytes, image, scripts, appendix, quality, outputStream, and type-specific parameters. If params.outputChannel != null, then we are passing back the data, and the channel will not be closed.
      Returns:
        bytes[] if params.fileName==null and params.outputChannel==null otherwise, return a message string or null
      Throws:
        `java.lang.Exception`

    - #### getWrappedState

          java.lang.Object getWrappedState(java.lang.String pngjName,
                                           java.lang.String[] scripts,
                                           java.lang.Object objImage,
                                           javajs.util.OC pgjOut)

      Parameters:
        `pngjName` -
        `scripts` -
        `objImage` -
        `pgjOut` -
      Returns:
        either byte[] (a full ZIP file) or String (just an embedded state script)

    - #### createTheImage

          private boolean createTheImage(java.lang.Object objImage,
                                         java.lang.String type,
                                         javajs.util.OC out,
                                         java.util.Map<java.lang.String,java.lang.Object> params,
                                         java.lang.String[] errRet)

      Parameters:
        `objImage` -
        `type` -
        `out` -
        `params` -
        `errRet` -
      Returns:
        byte array if needed

    - #### encodeImage

          private int[] encodeImage(int width,
                                    int height,
                                    java.lang.Object objImage)
                             throws java.lang.Exception

      general image encoder, allows for BufferedImage, int[], or HTML5 2D canvas
      Parameters:
        `width` -
        `height` -
        `objImage` -
      Returns:
        linear int[] array of ARGB values
      Throws:
        `java.lang.Exception`

    - #### outputToFile

          java.lang.String outputToFile(java.util.Map<java.lang.String,java.lang.Object> params)

    - #### getOutputChannel

          javajs.util.OC getOutputChannel(java.lang.String fileName,
                                          java.lang.String[] fullPath)

    - #### processWriteOrCapture

          java.lang.String processWriteOrCapture(java.util.Map<java.lang.String,java.lang.Object> params)

      Parameters:
        `params` - include fileName, type, text, bytes, scripts, quality, width, height, bsFrames, nVibes, fullPath
      Returns:
        message

    - #### getInt

          private static int getInt(java.util.Map<java.lang.String,java.lang.Object> params,
                                    java.lang.String key,
                                    int def)

    - #### processMultiFrameOutput

          private java.lang.String processMultiFrameOutput(java.lang.String fileName,
                                                           javajs.util.BS bsFrames,
                                                           int nVibes,
                                                           java.util.Map<java.lang.String,java.lang.Object> params)

    - #### getRootExt

          private static java.lang.Object getRootExt(java.lang.String fileName,
                                                     java.lang.String[] rootExt,
                                                     int n)

    - #### setFullPath

          private java.lang.String setFullPath(java.util.Map<java.lang.String,java.lang.Object> params,
                                               java.lang.String fileName)

    - #### getOutputFromExport

          java.lang.String getOutputFromExport(java.util.Map<java.lang.String,java.lang.Object> params)

    - #### getImageAsBytes

          byte[] getImageAsBytes(java.lang.String type,
                                 int width,
                                 int height,
                                 int quality,
                                 java.lang.String[] errMsg)

      Called when a simple image is required -- from x=getProperty("image") or for a simple preview PNG image for inclusion in a ZIP file from write xxx.zip or xxx.jmol, or for a PNGJ or PNG image that is being posted because of a URL that contains "?POST?_PNG_" or ?POST?_PNGJ_" or ?POST?_PNGJBIN_".
      Parameters:
        `type` -
        `width` -
        `height` -
        `quality` -
        `errMsg` -
      Returns:
        image bytes or, if an error, null and an error message

    - #### writeFileData

          java.lang.String writeFileData(java.lang.String fileName,
                                         java.lang.String type,
                                         int modelIndex,
                                         java.lang.Object[] plotParameters)

      Generates file data and passes it on either to a FileOuputStream (Java) or via POSTing to a url using a ByteOutputStream (JavaScript)
      Parameters:
        `fileName` -
        `type` - one of: PDB PQR FILE PLOT
        `modelIndex` -
        `plotParameters` -
      Returns:
        "OK..." or "" or null

    - #### writeFrame

          private boolean writeFrame(int n,
                                     java.lang.String[] rootExt,
                                     java.util.Map<java.lang.String,java.lang.Object> params,
                                     javajs.util.SB sb)

    - #### getOutputFileNameFromDialog

          private java.lang.String getOutputFileNameFromDialog(java.lang.String fileName,
                                                               int quality,
                                                               java.util.Map<java.lang.String,java.lang.Object> params)

    - #### handleOutputToFile

          protected java.lang.String handleOutputToFile(java.util.Map<java.lang.String,java.lang.Object> params,
                                                        boolean doCheck)

      general routine for creating an image or writing data to a file passes request to statusManager to pass along to app or applet jmolStatusListener interface
      Parameters:
        `params` - include: fileName: starts with ? --> use file dialog; type: PNG, JPG, etc.; text: String to output; bytes: byte[] or null if an image; scripts for scenes; quality: for JPG and PNG; width: image width; height: image height; fullPath: String[] return
        `doCheck` -
      Returns:
        null (canceled) or a message starting with OK or an error message

    - #### setLogFile

          java.lang.String setLogFile(java.lang.String value)

    - #### logToFile

          void logToFile(java.lang.String data)

    - #### createZipSet

          private java.lang.String createZipSet(java.lang.String script,
                                                java.lang.String[] scripts,
                                                boolean includeRemoteFiles,
                                                javajs.util.OC out,
                                                java.lang.String pngjName)

    - #### addPngFileBytes

          private java.lang.String addPngFileBytes(java.lang.String name,
                                                   byte[] ret,
                                                   int iFile,
                                                   java.util.Hashtable<java.lang.Object,java.lang.String> crcMap,
                                                   boolean isSparDir,
                                                   java.lang.String newName,
                                                   int ptSlash,
                                                   javajs.util.Lst<java.lang.Object> v)

    - #### writeZipFile

          private java.lang.String writeZipFile(javajs.util.OC out,
                                                javajs.util.Lst<java.lang.Object> fileNamesAndByteArrays,
                                                java.lang.String msg,
                                                java.lang.String pngjName)

      generic method to create a zip file based on http://www.exampledepot.com/egs/java.util.zip/CreateZip.html
      Parameters:
        `out` -
        `fileNamesAndByteArrays` - Vector of [filename1, bytes|null, filename2, bytes|null, ...]
        `msg` -
        `pngjName` - TODO
      Returns:
        msg bytes filename or errorMessage or byte[]

    - #### wrapPathForAllFiles

          protected java.lang.String wrapPathForAllFiles(java.lang.String cmd,
                                                         java.lang.String strCatch)