Difference between revisions of "Writing plugins for Micro-Manager"
Line 3: | Line 3: | ||
Micro-Manager's classpath is set up so that Micro-Manager plugins can import classes from: | Micro-Manager's classpath is set up so that Micro-Manager plugins can import classes from: | ||
# the [http://java.sun.com/j2se/1.6.0/docs/api/ Java 2 SE 6.0 Libraries] | # the [http://java.sun.com/j2se/1.6.0/docs/api/ Java 2 SE 6.0 Libraries] | ||
− | # [https://valelab.ucsf.edu/~ | + | # [https://valelab.ucsf.edu/~MM/doc/mmcorej/index.html Micro-Manager Core] |
+ | # [https://valelab.ucsf.edu/~MM/doc/mmstudio/index.html Micro-Manager GUI] | ||
# [http://rsbweb.nih.gov/ij/developer/api/ ImageJ] | # [http://rsbweb.nih.gov/ij/developer/api/ ImageJ] | ||
# [http://commons.apache.org/math/userguide/overview.html Apache Commons Math] | # [http://commons.apache.org/math/userguide/overview.html Apache Commons Math] |
Revision as of 09:47, 5 October 2013
Micro-Manager has a Java-based plugin system similar to ImageJ's. To write a Micro-Manager plugin, simply implement theMMPlugin
interface. menuName
lets you control the name of the plugin that appears in the Micro-Manager Plugins menu.Micro-Manager's classpath is set up so that Micro-Manager plugins can import classes from:
The MMPlugins API provides you access to the GUI and core instances (objects) already created by Micro-Manager startup. Micro-Manager will call
public void setApp(ScriptInterface app);
you can get the GUI object, core and acquisition engine objects thus:
MMStudioMainFrame gui_ = (MMStudioMainFrame) app; CMMCore core_ = gui_.getMMCore(); AcquisitionEngine acq_ = gui_.getAcquisitionEngine();
Once you have compiled your code into a .class
file or a .jar
file, drop that file into Micro-Manager's mmplugins
directory, and it will be loaded at startup.
The source code for a number of Micro-Manager plugins is publicly available here. Seamus Holden has also contributed a Hello World Example plugin.
Using Netbeans
The dynamic loading feature (described above) is useful if you are developing your plugin using an IDE such as Eclipse or Netbeans. (The Micro-Manager distribution includes swing-layout-*.*.jar
so that you can use the free Netbeans GUI Builder for your plugin.) Here are the steps for Netbeans:
- Install Netbeans. Note, Netbeans currently comes with the Java 1.7.0 run time environment. After install, you will need to manually install and add the JRE that Micro-Manager uses: 1.6.0, 64-bit if you need it.
- Select New > New Project... > Java > Java Class Library.
- Name your plugin project and press Finish.
- Under the Projects tab, right-click your plugin project and choose Properties.
- Then choose Libraries > Compile > Add JAR/Folder.
- Browse to
C:\Program Files\Micro-Manager-1.4\plugins\Micro-Manager
and choose all jars in that directory. - Click Add JAR/Folder again and add
C:\Program Files\Micro-Manager-1.4\ij.jar
- Click Categories > Run and set Main Class to
ij.ImageJ
, working directory toC:\Program Files\Micro-Manager-1.4\
. Click OK.
- Browse to
- Now choose Debug > Debug Project from the Menu and ImageJ/Micro-Manager should launch. Close it for now.
- Right-click your Source Packages in your project, under the Projects tab. Select New > Java Class... and give your plugin a class name and package name.
- Edit the class declaration so that it contains the phrase
implements org.micromanager.api.MMPlugin
. Left-click on the light-bulb with a red pimple to the left of this line, and select "Implement all abstract methods." - Compile your project, and manually copy the project jar file to Micro-Manager's
mmplugins
directory. Alternatively, you can add the following to your projectbuild.xml
file (look in the Project "Files" tab in Netbeans):
<property name="pluginsDir" location="C:\Program Files\Micro-Manager-1.4\mmplugins" /> <target name="-post-jar"> System.out.println(info); <echo message="--Copied MM plugin JAR to basedir: ${basedir}" /> <copy file="${basedir}/${dist.jar}" toDir="${pluginsDir}" /> </target>
- When "Clean and Build" is run, this will automatically copy the current version of your plugin to the
mmplugins
folder.
- Now choose Debug > Debug Project and your nascent plugin should appear in the Plugins menu.
- You can also dynamically load your plugin by including a line in the
MMStartup.bsh
file. (This file should reside in the root directory of your Micro-Manager installation; if there isn't one yet, you can create it with any text editor program.) For example:
gui.installPlugin("org.micromanager.surveyor.SurveyorPlugin");
- Make sure you change the "Layout Generation Style" property from "Automatic" to "Swing Layout Extensions Library" as explained on the Netbeans website.