import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.print.PrinterJob;
import java.beans.PropertyChangeEvent;
import java.io.File;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
{
formatMenu.add(vsel);
}
+ addFocusListener(new FocusAdapter()
+ {
+ @Override
+ public void focusGained(FocusEvent e)
+ {
+ Desktop.setCurrentAlignFrame(AlignFrame.this);
+ }
+ });
}
.setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
showProducts.setEnabled(canShowProducts());
+ setGroovyEnabled(Desktop.instance.getGroovyConsole() != null);
updateEditMenuBar();
}
+ /**
+ * Set the enabled state of the 'Run Groovy' option in the Calculate menu
+ *
+ * @param b
+ */
+ public void setGroovyEnabled(boolean b)
+ {
+ runGroovy.setEnabled(b);
+ }
+
private IProgressIndicator progressBar;
/*
return;
}
}
+
+ /**
+ * Try to run a script in the Groovy console, having first ensured that this
+ * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
+ * be targeted at this alignment.
+ */
+ @Override
+ protected void runGroovy_actionPerformed()
+ {
+ Desktop.setCurrentAlignFrame(this);
+ Object console = Desktop.instance.getGroovyConsole();
+ if (console != null)
+ {
+ /*
+ * use reflection here to avoid compile-time dependency
+ * on Groovy libraries
+ */
+ try
+ {
+ Class<?> gcClass = getClass().getClassLoader().loadClass(
+ "groovy.ui.Console");
+ Method runScript = gcClass.getMethod("runScript");
+ runScript.invoke(console);
+ } catch (Exception ex)
+ {
+ System.err.println((ex.toString()));
+ JOptionPane
+ .showInternalMessageDialog(Desktop.desktop, MessageManager
+ .getString("label.couldnt_run_groovy_script"),
+ MessageManager
+ .getString("label.groovy_support_failed"),
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ else
+ {
+ System.err.println("Can't run Groovy script as console not found");
+ }
+ }
}
class PrintThread extends Thread
java.lang.reflect.Method setvar = gcClass.getMethod("setVariable",
new Class[] { String.class, Object.class });
java.lang.reflect.Method run = gcClass.getMethod("run");
- Object gc = gccons.newInstance();
- setvar.invoke(gc, new Object[] { "Jalview", this });
- run.invoke(gc);
+ groovyConsole = gccons.newInstance();
+ setvar.invoke(groovyConsole, new Object[] { "Jalview", this });
+ run.invoke(groovyConsole);
+ /*
+ * and rebuild alignframe menus to enable 'Run Groovy'
+ */
+
+ AlignFrame[] alignFrames = getAlignFrames();
+ if (alignFrames != null)
+ {
+ for (AlignFrame af : alignFrames)
+ {
+ af.setGroovyEnabled(true);
+ }
+ }
} catch (Exception ex)
{
jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
*/
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;
+
/**
* add another dialog thread to the queue
*
Desktop.currentAlignFrame = currentAlignFrame;
}
+ public Object getGroovyConsole()
+ {
+ return groovyConsole;
+ }
+
}
protected JMenu showProducts = new JMenu();
+ protected JMenuItem runGroovy = new JMenuItem();
+
protected JMenuItem rnahelicesColour = new JMenuItem();
protected JCheckBoxMenuItem autoCalculate = new JCheckBoxMenuItem();
// for show products actions see AlignFrame.canShowProducts
showProducts.setText(MessageManager.getString("label.get_cross_refs"));
+ runGroovy.setText(MessageManager.getString("label.run_groovy"));
+ runGroovy.setToolTipText(MessageManager.getString("label.run_groovy_tip"));
+ runGroovy.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ runGroovy_actionPerformed();
+ }
+ });
+
JMenuItem openFeatureSettings = new JMenuItem(
MessageManager.getString("action.feature_settings"));
openFeatureSettings.addActionListener(new ActionListener()
alignFrameMenuBar.add(colourMenu);
alignFrameMenuBar.add(calculateMenu);
alignFrameMenuBar.add(webService);
+
fileMenu.add(fetchSequence);
fileMenu.add(addSequenceMenu);
fileMenu.add(reload);
fileMenu.add(associatedData);
fileMenu.addSeparator();
fileMenu.add(closeMenuItem);
+
+ pasteMenu.add(pasteNew);
+ pasteMenu.add(pasteThis);
editMenu.add(undoMenuItem);
editMenu.add(redoMenuItem);
editMenu.add(cut);
// editMenu.addSeparator();
editMenu.add(padGapsMenuitem);
+ showMenu.add(showAllColumns);
+ showMenu.add(showAllSeqs);
+ showMenu.add(showAllhidden);
+ hideMenu.add(hideSelColumns);
+ hideMenu.add(hideSelSequences);
+ hideMenu.add(hideAllSelection);
+ hideMenu.add(hideAllButSelection);
viewMenu.add(newView);
viewMenu.add(expandViews);
viewMenu.add(gatherViews);
colourMenu.add(modifyPID);
colourMenu.add(annotationColour);
colourMenu.add(rnahelicesColour);
+
+ sort.add(sortIDMenuItem);
+ sort.add(sortLengthMenuItem);
+ sort.add(sortGroupMenuItem);
+ sort.add(sortPairwiseMenuItem);
+ sort.add(sortByTreeMenu);
calculateMenu.add(sort);
calculateMenu.add(calculateTree);
calculateMenu.addSeparator();
calculateMenu.add(autoCalculate);
calculateMenu.add(sortByTree);
calculateMenu.addSeparator();
+ calculateMenu.add(expandAlignment);
calculateMenu.add(extractScores);
+ calculateMenu.addSeparator();
+ calculateMenu.add(runGroovy);
+
webServiceNoServices = new JMenuItem(
MessageManager.getString("label.no_services"));
webService.add(webServiceNoServices);
- pasteMenu.add(pasteNew);
- pasteMenu.add(pasteThis);
- sort.add(sortIDMenuItem);
- sort.add(sortLengthMenuItem);
- sort.add(sortGroupMenuItem);
- sort.add(sortPairwiseMenuItem);
- sort.add(sortByTreeMenu);
exportImageMenu.add(htmlMenuItem);
exportImageMenu.add(epsFile);
exportImageMenu.add(createPNG);
this.getContentPane().add(statusPanel, java.awt.BorderLayout.SOUTH);
statusPanel.add(statusBar, null);
this.getContentPane().add(tabbedPane, java.awt.BorderLayout.CENTER);
- showMenu.add(showAllColumns);
- showMenu.add(showAllSeqs);
- showMenu.add(showAllhidden);
- hideMenu.add(hideSelColumns);
- hideMenu.add(hideSelSequences);
- hideMenu.add(hideAllSelection);
- hideMenu.add(hideAllButSelection);
formatMenu.add(font);
formatMenu.addSeparator();
selectMenu.add(grpsFromSelection);
selectMenu.add(deleteGroups);
selectMenu.add(annotationColumn);
- calculateMenu.add(expandAlignment);
// TODO - determine if the listenToViewSelections button is needed : see bug
// JAL-574
// selectMenu.addSeparator();
}
/**
+ * Try to run script in a Groovy console, having first ensured that this
+ * alignframe is set as currentAlignFrame in Desktop
+ */
+ protected void runGroovy_actionPerformed()
+ {
+
+ }
+ /**
* Adds the given action listener and key accelerator to the given menu item.
* Also saves in a lookup table to support lookup of action by key stroke.
*