X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=doc%2FAddingGroovySupport.html;h=6726612df0a7e84b0cd46d1d0fb4f45035f0b3ea;hb=fdb9f5bbf2b5044a13131f1ad446a7967e20df34;hp=efefcc2d261ffc3e76bceab3eb4e269ccdc0c484;hpb=8247c538f13da72c218ef52714ac9ca4acf564d3;p=jalview.git diff --git a/doc/AddingGroovySupport.html b/doc/AddingGroovySupport.html index efefcc2..6726612 100644 --- a/doc/AddingGroovySupport.html +++ b/doc/AddingGroovySupport.html @@ -1,122 +1,122 @@ - -
-There is currently no scripting language -extension within Jalview, in part because a -scripting API has not been developed. -
-It is, however, really easy to embed scripting -engines within Jalview. We haven't done it -with the Bean Scripting Framework, but the -code snippets below show you how to get going -with groovy. -
--For each class below, add the following objects and methods to their definitions. -
--.. -protected JMenuItem groovyShell = new JMenuItem(); -.. -jbInit() { -.. -groovyShell.setText("Groovy Shell..."); -groovyShell.addActionListener(new ActionListener() -{ - public void actionPerformed(ActionEvent e) { - groovyShell_actionPerformed(e); - } -}); -.. -} -.. -protected void groovyShell_actionPerformed(ActionEvent e) -{ -} -.. -
-.. -/** - * Accessor method to quickly get all the AlignmentFrames - * loaded. - */ -protected AlignFrame[] getAlignframes() { - JInternalFrame[] frames = Desktop.desktop.getAllFrames(); - - if (frames == null) - { - return null; - } - Vector avp=new Vector(); - try - { - //REVERSE ORDER - for (int i = frames.length - 1; i > -1; i--) - { - if (frames[i] instanceof AlignFrame) - { - AlignFrame af = (AlignFrame) frames[i]; - avp.addElement(af); - } - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } - if (avp.size()==0) - { - return null; - } - AlignFrame afs[] = new AlignFrame[avp.size()]; - for (int i=0,j=avp.size(); i<j; i++) { - afs[i] = (AlignFrame) avp.elementAt(i); - } - avp.clear(); - return afs; -} - -/** - * Add Groovy Support to Jalview - */ -public void groovyShell_actionPerformed(ActionEvent e) { - Console gc = new Console(); - gc.setVariable("Jalview", this); - gc.run(); -} -.. --
-Finally, compile and run with the groovy-all-*.jar (get the jar
-from the embedded directory within the groovy distribution).
-Then, you should be able to open the Groovy shell
-window from the Desktop's Tools menu. To check things are working,
-try a simple test script :
-
- - print Jalview.getAlignframes()[0].getTitle(); --Executing this will print the title of the first alignment loaded into Jalview. - -
-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.
-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. -
- - - + ++There is currently no scripting language +extension within Jalview, in part because a +scripting API has not been developed. +
+It is, however, really easy to embed scripting +engines within Jalview. We haven't done it +with the Bean Scripting Framework, but the +code snippets below show you how to get going +with groovy. +
++For each class below, add the following objects and methods to their definitions. +
++.. +protected JMenuItem groovyShell = new JMenuItem(); +.. +jbInit() { +.. +groovyShell.setText("Groovy Shell..."); +groovyShell.addActionListener(new ActionListener() +{ + public void actionPerformed(ActionEvent e) { + groovyShell_actionPerformed(e); + } +}); +.. +} +.. +protected void groovyShell_actionPerformed(ActionEvent e) +{ +} +.. +
+.. +/** + * Accessor method to quickly get all the AlignmentFrames + * loaded. + */ +protected AlignFrame[] getAlignframes() { + JInternalFrame[] frames = Desktop.desktop.getAllFrames(); + + if (frames == null) + { + return null; + } + Vector avp=new Vector(); + try + { + //REVERSE ORDER + for (int i = frames.length - 1; i > -1; i--) + { + if (frames[i] instanceof AlignFrame) + { + AlignFrame af = (AlignFrame) frames[i]; + avp.addElement(af); + } + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + if (avp.size()==0) + { + return null; + } + AlignFrame afs[] = new AlignFrame[avp.size()]; + for (int i=0,j=avp.size(); i<j; i++) { + afs[i] = (AlignFrame) avp.elementAt(i); + } + avp.clear(); + return afs; +} + +/** + * Add Groovy Support to Jalview + */ +public void groovyShell_actionPerformed(ActionEvent e) { + Console gc = new Console(); + gc.setVariable("Jalview", this); + gc.run(); +} +.. ++
+Finally, compile and run with the groovy-all-*.jar (get the jar
+from the embedded directory within the groovy distribution).
+Then, you should be able to open the Groovy shell
+window from the Desktop's Tools menu. To check things are working,
+try a simple test script :
+
+ + print Jalview.getAlignframes()[0].getTitle(); ++Executing this will print the title of the first alignment loaded into Jalview. + +
+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.
+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. +
+ + +