Class ScriptInstaller

java.lang.Object
sc.fiji.snt.gui.ScriptInstaller

public class ScriptInstaller extends Object
Utility class for discovery of SNT scripts
Author:
Tiago Ferreira
  • Field Details

    • DEMO_SCRIPT

      public static final Pattern DEMO_SCRIPT
      Pattern to match demo scripts (case-insensitive)
    • NON_DEMO_SCRIPT

      public static final Pattern NON_DEMO_SCRIPT
      Pattern to match non-demo scripts (case-insensitive)
  • Constructor Details

    • ScriptInstaller

      public ScriptInstaller(org.scijava.Context context, Component parent)
  • Method Details

    • getScriptsDir

      public File getScriptsDir()
    • getBatchScriptsMenu

      public JMenu getBatchScriptsMenu()
      Returns a UI list of SNT's 'Batch' scripts
    • getScriptsMenu

      public JMenu getScriptsMenu()
      Returns a UI list with all the bundled non-demo SNT scripts
    • getScriptsMenu

      public JMenu getScriptsMenu(Pattern excludePattern, String... directories)
      Returns a UI list with the bundled SNT scripts (specified directories only).
      Parameters:
      excludePattern - the exclusion pattern (e.g., DEMO_SCRIPT). Null allowed.
      directories - the subset of directories (e.g., Analysis, Batch, etc.)
      Returns:
      the scripts menu
    • openScript

      public void openScript(String folder, String name) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • runScript

      public void runScript(String folder, String name) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • newScript

      public static void newScript(String contents, String scriptNameWithExtension)
    • loadRecipe

      public static String loadRecipe(String recipeName) throws IOException
      Loads a recipe from the script_templates/Neuroanatomy/Recipes/ resource directory. The template note (the block delimited by // >>> TEMPLATE-NOTE and // <<< TEMPLATE-NOTE) is removed
      Parameters:
      recipeName - the file name, e.g., "BigViewerRecording.groovy"
      Returns:
      the script contents
      Throws:
      IOException - if the recipe could not be read
    • fillRecipe

      public static String fillRecipe(String recipeName, Map<String,?> values) throws IOException
      Loads a recipe and replaces its #{KEY} placeholders. Numbers are inserted as is. Other values are inserted as text escaped for a single-quoted string (backslashes and single quotes), so the template must quote string placeholders itself
      Parameters:
      recipeName - the file name, e.g., "ChannelUnmixing.groovy"
      values - the value of each placeholder
      Returns:
      the script contents
      Throws:
      IOException - if the recipe could not be read
      IllegalStateException - if the recipe has placeholders without a value
    • newRecipe

      public static void newRecipe(String recipeName, Map<String,?> values, String scriptName) throws IOException
      Opens a recipe in the Script Editor after replacing its placeholders (see fillRecipe(java.lang.String, java.util.Map<java.lang.String, ?>))
      Parameters:
      recipeName - the file name, e.g., "ChannelUnmixing.groovy"
      values - the value of each placeholder. Null if the recipe has none
      scriptName - the name of the new script (with extension). Null to use the recipe name
      Throws:
      IOException - if the recipe could not be read
      IllegalStateException - if the recipe has placeholders without a value
    • getBoilerplateScript

      public static String getBoilerplateScript(String extension)
    • runScript

      public static boolean runScript(String dir, String file, Map<String,Object> inputMap)
    • runScript

      public static boolean runScript(String scriptPath)
      Runs the specified script known to ScriptService.
      Parameters:
      scriptPath - the script path as registered in ScriptService, (e.g., File/Open_Samples/Comparing_Lengths.ijm or File > Open Samples > Comparing Lengths)
      Returns:
      whether the script was executed