ImageJ的相关信息可以直接从其官网了解,从这个网站上可以下载到其运行程序,并可以得到相关的源码,在源码的基本上我们可以进行插件开发。
1)了解插件的类型及其接口:
a) PlugIn:启动该插件时不需要打开一幅图象
b) PlugInFilter:启动该插件时,需要传递给该插件一幅打开图象的指针。该插件的操作将施加在该图象上。
c) PlugInFrame:该插件可以扩展一个独立的操作交互界面。
2)相关程序的运行方式,只要将相关的插件的.java和.class放在源码目录source/plugins下就可以了,可以使用再往下一级的目录进行存放,然后重新编译运行整个ImageJ源码就可以了,它会自己识别source/plugins下的插件,并将插件显示在运行后的程序的Plugins栏目下;
3)为了便于在同一个目录下进行编译和运行,使用了如下的build.xml(引用了整体程序的build.xml),plugins下使用一级目录
source/build.xml
<!-- Ant makefile for ImageJ --> <project name="ImageJ" default="run"> <target name="compile" description="Compile everything."> <!-- First, ensure the build directory exists. --> <mkdir dir="build" /> <!-- Build everything; add debug="on" to debug --> <javac srcdir="." destdir="build" optimize="on" source="1.5" target="1.5" debug="on" includeantruntime="false"> <!-- The plugins directory only needs to be present at runtime, not at build time. --> <exclude name="plugins/**"/> </javac> </target> <target name="build" depends="compile" description="Build ij.jar."> <!-- Copy needed files into the build directory. --> <copy file="IJ_Props.txt" todir="build" /> <copy file="images/microscope.gif" tofile="build/microscope.gif" /> <copy file="images/about.jpg" tofile="build/about.jpg" /> <copy file="plugins/MacAdapter.class" tofile="build/MacAdapter.class" /> <copy file="plugins/MacClipboard.class" tofile="build/MacClipboard.class" /> <copy todir="build/macros"><fileset dir="macros"/></copy> <!-- Build ij.jar. --> <jar jarfile="ij.jar" basedir="build" manifest="MANIFEST.MF" /> </target> <target name="clean" description="Delete the build files."> <delete dir="build" /> <delete file="ij.jar" /> <delete file="./../ij.jar" /> <delete dir="./../api" /> </target> <target name="run" depends="build" description="Build and run ImageJ."> <copy file="ij.jar" toDir=".." /> <java maxmemory="640m" jar="ij.jar" fork="yes" /> </target> <target name="run2" depends="build" description="Build and run ImageJ."> <!-- Run in ImageJ directory --> <copy file="ij.jar" toDir=".." /> <java maxmemory="640m" dir=".." jar="ij.jar" fork="yes" /> </target> <target name="zip" depends="clean" description="Build zrc.zip."> <zip zipfile="../src.zip" basedir=".." includes="source/**" /> </target> <target name="javadocs" description="Build the JavaDocs."> <delete dir="../api" /> <mkdir dir="../api" /> <javadoc sourcepath="." packagenames="ij.*" destdir="../api" author="true" version="true" use="true" windowtitle="ImageJ API"> </javadoc> </target> </project>
source/plugins/Plugin/build.xml
<?xml version="1.0"?> <project default="compile" name="Plugin Project" basedir="."> <description>My plugin</description> <property name="srcDir" location="."/> <property name="runDir" location="./../.." /> <path id="ij"> <pathelement path=".:./../../ij.jar"/> </path> <target name="init"> </target> <target name="compile" depends="init"> <javac srcdir="${srcDir}" destdir="${srcDir}"> <classpath> <path refid="ij" /> </classpath> </javac> </target> <target name="run" description="run the ImageJ with the external build.xml"> <antcall target="compile"/> <ant antfile="build.xml" dir="${runDir}" inheritall="true" target="run"> </ant> </target> <target name="clean"> <delete> <fileset dir="." includes="*.class"/> </delete> </target> <target name="cleanAll"> <antcall target="clean" /> <ant antfile="build.xml" dir="${runDir}" inheritall="true" target="clean"> </ant> </target> </project>