processing.app
Class Base

java.lang.Object
  extended by processing.app.Base

public class Base
extends java.lang.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
static java.lang.String librariesClassPath
           
 
Constructor Summary
Base(java.lang.String[] args)
           
 
Method Summary
static int calcFolderSize(java.io.File folder)
          Calculate the size of the contents of a folder.
static void copyDir(java.io.File sourceDir, java.io.File targetDir)
          Copy a folder from one place to another.
static void copyFile(java.io.File sourceFile, java.io.File targetFile)
           
static int countLines(java.lang.String what)
          Get the number of lines in a file by counting the number of newline characters inside a String (and adding 1).
static java.io.File createTempFolder(java.lang.String name)
          Get the path to the platform's temporary folder, by creating a temporary temporary file and getting its parent folder.
static java.io.File getBuildFolder()
           
static java.io.File getContentFile(java.lang.String name)
          Get a path for something in the Processing lib folder.
static java.lang.String getExamplesPath()
           
static java.awt.Image getLibImage(java.lang.String name, java.awt.Component who)
          Return an Image object from inside the Processing lib folder.
static java.lang.String getLibrariesPath()
           
static java.io.InputStream getLibStream(java.lang.String filename)
          Return an InputStream for a file inside the Processing lib folder.
static int getPlatformIndex(java.lang.String what)
           
static java.lang.String getPlatformName()
          Get list of platform constants.
static java.lang.String getPlatformName(int which)
          Map a platform constant to its name.
static java.io.File getSettingsFile(java.lang.String filename)
          Convenience method to get a File object for the specified filename inside the settings folder.
static java.io.File getSettingsFolder()
           
static java.io.File getSketchbookFolder()
           
static java.io.File getSketchbookLibrariesFolder()
           
static java.awt.Image getThemeImage(java.lang.String name, java.awt.Component who)
          Get an image associated with the current color theme.
static java.io.File getToolsFolder()
           
static java.lang.String getToolsPath()
           
 void handleAbout()
          Show the About box.
 boolean handleClose(Editor editor)
          Close a sketch as specified by its editor window.
 void handleNew()
          Create a new untitled document in a new sketch window.
 void handleNewReplace()
          Replace the sketch in the current window with a new untitled document.
 Editor handleOpen(java.lang.String path)
          Open a sketch in a new window.
 void handleOpenPrompt()
          Prompt for a sketch to open, and open it in a new window.
 void handleOpenReplace(java.lang.String path)
          Open a sketch, replacing the sketch in the current window.
 void handlePrefs()
          Show the Preferences window.
 boolean handleQuit()
          Handler for File → Quit.
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 isWindows()
          returns true if running on windows.
static java.lang.String[] listFiles(java.io.File folder, boolean relative)
           
static java.lang.String[] listFiles(java.lang.String path, boolean relative)
          Recursively creates a list of all files within the specified folder, and returns a list of their relative paths.
static byte[] loadBytesRaw(java.io.File file)
          Same as PApplet.loadBytes(), however never does gzip decoding.
static java.lang.String loadFile(java.io.File file)
          Grab the contents of a file as a string.
static void main(java.lang.String[] args)
           
static void openFolder(java.io.File file)
          Implements the other cross-platform headache of opening a folder in the machine's native file browser.
static void openURL(java.lang.String url)
          Implements the cross-platform headache of opening URLs TODO This code should be replaced by PApplet.link(), however that's not a static method (because it requires an AppletContext when used as an applet), so it's mildly trickier than just removing this method.
 void rebuildExamplesMenu(javax.swing.JMenu menu)
           
 void rebuildImportMenu(javax.swing.JMenu importMenu)
           
static void registerWindowCloseKeys(javax.swing.JRootPane root, java.awt.event.ActionListener disposer)
          Registers key events for a Ctrl-W and ESC with an ActionListener that will take care of disposing the window.
static void removeDescendants(java.io.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(java.io.File dir)
          Remove all files in a directory and the directory itself.
static void saveFile(java.lang.String str, java.io.File file)
          Spew the contents of a String object out to a file.
static java.io.File selectFolder(java.lang.String prompt, java.io.File folder, java.awt.Frame frame)
          Prompt for a fodler and return it as a File object (or null).
static void setIcon(java.awt.Frame frame)
          Give this Frame a Processing icon.
static void showEnvironment()
           
static void showError(java.lang.String title, java.lang.String message, java.lang.Throwable e)
          Show an error message that's actually fatal to the program.
static void showMessage(java.lang.String title, java.lang.String message)
          "No cookie for you" type messages.
static void showPlatforms()
           
static void showReference()
           
static void showReference(java.lang.String filename)
           
static void showTroubleshooting()
           
static void showWarning(java.lang.String title, java.lang.String message, java.lang.Exception e)
          Non-fatal error message with optional stack trace side dish.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

librariesClassPath

public static java.lang.String librariesClassPath
Constructor Detail

Base

public Base(java.lang.String[] args)
Method Detail

main

public static void main(java.lang.String[] args)

handleNew

public void handleNew()
Create a new untitled document in a new sketch window.


handleNewReplace

public void handleNewReplace()
Replace the sketch in the current window with a new untitled document.


handleOpenReplace

public void handleOpenReplace(java.lang.String path)
Open a sketch, replacing the sketch in the current window.

Parameters:
path - Location of the primary pde file for the sketch.

handleOpenPrompt

public void handleOpenPrompt()
Prompt for a sketch to open, and open it in a new window.


handleOpen

public Editor handleOpen(java.lang.String path)
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)
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.

