{
// Execute the groovy script after we've done all the rendering stuff
// and before any images or figures are generated.
- if (jalview.bin.Cache.groovyJarsPresent())
- {
- System.out.println("Executing script " + groovyscript);
- executeGroovyScript(groovyscript, new Object[] { desktop, af });
-
- System.out.println("CMD groovy[" + groovyscript
- + "] executed successfully!");
- }
- else
- {
- System.err
- .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
- + groovyscript);
- }
+ System.out.println("Executing script " + groovyscript);
+ executeGroovyScript(groovyscript, new Object[] { desktop, af });
+ System.out.println("CMD groovy[" + groovyscript
+ + "] executed successfully!");
groovyscript = null;
}
String imageName = "unnamed.png";
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
*/
instance = this;
doVamsasClientCheck();
- doGroovyCheck();
+
+ groovyShell = new JMenuItem();
+ groovyShell.setText(MessageManager.getString("label.groovy_console"));
+ groovyShell.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ groovyShell_actionPerformed();
+ }
+ });
+ toolsMenu.add(groovyShell);
+ groovyShell.setVisible(true);
+
doConfigureStructurePrefs();
setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
protected JMenuItem groovyShell;
- public void doGroovyCheck()
- {
- if (jalview.bin.Cache.groovyJarsPresent())
- {
- groovyShell = new JMenuItem();
- groovyShell.setText(MessageManager.getString("label.groovy_console"));
- groovyShell.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- groovyShell_actionPerformed();
- }
- });
- toolsMenu.add(groovyShell);
- groovyShell.setVisible(true);
- }
- }
-
/**
* Accessor method to quickly get all the AlignmentFrames loaded.
*
*/
public void groovyShell_actionPerformed()
{
- if (!jalview.bin.Cache.groovyJarsPresent())
- {
- throw new Error(
- MessageManager
- .getString("error.implementation_error_cannot_create_groovyshell"));
- }
try
{
openGroovyConsole();
}
/**
- * Open the Groovy console, using reflection to avoid creating compile-time
- * dependency on Groovy libraries
- *
- * @throws ClassNotFoundException
- * @throws NoSuchMethodException
- * @throws InstantiationException
- * @throws IllegalAccessException
- * @throws InvocationTargetException
+ * Open the Groovy console
*/
- void openGroovyConsole() throws ClassNotFoundException,
- NoSuchMethodException, InstantiationException,
- IllegalAccessException, InvocationTargetException
+ void openGroovyConsole()
{
- Class<?> gcClass = Desktop.class.getClassLoader().loadClass(
- "groovy.ui.Console");
- Constructor<?> gccons = gcClass.getConstructor();
- groovyConsole = gccons.newInstance();
+ groovyConsole = new groovy.ui.Console();
/*
* bind groovy variable 'Jalview' to the Desktop object
*/
- Method setvar = gcClass.getMethod("setVariable", new Class[] {
- String.class, Object.class });
- setvar.invoke(groovyConsole, new Object[] { "Jalview", this });
+ groovyConsole.setVariable("Jalview", this);
/*
* start the console
*/
- Method run = gcClass.getMethod("run");
- run.invoke(groovyConsole);
+ groovyConsole.run();
/*
* Allow only one console at a time, so that the AlignFrame menu option
* Disable 'new console', and enable 'Run script', when the console is
* opened, and the reverse when it is closed
*/
- Method getFrame = gcClass.getMethod("getFrame");
- Window window = (Window) getFrame.invoke(groovyConsole);
+ Window window = (Window) groovyConsole.getFrame();
window.addWindowListener(new WindowAdapter()
{
@Override
*/
private java.util.concurrent.Semaphore block = new Semaphore(0);
- /*
- * groovy.ui.Console object - if Groovy jars are present and the
- * user has activated the Groovy console. Use via reflection to
- * avoid compile-time dependency on Groovy libraries.
- */
- private static Object groovyConsole;
+ private static groovy.ui.Console groovyConsole;
/**
* add another dialog thread to the queue
Desktop.currentAlignFrame = currentAlignFrame;
}
- public static Object getGroovyConsole()
+ public static groovy.ui.Console getGroovyConsole()
{
return groovyConsole;
}