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;
30 import javax.swing.event.MenuEvent;
31 import javax.swing.event.MenuListener;
40 extends jalview.jbgui.GDesktop implements DropTargetListener,
44 public static Desktop instance;
46 //Need to decide if the Memory Usage is to be included in
47 //Next release or not.
48 // public static MyDesktopPane desktop;
49 public static JDesktopPane desktop;
52 static int openFrameCount = 0;
53 static final int xOffset = 30;
54 static final int yOffset = 30;
55 public static jalview.ws.Discoverer discoverer;
57 public static Object[] jalviewClipboard;
58 public static boolean internalCopy = false;
60 static int fileLoadingCount = 0;
63 * Creates a new Desktop object.
68 doVamsasClientCheck();
72 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
73 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
75 desktop = new JDesktopPane();
76 desktop.setBackground(Color.white);
77 getContentPane().setLayout(new BorderLayout());
78 getContentPane().add(desktop, BorderLayout.CENTER);
79 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
81 // This line prevents Windows Look&Feel resizing all new windows to maximum
82 // if previous window was maximised
83 desktop.setDesktopManager(new DefaultDesktopManager());
85 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
86 String x = jalview.bin.Cache.getProperty("SCREEN_X");
87 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
88 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
89 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
91 if ( (x != null) && (y != null) && (width != null) && (height != null))
93 setBounds(Integer.parseInt(x), Integer.parseInt(y),
94 Integer.parseInt(width), Integer.parseInt(height));
98 setBounds( (int) (screenSize.width - 900) / 2,
99 (int) (screenSize.height - 650) / 2, 900, 650);
102 this.addWindowListener(new WindowAdapter()
104 public void windowClosing(WindowEvent evt)
110 this.addMouseListener(new MouseAdapter()
112 public void mousePressed(MouseEvent evt)
114 if(SwingUtilities.isRightMouseButton(evt))
116 showPasteMenu(evt.getX(), evt.getY());
122 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
124 /////////Add a splashscreen on startup
125 /////////Add a splashscreen on startup
129 discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
132 private void doVamsasClientCheck()
134 if (jalview.bin.Cache.vamsasJarsPresent())
136 setupVamsasDisconnectedGui();
137 VamsasMenu.setVisible(true);
138 final Desktop us = this;
139 VamsasMenu.addMenuListener(new MenuListener() {
140 // this listener remembers when the menu was first selected, and
141 // doesn't rebuild the session list until it has been cleared and
143 boolean refresh=true;
144 public void menuCanceled(MenuEvent e)
149 public void menuDeselected(MenuEvent e)
154 public void menuSelected(MenuEvent e)
158 us.buildVamsasStMenu();
163 vamsasStart.setVisible(true);
167 void showPasteMenu(int x, int y)
169 JPopupMenu popup = new JPopupMenu();
170 JMenuItem item = new JMenuItem("Paste To New Window");
171 item.addActionListener(new ActionListener()
173 public void actionPerformed(ActionEvent evt)
180 popup.show(this, x, y);
187 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
188 Transferable contents = c.getContents(this);
190 if (contents != null)
192 String file = (String) contents
193 .getTransferData(DataFlavor.stringFlavor);
195 String format = new IdentifyFile().Identify(file,
196 FormatAdapter.PASTE);
198 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
204 System.out.println("Unable to paste alignment from system clipboard:\n"
212 * @param frame DOCUMENT ME!
213 * @param title DOCUMENT ME!
214 * @param w DOCUMENT ME!
215 * @param h DOCUMENT ME!
217 public static synchronized void addInternalFrame(final JInternalFrame frame,
218 String title, int w, int h)
220 addInternalFrame(frame, title, w, h, true);
226 * @param frame DOCUMENT ME!
227 * @param title DOCUMENT ME!
228 * @param w DOCUMENT ME!
229 * @param h DOCUMENT ME!
230 * @param resizable DOCUMENT ME!
232 public static synchronized void addInternalFrame(final JInternalFrame frame,
233 String title, int w, int h, boolean resizable)
236 frame.setTitle(title);
237 if (frame.getWidth() < 1 || frame.getHeight() < 1)
241 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
242 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
243 // IF JALVIEW IS RUNNING HEADLESS
244 /////////////////////////////////////////////////
245 if (System.getProperty("java.awt.headless") != null
246 && System.getProperty("java.awt.headless").equals("true"))
253 frame.setVisible(true);
254 frame.setClosable(true);
255 frame.setResizable(resizable);
256 frame.setMaximizable(resizable);
257 frame.setIconifiable(resizable);
258 frame.setFrameIcon(null);
260 if (frame.getX() < 1 && frame.getY() < 1)
262 frame.setLocation(xOffset * openFrameCount,
263 yOffset * ( (openFrameCount - 1) % 10) + yOffset);
266 final JMenuItem menuItem = new JMenuItem(title);
267 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
269 public void internalFrameActivated(javax.swing.event.
270 InternalFrameEvent evt)
272 JInternalFrame itf = desktop.getSelectedFrame();
280 public void internalFrameClosed(
281 javax.swing.event.InternalFrameEvent evt)
283 PaintRefresher.RemoveComponent(frame);
285 windowMenu.remove(menuItem);
286 JInternalFrame itf = desktop.getSelectedFrame();
296 menuItem.addActionListener(new ActionListener()
298 public void actionPerformed(ActionEvent e)
302 frame.setSelected(true);
303 frame.setIcon(false);
305 catch (java.beans.PropertyVetoException ex)
312 windowMenu.add(menuItem);
318 frame.setSelected(true);
319 frame.requestFocus();
321 catch (java.beans.PropertyVetoException ve)
325 public void lostOwnership(Clipboard clipboard, Transferable contents)
329 Desktop.jalviewClipboard = null;
332 internalCopy = false;
335 public void dragEnter(DropTargetDragEvent evt)
338 public void dragExit(DropTargetEvent evt)
341 public void dragOver(DropTargetDragEvent evt)
344 public void dropActionChanged(DropTargetDragEvent evt)
350 * @param evt DOCUMENT ME!
352 public void drop(DropTargetDropEvent evt)
354 Transferable t = evt.getTransferable();
355 java.util.List files = null;
359 DataFlavor uriListFlavor = new DataFlavor(
360 "text/uri-list;class=java.lang.String");
361 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
363 //Works on Windows and MacOSX
364 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
365 files = (java.util.List) t.getTransferData(DataFlavor.
368 else if (t.isDataFlavorSupported(uriListFlavor))
370 // This is used by Unix drag system
371 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
372 String data = (String) t.getTransferData(uriListFlavor);
373 files = new java.util.ArrayList(1);
374 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
377 st.hasMoreTokens(); )
379 String s = st.nextToken();
380 if (s.startsWith("#"))
382 // the line is a comment (as per the RFC 2483)
386 java.net.URI uri = new java.net.URI(s);
387 java.io.File file = new java.io.File(uri);
399 for (int i = 0; i < files.size(); i++)
401 String file = files.get(i).toString();
402 String protocol = FormatAdapter.FILE;
403 String format = null;
405 if (file.endsWith(".jar"))
412 format = new IdentifyFile().Identify(file,
416 new FileLoader().LoadFile(file, protocol, format);
428 * @param e DOCUMENT ME!
430 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
432 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
437 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
442 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
443 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
445 chooser.setFileView(new JalviewFileView());
446 chooser.setDialogTitle("Open local file");
447 chooser.setToolTipText("Open");
449 int value = chooser.showOpenDialog(this);
451 if (value == JalviewFileChooser.APPROVE_OPTION)
453 String choice = chooser.getSelectedFile().getPath();
454 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
455 chooser.getSelectedFile().getParent());
457 String format = null;
458 if (chooser.getSelectedFormat().equals("Jalview"))
464 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
467 if (viewport != null)
469 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
473 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
481 * @param e DOCUMENT ME!
483 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
485 // This construct allows us to have a wider textfield
487 JLabel label = new JLabel("Enter URL of Input File");
488 final JComboBox history = new JComboBox();
490 JPanel panel = new JPanel(new GridLayout(2, 1));
493 history.setPreferredSize(new Dimension(400, 20));
494 history.setEditable(true);
495 history.addItem("http://www.");
497 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
501 if (historyItems != null)
503 st = new StringTokenizer(historyItems, "\t");
505 while (st.hasMoreTokens())
507 history.addItem(st.nextElement());
511 int reply = JOptionPane.showInternalConfirmDialog(desktop,
512 panel, "Input Alignment From URL",
513 JOptionPane.OK_CANCEL_OPTION);
515 if (reply != JOptionPane.OK_OPTION)
520 String url = history.getSelectedItem().toString();
522 if (url.toLowerCase().endsWith(".jar"))
524 if (viewport != null)
526 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
530 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
535 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
537 if (format.equals("URL NOT FOUND"))
539 JOptionPane.showInternalMessageDialog(Desktop.desktop,
540 "Couldn't locate " + url,
542 JOptionPane.WARNING_MESSAGE);
547 if (viewport != null)
549 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
553 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
561 * @param e DOCUMENT ME!
563 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
565 CutAndPasteTransfer cap = new CutAndPasteTransfer();
566 cap.setForInput(viewport);
567 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
575 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
576 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
577 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
578 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
585 * @param e DOCUMENT ME!
587 public void aboutMenuItem_actionPerformed(ActionEvent e)
589 StringBuffer message = new StringBuffer("JalView version " +
590 jalview.bin.Cache.getProperty(
594 Cache.getDefault("BUILD_DATE",
597 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
598 jalview.bin.Cache.getProperty("VERSION")))
600 message.append("\n\n!! Jalview version "
601 + jalview.bin.Cache.getProperty("LATEST_VERSION")
603 " is available for download from http://www.jalview.org !!\n");
607 message.append("\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
608 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
609 "\nFor all issues relating to Jalview, email help@jalview.org" +
610 "\n\nIf you use JalView, please cite:" +
611 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
612 "\nBioinformatics, 2004 20;426-7.");
614 JOptionPane.showInternalMessageDialog(Desktop.desktop,
616 message.toString(), "About Jalview",
617 JOptionPane.INFORMATION_MESSAGE);
623 * @param e DOCUMENT ME!
625 public void documentationMenuItem_actionPerformed(ActionEvent e)
629 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
630 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
631 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
633 javax.help.HelpBroker hb = hs.createHelpBroker();
634 hb.setCurrentID("home");
635 hb.setDisplayed(true);
641 public void closeAll_actionPerformed(ActionEvent e)
643 JInternalFrame[] frames = desktop.getAllFrames();
644 for (int i = 0; i < frames.length; i++)
648 frames[i].setClosed(true);
650 catch (java.beans.PropertyVetoException ex)
653 System.out.println("ALL CLOSED");
657 public void raiseRelated_actionPerformed(ActionEvent e)
659 reorderAssociatedWindows(false, false);
662 public void minimizeAssociated_actionPerformed(ActionEvent e)
664 reorderAssociatedWindows(true, false);
667 void closeAssociatedWindows()
669 reorderAssociatedWindows(false, true);
672 void reorderAssociatedWindows(boolean minimize, boolean close)
674 JInternalFrame[] frames = desktop.getAllFrames();
675 if (frames == null || frames.length < 1)
680 AlignViewport source = null, target = null;
681 if (frames[0] instanceof AlignFrame)
683 source = ( (AlignFrame) frames[0]).getCurrentView();
685 else if (frames[0] instanceof TreePanel)
687 source = ( (TreePanel) frames[0]).getViewPort();
689 else if (frames[0] instanceof PCAPanel)
691 source = ( (PCAPanel) frames[0]).av;
693 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
695 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
700 for (int i = 0; i < frames.length; i++)
703 if (frames[i] == null)
707 if (frames[i] instanceof AlignFrame)
709 target = ( (AlignFrame) frames[i]).getCurrentView();
711 else if (frames[i] instanceof TreePanel)
713 target = ( (TreePanel) frames[i]).getViewPort();
715 else if (frames[i] instanceof PCAPanel)
717 target = ( (PCAPanel) frames[i]).av;
719 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
721 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
724 if (source == target)
730 frames[i].setClosed(true);
734 frames[i].setIcon(minimize);
742 catch (java.beans.PropertyVetoException ex)
752 * @param e DOCUMENT ME!
754 protected void preferences_actionPerformed(ActionEvent e)
762 * @param e DOCUMENT ME!
764 public void saveState_actionPerformed(ActionEvent e)
766 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
768 "LAST_DIRECTORY"), new String[]
771 {"Jalview Project"}, "Jalview Project");
773 chooser.setFileView(new JalviewFileView());
774 chooser.setDialogTitle("Save State");
776 int value = chooser.showSaveDialog(this);
778 if (value == JalviewFileChooser.APPROVE_OPTION)
780 java.io.File choice = chooser.getSelectedFile();
781 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
782 new Jalview2XML().SaveState(choice);
789 * @param e DOCUMENT ME!
791 public void loadState_actionPerformed(ActionEvent e)
793 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
795 "LAST_DIRECTORY"), new String[]
798 {"Jalview Project"}, "Jalview Project");
799 chooser.setFileView(new JalviewFileView());
800 chooser.setDialogTitle("Restore state");
802 int value = chooser.showOpenDialog(this);
804 if (value == JalviewFileChooser.APPROVE_OPTION)
806 String choice = chooser.getSelectedFile().getAbsolutePath();
807 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
808 chooser.getSelectedFile().getParent());
809 new Jalview2XML().LoadJalviewAlign(choice);
813 public void inputSequence_actionPerformed(ActionEvent e)
815 new SequenceFetcher(null);
818 JPanel progressPanel;
820 public void startLoading(final String fileName)
822 if (fileLoadingCount == 0)
824 progressPanel = new JPanel(new BorderLayout());
825 JProgressBar progressBar = new JProgressBar();
826 progressBar.setIndeterminate(true);
828 progressPanel.add(new JLabel("Loading File: " + fileName + " "),
831 progressPanel.add(progressBar, BorderLayout.CENTER);
833 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
839 public void stopLoading()
842 if (fileLoadingCount < 1)
844 if (progressPanel != null)
846 this.getContentPane().remove(progressPanel);
847 progressPanel = null;
849 fileLoadingCount = 0;
854 public static int getViewCount(String viewId)
857 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
858 for (int t = 0; t < frames.length; t++)
860 if (frames[t] instanceof AlignFrame)
862 AlignFrame af = (AlignFrame) frames[t];
863 for (int a = 0; a < af.alignPanels.size(); a++)
866 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
879 public void explodeViews(AlignFrame af)
881 int size = af.alignPanels.size();
887 for (int i = 0; i < size; i++)
889 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
890 AlignFrame newaf = new AlignFrame(ap);
891 if (ap.av.explodedPosition != null &&
892 !ap.av.explodedPosition.equals(af.getBounds()))
894 newaf.setBounds(ap.av.explodedPosition);
897 ap.av.gatherViewsHere = false;
899 addInternalFrame(newaf, af.getTitle(),
900 AlignFrame.DEFAULT_WIDTH,
901 AlignFrame.DEFAULT_HEIGHT);
904 af.alignPanels.clear();
905 af.closeMenuItem_actionPerformed(true);
909 public void gatherViews(AlignFrame source)
911 source.viewport.gatherViewsHere = true;
912 source.viewport.explodedPosition = source.getBounds();
913 JInternalFrame[] frames = desktop.getAllFrames();
914 String viewId = source.viewport.sequenceSetID;
916 for (int t = 0; t < frames.length; t++)
918 if (frames[t] instanceof AlignFrame && frames[t] != source)
920 AlignFrame af = (AlignFrame) frames[t];
921 boolean gatherThis = false;
922 for (int a = 0; a < af.alignPanels.size(); a++)
924 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
925 if (viewId.equals(ap.av.getSequenceSetId()))
928 ap.av.gatherViewsHere = false;
929 ap.av.explodedPosition = af.getBounds();
930 source.addAlignmentPanel(ap, false);
936 af.alignPanels.clear();
937 af.closeMenuItem_actionPerformed(true);
944 jalview.gui.VamsasApplication v_client = null;
945 public void vamsasImport_actionPerformed(ActionEvent e)
949 // Load and try to start a session.
950 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
951 getProperty("LAST_DIRECTORY"));
953 chooser.setFileView(new JalviewFileView());
954 chooser.setDialogTitle("Open a saved VAMSAS session");
955 chooser.setToolTipText("select a vamsas session to be opened as a new vamsas session.");
957 int value = chooser.showOpenDialog(this);
959 if (value == JalviewFileChooser.APPROVE_OPTION)
962 v_client = new jalview.gui.VamsasApplication(this,
963 chooser.getSelectedFile());
964 } catch (Exception ex)
966 jalview.bin.Cache.log.error("New vamsas session from existing session file failed:",ex);
969 setupVamsasConnectedGui();
970 v_client.initial_update(); // TODO: thread ?
973 jalview.bin.Cache.log.error("Implementation error - load session from a running session is not supported.");
977 public void vamsasStart_actionPerformed(ActionEvent e)
979 if (v_client == null)
982 // we just start a default session for moment.
984 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
985 getProperty("LAST_DIRECTORY"));
987 chooser.setFileView(new JalviewFileView());
988 chooser.setDialogTitle("Load Vamsas file");
989 chooser.setToolTipText("Import");
991 int value = chooser.showOpenDialog(this);
993 if (value == JalviewFileChooser.APPROVE_OPTION)
995 v_client = new jalview.gui.VamsasApplication(this,
996 chooser.getSelectedFile());
999 v_client = new VamsasApplication(this);
1000 setupVamsasConnectedGui();
1001 v_client.initial_update(); // TODO: thread ?
1005 // store current data in session.
1006 v_client.push_update(); // TODO: thread
1010 protected void setupVamsasConnectedGui()
1012 vamsasStart.setText("Session Update");
1013 vamsasSave.setVisible(true);
1014 vamsasStop.setVisible(true);
1015 vamsasImport.setVisible(false); // Document import to existing session is not possible for vamsas-client-1.0.
1017 protected void setupVamsasDisconnectedGui()
1019 vamsasSave.setVisible(false);
1020 vamsasStop.setVisible(false);
1021 vamsasImport.setVisible(true);
1022 vamsasStart.setText("New Vamsas Session...");
1025 public void vamsasStop_actionPerformed(ActionEvent e)
1027 if (v_client != null)
1029 v_client.end_session();
1031 setupVamsasDisconnectedGui();
1034 protected void buildVamsasStMenu()
1036 if (v_client == null)
1038 String[] sess = null;
1041 sess = VamsasApplication.getSessionList();
1042 } catch (Exception e)
1044 jalview.bin.Cache.log.warn(
1045 "Problem getting current sessions list.", e);
1050 jalview.bin.Cache.log.debug("Got current sessions list: "
1051 + sess.length + " entries.");
1052 VamsasStMenu.removeAll();
1053 for (int i = 0; i < sess.length; i++)
1055 JMenuItem sessit = new JMenuItem();
1056 sessit.setText(sess[i]);
1057 sessit.setToolTipText("Connect to session " + sess[i]);
1058 final Desktop dsktp = this;
1059 final String mysesid = sess[i];
1060 sessit.addActionListener(new ActionListener()
1063 public void actionPerformed(ActionEvent e)
1065 if (dsktp.v_client == null)
1067 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1068 dsktp.setupVamsasConnectedGui();
1069 dsktp.v_client.initial_update();
1073 VamsasStMenu.add(sessit);
1075 VamsasStMenu.setVisible(true);
1079 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1080 VamsasStMenu.removeAll();
1081 VamsasStMenu.setVisible(false);
1084 // Not interested in the content. Just hide ourselves.
1085 VamsasStMenu.setVisible(false);
1088 public void vamsasSave_actionPerformed(ActionEvent e)
1090 if (v_client != null)
1092 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1094 "LAST_DIRECTORY"), new String[]
1095 {"vdj"}, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1097 {"Vamsas Document"}, "Vamsas Document");
1099 chooser.setFileView(new JalviewFileView());
1100 chooser.setDialogTitle("Save Vamsas Document Archive");
1102 int value = chooser.showSaveDialog(this);
1104 if (value == JalviewFileChooser.APPROVE_OPTION)
1106 java.io.File choice = chooser.getSelectedFile();
1107 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1108 String warnmsg=null;
1109 String warnttl=null;
1111 v_client.vclient.storeDocument(choice);
1115 warnttl = "Serious Problem saving Vamsas Document";
1116 warnmsg = ex.toString();
1117 jalview.bin.Cache.log.error("Error Whilst saving document to "+choice,ex);
1120 catch (Exception ex)
1122 warnttl = "Problem saving Vamsas Document.";
1123 warnmsg = ex.toString();
1124 jalview.bin.Cache.log.warn("Exception Whilst saving document to "+choice,ex);
1129 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1132 JOptionPane.ERROR_MESSAGE);
1138 * hide vamsas user gui bits when a vamsas document event is being handled.
1139 * @param b true to hide gui, false to reveal gui
1141 public void setVamsasUpdate(boolean b)
1143 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
1144 (b ? "in progress" : "finished"));
1145 vamsasStart.setVisible(!b);
1146 vamsasStop.setVisible(!b);
1147 vamsasSave.setVisible(!b);
1150 public JInternalFrame[] getAllFrames()
1152 return desktop.getAllFrames();
1157 * Checks the given url to see if it gives a response indicating that
1158 * the user should be informed of a new questionnaire.
1161 public void checkForQuestionnaire(String url)
1163 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1164 javax.swing.SwingUtilities.invokeLater(jvq);
1168 class MyDesktopPane extends JDesktopPane implements Runnable
1170 boolean showMemoryUsage = false;
1172 java.text.NumberFormat df;
1174 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1176 public MyDesktopPane(boolean showMemoryUsage)
1178 showMemoryUsage(showMemoryUsage);
1181 public void showMemoryUsage(boolean showMemoryUsage)
1183 this.showMemoryUsage = showMemoryUsage;
1184 if (showMemoryUsage)
1186 Thread worker = new Thread(this);
1193 df = java.text.NumberFormat.getNumberInstance();
1194 df.setMaximumFractionDigits(2);
1195 runtime = Runtime.getRuntime();
1197 while (showMemoryUsage)
1202 maxMemory = runtime.maxMemory() / 1048576f;
1203 allocatedMemory = runtime.totalMemory() / 1048576f;
1204 freeMemory = runtime.freeMemory() / 1048576f;
1205 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1207 percentUsage = (totalFreeMemory / maxMemory) * 100;
1209 // if (percentUsage < 20)
1211 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1212 // instance.set.setBorder(border1);
1217 catch (Exception ex)
1219 ex.printStackTrace();
1224 public void paintComponent(Graphics g)
1228 if (percentUsage < 20)
1229 g.setColor(Color.red);
1231 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1232 + "MB; Max Memory: " + df.format(maxMemory)
1233 + "MB; " + df.format(percentUsage) + "%", 10,
1234 getHeight() - g.getFontMetrics().getHeight());
1238 protected JMenuItem groovyShell;
1239 public void doGroovyCheck() {
1240 if (jalview.bin.Cache.groovyJarsPresent())
1242 groovyShell = new JMenuItem();
1243 groovyShell.setText("Groovy Shell...");
1244 groovyShell.addActionListener(new ActionListener()
1246 public void actionPerformed(ActionEvent e) {
1247 groovyShell_actionPerformed(e);
1250 toolsMenu.add(groovyShell);
1251 groovyShell.setVisible(true);
1255 * Accessor method to quickly get all the AlignmentFrames
1258 protected AlignFrame[] getAlignframes() {
1259 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1265 Vector avp=new Vector();
1269 for (int i = frames.length - 1; i > -1; i--)
1271 if (frames[i] instanceof AlignFrame)
1273 AlignFrame af = (AlignFrame) frames[i];
1278 catch (Exception ex)
1280 ex.printStackTrace();
1286 AlignFrame afs[] = new AlignFrame[avp.size()];
1287 for (int i=0,j=avp.size(); i<j; i++) {
1288 afs[i] = (AlignFrame) avp.elementAt(i);
1295 * Add Groovy Support to Jalview
1297 public void groovyShell_actionPerformed(ActionEvent e) {
1298 // use reflection to avoid creating compilation dependency.
1299 if (!jalview.bin.Cache.groovyJarsPresent())
1301 throw new Error("Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1304 Class gcClass = Desktop.class.getClassLoader().loadClass("groovy.ui.Console");
1305 Constructor gccons = gcClass.getConstructor(null);
1306 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", new Class[] { String.class, Object.class} );
1307 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1308 Object gc = gccons.newInstance(null);
1309 setvar.invoke(gc, new Object[] { "Jalview", this});
1310 run.invoke(gc, null);
1312 catch (Exception ex)
1314 jalview.bin.Cache.log.error("Groovy Shell Creation failed.",ex);
1315 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1317 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.", "Jalview Groovy Support Failed",
1318 JOptionPane.ERROR_MESSAGE);