2 <title>Adding Groovy Support to Jalview
6 Adding Groovy Support to Jalview
9 There is currently no scripting language
10 extension within Jalview, in part because a
11 scripting API has not been developed.
13 <p>It is, however, really easy to embed scripting
14 engines within Jalview. We haven't done it
15 with the Bean Scripting Framework, but the
16 code snippets below show you how to get going
19 <h2>Modifications</h2>
21 For each class below, add the following objects and methods to their definitions.
24 jalview.jbgui.GDesktop
27 protected JMenuItem groovyShell = new JMenuItem();
31 groovyShell.setText("Groovy Shell...");
32 groovyShell.addActionListener(new ActionListener()
34 public void actionPerformed(ActionEvent e) {
35 groovyShell_actionPerformed(e);
41 protected void groovyShell_actionPerformed(ActionEvent e)
46 <li>jalview.gui.Desktop
50 * Accessor method to quickly get all the AlignmentFrames
53 protected AlignFrame[] getAlignframes() {
54 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
60 Vector avp=new Vector();
64 for (int i = frames.length - 1; i > -1; i--)
66 if (frames[i] instanceof AlignFrame)
68 AlignFrame af = (AlignFrame) frames[i];
81 AlignFrame afs[] = new AlignFrame[avp.size()];
82 for (int i=0,j=avp.size(); i<j; i++) {
83 afs[i] = (AlignFrame) avp.elementAt(i);
90 * Add Groovy Support to Jalview
92 public void groovyShell_actionPerformed(ActionEvent e) {
93 Console gc = new Console();
94 gc.setVariable("Jalview", this);
102 Finally, compile and run with the groovy-all-*.jar (get the jar
103 from the <em>embedded</em> directory within the <a
104 href="http://dist.codehaus.org/groovy/distributions"/>groovy distribution</a>).
105 Then, you should be able to open the Groovy shell
106 window from the Desktop's Tools menu. To check things are working,
107 try a simple test script :<br>
110 print Jalview.getAlignframes()[0].getTitle();
112 Executing this will print the title of the first alignment loaded into Jalview.</p>
116 Using Java class methods from Groovy is straightforward, but currently, there isn't a set of easy to use methods for the jalview objects. A Jalview Scripting API needs to be developed to make this easier.</p>
117 <h3>Making it easier</h3>
118 <p>jalview.bin.JalviewScript could be a top level jalview instance of a script execution thread, creating and maintaining the context for scripts operating on the jalview datamodel and interfacing with the Jalview GUI.