Size: 1822
Comment:
|
← Revision 9 as of 2010-07-22 20:07:25
Size: 2320
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 4: | Line 4: |
package helloworld; import java.awt.event.ActionEvent; |
|
Line 5: | Line 8: |
import cytoscape.Cytoscape; | |
Line 6: | Line 10: |
import cytoscape.plugin.Cytoscape; | import cytoscape.util.CytoscapeAction; |
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 19: |
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(),"Hello World is selected!"); } } |
Line 17: | Line 36: |
Line 20: | Line 40: |
attachment:HelloWorld.java | [[attachment:HelloWorldPlugin.java]] |
Line 22: | Line 42: |
attachment:HelloWorld.jar | [[attachment:helloworld.jar]] |
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 javax.swing.JOptionPane;
5 import cytoscape.Cytoscape;
6 import cytoscape.plugin.CytoscapePlugin;
7 import cytoscape.util.CytoscapeAction;
8
9
10 /**
11 * A menu item "Hello World" will appear at Plugins menu. Click on the menu
12 * item, a message dialog will show up.
13 */
14 public class HelloWorldPlugin extends CytoscapePlugin {
15
16 public HelloWorldPlugin() {
17 MyPluginMenuAction menuAction = new MyPluginMenuAction(this);
18 Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) menuAction);
19 }
20
21 public class MyPluginMenuAction extends CytoscapeAction {
22
23 public MyPluginMenuAction(HelloWorldPlugin myPlugin) {
24 super("Hello World");
25 setPreferredMenu("Plugins");
26 }
27
28 public void actionPerformed(ActionEvent e) {
29 JOptionPane.showMessageDialog(Cytoscape.getDesktop(),"Hello World is selected!");
30 }
31 }
32 }
33
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.