processing.app

## Class Mode

- Object
- - Mode

-     public abstract class Mode
      extends Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `ArrayList<Library>` | `contribLibraries`
    `ArrayList<Library>` | `coreLibraries`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Mode(Base base, File folder)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `DefaultMutableTreeNode` | `buildExamplesTree()`
    `DefaultMutableTreeNode` | `buildSketchbookTree()`
    `boolean` | `canEdit(File f)`
    `abstract Editor` | `createEditor(Base base, String path, EditorState state)` Create a new editor associated with this mode.
    `Library` | `findLibraryByName(String libName)` Checks coreLibraries and contribLibraries for a library with the specified name
    `boolean` | `getBoolean(String attribute)`
    `ClassLoader` | `getClassLoader()`
    `Color` | `getColor(String attribute)`
    `File` | `getContentFile(String path)`
    `InputStream` | `getContentStream(String path)`
    `Library` | `getCoreLibrary()`
    `abstract String` | `getDefaultExtension()` Returns the default extension for this editor setup.
    `File[]` | `getExampleCategoryFolders()` Override this to control the order of the first set of example folders and how they appear in the examples window.
    `File` | `getExamplesFolder()`
    `abstract String[]` | `getExtensions()` Returns a String[] array of proper extensions.
    `File` | `getFolder()` Get the folder where this mode is stored.
    `Font` | `getFont(String attribute)`
    `String` | `getIdentifier()` Get an identifier that can be used to resurrect this mode and connect it to a sketch.
    `abstract String[]` | `getIgnorable()` Get array of file/directory names that needn't be copied during "Save As".
    `JMenu` | `getImportMenu()`
    `int` | `getInteger(String attribute)`
    `File[]` | `getKeywordFiles()` To add additional keywords, or to grab them from another mode, override this function.
    `File` | `getLibrariesFolder()`
    `Library` | `getLibrary(String pkgName)`
    `String` | `getModuleExtension()` Returns the appropriate file extension to use for auxilliary source files in a sketch.
    `File` | `getReferenceFolder()`
    `String` | `getString(String attribute)`
    `SyntaxStyle` | `getStyle(String attribute)`
    `abstract String` | `getTitle()` Return the pretty/printable/menu name for this mode.
    `TokenMarker` | `getTokenMarker()`
    `JMenu` | `getToolbarMenu()`
    `boolean` | `hideExtension(String what)` True if the specified extension should be hidden when shown on a tab.
    `void` | `insertImportMenu(JMenu sketchMenu)` Re-insert the Import Library menu.
    `void` | `insertToolbarRecentMenu()`
    `boolean` | `isDefaultExtension(SketchCode code)` True if the specified code has the default file extension.
    `boolean` | `isDefaultExtension(String what)` True if the specified extension is the default file extension.
    `ImageIcon` | `loadIcon(String filename)` Get an ImageIcon object from the Mode folder.
    `Image` | `loadImage(String filename)` Get an image object from the mode folder.
    `String` | `lookupReference(String keyword)` Returns the HTML filename (including path prefix if necessary) for this keyword, or null if it doesn't exist.
    `Image` | `makeGradient(String attribute, int wide, int high)`
    `void` | `prepareExportFolder(File targetFolder)` Create a fresh applet/application folder if the 'delete target folder' pref has been set in the preferences.
    `void` | `rebuildExamplesFrame()`
    `void` | `rebuildImportMenu()`
    `void` | `rebuildLibraryList()`
    `void` | `rebuildSketchbookFrame()` Sketchbook has changed, update it on next viewing.
    `void` | `removeImportMenu(JMenu sketchMenu)` Rather than re-building the library menu for every open sketch (very slow and prone to bugs when updating libs, particularly with the contribs mgr), share a single instance across all windows.
    `void` | `removeToolbarRecentMenu()`
    `void` | `setClassLoader(ClassLoader loader)`
    `void` | `setupGUI()` Setup additional elements that are only required when running with a GUI, rather than from the command-line.
    `void` | `showExamplesFrame()`
    `void` | `showSketchbookFrame()`
    `String` | `toString()`
    `boolean` | `validExtension(String what)` Check this extension (no dots, please) against the list of valid extensions.

    - ### Methods inherited from class Object

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

