2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 import java.awt.datatransfer.*;
24 import java.awt.dnd.*;
25 import java.awt.event.*;
26 import java.lang.reflect.Constructor;
38 extends jalview.jbgui.GDesktop implements DropTargetListener,
42 public static Desktop instance;
44 //Need to decide if the Memory Usage is to be included in
45 //Next release or not.
46 // public static MyDesktopPane desktop;
47 public static JDesktopPane desktop;
50 static int openFrameCount = 0;
51 static final int xOffset = 30;
52 static final int yOffset = 30;
53 public static jalview.ws.Discoverer discoverer;
55 public static Object[] jalviewClipboard;
56 public static boolean internalCopy = false;
58 static int fileLoadingCount = 0;
61 * Creates a new Desktop object.
66 doVamsasClientCheck();
70 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
71 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
73 desktop = new JDesktopPane();
74 desktop.setBackground(Color.white);
75 getContentPane().setLayout(new BorderLayout());
76 getContentPane().add(desktop, BorderLayout.CENTER);
77 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
79 // This line prevents Windows Look&Feel resizing all new windows to maximum
80 // if previous window was maximised
81 desktop.setDesktopManager(new DefaultDesktopManager());
83 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
84 String x = jalview.bin.Cache.getProperty("SCREEN_X");
85 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
86 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
87 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
89 if ( (x != null) && (y != null) && (width != null) && (height != null))
91 setBounds(Integer.parseInt(x), Integer.parseInt(y),
92 Integer.parseInt(width), Integer.parseInt(height));
96 setBounds( (int) (screenSize.width - 900) / 2,
97 (int) (screenSize.height - 650) / 2, 900, 650);
100 this.addWindowListener(new WindowAdapter()
102 public void windowClosing(WindowEvent evt)
108 this.addMouseListener(new MouseAdapter()
110 public void mousePressed(MouseEvent evt)
112 if(SwingUtilities.isRightMouseButton(evt))
114 showPasteMenu(evt.getX(), evt.getY());
120 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
122 /////////Add a splashscreen on startup
123 /////////Add a splashscreen on startup
127 discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
130 private void doVamsasClientCheck()
132 if (jalview.bin.Cache.vamsasJarsPresent())
134 VamsasMenu.setVisible(true);
135 vamsasLoad.setVisible(true);
139 void showPasteMenu(int x, int y)
141 JPopupMenu popup = new JPopupMenu();
142 JMenuItem item = new JMenuItem("Paste To New Window");
143 item.addActionListener(new ActionListener()
145 public void actionPerformed(ActionEvent evt)
152 popup.show(this, x, y);
159 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
160 Transferable contents = c.getContents(this);
162 if (contents != null)
164 String file = (String) contents
165 .getTransferData(DataFlavor.stringFlavor);
167 String format = new IdentifyFile().Identify(file,
168 FormatAdapter.PASTE);
170 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
176 System.out.println("Unable to paste alignment from system clipboard:\n"
184 * @param frame DOCUMENT ME!
185 * @param title DOCUMENT ME!
186 * @param w DOCUMENT ME!
187 * @param h DOCUMENT ME!
189 public static synchronized void addInternalFrame(final JInternalFrame frame,
190 String title, int w, int h)
192 addInternalFrame(frame, title, w, h, true);
198 * @param frame DOCUMENT ME!
199 * @param title DOCUMENT ME!
200 * @param w DOCUMENT ME!
201 * @param h DOCUMENT ME!
202 * @param resizable DOCUMENT ME!
204 public static synchronized void addInternalFrame(final JInternalFrame frame,
205 String title, int w, int h, boolean resizable)
208 frame.setTitle(title);
209 if (frame.getWidth() < 1 || frame.getHeight() < 1)
213 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
214 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
215 // IF JALVIEW IS RUNNING HEADLESS
216 /////////////////////////////////////////////////
217 if (System.getProperty("java.awt.headless") != null
218 && System.getProperty("java.awt.headless").equals("true"))
225 frame.setVisible(true);
226 frame.setClosable(true);
227 frame.setResizable(resizable);
228 frame.setMaximizable(resizable);
229 frame.setIconifiable(resizable);
230 frame.setFrameIcon(null);
232 if (frame.getX() < 1 && frame.getY() < 1)
234 frame.setLocation(xOffset * openFrameCount,
235 yOffset * ( (openFrameCount - 1) % 10) + yOffset);
238 final JMenuItem menuItem = new JMenuItem(title);
239 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
241 public void internalFrameActivated(javax.swing.event.
242 InternalFrameEvent evt)
244 JInternalFrame itf = desktop.getSelectedFrame();
252 public void internalFrameClosed(
253 javax.swing.event.InternalFrameEvent evt)
255 PaintRefresher.RemoveComponent(frame);
257 windowMenu.remove(menuItem);
258 JInternalFrame itf = desktop.getSelectedFrame();
268 menuItem.addActionListener(new ActionListener()
270 public void actionPerformed(ActionEvent e)
274 frame.setSelected(true);
275 frame.setIcon(false);
277 catch (java.beans.PropertyVetoException ex)
284 windowMenu.add(menuItem);
290 frame.setSelected(true);
291 frame.requestFocus();
293 catch (java.beans.PropertyVetoException ve)
297 public void lostOwnership(Clipboard clipboard, Transferable contents)
301 Desktop.jalviewClipboard = null;
304 internalCopy = false;
307 public void dragEnter(DropTargetDragEvent evt)
310 public void dragExit(DropTargetEvent evt)
313 public void dragOver(DropTargetDragEvent evt)
316 public void dropActionChanged(DropTargetDragEvent evt)
322 * @param evt DOCUMENT ME!
324 public void drop(DropTargetDropEvent evt)
326 Transferable t = evt.getTransferable();
327 java.util.List files = null;
331 DataFlavor uriListFlavor = new DataFlavor(
332 "text/uri-list;class=java.lang.String");
333 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
335 //Works on Windows and MacOSX
336 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
337 files = (java.util.List) t.getTransferData(DataFlavor.
340 else if (t.isDataFlavorSupported(uriListFlavor))
342 // This is used by Unix drag system
343 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
344 String data = (String) t.getTransferData(uriListFlavor);
345 files = new java.util.ArrayList(1);
346 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
349 st.hasMoreTokens(); )
351 String s = st.nextToken();
352 if (s.startsWith("#"))
354 // the line is a comment (as per the RFC 2483)
358 java.net.URI uri = new java.net.URI(s);
359 java.io.File file = new java.io.File(uri);
371 for (int i = 0; i < files.size(); i++)
373 String file = files.get(i).toString();
374 String protocol = FormatAdapter.FILE;
375 String format = null;
377 if (file.endsWith(".jar"))
384 format = new IdentifyFile().Identify(file,
388 new FileLoader().LoadFile(file, protocol, format);
400 * @param e DOCUMENT ME!
402 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
404 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
409 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
414 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
415 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
417 chooser.setFileView(new JalviewFileView());
418 chooser.setDialogTitle("Open local file");
419 chooser.setToolTipText("Open");
421 int value = chooser.showOpenDialog(this);
423 if (value == JalviewFileChooser.APPROVE_OPTION)
425 String choice = chooser.getSelectedFile().getPath();
426 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
427 chooser.getSelectedFile().getParent());
429 String format = null;
430 if (chooser.getSelectedFormat().equals("Jalview"))
436 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
439 if (viewport != null)
441 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
445 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
453 * @param e DOCUMENT ME!
455 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
457 // This construct allows us to have a wider textfield
459 JLabel label = new JLabel("Enter URL of Input File");
460 final JComboBox history = new JComboBox();
462 JPanel panel = new JPanel(new GridLayout(2, 1));
465 history.setPreferredSize(new Dimension(400, 20));
466 history.setEditable(true);
467 history.addItem("http://www.");
469 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
473 if (historyItems != null)
475 st = new StringTokenizer(historyItems, "\t");
477 while (st.hasMoreTokens())
479 history.addItem(st.nextElement());
483 int reply = JOptionPane.showInternalConfirmDialog(desktop,
484 panel, "Input Alignment From URL",
485 JOptionPane.OK_CANCEL_OPTION);
487 if (reply != JOptionPane.OK_OPTION)
492 String url = history.getSelectedItem().toString();
494 if (url.toLowerCase().endsWith(".jar"))
496 if (viewport != null)
498 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
502 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
507 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
509 if (format.equals("URL NOT FOUND"))
511 JOptionPane.showInternalMessageDialog(Desktop.desktop,
512 "Couldn't locate " + url,
514 JOptionPane.WARNING_MESSAGE);
519 if (viewport != null)
521 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
525 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
533 * @param e DOCUMENT ME!
535 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
537 CutAndPasteTransfer cap = new CutAndPasteTransfer();
538 cap.setForInput(viewport);
539 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
547 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
548 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
549 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
550 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
557 * @param e DOCUMENT ME!
559 public void aboutMenuItem_actionPerformed(ActionEvent e)
561 StringBuffer message = new StringBuffer("JalView version " +
562 jalview.bin.Cache.getProperty(
566 Cache.getDefault("BUILD_DATE",
569 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
570 jalview.bin.Cache.getProperty("VERSION")))
572 message.append("\n\n!! Jalview version "
573 + jalview.bin.Cache.getProperty("LATEST_VERSION")
575 " is available for download from http://www.jalview.org !!\n");
579 message.append("\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
580 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
581 "\nFor all issues relating to Jalview, email help@jalview.org" +
582 "\n\nIf you use JalView, please cite:" +
583 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
584 "\nBioinformatics, 2004 20;426-7.");
586 JOptionPane.showInternalMessageDialog(Desktop.desktop,
588 message.toString(), "About Jalview",
589 JOptionPane.INFORMATION_MESSAGE);
595 * @param e DOCUMENT ME!
597 public void documentationMenuItem_actionPerformed(ActionEvent e)
601 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
602 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
603 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
605 javax.help.HelpBroker hb = hs.createHelpBroker();
606 hb.setCurrentID("home");
607 hb.setDisplayed(true);
613 public void closeAll_actionPerformed(ActionEvent e)
615 JInternalFrame[] frames = desktop.getAllFrames();
616 for (int i = 0; i < frames.length; i++)
620 frames[i].setClosed(true);
622 catch (java.beans.PropertyVetoException ex)
625 System.out.println("ALL CLOSED");
629 public void raiseRelated_actionPerformed(ActionEvent e)
631 reorderAssociatedWindows(false, false);
634 public void minimizeAssociated_actionPerformed(ActionEvent e)
636 reorderAssociatedWindows(true, false);
639 void closeAssociatedWindows()
641 reorderAssociatedWindows(false, true);
644 void reorderAssociatedWindows(boolean minimize, boolean close)
646 JInternalFrame[] frames = desktop.getAllFrames();
647 if (frames == null || frames.length < 1)
652 AlignViewport source = null, target = null;
653 if (frames[0] instanceof AlignFrame)
655 source = ( (AlignFrame) frames[0]).getCurrentView();
657 else if (frames[0] instanceof TreePanel)
659 source = ( (TreePanel) frames[0]).getViewPort();
661 else if (frames[0] instanceof PCAPanel)
663 source = ( (PCAPanel) frames[0]).av;
665 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
667 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
672 for (int i = 0; i < frames.length; i++)
675 if (frames[i] == null)
679 if (frames[i] instanceof AlignFrame)
681 target = ( (AlignFrame) frames[i]).getCurrentView();
683 else if (frames[i] instanceof TreePanel)
685 target = ( (TreePanel) frames[i]).getViewPort();
687 else if (frames[i] instanceof PCAPanel)
689 target = ( (PCAPanel) frames[i]).av;
691 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
693 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
696 if (source == target)
702 frames[i].setClosed(true);
706 frames[i].setIcon(minimize);
714 catch (java.beans.PropertyVetoException ex)
724 * @param e DOCUMENT ME!
726 protected void preferences_actionPerformed(ActionEvent e)
734 * @param e DOCUMENT ME!
736 public void saveState_actionPerformed(ActionEvent e)
738 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
740 "LAST_DIRECTORY"), new String[]
743 {"Jalview Project"}, "Jalview Project");
745 chooser.setFileView(new JalviewFileView());
746 chooser.setDialogTitle("Save State");
748 int value = chooser.showSaveDialog(this);
750 if (value == JalviewFileChooser.APPROVE_OPTION)
752 java.io.File choice = chooser.getSelectedFile();
753 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
754 new Jalview2XML().SaveState(choice);
761 * @param e DOCUMENT ME!
763 public void loadState_actionPerformed(ActionEvent e)
765 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
767 "LAST_DIRECTORY"), new String[]
770 {"Jalview Project"}, "Jalview Project");
771 chooser.setFileView(new JalviewFileView());
772 chooser.setDialogTitle("Restore state");
774 int value = chooser.showOpenDialog(this);
776 if (value == JalviewFileChooser.APPROVE_OPTION)
778 String choice = chooser.getSelectedFile().getAbsolutePath();
779 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
780 chooser.getSelectedFile().getParent());
781 new Jalview2XML().LoadJalviewAlign(choice);
785 public void inputSequence_actionPerformed(ActionEvent e)
787 new SequenceFetcher(null);
790 JPanel progressPanel;
792 public void startLoading(final String fileName)
794 if (fileLoadingCount == 0)
796 progressPanel = new JPanel(new BorderLayout());
797 JProgressBar progressBar = new JProgressBar();
798 progressBar.setIndeterminate(true);
800 progressPanel.add(new JLabel("Loading File: " + fileName + " "),
803 progressPanel.add(progressBar, BorderLayout.CENTER);
805 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
811 public void stopLoading()
814 if (fileLoadingCount < 1)
816 if (progressPanel != null)
818 this.getContentPane().remove(progressPanel);
819 progressPanel = null;
821 fileLoadingCount = 0;
826 public static int getViewCount(String viewId)
829 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
830 for (int t = 0; t < frames.length; t++)
832 if (frames[t] instanceof AlignFrame)
834 AlignFrame af = (AlignFrame) frames[t];
835 for (int a = 0; a < af.alignPanels.size(); a++)
838 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
851 public void explodeViews(AlignFrame af)
853 int size = af.alignPanels.size();
859 for (int i = 0; i < size; i++)
861 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
862 AlignFrame newaf = new AlignFrame(ap);
863 if (ap.av.explodedPosition != null &&
864 !ap.av.explodedPosition.equals(af.getBounds()))
866 newaf.setBounds(ap.av.explodedPosition);
869 ap.av.gatherViewsHere = false;
871 addInternalFrame(newaf, af.getTitle(),
872 AlignFrame.DEFAULT_WIDTH,
873 AlignFrame.DEFAULT_HEIGHT);
876 af.alignPanels.clear();
877 af.closeMenuItem_actionPerformed(true);
881 public void gatherViews(AlignFrame source)
883 source.viewport.gatherViewsHere = true;
884 source.viewport.explodedPosition = source.getBounds();
885 JInternalFrame[] frames = desktop.getAllFrames();
886 String viewId = source.viewport.sequenceSetID;
888 for (int t = 0; t < frames.length; t++)
890 if (frames[t] instanceof AlignFrame && frames[t] != source)
892 AlignFrame af = (AlignFrame) frames[t];
893 boolean gatherThis = false;
894 for (int a = 0; a < af.alignPanels.size(); a++)
896 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
897 if (viewId.equals(ap.av.getSequenceSetId()))
900 ap.av.gatherViewsHere = false;
901 ap.av.explodedPosition = af.getBounds();
902 source.addAlignmentPanel(ap, false);
908 af.alignPanels.clear();
909 af.closeMenuItem_actionPerformed(true);
916 jalview.gui.VamsasApplication v_client = null;
917 public void vamsasLoad_actionPerformed(ActionEvent e)
919 if (v_client == null)
922 // we just start a default session for moment.
924 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
925 getProperty("LAST_DIRECTORY"));
927 chooser.setFileView(new JalviewFileView());
928 chooser.setDialogTitle("Load Vamsas file");
929 chooser.setToolTipText("Import");
931 int value = chooser.showOpenDialog(this);
933 if (value == JalviewFileChooser.APPROVE_OPTION)
935 v_client = new jalview.gui.VamsasApplication(this,
936 chooser.getSelectedFile());
939 v_client = new VamsasApplication(this);
940 vamsasLoad.setText("Session Update");
941 vamsasStop.setVisible(true);
942 v_client.initial_update();
946 // store current data in session.
947 v_client.push_update();
951 public void vamsasStop_actionPerformed(ActionEvent e)
953 if (v_client != null)
955 v_client.end_session();
957 this.vamsasStop.setVisible(false);
958 this.vamsasLoad.setText("Start Vamsas Session...");
963 * hide vamsas user gui bits when a vamsas document event is being handled.
964 * @param b true to hide gui, false to reveal gui
966 public void setVamsasUpdate(boolean b)
968 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
969 (b ? "in progress" : "finished"));
970 vamsasLoad.setVisible(!b);
971 vamsasStop.setVisible(!b);
975 public JInternalFrame[] getAllFrames()
977 return desktop.getAllFrames();
982 * Checks the given url to see if it gives a response indicating that
983 * the user should be informed of a new questionnaire.
986 public void checkForQuestionnaire(String url)
988 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
989 javax.swing.SwingUtilities.invokeLater(jvq);
993 class MyDesktopPane extends JDesktopPane implements Runnable
995 boolean showMemoryUsage = false;
997 java.text.NumberFormat df;
999 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1001 public MyDesktopPane(boolean showMemoryUsage)
1003 showMemoryUsage(showMemoryUsage);
1006 public void showMemoryUsage(boolean showMemoryUsage)
1008 this.showMemoryUsage = showMemoryUsage;
1009 if (showMemoryUsage)
1011 Thread worker = new Thread(this);
1018 df = java.text.NumberFormat.getNumberInstance();
1019 df.setMaximumFractionDigits(2);
1020 runtime = Runtime.getRuntime();
1022 while (showMemoryUsage)
1027 maxMemory = runtime.maxMemory() / 1048576f;
1028 allocatedMemory = runtime.totalMemory() / 1048576f;
1029 freeMemory = runtime.freeMemory() / 1048576f;
1030 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1032 percentUsage = (totalFreeMemory / maxMemory) * 100;
1034 // if (percentUsage < 20)
1036 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1037 // instance.set.setBorder(border1);
1042 catch (Exception ex)
1044 ex.printStackTrace();
1049 public void paintComponent(Graphics g)
1053 if (percentUsage < 20)
1054 g.setColor(Color.red);
1056 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1057 + "MB; Max Memory: " + df.format(maxMemory)
1058 + "MB; " + df.format(percentUsage) + "%", 10,
1059 getHeight() - g.getFontMetrics().getHeight());
1063 protected JMenuItem groovyShell;
1064 public void doGroovyCheck() {
1065 if (jalview.bin.Cache.groovyJarsPresent())
1067 groovyShell = new JMenuItem();
1068 groovyShell.setText("Groovy Shell...");
1069 groovyShell.addActionListener(new ActionListener()
1071 public void actionPerformed(ActionEvent e) {
1072 groovyShell_actionPerformed(e);
1075 toolsMenu.add(groovyShell);
1076 groovyShell.setVisible(true);
1080 * Accessor method to quickly get all the AlignmentFrames
1083 protected AlignFrame[] getAlignframes() {
1084 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1090 Vector avp=new Vector();
1094 for (int i = frames.length - 1; i > -1; i--)
1096 if (frames[i] instanceof AlignFrame)
1098 AlignFrame af = (AlignFrame) frames[i];
1103 catch (Exception ex)
1105 ex.printStackTrace();
1111 AlignFrame afs[] = new AlignFrame[avp.size()];
1112 for (int i=0,j=avp.size(); i<j; i++) {
1113 afs[i] = (AlignFrame) avp.elementAt(i);
1120 * Add Groovy Support to Jalview
1122 public void groovyShell_actionPerformed(ActionEvent e) {
1123 // use reflection to avoid creating compilation dependency.
1124 if (!jalview.bin.Cache.groovyJarsPresent())
1126 throw new Error("Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1129 Class gcClass = Desktop.class.getClassLoader().loadClass("groovy.ui.Console");
1130 Constructor gccons = gcClass.getConstructor(null);
1131 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", new Class[] { String.class, Object.class} );
1132 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1133 Object gc = gccons.newInstance(null);
1134 setvar.invoke(gc, new Object[] { "Jalview", this});
1135 run.invoke(gc, null);
1137 catch (Exception ex)
1139 jalview.bin.Cache.log.error("Groovy Shell Creation failed.",ex);
1140 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1142 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.", "Jalview Groovy Support Failed",
1143 JOptionPane.ERROR_MESSAGE);