|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjaitools.jiffle.Jiffle
public class Jiffle
Compiles scripts and generates Java sources and executable bytecode for runtime classes.
Example of use:
// A script to write sequential values to image pixels
String script = "init { n = 0; } dest = n++ ;" ;
// We tell Jiffle about variable names that represent images
// (in this case, only "dest") via a Map of parameters
Map<String, Jiffle.ImageRole> imageParams = CollectionFactory.map();
imageParams.put("dest", Jiffle.ImageRole.DEST);
// Using this constructor results in the script being compiled
// immediately (any errors will generate JiffleExceptions)
Jiffle jiffle = new Jiffle(script, imageParams);
// Now get a runtime object
JiffleDirectRuntime runtime = jiffle.getRuntimeInstance();
// Create an image to hold the results of the script and pass it
// to the runtime object
final int width = 10;
TiledImage destImg = ImageUtils.createConstantImage(width, width, 0.0d);
runtime.setDestinationImage("dest", destImg);
// Evaluate the script for all destination image pixels
runtime.evaluateAll();
For further examples of how to create and run Jiffle scripts see the
jaitools.demo.jiffle package in the JAI-tools demo module.
JiffleBuilder,
JiffleExecutor| Nested Class Summary | |
|---|---|
static class |
Jiffle.ImageRole
Used to specify the roles of images referenced in a Jiffle script. |
static class |
Jiffle.RuntimeModel
Constants for runtime model. |
| Constructor Summary | |
|---|---|
Jiffle()
Creates a new instance. |
|
Jiffle(File scriptFile,
Map<String,Jiffle.ImageRole> params)
Creates a new instance by compiling the script read from scriptFile. |
|
Jiffle(String script,
Map<String,Jiffle.ImageRole> params)
Creates a new instance by compiling the provided script. |
|
| Method Summary | ||
|---|---|---|
void |
compile()
Compiles the script into Java source for the runtime class. |
|
Map<String,Jiffle.ImageRole> |
getImageParams()
Gets the current image parameters. |
|
String |
getName()
Gets the name assigned to this object. |
|
JiffleDirectRuntime |
getRuntimeInstance()
Creates an instance of the default runtime class. |
|
|
getRuntimeInstance(Class<T> baseClass)
Gets the runtime object for this script. |
|
JiffleRuntime |
getRuntimeInstance(Jiffle.RuntimeModel model)
Creates a runtime object based using the class specified by model. |
|
String |
getRuntimeSource(Jiffle.RuntimeModel model,
boolean scriptInDocs)
Gets a copy of the Java source for the runtime class. |
|
String |
getScript()
Gets the Jiffle script. |
|
boolean |
isCompiled()
Tests whether the script has been compiled successfully. |
|
void |
setImageParams(Map<String,Jiffle.ImageRole> params)
Sets the image parameters. |
|
void |
setName(String name)
Replaces the default name set for this object with a user-supplied name. |
|
void |
setScript(File scriptFile)
Sets the script. |
|
void |
setScript(String script)
Sets the script. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Jiffle()
public Jiffle(String script,
Map<String,Jiffle.ImageRole> params)
throws JiffleException
Jiffle jiffle = new Jiffle();
jiffle.setScript(script);
jiffle.setImageParams(params);
jiffle.compile();
script - Jiffle source code to compileparams - defines the names and roles of image variables
referred to in the script.
JiffleException - if there are any errors compiling the script
public Jiffle(File scriptFile,
Map<String,Jiffle.ImageRole> params)
throws JiffleException
scriptFile.
Using this constructor is equivalent to:
Jiffle jiffle = new Jiffle();
jiffle.setScript(scriptFile);
jiffle.setImageParams(params);
jiffle.compile();
scriptFile - file containing the Jiffle scriptparams - defines the names and roles of image variables
referred to in the script.
JiffleException - if the file cannot be read or if there are
any errors compiling the script| Method Detail |
|---|
public final void setScript(String script)
throws JiffleException
script - a Jiffle script
JiffleException - if the script is null or empty
public final void setScript(File scriptFile)
throws JiffleException
scriptFile - a file containing a Jiffle script
JiffleException - on errors reading the script filepublic String getScript()
String if none
has been setpublic final void setImageParams(Map<String,Jiffle.ImageRole> params)
This may be called before or after setting the script. No check is made between script and parameters until the script is compiled.
params - the image parameterspublic Map<String,Jiffle.ImageRole> getImageParams()
Map if none
are setpublic void setName(String name)
name - the name to assignpublic String getName()
setName(String)
public final void compile()
throws JiffleException
JiffleException - if no script has been set or if any errors
occur during compilationpublic boolean isCompiled()
true if the script has been compiled;
false otherwise
public JiffleDirectRuntime getRuntimeInstance()
throws JiffleException
The default runtime class implements JiffleDirectRuntime and
extends an abstract base class provided by the Jiffle compiler. Objects
of this class evaluate the Jiffle script and write results directly to
the destination image(s). Client code can call either of the methods:
evaluate(int x, int y)
evaluateAll(JiffleProgressListener listener
Jiffle object must be compiled before calling this method.
JiffleException - if the runtime object could not be created
public JiffleRuntime getRuntimeInstance(Jiffle.RuntimeModel model)
throws JiffleException
model.
The Jiffle object must be compiled before calling this method.
model - the Jiffle.RuntimeModel
JiffleException - if the runtime object could not be created
public <T extends JiffleRuntime> T getRuntimeInstance(Class<T> baseClass)
throws JiffleException
The runtime object is an instance of JiffleRuntime. By default
it extends an abstract base class supplied JAI-tools:
AbstractDirectRuntime
when using the direct runtiem model or
AbstractIndirectRuntime
when using the indirect model. This method allows you to
specify a custom base class. The custom class must implement either
JiffleDirectRuntime or JiffleIndirectRuntime.
T - the runtime base class typebaseClass - the runtime base class
JiffleException - if the runtime object could not be created
public String getRuntimeSource(Jiffle.RuntimeModel model,
boolean scriptInDocs)
throws JiffleException
model - the Jiffle.RuntimeModelscriptInDocs - whether to include the original Jiffle script
in the class javadocs
JiffleException - on error creating the runtime source
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||