Codota Logo
Jiffle
Code IndexAdd Codota to your IDE (free)

How to use
Jiffle
in
it.geosolutions.jaiext.jiffle

Best Java code snippets using it.geosolutions.jaiext.jiffle.Jiffle (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
FileOutputStream f =
  • Codota IconFile file;new FileOutputStream(file)
  • Codota IconString name;new FileOutputStream(name)
  • Codota IconFile file;new FileOutputStream(file, true)
  • Smart code suggestions by Codota
}
origin: geosolutions-it/jai-ext

private void createRuntimeInstances() {
  try {
    Jiffle jiffle = new Jiffle();
    Map<String, Jiffle.ImageRole> imageParams = new HashMap<>();
    imageParams.put(WORLD_NAME, Jiffle.ImageRole.SOURCE);
    imageParams.put(NEXT_WORLD_NAME, Jiffle.ImageRole.DEST);
    
    // First create a runtime for the toroidal world
    URL url = getClass().getResource("life-toroid.jfl");
    File file = new File(url.toURI());
    jiffle.setScript(file);
    jiffle.setImageParams(imageParams);
    jiffle.compile();
    toroidRuntime = jiffle.getRuntimeInstance();
    // Now create a second runtime for the hard-edged world
    url = getClass().getResource("life-edges.jfl");
    file = new File(url.toURI());
    jiffle.setScript(file);
    jiffle.setImageParams(imageParams);
    jiffle.compile();
    edgeRuntime = jiffle.getRuntimeInstance();
    // Set the active runtime
    activeRuntime = worldType == WorldType.EDGES ? edgeRuntime : toroidRuntime;
    
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}

origin: geotools/geotools

Set<GetSourceValue> positions = Jiffle.getReadPositions(script, Arrays.asList(sourceName));
if (positions.isEmpty()) {
  return null;
origin: geosolutions-it/jai-ext

public void getSourceFromJiffleObject(String script) throws JiffleException {
  Jiffle jiffle = new Jiffle();
  jiffle.setScript(script);
  
  // You have to compile the script before getting the runtime
  // source otherwise an Exception will be thrown
  jiffle.compile();
  
  // Get the Java source. The boolean argument specifies that we
  // want the input script copied into the class javadocs
  String runtimeSource = jiffle.getRuntimeSource(true);
}
// docs end getSourceFromJiffleObject
origin: it.geosolutions.jaiext.jiffle/jt-jiffle-language

/**
 * Creates a new instance by compiling the script read from {@code scriptFile}. 
 * Using this constructor is equivalent to:
 * <pre><code>
 * Jiffle jiffle = new Jiffle();
 * jiffle.setScript(scriptFile);
 * jiffle.setImageParams(params);
 * jiffle.compile();
 * </code></pre>
 * 
 * @param scriptFile file containing the Jiffle script
 * 
 * @param params defines the names and roles of image variables
 *        referred to in the script.
 * 
 * @throws JiffleException on compilation errors
 */
public Jiffle(File scriptFile, Map<String, Jiffle.ImageRole> params)
    throws it.geosolutions.jaiext.jiffle.JiffleException {
  init();
  setScript(scriptFile);
  setImageParams(params);
  compile();
}

origin: it.geosolutions.jaiext.jiffle/jt-jiffle-language

/**
 * Gets the Java run-time class code generated from the compiled script.
 *
 * @return the run-time source code
 *
 * @throws JiffleException if the script has not been set yet or if
 *         compilation errors occur
 */
public String getRuntimeSource() throws JiffleException {
  if (script == null) {
    throw new IllegalStateException("Jiffle script has not been set yet");
  }
  
  Jiffle jiffle = new Jiffle(script, imageParams);
  return jiffle.getRuntimeSource(Jiffle.RuntimeModel.DIRECT, true);
}
origin: geosolutions-it/jai-ext

/**
 * Compiles a script read from a file and submits it for execution.
 * 
 * @param scriptFile file containing the Jiffle script
 * @throws Exception on problems compiling the script
 */
public void compileAndRun(File scriptFile) throws Exception {
  Map<String, Jiffle.ImageRole> imageParams = new HashMap<>();
  imageParams.put("result", Jiffle.ImageRole.DEST);
  Jiffle jiffle = new Jiffle(scriptFile, imageParams);
  JiffleDirectRuntime runtime = jiffle.getRuntimeInstance();
  
  WritableRenderedImage destImage = ImageUtilities.createConstantImage(WIDTH, HEIGHT, 0d);
  runtime.setDestinationImage("result", destImage);
  executor.submit(runtime, new NullProgressListener());
}
origin: geosolutions-it/jai-ext

  protected void compileScript(String script) throws JiffleException {
    Jiffle jiffle = new Jiffle();
    jiffle.setScript(script);
    jiffle.compile();
  }
}
origin: geosolutions-it/jai-ext

@Test
public void compileValidScript() throws Exception {
  System.out.println("   compile valid script");
  
  String script = "dest = 42;";
  imageParams.put("dest", Jiffle.ImageRole.DEST);
  
  jiffle.setScript(script);
  jiffle.setImageParams(imageParams);
  jiffle.compile();
  
  assertTrue(jiffle.isCompiled());
}
origin: geosolutions-it/jai-ext

private void setupSingleDestScript() throws JiffleException {
  String script = "dest = 42;";
  jiffle.setScript(script);
  
  imageParams.put("dest", Jiffle.ImageRole.DEST);
  jiffle.setImageParams(imageParams);
  jiffle.compile();
}

origin: geosolutions-it/jai-ext

  @Test(expected=JiffleException.class)
  public void getRuntimeBeforeCompiling() throws Exception {
    System.out.println("   getRuntimeInstance before compiling");
    
    String script = "dest = 42;";
    jiffle.setScript(script);
    
    imageParams.put("dest", Jiffle.ImageRole.DEST);
    jiffle.setImageParams(imageParams);
    
    JiffleRuntime runtime = jiffle.getRuntimeInstance();
  }    
}
origin: geosolutions-it/jai-ext

