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.
435 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
436 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
437 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
439 chooser.setFileView(new JalviewFileView());
440 chooser.setDialogTitle("Open local file");
441 chooser.setToolTipText("Open");
443 int value = chooser.showOpenDialog(this);
445 if (value == JalviewFileChooser.APPROVE_OPTION)
447 String choice = chooser.getSelectedFile().getPath();
448 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
449 chooser.getSelectedFile().getParent());
451 String format = null;
452 if (chooser.getSelectedFormat().equals("Jalview"))
458 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
461 if (viewport != null)
463 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
467 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
475 * @param e DOCUMENT ME!
477 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
479 // This construct allows us to have a wider textfield
481 JLabel label = new JLabel("Enter URL of Input File");
482 final JComboBox history = new JComboBox();
484 JPanel panel = new JPanel(new GridLayout(2, 1));
487 history.setPreferredSize(new Dimension(400, 20));
488 history.setEditable(true);
489 history.addItem("http://www.");
491 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
495 if (historyItems != null)
497 st = new StringTokenizer(historyItems, "\t");
499 while (st.hasMoreTokens())
501 history.addItem(st.nextElement());
505 int reply = JOptionPane.showInternalConfirmDialog(desktop,
506 panel, "Input Alignment From URL",
507 JOptionPane.OK_CANCEL_OPTION);
509 if (reply != JOptionPane.OK_OPTION)
514 String url = history.getSelectedItem().toString();
516 if (url.toLowerCase().endsWith(".jar"))
518 if (viewport != null)
520 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
524 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
529 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
531 if (format.equals("URL NOT FOUND"))
533 JOptionPane.showInternalMessageDialog(Desktop.desktop,
534 "Couldn't locate " + url,
536 JOptionPane.WARNING_MESSAGE);
541 if (viewport != null)
543 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
547 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
555 * @param e DOCUMENT ME!
557 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
559 CutAndPasteTransfer cap = new CutAndPasteTransfer();
560 cap.setForInput(viewport);
561 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
569 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
570 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
571 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
572 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
579 * @param e DOCUMENT ME!
581 public void aboutMenuItem_actionPerformed(ActionEvent e)
583 StringBuffer message = new StringBuffer("JalView version " +
584 jalview.bin.Cache.getProperty(
588 Cache.getDefault("BUILD_DATE",
591 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
592 jalview.bin.Cache.getProperty("VERSION")))
594 message.append("\n\n!! Jalview version "
595 + jalview.bin.Cache.getProperty("LATEST_VERSION")
597 " is available for download from http://www.jalview.org !!\n");
601 message.append("\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
602 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
603 "\nFor all issues relating to Jalview, email help@jalview.org" +
604 "\n\nIf you use JalView, please cite:" +
605 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
606 "\nBioinformatics, 2004 20;426-7.");
608 JOptionPane.showInternalMessageDialog(Desktop.desktop,
610 message.toString(), "About Jalview",
611 JOptionPane.INFORMATION_MESSAGE);
617 * @param e DOCUMENT ME!
619 public void documentationMenuItem_actionPerformed(ActionEvent e)
623 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
624 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
625 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
627 javax.help.HelpBroker hb = hs.createHelpBroker();
628 hb.setCurrentID("home");
629 hb.setDisplayed(true);
635 public void closeAll_actionPerformed(ActionEvent e)
637 JInternalFrame[] frames = desktop.getAllFrames();
638 for (int i = 0; i < frames.length; i++)
642 frames[i].setClosed(true);
644 catch (java.beans.PropertyVetoException ex)
647 System.out.println("ALL CLOSED");
651 public void raiseRelated_actionPerformed(ActionEvent e)
653 reorderAssociatedWindows(false, false);
656 public void minimizeAssociated_actionPerformed(ActionEvent e)
658 reorderAssociatedWindows(true, false);
661 void closeAssociatedWindows()
663 reorderAssociatedWindows(false, true);
666 void reorderAssociatedWindows(boolean minimize, boolean close)
668 JInternalFrame[] frames = desktop.getAllFrames();
669 if (frames == null || frames.length < 1)
674 AlignViewport source = null, target = null;
675 if (frames[0] instanceof AlignFrame)
677 source = ( (AlignFrame) frames[0]).getCurrentView();
679 else if (frames[0] instanceof TreePanel)
681 source = ( (TreePanel) frames[0]).getViewPort();
683 else if (frames[0] instanceof PCAPanel)
685 source = ( (PCAPanel) frames[0]).av;
687 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
689 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
694 for (int i = 0; i < frames.length; i++)
697 if (frames[i] == null)
701 if (frames[i] instanceof AlignFrame)
703 target = ( (AlignFrame) frames[i]).getCurrentView();
705 else if (frames[i] instanceof TreePanel)
707 target = ( (TreePanel) frames[i]).getViewPort();
709 else if (frames[i] instanceof PCAPanel)
711 target = ( (PCAPanel) frames[i]).av;
713 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
715 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
718 if (source == target)
724 frames[i].setClosed(true);
728 frames[i].setIcon(minimize);
736 catch (java.beans.PropertyVetoException ex)
746 * @param e DOCUMENT ME!
748 protected void preferences_actionPerformed(ActionEvent e)
756 * @param e DOCUMENT ME!
758 public void saveState_actionPerformed(ActionEvent e)
760 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
762 "LAST_DIRECTORY"), new String[]
765 {"Jalview Project"}, "Jalview Project");
767 chooser.setFileView(new JalviewFileView());
768 chooser.setDialogTitle("Save State");
770 int value = chooser.showSaveDialog(this);
772 if (value == JalviewFileChooser.APPROVE_OPTION)
774 java.io.File choice = chooser.getSelectedFile();
775 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
776 new Jalview2XML().SaveState(choice);
783 * @param e DOCUMENT ME!
785 public void loadState_actionPerformed(ActionEvent e)
787 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
789 "LAST_DIRECTORY"), new String[]
792 {"Jalview Project"}, "Jalview Project");
793 chooser.setFileView(new JalviewFileView());
794 chooser.setDialogTitle("Restore state");
796 int value = chooser.showOpenDialog(this);
798 if (value == JalviewFileChooser.APPROVE_OPTION)
800 String choice = chooser.getSelectedFile().getAbsolutePath();
801 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
802 chooser.getSelectedFile().getParent());
803 new Jalview2XML().LoadJalviewAlign(choice);
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 addProgressPanel("Loading File: " + fileName + " ");
823 private JProgressBar addProgressPanel(String string)
825 if (progressPanel==null)
827 progressPanel = new JPanel(new BorderLayout());
828 totalProgressCount=0;
830 JProgressBar progressBar = new JProgressBar();
831 progressBar.setIndeterminate(true);
833 progressPanel.add(new JLabel(string),
836 progressPanel.add(progressBar, BorderLayout.CENTER);
838 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
839 totalProgressCount++;
843 int totalProgressCount=0;
844 private void removeProgressPanel(JProgressBar progbar)
846 if (progressPanel!=null)
848 progressPanel.remove(progbar);
849 if (--totalProgressCount<1)
851 this.getContentPane().remove(progressPanel);
852 progressPanel = null;
857 public void stopLoading()
860 if (fileLoadingCount < 1)
862 if (progressPanel != null)
864 this.getContentPane().remove(progressPanel);
865 progressPanel = null;
867 fileLoadingCount = 0;
871 public static int getViewCount(String viewId)
874 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
875 for (int t = 0; t < frames.length; t++)
877 if (frames[t] instanceof AlignFrame)
879 AlignFrame af = (AlignFrame) frames[t];
880 for (int a = 0; a < af.alignPanels.size(); a++)
883 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
896 public void explodeViews(AlignFrame af)
898 int size = af.alignPanels.size();
904 for (int i = 0; i < size; i++)
906 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
907 AlignFrame newaf = new AlignFrame(ap);
908 if (ap.av.explodedPosition != null &&
909 !ap.av.explodedPosition.equals(af.getBounds()))
911 newaf.setBounds(ap.av.explodedPosition);
914 ap.av.gatherViewsHere = false;
916 addInternalFrame(newaf, af.getTitle(),
917 AlignFrame.DEFAULT_WIDTH,
918 AlignFrame.DEFAULT_HEIGHT);
921 af.alignPanels.clear();
922 af.closeMenuItem_actionPerformed(true);
926 public void gatherViews(AlignFrame source)
928 source.viewport.gatherViewsHere = true;
929 source.viewport.explodedPosition = source.getBounds();
930 JInternalFrame[] frames = desktop.getAllFrames();
931 String viewId = source.viewport.sequenceSetID;
933 for (int t = 0; t < frames.length; t++)
935 if (frames[t] instanceof AlignFrame && frames[t] != source)
937 AlignFrame af = (AlignFrame) frames[t];
938 boolean gatherThis = false;
939 for (int a = 0; a < af.alignPanels.size(); a++)
941 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
942 if (viewId.equals(ap.av.getSequenceSetId()))
945 ap.av.gatherViewsHere = false;
946 ap.av.explodedPosition = af.getBounds();
947 source.addAlignmentPanel(ap, false);
953 af.alignPanels.clear();
954 af.closeMenuItem_actionPerformed(true);
961 jalview.gui.VamsasApplication v_client = null;
962 public void vamsasImport_actionPerformed(ActionEvent e)
966 // Load and try to start a session.
967 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
968 getProperty("LAST_DIRECTORY"));
970 chooser.setFileView(new JalviewFileView());
971 chooser.setDialogTitle("Open a saved VAMSAS session");
972 chooser.setToolTipText("select a vamsas session to be opened as a new vamsas session.");
974 int value = chooser.showOpenDialog(this);
976 if (value == JalviewFileChooser.APPROVE_OPTION)
979 v_client = new jalview.gui.VamsasApplication(this,
980 chooser.getSelectedFile());
981 } catch (Exception ex)
983 jalview.bin.Cache.log.error("New vamsas session from existing session file failed:",ex);
986 setupVamsasConnectedGui();
987 v_client.initial_update(); // TODO: thread ?
990 jalview.bin.Cache.log.error("Implementation error - load session from a running session is not supported.");
994 public void vamsasStart_actionPerformed(ActionEvent e)
996 if (v_client == null)
999 // we just start a default session for moment.
1001 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1002 getProperty("LAST_DIRECTORY"));
1004 chooser.setFileView(new JalviewFileView());
1005 chooser.setDialogTitle("Load Vamsas file");
1006 chooser.setToolTipText("Import");
1008 int value = chooser.showOpenDialog(this);
1010 if (value == JalviewFileChooser.APPROVE_OPTION)
1012 v_client = new jalview.gui.VamsasApplication(this,
1013 chooser.getSelectedFile());
1016 v_client = new VamsasApplication(this);
1017 setupVamsasConnectedGui();
1018 v_client.initial_update(); // TODO: thread ?
1022 // store current data in session.
1023 v_client.push_update(); // TODO: thread
1027 protected void setupVamsasConnectedGui()
1029 vamsasStart.setText("Session Update");
1030 vamsasSave.setVisible(true);
1031 vamsasStop.setVisible(true);
1032 vamsasImport.setVisible(false); // Document import to existing session is not possible for vamsas-client-1.0.
1034 protected void setupVamsasDisconnectedGui()
1036 vamsasSave.setVisible(false);
1037 vamsasStop.setVisible(false);
1038 vamsasImport.setVisible(true);
1039 vamsasStart.setText("New Vamsas Session...");
1042 public void vamsasStop_actionPerformed(ActionEvent e)
1044 if (v_client != null)
1046 v_client.end_session();
1048 setupVamsasDisconnectedGui();
1051 protected void buildVamsasStMenu()
1053 if (v_client == null)
1055 String[] sess = null;
1058 sess = VamsasApplication.getSessionList();
1059 } catch (Exception e)
1061 jalview.bin.Cache.log.warn(
1062 "Problem getting current sessions list.", e);
1067 jalview.bin.Cache.log.debug("Got current sessions list: "
1068 + sess.length + " entries.");
1069 VamsasStMenu.removeAll();
1070 for (int i = 0; i < sess.length; i++)
1072 JMenuItem sessit = new JMenuItem();
1073 sessit.setText(sess[i]);
1074 sessit.setToolTipText("Connect to session " + sess[i]);
1075 final Desktop dsktp = this;
1076 final String mysesid = sess[i];
1077 sessit.addActionListener(new ActionListener()
1080 public void actionPerformed(ActionEvent e)
1082 if (dsktp.v_client == null)
1084 Thread rthr = new Thread(new Runnable() {
1088 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1089 dsktp.setupVamsasConnectedGui();
1090 dsktp.v_client.initial_update();
1098 VamsasStMenu.add(sessit);
1100 // don't show an empty menu.
1101 VamsasStMenu.setVisible(sess.length>0);
1106 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1107 VamsasStMenu.removeAll();
1108 VamsasStMenu.setVisible(false);
1111 // Not interested in the content. Just hide ourselves.
1112 VamsasStMenu.setVisible(false);
1115 public void vamsasSave_actionPerformed(ActionEvent e)
1117 if (v_client != null)
1119 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1121 "LAST_DIRECTORY"), new String[]
1122 {"vdj"}, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1124 {"Vamsas Document"}, "Vamsas Document");
1126 chooser.setFileView(new JalviewFileView());
1127 chooser.setDialogTitle("Save Vamsas Document Archive");
1129 int value = chooser.showSaveDialog(this);
1131 if (value == JalviewFileChooser.APPROVE_OPTION)
1133 java.io.File choice = chooser.getSelectedFile();
1134 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1135 String warnmsg=null;
1136 String warnttl=null;
1138 v_client.vclient.storeDocument(choice);
1142 warnttl = "Serious Problem saving Vamsas Document";
1143 warnmsg = ex.toString();
1144 jalview.bin.Cache.log.error("Error Whilst saving document to "+choice,ex);
1147 catch (Exception ex)
1149 warnttl = "Problem saving Vamsas Document.";
1150 warnmsg = ex.toString();
1151 jalview.bin.Cache.log.warn("Exception Whilst saving document to "+choice,ex);
1156 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1159 JOptionPane.ERROR_MESSAGE);
1164 JProgressBar vamUpdate = null;
1166 * hide vamsas user gui bits when a vamsas document event is being handled.
1167 * @param b true to hide gui, false to reveal gui
1169 public void setVamsasUpdate(boolean b)
1171 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
1172 (b ? "in progress" : "finished"));
1174 if (vamUpdate!=null)
1176 this.removeProgressPanel(vamUpdate);
1180 vamUpdate = this.addProgressPanel("Updating vamsas session");
1182 vamsasStart.setVisible(!b);
1183 vamsasStop.setVisible(!b);
1184 vamsasSave.setVisible(!b);
1187 public JInternalFrame[] getAllFrames()
1189 return desktop.getAllFrames();
1194 * Checks the given url to see if it gives a response indicating that
1195 * the user should be informed of a new questionnaire.
1198 public void checkForQuestionnaire(String url)
1200 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1201 javax.swing.SwingUtilities.invokeLater(jvq);
1205 class MyDesktopPane extends JDesktopPane implements Runnable
1207 boolean showMemoryUsage = false;
1209 java.text.NumberFormat df;
1211 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1213 public MyDesktopPane(boolean showMemoryUsage)
1215 showMemoryUsage(showMemoryUsage);
1218 public void showMemoryUsage(boolean showMemoryUsage)
1220 this.showMemoryUsage = showMemoryUsage;
1221 if (showMemoryUsage)
1223 Thread worker = new Thread(this);
1230 df = java.text.NumberFormat.getNumberInstance();
1231 df.setMaximumFractionDigits(2);
1232 runtime = Runtime.getRuntime();
1234 while (showMemoryUsage)
1239 maxMemory = runtime.maxMemory() / 1048576f;
1240 allocatedMemory = runtime.totalMemory() / 1048576f;
1241 freeMemory = runtime.freeMemory() / 1048576f;
1242 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1244 percentUsage = (totalFreeMemory / maxMemory) * 100;
1246 // if (percentUsage < 20)
1248 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1249 // instance.set.setBorder(border1);
1254 catch (Exception ex)
1256 ex.printStackTrace();
1261 public void paintComponent(Graphics g)
1265 if (percentUsage < 20)
1266 g.setColor(Color.red);
1268 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1269 + "MB; Max Memory: " + df.format(maxMemory)
1270 + "MB; " + df.format(percentUsage) + "%", 10,
1271 getHeight() - g.getFontMetrics().getHeight());
1275 protected JMenuItem groovyShell;
1276 public void doGroovyCheck() {
1277 if (jalview.bin.Cache.groovyJarsPresent())
1279 groovyShell = new JMenuItem();
1280 groovyShell.setText("Groovy Shell...");
1281 groovyShell.addActionListener(new ActionListener()
1283 public void actionPerformed(ActionEvent e) {
1284 groovyShell_actionPerformed(e);
1287 toolsMenu.add(groovyShell);
1288 groovyShell.setVisible(true);
1292 * Accessor method to quickly get all the AlignmentFrames
1295 public static AlignFrame[] getAlignframes() {
1296 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1302 Vector avp=new Vector();
1306 for (int i = frames.length - 1; i > -1; i--)
1308 if (frames[i] instanceof AlignFrame)
1310 AlignFrame af = (AlignFrame) frames[i];
1315 catch (Exception ex)
1317 ex.printStackTrace();
1323 AlignFrame afs[] = new AlignFrame[avp.size()];
1324 for (int i=0,j=avp.size(); i<j; i++) {
1325 afs[i] = (AlignFrame) avp.elementAt(i);
1332 * Add Groovy Support to Jalview
1334 public void groovyShell_actionPerformed(ActionEvent e) {
1335 // use reflection to avoid creating compilation dependency.
1336 if (!jalview.bin.Cache.groovyJarsPresent())
1338 throw new Error("Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1341 Class gcClass = Desktop.class.getClassLoader().loadClass("groovy.ui.Console");
1342 Constructor gccons = gcClass.getConstructor(null);
1343 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", new Class[] { String.class, Object.class} );
1344 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1345 Object gc = gccons.newInstance(null);
1346 setvar.invoke(gc, new Object[] { "Jalview", this});
1347 run.invoke(gc, null);
1349 catch (Exception ex)
1351 jalview.bin.Cache.log.error("Groovy Shell Creation failed.",ex);
1352 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1354 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.", "Jalview Groovy Support Failed",
1355 JOptionPane.ERROR_MESSAGE);