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 vamsasLoad_actionPerformed(ActionEvent e)
787 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
788 getProperty("LAST_DIRECTORY"));
790 chooser.setFileView(new JalviewFileView());
791 chooser.setDialogTitle("Load Vamsas file");
792 chooser.setToolTipText("Import");
794 int value = chooser.showOpenDialog(this);
796 if (value == JalviewFileChooser.APPROVE_OPTION)
798 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
800 chooser.getSelectedFile().getAbsolutePath()
807 public void inputSequence_actionPerformed(ActionEvent e)
809 new SequenceFetcher(null);
812 JPanel progressPanel;
814 public void startLoading(final String fileName)
816 if (fileLoadingCount == 0)
818 progressPanel = new JPanel(new BorderLayout());
819 JProgressBar progressBar = new JProgressBar();
820 progressBar.setIndeterminate(true);
822 progressPanel.add(new JLabel("Loading File: " + fileName + " "),
825 progressPanel.add(progressBar, BorderLayout.CENTER);
827 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
833 public void stopLoading()
836 if (fileLoadingCount < 1)
838 if (progressPanel != null)
840 this.getContentPane().remove(progressPanel);
841 progressPanel = null;
843 fileLoadingCount = 0;
848 public static int getViewCount(String viewId)
851 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
852 for (int t = 0; t < frames.length; t++)
854 if (frames[t] instanceof AlignFrame)
856 AlignFrame af = (AlignFrame) frames[t];
857 for (int a = 0; a < af.alignPanels.size(); a++)
860 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
873 public void explodeViews(AlignFrame af)
875 int size = af.alignPanels.size();
881 for (int i = 0; i < size; i++)
883 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
884 AlignFrame newaf = new AlignFrame(ap);
885 if (ap.av.explodedPosition != null &&
886 !ap.av.explodedPosition.equals(af.getBounds()))
888 newaf.setBounds(ap.av.explodedPosition);
891 ap.av.gatherViewsHere = false;
893 addInternalFrame(newaf, af.getTitle(),
894 AlignFrame.DEFAULT_WIDTH,
895 AlignFrame.DEFAULT_HEIGHT);
898 af.alignPanels.clear();
899 af.closeMenuItem_actionPerformed(true);
903 public void gatherViews(AlignFrame source)
905 source.viewport.gatherViewsHere = true;
906 source.viewport.explodedPosition = source.getBounds();
907 JInternalFrame[] frames = desktop.getAllFrames();
908 String viewId = source.viewport.sequenceSetID;
910 for (int t = 0; t < frames.length; t++)
912 if (frames[t] instanceof AlignFrame && frames[t] != source)
914 AlignFrame af = (AlignFrame) frames[t];
915 boolean gatherThis = false;
916 for (int a = 0; a < af.alignPanels.size(); a++)
918 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
919 if (viewId.equals(ap.av.getSequenceSetId()))
922 ap.av.gatherViewsHere = false;
923 ap.av.explodedPosition = af.getBounds();
924 source.addAlignmentPanel(ap, false);
930 af.alignPanels.clear();
931 af.closeMenuItem_actionPerformed(true);
938 jalview.gui.VamsasClient v_client = null;
939 public void vamsasLoad_actionPerformed(ActionEvent e)
941 if (v_client == null)
944 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
945 getProperty("LAST_DIRECTORY"));
947 chooser.setFileView(new JalviewFileView());
948 chooser.setDialogTitle("Load Vamsas file");
949 chooser.setToolTipText("Import");
951 int value = chooser.showOpenDialog(this);
953 if (value == JalviewFileChooser.APPROVE_OPTION)
955 v_client = new jalview.gui.VamsasClient(this,
956 chooser.getSelectedFile());
957 this.vamsasLoad.setText("Session Update");
958 this.vamsasStop.setVisible(true);
959 v_client.initial_update();
960 v_client.startWatcher();
965 // store current data in session.
966 v_client.push_update();
970 public void vamsasStop_actionPerformed(ActionEvent e)
972 if (v_client != null)
974 v_client.end_session();
976 this.vamsasStop.setVisible(false);
977 this.vamsasLoad.setText("Start Vamsas Session...");
982 * hide vamsas user gui bits when a vamsas document event is being handled.
983 * @param b true to hide gui, false to reveal gui
985 public void setVamsasUpdate(boolean b)
987 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
988 (b ? "in progress" : "finished"));
989 vamsasLoad.setVisible(!b);
990 vamsasStop.setVisible(!b);
994 public JInternalFrame[] getAllFrames()
996 return desktop.getAllFrames();
1001 * Checks the given url to see if it gives a response indicating that
1002 * the user should be informed of a new questionnaire.
1005 public void checkForQuestionnaire(String url)
1007 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1008 javax.swing.SwingUtilities.invokeLater(jvq);
1012 class MyDesktopPane extends JDesktopPane implements Runnable
1014 boolean showMemoryUsage = false;
1016 java.text.NumberFormat df;
1018 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1020 public MyDesktopPane(boolean showMemoryUsage)
1022 showMemoryUsage(showMemoryUsage);
1025 public void showMemoryUsage(boolean showMemoryUsage)
1027 this.showMemoryUsage = showMemoryUsage;
1028 if (showMemoryUsage)
1030 Thread worker = new Thread(this);
1037 df = java.text.NumberFormat.getNumberInstance();
1038 df.setMaximumFractionDigits(2);
1039 runtime = Runtime.getRuntime();
1041 while (showMemoryUsage)
1046 maxMemory = runtime.maxMemory() / 1048576f;
1047 allocatedMemory = runtime.totalMemory() / 1048576f;
1048 freeMemory = runtime.freeMemory() / 1048576f;
1049 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1051 percentUsage = (totalFreeMemory / maxMemory) * 100;
1053 // if (percentUsage < 20)
1055 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1056 // instance.set.setBorder(border1);
1061 catch (Exception ex)
1063 ex.printStackTrace();
1068 public void paintComponent(Graphics g)
1072 if (percentUsage < 20)
1073 g.setColor(Color.red);
1075 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1076 + "MB; Max Memory: " + df.format(maxMemory)
1077 + "MB; " + df.format(percentUsage) + "%", 10,
1078 getHeight() - g.getFontMetrics().getHeight());
1082 protected JMenuItem groovyShell;
1083 public void doGroovyCheck() {
1084 if (jalview.bin.Cache.groovyJarsPresent())
1086 groovyShell = new JMenuItem();
1087 groovyShell.setText("Groovy Shell...");
1088 groovyShell.addActionListener(new ActionListener()
1090 public void actionPerformed(ActionEvent e) {
1091 groovyShell_actionPerformed(e);
1094 toolsMenu.add(groovyShell);
1095 groovyShell.setVisible(true);
1099 * Accessor method to quickly get all the AlignmentFrames
1102 protected AlignFrame[] getAlignframes() {
1103 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1109 Vector avp=new Vector();
1113 for (int i = frames.length - 1; i > -1; i--)
1115 if (frames[i] instanceof AlignFrame)
1117 AlignFrame af = (AlignFrame) frames[i];
1122 catch (Exception ex)
1124 ex.printStackTrace();
1130 AlignFrame afs[] = new AlignFrame[avp.size()];
1131 for (int i=0,j=avp.size(); i<j; i++) {
1132 afs[i] = (AlignFrame) avp.elementAt(i);
1139 * Add Groovy Support to Jalview
1141 public void groovyShell_actionPerformed(ActionEvent e) {
1142 // use reflection to avoid creating compilation dependency.
1143 if (!jalview.bin.Cache.groovyJarsPresent())
1145 throw new Error("Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1148 Class gcClass = Desktop.class.getClassLoader().loadClass("groovy.ui.Console");
1149 Constructor gccons = gcClass.getConstructor(null);
1150 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", new Class[] { String.class, Object.class} );
1151 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1152 Object gc = gccons.newInstance(null);
1153 setvar.invoke(gc, new Object[] { "Jalview", this});
1154 run.invoke(gc, null);
1156 catch (Exception ex)
1158 jalview.bin.Cache.log.error("Groovy Shell Creation failed.",ex);
1159 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1161 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.", "Jalview Groovy Support Failed",
1162 JOptionPane.ERROR_MESSAGE);