Skip to content

Commit

Permalink
Allow testing of scripts in the Experimental module
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsacha committed Apr 1, 2024
1 parent 8f2f7f3 commit 39158a9
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
20 changes: 20 additions & 0 deletions experimental/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resolvers += "SCI Java Releases" at "https://maven.scijava.org/content/repositories/thirdparty/"

libraryDependencies ++= Seq(
"org.scijava" % "script-editor" % "1.1.0",
"org.scijava" % "scripting-groovy" % "1.0.0",
"org.scijava" % "scripting-java" % "0.4.1",
"org.scijava" % "scripting-scala" % "0.3.2",
"org.scijava" % "script-editor-scala" % "0.2.1",
"org.scijava" % "script-editor-jython" % "1.1.0",
// "org.scijava" % "scripting-javascript" % "1.0.0",

// not needed for script editor
"org.python" % "jython-slim" % "2.7.3",

// dependency overrides to pull bug fixes in transitive dependencies
"org.scijava" % "scijava-optional" % "1.0.1",
"org.scijava" % "scijava-table" % "1.0.2",
"org.scijava" % "scijava-ui-swing" % "1.0.1"
// "org.codehaus.groovy" % "groovy" % "3.0.17"
)
2 changes: 2 additions & 0 deletions experimental/src/main/resources/plugins.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ Plugins>JavaCV>Experimental, "IJPCV Hough Lines...", ij_plugins.javacv.imgpr
Plugins>JavaCV>Experimental, "Mat() GC Tester...", ij_plugins.javacv.imgproc.MatGCTesterPlugin
Plugins>JavaCV>Experimental, "Open with OpenCV...", ij_plugins.javacv.imgproc.OpenWithOpenCVPlugIn
Plugins>JavaCV>Experimental, "Region Selection Demo...", ij_plugins.javacv.RegionSelectionPlugin

Plugins>Scripting, "Script Editor", ij_plugins.javacv.experimental.ScriptEditorRunner
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Image/J Plugins
* Copyright (C) 2002-2023 Jarek Sacha
* Author's email: jpsacha at gmail dot com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Latest release available at http://sourceforge.net/projects/ij-plugins/
*/

package ij_plugins.javacv.experimental

import ij.plugin.PlugIn
import org.scijava.Context
import org.scijava.script.{ScriptLanguage, ScriptService}
import org.scijava.ui.DefaultUIService
import org.scijava.ui.swing.script.{Helper, Main, ScriptEditor, TextEditor}

import java.awt.event.{WindowAdapter, WindowEvent}
import javax.swing.{SwingUtilities, WindowConstants}

object ScriptEditorRunner {
// private lazy val context = new org.scijava.Context()
def main(args: Array[String]): Unit = {
Helper.launch("Groovy", true)
// Main.launch("Groovy")
}
}

class ScriptEditorRunner extends PlugIn {

import org.scijava.util.VersionUtils

VersionUtils.getVersion(classOf[VersionUtils])

// import ScriptEditorRunner.*
override def run(arg: String): Unit = {
Helper.launch("Groovy", false)
// Main.launch("Groovy")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Image/J Plugins
* Copyright (C) 2002-2023 Jarek Sacha
* Author's email: jpsacha at gmail dot com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Latest release available at http://sourceforge.net/projects/ij-plugins/
*/

package org.scijava.ui.swing.script

import org.scijava.Context
import org.scijava.script.{ScriptLanguage, ScriptService}
import org.scijava.ui.DefaultUIService
import org.scijava.ui.swing.script.TextEditor

import java.awt.event.{WindowAdapter, WindowEvent}
import javax.swing.{SwingUtilities, WindowConstants}

object Helper {
def launch(language: String, exitOnClose: Boolean): Unit = {
val context = new Context()
val defaultUIService = context.getService(classOf[DefaultUIService])
defaultUIService.showUI()
val editor = new TextEditor(context)
val scriptService = context.getService(classOf[ScriptService])
val lang = scriptService.getLanguageByName(language)
if (lang == null) throw new IllegalArgumentException("Script language '" + language + "' not found")
editor.setLanguage(lang)
editor.addWindowListener(new WindowAdapter() {
override def windowClosed(e: WindowEvent): Unit = {
defaultUIService.dispose()
SwingUtilities.invokeLater(() => { context.dispose() })
}
})
if (exitOnClose) editor.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
editor.setVisible(true)
// Main.launch(language)
}
}

0 comments on commit 39158a9

Please sign in to comment.