diff --git a/.gitignore b/.gitignore index d054a8f0873988d37e7828bfd603990b5d79a970..fb538c4fbbe2731cd2e50862ffe5ebc399ca2450 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ .settings/ target/ build/ +out/ *.iml .classpath .project +**/.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 3723ff80a7bce8d753eb34b72df72907260d9e7d..f8ed769c4233f7f69f4cdd3ad4e57b4e4aa38416 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Just keep it as is. By convention the Java package of Icy plugins takes the following form: ```java -package plugins.authorname.pluginname +package plugins.authorname.pluginname; ``` `authorname` should be a condensed version of your name. For instance the author Alexandre Dufour uses `adufour`. Jean-Yves Tinevez uses `tinevez` _etc_. @@ -139,7 +139,7 @@ http://icy.bioimageanalysis.org ## Author(s) -Amandine TOURNAY, Jean-Yves Tinevez, Stéphane Dallongeville +Amandine TOURNAY, Jean-Yves Tinevez, Stéphane Dallongeville, Thomas MUSSET ## Additional information diff --git a/pom.xml b/pom.xml index 0fe5388137d7c050526c103603aaeb4cb25dbaad..e4f0badb3aa87c507ca2e9b2d30231500ffb3fe3 100644 --- a/pom.xml +++ b/pom.xml @@ -8,19 +8,17 @@ <parent> <artifactId>pom-icy</artifactId> <groupId>org.bioimageanalysis.icy</groupId> - <version>2.1.0</version> + <version>2.1.5</version> </parent> <!-- Project Information --> <artifactId>plugin-template</artifactId> - <version>1.0.3-SNAPSHOT</version> - - <packaging>jar</packaging> + <version>1.0.0-SNAPSHOT</version> <name>A template for Icy plugins.</name> <description>This repo serves as a template for you to implement new Icy plugins.</description> - <url></url> - <inceptionYear>2020</inceptionYear> + <url>https://www.example.org</url> + <inceptionYear>2023</inceptionYear> <organization> <name>MyOrganizationName</name> @@ -55,21 +53,16 @@ <!-- Project properties --> <properties> - + <artifact-to-extract>JMathPlot,JMathIO,JMathArray</artifact-to-extract> </properties> - <!-- Project build configuration --> - <build> - - </build> - <!-- List of project's dependencies --> <dependencies> <!-- The core of Icy --> <dependency> <groupId>org.bioimageanalysis.icy</groupId> <artifactId>icy-kernel</artifactId> - <version>2.1.4</version> + <version>2.4.3</version> </dependency> <!-- The EzPlug library, simplifies writing UI for Icy plugins. --> @@ -78,6 +71,22 @@ <artifactId>ezplug</artifactId> </dependency> + <!-- External libraries example --> + <dependency> + <groupId>com.github.yannrichet</groupId> + <artifactId>JMathPlot</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>com.github.yannrichet</groupId> + <artifactId>JMathIO</artifactId> + <version>1.0</version> + </dependency> + <dependency> + <groupId>com.github.yannrichet</groupId> + <artifactId>JMathArray</artifactId> + <version>1.0</version> + </dependency> </dependencies> <!-- Icy Maven repository (to find parent POM) --> @@ -88,15 +97,4 @@ <url>https://icy-nexus.pasteur.fr/repository/Icy/</url> </repository> </repositories> - - <distributionManagement> - <snapshotRepository> - <id>server-id</id> - <url>server's url</url> - </snapshotRepository> - <repository> - <id>server-id</id> - <url>server's url</url> - </repository> - </distributionManagement> </project> diff --git a/src/main/java/plugins/authorname/templateplugin/MyEzPlugIcyPlugin.java b/src/main/java/plugins/authorname/templateplugin/MyEzPlugIcyPlugin.java index 8b91ed889767a3d9b6269f4b699ea58465f2733c..2931121e54e0a536d7bde5d1fc084d01f720ab09 100644 --- a/src/main/java/plugins/authorname/templateplugin/MyEzPlugIcyPlugin.java +++ b/src/main/java/plugins/authorname/templateplugin/MyEzPlugIcyPlugin.java @@ -1,8 +1,22 @@ -package plugins.authorname.templateplugin; - -import java.lang.reflect.InvocationTargetException; +/* + * Copyright (c) 2010-2023. Institut Pasteur. + * + * This file is part of Icy. + * Icy is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Icy 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Icy. If not, see <https://www.gnu.org/licenses/>. + */ -import javax.swing.SwingUtilities; +package plugins.authorname.templateplugin; import icy.file.Loader; import icy.gui.dialog.MessageDialog; @@ -11,76 +25,75 @@ import icy.main.Icy; import icy.plugin.PluginLauncher; import icy.plugin.PluginLoader; import icy.sequence.Sequence; +import icy.system.IcyExceptionHandler; import icy.system.thread.ThreadUtil; import plugins.adufour.ezplug.EzButton; import plugins.adufour.ezplug.EzPlug; import plugins.adufour.ezplug.EzVarBoolean; import plugins.adufour.ezplug.EzVarInteger; -public class MyEzPlugIcyPlugin extends EzPlug -{ - - private final EzVarInteger age = new EzVarInteger( "Your age", 30, 10, 100, 1 ); - - private final EzVarBoolean yummy = new EzVarBoolean( "Like chocolate?", true ); - - private final EzButton button = new EzButton( "Load an show an image now", l -> loadAndShow() ); - - @Override - protected void initialize() - { - // Add elements in order of appearance. - addEzComponent( age ); - addEzComponent( yummy ); - addEzComponent( button ); - } - - @Override - public void clean() - { - // Nothing to do - } - - @Override - protected void execute() - { - final String str = "This plugin start button does not do anything useful.\n " - + "You say you are " + age.getValue() + " years old and you " - + (yummy.getValue() ? "like" : "don't like" ) - + " chocolate."; - MessageDialog.showDialog( str ); - } - - private void loadAndShow() - { - final String imagePath = "samples/Cont1.lsm"; - - // Load in a separate thread. - ThreadUtil.bgRun(() -> { - - final Sequence sequence = Loader.loadSequence( imagePath, 0, true ); - - // Display the images. - try - { - SwingUtilities.invokeAndWait( () -> new Viewer( sequence )); - } - catch ( InvocationTargetException | InterruptedException e ) - { - e.printStackTrace(); - } - }); - } - - public static void main( final String[] args ) - { - // Launch the application. - Icy.main( args ); - - /* - * Programmatically launch a plugin, as if the user had clicked its - * button. - */ - PluginLauncher.start( PluginLoader.getPlugin( MyEzPlugIcyPlugin.class.getName() ) ); - } +import javax.swing.*; +import java.lang.reflect.InvocationTargetException; + +public class MyEzPlugIcyPlugin extends EzPlug { + + private final EzVarInteger age = new EzVarInteger("Your age", 30, 10, 100, 1); + + private final EzVarBoolean yummy = new EzVarBoolean("Like chocolate?", true); + + private final EzButton button = new EzButton("Load an show an image now", l -> loadAndShow()); + + @Override + protected void initialize() { + // Add elements in order of appearance. + addEzComponent(age); + addEzComponent(yummy); + addEzComponent(button); + } + + @Override + public void clean() { + // Nothing to do + } + + @Override + protected void execute() { + final String str = "This plugin start button does not do anything useful.\n " + + "You say you are " + age.getValue() + " years old and you " + + (yummy.getValue() ? "like" : "don't like") + + " chocolate."; + MessageDialog.showDialog(str); + } + + private void loadAndShow() { + final String imagePath = "samples/Cont1.lsm"; + + // Load in a separate thread. + ThreadUtil.bgRun(() -> { + + final Sequence sequence = Loader.loadSequence(imagePath, 0, true); + + // Display the images. + try { + SwingUtilities.invokeAndWait(() -> new Viewer(sequence)); + } + catch (final InvocationTargetException | InterruptedException e) { + IcyExceptionHandler.showErrorMessage(e, true); + } + }); + } + + /** + * Only for test purpose. + */ + public static void main(final String[] args) { + // Launch the application. + Icy.main(args); + + /* + * Programmatically launch a plugin, as if the user had clicked its + * button. + */ + PluginLauncher.start(PluginLoader.getPlugin(MyEzPlugIcyPlugin.class.getName())); + } } diff --git a/src/main/java/plugins/authorname/templateplugin/MyIcyPlugin.java b/src/main/java/plugins/authorname/templateplugin/MyIcyPlugin.java index 58c05df0eb1905d6d3463a110481b0c0b47eb0b8..393657a84e216999ca9e8b1cf41558104f60516e 100644 --- a/src/main/java/plugins/authorname/templateplugin/MyIcyPlugin.java +++ b/src/main/java/plugins/authorname/templateplugin/MyIcyPlugin.java @@ -1,8 +1,22 @@ -package plugins.authorname.templateplugin; - -import java.lang.reflect.InvocationTargetException; +/* + * Copyright (c) 2010-2023. Institut Pasteur. + * + * This file is part of Icy. + * Icy is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Icy 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Icy. If not, see <https://www.gnu.org/licenses/>. + */ -import javax.swing.SwingUtilities; +package plugins.authorname.templateplugin; import icy.file.Loader; import icy.gui.dialog.MessageDialog; @@ -14,6 +28,9 @@ import icy.sequence.Sequence; import icy.sequence.SequenceUtil; import icy.system.thread.ThreadUtil; +import javax.swing.*; +import java.lang.reflect.InvocationTargetException; + /** * A simple plugin demonstration. * <p> @@ -22,123 +39,112 @@ import icy.system.thread.ThreadUtil; * <p> * This is toy that shows how to make a plugin that can be launched from Icy and * that will MODIFY an image. - * - * @author Jean-Yves Tinevez * + * @author Jean-Yves Tinevez */ -public class MyIcyPlugin extends PluginActionable -{ - - /* - * The run() method is called when the user presses the plugin button. - */ - - @Override - public void run() - { - /* - * We are in the Event Dispatch Thread (EDT) right now. It is a good - * idea to jump into another thread so that the processing of our plugin - * does not prevent the EDT to deal with the user-interface. - */ - - ThreadUtil.bgRun(() -> { - - /* - * We are are not the EDT anymore. Now we can do heavy-lifting - * operations and the Icy UI won't be blocked. - */ - - final Sequence sequence = getActiveSequence(); - - // Check if a sequence is opened. - if ( sequence == null ) - { - MessageDialog.showDialog( "This plugin needs an opened sequence." ); - return; - } - - final int width = sequence.getSizeX(); - final int height = sequence.getSizeY(); - final int nChannel = sequence.getSizeC(); - - // Iterate over all the planes of the image, through C and Z. - for ( final IcyBufferedImage plane : sequence.getAllImage() ) - { - try - { - /* - * We put the pixel edit between a beginUpdate() and an - * endUpdate (all in a try/finally block), so that we - * only display the display (which takes time) once the - * edits of a plane are over. - * - * We could also have chosen to put the beginUpdate() - * before editing the sequence to have only one display - * update. - */ - - plane.beginUpdate(); - - /* - * We pedestriantly iterate pixel by pixel and recopy - * the value of the every 7th pixel on the 2 that - * follows. - */ - - for ( int c = 0; c < nChannel; c++ ) - { - for ( int y = 0; y < height; y++ ) - { - double val = 0; - for ( int x = 0; x < width; x++ ) - { - if ( x % 7 == 0 ) - val = plane.getData( x, y, c ); - - plane.setData( x, y, c, val ); - } - } - } - } - finally - { - plane.endUpdate(); - } - } - }); - } - - /* - * We use a main method to make this class runnable from your favorite IDE. - * If you run this class, it will simply starts Icy. Your preferences won't - * be there however, and it will be a naked" icy. - * - * Custom plugins with no extra configuration will show up in the "Plugins" - * ribbons, under the "Other Plugins" button. This plugin button gets - * automatically placed in the "authorname" menu. This is why by convention - * Icy plugins have a package that always starts with "plugins.authorname". - */ - - public static void main( final String[] args ) throws InvocationTargetException, InterruptedException - { - // Launch the application. - Icy.main( args ); - - // Load an image. - final String imagePath = "samples/Cont1.lsm"; - final Sequence sequence = Loader.loadSequence( imagePath, 0, true ); - - // Copy it so that we work on a copy. - final Sequence copy = SequenceUtil.getCopy( sequence ); - - // Display the images. - SwingUtilities.invokeAndWait( () -> { - new Viewer( sequence ); - new Viewer( copy ); - } ); - - // Run the plugin on the last active image (the copy). - new MyIcyPlugin().run(); - } +public class MyIcyPlugin extends PluginActionable { + + /* + * The run() method is called when the user presses the plugin button. + */ + @Override + public void run() { + /* + * We are in the Event Dispatch Thread (EDT) right now. It is a good + * idea to jump into another thread so that the processing of our plugin + * does not prevent the EDT to deal with the user-interface. + */ + + ThreadUtil.bgRun(() -> { + + /* + * We are not the EDT anymore. Now we can do heavy-lifting + * operations and the Icy UI won't be blocked. + */ + + final Sequence sequence = getActiveSequence(); + + // Check if a sequence is opened. + if (sequence == null) { + MessageDialog.showDialog("This plugin needs an opened sequence."); + return; + } + + final int width = sequence.getSizeX(); + final int height = sequence.getSizeY(); + final int nChannel = sequence.getSizeC(); + + // Iterate over all the planes of the image, through C and Z. + for (final IcyBufferedImage plane : sequence.getAllImage()) { + try { + /* + * We put the pixel edit between a beginUpdate() and an + * endUpdate (all in a try/finally block), so that we + * only display the display (which takes time) once the + * edits of a plane are over. + * + * We could also have chosen to put the beginUpdate() + * before editing the sequence to have only one display + * update. + */ + + plane.beginUpdate(); + + /* + * We pedestriantly iterate pixel by pixel and recopy + * the value of the every 7th pixel on the 2 that + * follows. + */ + + for (int c = 0; c < nChannel; c++) { + for (int y = 0; y < height; y++) { + double val = 0; + for (int x = 0; x < width; x++) { + if (x % 7 == 0) + val = plane.getData(x, y, c); + + plane.setData(x, y, c, val); + } + } + } + } + finally { + plane.endUpdate(); + } + } + }); + } + + /** + * We use a main method to make this class runnable from your favorite IDE. + * If you run this class, it will simply starts Icy. Your preferences won't + * be there however, and it will be a naked" icy. + * <p> + * Custom plugins with no extra configuration will show up in the "Plugins" + * ribbons, under the "Other Plugins" button. This plugin button gets + * automatically placed in the "authorname" menu. This is why by convention + * Icy plugins have a package that always starts with "plugins.authorname". + * <p> + * Only for test purpose. + */ + public static void main(final String[] args) throws InvocationTargetException, InterruptedException { + // Launch the application. + Icy.main(args); + + // Load an image. + final String imagePath = "samples/Cont1.lsm"; + final Sequence sequence = Loader.loadSequence(imagePath, 0, true); + + // Copy it so that we work on a copy. + final Sequence copy = SequenceUtil.getCopy(sequence); + + // Display the images. + SwingUtilities.invokeAndWait(() -> { + new Viewer(sequence); + new Viewer(copy); + }); + + // Run the plugin on the last active image (the copy). + new MyIcyPlugin().run(); + } } diff --git a/src/main/resources/plugins/authorname/templateplugin/add_resources_here.txt b/src/main/resources/plugins/authorname/templateplugin/add_resources_here.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391