top bar

Difference between revisions of "Writing plugins for Micro-Manager"

(add note template)
Line 18: Line 18:
 
</pre>
 
</pre>
  
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. 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:
+
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.
 
+
<pre>
+
gui.installPlugin("org.micromanager.surveyor.SurveyorPlugin");
+
</pre>
+
  
 
The source code for a number of Micro-Manager plugins is publicly available [https://valelab.ucsf.edu/svn/micromanager2/branches/micromanager1.3/plugins/ here].
 
The source code for a number of Micro-Manager plugins is publicly available [https://valelab.ucsf.edu/svn/micromanager2/branches/micromanager1.3/plugins/ here].
Line 35: Line 31:
 
<li>Name your plugin project and press Finish.</li>
 
<li>Name your plugin project and press Finish.</li>
 
<li>Under the Projects tab, right-click your plugin project and choose Properties. Then choose Compile > Libraries > Add JAR/Folder.
 
<li>Under the Projects tab, right-click your plugin project and choose Properties. Then choose Compile > Libraries > Add JAR/Folder.
<li>Browse to C:\Program Files\Micro-Manager-1.3\plugins\Micro-Manager and choose bsh-2.0b4.jar, commons-math-2.0.jar, MMCoreJ.jar, MMJ_.jar, swing-layout-1.0.4.jar, and swingx-0.9.5.jar.</li>
+
<li>Browse to C:\Program Files\Micro-Manager-1.4\plugins\Micro-Manager and choose all jars in that directory.</li>
<li>Click Add JAR/Folder again and add C:\Program Files\Micro-Manager-1.3\ij.jar</li>
+
<li>Click Add JAR/Folder again and add C:\Program Files\Micro-Manager-1.4\ij.jar</li>
<li>Click Categories > Run and set Main Class to ij.ImageJ, working directory to C:\Program Files\Micro-Manager-1.3\ . Click OK.</li>
+
<li>Click Categories > Run and set Main Class to ij.ImageJ, working directory to C:\Program Files\Micro-Manager-1.4\ . Click OK.</li>
 
<li>Now choose Debug > Debug Project from the Menu and ImageJ/Micro-Manager should launch. Close it for now.</li>
 
<li>Now choose Debug > Debug Project from the Menu and ImageJ/Micro-Manager should launch. Close it for now.</li>
 
<li>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.</li>
 
<li>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.</li>

Revision as of 21:27, 27 September 2012

Micro-Manager has a Java-based plugin system similar to ImageJ's. To write a Micro-Manager plugin, simply implement the MMPlugin interface.
Note
The static String 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:

  1. the Java 2 SE 5.0 Libraries
  2. Micro-Manager
  3. ImageJ
  4. Apache Commons Math

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.


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:

  1. Install Netbeans.
  2. Select New > New Project... > Java > Java Class Library.
  3. Name your plugin project and press Finish.
  4. Under the Projects tab, right-click your plugin project and choose Properties. Then choose Compile > Libraries > Add JAR/Folder.
  5. Browse to C:\Program Files\Micro-Manager-1.4\plugins\Micro-Manager and choose all jars in that directory.
  6. Click Add JAR/Folder again and add C:\Program Files\Micro-Manager-1.4\ij.jar
  7. Click Categories > Run and set Main Class to ij.ImageJ, working directory to C:\Program Files\Micro-Manager-1.4\ . Click OK.
  8. Now choose Debug > Debug Project from the Menu and ImageJ/Micro-Manager should launch. Close it for now.
  9. 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.
  10. 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."
  11. Create or edit the MMStartup.bsh file as described above.
  12. Now choose Debug > Debug Project and after Micro-Manager launches, MMStartup.bsh script will load your nascent plugin in the Plugins menu.


For distribution: in the dist folder of your Netbeans project folder, Netbeans will automatically produce a jar every time you build the project. You can copy this jar to the Micro-Manager plugins folder and it will be loaded in the Plugins menu, even in the absence of the MMStartup.bsh script.

Make sure you set the "Layout Generation Style" property as explained on the Netbeans website.

© Micro-Manager : Vale Lab, UCSF 2006-2011 | All Rights Reserved | Contact