- - ### Field Detail

    - #### coreLibraries

          public ArrayList<Library> coreLibraries

    - #### contribLibraries

          public ArrayList<Library> contribLibraries

  - ### Constructor Detail

    - #### Mode

          public Mode(Base base,
                      File folder)

  - ### Method Detail

    - #### getKeywordFiles

          public File[] getKeywordFiles()

      To add additional keywords, or to grab them from another mode, override this function. If your mode has no keywords, return a zero length array.

    - #### setClassLoader

          public void setClassLoader(ClassLoader loader)

    - #### getClassLoader

          public ClassLoader getClassLoader()

    - #### setupGUI

          public void setupGUI()

      Setup additional elements that are only required when running with a GUI, rather than from the command-line. Note that this will not be called when the Mode is used from the command line (because Base will be null).

    - #### getContentFile

          public File getContentFile(String path)

    - #### getContentStream

          public InputStream getContentStream(String path)
                                       throws FileNotFoundException

      Throws:
        `FileNotFoundException`

    - #### getTitle

          public abstract String getTitle()

      Return the pretty/printable/menu name for this mode. This is separate from the single word name of the folder that contains this mode. It could even have spaces, though that might result in sheer madness or total mayhem.

    - #### getIdentifier

          public String getIdentifier()

      Get an identifier that can be used to resurrect this mode and connect it to a sketch. Using this instead of getTitle() because there might be name clashes with the titles, but there should not be once the actual package, et al. is included.
      Returns:
        full name (package + class name) for this mode.

    - #### createEditor

          public abstract Editor createEditor(Base base,
                                              String path,
                                              EditorState state)

      Create a new editor associated with this mode.

    - #### getFolder

          public File getFolder()

      Get the folder where this mode is stored.
      Since:
        3.0a3

    - #### getExamplesFolder

          public File getExamplesFolder()

    - #### getLibrariesFolder

          public File getLibrariesFolder()

    - #### getReferenceFolder

          public File getReferenceFolder()

    - #### rebuildLibraryList

          public void rebuildLibraryList()

    - #### getCoreLibrary

          public Library getCoreLibrary()

    - #### getLibrary

          public Library getLibrary(String pkgName)
                             throws SketchException

      Throws:
        `SketchException`

    - #### getToolbarMenu

          public JMenu getToolbarMenu()

    - #### insertToolbarRecentMenu

          public void insertToolbarRecentMenu()

    - #### removeToolbarRecentMenu

          public void removeToolbarRecentMenu()

    - #### removeImportMenu

          public void removeImportMenu(JMenu sketchMenu)

      Rather than re-building the library menu for every open sketch (very slow and prone to bugs when updating libs, particularly with the contribs mgr), share a single instance across all windows.
      Parameters:
        `sketchMenu` - the Sketch menu that's currently active
      Since:
        3.0a6

    - #### insertImportMenu

          public void insertImportMenu(JMenu sketchMenu)

      Re-insert the Import Library menu. Added function so that other modes need not have an 'import' menu.
      Parameters:
        `sketchMenu` - the Sketch menu that's currently active
      Since:
        3.0a6

    - #### getImportMenu

          public JMenu getImportMenu()

    - #### rebuildImportMenu

          public void rebuildImportMenu()

    - #### getExampleCategoryFolders

          public File[] getExampleCategoryFolders()

      Override this to control the order of the first set of example folders and how they appear in the examples window.

    - #### buildExamplesTree

          public DefaultMutableTreeNode buildExamplesTree()

    - #### rebuildExamplesFrame

          public void rebuildExamplesFrame()

    - #### showExamplesFrame

          public void showExamplesFrame()

    - #### buildSketchbookTree

          public DefaultMutableTreeNode buildSketchbookTree()

    - #### rebuildSketchbookFrame

          public void rebuildSketchbookFrame()

      Sketchbook has changed, update it on next viewing.

    - #### showSketchbookFrame

          public void showSketchbookFrame()

    - #### loadIcon

          public ImageIcon loadIcon(String filename)

      Get an ImageIcon object from the Mode folder. Or when prefixed with /lib, load it from the main /lib folder.
      Since:
        3.0a6

    - #### loadImage

          public Image loadImage(String filename)

      Get an image object from the mode folder. Or when prefixed with /lib, load it from the main /lib folder.

    - #### lookupReference

          public String lookupReference(String keyword)

      Returns the HTML filename (including path prefix if necessary) for this keyword, or null if it doesn't exist.

    - #### getTokenMarker

          public TokenMarker getTokenMarker()

    - #### getString

          public String getString(String attribute)

      Since:
        3.0a6

    - #### getBoolean

          public boolean getBoolean(String attribute)

    - #### getInteger

          public int getInteger(String attribute)

    - #### getColor

          public Color getColor(String attribute)

    - #### getFont

          public Font getFont(String attribute)

    - #### getStyle

          public SyntaxStyle getStyle(String attribute)

    - #### makeGradient

          public Image makeGradient(String attribute,
                                    int wide,
                                    int high)

    - #### hideExtension

          public boolean hideExtension(String what)

      True if the specified extension should be hidden when shown on a tab. For Processing, this is true for .pde files. (Broken out for subclasses.) You can override this in your Mode subclass to handle it differently.

    - #### isDefaultExtension

          public boolean isDefaultExtension(SketchCode code)

      True if the specified code has the default file extension.

    - #### isDefaultExtension

          public boolean isDefaultExtension(String what)

      True if the specified extension is the default file extension.

    - #### canEdit

          public boolean canEdit(File f)

      Parameters:
        `f` - File to be checked against this mode's accepted extensions.
      Returns:
        Whether or not the given file name features an extension supported by this mode.

    - #### validExtension

          public boolean validExtension(String what)

      Check this extension (no dots, please) against the list of valid extensions.

    - #### getDefaultExtension

          public abstract String getDefaultExtension()

      Returns the default extension for this editor setup.

    - #### getModuleExtension

          public String getModuleExtension()

      Returns the appropriate file extension to use for auxilliary source files in a sketch. For example, in a Java-mode sketch, auxilliary files should be name "Foo.java"; in Python mode, they should be named "foo.py".

      Modes that do not override this function will get the default behavior of returning the default extension.

    - #### getExtensions

          public abstract String[] getExtensions()

      Returns a String[] array of proper extensions.

    - #### getIgnorable

          public abstract String[] getIgnorable()

      Get array of file/directory names that needn't be copied during "Save As".

    - #### findLibraryByName

          public Library findLibraryByName(String libName)

      Checks coreLibraries and contribLibraries for a library with the specified name
      Parameters:
        `libName` - the name of the library to find
      Returns:
        the Library or null if not found

    - #### prepareExportFolder

          public void prepareExportFolder(File targetFolder)

      Create a fresh applet/application folder if the 'delete target folder' pref has been set in the preferences.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`