public abstract class DataLoader
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
COLOR_PALETTE
File type: COLOR_PALETTE (.color.json)
|
static int |
CSV
File type: CSV (.csv)
|
protected int |
fileIndex
The index of the current loaded file.
|
protected java.lang.String[] |
filePaths
Contains the absolut paths to files which will be loaded.
|
static int |
IMAGE
File type: Image (.jpg, .gif, .png, ...)
|
static int |
JSON
File type: JSON (.json)
|
protected processing.core.PApplet |
parent
The PApplet object (KeyEvents will be regulated by it).
|
static int |
SHAPE
File type: Shape (.svg)
|
static int |
TEXT
File type: Text (.txt)
|
protected int |
type
The type of this object, e.g.
|
static int |
XML
File type: XML (.xml, .htm, .html)
|
| Modifier | Constructor and Description |
|---|---|
protected |
DataLoader(processing.core.PApplet parent,
java.lang.String folderPath,
java.lang.String folderName)
Builds the DataLoader and registers the KeyEvent to the parent (PApplet).
|
| Modifier and Type | Method and Description |
|---|---|
DataLoader |
disableKeys()
Disable the automatic key events of this object.
|
DataLoader |
enableKeys()
Enables the automatic key events of this object.
|
abstract java.lang.Object |
first()
Loads (if necessary) and returns the first file of the given folder.
|
abstract java.lang.Object |
get(int index)
Loads (if necessary) and returns the file with the given index.
|
abstract java.lang.Object |
getCurrent()
Loads (if necessary) and returns the current file.
|
java.lang.String |
getFileName()
Gets the file name of the current file.
|
java.lang.String |
getFileName(boolean removeFileType)
Gets the file name of the current file.
|
java.lang.String |
getFileName(int index)
Gets the file name of the file with the given index.
|
java.lang.String |
getFileName(int index,
boolean removeFileType)
Gets the file name of the file with the given index.
|
java.lang.String |
getFolder()
Returns the name of the folder of whom the files will be loaded.
|
java.lang.String |
getLoadingDirectory()
Returns the path of the directory where all files of the given type will
be loaded.
|
java.lang.String |
getPath()
Returns the path to the loading folder.
|
void |
keyEvent(processing.event.KeyEvent evt)
A function for handling the KeyEvent.
|
abstract java.lang.Object |
last()
Loads (if necessary) and returns the last file of the given folder.
|
abstract java.lang.Object[] |
loadAllFiles()
Loads all files (if not loaded yet) and returns them all.
|
abstract java.lang.Object |
loadFile(int index)
Loads a file with the given index and returns it.
|
protected java.lang.String[] |
loadPaths(int type)
Loads all the absolute paths for all valid files defined by the given
type in the set folder.
|
protected java.lang.String[] |
loadPaths(java.lang.String[] dataTypes)
Loads all the absolute paths for all valid files defined by the given
dataTypes array in the set folder.
|
abstract java.lang.Object |
next()
Loads (if necessary) and returns the next file of the given folder.
|
abstract java.lang.Object |
nextRandom()
Loads (if necessary) and returns the next random file of the given
folder.
|
abstract java.lang.Object |
previous()
Loads (if necessary) and returns the previous file of the given folder.
|
DataLoader |
resetKeySettings()
Resets the key settings for the KeyEvents to its default.
|
DataLoader |
setIndex(int index)
Sets the current element.
|
DataLoader |
setIndex(java.lang.String filename)
Sets the current element.
|
DataLoader |
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.
|
int |
size()
Returns the number of files within the given folder.
|
DataLoader |
update()
Re-Loads all the absolute paths for all valid files defined by the given
type in the set folder.
|
protected processing.core.PApplet parent
protected java.lang.String[] filePaths
protected int type
protected int fileIndex
public static final int IMAGE
public static final int TEXT
public static final int CSV
public static final int JSON
public static final int SHAPE
public static final int XML
public static final int COLOR_PALETTE
protected DataLoader(processing.core.PApplet parent,
java.lang.String folderPath,
java.lang.String folderName)
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 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.public java.lang.String getFolder()
public java.lang.String getPath()
public java.lang.String getLoadingDirectory()
public abstract java.lang.Object loadFile(int index)
index - The index of the file which should be loaded.public abstract java.lang.Object[] loadAllFiles()
public abstract java.lang.Object nextRandom()
public abstract java.lang.Object previous()
public abstract java.lang.Object next()
public abstract java.lang.Object first()
public abstract java.lang.Object last()
public abstract java.lang.Object getCurrent()
public abstract java.lang.Object get(int index)
public DataLoader setIndex(int index)
index - The index of the element which should be the current element.
Index is in range of [0, size()).public DataLoader setIndex(java.lang.String filename)
filename - The name of the file which should be the current element.public DataLoader resetKeySettings()
public int size()
public void keyEvent(processing.event.KeyEvent evt)
evt - The object containing the information about the KeyEvent.public DataLoader disableKeys()
public DataLoader enableKeys()
public DataLoader setKey(java.lang.String which, int keyCode)
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.public DataLoader setKey(java.lang.String which, char key)
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.public java.lang.String getFileName(int index,
boolean removeFileType)
index - The index of the file of which the name should be returned.removeFileType - True if the file extension should be removed.public java.lang.String getFileName(int index)
index - The index of the file of which the name should be returned.public java.lang.String getFileName()
public java.lang.String getFileName(boolean removeFileType)
removeFileType - True if the file extension should be removed.public DataLoader update()
protected java.lang.String[] loadPaths(int type)
type - A file type (DataLoader.IMAGE, DataLoader.Text, ...)protected java.lang.String[] loadPaths(java.lang.String[] dataTypes)
dataTypes - An array containing the valid extension types in form of e.g.
\".jpg\"