net.returnvoid.io

## Class ImageLoader

- java.lang.Object
- - net.returnvoid.io.DataLoader
  - - net.returnvoid.io.ImageLoader

-     public class ImageLoader
      extends DataLoader

  ImageLoader will handle to load files from type image (.jpg, .tif, .png, .gif). Currently doesn't support the automatic loading of files within sub-folders. The files are loaded "on demand" as they are tried to be read with the getCurrent() or any other get method. The class will handle to run through all files of the given type via methods (e.g. next()) or on a KeyEvent (keyPressed with a pre-defined / defined key / keycode).
  On default the keyPressed event with following keys are associated with following methods:
  Arrow left : previous() - previous image
  Arrow right : next() - next image
  Arrow up : first() - first image in directory
  Arrow down: last() - last image in directory
  Tab : nextRandom() - random image in directory
  Use disableKeys() to disable these automatic set key events.
  You can add ImageUpdateObservers. These observers will be informed when the current image has changed. (e.g. after every next() method call).
  Author:
    Diana Lange

- - ### Field Summary

    - ### Fields inherited from class net.returnvoid.io.DataLoader

      `COLOR_PALETTE, CSV, fileIndex, filePaths, IMAGE, JSON, parent, SHAPE, TEXT, type, XML`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ImageLoader(processing.core.PApplet parent)` Builds the ImageLoader and registers the KeyEvent to the parent (PApplet).
    `ImageLoader(processing.core.PApplet parent, boolean autoResize)` Builds the ImageLoader and registers the KeyEvent to the parent (PApplet).
    `ImageLoader(processing.core.PApplet parent, java.lang.String folderName)` Builds the ImageLoader and registers the KeyEvent to the parent (PApplet).
    `ImageLoader(processing.core.PApplet parent, java.lang.String folderName, boolean autoResize)` Builds the ImageLoader and registers the KeyEvent to the parent (PApplet).
    `ImageLoader(processing.core.PApplet parent, java.lang.String folderPath, java.lang.String folderName)` Builds the ImageLoader and registers the KeyEvent to the parent (PApplet).
    `ImageLoader(processing.core.PApplet parent, java.lang.String folderPath, java.lang.String folderName, boolean autoResize)` Builds the ImageLoader and registers the KeyEvent to the parent (PApplet).

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `ImageLoader` | `addObserver(ImageUpdateObserver observer)` Add an object that wants to be informed when there is a change of the current image.
    `ImageLoader` | `clearObservers()` Remove all observers from this loader.
    `ImageLoader` | `disableAutoResize()` Disable auto resizing of images.
    `ImageLoader` | `disableKeys()` Disable the automatic key events of this object.
    `ImageLoader` | `enableAutoResize()` Enable auto resizing of images.
    `ImageLoader` | `enableKeys()` Enables the automatic key events of this object.
    `processing.core.PImage` | `first()` Loads (if necessary) and returns the first file of the given folder.
    `processing.core.PImage` | `get(int index)` Loads (if necessary) and returns the file with the given index.
    `processing.core.PImage` | `getCurrent()` Loads (if necessary) and returns the current file.
    `processing.core.PImage` | `last()` Loads (if necessary) and returns the last file of the given folder.
    `processing.core.PImage[]` | `loadAllFiles()` Loads all files (if not loaded yet) and returns them all.
    `processing.core.PImage` | `loadFile(int index)` Loads a file with the given index and returns it.
    `processing.core.PImage` | `next()` Loads (if necessary) and returns the next file of the given folder.
    `processing.core.PImage` | `nextRandom()` Loads (if necessary) and returns the next random file of the given folder.
    `processing.core.PImage` | `previous()` Loads (if necessary) and returns the previous file of the given folder.
    `ImageLoader` | `removeObserver(ImageUpdateObserver observer)` Remove an observer from this loader.
    `ImageLoader` | `resetKeySettings()` Resets the key settings for the KeyEvents to its default.
    `ImageLoader` | `setIndex(int index)` Sets the current element.
    `ImageLoader` | `setIndex(java.lang.String filename)` Sets the current element.
    `ImageLoader` | `setKey(java.lang.String which, char key)` Links a certain method call (e.g. next()) with a certain key (e.g.
    `DataLoader` | `setKey(java.lang.String which, int keyCode)` Links a certain method call (e.g. next()) with a certain keyCode (e.g.
    `ImageLoader` | `update()` Re-Loads all the absolute paths for all valid files defined by the given type in the set folder.

    - ### Methods inherited from class net.returnvoid.io.DataLoader

      `getFileName, getFileName, getFileName, getFileName, getFolder, getLoadingDirectory, getPath, keyEvent, loadPaths, loadPaths, size`

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

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

- - ### Constructor Detail

    - #### ImageLoader

          public ImageLoader(processing.core.PApplet parent)

      Builds the ImageLoader and registers the KeyEvent to the parent (PApplet). The files have to be located in a sub-folder named "data" in the current sketch folder. The "data" folder should at least contain one image file. Auto resize is set to false.
      Parameters:
        `parent` - A PApplet object.

    - #### ImageLoader

          public ImageLoader(processing.core.PApplet parent,
                             boolean autoResize)

      Builds the ImageLoader and registers the KeyEvent to the parent (PApplet). The files have to be located in a sub-folder named "data" in the current sketch folder. The "data" folder should at least contain one image file.
      Parameters:
        `parent` - A PApplet object.
        `autoResize` - If true, all images will be resized to the parents width and height directly after they are loaded.

    - #### ImageLoader

          public ImageLoader(processing.core.PApplet parent,
                             java.lang.String folderName)

      Builds the ImageLoader and registers the KeyEvent to the parent (PApplet). The given folder should at least contain one image file. Auto resize is set to false.
      Parameters:
        `parent` - A PApplet object.
        `folderName` - Folder containing files (not null). This folder should at least contain one image file. The given folder should be a sub-folder in the current sketch folder or a relative path to the sketch folder. e.g. "..\\data" is a folder which is located in the parent directory of the sketch folder. Make sure to escape the backslashes in the path in the shown way.

    - #### ImageLoader

          public ImageLoader(processing.core.PApplet parent,
                             java.lang.String folderName,
                             boolean autoResize)

      Builds the ImageLoader and registers the KeyEvent to the parent (PApplet). The given folder should at least contain one image file.
      Parameters:
        `parent` - A PApplet object.
        `folderName` - Folder containing files (not null). This folder should at least contain one image file. The given folder should be a sub-folder in the current sketch folder or a relative path to the sketch folder. e.g. "..\\data" is a folder which is located in the parent directory of the sketch folder. Make sure to escape the backslashes in the path in the shown way.
        `autoResize` - If true, all images will be resized to the parents width and height directly after they are loaded.

    - #### ImageLoader

          public ImageLoader(processing.core.PApplet parent,
                             java.lang.String folderPath,
                             java.lang.String folderName)

      Builds the ImageLoader and registers the KeyEvent to the parent (PApplet). The given folder should at least contain one image file. Auto resize is set to false.
      Parameters:
        `parent` - A PApplet object.
        `folderPath` - A absolute path to the folder. Example: "C:\\" is the folderPath and "data " is the foldername then the files of the folder located at " C:\\data\\" will be loaded. Make sure to escape the backslashes in the path in the shown way. If folderPath is null, the sketch location will be used to set this path.
        `folderName` - Folder containing files (not null). This folder should at least contain one image file. The given folder should be a sub-folder of folderpath or a relative path to folderPath. e.g. "C:\\data" is the folderpath and "..\\temp" is the foldername then "C:\\temp\\" will be the location where the files will be loaded. Make sure to escape the backslashes in the path in the shown way.

    - #### ImageLoader

          public ImageLoader(processing.core.PApplet parent,
                             java.lang.String folderPath,
                             java.lang.String folderName,
                             boolean autoResize)

      Builds the ImageLoader and registers the KeyEvent to the parent (PApplet). The given folder should at least contain one image file.
      Parameters:
        `parent` - A PApplet object.
        `folderPath` - A absolute path to the folder. Example: "C:\\" is the folderPath and "data " is the foldername then the files of the folder located at " C:\\data\\" will be loaded. Make sure to escape the backslashes in the path in the shown way.
        `folderName` - Folder containing files (not null). This folder should at least contain one image file. The given folder should be a sub-folder of folderpath or a relative path to folderPath. e.g. "C:\\data" is the folderpath and "..\\temp" is the foldername then "C:\\temp\\" will be the location where the files will be loaded. Make sure to escape the backslashes in the path in the shown way.
        `autoResize` - If true, all images will be resized to the parents width and height directly after they are loaded.

  - ### Method Detail

    - #### update

          public ImageLoader update()

      Description copied from class: `DataLoader`
      Re-Loads all the absolute paths for all valid files defined by the given type in the set folder. All already loaded (and buffered) files will have to be reloaded afterwards. Update might get called after a change in the directory has been made (e.g. a file has been removed). The current object will still be the same after update() if the file still exits in the directory.
      Overrides:
        `update` in class `DataLoader`
      Returns:
        The DataLoader object.

    - #### resetKeySettings

          public ImageLoader resetKeySettings()

      Description copied from class: `DataLoader`
      Resets the key settings for the KeyEvents to its default. The default is:
      Arrow left = previous
      Arrow right = next
      Arrow up = first
      Arrow down = last
      Tabulator = next random
      Overrides:
        `resetKeySettings` in class `DataLoader`
      Returns:
        The DataLoader object.

    - #### disableKeys

          public ImageLoader disableKeys()

      Description copied from class: `DataLoader`
      Disable the automatic key events of this object.
      Overrides:
        `disableKeys` in class `DataLoader`
      Returns:
        The DataLoader object.

    - #### enableKeys

          public ImageLoader enableKeys()

      Description copied from class: `DataLoader`
      Enables the automatic key events of this object.
      Overrides:
        `enableKeys` in class `DataLoader`
      Returns:
        The DataLoader object.

    - #### setKey

          public DataLoader setKey(java.lang.String which,
                                   int keyCode)

      Description copied from class: `DataLoader`
      Links a certain method call (e.g. next()) with a certain keyCode (e.g. KeyEvent.VK_RIGHT).
      Overrides:
        `setKey` in class `DataLoader`
      Parameters:
        `which` - A String representing the method which should be linked to the keyCode. Possible values: \ "previous\", \"next\", \"first\", \"last\", \"random\".
        `keyCode` - The keyCode for the key which should be used for the given function.
      Returns:
        The DataLoader object.

    - #### setKey

          public ImageLoader setKey(java.lang.String which,
                                    char key)

      Description copied from class: `DataLoader`
      Links a certain method call (e.g. next()) with a certain key (e.g. \'n\').
      Overrides:
        `setKey` in class `DataLoader`
      Parameters:
        `which` - A String representing the method which should be linked to the keyCode. Possible values: \ "previous\", \"next\", \"first\", \"last\", \"random\".
        `key` - The char containing the key which should be used for the given function.
      Returns:
        The DataLoader object.

    - #### enableAutoResize

          public ImageLoader enableAutoResize()

      Enable auto resizing of images. If this is actived, the images will be resized to the width and height of the parent object.
      Returns:
        The current ImageLoader object.

    - #### disableAutoResize

          public ImageLoader disableAutoResize()

      Disable auto resizing of images. Images will be loaded with their actual size.
      Returns:
        The current ImageLoader object.

    - #### loadFile

          public processing.core.PImage loadFile(int index)

      Description copied from class: `DataLoader`
      Loads a file with the given index and returns it. Prevent out of bounds exception by checking the range with the size() method. Even if the files has been loaded before this will induce a load again. This might be useful if the content of the file has been changed in the meen time.
      Specified by:
        `loadFile` in class `DataLoader`
      Parameters:
        `index` - The index of the file which should be loaded.
      Returns:
        The loaded file.

    - #### loadAllFiles

          public processing.core.PImage[] loadAllFiles()

      Description copied from class: `DataLoader`
      Loads all files (if not loaded yet) and returns them all.
      Specified by:
        `loadAllFiles` in class `DataLoader`
      Returns:
        The object of the file.

    - #### nextRandom

          public processing.core.PImage nextRandom()

      Description copied from class: `DataLoader`
      Loads (if necessary) and returns the next random file of the given folder.
      Specified by:
        `nextRandom` in class `DataLoader`
      Returns:
        The object of the file.

    - #### previous

          public processing.core.PImage previous()

      Description copied from class: `DataLoader`
      Loads (if necessary) and returns the previous file of the given folder. The order of the files is set by their file names. Previous will load the file previous to the current file concerning their names.
      Specified by:
        `previous` in class `DataLoader`
      Returns:
        The object of the file.

    - #### next

          public processing.core.PImage next()

      Description copied from class: `DataLoader`
      Loads (if necessary) and returns the next file of the given folder. The order of the files is set by their file names. Previous will load the file previous to the current file concerning their names.
      Specified by:
        `next` in class `DataLoader`
      Returns:
        The object of the file.

    - #### first

          public processing.core.PImage first()

      Description copied from class: `DataLoader`
      Loads (if necessary) and returns the first file of the given folder. The order of the files is set by their file names.
      Specified by:
        `first` in class `DataLoader`
      Returns:
        The object of the file.

    - #### last

          public processing.core.PImage last()

      Description copied from class: `DataLoader`
      Loads (if necessary) and returns the last file of the given folder. The order of the files is set by their file names.
      Specified by:
        `last` in class `DataLoader`
      Returns:
        The object of the file.

    - #### setIndex

          public ImageLoader setIndex(int index)

      Sets the current element.
      Overrides:
        `setIndex` in class `DataLoader`
      Parameters:
        `index` - The index of the element which should be the current element. Index is in range of [0, size()).
      Returns:
        The current ImageLoader object.

    - #### setIndex

          public ImageLoader setIndex(java.lang.String filename)

      Description copied from class: `DataLoader`
      Sets the current element.
      Overrides:
        `setIndex` in class `DataLoader`
      Parameters:
        `filename` - The name of the file which should be the current element.
      Returns:
        The current DataLoader object.

    - #### getCurrent

          public processing.core.PImage getCurrent()

      Description copied from class: `DataLoader`
      Loads (if necessary) and returns the current file.
      Specified by:
        `getCurrent` in class `DataLoader`
      Returns:
        The object of the file.

    - #### get

          public processing.core.PImage get(int index)

      Description copied from class: `DataLoader`
      Loads (if necessary) and returns the file with the given index. Prevent out of bounds exception by checking the range with the size() method.
      Specified by:
        `get` in class `DataLoader`
      Returns:
        The object of the file.

    - #### addObserver

          public ImageLoader addObserver(ImageUpdateObserver observer)

      Add an object that wants to be informed when there is a change of the current image.
      Parameters:
        `observer` - An object that will be informed at a change of the current color palette.
      Returns:
        The ImageLoader object.

    - #### removeObserver

          public ImageLoader removeObserver(ImageUpdateObserver observer)

      Remove an observer from this loader.
      Parameters:
        `observer` - An object that was formerly an observer and which should be removed.
      Returns:
        The ImageLoader object.

    - #### clearObservers

          public ImageLoader clearObservers()

      Remove all observers from this loader.
      Returns:
        The ImageLoader object.