From 39158a9156557acd78bbf959e07402663ed26721 Mon Sep 17 00:00:00 2001 From: Jarek Sacha Date: Mon, 1 Apr 2024 18:21:16 -0400 Subject: [PATCH] Allow testing of scripts in the Experimental module --- experimental/build.sbt | 20 +++++++ .../src/main/resources/plugins.config | 2 + .../experimental/ScriptEditorRunner.scala | 53 +++++++++++++++++++ .../org/scijava/ui/swing/script/Helper.scala | 53 +++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 experimental/build.sbt create mode 100644 experimental/src/main/scala/ij_plugins/javacv/experimental/ScriptEditorRunner.scala create mode 100644 experimental/src/main/scala/org/scijava/ui/swing/script/Helper.scala diff --git a/experimental/build.sbt b/experimental/build.sbt new file mode 100644 index 0000000..caa2795 --- /dev/null +++ b/experimental/build.sbt @@ -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" +) diff --git a/experimental/src/main/resources/plugins.config b/experimental/src/main/resources/plugins.config index fa30737..174d4f5 100644 --- a/experimental/src/main/resources/plugins.config +++ b/experimental/src/main/resources/plugins.config @@ -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 diff --git a/experimental/src/main/scala/ij_plugins/javacv/experimental/ScriptEditorRunner.scala b/experimental/src/main/scala/ij_plugins/javacv/experimental/ScriptEditorRunner.scala new file mode 100644 index 0000000..66bf146 --- /dev/null +++ b/experimental/src/main/scala/ij_plugins/javacv/experimental/ScriptEditorRunner.scala @@ -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") + } +} diff --git a/experimental/src/main/scala/org/scijava/ui/swing/script/Helper.scala b/experimental/src/main/scala/org/scijava/ui/swing/script/Helper.scala new file mode 100644 index 0000000..33f7173 --- /dev/null +++ b/experimental/src/main/scala/org/scijava/ui/swing/script/Helper.scala @@ -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) + } +}