rebuildImportMenu

public void rebuildImportMenu(javax.swing.JMenu importMenu)

rebuildExamplesMenu

public void rebuildExamplesMenu(javax.swing.JMenu menu)

handleAbout

public void handleAbout()
Show the About box.


handlePrefs

public void handlePrefs()
Show the Preferences window.


getPlatformName

public static java.lang.String getPlatformName()
Get list of platform constants.


getPlatformName

public static java.lang.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(java.lang.String what)

isMacOS

public static boolean isMacOS()
returns true if Processing is running on a Mac OS X machine.


isWindows

public static boolean isWindows()
returns true if running on windows.


isLinux

public static boolean isLinux()
true if running on linux.


getSettingsFolder

public static java.io.File getSettingsFolder()

getSettingsFile

public static java.io.File getSettingsFile(java.lang.String filename)
Convenience method to get a File object for the specified filename inside the settings folder. For now, only used by Preferences to get the preferences.txt file.

Parameters:
filename - A file inside the settings folder.
Returns:
filename wrapped as a File object inside the settings folder

getBuildFolder

public static java.io.File getBuildFolder()

createTempFolder

public static java.io.File createTempFolder(java.lang.String name)
Get the path to the platform's temporary folder, by creating a temporary temporary file and getting its parent folder.
Modified for revision 0094 to actually make the folder randomized to avoid conflicts in multi-user environments. (Bug 177)


getExamplesPath

public static java.lang.String getExamplesPath()

getLibrariesPath

public static java.lang.String getLibrariesPath()

getToolsFolder

public static java.io.File getToolsFolder()

getToolsPath

public static java.lang.String getToolsPath()

getSketchbookFolder

public static java.io.File getSketchbookFolder()

getSketchbookLibrariesFolder

public static java.io.File getSketchbookLibrariesFolder()

openURL

public static void openURL(java.lang.String url)
Implements the cross-platform headache of opening URLs TODO This code should be replaced by PApplet.link(), however that's not a static method (because it requires an AppletContext when used as an applet), so it's mildly trickier than just removing this method.


openFolder

public static void openFolder(java.io.File file)
Implements the other cross-platform headache of opening a folder in the machine's native file browser.


selectFolder

public static java.io.File selectFolder(java.lang.String prompt,
                                        java.io.File folder,
                                        java.awt.Frame frame)
Prompt for a fodler and return it as a File object (or null). Implementation for choosing directories that handles both the Mac OS X hack to allow the native AWT file dialog, or uses the JFileChooser on other platforms. Mac AWT trick obtained from this post on the OS X Java dev archive which explains the cryptic note in Apple's Java 1.4 release docs about the special System property.


setIcon

public static void setIcon(java.awt.Frame frame)
Give this Frame a Processing icon.


registerWindowCloseKeys

public static void registerWindowCloseKeys(javax.swing.JRootPane root,
                                           java.awt.event.ActionListener disposer)
Registers key events for a Ctrl-W and ESC with an ActionListener that will take care of disposing the window.


showReference

public static void showReference(java.lang.String filename)

showReference

public static void showReference()

showEnvironment

public static void showEnvironment()

showPlatforms

public static void showPlatforms()

showTroubleshooting

public static void showTroubleshooting()

showMessage

public static void showMessage(java.lang.String title,
                               java.lang.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(java.lang.String title,
                               java.lang.String message,
                               java.lang.Exception e)
Non-fatal error message with optional stack trace side dish.


showError

public static void showError(java.lang.String title,
                             java.lang.String message,
                             java.lang.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.


getContentFile

public static java.io.File getContentFile(java.lang.String name)
Get a path for something in the Processing lib folder.


getThemeImage

public static java.awt.Image getThemeImage(java.lang.String name,
                                           java.awt.Component who)
Get an image associated with the current color theme.


getLibImage

public static java.awt.Image getLibImage(java.lang.String name,
                                         java.awt.Component who)
Return an Image object from inside the Processing lib folder.


getLibStream

public static java.io.InputStream getLibStream(java.lang.String filename)
                                        throws java.io.IOException
Return an InputStream for a file inside the Processing lib folder.

Throws:
java.io.IOException

countLines

public static int countLines(java.lang.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(java.io.File file)
                           throws java.io.IOException
Same as PApplet.loadBytes(), however never does gzip decoding.

Throws:
java.io.IOException

copyFile

public static void copyFile(java.io.File sourceFile,
                            java.io.File targetFile)
                     throws java.io.IOException
Throws:
java.io.IOException

loadFile

public static java.lang.String loadFile(java.io.File file)
                                 throws java.io.IOException
Grab the contents of a file as a string.

Throws:
java.io.IOException

saveFile

public static void saveFile(java.lang.String str,
                            java.io.File file)
                     throws java.io.IOException
Spew the contents of a String object out to a file.

Throws:
java.io.IOException

copyDir

public static void copyDir(java.io.File sourceDir,
                           java.io.File targetDir)
                    throws java.io.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:
java.io.IOException

removeDir

public static void removeDir(java.io.File dir)
Remove all files in a directory and the directory itself.


removeDescendants

public static void removeDescendants(java.io.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(java.io.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 java.lang.String[] listFiles(java.lang.String path,
                                           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 java.lang.String[] listFiles(java.io.File folder,
                                           boolean relative)