/**
 * Compiles a script read from a file and submits it for execution.
 * 
 * @param scriptFile file containing the Jiffle script
 * @throws Exception on an error in the Jiffle compiler
 */
public void compileAndRun(File scriptFile) throws Exception {
  Map<String, Jiffle.ImageRole> imageParams = new HashMap<>();
  imageParams.put("result", Jiffle.ImageRole.DEST);
  Jiffle jiffle = new Jiffle(scriptFile, imageParams);
  Map<String, RenderedImage> images = new HashMap<>();
  images.put("result",
      ImageUtilities.createConstantImage(WIDTH, HEIGHT, Double.valueOf(0d)));
  if (jiffle.isCompiled()) {
    JiffleDirectRuntime runtime = jiffle.getRuntimeInstance();
    final TiledImage destImg = ImageUtilities.createConstantImage(WIDTH, HEIGHT, 0d);
    runtime.setDestinationImage("result", destImg);
    
    runtime.evaluateAll(null);
    
    ImageFrame frame = new ImageFrame(destImg, "Jiffle image demo");
    frame.setVisible(true);
  }
}
origin: it.geosolutions.jaiext.jiffle/jt-jiffle-language

/**
 * Creates an instance of the default runtime class. 
 * <p>
 * The default runtime class implements {@link 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:
 * <ul>
 * <li>{@code evaluate(int x, int y)}
 * <li>{@code evaluateAll(JiffleProgressListener listener}
 * </ul>
 * The {@code Jiffle} object must be compiled before calling this method.
 * 
 * @return the runtime object
 * @throws JiffleException if the script has not been compiled or if errors
 *         occur in creating the runtime instance
 */
public JiffleDirectRuntime getRuntimeInstance() throws
    it.geosolutions.jaiext.jiffle.JiffleException {
  return (JiffleDirectRuntime) getRuntimeInstance(RuntimeModel.DIRECT);
}

origin: geosolutions-it/jai-ext

@Test(expected=JiffleException.class)
public void compileScriptWithoutImageParams() throws Exception {
  System.out.println("   compile script with missing image params");
  
  String script = "dest = 42;";
  
  jiffle.setScript(script);
  jiffle.compile();
}

origin: geosolutions-it/jai-ext

@Test(expected=JiffleException.class)
public void compileWithNoScript() throws Exception {
  System.out.println("   compile with no script set");
  
  imageParams.put("dest", Jiffle.ImageRole.DEST);
  jiffle.setImageParams(imageParams);
  jiffle.compile();
}
origin: geosolutions-it/jai-ext

@Test
public void scriptWithParamsConstructor() throws Exception {
  System.out.println("   Jiffle(script, imageParams)");
  
  String script = "dest = 42;";
  imageParams.put("dest", Jiffle.ImageRole.DEST);
  jiffle = new Jiffle(script, imageParams);
  
  assertTrue(jiffle.isCompiled());
}

origin: it.geosolutions.jaiext.jiffle/jt-jiffle-language

