processing.app

## Class Base

- Object
- - Base

-     public class Base
      extends Object

  The base class for the main processing application. Primary role of this class is for platform identification and general interaction with the system (launching URLs, loading files and images, etc) that comes from that.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static boolean` | `DEBUG` True if heavy debugging error/log messages are enabled
    `static JMenu` | `defaultFileMenu` A lone file menu to be used when all sketch windows are closed.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Base(String[] args)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `calcFolderSize(File folder)` Calculate the size of the contents of a folder.
    `static String` | `contentsToClassPath(File folder)` Given a folder, return a list of absolute paths to all jar or zip files inside that folder, separated by pathSeparatorChar.
    `static void` | `copyDir(File sourceDir, File targetDir)` Copy a folder from one place to another.
    `static void` | `copyDirNative(File sourceDir, File targetDir)`
    `static void` | `copyFile(File sourceFile, File targetFile)`
    `static int` | `countLines(String what)` Get the number of lines in a file by counting the number of newline characters inside a String (and adding 1).
    `static File` | `createTempFolder(String prefix, String suffix, File directory)` Create a temporary folder by using the createTempFile() mechanism, deleting the file it creates, and making a folder using the location that was provided.
    `Editor` | `getActiveEditor()` Returns the front most, active editor window.
    `static File` | `getContentFile(String name)`
    `List<Editor>` | `getEditors()` Get the list of currently active editor windows.
    `static File` | `getJavaHome()`
    `static String` | `getJavaPath()` Get the path to the embedded Java executable.
    `static InputStream` | `getLibStream(String filename)` Return an InputStream for a file inside the Processing lib folder.
    `ArrayList<ModeContribution>` | `getModeContribs()`
    `ArrayList<Mode>` | `getModeList()`
    `static int` | `getNativeBits()` Return whether sketches will run as 32- or 64-bits based on the JVM that's in use.
    `static Platform` | `getPlatform()`
    `static int` | `getPlatformIndex(String what)`
    `static String` | `getPlatformName()`
    `static String` | `getPlatformName(int which)` Map a platform constant to its name.
    `JMenu` | `getRecentMenu()`
    `static int` | `getRevision()`
    `static File` | `getSettingsFile(String filename)` Convenience method to get a File object for the specified filename inside the settings folder.
    `static File` | `getSettingsFolder()`
    `static File` | `getSketchbookFolder()`
    `static File` | `getSketchbookLibrariesFolder()`
    `JMenu` | `getSketchbookMenu()`
    `static File` | `getSketchbookModesFolder()`
    `static File` | `getSketchbookToolsFolder()`
    `JMenu` | `getToolbarRecentMenu()`
    `static File` | `getToolsFolder()`
    `static String` | `getVersionName()` Return the version name, something like 1.5 or 2.0b8 or 0213 if it's not a release version.
    `boolean` | `handleClose(Editor editor, boolean modeSwitch)` Close a sketch as specified by its editor window.
    `void` | `handleNew()` Create a new untitled document in a new sketch window.
    `Editor` | `handleOpen(String path)` Open a sketch from the path specified.
    `Editor` | `handleOpen(String path, boolean untitled)` Open a sketch in a new window.
    `void` | `handleOpenLibraryManager()` Show the library installer window.
    `void` | `handleOpenModeManager()` Show the mode installer window.
    `void` | `handleOpenPrompt()` Prompt for a sketch to open, and open it in a new window.
    `void` | `handleOpenToolManager()` Show the tool installer window.
    `void` | `handlePrefs()` Show the Preferences window.
    `boolean` | `handleQuit()` Handler for File → Quit.
    `void` | `handleRecent(Editor editor)`
    `void` | `handleShowUpdates()`
    `static void` | `initPlatform()`
    `static void` | `initRequirements()`
    `static boolean` | `isLinux()` true if running on linux.
    `static boolean` | `isMacOS()` returns true if Processing is running on a Mac OS X machine.
    `static boolean` | `isUsableOracleJava()`
    `static boolean` | `isWindows()` returns true if running on windows.
    `static String[]` | `listFiles(File folder, boolean relative)` Recursively creates a list of all files within the specified folder, and returns a list of their relative paths.
    `static String[]` | `listFiles(File folder, boolean relative, String extension)`
    `static File[]` | `listJarFiles(File folder)`
    `static byte[]` | `loadBytesRaw(File file)` Same as PApplet.loadBytes(), however never does gzip decoding.
    `static String` | `loadFile(File file)` Grab the contents of a file as a string.
    `static void` | `locateSketchbookFolder()`
    `static void` | `log(Object from, String message)`
    `static void` | `log(String message)`
    `static void` | `log(String message, Throwable e)`
    `static void` | `logf(String message, Object... args)`
    `static void` | `main(String[] args)`
    `static void` | `openFolder(File file)` Implements the other cross-platform headache of opening a folder in the machine's native file browser.
    `static void` | `openURL(String url)` Implements the cross-platform headache of opening URLs.
    `static String[]` | `packageListFromClassPath(String path)` A classpath, separated by the path separator, will contain a series of .jar/.zip files or directories containing .class files, or containing subdirectories that have .class files.
    `static boolean` | `platformDelete(File file)` Delete a file or directory in a platform-specific manner.
    `void` | `populateSketchbookMenu(JMenu menu)`
    `static HashMap<String,String>` | `readSettings(File inputFile)` Read from a file with a bunch of attribute/value pairs that are separated by = and ignore comments with #.
    `static void` | `readSettings(String filename, String[] lines, HashMap<String,String> settings)` Parse a String array that contains attribute/value pairs separated by = (the equals sign).
    `static void` | `removeDescendants(File dir)` Recursively remove all files within a directory, used with removeDir(), or when the contents of a dir should be removed, but not the directory itself.
    `static void` | `removeDir(File dir)` Remove all files in a directory and the directory itself.
    `void` | `removeRecent(Editor editor)` Called before a sketch is renamed so that its old name is no longer in the menu.
    `static void` | `saveFile(String str, File file)` Spew the contents of a String object out to a file.
    `static void` | `setCommandLine()`
    `void` | `setSketchbookFolder(File folder)`
    `static void` | `showError(String title, String message, Throwable e)` Show an error message that's actually fatal to the program.
    `static void` | `showMessage(String title, String message)` "No cookie for you" type messages.
    `static void` | `showWarning(String title, String message, Throwable e)` Non-fatal error message with optional stack trace side dish.
    `static void` | `showWarningTiered(String title, String primary, String secondary, Throwable e)` Non-fatal error message with optional stack trace side dish.
    `static int` | `showYesNoCancelQuestion(Editor editor, String title, String primary, String secondary)`
    `static int` | `showYesNoQuestion(Frame editor, String title, String primary, String secondary)`
    `void` | `thinkDifferentExamples()`
    `static void` | `unzip(File zipFile, File dest)`

    - ### Methods inherited from class Object

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

- - ### Field Detail

    - #### DEBUG

          public static boolean DEBUG

      True if heavy debugging error/log messages are enabled

    - #### defaultFileMenu

          public static JMenu defaultFileMenu

      A lone file menu to be used when all sketch windows are closed.

  - ### Constructor Detail

    - #### Base

          public Base(String[] args)
               throws Exception

      Throws:
        `Exception`

  - ### Method Detail

    - #### main

          public static void main(String[] args)

    - #### setCommandLine

          public static void setCommandLine()

    - #### initPlatform

          public static void initPlatform()

    - #### initRequirements

          public static void initRequirements()

    - #### getActiveEditor

          public Editor getActiveEditor()

      Returns the front most, active editor window.

    - #### getEditors

          public List<Editor> getEditors()

      Get the list of currently active editor windows.

    - #### getModeContribs

          public ArrayList<ModeContribution> getModeContribs()

    - #### getModeList

          public ArrayList<Mode> getModeList()

    - #### handleNew

          public void handleNew()

      Create a new untitled document in a new sketch window.

    - #### handleOpenPrompt

          public void handleOpenPrompt()

      Prompt for a sketch to open, and open it in a new window.

    - #### handleOpen

          public Editor handleOpen(String path)

      Open a sketch from the path specified. Do not use for untitled sketches.

    - #### handleOpen

          public Editor handleOpen(String path,
                          boolean untitled)

      Open a sketch in a new window.
      Parameters:
        `path` - Path to the pde file for the sketch in question
      Returns:
        the Editor object, so that properties (like 'untitled') can be set by the caller

    - #### handleClose

          public boolean handleClose(Editor editor,
                            boolean modeSwitch)

      Close a sketch as specified by its editor window.
      Parameters:
        `editor` - Editor object of the sketch to be closed.
      Returns:
        true if succeeded in closing, false if canceled.

    - #### handleQuit

          public boolean handleQuit()

      Handler for File → Quit.
      Returns:
        false if canceled, true otherwise.

    - #### thinkDifferentExamples

          public void thinkDifferentExamples()

    - #### populateSketchbookMenu

          public void populateSketchbookMenu(JMenu menu)

    - #### getSketchbookMenu

          public JMenu getSketchbookMenu()

    - #### getRecentMenu

          public JMenu getRecentMenu()

    - #### getToolbarRecentMenu

          public JMenu getToolbarRecentMenu()

    - #### handleRecent

          public void handleRecent(Editor editor)

    - #### removeRecent

          public void removeRecent(Editor editor)

      Called before a sketch is renamed so that its old name is no longer in the menu.

    - #### handlePrefs

          public void handlePrefs()

      Show the Preferences window.

    - #### handleOpenLibraryManager

          public void handleOpenLibraryManager()

      Show the library installer window.

    - #### handleOpenToolManager

          public void handleOpenToolManager()

      Show the tool installer window.

    - #### handleOpenModeManager

          public void handleOpenModeManager()

      Show the mode installer window.

    - #### handleShowUpdates

          public void handleShowUpdates()

    - #### getRevision

          public static int getRevision()

    - #### getVersionName

          public static String getVersionName()

      Return the version name, something like 1.5 or 2.0b8 or 0213 if it's not a release version.

    - #### getPlatform

          public static Platform getPlatform()

    - #### getPlatformName

          public static String getPlatformName()

    - #### getNativeBits

          public static int getNativeBits()

      Return whether sketches will run as 32- or 64-bits based on the JVM that's in use.

    - #### getPlatformName

          public static String getPlatformName(int which)

      Map a platform constant to its name.
      Parameters:
        `which` - PConstants.WINDOWS, PConstants.MACOSX, PConstants.LINUX
      Returns:
        one of "windows", "macosx", or "linux"

    - #### getPlatformIndex

          public static int getPlatformIndex(String what)

    - #### isMacOS

          public static boolean isMacOS()

      returns true if Processing is running on a Mac OS X machine.

    - #### isUsableOracleJava

          public static boolean isUsableOracleJava()

    - #### isWindows

          public static boolean isWindows()

      returns true if running on windows.

    - #### isLinux

          public static boolean isLinux()

      true if running on linux.

    - #### getSettingsFolder

          public static File getSettingsFolder()

    - #### getSettingsFile

          public static File getSettingsFile(String filename)

      Convenience method to get a File object for the specified filename inside the settings folder. Used to get preferences and recent sketch files.
      Parameters:
        `filename` - A file inside the settings folder.
      Returns:
        filename wrapped as a File object inside the settings folder

    - #### createTempFolder

          public static File createTempFolder(String prefix,
                              String suffix,
                              File directory)
                                       throws IOException

      Create a temporary folder by using the createTempFile() mechanism, deleting the file it creates, and making a folder using the location that was provided. Unlike createTempFile(), there is no minimum size for prefix. If prefix is less than 3 characters, the remaining characters will be filled with underscores
      Throws:
        `IOException`

    - #### getToolsFolder

          public static File getToolsFolder()

    - #### locateSketchbookFolder

          public static void locateSketchbookFolder()

    - #### setSketchbookFolder

          public void setSketchbookFolder(File folder)

    - #### getSketchbookFolder

          public static File getSketchbookFolder()

    - #### getSketchbookLibrariesFolder

          public static File getSketchbookLibrariesFolder()

    - #### getSketchbookToolsFolder

          public static File getSketchbookToolsFolder()

    - #### getSketchbookModesFolder

          public static File getSketchbookModesFolder()

    - #### openURL

          public static void openURL(String url)

      Implements the cross-platform headache of opening URLs. For 2.0a8 and later, this requires the parameter to be an actual URL, meaning that you can't send it a file:// path without a prefix. It also just calls into Platform, which now uses java.awt.Desktop (where possible, meaning not on Linux) now that we're requiring Java 6. As it happens the URL must also be properly URL-encoded.

    - #### openFolder

          public static void openFolder(File file)

      Implements the other cross-platform headache of opening a folder in the machine's native file browser.

    - #### showMessage

          public static void showMessage(String title,
                         String message)

      "No cookie for you" type messages. Nothing fatal or all that much of a bummer, but something to notify the user about.

    - #### showWarning

          public static void showWarning(String title,
                         String message,
                         Throwable e)

      Non-fatal error message with optional stack trace side dish.

    - #### showWarningTiered

          public static void showWarningTiered(String title,
                               String primary,
                               String secondary,
                               Throwable e)

      Non-fatal error message with optional stack trace side dish.

    - #### showError

          public static void showError(String title,
                       String message,
                       Throwable e)

      Show an error message that's actually fatal to the program. This is an error that can't be recovered. Use showWarning() for errors that allow P5 to continue running.

    - #### showYesNoCancelQuestion

          public static int showYesNoCancelQuestion(Editor editor,
                                    String title,
                                    String primary,
                                    String secondary)

    - #### showYesNoQuestion

          public static int showYesNoQuestion(Frame editor,
                              String title,
                              String primary,
                              String secondary)

    - #### getContentFile

          public static File getContentFile(String name)

    - #### getJavaHome

          public static File getJavaHome()

    - #### getJavaPath

          public static String getJavaPath()

      Get the path to the embedded Java executable.

    - #### getLibStream

          public static InputStream getLibStream(String filename)
                                          throws IOException

      Return an InputStream for a file inside the Processing lib folder.
      Throws:
        `IOException`

    - #### countLines

          public static int countLines(String what)

      Get the number of lines in a file by counting the number of newline characters inside a String (and adding 1).

    - #### loadBytesRaw

          public static byte[] loadBytesRaw(File file)
                                     throws IOException

      Same as PApplet.loadBytes(), however never does gzip decoding.
      Throws:
        `IOException`

    - #### readSettings

          public static HashMap<String,String> readSettings(File inputFile)

      Read from a file with a bunch of attribute/value pairs that are separated by = and ignore comments with #.

    - #### readSettings

          public static void readSettings(String filename,
                          String[] lines,
                          HashMap<String,String> settings)

      Parse a String array that contains attribute/value pairs separated by = (the equals sign). The # (hash) symbol is used to denote comments. Comments can be anywhere on a line. Blank lines are ignored.

    - #### copyFile

          public static void copyFile(File sourceFile,
                      File targetFile)
                               throws IOException

      Throws:
        `IOException`

    - #### loadFile

          public static String loadFile(File file)
                                 throws IOException

      Grab the contents of a file as a string.
      Throws:
        `IOException`

    - #### saveFile

          public static void saveFile(String str,
                      File file)
                               throws IOException

      Spew the contents of a String object out to a file.
      Throws:
        `IOException`

    - #### copyDir

          public static void copyDir(File sourceDir,
                     File targetDir)
                              throws IOException

      Copy a folder from one place to another. This ignores all dot files and folders found in the source directory, to avoid copying silly .DS_Store files and potentially troublesome .svn folders.
      Throws:
        `IOException`

    - #### copyDirNative

          public static void copyDirNative(File sourceDir,
                           File targetDir)
                                    throws IOException

      Throws:
        `IOException`

    - #### platformDelete

          public static boolean platformDelete(File file)
                                        throws IOException

      Delete a file or directory in a platform-specific manner. Removes a File object (a file or directory) from the system by placing it in the Trash or Recycle Bin (if available) or simply deleting it (if not). When the file/folder is on another file system, it may simply be removed immediately, without additional warning. So only use this if you want to, you know, "delete" the subject in question. NOTE: Not yet tested nor ready for prime-time.
      Parameters:
        `file` - the victim (a directory or individual file)
      Returns:
        true if all ends well
      Throws:
        `IOException` - what went wrong

    - #### removeDir

          public static void removeDir(File dir)

      Remove all files in a directory and the directory itself.

    - #### removeDescendants

          public static void removeDescendants(File dir)

      Recursively remove all files within a directory, used with removeDir(), or when the contents of a dir should be removed, but not the directory itself. (i.e. when cleaning temp files from lib/build)

    - #### calcFolderSize

          public static int calcFolderSize(File folder)

      Calculate the size of the contents of a folder. Used to determine whether sketches are empty or not. Note that the function calls itself recursively.

    - #### listFiles

          public static String[] listFiles(File folder,
                           boolean relative)

      Recursively creates a list of all files within the specified folder, and returns a list of their relative paths. Ignores any files/folders prefixed with a dot.

    - #### listFiles

          public static String[] listFiles(File folder,
                           boolean relative,
                           String extension)

    - #### listJarFiles

          public static File[] listJarFiles(File folder)

      Parameters:
        `folder` - source folder to search
      Returns:
        a list of .jar and .zip files in that folder

    - #### contentsToClassPath

          public static String contentsToClassPath(File folder)

      Given a folder, return a list of absolute paths to all jar or zip files inside that folder, separated by pathSeparatorChar. This will prepend a colon (or whatever the path separator is) so that it can be directly appended to another path string. As of 0136, this will no longer add the root folder as well. This function doesn't bother checking to see if there are any .class files in the folder or within a subfolder.

    - #### packageListFromClassPath

          public static String[] packageListFromClassPath(String path)

      A classpath, separated by the path separator, will contain a series of .jar/.zip files or directories containing .class files, or containing subdirectories that have .class files.
      Parameters:
        `path` - the input classpath
      Returns:
        array of possible package names

    - #### unzip

          public static void unzip(File zipFile,
                   File dest)

    - #### log

          public static void log(Object from,
                 String message)

    - #### log

          public static void log(String message)

    - #### logf

          public static void logf(String message,
                  Object... args)

    - #### log

          public static void log(String message,
                 Throwable e)