← Revision 5 as of 2009-02-12 01:03:30
Size: 1823
Comment: converted to 1.6 markup
|
← Revision 6 as of 2010-07-22 19:59:24 →
Size: 2330
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 4: | Line 4: |
package helloworld; import java.awt.event.ActionEvent; import cytoscape.Cytoscape; import cytoscape.plugin.CytoscapePlugin; import cytoscape.util.CytoscapeAction; |
|
Line 5: | Line 11: |
import cytoscape.plugin.CytoscapePlugin; import cytoscape.Cytoscape; |
|
Line 8: | Line 12: |
/** * A menu item "Hello World" will appear at Plugins menu. Click on the menu * item, a message dialog will show up. */ |
|
Line 10: | Line 18: |
public HelloWorldPlugin () { String message = "Hello World!"; System.out.println(message); // use the CytoscapeDesktop as parent for a Swing dialog JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message); } |
public HelloWorldPlugin() { MyPluginMenuAction menuAction = new MyPluginMenuAction(this); Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) menuAction); } public class MyPluginMenuAction extends CytoscapeAction { public MyPluginMenuAction(HelloWorldPlugin myPlugin) { super("Hello World"); setPreferredMenu("Plugins"); } public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(Cytoscape.getDesktop(),"MenuItem Plugins->Hello World is selected!"); } } |
Line 17: | Line 35: |
Here is a simple "Hello World" example as a Cytoscape plugin where a Java Swing utility class is used to display the message in a dialog window.
1 package helloworld;
2
3 import java.awt.event.ActionEvent;
4 import cytoscape.Cytoscape;
5 import cytoscape.plugin.CytoscapePlugin;
6 import cytoscape.util.CytoscapeAction;
7 import javax.swing.JOptionPane;
8
9 /**
10 * A menu item "Hello World" will appear at Plugins menu. Click on the menu
11 * item, a message dialog will show up.
12 */
13 public class HelloWorldPlugin extends CytoscapePlugin {
14
15 public HelloWorldPlugin() {
16 MyPluginMenuAction menuAction = new MyPluginMenuAction(this);
17 Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) menuAction);
18 }
19
20 public class MyPluginMenuAction extends CytoscapeAction {
21
22 public MyPluginMenuAction(HelloWorldPlugin myPlugin) {
23 super("Hello World");
24 setPreferredMenu("Plugins");
25 }
26
27 public void actionPerformed(ActionEvent e) {
28 JOptionPane.showMessageDialog(Cytoscape.getDesktop(),"MenuItem Plugins->Hello World is selected!");
29 }
30 }
31 }
32
Looking at the Plugin
Imports:
1 import cytoscape.plugin.CytoscapePlugin;
2 import cytoscape.Cytoscape;
3
All plugins must extend the class cytoscape.plugin.CytoscapePlugin. The specific class that extends CytoscapePlugin doesn't need to stand alone; it can reference any number of other classes and libraries. This "main" class is simply Cytoscape's entry point to your code.
The static class cytoscape.Cytoscape provides access the data objects and utilities of the Cytoscape core. Here, the plugin gets a reference to a window created by Cytoscape for a parent of a new dialog window.
Methods:
1 public HelloWorldPlugin ()
2
- All plugins must have a default constructor (that is, a constructor with no arguments). Cytoscape will call this constructor to create an instance of your plugin class.
To load this plugin into Cytoscape, save the jar file at the above link to your local disk in the Cytoscape plugins folder. Then start Cytoscape which will then load the plugin from the jar. You should see the "Hello World" dialog appear above your main Cytoscape window.