Jiffle.Result<ParseTree> parseResult = parseScript(theScript);
if (parseResult.messages.isError()) {
  reportMessages(parseResult);
  return;
  Jiffle.Result<Map<String, Jiffle.ImageRole>> r = getScriptImageParams(
      tree);
  if (r.messages.isError()) {
    reportMessages(r);
    return;
  setImageParams(r.result);
reportMessages(optionsWorker.messages);
InitBlockWorker initWorker = new InitBlockWorker(tree);
reportMessages(initWorker.messages);
VarWorker vw = new VarWorker(tree, imageParams);
ExpressionWorker expressionWorker = new ExpressionWorker(tree, vw);
reportMessages(expressionWorker.messages);
origin: geosolutions-it/jai-ext

@Test(expected=JiffleException.class)
public void passingEmptyScriptToConstructor() throws Exception {
  System.out.println("   Jiffle(script, imageParams) with empty script");
  
  String script = "";
  imageParams.put("dest", Jiffle.ImageRole.DEST);
  jiffle = new Jiffle(script, imageParams);
}

origin: geosolutions-it/jai-ext

@Test(expected=UnsupportedOperationException.class)
public void tryToModifyImageParams() {
  System.out.println("   trying to modify map returned by getImageParams");
  
  imageParams.put("dest", Jiffle.ImageRole.DEST);
  jiffle.setImageParams(imageParams);
  
  Map<String, Jiffle.ImageRole> unmodifiableMap = jiffle.getImageParams();
  
  // this should provoke an exception
  unmodifiableMap.clear();
}
origin: geosolutions-it/jai-ext

@Test
public void resetScript() throws Exception {
  System.out.println("   resetScript");
  
  String script1 = "dest = 42;";
  String script2 = "dest = foo;";
  
  jiffle.setScript(script1);
  jiffle.setScript(script2);
  
  String result = jiffle.getScript();
  assertFalse(result.contains(script1));
  assertTrue(result.contains(script2));
}

origin: it.geosolutions.jaiext.jiffle/jt-jiffle-language

setScript(sb.toString());
it.geosolutions.jaiext.jiffleJiffle

Javadoc

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 = "images { dest=write; } dest = x() + y() * width();" ; 
Jiffle jiffle = new Jiffle(); 
jiffle.setScript(script); 
jifle.compile(); 
// Now we get the runtime object from the compiled Jiffle object 
JiffleDirectRuntime runtime = jiffle.getRuntimeInstance(); 
// Create an image to hold the results of the script 
final int width = 10; 
WritableRenderedImage destImg = ImageUtils.createConstantImage(width, width, 0.0d); 
// Associate this image with the variable name used in the script 
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 it.geosolutions.jaiext.demo.jiffle package in the JAI-tools demo module.

Implementation note

The Jiffle compiler is actually a Jiffle to Java translator. When a client requests a runtime object, the script is translated into Java source for a runtime class. This source code is then passed to an embedded Janino compiler which produces the runtime object.

Most used methods

  • <init>
    Creates a new instance by compiling the provided script. Using this constructor is equivalent to: J
  • compile
    Compiles the script into Java source for the runtime class.
  • getRuntimeInstance
    Gets the runtime object for this script. The runtime object is an instance of JiffleRuntime. By defa
  • setImageParams
    Sets the image parameters. These define which variables in the script refer to images and their type
  • setScript
    Sets the script. Calling this method will clear any previous script and runtime objects.
  • isCompiled
    Tests whether the script has been compiled successfully.
  • getReadPositions
    A utility method returning the source positions used in a given script
  • getRuntimeSource
    Gets a copy of the Java source for the runtime class. The script must have been compiled before call
  • clearCompiledObjects
    Clears all compiler and runtime objects.
  • createRuntimeInstance
  • createRuntimeSource
  • getImageParams
    Gets the current image parameters. The parameters are returned as an unmodifiable map.
  • createRuntimeSource,
  • getImageParams,
  • getName,
  • getRuntimeBaseClass,
  • getScript,
  • getScriptImageParams,
  • init,
  • parseScript,
  • reportMessages,
  • setName

Popular in Java

  • Updating database using SQL prepared statement
  • getSupportFragmentManager (FragmentActivity)
  • findViewById (Activity)
  • getResourceAsStream (ClassLoader)
    Returns a stream for the resource with the specified name. See #getResource(String) for a descriptio
  • Color (java.awt)
    The Color class is used encapsulate colors in the default sRGB color space or colors in arbitrary co
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • URI (java.net)
    Represents a Uniform Resource Identifier (URI) reference. Aside from some minor deviations noted bel
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • ArrayList (java.util)
    Resizable-array implementation of the List interface. Implements all optional list operations, and p
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now