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();
73 java.net.URL url = getClass().getResource("/images/logo.gif");
77 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
79 MediaTracker mt = new MediaTracker(this);
80 mt.addImage(image, 0);
89 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
90 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
92 // desktop = new MyDesktopPane(true);
93 desktop = new JDesktopPane();
94 desktop.setBackground(Color.white);
95 getContentPane().setLayout(new BorderLayout());
96 getContentPane().add(desktop, BorderLayout.CENTER);
97 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
99 // This line prevents Windows Look&Feel resizing all new windows to maximum
100 // if previous window was maximised
101 desktop.setDesktopManager(new DefaultDesktopManager());
103 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
104 String x = jalview.bin.Cache.getProperty("SCREEN_X");
105 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
106 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
107 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
109 if ( (x != null) && (y != null) && (width != null) && (height != null))
111 setBounds(Integer.parseInt(x), Integer.parseInt(y),
112 Integer.parseInt(width), Integer.parseInt(height));
116 setBounds( (int) (screenSize.width - 900) / 2,
117 (int) (screenSize.height - 650) / 2, 900, 650);
120 this.addWindowListener(new WindowAdapter()
122 public void windowClosing(WindowEvent evt)
128 this.addMouseListener(new MouseAdapter()
130 public void mousePressed(MouseEvent evt)
132 if(SwingUtilities.isRightMouseButton(evt))
134 showPasteMenu(evt.getX(), evt.getY());
140 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
142 /////////Add a splashscreen on startup
143 /////////Add a splashscreen on startup
144 JInternalFrame frame = new JInternalFrame();
146 SplashScreen splash = new SplashScreen(frame, image);
147 frame.setContentPane(splash);
148 frame.setLayer(JLayeredPane.PALETTE_LAYER);
149 frame.setLocation( (int) ( (getWidth() - 750) / 2),
150 (int) ( (getHeight() - 160) / 2));
152 addInternalFrame(frame, "", 750, 160, false);
154 discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
157 private void doVamsasClientCheck()
159 if (jalview.bin.Cache.vamsasJarsPresent())
161 VamsasMenu.setVisible(true);
162 vamsasLoad.setVisible(true);
166 void showPasteMenu(int x, int y)
168 JPopupMenu popup = new JPopupMenu();
169 JMenuItem item = new JMenuItem("Paste To New Window");
170 item.addActionListener(new ActionListener()
172 public void actionPerformed(ActionEvent evt)
179 popup.show(this, x, y);
186 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
187 Transferable contents = c.getContents(this);
189 if (contents != null)
191 String file = (String) contents
192 .getTransferData(DataFlavor.stringFlavor);
194 String format = new IdentifyFile().Identify(file,
195 FormatAdapter.PASTE);
197 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
203 System.out.println("Unable to paste alignment from system clipboard:\n"
211 * @param frame DOCUMENT ME!
212 * @param title DOCUMENT ME!
213 * @param w DOCUMENT ME!
214 * @param h DOCUMENT ME!
216 public static synchronized void addInternalFrame(final JInternalFrame frame,
217 String title, int w, int h)
219 addInternalFrame(frame, title, w, h, true);
225 * @param frame DOCUMENT ME!
226 * @param title DOCUMENT ME!
227 * @param w DOCUMENT ME!
228 * @param h DOCUMENT ME!
229 * @param resizable DOCUMENT ME!
231 public static synchronized void addInternalFrame(final JInternalFrame frame,
232 String title, int w, int h, boolean resizable)
235 frame.setTitle(title);
236 if (frame.getWidth() < 1 || frame.getHeight() < 1)
240 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
241 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
242 // IF JALVIEW IS RUNNING HEADLESS
243 /////////////////////////////////////////////////
244 if (System.getProperty("java.awt.headless") != null
245 && System.getProperty("java.awt.headless").equals("true"))
252 frame.setVisible(true);
253 frame.setClosable(true);
254 frame.setResizable(resizable);
255 frame.setMaximizable(resizable);
256 frame.setIconifiable(resizable);
257 frame.setFrameIcon(null);
259 if (frame.getX() < 1 && frame.getY() < 1)
261 frame.setLocation(xOffset * openFrameCount,
262 yOffset * ( (openFrameCount - 1) % 10) + yOffset);
265 final JMenuItem menuItem = new JMenuItem(title);
266 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
268 public void internalFrameActivated(javax.swing.event.
269 InternalFrameEvent evt)
271 JInternalFrame itf = desktop.getSelectedFrame();
279 public void internalFrameClosed(
280 javax.swing.event.InternalFrameEvent evt)
282 PaintRefresher.RemoveComponent(frame);
284 windowMenu.remove(menuItem);
285 JInternalFrame itf = desktop.getSelectedFrame();
295 menuItem.addActionListener(new ActionListener()
297 public void actionPerformed(ActionEvent e)
301 frame.setSelected(true);
302 frame.setIcon(false);
304 catch (java.beans.PropertyVetoException ex)
311 windowMenu.add(menuItem);
317 frame.setSelected(true);
318 frame.requestFocus();
320 catch (java.beans.PropertyVetoException ve)
324 public void lostOwnership(Clipboard clipboard, Transferable contents)
328 Desktop.jalviewClipboard = null;
331 internalCopy = false;
334 public void dragEnter(DropTargetDragEvent evt)
337 public void dragExit(DropTargetEvent evt)
340 public void dragOver(DropTargetDragEvent evt)
343 public void dropActionChanged(DropTargetDragEvent evt)
349 * @param evt DOCUMENT ME!
351 public void drop(DropTargetDropEvent evt)
353 Transferable t = evt.getTransferable();
354 java.util.List files = null;
358 DataFlavor uriListFlavor = new DataFlavor(
359 "text/uri-list;class=java.lang.String");
360 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
362 //Works on Windows and MacOSX
363 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
364 files = (java.util.List) t.getTransferData(DataFlavor.
367 else if (t.isDataFlavorSupported(uriListFlavor))
369 // This is used by Unix drag system
370 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
371 String data = (String) t.getTransferData(uriListFlavor);
372 files = new java.util.ArrayList(1);
373 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
376 st.hasMoreTokens(); )
378 String s = st.nextToken();
379 if (s.startsWith("#"))
381 // the line is a comment (as per the RFC 2483)
385 java.net.URI uri = new java.net.URI(s);
386 java.io.File file = new java.io.File(uri);
398 for (int i = 0; i < files.size(); i++)
400 String file = files.get(i).toString();
401 String protocol = FormatAdapter.FILE;
402 String format = null;
404 if (file.endsWith(".jar"))
411 format = new IdentifyFile().Identify(file,
415 new FileLoader().LoadFile(file, protocol, format);
427 * @param e DOCUMENT ME!
429 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
431 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
436 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
441 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
442 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
444 chooser.setFileView(new JalviewFileView());
445 chooser.setDialogTitle("Open local file");
446 chooser.setToolTipText("Open");
448 int value = chooser.showOpenDialog(this);
450 if (value == JalviewFileChooser.APPROVE_OPTION)
452 String choice = chooser.getSelectedFile().getPath();
453 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
454 chooser.getSelectedFile().getParent());
456 String format = null;
457 if (chooser.getSelectedFormat().equals("Jalview"))
463 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
466 if (viewport != null)
468 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
472 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
480 * @param e DOCUMENT ME!
482 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
484 // This construct allows us to have a wider textfield
486 JLabel label = new JLabel("Enter URL of Input File");
487 final JComboBox history = new JComboBox();
489 JPanel panel = new JPanel(new GridLayout(2, 1));
492 history.setPreferredSize(new Dimension(400, 20));
493 history.setEditable(true);
494 history.addItem("http://www.");
496 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
500 if (historyItems != null)
502 st = new StringTokenizer(historyItems, "\t");
504 while (st.hasMoreTokens())
506 history.addItem(st.nextElement());
510 int reply = JOptionPane.showInternalConfirmDialog(desktop,
511 panel, "Input Alignment From URL",
512 JOptionPane.OK_CANCEL_OPTION);
514 if (reply != JOptionPane.OK_OPTION)
519 String url = history.getSelectedItem().toString();
521 if (url.toLowerCase().endsWith(".jar"))
523 if (viewport != null)
525 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
529 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
534 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
536 if (format.equals("URL NOT FOUND"))
538 JOptionPane.showInternalMessageDialog(Desktop.desktop,
539 "Couldn't locate " + url,
541 JOptionPane.WARNING_MESSAGE);
546 if (viewport != null)
548 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
552 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
560 * @param e DOCUMENT ME!
562 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
564 CutAndPasteTransfer cap = new CutAndPasteTransfer();
565 cap.setForInput(viewport);
566 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
574 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
575 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
576 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
577 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
584 * @param e DOCUMENT ME!
586 public void aboutMenuItem_actionPerformed(ActionEvent e)
588 StringBuffer message = new StringBuffer("JalView version " +
589 jalview.bin.Cache.getProperty(
593 Cache.getDefault("BUILD_DATE",
596 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
597 jalview.bin.Cache.getProperty("VERSION")))
599 message.append("\n\n!! Jalview version "
600 + jalview.bin.Cache.getProperty("LATEST_VERSION")
602 " is available for download from http://www.jalview.org !!\n");
606 message.append("\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
607 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
608 "\nFor all issues relating to Jalview, email help@jalview.org" +
609 "\n\nIf you use JalView, please cite:" +
610 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
611 "\nBioinformatics, 2004 20;426-7.");
613 JOptionPane.showInternalMessageDialog(Desktop.desktop,
615 message.toString(), "About Jalview",
616 JOptionPane.INFORMATION_MESSAGE);
622 * @param e DOCUMENT ME!
624 public void documentationMenuItem_actionPerformed(ActionEvent e)
628 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
629 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
630 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
632 javax.help.HelpBroker hb = hs.createHelpBroker();
633 hb.setCurrentID("home");
634 hb.setDisplayed(true);
640 public void closeAll_actionPerformed(ActionEvent e)
642 JInternalFrame[] frames = desktop.getAllFrames();
643 for (int i = 0; i < frames.length; i++)
647 frames[i].setClosed(true);
649 catch (java.beans.PropertyVetoException ex)
652 System.out.println("ALL CLOSED");
656 public void raiseRelated_actionPerformed(ActionEvent e)
658 reorderAssociatedWindows(false, false);
661 public void minimizeAssociated_actionPerformed(ActionEvent e)
663 reorderAssociatedWindows(true, false);
666 void closeAssociatedWindows()
668 reorderAssociatedWindows(false, true);
671 void reorderAssociatedWindows(boolean minimize, boolean close)
673 JInternalFrame[] frames = desktop.getAllFrames();
674 if (frames == null || frames.length < 1)
679 AlignViewport source = null, target = null;
680 if (frames[0] instanceof AlignFrame)
682 source = ( (AlignFrame) frames[0]).getCurrentView();
684 else if (frames[0] instanceof TreePanel)
686 source = ( (TreePanel) frames[0]).getViewPort();
688 else if (frames[0] instanceof PCAPanel)
690 source = ( (PCAPanel) frames[0]).av;
692 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
694 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
699 for (int i = 0; i < frames.length; i++)
702 if (frames[i] == null)
706 if (frames[i] instanceof AlignFrame)
708 target = ( (AlignFrame) frames[i]).getCurrentView();
710 else if (frames[i] instanceof TreePanel)
712 target = ( (TreePanel) frames[i]).getViewPort();
714 else if (frames[i] instanceof PCAPanel)
716 target = ( (PCAPanel) frames[i]).av;
718 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
720 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
723 if (source == target)
729 frames[i].setClosed(true);
733 frames[i].setIcon(minimize);
741 catch (java.beans.PropertyVetoException ex)
751 * @param e DOCUMENT ME!
753 protected void preferences_actionPerformed(ActionEvent e)
761 * @param e DOCUMENT ME!
763 public void saveState_actionPerformed(ActionEvent e)
765 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
767 "LAST_DIRECTORY"), new String[]
770 {"Jalview Project"}, "Jalview Project");
772 chooser.setFileView(new JalviewFileView());
773 chooser.setDialogTitle("Save State");
775 int value = chooser.showSaveDialog(this);
777 if (value == JalviewFileChooser.APPROVE_OPTION)
779 java.io.File choice = chooser.getSelectedFile();
780 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
781 new Jalview2XML().SaveState(choice);
788 * @param e DOCUMENT ME!
790 public void loadState_actionPerformed(ActionEvent e)
792 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
794 "LAST_DIRECTORY"), new String[]
797 {"Jalview Project"}, "Jalview Project");
798 chooser.setFileView(new JalviewFileView());
799 chooser.setDialogTitle("Restore state");
801 int value = chooser.showOpenDialog(this);
803 if (value == JalviewFileChooser.APPROVE_OPTION)
805 String choice = chooser.getSelectedFile().getAbsolutePath();
806 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
807 chooser.getSelectedFile().getParent());
808 new Jalview2XML().LoadJalviewAlign(choice);
812 /* public void vamsasLoad_actionPerformed(ActionEvent e)
814 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
815 getProperty("LAST_DIRECTORY"));
817 chooser.setFileView(new JalviewFileView());
818 chooser.setDialogTitle("Load Vamsas file");
819 chooser.setToolTipText("Import");
821 int value = chooser.showOpenDialog(this);
823 if (value == JalviewFileChooser.APPROVE_OPTION)
825 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
827 chooser.getSelectedFile().getAbsolutePath()
834 public void inputSequence_actionPerformed(ActionEvent e)
836 new SequenceFetcher(null);
839 JPanel progressPanel;
841 public void startLoading(final String fileName)
843 if (fileLoadingCount == 0)
845 progressPanel = new JPanel(new BorderLayout());
846 JProgressBar progressBar = new JProgressBar();
847 progressBar.setIndeterminate(true);
849 progressPanel.add(new JLabel("Loading File: " + fileName + " "),
852 progressPanel.add(progressBar, BorderLayout.CENTER);
854 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
860 public void stopLoading()
863 if (fileLoadingCount < 1)
865 if (progressPanel != null)
867 this.getContentPane().remove(progressPanel);
868 progressPanel = null;
870 fileLoadingCount = 0;
875 public static int getViewCount(String viewId)
878 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
879 for (int t = 0; t < frames.length; t++)
881 if (frames[t] instanceof AlignFrame)
883 AlignFrame af = (AlignFrame) frames[t];
884 for (int a = 0; a < af.alignPanels.size(); a++)
887 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
900 public void explodeViews(AlignFrame af)
902 int size = af.alignPanels.size();
908 for (int i = 0; i < size; i++)
910 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
911 AlignFrame newaf = new AlignFrame(ap);
912 if (ap.av.explodedPosition != null &&
913 !ap.av.explodedPosition.equals(af.getBounds()))
915 newaf.setBounds(ap.av.explodedPosition);
918 ap.av.gatherViewsHere = false;
920 addInternalFrame(newaf, af.getTitle(),
921 AlignFrame.DEFAULT_WIDTH,
922 AlignFrame.DEFAULT_HEIGHT);
925 af.alignPanels.clear();
926 af.closeMenuItem_actionPerformed(true);
930 public void gatherViews(AlignFrame source)
932 source.viewport.gatherViewsHere = true;
933 source.viewport.explodedPosition = source.getBounds();
934 JInternalFrame[] frames = desktop.getAllFrames();
935 String viewId = source.viewport.sequenceSetID;
937 for (int t = 0; t < frames.length; t++)
939 if (frames[t] instanceof AlignFrame && frames[t] != source)
941 AlignFrame af = (AlignFrame) frames[t];
942 boolean gatherThis = false;
943 for (int a = 0; a < af.alignPanels.size(); a++)
945 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
946 if (viewId.equals(ap.av.getSequenceSetId()))
949 ap.av.gatherViewsHere = false;
950 ap.av.explodedPosition = af.getBounds();
951 source.addAlignmentPanel(ap, false);
957 af.alignPanels.clear();
958 af.closeMenuItem_actionPerformed(true);
965 jalview.gui.VamsasClient v_client = null;
966 public void vamsasLoad_actionPerformed(ActionEvent e)
968 if (v_client == null)
971 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
972 getProperty("LAST_DIRECTORY"));
974 chooser.setFileView(new JalviewFileView());
975 chooser.setDialogTitle("Load Vamsas file");
976 chooser.setToolTipText("Import");
978 int value = chooser.showOpenDialog(this);
980 if (value == JalviewFileChooser.APPROVE_OPTION)
982 v_client = new jalview.gui.VamsasClient(this,
983 chooser.getSelectedFile());
984 this.vamsasLoad.setText("Session Update");
985 this.vamsasStop.setVisible(true);
986 v_client.initial_update();
987 v_client.startWatcher();
992 // store current data in session.
993 v_client.push_update();
997 public void vamsasStop_actionPerformed(ActionEvent e)
999 if (v_client != null)
1001 v_client.end_session();
1003 this.vamsasStop.setVisible(false);
1004 this.vamsasLoad.setText("Start Vamsas Session...");
1009 * hide vamsas user gui bits when a vamsas document event is being handled.
1010 * @param b true to hide gui, false to reveal gui
1012 public void setVamsasUpdate(boolean b)
1014 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
1015 (b ? "in progress" : "finished"));
1016 vamsasLoad.setVisible(!b);
1017 vamsasStop.setVisible(!b);
1021 public JInternalFrame[] getAllFrames()
1023 return desktop.getAllFrames();
1028 * Checks the given url to see if it gives a response indicating that
1029 * the user should be informed of a new questionnaire.
1032 public void checkForQuestionnaire(String url)
1034 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1035 javax.swing.SwingUtilities.invokeLater(jvq);
1039 class MyDesktopPane extends JDesktopPane implements Runnable
1041 boolean showMemoryUsage = false;
1043 java.text.NumberFormat df;
1045 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1047 public MyDesktopPane(boolean showMemoryUsage)
1049 showMemoryUsage(showMemoryUsage);
1052 public void showMemoryUsage(boolean showMemoryUsage)
1054 this.showMemoryUsage = showMemoryUsage;
1055 if (showMemoryUsage)
1057 Thread worker = new Thread(this);
1064 df = java.text.NumberFormat.getNumberInstance();
1065 df.setMaximumFractionDigits(2);
1066 runtime = Runtime.getRuntime();
1068 while (showMemoryUsage)
1073 maxMemory = runtime.maxMemory() / 1048576f;
1074 allocatedMemory = runtime.totalMemory() / 1048576f;
1075 freeMemory = runtime.freeMemory() / 1048576f;
1076 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1078 percentUsage = (totalFreeMemory / maxMemory) * 100;
1080 // if (percentUsage < 20)
1082 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1083 // instance.set.setBorder(border1);
1088 catch (Exception ex)
1090 ex.printStackTrace();
1095 public void paintComponent(Graphics g)
1099 if (percentUsage < 20)
1100 g.setColor(Color.red);
1102 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1103 + "MB; Max Memory: " + df.format(maxMemory)
1104 + "MB; " + df.format(percentUsage) + "%", 10,
1105 getHeight() - g.getFontMetrics().getHeight());
1109 protected JMenuItem groovyShell;
1110 public void doGroovyCheck() {
1111 if (jalview.bin.Cache.groovyJarsPresent())
1113 groovyShell = new JMenuItem();
1114 groovyShell.setText("Groovy Shell...");
1115 groovyShell.addActionListener(new ActionListener()
1117 public void actionPerformed(ActionEvent e) {
1118 groovyShell_actionPerformed(e);
1121 toolsMenu.add(groovyShell);
1122 groovyShell.setVisible(true);
1126 * Accessor method to quickly get all the AlignmentFrames
1129 protected AlignFrame[] getAlignframes() {
1130 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1136 Vector avp=new Vector();
1140 for (int i = frames.length - 1; i > -1; i--)
1142 if (frames[i] instanceof AlignFrame)
1144 AlignFrame af = (AlignFrame) frames[i];
1149 catch (Exception ex)
1151 ex.printStackTrace();
1157 AlignFrame afs[] = new AlignFrame[avp.size()];
1158 for (int i=0,j=avp.size(); i<j; i++) {
1159 afs[i] = (AlignFrame) avp.elementAt(i);
1166 * Add Groovy Support to Jalview
1168 public void groovyShell_actionPerformed(ActionEvent e) {
1169 // use reflection to avoid creating compilation dependency.
1170 if (!jalview.bin.Cache.groovyJarsPresent())
1172 throw new Error("Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1175 Class gcClass = Desktop.class.getClassLoader().loadClass("groovy.ui.Console");
1176 Constructor gccons = gcClass.getConstructor(null);
1177 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", new Class[] { String.class, Object.class} );
1178 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1179 Object gc = gccons.newInstance(null);
1180 setvar.invoke(gc, new Object[] { "Jalview", this});
1181 run.invoke(gc, null);
1183 catch (Exception ex)
1185 jalview.bin.Cache.log.error("Groovy Shell Creation failed.",ex);
1186 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1188 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.", "Jalview Groovy Support Failed",
1189 JOptionPane.ERROR_MESSAGE);